2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file ratsnest.cpp
|
|
|
|
* @brief Ratsnets functions.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <colors_selection.h>
|
|
|
|
#include <wxBasePcbFrame.h>
|
2013-05-02 18:06:58 +00:00
|
|
|
#include <macros.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_track.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <minimun_spanning_tree.h>
|
2009-05-28 08:42:24 +00:00
|
|
|
|
2011-11-06 16:16:19 +00:00
|
|
|
/**
|
2014-06-29 20:33:29 +00:00
|
|
|
* @brief class MIN_SPAN_TREE_PADS (derived from MIN_SPAN_TREE) specializes
|
|
|
|
* the base class to calculate a minimum spanning tree from a list of pads,
|
2011-11-06 16:16:19 +00:00
|
|
|
* and to add this tree as ratsnest to the main ratsnest list.
|
|
|
|
*/
|
|
|
|
class MIN_SPAN_TREE_PADS: public MIN_SPAN_TREE
|
|
|
|
{
|
|
|
|
friend class MIN_SPAN_TREE;
|
|
|
|
public:
|
|
|
|
std::vector <D_PAD*>* m_PadsList; // list of pads:
|
|
|
|
/* these pads are the parents of nodes of the tree.
|
|
|
|
* Each node position is the corresponding pad position.
|
|
|
|
* This pad list is used to evaluate the weight of an edge in tree.
|
|
|
|
* -> edge = link between 2 nodes = links between 2 pads.
|
|
|
|
* -> weight of a link = rectilinear distance between the 2 pads
|
|
|
|
*/
|
|
|
|
|
|
|
|
public:
|
|
|
|
MIN_SPAN_TREE_PADS(): MIN_SPAN_TREE()
|
|
|
|
{
|
|
|
|
m_PadsList = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MSP_Init( std::vector <D_PAD*>* aPadsList )
|
|
|
|
{
|
|
|
|
m_PadsList = aPadsList;
|
|
|
|
MIN_SPAN_TREE::MSP_Init( (int) m_PadsList->size() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-11-08 16:18:46 +00:00
|
|
|
* Function AddTreeToRatsnest
|
2011-11-06 16:16:19 +00:00
|
|
|
* Adds the current minimum spanning tree as ratsnest items
|
|
|
|
* to the main ratsnest list
|
2014-06-29 20:33:29 +00:00
|
|
|
* @param aRatsnestList = a ratsnest list to add to
|
2011-11-06 16:16:19 +00:00
|
|
|
*/
|
2014-06-29 20:33:29 +00:00
|
|
|
void AddTreeToRatsnest( std::vector<RATSNEST_ITEM>* aRatsnestList );
|
2011-11-06 16:16:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetWeight
|
|
|
|
* calculates the weight between 2 items
|
|
|
|
* NOTE: The weight between a node and itself should be 0
|
|
|
|
* @param aItem1 = first item
|
|
|
|
* @param aItem2 = other item
|
|
|
|
* @return the weight between items ( the rectilinear distance )
|
|
|
|
*/
|
|
|
|
int GetWeight( int aItem1, int aItem2 );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
void MIN_SPAN_TREE_PADS::AddTreeToRatsnest( std::vector<RATSNEST_ITEM>* aRatsnestList )
|
2011-11-06 16:16:19 +00:00
|
|
|
{
|
2014-01-10 16:19:33 +00:00
|
|
|
std::vector<D_PAD*>& padsBuffer = *m_PadsList;
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2014-01-10 16:19:33 +00:00
|
|
|
if( padsBuffer.empty() )
|
|
|
|
return;
|
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
int netcode = padsBuffer[0]->GetNetCode();
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2011-11-06 16:16:19 +00:00
|
|
|
// Note: to get edges in minimum spanning tree,
|
|
|
|
// the index value 0 is not used: it is just
|
|
|
|
// the entry point of the minimum spanning tree.
|
|
|
|
// The first edge (i.e. rastnest) starts at index 1
|
|
|
|
for( int ii = 1; ii < m_Size; ii++ )
|
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Create the new ratsnest
|
2011-11-06 16:16:19 +00:00
|
|
|
RATSNEST_ITEM net;
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2011-11-06 16:16:19 +00:00
|
|
|
net.SetNet( netcode );
|
|
|
|
net.m_Status = CH_ACTIF | CH_VISIBLE;
|
|
|
|
net.m_Lenght = GetDist(ii);
|
|
|
|
net.m_PadStart = padsBuffer[ii];
|
|
|
|
net.m_PadEnd = padsBuffer[ GetWhoTo(ii) ];
|
2014-06-29 20:33:29 +00:00
|
|
|
|
|
|
|
aRatsnestList->push_back( net );
|
2011-11-06 16:16:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function GetWeight
|
|
|
|
* calculates the weight between 2 items
|
|
|
|
* Here it calculate the rectilinear distance between 2 pads (2 items)
|
|
|
|
* NOTE: The weight between a node and itself should be <=0
|
|
|
|
* aItem1 and aItem2 are the 2 items
|
|
|
|
* return the rectilinear distance
|
|
|
|
*/
|
|
|
|
int MIN_SPAN_TREE_PADS::GetWeight( int aItem1, int aItem2 )
|
|
|
|
{
|
|
|
|
// NOTE: The distance (weight) between a node and itself should be 0
|
2013-01-25 17:29:54 +00:00
|
|
|
// so we add 1 to other distances to be sure we never have 0
|
2011-11-06 16:16:19 +00:00
|
|
|
// in cases other than a node and itself
|
|
|
|
|
|
|
|
D_PAD* pad1 = (*m_PadsList)[aItem1];
|
|
|
|
D_PAD* pad2 = (*m_PadsList)[aItem2];
|
|
|
|
|
|
|
|
if( pad1 == pad2 )
|
|
|
|
return 0;
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
int weight = abs( pad2->GetPosition().x - pad1->GetPosition().x ) +
|
|
|
|
abs( pad2->GetPosition().y - pad1->GetPosition().y );
|
2011-11-06 16:16:19 +00:00
|
|
|
return weight + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
/* Note about the ratsnest computation:
|
2011-11-06 16:16:19 +00:00
|
|
|
* Building the general ratsnest:
|
|
|
|
* For each net, the ratsnest is the set of lines connecting pads,
|
|
|
|
* using the shorter distance
|
|
|
|
* Therefore this problem is well known in graph therory, and sloved
|
|
|
|
* using the "minimum spanning tree".
|
|
|
|
* We use here an algorithm to build the minimum spanning tree known as Prim's algorithm
|
2007-10-13 12:17:17 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Compile_Ratsnest
|
2009-11-20 14:55:20 +00:00
|
|
|
* Create the entire board ratsnest.
|
2007-10-13 12:17:17 +00:00
|
|
|
* Must be called after a board change (changes for
|
|
|
|
* pads, footprints or a read netlist ).
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aDC = the current device context (can be NULL)
|
|
|
|
* @param aDisplayStatus : if true, display the computation results
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_BASE_FRAME::Compile_Ratsnest( wxDC* aDC, bool aDisplayStatus )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0; // we want a full ratsnest computation, from the scratch
|
2011-04-12 14:19:59 +00:00
|
|
|
ClearMsgPanel();
|
2009-06-05 15:57:41 +00:00
|
|
|
|
|
|
|
// Rebuild the full pads and net info list
|
|
|
|
RecalculateAllTracksNetcode();
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aDisplayStatus )
|
2009-05-24 18:28:36 +00:00
|
|
|
{
|
2011-12-10 05:33:24 +00:00
|
|
|
msg.Printf( wxT( " %d" ), m_Pcb->GetPadCount() );
|
2011-04-12 14:19:59 +00:00
|
|
|
AppendMsgPanel( wxT( "Pads" ), msg, RED );
|
2011-12-10 05:33:24 +00:00
|
|
|
msg.Printf( wxT( " %d" ), m_Pcb->GetNetCount() );
|
2011-04-12 14:19:59 +00:00
|
|
|
AppendMsgPanel( wxT( "Nets" ), msg, CYAN );
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
/* Compute the full ratsnest
|
|
|
|
* which can be see like all the possible links or logical connections.
|
2009-11-20 14:55:20 +00:00
|
|
|
* some of them are active (no track connected) and others are inactive
|
2011-11-06 16:16:19 +00:00
|
|
|
* (when tracks connect pads)
|
2007-10-13 12:17:17 +00:00
|
|
|
* This full ratsnest is not modified by track editing.
|
2009-05-24 18:28:36 +00:00
|
|
|
* It changes only when a netlist is read, or footprints are modified
|
2007-10-13 12:17:17 +00:00
|
|
|
*/
|
2011-11-06 16:16:19 +00:00
|
|
|
Build_Board_Ratsnest();
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
// Compute the pad connections due to the existing tracks (physical connections)
|
2011-11-10 08:21:11 +00:00
|
|
|
TestConnections();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
/* Compute the active ratsnest, i.e. the unconnected links
|
|
|
|
*/
|
2011-11-08 16:18:46 +00:00
|
|
|
TestForActiveLinksInRatsnest( 0 );
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
|
|
// Redraw the active ratsnest ( if enabled )
|
2010-12-29 17:47:32 +00:00
|
|
|
if( GetBoard()->IsElementVisible(RATSNEST_VISIBLE) && aDC )
|
|
|
|
DrawGeneralRatsnest( aDC, 0 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aDisplayStatus )
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( m_Pcb );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
/* Sort function used by QSORT
|
|
|
|
* Sort pads by net code
|
|
|
|
*/
|
2011-11-06 16:16:19 +00:00
|
|
|
static bool sortByNetcode( const D_PAD* const & ref, const D_PAD* const & item )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2014-02-25 10:40:34 +00:00
|
|
|
return ref->GetNetCode() < item->GetNetCode();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
2011-11-06 16:16:19 +00:00
|
|
|
* Function to compute the full ratsnest
|
2011-11-07 18:04:19 +00:00
|
|
|
* This is the "basic" ratsnest depending only on pads.
|
2007-10-13 12:17:17 +00:00
|
|
|
*
|
2011-11-06 16:16:19 +00:00
|
|
|
* Create the sorted pad list (if necessary)
|
|
|
|
* The active pads (i.e included in a net ) are called nodes
|
|
|
|
* This pad list is sorted by net codes
|
|
|
|
* A ratsnest can be seen as a logical connection.
|
2007-10-13 12:17:17 +00:00
|
|
|
*
|
|
|
|
* Update :
|
|
|
|
* nb_nodes = Active pads count for the board
|
|
|
|
* nb_links = link count for the board (logical connection count)
|
2011-11-07 18:04:19 +00:00
|
|
|
* (there are n-1 links in a net which counting n active pads) .
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-11-06 16:16:19 +00:00
|
|
|
void PCB_BASE_FRAME::Build_Board_Ratsnest()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
D_PAD* pad;
|
|
|
|
int noconn;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-01-09 18:52:44 +00:00
|
|
|
m_Pcb->SetUnconnectedNetCount( 0 );
|
2009-03-16 19:51:23 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
m_Pcb->m_FullRatsnest.clear();
|
2009-03-16 19:51:23 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
if( m_Pcb->GetPadCount() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Created pad list and the net_codes if needed
|
2007-08-23 04:28:46 +00:00
|
|
|
if( (m_Pcb->m_Status_Pcb & NET_CODES_OK) == 0 )
|
2011-12-10 05:33:24 +00:00
|
|
|
m_Pcb->BuildListOfNets();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
for( unsigned ii = 0; ii<m_Pcb->GetPadCount(); ++ii )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-12-10 05:33:24 +00:00
|
|
|
pad = m_Pcb->GetPad( ii );
|
2008-11-18 18:13:55 +00:00
|
|
|
pad->SetSubRatsnest( 0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
if( m_Pcb->GetNodesCount() == 0 )
|
2012-02-19 04:02:19 +00:00
|
|
|
return; // No useful connections.
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Ratsnest computation
|
2009-11-20 14:55:20 +00:00
|
|
|
unsigned current_net_code = 1; // First net code is analyzed.
|
|
|
|
// (net_code = 0 -> no connect)
|
2009-05-24 18:28:36 +00:00
|
|
|
noconn = 0;
|
2011-11-06 16:16:19 +00:00
|
|
|
MIN_SPAN_TREE_PADS min_spanning_tree;
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
for( ; current_net_code < m_Pcb->GetNetCount(); current_net_code++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
NETINFO_ITEM* net = m_Pcb->FindNet( current_net_code );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-04-18 02:05:40 +00:00
|
|
|
if( !net ) // Should not occur
|
2009-05-28 08:42:24 +00:00
|
|
|
{
|
2014-04-18 02:05:40 +00:00
|
|
|
UTF8 msg = StrPrintf( "%s: error, net %d not found", __func__, current_net_code );
|
|
|
|
wxMessageBox( msg ); // BTW, it does happen.
|
2009-05-28 08:42:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
net->m_RatsnestStartIdx = m_Pcb->GetRatsnestsCount();
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2011-12-17 21:21:03 +00:00
|
|
|
min_spanning_tree.MSP_Init( &net->m_PadInNetList );
|
2011-11-06 16:16:19 +00:00
|
|
|
min_spanning_tree.BuildTree();
|
2014-06-29 20:33:29 +00:00
|
|
|
min_spanning_tree.AddTreeToRatsnest( &m_Pcb->m_FullRatsnest );
|
2009-06-20 19:09:43 +00:00
|
|
|
net->m_RatsnestEndIdx = m_Pcb->GetRatsnestsCount();
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2013-01-09 18:52:44 +00:00
|
|
|
m_Pcb->SetUnconnectedNetCount( noconn );
|
2009-05-24 18:28:36 +00:00
|
|
|
m_Pcb->m_Status_Pcb |= LISTE_RATSNEST_ITEM_OK;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-06 16:16:19 +00:00
|
|
|
// Update the ratsnest display option (visible/invisible) flag
|
2009-05-28 08:42:24 +00:00
|
|
|
for( unsigned ii = 0; ii < m_Pcb->GetRatsnestsCount(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2014-06-29 20:33:29 +00:00
|
|
|
if( !GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) ) // Clear VISIBLE flag
|
2009-05-28 08:42:24 +00:00
|
|
|
m_Pcb->m_FullRatsnest[ii].m_Status &= ~CH_VISIBLE;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
/**
|
2011-11-07 18:04:19 +00:00
|
|
|
* function DrawGeneralRatsnest
|
|
|
|
* Only ratsnest items with the status bit CH_VISIBLE set are displayed
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aDC = the current device context (can be NULL)
|
2011-11-07 18:04:19 +00:00
|
|
|
* @param aNetcode: if > 0, Display only the ratsnest relative to the
|
2009-11-20 14:55:20 +00:00
|
|
|
* corresponding net_code
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_BASE_FRAME::DrawGeneralRatsnest( wxDC* aDC, int aNetcode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
if( ( m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
if( ( m_Pcb->m_Status_Pcb & DO_NOT_SHOW_GENERAL_RASTNEST ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( aDC == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
const int state = CH_VISIBLE | CH_ACTIF;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
for( unsigned ii = 0; ii < m_Pcb->GetRatsnestsCount(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2010-01-21 20:36:48 +00:00
|
|
|
RATSNEST_ITEM& item = m_Pcb->m_FullRatsnest[ii];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-01-21 20:36:48 +00:00
|
|
|
if( ( item.m_Status & state ) != state )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2010-12-29 17:47:32 +00:00
|
|
|
if( ( aNetcode <= 0 ) || ( aNetcode == item.GetNet() ) )
|
2010-01-21 20:36:48 +00:00
|
|
|
{
|
2011-12-22 13:28:11 +00:00
|
|
|
item.Draw( m_canvas, aDC, GR_XOR, wxPoint( 0, 0 ) );
|
2010-01-21 20:36:48 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
/**
|
2011-11-08 16:18:46 +00:00
|
|
|
* Function used by TestForActiveLinksInRatsnest
|
2011-11-10 08:21:11 +00:00
|
|
|
* Function testing the ratsnest between 2 blocks ( of the same net )
|
2007-10-13 12:17:17 +00:00
|
|
|
* The search is made between pads in block 1 and the others blocks
|
2011-11-10 08:21:11 +00:00
|
|
|
* The block n ( n > 1 ) is merged with block 1 and linked by the smallest ratsnest
|
|
|
|
* between block 1 and the block n (activate the logical connection)
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aRatsnestBuffer = the buffer to store NETINFO_ITEM* items
|
2011-11-08 16:18:46 +00:00
|
|
|
* @param aNetinfo = the current NETINFO_ITEM for the current net
|
2011-11-10 08:21:11 +00:00
|
|
|
* output: .state member, bit CH_ACTIF of the ratsnest item
|
|
|
|
* @return last subratsnest id in use
|
2007-06-05 12:10:51 +00:00
|
|
|
*/
|
2011-11-10 08:21:11 +00:00
|
|
|
static int tst_links_between_blocks( NETINFO_ITEM* aNetinfo,
|
2012-08-03 15:43:15 +00:00
|
|
|
std::vector<RATSNEST_ITEM>& aRatsnestBuffer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-10 08:21:11 +00:00
|
|
|
int subratsnest_id, min_id;
|
2011-11-08 16:18:46 +00:00
|
|
|
RATSNEST_ITEM* link, * best_link;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Search a link from a block to an other block
|
2011-11-08 16:18:46 +00:00
|
|
|
best_link = NULL;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
for( unsigned ii = aNetinfo->m_RatsnestStartIdx; ii < aNetinfo->m_RatsnestEndIdx; ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-08 16:18:46 +00:00
|
|
|
link = &aRatsnestBuffer[ii];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
// If this link joints 2 pads inside the same block, do nothing
|
|
|
|
// (these pads are already connected)
|
|
|
|
if( link->m_PadStart->GetSubRatsnest() == link->m_PadEnd->GetSubRatsnest() )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
// This link joints 2 pads of different blocks: this is a candidate,
|
|
|
|
// but we want to select the shorter link, so use it only if it is shorter
|
|
|
|
// than the previous candidate:
|
|
|
|
if( best_link == NULL ) // no candidate
|
|
|
|
best_link = link;
|
|
|
|
else if( best_link->m_Lenght > link->m_Lenght ) // It is a better candidate.
|
|
|
|
best_link = link;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
if( best_link == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
return 1;
|
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
/* At this point we have found a link between 2 different blocks (subratsnest)
|
2007-10-13 12:17:17 +00:00
|
|
|
* we must set its status to ACTIVE and merge the 2 blocks
|
|
|
|
*/
|
2011-11-08 16:18:46 +00:00
|
|
|
best_link->m_Status |= CH_ACTIF;
|
2011-11-10 08:21:11 +00:00
|
|
|
subratsnest_id = best_link->m_PadStart->GetSubRatsnest();
|
|
|
|
min_id = best_link->m_PadEnd->GetSubRatsnest();
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-10 08:21:11 +00:00
|
|
|
if( min_id > subratsnest_id )
|
|
|
|
EXCHG( min_id, subratsnest_id );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
// Merge the 2 blocks in one sub ratsnest:
|
2011-12-17 21:21:03 +00:00
|
|
|
for( unsigned ii = 0; ii < aNetinfo->m_PadInNetList.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-12-17 21:21:03 +00:00
|
|
|
if( aNetinfo->m_PadInNetList[ii]->GetSubRatsnest() == subratsnest_id )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-12-17 21:21:03 +00:00
|
|
|
aNetinfo->m_PadInNetList[ii]->SetSubRatsnest( min_id );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 08:21:11 +00:00
|
|
|
return subratsnest_id;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
/**
|
2011-11-08 16:18:46 +00:00
|
|
|
* Function used by TestForActiveLinksInRatsnest_general
|
|
|
|
* The general ratsnest list must exists because this function explores this ratsnest
|
2011-11-10 08:21:11 +00:00
|
|
|
* Activates (i.e. set the CH_ACTIF flag) the ratsnest links between 2 pads when
|
|
|
|
* at least one pad not already connected (SubRatsnest = 0)
|
|
|
|
* and actives the corresponding link
|
2007-10-13 12:17:17 +00:00
|
|
|
*
|
2011-11-08 16:18:46 +00:00
|
|
|
* @param aFirstItem = starting address for the ratsnest list
|
|
|
|
* @param aLastItem = ending address for the ratsnest list
|
2011-11-10 08:21:11 +00:00
|
|
|
* @param aCurrSubRatsnestId = last sub ratsnest id in use (computed from the track
|
2009-11-20 14:55:20 +00:00
|
|
|
* analysis)
|
2007-10-13 12:17:17 +00:00
|
|
|
*
|
|
|
|
* output:
|
2011-11-08 16:18:46 +00:00
|
|
|
* ratsnest list (status member bit CH_ACTIF set)
|
|
|
|
* and pads linked (m_SubRatsnest value set)
|
2007-10-13 12:17:17 +00:00
|
|
|
*
|
|
|
|
* @return new block number
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2011-11-10 08:21:11 +00:00
|
|
|
static void tst_links_between_pads( int & aCurrSubRatsnestId,
|
2011-11-08 16:18:46 +00:00
|
|
|
RATSNEST_ITEM* aFirstItem,
|
|
|
|
RATSNEST_ITEM* aLastItem )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-08 16:18:46 +00:00
|
|
|
for( RATSNEST_ITEM* item = aFirstItem; item < aLastItem; item++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-08 16:18:46 +00:00
|
|
|
D_PAD* pad_start = item->m_PadStart;
|
|
|
|
D_PAD* pad_end = item->m_PadEnd;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
/* Update the current SubRatsnest if the 2 pads are not connected :
|
|
|
|
* a new cluster is created and the link activated
|
2007-10-13 12:17:17 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
if( (pad_start->GetSubRatsnest() == 0) && (pad_end->GetSubRatsnest() == 0) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-08 16:18:46 +00:00
|
|
|
aCurrSubRatsnestId++;
|
|
|
|
pad_start->SetSubRatsnest( aCurrSubRatsnestId );
|
|
|
|
pad_end->SetSubRatsnest( aCurrSubRatsnestId );
|
2011-09-07 19:41:04 +00:00
|
|
|
item->m_Status |= CH_ACTIF;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
/* If a pad is already connected to a subratsnest: activate the link
|
|
|
|
* the pad other is merged in the existing subratsnest
|
|
|
|
*/
|
2008-11-18 18:13:55 +00:00
|
|
|
else if( pad_start->GetSubRatsnest() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
pad_start->SetSubRatsnest( pad_end->GetSubRatsnest() );
|
2011-09-07 19:41:04 +00:00
|
|
|
item->m_Status |= CH_ACTIF;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2008-11-18 18:13:55 +00:00
|
|
|
else if( pad_end->GetSubRatsnest() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
pad_end->SetSubRatsnest( pad_start->GetSubRatsnest() );
|
2011-09-07 19:41:04 +00:00
|
|
|
item->m_Status |= CH_ACTIF;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
/* function TestForActiveLinksInRatsnest
|
2011-11-07 18:04:19 +00:00
|
|
|
* determine the active links inside the full ratsnest
|
|
|
|
*
|
2011-11-08 16:18:46 +00:00
|
|
|
* I used an algorithm inspired by the "Lee algorithm".
|
|
|
|
* The idea is all pads must be connected by a physical track or a logical track
|
|
|
|
* a physical track is the existing track on copper layers.
|
|
|
|
* a logical track is the link that must be activated (visible) if
|
|
|
|
* no track found between 2 pads.
|
2011-11-07 18:04:19 +00:00
|
|
|
* The algorithm explore the existing full ratnest
|
|
|
|
* This is a 2 steps algorithm (executed for each net).
|
|
|
|
* - First:
|
|
|
|
* Initialise for each pad the subratsnest id to its subnet value
|
|
|
|
* explore the full ratnest (relative to the net) and active a link each time at least one pad of
|
|
|
|
* the given link is not connected to an other pad by a track ( subratsnest = 0)
|
|
|
|
* If the 2 pads linked have both the subratsnest id = 0, a new subratsnest value is created
|
|
|
|
* - Second:
|
|
|
|
* explore the full ratnest (relative to the net) and find a link that links
|
|
|
|
* 2 pads having different subratsnest values
|
|
|
|
* Active the link and merge the 2 subratsnest value.
|
|
|
|
*
|
2011-11-08 16:18:46 +00:00
|
|
|
* This is usually fast because the ratsnest is not built here: it is just explored
|
|
|
|
* to see what link must be activated
|
2011-11-07 18:04:19 +00:00
|
|
|
*/
|
2011-11-08 16:18:46 +00:00
|
|
|
void PCB_BASE_FRAME::TestForActiveLinksInRatsnest( int aNetCode )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
RATSNEST_ITEM* rats;
|
2009-05-25 11:53:55 +00:00
|
|
|
D_PAD* pad;
|
|
|
|
NETINFO_ITEM* net;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
if( m_Pcb->GetPadCount() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
|
2011-11-06 16:16:19 +00:00
|
|
|
Build_Board_Ratsnest();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-12-10 05:33:24 +00:00
|
|
|
for( int net_code = 1; net_code < (int) m_Pcb->GetNetCount(); net_code++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
net = m_Pcb->FindNet( net_code );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
wxCHECK_RET( net != NULL,
|
|
|
|
wxString::Format( wxT( "Net code %d not found!" ), net_code ) );
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
if( aNetCode && (net_code != aNetCode) )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
// Create subratsnests id from subnets created by existing tracks:
|
2011-11-10 08:21:11 +00:00
|
|
|
int subratsnest = 0;
|
2011-12-17 21:21:03 +00:00
|
|
|
for( unsigned ip = 0; ip < net->m_PadInNetList.size(); ip++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-12-17 21:21:03 +00:00
|
|
|
pad = net->m_PadInNetList[ip];
|
2009-05-24 18:28:36 +00:00
|
|
|
int subnet = pad->GetSubNet();
|
|
|
|
pad->SetSubRatsnest( subnet );
|
2012-09-22 11:19:37 +00:00
|
|
|
subratsnest = std::max( subratsnest, subnet );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
for( unsigned ii = net->m_RatsnestStartIdx; ii < net->m_RatsnestEndIdx; ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
m_Pcb->m_FullRatsnest[ii].m_Status &= ~CH_ACTIF;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 08:21:11 +00:00
|
|
|
// First pass - activate links for not connected pads
|
2009-05-28 08:42:24 +00:00
|
|
|
rats = &m_Pcb->m_FullRatsnest[0];
|
2011-11-10 08:21:11 +00:00
|
|
|
tst_links_between_pads( subratsnest,
|
|
|
|
rats + net->m_RatsnestStartIdx,
|
|
|
|
rats + net->m_RatsnestEndIdx );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
// Second pass activate links between blocks (Iteration)
|
2011-11-10 08:21:11 +00:00
|
|
|
while( subratsnest > 1 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-10 08:21:11 +00:00
|
|
|
subratsnest = tst_links_between_blocks( net, m_Pcb->m_FullRatsnest );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-05-25 11:53:55 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2013-01-09 18:52:44 +00:00
|
|
|
m_Pcb->SetUnconnectedNetCount( 0 );
|
|
|
|
|
|
|
|
unsigned cnt = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
for( unsigned ii = 0; ii < m_Pcb->GetRatsnestsCount(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-11 07:00:51 +00:00
|
|
|
if( m_Pcb->m_FullRatsnest[ii].IsActive() )
|
2013-01-09 18:52:44 +00:00
|
|
|
cnt++;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2013-01-09 18:52:44 +00:00
|
|
|
|
|
|
|
m_Pcb->SetUnconnectedNetCount( cnt );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-03-01 19:26:17 +00:00
|
|
|
void PCB_BASE_FRAME::build_ratsnest_module( MODULE* aModule )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-07 18:04:19 +00:00
|
|
|
// for local ratsnest calculation when moving a footprint:
|
|
|
|
// list of pads to use for this local ratsnets:
|
|
|
|
// this is the list of connected pads of the current module,
|
|
|
|
// and all pads connected to these pads:
|
|
|
|
static std::vector <D_PAD*> localPadList;
|
2009-11-20 14:55:20 +00:00
|
|
|
static unsigned pads_module_count; // node count (node = pad with a net
|
|
|
|
// code) for the footprint being moved
|
|
|
|
static unsigned internalRatsCount; // number of internal links (links
|
|
|
|
// between pads of the module)
|
2009-05-28 08:42:24 +00:00
|
|
|
D_PAD* pad_ref;
|
|
|
|
D_PAD* pad_externe;
|
|
|
|
int current_net_code;
|
2009-11-20 14:55:20 +00:00
|
|
|
int distance;
|
|
|
|
wxPoint pad_pos; // True pad position according to the
|
|
|
|
// current footprint position
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
if( (GetBoard()->m_Status_Pcb & LISTE_PAD_OK) == 0 )
|
|
|
|
{
|
2009-06-05 15:57:41 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2011-12-10 05:33:24 +00:00
|
|
|
GetBoard()->BuildListOfNets();
|
2009-05-24 18:28:36 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
/* Compute the "local" ratsnest if needed (when this footprint starts move)
|
2009-11-20 14:55:20 +00:00
|
|
|
* and the list of external pads to consider, i.e pads in others
|
|
|
|
* footprints which are "connected" to
|
2009-05-24 18:28:36 +00:00
|
|
|
* a pad in the current footprint
|
|
|
|
*/
|
2011-11-07 18:04:19 +00:00
|
|
|
if( (m_Pcb->m_Status_Pcb & RATSNEST_ITEM_LOCAL_OK) == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2014-06-29 20:33:29 +00:00
|
|
|
// Compute the "internal" ratsnest, i.e the links between the current
|
|
|
|
// footprint pads
|
2011-11-07 18:04:19 +00:00
|
|
|
localPadList.clear();
|
|
|
|
m_Pcb->m_LocalRatsnest.clear();
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
// collect active pads of the module:
|
2014-06-29 20:33:29 +00:00
|
|
|
for( pad_ref = aModule->Pads(); pad_ref; pad_ref = pad_ref->Next() )
|
2011-11-07 18:04:19 +00:00
|
|
|
{
|
2014-02-25 10:40:34 +00:00
|
|
|
if( pad_ref->GetNetCode() == NETINFO_LIST::UNCONNECTED )
|
2011-11-07 18:04:19 +00:00
|
|
|
continue;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
localPadList.push_back( pad_ref );
|
|
|
|
pad_ref->SetSubRatsnest( 0 );
|
|
|
|
pad_ref->SetSubNet( 0 );
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
pads_module_count = localPadList.size();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
if( pads_module_count == 0 )
|
2012-02-19 04:02:19 +00:00
|
|
|
return; // no connection!
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
sort( localPadList.begin(), localPadList.end(), sortByNetcode );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Build the list of pads linked to the current footprint pads
|
2011-11-07 18:04:19 +00:00
|
|
|
current_net_code = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
for( unsigned ii = 0; ii < pads_module_count; ii++ )
|
|
|
|
{
|
|
|
|
pad_ref = localPadList[ii];
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
if( pad_ref->GetNetCode() == current_net_code )
|
2011-11-07 18:04:19 +00:00
|
|
|
continue;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
// A new net was found, load all pads of others modules members of this net:
|
2014-02-25 10:40:34 +00:00
|
|
|
NETINFO_ITEM* net = pad_ref->GetNet();
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
if( net == NULL ) //Should not occur
|
|
|
|
{
|
|
|
|
wxMessageBox( wxT( "build_ratsnest_module() error: net not found" ) );
|
|
|
|
return;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-12-17 21:21:03 +00:00
|
|
|
for( unsigned jj = 0; jj < net->m_PadInNetList.size(); jj++ )
|
2011-11-07 18:04:19 +00:00
|
|
|
{
|
2011-12-17 21:21:03 +00:00
|
|
|
pad_externe = net->m_PadInNetList[jj];
|
2011-11-07 18:04:19 +00:00
|
|
|
|
|
|
|
if( pad_externe->GetParent() == aModule )
|
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
pad_externe->SetSubRatsnest( 0 );
|
|
|
|
pad_externe->SetSubNet( 0 );
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
localPadList.push_back( pad_externe );
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Sort the pad list by net_code
|
2011-11-07 18:04:19 +00:00
|
|
|
sort( localPadList.begin() + pads_module_count, localPadList.end(),
|
|
|
|
sortByNetcode );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
/* Compute the internal rats nest:
|
|
|
|
* this is the same as general ratsnest, but considers only the current
|
|
|
|
* footprint pads it is therefore not time consuming, and it is made only
|
|
|
|
* once
|
|
|
|
*/
|
2014-02-25 10:40:34 +00:00
|
|
|
current_net_code = localPadList[0]->GetNetCode();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
MIN_SPAN_TREE_PADS min_spanning_tree;
|
2011-11-07 18:04:19 +00:00
|
|
|
std::vector<D_PAD*> padsBuffer; // contains pads of only one net
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
for( unsigned ii = 0; ii < pads_module_count; ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Search the end of pad list relative to the current net
|
2011-11-07 18:04:19 +00:00
|
|
|
unsigned jj = ii + 1;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
for( ; jj <= pads_module_count; jj++ )
|
|
|
|
{
|
|
|
|
if( jj >= pads_module_count )
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
if( localPadList[jj]->GetNetCode() != current_net_code )
|
2011-11-07 18:04:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2014-06-29 20:33:29 +00:00
|
|
|
for( unsigned kk = ii; kk < jj; kk++ )
|
2011-11-07 18:04:19 +00:00
|
|
|
padsBuffer.push_back( localPadList[kk] );
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
min_spanning_tree.MSP_Init( &padsBuffer );
|
|
|
|
min_spanning_tree.BuildTree();
|
2014-06-29 20:33:29 +00:00
|
|
|
min_spanning_tree.AddTreeToRatsnest( &m_Pcb->m_LocalRatsnest );
|
2011-11-07 18:04:19 +00:00
|
|
|
padsBuffer.clear();
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
ii = jj;
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
if( ii < localPadList.size() )
|
2014-02-25 10:40:34 +00:00
|
|
|
current_net_code = localPadList[ii]->GetNetCode();
|
2011-11-07 18:04:19 +00:00
|
|
|
}
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
internalRatsCount = m_Pcb->m_LocalRatsnest.size();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
// set the flag LOCAL_RATSNEST_ITEM of the ratsnest status:
|
|
|
|
for( unsigned ii = 0; ii < m_Pcb->m_LocalRatsnest.size(); ii++ )
|
|
|
|
m_Pcb->m_LocalRatsnest[ii].m_Status = LOCAL_RATSNEST_ITEM;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
m_Pcb->m_Status_Pcb |= RATSNEST_ITEM_LOCAL_OK;
|
|
|
|
} // End of internal ratsnest build
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
/* This section computes the "external" ratsnest: it is done when the
|
2009-11-20 14:55:20 +00:00
|
|
|
* footprint position changes
|
2011-11-07 18:04:19 +00:00
|
|
|
*
|
|
|
|
* This section search:
|
2009-11-20 14:55:20 +00:00
|
|
|
* for each current module pad the nearest neighbor external pad (of
|
|
|
|
* course for the same net code).
|
|
|
|
* For each current footprint cluster of pad (pads having the same net
|
|
|
|
* code),
|
2009-05-28 08:42:24 +00:00
|
|
|
* we search the smaller rats nest.
|
|
|
|
* so, for each net, only one rats nest item is created
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-05-28 08:42:24 +00:00
|
|
|
RATSNEST_ITEM local_rats;
|
2014-06-29 20:33:29 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
local_rats.m_Lenght = INT_MAX;
|
2009-05-28 08:42:24 +00:00
|
|
|
local_rats.m_Status = 0;
|
|
|
|
bool addRats = false;
|
2011-09-15 17:58:35 +00:00
|
|
|
|
2011-11-07 18:04:19 +00:00
|
|
|
// Erase external ratsnest items:
|
2009-05-28 08:42:24 +00:00
|
|
|
if( internalRatsCount < m_Pcb->m_LocalRatsnest.size() )
|
2011-09-07 19:41:04 +00:00
|
|
|
m_Pcb->m_LocalRatsnest.erase( m_Pcb->m_LocalRatsnest.begin() + internalRatsCount,
|
|
|
|
m_Pcb->m_LocalRatsnest.end() );
|
2009-05-28 08:42:24 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
current_net_code = localPadList[0]->GetNetCode();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
for( unsigned ii = 0; ii < pads_module_count; ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-07 18:04:19 +00:00
|
|
|
pad_ref = localPadList[ii];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
if( pad_ref->GetNetCode() != current_net_code )
|
2007-10-13 12:17:17 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// if needed, creates a new ratsnest for the old net
|
2009-05-28 08:42:24 +00:00
|
|
|
if( addRats )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
m_Pcb->m_LocalRatsnest.push_back( local_rats );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
addRats = false;
|
2014-02-25 10:40:34 +00:00
|
|
|
current_net_code = pad_ref->GetNetCode();
|
2011-11-07 18:04:19 +00:00
|
|
|
local_rats.m_Lenght = INT_MAX;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
pad_pos = pad_ref->GetPosition() - g_Offset_Module;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
// Search the nearest external pad of this current pad
|
2011-11-07 18:04:19 +00:00
|
|
|
for( unsigned jj = pads_module_count; jj < localPadList.size(); jj++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-07 18:04:19 +00:00
|
|
|
pad_externe = localPadList[jj];
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// we search pads having the same net code
|
2014-02-25 10:40:34 +00:00
|
|
|
if( pad_externe->GetNetCode() < pad_ref->GetNetCode() )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
if( pad_externe->GetNetCode() > pad_ref->GetNetCode() ) // pads are sorted by net code
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
distance = abs( pad_externe->GetPosition().x - pad_pos.x ) +
|
|
|
|
abs( pad_externe->GetPosition().y - pad_pos.y );
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
if( distance < local_rats.m_Lenght )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
local_rats.m_PadStart = pad_ref;
|
|
|
|
local_rats.m_PadEnd = pad_externe;
|
2014-02-25 10:40:34 +00:00
|
|
|
local_rats.SetNet( pad_ref->GetNetCode() );
|
2009-05-28 08:42:24 +00:00
|
|
|
local_rats.m_Lenght = distance;
|
|
|
|
local_rats.m_Status = 0;
|
2008-03-22 18:08:44 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
addRats = true;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
if( addRats ) // Ensure the last created rats nest item is stored in buffer
|
|
|
|
m_Pcb->m_LocalRatsnest.push_back( local_rats );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
void PCB_BASE_FRAME::TraceModuleRatsNest( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
if( DC == NULL )
|
2008-03-22 18:08:44 +00:00
|
|
|
return;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
if( ( m_Pcb->m_Status_Pcb & RATSNEST_ITEM_LOCAL_OK ) == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
|
2012-09-02 12:06:47 +00:00
|
|
|
EDA_COLOR_T tmpcolor = g_ColorsSettings.GetItemColor(RATSNEST_VISIBLE);
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
for( unsigned ii = 0; ii < m_Pcb->m_LocalRatsnest.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
RATSNEST_ITEM* rats = &m_Pcb->m_LocalRatsnest[ii];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
if( rats->m_Status & LOCAL_RATSNEST_ITEM )
|
2009-05-25 14:14:54 +00:00
|
|
|
{
|
2010-01-29 20:36:12 +00:00
|
|
|
g_ColorsSettings.SetItemColor(RATSNEST_VISIBLE, YELLOW);
|
2011-12-22 13:28:11 +00:00
|
|
|
rats->Draw( m_canvas, DC, GR_XOR, g_Offset_Module );
|
2009-05-25 14:14:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-29 20:36:12 +00:00
|
|
|
g_ColorsSettings.SetItemColor(RATSNEST_VISIBLE, tmpcolor);
|
2012-02-19 04:02:19 +00:00
|
|
|
|
|
|
|
wxPoint tmp = rats->m_PadStart->GetPosition();
|
|
|
|
|
|
|
|
rats->m_PadStart->SetPosition( tmp - g_Offset_Module );
|
2011-12-22 13:28:11 +00:00
|
|
|
rats->Draw( m_canvas, DC, GR_XOR, wxPoint( 0, 0 ) );
|
2012-02-19 04:02:19 +00:00
|
|
|
|
|
|
|
rats->m_PadStart->SetPosition( tmp );
|
2009-05-25 14:14:54 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-05-25 16:07:33 +00:00
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
g_ColorsSettings.SetItemColor( RATSNEST_VISIBLE, tmpcolor );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
/*
|
2011-11-10 08:21:11 +00:00
|
|
|
* PCB_BASE_FRAME::BuildAirWiresTargetsList and
|
|
|
|
* PCB_BASE_FRAME::TraceAirWiresToTargets
|
|
|
|
* are 2 function to show the near connecting points when
|
|
|
|
* a new track is created, by displaying g_MaxLinksShowed airwires
|
|
|
|
* between the on grid mouse cursor and these connecting points
|
|
|
|
* during the creation of a track
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
/* Buffer to store pads coordinates when creating a track.
|
|
|
|
* these pads are members of the net
|
2009-11-20 14:55:20 +00:00
|
|
|
* and when the mouse is moved, the g_MaxLinksShowed links to neighbors are
|
|
|
|
* drawn
|
2009-05-25 11:53:55 +00:00
|
|
|
*/
|
2011-11-08 16:18:46 +00:00
|
|
|
static std::vector <wxPoint> s_TargetsLocations;
|
2009-11-20 14:55:20 +00:00
|
|
|
static wxPoint s_CursorPos; // Coordinate of the moving point (mouse cursor and
|
|
|
|
// end of current track segment)
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
/* Used by BuildAirWiresTargetsList(): sort function by link length
|
|
|
|
* (rectilinear distance between s_CursorPos and item pos)
|
2009-11-20 14:55:20 +00:00
|
|
|
*/
|
2011-11-08 16:18:46 +00:00
|
|
|
static bool sort_by_distance( const wxPoint& ref, const wxPoint& compare )
|
2009-05-25 11:53:55 +00:00
|
|
|
{
|
2011-11-08 16:18:46 +00:00
|
|
|
wxPoint deltaref = ref - s_CursorPos; // relative coordinate of ref
|
|
|
|
wxPoint deltacmp = compare - s_CursorPos; // relative coordinate of compare
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
// rectilinear distance between ref and s_CursorPos:
|
2009-05-25 11:53:55 +00:00
|
|
|
int lengthref = abs( deltaref.x ) + abs( deltaref.y );
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
// rectilinear distance between compare and s_CursorPos:
|
2009-05-25 11:53:55 +00:00
|
|
|
int lengthcmp = abs( deltacmp.x ) + abs( deltacmp.y );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
return lengthref < lengthcmp;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2014-06-30 04:40:16 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
static bool sort_by_point( const wxPoint& ref, const wxPoint& compare )
|
|
|
|
{
|
|
|
|
if( ref.x == compare.x )
|
|
|
|
return ref.y < compare.y;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
return ref.x < compare.x;
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
/* Function BuildAirWiresTargetsList
|
|
|
|
* Build a list of candidates that can be a coonection point
|
|
|
|
* when a track is started.
|
|
|
|
* This functions prepares data to show airwires to nearest connecting points (pads)
|
|
|
|
* from the current new track to candidates during track creation
|
|
|
|
*/
|
|
|
|
void PCB_BASE_FRAME::BuildAirWiresTargetsList( BOARD_CONNECTED_ITEM* aItemRef,
|
|
|
|
const wxPoint& aPosition, bool aInit )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
if( ( ( m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 )
|
|
|
|
|| ( ( m_Pcb->m_Status_Pcb & LISTE_PAD_OK ) == 0 )
|
|
|
|
|| ( ( m_Pcb->m_Status_Pcb & NET_CODES_OK ) == 0 ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-08 16:18:46 +00:00
|
|
|
s_TargetsLocations.clear();
|
2009-05-25 11:53:55 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
s_CursorPos = aPosition; // needed for sort_by_distance
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
if( aInit )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-11-08 16:18:46 +00:00
|
|
|
s_TargetsLocations.clear();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
if( aItemRef == NULL )
|
2009-05-25 11:53:55 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2014-02-25 10:40:34 +00:00
|
|
|
int net_code = aItemRef->GetNetCode();
|
2011-11-08 16:18:46 +00:00
|
|
|
int subnet = aItemRef->GetSubNet();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
if( net_code <= 0 )
|
2009-05-25 11:53:55 +00:00
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
NETINFO_ITEM* net = m_Pcb->FindNet( net_code );
|
2009-11-20 14:55:20 +00:00
|
|
|
|
|
|
|
if( net == NULL ) // Should not occur
|
2009-05-28 08:42:24 +00:00
|
|
|
{
|
2011-11-08 16:18:46 +00:00
|
|
|
wxMessageBox( wxT( "BuildAirWiresTargetsList() error: net not found" ) );
|
2009-05-25 11:53:55 +00:00
|
|
|
return;
|
2009-05-28 08:42:24 +00:00
|
|
|
}
|
2009-05-25 16:07:33 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
// Create a list of pads candidates ( pads not already connected to the
|
2011-11-08 16:18:46 +00:00
|
|
|
// current track ):
|
2011-12-17 21:21:03 +00:00
|
|
|
for( unsigned ii = 0; ii < net->m_PadInNetList.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2011-12-17 21:21:03 +00:00
|
|
|
D_PAD* pad = net->m_PadInNetList[ii];
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
if( pad == aItemRef )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !pad->GetSubNet() || (pad->GetSubNet() != subnet) )
|
2012-02-19 04:02:19 +00:00
|
|
|
s_TargetsLocations.push_back( pad->GetPosition() );
|
2011-11-08 16:18:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a list of tracks ends candidates, not already connected to the
|
|
|
|
// current track:
|
|
|
|
for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() )
|
|
|
|
{
|
2014-02-25 10:40:34 +00:00
|
|
|
if( track->GetNetCode() < net_code )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2014-02-25 10:40:34 +00:00
|
|
|
if( track->GetNetCode() > net_code )
|
2011-11-08 16:18:46 +00:00
|
|
|
break;;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
if( !track->GetSubNet() || (track->GetSubNet() != subnet) )
|
|
|
|
{
|
2013-01-13 00:04:00 +00:00
|
|
|
if( aPosition != track->GetStart() )
|
|
|
|
s_TargetsLocations.push_back( track->GetStart() );
|
|
|
|
if( aPosition != track->GetEnd() && track->GetStart() != track->GetEnd() )
|
|
|
|
s_TargetsLocations.push_back( track->GetEnd() );
|
2011-11-08 16:18:46 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2011-11-08 16:18:46 +00:00
|
|
|
|
|
|
|
// Remove duplicate targets, using the C++ unique algorithm
|
|
|
|
sort( s_TargetsLocations.begin(), s_TargetsLocations.end(), sort_by_point );
|
|
|
|
std::vector< wxPoint >::iterator it = unique( s_TargetsLocations.begin(), s_TargetsLocations.end() );
|
2012-02-19 04:02:19 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
// Using the C++ unique algorithm only moves the duplicate entries to the end of
|
|
|
|
// of the array. This removes the duplicate entries from the array.
|
|
|
|
s_TargetsLocations.resize( it - s_TargetsLocations.begin() );
|
2012-02-19 04:02:19 +00:00
|
|
|
} // end if Init
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
// in all cases, sort by distances:
|
|
|
|
sort( s_TargetsLocations.begin(), s_TargetsLocations.end(), sort_by_distance );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
void PCB_BASE_FRAME::TraceAirWiresToTargets( wxDC* aDC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
if( aDC == NULL )
|
2008-03-22 18:08:44 +00:00
|
|
|
return;
|
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
if( s_TargetsLocations.size() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
GRSetDrawMode( aDC, GR_XOR );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-08 16:18:46 +00:00
|
|
|
for( int ii = 0; ii < (int) s_TargetsLocations.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
if( ii >= g_MaxLinksShowed )
|
|
|
|
break;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
GRLine( m_canvas->GetClipBox(), aDC, s_CursorPos, s_TargetsLocations[ii], 0, YELLOW );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|