2007-10-13 12:17:17 +00:00
|
|
|
|
/***********************/
|
|
|
|
|
/**** ratsnest.cpp ****/
|
|
|
|
|
/* Ratsnets functions */
|
|
|
|
|
/***********************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include "class_drawpanel.h"
|
|
|
|
|
#include "confirm.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
#include "pcbnew.h"
|
|
|
|
|
#include "autorout.h"
|
|
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
|
|
|
|
/* local variables */
|
2009-05-28 08:42:24 +00:00
|
|
|
|
static std::vector <D_PAD*> s_localPadBuffer; // for local ratsnest calculations when moving a footprint: buffer of pads to consider
|
|
|
|
|
|
|
|
|
|
static bool DisplayRastnestInProgress; // Enable the display of the ratsnest during the ratsnest computations
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
|
|
|
|
/* Note about the ratsnest computation:
|
|
|
|
|
* Building the general ratsnest:
|
|
|
|
|
* I used the "lee algoritm".
|
|
|
|
|
* This is a 2 steps algoritm.
|
2008-11-18 18:13:55 +00:00
|
|
|
|
* the m_SubRatsnest member of pads handle a "block number" or a "cluster number" or a "subnet number"
|
|
|
|
|
* initially, m_SubRatsnest = 0 (pad not connected).
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* Build_Board_Ratsnest( wxDC* DC ) Create this rastnest
|
|
|
|
|
* for each net:
|
|
|
|
|
* First:
|
2007-10-16 19:05:33 +00:00
|
|
|
|
* we create a link (and therefore a logical block) between 2 pad. This is achieved by:
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* search for a pad without link.
|
|
|
|
|
* search its nearest pad
|
|
|
|
|
* link these 2 pads (i.e. create a ratsnest item)
|
|
|
|
|
* the pads are grouped in a logical block ( a cluster).
|
|
|
|
|
* until no pad without link found.
|
2008-10-29 15:26:53 +00:00
|
|
|
|
* Each logical block has a number called block number or "subnet number",
|
2008-11-18 18:13:55 +00:00
|
|
|
|
* stored in m_SubRatsnest member for each pad of the block.
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* The first block has its block number = 1, the second is 2 ...
|
|
|
|
|
* the function to do thas is gen_rats_pad_to_pad()
|
|
|
|
|
*
|
|
|
|
|
* Secondly:
|
|
|
|
|
* The first pass created many logical blocks
|
|
|
|
|
* A block contains 2 or more pads.
|
|
|
|
|
* we create links between 2 block. This is achieved by:
|
|
|
|
|
* Test all pads in the first block, and search (for each pad)
|
|
|
|
|
* a neighboor in other blocks and compute the distance between pads,
|
|
|
|
|
* We select the pad pair which have the smallest distance.
|
|
|
|
|
* These 2 pads are linked (i.e. a new ratsnest item is created between thes 2 pads)
|
|
|
|
|
* and the 2 block are merged.
|
|
|
|
|
* Therefore the logical block 1 contains the initial block 1 "eats" the pads of the other block
|
|
|
|
|
* The computation is made until only one block is found.
|
|
|
|
|
* the function used is gen_rats_block_to_block()
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* How existing and new tracks are handled:
|
|
|
|
|
* The complete rastnest (using the pad analysis) is computed.
|
|
|
|
|
* it is independant of the tracks and handle the "logical connections".
|
|
|
|
|
* It depends only on the footprints geometry (and the netlist),
|
|
|
|
|
* and must be computed only after a netlist read or a footprints geometry change.
|
|
|
|
|
* Each link (ratsnest) can only be INACTIVE (because pads are connected by a track) or ACTIVE (no tracks)
|
|
|
|
|
*
|
|
|
|
|
* After the complete rastnest is built, or when a track is added or deleted,
|
|
|
|
|
* we run an algorithm derived from the complete rastnest computation.
|
|
|
|
|
* it is much faster because it analyses only the existing rastnest and not all the pads list
|
|
|
|
|
* and determine only if an existing rastnest must be activated
|
|
|
|
|
* (no physical track exists) or not (a physical track exists)
|
|
|
|
|
* if a track is added or deleted only the corresponding net is tested.
|
|
|
|
|
*
|
2008-11-18 18:13:55 +00:00
|
|
|
|
* the m_SubRatsnest member of pads is set to 0 (no blocks), and alls links are set to INACTIVE (ratsnest not show).
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* Before running this fast lee algorithm, we create blocks (and their corresponding block number)
|
|
|
|
|
* by grouping pads connected by tracks.
|
|
|
|
|
* So, when tracks exists, the fast lee algorithm is started with some blocks already created.
|
|
|
|
|
* because the fast lee algorithm test only the ratsnest and does not search for
|
|
|
|
|
* nearest pads (this search was previously made) the online ratsnest can be done
|
|
|
|
|
* when a track is created without noticeable computing time
|
|
|
|
|
* First:
|
|
|
|
|
* for all links (in this step, all are inactive):
|
2008-11-18 18:13:55 +00:00
|
|
|
|
* search for a link which have 1 (or 2) pad having the m_SubRatsnest member = 0.
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* if found the link is set to ACTIVE (i.e. the ratsnest will be showed) and the pad is meged with the block
|
|
|
|
|
* or a new block is created ( see tst_rats_pad_to_pad() ).
|
|
|
|
|
* Secondly:
|
|
|
|
|
* blocks are tested:
|
|
|
|
|
* for all links we search if the 2 pads linkeds are in 2 different block.
|
|
|
|
|
* if yes, the link status is set to ACTIVE, and the 2 block are merged
|
|
|
|
|
* until only one block is found
|
|
|
|
|
* ( see tst_rats_block_to_block() )
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/******************************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
void WinEDA_BasePcbFrame::Compile_Ratsnest( wxDC* DC, bool display_status_pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/** Function Compile_Ratsnest
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* Create the entire board ratsnesr.
|
|
|
|
|
* Must be called after a board change (changes for
|
|
|
|
|
* pads, footprints or a read netlist ).
|
|
|
|
|
*
|
2009-05-24 18:28:36 +00:00
|
|
|
|
* @param display_status_pcb : if true, display the computation results
|
2007-08-23 04:28:46 +00:00
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
|
|
DisplayRastnestInProgress = TRUE;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
GetBoard()->m_Status_Pcb = 0; /* we want a full ratnest computation, from the scratch */
|
2009-06-20 19:09:43 +00:00
|
|
|
|
MsgPanel->EraseMsgBox();
|
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
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
if( display_status_pcb )
|
|
|
|
|
{
|
2009-06-06 18:08:49 +00:00
|
|
|
|
msg.Printf( wxT( " %d" ), m_Pcb->GetPadsCount() );
|
2009-05-24 18:28:36 +00:00
|
|
|
|
Affiche_1_Parametre( this, 1, wxT( "pads" ), msg, RED );
|
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
if( display_status_pcb )
|
|
|
|
|
{
|
2009-06-06 18:08:49 +00:00
|
|
|
|
msg.Printf( wxT( " %d" ), m_Pcb->m_NetInfo->GetNetsCount() );
|
2009-05-24 18:28:36 +00:00
|
|
|
|
Affiche_1_Parametre( this, 8, wxT( "Nets" ), msg, CYAN );
|
|
|
|
|
}
|
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.
|
|
|
|
|
* some of thems are active (no track connected) and others are inactive (when track connect pads)
|
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
Build_Board_Ratsnest( DC );
|
|
|
|
|
|
|
|
|
|
/* Compute the pad connections due to the existing tracks (physical connections)*/
|
|
|
|
|
test_connexions( DC );
|
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
|
|
|
|
|
* it is faster than Build_Board_Ratsnest()
|
|
|
|
|
* because many optimisations and computations are already made
|
|
|
|
|
*/
|
|
|
|
|
Tst_Ratsnest( DC, 0 );
|
|
|
|
|
|
|
|
|
|
// Redraw the active ratsnest ( if enabled )
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( g_Show_Ratsnest && DC )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
DrawGeneralRatsnest( DC, 0 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
if( display_status_pcb )
|
2009-04-17 08:51:02 +00:00
|
|
|
|
m_Pcb->DisplayInfo( this );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************/
|
2009-05-28 08:42:24 +00:00
|
|
|
|
static int sortByNetcode( const void* o1, const void* o2 )
|
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
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
D_PAD** pt_ref = (D_PAD**) o1;
|
|
|
|
|
D_PAD** pt_compare = (D_PAD**) o2;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
|
return (*pt_ref)->GetNet() - (*pt_compare)->GetNet();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/********************************************************/
|
2007-10-11 00:11:59 +00:00
|
|
|
|
static int sort_by_length( const void* o1, const void* o2 )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/********************************************************/
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
|
|
|
|
/* Sort function used by QSORT
|
|
|
|
|
* Sort ratsnest by lenght
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
RATSNEST_ITEM* ref = (RATSNEST_ITEM*) o1;
|
|
|
|
|
RATSNEST_ITEM* compare = (RATSNEST_ITEM*) o2;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
return ref->m_Lenght - compare->m_Lenght;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2009-06-23 15:45:53 +00:00
|
|
|
|
static int gen_rats_block_to_block( std::vector<RATSNEST_ITEM>& aRatsnestBuffer,
|
|
|
|
|
std::vector<D_PAD*>& aPadBuffer,
|
|
|
|
|
unsigned aPadIdxStart,
|
|
|
|
|
unsigned aPadIdxMax )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*****************************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* Function used by Build_Board_Ratsnest()
|
|
|
|
|
* This function creates a rastsnet between two blocks ( which fit the same net )
|
|
|
|
|
* A block is a group of pads already linked (by a previous ratsnest computation, or tracks)
|
|
|
|
|
* The search is made between the pads in block 1 (the reference block) and other blocks
|
|
|
|
|
* the block n ( n > 1 ) it connected to block 1 by their 2 nearest pads.
|
|
|
|
|
* When the block is found, it is merged with the block 1
|
2008-11-18 18:13:55 +00:00
|
|
|
|
* the D_PAD member m_SubRatsnest handles the block number
|
2009-05-28 08:42:24 +00:00
|
|
|
|
* @param aRatsnestBuffer = a std::vector<RATSNEST_ITEM> buffer to fill with new ratsnest items
|
2009-06-23 15:45:53 +00:00
|
|
|
|
* @param aPadBuffer = a std::vector<D_PAD*> that is the list of pads to consider
|
|
|
|
|
* @param aPadIdxStart = starting index (within the pad list) for search
|
|
|
|
|
* @param aPadIdxMax = ending index (within the pad list) for search
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* @return blocks not connected count
|
2007-06-05 12:10:51 +00:00
|
|
|
|
*/
|
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
int dist_min, current_dist;
|
|
|
|
|
int current_num_block = 1;
|
|
|
|
|
int padBlock1Idx = -1; // Index in aPadBuffer for the "better" pad found in block 1
|
|
|
|
|
int padBlockToMergeIdx = -1; // Index in aPadBuffer for the "better" pad found in block to merge
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2007-10-11 00:11:59 +00:00
|
|
|
|
dist_min = 0x7FFFFFFF;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
|
|
|
|
/* Search the nearest pad from block 1 */
|
2009-06-23 15:45:53 +00:00
|
|
|
|
for( unsigned ii = aPadIdxStart; ii < aPadIdxMax; ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
D_PAD* ref_pad = aPadBuffer[ii];
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
|
|
|
|
/* search a pad which is in the block 1 */
|
2008-11-18 18:13:55 +00:00
|
|
|
|
if( ref_pad->GetSubRatsnest() != 1 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* pad is found, search its nearest neighbour in other blocks */
|
2009-06-23 15:45:53 +00:00
|
|
|
|
for( unsigned jj = aPadIdxStart; jj < aPadIdxMax; jj++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
D_PAD* curr_pad = aPadBuffer[jj];
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
|
if( curr_pad->GetSubRatsnest() == 1 ) // not in an other block
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* Compare distance between pads ("Manhattan" distance) */
|
2007-10-13 06:18:44 +00:00
|
|
|
|
current_dist = abs( curr_pad->m_Pos.x - ref_pad->m_Pos.x ) +
|
|
|
|
|
abs( curr_pad->m_Pos.y - ref_pad->m_Pos.y );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
if( dist_min > current_dist ) // we have found a better pad pair
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2007-10-13 12:17:17 +00:00
|
|
|
|
// The tested block can be a good candidate for merging
|
|
|
|
|
// we memorise the "best" current values for merging
|
2008-11-18 18:13:55 +00:00
|
|
|
|
current_num_block = curr_pad->GetSubRatsnest();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
dist_min = current_dist;
|
2008-03-22 18:08:44 +00:00
|
|
|
|
|
2009-06-23 15:45:53 +00:00
|
|
|
|
padBlockToMergeIdx = jj;
|
|
|
|
|
padBlock1Idx = ii;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* The reference block is labelled block 1.
|
|
|
|
|
* if current_num_block != 1 we have found an other block, and we must merge it
|
|
|
|
|
* with the reference block
|
|
|
|
|
* The link is made by the 2 nearest pads
|
|
|
|
|
*/
|
|
|
|
|
if( current_num_block > 1 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
/* The block n (n=current_num_block) is merged with the bloc 1 :
|
2008-11-18 18:13:55 +00:00
|
|
|
|
* to do that, we set the m_SubRatsnest member to 1 for all pads in block n
|
2007-10-13 12:17:17 +00:00
|
|
|
|
*/
|
2009-06-23 15:45:53 +00:00
|
|
|
|
for( unsigned ii = aPadIdxStart; ii < aPadIdxMax; ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
D_PAD* pad = aPadBuffer[ii];
|
|
|
|
|
if( pad->GetSubRatsnest() == current_num_block )
|
|
|
|
|
pad->SetSubRatsnest( 1 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-23 15:45:53 +00:00
|
|
|
|
if( padBlock1Idx < 0 )
|
|
|
|
|
DisplayError( NULL, wxT( "gen_rats_block_to_block() internal error" ) );
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Create the new ratsnet */
|
|
|
|
|
RATSNEST_ITEM net;
|
|
|
|
|
net.SetNet( aPadBuffer[padBlock1Idx]->GetNet() );
|
|
|
|
|
net.m_Status = CH_ACTIF | CH_VISIBLE;
|
|
|
|
|
net.m_Lenght = dist_min;
|
|
|
|
|
net.m_PadStart = aPadBuffer[padBlock1Idx];
|
|
|
|
|
net.m_PadEnd = aPadBuffer[padBlockToMergeIdx];
|
|
|
|
|
aRatsnestBuffer.push_back( net );
|
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
return current_num_block;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*****************************************************************************/
|
2009-06-23 15:45:53 +00:00
|
|
|
|
static int gen_rats_pad_to_pad( vector<RATSNEST_ITEM>& aRatsnestBuffer,
|
|
|
|
|
std::vector<D_PAD*>& aPadBuffer,
|
|
|
|
|
unsigned aPadIdxStart,
|
|
|
|
|
unsigned aPadIdxMax,
|
2009-05-28 08:42:24 +00:00
|
|
|
|
int current_num_block )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*****************************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* Function used by Build_Board_Ratsnest()
|
|
|
|
|
* this is the first pass of the lee algorithm
|
|
|
|
|
* This function creates the link (ratsnest) between 2 pads ( fitting the same net )
|
|
|
|
|
* the function search for a first not connected pad
|
|
|
|
|
* and search its nearest neighboor
|
|
|
|
|
* Its creates a block if the 2 pads are not connected, or merge the unconnected pad to the existing block.
|
|
|
|
|
* These blocks include 2 pads and the 2 pads are linked by a ratsnest.
|
|
|
|
|
*
|
2009-06-23 15:45:53 +00:00
|
|
|
|
* @param aRatsnestBuffer = a std::vector<RATSNEST_ITEM> buffer to fill with new ratsnest items
|
|
|
|
|
* @param aPadBuffer = a std::vector<D_PAD*> that is the list of pads to consider
|
|
|
|
|
* @param aPadIdxStart = starting index (within the pad list) for search
|
|
|
|
|
* @param aPadIdxMax = ending index (within the pad list) for search
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* @param current_num_block = Last existing block number de pads
|
2009-05-28 08:42:24 +00:00
|
|
|
|
* These block are created by the existing tracks analysis
|
2007-10-13 12:17:17 +00:00
|
|
|
|
*
|
2009-05-28 08:42:24 +00:00
|
|
|
|
* @return the last block number used
|
2007-06-05 12:10:51 +00:00
|
|
|
|
*/
|
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
int dist_min, current_dist;
|
|
|
|
|
D_PAD* ref_pad, * pad;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-06-23 15:45:53 +00:00
|
|
|
|
for( unsigned ii = aPadIdxStart; ii < aPadIdxMax; ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
ref_pad = aPadBuffer[ii];
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
|
if( ref_pad->GetSubRatsnest() )
|
2007-10-13 12:17:17 +00:00
|
|
|
|
continue; // Pad already connected
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-11 00:11:59 +00:00
|
|
|
|
dist_min = 0x7FFFFFFF;
|
2009-06-23 15:45:53 +00:00
|
|
|
|
int padBlockToMergeIdx = -1; // Index in aPadBuffer for the "better" pad found in block to merge
|
|
|
|
|
for( unsigned jj = aPadIdxStart; jj < aPadIdxMax; jj++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
if( ii == jj )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2009-06-23 15:45:53 +00:00
|
|
|
|
pad = aPadBuffer[jj];
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
|
|
|
|
/* Compare distance between pads ("Manhattan" distance) */
|
2009-05-24 18:28:36 +00:00
|
|
|
|
current_dist = abs( pad->m_Pos.x - ref_pad->m_Pos.x ) +
|
|
|
|
|
abs( pad->m_Pos.y - ref_pad->m_Pos.y );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
if( dist_min > current_dist )
|
|
|
|
|
{
|
|
|
|
|
dist_min = current_dist;
|
2009-06-23 15:45:53 +00:00
|
|
|
|
padBlockToMergeIdx = jj;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-23 15:45:53 +00:00
|
|
|
|
if( padBlockToMergeIdx >= 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
pad = aPadBuffer[padBlockToMergeIdx];
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* Update the block number
|
|
|
|
|
* if the 2 pads are not already created : a new block is created
|
|
|
|
|
*/
|
2008-11-18 18:13:55 +00:00
|
|
|
|
if( (pad->GetSubRatsnest() == 0) && (ref_pad->GetSubRatsnest() == 0) )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
current_num_block++; // Creates a new block number (or subratsnest)
|
2009-05-24 18:28:36 +00:00
|
|
|
|
pad->SetSubRatsnest( current_num_block );
|
|
|
|
|
ref_pad->SetSubRatsnest( current_num_block );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* If a pad is already connected connected : merge the other pad in the block */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
ref_pad->SetSubRatsnest( pad->GetSubRatsnest() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
/* Create the new ratsnet item */
|
|
|
|
|
RATSNEST_ITEM rast;
|
|
|
|
|
rast.SetNet( ref_pad->GetNet() );
|
|
|
|
|
rast.m_Status = CH_ACTIF | CH_VISIBLE;
|
|
|
|
|
rast.m_Lenght = dist_min;
|
|
|
|
|
rast.m_PadStart = ref_pad;
|
|
|
|
|
rast.m_PadEnd = pad;
|
|
|
|
|
aRatsnestBuffer.push_back( rast );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return current_num_block;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
void WinEDA_BasePcbFrame::Build_Board_Ratsnest( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/***********************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/** Function to compute the full ratsnest (using the LEE algorithm )
|
|
|
|
|
* In the functions tracks are not considered
|
|
|
|
|
* This is only the "basic" ratsnest depending only on pads.
|
|
|
|
|
*
|
|
|
|
|
* - 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
|
|
|
|
|
*
|
|
|
|
|
* - Compute the ratsnest (LEE algorithm ):
|
|
|
|
|
* a - Create the ratsnest between a not connected pad and its nearest
|
|
|
|
|
* neighbour. Blocks of pads are created
|
|
|
|
|
* b - Create the ratsnest between blocks:
|
|
|
|
|
* Test the pads of the 1st block and create a link (ratsnest)
|
|
|
|
|
* with the nearest pad found in an other block.
|
2008-12-04 04:28:11 +00:00
|
|
|
|
* The other block is merged with the first block.
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* until only one block is left.
|
|
|
|
|
*
|
|
|
|
|
* A ratnest can be seen as a logical connection.
|
|
|
|
|
*
|
|
|
|
|
* Update :
|
|
|
|
|
* nb_nodes = Active pads count for the board
|
|
|
|
|
* nb_links = link count for the board (logical connection count)
|
|
|
|
|
* (there are n-1 links for an equipotent which have n active pads) .
|
|
|
|
|
*
|
2007-08-23 04:28:46 +00:00
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
|
m_Pcb->m_NbNoconnect = 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
|
|
|
|
|
2009-06-06 18:08:49 +00:00
|
|
|
|
if( m_Pcb->GetPadsCount() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2007-10-13 12:17:17 +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 )
|
2009-05-24 18:28:36 +00:00
|
|
|
|
m_Pcb->m_NetInfo->BuildListOfNets();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-06-06 18:08:49 +00:00
|
|
|
|
for( unsigned ii = 0; ii<m_Pcb->GetPadsCount(); ++ii )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
pad = m_Pcb->m_NetInfo->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 )
|
2007-10-13 12:17:17 +00:00
|
|
|
|
return; /* pas de connexions utiles */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* Ratsnest computation */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
DisplayRastnestInProgress = TRUE;
|
2008-03-22 18:08:44 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
unsigned current_net_code = 1; // 1er net_code a analyser (net_code = 0 -> no connect)
|
|
|
|
|
noconn = 0;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
2009-06-06 18:08:49 +00:00
|
|
|
|
for( ; current_net_code < m_Pcb->m_NetInfo->GetNetsCount(); 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 );
|
2009-06-23 15:45:53 +00:00
|
|
|
|
if( net == NULL ) //Should not occur
|
2009-05-28 08:42:24 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
DisplayError( this, wxT( "Build_Board_Ratsnest() error: net not found" ) );
|
2009-05-28 08:42:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-06-20 19:09:43 +00:00
|
|
|
|
net->m_RatsnestStartIdx = m_Pcb->GetRatsnestsCount();
|
2008-03-22 18:08:44 +00:00
|
|
|
|
|
2009-06-23 15:45:53 +00:00
|
|
|
|
// Search for the last subratsnest already in use
|
|
|
|
|
int num_block = 0;
|
2009-05-24 18:28:36 +00:00
|
|
|
|
for( unsigned ii = 0; ii < net->m_ListPad.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
pad = net->m_ListPad[ii];
|
2008-11-18 18:13:55 +00:00
|
|
|
|
if( num_block < pad->GetSubRatsnest() )
|
|
|
|
|
num_block = pad->GetSubRatsnest();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/* Compute the ratsnest relative to the current net */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/* a - first pass : create the blocks from not already in block pads */
|
2009-06-23 15:45:53 +00:00
|
|
|
|
int icnt = gen_rats_pad_to_pad( m_Pcb->m_FullRatsnest,
|
|
|
|
|
net->m_ListPad,
|
|
|
|
|
0,
|
|
|
|
|
net->m_ListPad.size(),
|
|
|
|
|
num_block );
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* b - blocks connection (Iteration) */
|
2009-05-24 18:28:36 +00:00
|
|
|
|
while( icnt > 1 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
icnt = gen_rats_block_to_block( m_Pcb->m_FullRatsnest, net->m_ListPad, 0,
|
|
|
|
|
net->m_ListPad.size() );
|
|
|
|
|
net = m_Pcb->FindNet( current_net_code );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-20 19:09:43 +00:00
|
|
|
|
net->m_RatsnestEndIdx = m_Pcb->GetRatsnestsCount();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/* sort by lenght */
|
2009-06-23 15:45:53 +00:00
|
|
|
|
net = m_Pcb->FindNet( current_net_code );
|
2009-06-20 19:09:43 +00:00
|
|
|
|
if( (net->m_RatsnestEndIdx - net->m_RatsnestStartIdx) > 1 )
|
2009-05-28 08:42:24 +00:00
|
|
|
|
{
|
|
|
|
|
RATSNEST_ITEM* rats = &m_Pcb->m_FullRatsnest[0];
|
2009-06-20 19:09:43 +00:00
|
|
|
|
qsort( rats + net->m_RatsnestStartIdx,
|
|
|
|
|
net->m_RatsnestEndIdx - net->m_RatsnestStartIdx,
|
2009-05-28 08:42:24 +00:00
|
|
|
|
sizeof(RATSNEST_ITEM), sort_by_length );
|
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_Pcb->m_NbNoconnect = 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
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
// erase the ratsnest displayed on screen if needed
|
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
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( !g_Show_Ratsnest ) // Clear VISIBLE flag
|
|
|
|
|
m_Pcb->m_FullRatsnest[ii].m_Status &= ~CH_VISIBLE;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
if( DC )
|
2009-05-28 08:42:24 +00:00
|
|
|
|
m_Pcb->m_FullRatsnest[ii].Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
void WinEDA_BasePcbFrame::DrawGeneralRatsnest( wxDC* DC, int net_code )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*********************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* Displays the general ratsnest
|
|
|
|
|
* Only ratsnets with the status bit CH_VISIBLE is set are displayed
|
|
|
|
|
* @param netcode if > 0, Display only the ratsnest relative to the correponding net_code
|
2007-08-23 04:28:46 +00:00
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
return;
|
|
|
|
|
if( (m_Pcb->m_Status_Pcb & DO_NOT_SHOW_GENERAL_RASTNEST) )
|
|
|
|
|
return;
|
|
|
|
|
if( DC == NULL )
|
|
|
|
|
return;
|
|
|
|
|
|
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
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
if( ( m_Pcb->m_FullRatsnest[ii].m_Status & (CH_VISIBLE | CH_ACTIF) ) !=
|
|
|
|
|
(CH_VISIBLE | CH_ACTIF) )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( (net_code <= 0) || ( net_code == m_Pcb->m_FullRatsnest[ii].GetNet() ) )
|
|
|
|
|
m_Pcb->m_FullRatsnest[ii].Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/**********************************************************************************************/
|
2009-05-28 08:42:24 +00:00
|
|
|
|
static int tst_rats_block_to_block( NETINFO_ITEM* net, vector<RATSNEST_ITEM>& aRatsnestBuffer )
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/**********************************************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* Function used by Tst_Ratsnest()
|
|
|
|
|
* Function like gen_rats_block_to_block(..)
|
|
|
|
|
* Function testing the ratsnest between 2 blocks ( same net )
|
|
|
|
|
* The search is made between pads in block 1 and the others blocks
|
|
|
|
|
* The block n ( n > 1 ) is merged with block 1 by the smallest ratsnest
|
2009-06-23 15:45:53 +00:00
|
|
|
|
* Difference between gen_rats_block_to_block(..):
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* The analysis is not made pads to pads but uses the general ratsnest list.
|
|
|
|
|
* The function activate the smallest ratsnest between block 1 and the block n
|
|
|
|
|
* (activate a logical connexion)
|
|
|
|
|
*
|
2009-05-24 18:28:36 +00:00
|
|
|
|
* @param net = the current NETINFO_ITEM for the current net
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* output:
|
|
|
|
|
* .state member of the ratsnests
|
|
|
|
|
* @return blocks not connected count
|
2007-06-05 12:10:51 +00:00
|
|
|
|
*/
|
|
|
|
|
{
|
2009-05-25 11:53:55 +00:00
|
|
|
|
int current_num_block, min_block;
|
2009-05-28 08:42:24 +00:00
|
|
|
|
RATSNEST_ITEM* rats, * min_rats;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/* Search a link from a block to an other block */
|
2009-05-28 08:42:24 +00:00
|
|
|
|
min_rats = NULL;
|
2009-06-20 19:09:43 +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
|
|
|
|
rats = &aRatsnestBuffer[ii];
|
|
|
|
|
if( rats->m_PadStart->GetSubRatsnest() == rats->m_PadEnd->GetSubRatsnest() ) // Same block
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( min_rats == NULL )
|
|
|
|
|
min_rats = rats;
|
|
|
|
|
else if( min_rats->m_Lenght > rats->m_Lenght )
|
|
|
|
|
min_rats = rats;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( min_rats == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
return 1;
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* At this point we have found a link between 2 differents blocks (clusters) :
|
|
|
|
|
* we must set its status to ACTIVE and merge the 2 blocks
|
|
|
|
|
*/
|
2009-05-28 08:42:24 +00:00
|
|
|
|
min_rats->m_Status |= CH_ACTIF;
|
|
|
|
|
current_num_block = min_rats->m_PadStart->GetSubRatsnest();
|
|
|
|
|
min_block = min_rats->m_PadEnd->GetSubRatsnest();
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
if( min_block > current_num_block )
|
|
|
|
|
EXCHG( min_block, current_num_block );
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* Merging the 2 blocks in one cluster */
|
2009-05-24 18:28:36 +00:00
|
|
|
|
for( unsigned ii = 0; ii < net->m_ListPad.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
if( net->m_ListPad[ii]->GetSubRatsnest() == current_num_block )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
net->m_ListPad[ii]->SetSubRatsnest( min_block );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return current_num_block;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*********************************************************************/
|
2009-05-28 08:42:24 +00:00
|
|
|
|
static int tst_rats_pad_to_pad( int current_num_block,
|
2009-05-24 18:28:36 +00:00
|
|
|
|
RATSNEST_ITEM* start_rat_list, RATSNEST_ITEM* end_rat_list )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/**********************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* Function used by Tst_Ratsnest_general()
|
|
|
|
|
* The general ratsnest list must exists
|
|
|
|
|
* Activates the ratsnest between 2 pads ( supposes du meme net )
|
|
|
|
|
* The function links 1 pad not already connected an other pad and activate
|
|
|
|
|
* some blocks linked by a ratsnest
|
|
|
|
|
* Its test only the existing ratsnest and activate some ratsnest (status bit CH_ACTIF set)
|
|
|
|
|
*
|
|
|
|
|
* @param start_rat_list = starting address for the ratnest list
|
|
|
|
|
* @param end_rat_list = ending address for the ratnest list
|
|
|
|
|
* @param current_num_block = last block number (computed from the track analysis)
|
|
|
|
|
*
|
|
|
|
|
* output:
|
|
|
|
|
* ratsnest list (status member set)
|
2008-11-18 18:13:55 +00:00
|
|
|
|
* and pad list (m_SubRatsnest set)
|
2007-10-13 12:17:17 +00:00
|
|
|
|
*
|
|
|
|
|
* @return new block number
|
2007-08-23 04:28:46 +00:00
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-05-25 11:53:55 +00:00
|
|
|
|
D_PAD* pad_start, * pad_end;
|
2009-05-24 18:28:36 +00:00
|
|
|
|
RATSNEST_ITEM* chevelu;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
|
|
for( chevelu = start_rat_list; chevelu < end_rat_list; chevelu++ )
|
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
pad_start = chevelu->m_PadStart;
|
|
|
|
|
pad_end = chevelu->m_PadEnd;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* Update the block if the 2 pads are not connected : a new block is created
|
|
|
|
|
*/
|
2008-11-18 18:13:55 +00:00
|
|
|
|
if( (pad_start->GetSubRatsnest() == 0) && (pad_end->GetSubRatsnest() == 0) )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
|
|
|
|
current_num_block++;
|
2009-05-24 18:28:36 +00:00
|
|
|
|
pad_start->SetSubRatsnest( current_num_block );
|
|
|
|
|
pad_end->SetSubRatsnest( current_num_block );
|
|
|
|
|
chevelu->m_Status |= CH_ACTIF;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* If a pad is already connected : the other is merged in the current block */
|
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() );
|
2009-05-24 18:28:36 +00:00
|
|
|
|
chevelu->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() );
|
2009-05-24 18:28:36 +00:00
|
|
|
|
chevelu->m_Status |= CH_ACTIF;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return current_num_block;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
void WinEDA_BasePcbFrame::Tst_Ratsnest( wxDC* DC, int ref_netcode )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*******************************************************************/
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* Compute the active ratsnest
|
|
|
|
|
* The general ratsnest list must exists
|
|
|
|
|
* Compute the ACTIVE ratsnests in the general ratsnest list
|
2009-05-24 18:28:36 +00:00
|
|
|
|
* if ref_netcode == 0, test all nets, else test only ref_netcode
|
2007-08-23 04:28:46 +00:00
|
|
|
|
*/
|
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
|
|
|
|
|
2009-06-06 18:08:49 +00:00
|
|
|
|
if( m_Pcb->GetPadsCount() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
return;
|
2009-05-25 11:53:55 +00:00
|
|
|
|
if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
|
2009-05-24 18:28:36 +00:00
|
|
|
|
Build_Board_Ratsnest( DC );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-06-06 18:08:49 +00:00
|
|
|
|
for( int net_code = 1; net_code < (int) m_Pcb->m_NetInfo->GetNetsCount(); net_code++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
net = m_Pcb->FindNet( net_code );
|
2009-06-23 15:45:53 +00:00
|
|
|
|
if( net == NULL ) //Should not occur
|
2009-05-28 08:42:24 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
DisplayError( this, wxT( "Tst_Ratsnest() error: net not found" ) );
|
2009-05-28 08:42:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
if( ref_netcode && (net_code != ref_netcode) )
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
int num_block = 0;
|
|
|
|
|
for( unsigned ip = 0; ip < net->m_ListPad.size(); ip++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-05-24 18:28:36 +00:00
|
|
|
|
pad = net->m_ListPad[ip];
|
|
|
|
|
int subnet = pad->GetSubNet();
|
|
|
|
|
pad->SetSubRatsnest( subnet );
|
|
|
|
|
num_block = MAX( num_block, subnet );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-20 19:09:43 +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
|
|
|
|
}
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* a - tst connection between pads */
|
2009-05-28 08:42:24 +00:00
|
|
|
|
rats = &m_Pcb->m_FullRatsnest[0];
|
2009-06-23 15:45:53 +00:00
|
|
|
|
int icnt = tst_rats_pad_to_pad( num_block,
|
|
|
|
|
rats + net->m_RatsnestStartIdx,
|
|
|
|
|
rats + net->m_RatsnestEndIdx );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* b - test connexion between blocks (Iteration) */
|
2009-05-28 08:42:24 +00:00
|
|
|
|
while( icnt > 1 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
|
icnt = tst_rats_block_to_block( 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
|
|
|
|
|
|
|
|
|
m_Pcb->m_NbNoconnect = 0;
|
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
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( m_Pcb->m_FullRatsnest[ii].m_Status & CH_ACTIF )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
m_Pcb->m_NbNoconnect++;
|
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/**************************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
int WinEDA_BasePcbFrame::Test_1_Net_Ratsnest( wxDC* DC, int ref_netcode )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/**************************************************************************/
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-25 16:07:33 +00:00
|
|
|
|
/** function Test_1_Net_Ratsnest
|
2007-10-13 12:17:17 +00:00
|
|
|
|
* Compute the rastnest relative to the net "net_code"
|
|
|
|
|
* @param ref_netcode = netcode used to compute the rastnest.
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
|
DisplayRastnestInProgress = FALSE;
|
|
|
|
|
DrawGeneralRatsnest( DC, ref_netcode );
|
|
|
|
|
Tst_Ratsnest( DC, ref_netcode );
|
|
|
|
|
DrawGeneralRatsnest( DC, ref_netcode );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
return m_Pcb->GetRatsnestsCount();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*****************************************************************************/
|
2009-05-28 08:42:24 +00:00
|
|
|
|
void WinEDA_BasePcbFrame::build_ratsnest_module( wxDC* DC, MODULE* Module )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*****************************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/**
|
|
|
|
|
* Build a rastenest relative to one footprint. This is a simplified computation
|
|
|
|
|
* used only in move footprint. It is not optimal, but it is fast and sufficient
|
|
|
|
|
* to guide a footprint placement
|
|
|
|
|
* It shows the connections from a pad to the nearest conected pad
|
|
|
|
|
* @param Module = module to consider.
|
|
|
|
|
*
|
|
|
|
|
* The ratsnest has 2 sections:
|
|
|
|
|
* - An "internal" ratsnet relative to pads of this footprint which are in the same net.
|
|
|
|
|
* this ratsnest section is computed once.
|
|
|
|
|
* - An "external" rastnest connecting a pad of this footprint to an other pad (in an other footprint)
|
|
|
|
|
* The ratsnest section must be computed for each new position
|
2007-08-23 04:28:46 +00:00
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
static unsigned pads_module_count; // node count (node = pad with a net code) for the footprint beeing moved
|
|
|
|
|
static unsigned internalRatsCount; // number of internal links (links between pads of the module)
|
2009-05-28 08:42:24 +00:00
|
|
|
|
D_PAD** baseListePad;
|
|
|
|
|
D_PAD* pad_ref;
|
|
|
|
|
D_PAD* pad_externe;
|
|
|
|
|
int current_net_code;
|
2009-06-23 15:45:53 +00:00
|
|
|
|
int distance; // variables de calcul de ratsnest
|
2009-05-28 08:42:24 +00:00
|
|
|
|
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;
|
2009-06-11 14:26:17 +00:00
|
|
|
|
GetBoard()->m_NetInfo->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-05-24 18:28:36 +00:00
|
|
|
|
* and the list of external pads to consider, i.e pads in others footprints which are "connected" to
|
|
|
|
|
* a pad in the current footprint
|
|
|
|
|
*/
|
|
|
|
|
if( (m_Pcb->m_Status_Pcb & RATSNEST_ITEM_LOCAL_OK) != 0 )
|
2009-05-28 08:42:24 +00:00
|
|
|
|
goto CalculateExternalRatsnest;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/* Compute the "internal" ratsnest, i.e the links between the curent footprint pads */
|
2009-05-28 08:42:24 +00:00
|
|
|
|
s_localPadBuffer.clear();
|
|
|
|
|
m_Pcb->m_LocalRatsnest.clear();
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
for( pad_ref = Module->m_Pads; pad_ref != NULL; pad_ref = pad_ref->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
|
if( pad_ref->GetNet() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
s_localPadBuffer.push_back( pad_ref );
|
2008-11-18 18:13:55 +00:00
|
|
|
|
pad_ref->SetSubRatsnest( 0 );
|
|
|
|
|
pad_ref->SetSubNet( 0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
pads_module_count = s_localPadBuffer.size();
|
|
|
|
|
if( pads_module_count == 0 )
|
|
|
|
|
return; /* no connection! */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
qsort( &s_localPadBuffer[0], pads_module_count, sizeof(D_PAD*), sortByNetcode );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/* Build the list of pads linked to the current footprint pads */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
DisplayRastnestInProgress = FALSE;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2007-10-11 00:11:59 +00:00
|
|
|
|
current_net_code = 0;
|
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
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
|
pad_ref = s_localPadBuffer[ii];
|
2007-10-13 06:18:44 +00:00
|
|
|
|
if( pad_ref->GetNet() == current_net_code )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
2008-03-22 18:08:44 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
// A new net was found, load all pads of others modules members of this net:
|
|
|
|
|
NETINFO_ITEM* net = m_Pcb->FindNet( pad_ref->GetNet() );
|
2009-06-23 15:45:53 +00:00
|
|
|
|
if( net == NULL ) //Should not occur
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
DisplayError( this, wxT( "build_ratsnest_module() error: net not found" ) );
|
2009-05-28 08:42:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
for( unsigned jj = 0; jj < net->m_ListPad.size(); jj++ )
|
|
|
|
|
{
|
|
|
|
|
pad_externe = net->m_ListPad[jj];
|
2008-11-24 06:53:43 +00:00
|
|
|
|
if( pad_externe->GetParent() == Module )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
pad_externe->SetSubRatsnest( 0 );
|
2008-11-18 18:13:55 +00:00
|
|
|
|
pad_externe->SetSubNet( 0 );
|
2008-03-22 18:08:44 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
s_localPadBuffer.push_back( pad_externe );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* Sort the pad list by net_code */
|
2009-05-28 08:42:24 +00:00
|
|
|
|
baseListePad = &s_localPadBuffer[0];
|
|
|
|
|
qsort( baseListePad + pads_module_count,
|
|
|
|
|
s_localPadBuffer.size() - pads_module_count,
|
|
|
|
|
sizeof(D_PAD*), sortByNetcode );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
|
/* Compute the internal rats nest:
|
2008-10-29 15:26:53 +00:00
|
|
|
|
* this is the same as general ratsnest, but considers only the current footprint pads
|
2008-11-24 06:53:43 +00:00
|
|
|
|
* it is therefore not time consuming, and it is made only once
|
2009-05-24 18:28:36 +00:00
|
|
|
|
*/
|
2009-05-28 08:42:24 +00:00
|
|
|
|
current_net_code = s_localPadBuffer[0]->GetNet();
|
2007-08-23 04:28:46 +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
|
|
|
|
{
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* Search the end of pad list relative to the current net */
|
2009-05-28 08:42:24 +00:00
|
|
|
|
unsigned jj = ii + 1;
|
|
|
|
|
for( ; jj <= pads_module_count; jj++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( jj >= pads_module_count )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
break;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( s_localPadBuffer[jj]->GetNet() != current_net_code )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* End of list found: */
|
|
|
|
|
/* a - first step of lee algorithm : build the pad to pad link list */
|
2009-06-23 15:45:53 +00:00
|
|
|
|
int icnt = gen_rats_pad_to_pad( m_Pcb->m_LocalRatsnest, s_localPadBuffer, ii, jj, 0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/* b - second step of lee algorithm : build the block to block link list (Iteration) */
|
2009-05-28 08:42:24 +00:00
|
|
|
|
while( icnt > 1 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
icnt = gen_rats_block_to_block( m_Pcb->m_LocalRatsnest, s_localPadBuffer, ii, jj );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
ii = jj;
|
|
|
|
|
if( ii < s_localPadBuffer.size() )
|
|
|
|
|
current_net_code = s_localPadBuffer[ii]->GetNet();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
internalRatsCount = m_Pcb->m_LocalRatsnest.size();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
/* set the ratsnets status, flag LOCAL_RATSNEST_ITEM */
|
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
|
|
|
|
m_Pcb->m_LocalRatsnest[ii].m_Status = LOCAL_RATSNEST_ITEM;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
m_Pcb->m_Status_Pcb |= RATSNEST_ITEM_LOCAL_OK;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/*
|
2009-05-24 18:28:36 +00:00
|
|
|
|
* This section computes the "external" ratsnest: must be done when the footprint position changes
|
|
|
|
|
*/
|
2009-05-28 08:42:24 +00:00
|
|
|
|
CalculateExternalRatsnest:
|
2009-06-23 15:45:53 +00:00
|
|
|
|
|
2007-10-13 12:17:17 +00:00
|
|
|
|
/* This section search:
|
|
|
|
|
* for each current module pad the nearest neighbour 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;
|
|
|
|
|
local_rats.m_Lenght = 0x7FFFFFFF;
|
|
|
|
|
local_rats.m_Status = 0;
|
|
|
|
|
bool addRats = false;
|
|
|
|
|
if( internalRatsCount < m_Pcb->m_LocalRatsnest.size() )
|
|
|
|
|
m_Pcb->m_LocalRatsnest.erase( m_Pcb->m_LocalRatsnest.begin() + internalRatsCount,
|
|
|
|
|
m_Pcb->m_LocalRatsnest.end() );
|
|
|
|
|
|
2009-06-23 15:45:53 +00:00
|
|
|
|
current_net_code = s_localPadBuffer[0]->GetNet();
|
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
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
|
pad_ref = s_localPadBuffer[ii];
|
2007-10-13 06:18:44 +00:00
|
|
|
|
if( pad_ref->GetNet() != current_net_code )
|
2007-10-13 12:17:17 +00:00
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
|
/* if needed, creates a new ratsnest for the old net */
|
|
|
|
|
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
|
|
|
|
}
|
2009-05-28 08:42:24 +00:00
|
|
|
|
addRats = false;
|
|
|
|
|
current_net_code = pad_ref->GetNet();
|
|
|
|
|
local_rats.m_Lenght = 0x7FFFFFFF;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
pad_pos = pad_ref->m_Pos - 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
|
|
|
|
|
for( unsigned jj = pads_module_count; jj < s_localPadBuffer.size(); jj++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
|
pad_externe = s_localPadBuffer[jj];
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
/* we search pads having the same net code */
|
2007-10-13 06:18:44 +00:00
|
|
|
|
if( pad_externe->GetNet() < pad_ref->GetNet() )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
|
|
|
|
if( pad_externe->GetNet() > pad_ref->GetNet() ) // remember pads are sorted by net code
|
2007-08-23 04:28:46 +00:00
|
|
|
|
break;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
distance = abs( pad_externe->m_Pos.x - pad_pos.x ) +
|
|
|
|
|
abs( pad_externe->m_Pos.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;
|
|
|
|
|
local_rats.SetNet( pad_ref->GetNet() );
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
void WinEDA_BasePcbFrame::trace_ratsnest_module( wxDC* DC )
|
2007-06-05 12:10:51 +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
|
|
|
|
* Display the rastnest of a moving footprint, computed by build_ratsnest_module()
|
2007-08-23 04:28:46 +00:00
|
|
|
|
*/
|
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;
|
2009-05-24 18:28:36 +00:00
|
|
|
|
if( (m_Pcb->m_Status_Pcb & RATSNEST_ITEM_LOCAL_OK) == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2009-05-25 14:14:54 +00:00
|
|
|
|
int tmpcolor = g_DesignSettings.m_RatsnestColor;
|
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];
|
|
|
|
|
if( rats->m_Status & LOCAL_RATSNEST_ITEM )
|
2009-05-25 14:14:54 +00:00
|
|
|
|
{
|
|
|
|
|
g_DesignSettings.m_RatsnestColor = YELLOW;
|
2009-05-28 08:42:24 +00:00
|
|
|
|
rats->Draw( DrawPanel, DC, GR_XOR, g_Offset_Module );
|
2009-05-25 14:14:54 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_DesignSettings.m_RatsnestColor = tmpcolor;
|
2009-05-28 08:42:24 +00:00
|
|
|
|
wxPoint tmp = rats->m_PadStart->m_Pos;
|
|
|
|
|
rats->m_PadStart->m_Pos -= g_Offset_Module;
|
|
|
|
|
rats->Draw( DrawPanel, DC, GR_XOR, wxPoint( 0, 0 ) );
|
|
|
|
|
rats->m_PadStart->m_Pos = 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
|
|
|
|
|
2009-05-25 14:14:54 +00:00
|
|
|
|
g_DesignSettings.m_RatsnestColor = tmpcolor;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
|
/*
|
2007-08-23 04:28:46 +00:00
|
|
|
|
* construction de la liste en mode de calcul rapide pour affichage
|
|
|
|
|
* en temps reel du chevelu d'un pad lors des trac<EFBFBD>s d'une piste d<EFBFBD>marrant
|
|
|
|
|
* sur ce pad.
|
2007-10-13 12:17:17 +00:00
|
|
|
|
*
|
2007-08-23 04:28:46 +00:00
|
|
|
|
* parametres d'appel:
|
|
|
|
|
* pad_ref ( si null : mise a 0 du nombre de chevelus )
|
|
|
|
|
* ox, oy = coord de l'extremite de la piste en trace
|
|
|
|
|
* init (flag)
|
|
|
|
|
* = 0 : mise a jour des chevelu
|
|
|
|
|
* <> 0: creation de la liste
|
|
|
|
|
*/
|
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
|
|
|
|
|
* and when the mouse is moved, the g_MaxLinksShowed links to neightbors are drawn
|
|
|
|
|
*/
|
|
|
|
|
static std::vector <wxPoint> s_RatsnestMouseToPads;
|
|
|
|
|
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
|
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
|
/* Used by build_ratsnest_pad(): sort function by link lenght (manhattan distance)*/
|
|
|
|
|
static bool sort_by_localnetlength( const wxPoint& ref, const wxPoint& compare )
|
|
|
|
|
{
|
|
|
|
|
wxPoint deltaref = ref - s_CursorPos;
|
|
|
|
|
wxPoint deltacmp = compare - s_CursorPos;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
|
// = distance between ref coordinate and pad ref
|
|
|
|
|
int lengthref = abs( deltaref.x ) + abs( deltaref.y );
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
|
// distance between ref coordinate and the other pad
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/****************************************************************************************/
|
2009-05-25 11:53:55 +00:00
|
|
|
|
void WinEDA_BasePcbFrame::build_ratsnest_pad( BOARD_ITEM* ref,
|
2007-08-23 04:28:46 +00:00
|
|
|
|
const wxPoint& refpos, bool init )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/****************************************************************************************/
|
|
|
|
|
{
|
2009-05-28 08:42:24 +00:00
|
|
|
|
int current_net_code = 0, conn_number = 0;
|
|
|
|
|
D_PAD* pad_ref = NULL;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-24 18:28:36 +00:00
|
|
|
|
if( ( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 )
|
2009-05-28 08:42:24 +00:00
|
|
|
|
|| ( (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
|
|
|
|
{
|
2009-05-25 11:53:55 +00:00
|
|
|
|
s_RatsnestMouseToPads.clear();
|
|
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-05-25 11:53:55 +00:00
|
|
|
|
s_CursorPos = refpos;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
if( init )
|
|
|
|
|
{
|
2009-05-25 11:53:55 +00:00
|
|
|
|
s_RatsnestMouseToPads.clear();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
if( ref == NULL )
|
2009-05-25 11:53:55 +00:00
|
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
|
switch( ref->Type() )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
|
case TYPE_PAD:
|
2007-08-23 04:28:46 +00:00
|
|
|
|
pad_ref = (D_PAD*) ref;
|
2007-10-13 06:18:44 +00:00
|
|
|
|
current_net_code = pad_ref->GetNet();
|
2008-11-18 18:13:55 +00:00
|
|
|
|
conn_number = pad_ref->GetSubNet();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
|
case TYPE_TRACK:
|
|
|
|
|
case TYPE_VIA:
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
|
|
|
|
TRACK* track_ref = (TRACK*) ref;
|
2007-10-13 06:18:44 +00:00
|
|
|
|
current_net_code = track_ref->GetNet();
|
|
|
|
|
conn_number = track_ref->GetSubNet();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( current_net_code <= 0 )
|
2009-05-25 11:53:55 +00:00
|
|
|
|
return;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
NETINFO_ITEM* net = m_Pcb->FindNet( current_net_code );
|
2009-06-23 15:45:53 +00:00
|
|
|
|
if( net == NULL ) //Should not occur
|
2009-05-28 08:42:24 +00:00
|
|
|
|
{
|
2009-06-23 15:45:53 +00:00
|
|
|
|
DisplayError( this, wxT( "build_ratsnest_pad() 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-05-25 11:53:55 +00:00
|
|
|
|
// Create a list of pads candidates ( pads not already connected to the current track:
|
|
|
|
|
for( unsigned ii = 0; ii < net->m_ListPad.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
2009-05-25 11:53:55 +00:00
|
|
|
|
D_PAD* pad = net->m_ListPad[ii];
|
2007-08-23 04:28:46 +00:00
|
|
|
|
if( pad == pad_ref )
|
|
|
|
|
continue;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
|
if( !pad->GetSubNet() || (pad->GetSubNet() != conn_number) )
|
2009-05-25 11:53:55 +00:00
|
|
|
|
s_RatsnestMouseToPads.push_back( pad->m_Pos );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
2007-10-13 12:17:17 +00:00
|
|
|
|
} /* end if Init */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( s_RatsnestMouseToPads.size() > 1 )
|
2009-05-25 11:53:55 +00:00
|
|
|
|
sort( s_RatsnestMouseToPads.begin(), s_RatsnestMouseToPads.end(), sort_by_localnetlength );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/*******************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
void WinEDA_BasePcbFrame::trace_ratsnest_pad( wxDC* DC )
|
2007-06-05 12:10:51 +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
|
|
|
|
* Displays a "ratsnest" during track creation
|
2007-08-23 04:28:46 +00:00
|
|
|
|
*/
|
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;
|
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
|
if( s_RatsnestMouseToPads.size() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2009-05-25 16:07:33 +00:00
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
GRSetDrawMode( DC, GR_XOR );
|
2009-05-28 08:42:24 +00:00
|
|
|
|
for( int ii = 0; ii < (int) s_RatsnestMouseToPads.size(); ii++ )
|
2007-08-23 04:28:46 +00:00
|
|
|
|
{
|
|
|
|
|
if( ii >= g_MaxLinksShowed )
|
|
|
|
|
break;
|
2007-10-13 12:17:17 +00:00
|
|
|
|
|
2009-05-25 16:07:33 +00:00
|
|
|
|
GRLine( &DrawPanel->m_ClipBox, DC, s_CursorPos, s_RatsnestMouseToPads[ii], 0, YELLOW );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|