2007-11-27 17:42:15 +00:00
|
|
|
/***************************************************************************************/
|
|
|
|
/* Rastnest calculations: Function to handle existing tracks in rastsnest calculations */
|
|
|
|
/***************************************************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "autorout.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
//#include <algorithm>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
extern void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb );
|
|
|
|
extern void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode );
|
|
|
|
|
|
|
|
/* Local functions */
|
|
|
|
static void Propagate_SubNet( TRACK* pt_start_conn, TRACK* pt_end_conn );
|
|
|
|
static void Build_Pads_Info_Connections_By_Tracks( TRACK* pt_start_conn, TRACK* pt_end_conn );
|
2007-08-23 04:28:46 +00:00
|
|
|
static void RebuildTrackChain( BOARD* pcb );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/*..*/
|
|
|
|
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
/**************************************************************************************************/
|
|
|
|
static int Merge_Two_SubNets( TRACK* pt_start_conn, TRACK* pt_end_conn, int old_val, int new_val )
|
|
|
|
/**************************************************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
/** Function Merge_Two_SubNets()
|
|
|
|
* Used by Propagate_SubNet()
|
2007-11-27 17:42:15 +00:00
|
|
|
* Change a subnet value to a new value, for tracks ans pads which are connected to corresponding track
|
2008-11-18 18:13:55 +00:00
|
|
|
* for pads and tracks, this is the .m_Subnet member that is tested and modified
|
2007-11-27 17:42:15 +00:00
|
|
|
* these members are block numbers (or cluster numbers) for a given net
|
2008-11-18 18:13:55 +00:00
|
|
|
* The result is merging 2 blocks (or subnets)
|
2007-11-27 17:42:15 +00:00
|
|
|
* @return modification count
|
|
|
|
* @param old_val = subnet value to modify
|
|
|
|
* @param new_val = new subnet value for each item whith have old_val as subnet value
|
|
|
|
* @param pt_start_conn = first track segment to test
|
|
|
|
* @param pt_end_conn = last track segment to test
|
|
|
|
* If pt_end_conn = NULL: search is made from pt_start_conn to end of linked list
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
TRACK* pt_conn;
|
|
|
|
int nb_change = 0;
|
|
|
|
D_PAD* pt_pad;
|
|
|
|
|
|
|
|
if( old_val == new_val )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if( (old_val > 0) && (old_val < new_val) )
|
|
|
|
EXCHG( old_val, new_val );
|
|
|
|
|
|
|
|
pt_conn = pt_start_conn;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pt_conn != NULL; pt_conn = pt_conn->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
if( pt_conn->GetSubNet() != old_val )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
if( pt_conn == pt_end_conn )
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nb_change++;
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_conn->SetSubNet( new_val );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( pt_conn->start && ( pt_conn->start->Type() == TYPE_PAD) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
pt_pad = (D_PAD*) (pt_conn->start);
|
2008-11-18 18:13:55 +00:00
|
|
|
if( pt_pad->GetSubNet() == old_val )
|
2009-03-16 19:51:23 +00:00
|
|
|
pt_pad->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( pt_conn->end && (pt_conn->end->Type() == TYPE_PAD) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
pt_pad = (D_PAD*) (pt_conn->end);
|
2008-11-18 18:13:55 +00:00
|
|
|
if( pt_pad->GetSubNet() == old_val )
|
2009-03-16 19:51:23 +00:00
|
|
|
pt_pad->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
if( pt_conn == pt_end_conn )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nb_change;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************************************************/
|
2008-11-18 18:13:55 +00:00
|
|
|
static void Propagate_SubNet( TRACK* pt_start_conn, TRACK* pt_end_conn )
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
/** Function Propagate_SubNet
|
2007-11-27 17:42:15 +00:00
|
|
|
* Test a list of track segment, to create or propagate a sub netcode to pads and segments connected together
|
2008-11-18 18:13:55 +00:00
|
|
|
* the track list must be sorted by nets, and all segments from pt_start_conn to pt_end_conn have the same net
|
2007-11-27 17:42:15 +00:00
|
|
|
* When 2 items are connected (a track to a pad, or a track to an other track) they are grouped in a cluster.
|
|
|
|
* for pads, this is the .m_physical_connexion member which is a cluster identifier
|
2008-10-25 10:21:46 +00:00
|
|
|
* for tracks, this is the .m_Subnet member which is a cluster identifier
|
2007-11-27 17:42:15 +00:00
|
|
|
* For a given net, if all tracks are created, there is only one cluster.
|
2008-11-18 18:13:55 +00:00
|
|
|
* but if not all tracks are created, there are more than one cluster, and some ratsnets will be shown.
|
2007-11-27 17:42:15 +00:00
|
|
|
* @param pt_start_conn = first track to test
|
|
|
|
* @param pt_end_conn = last segment to test
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-10-17 14:35:59 +00:00
|
|
|
TRACK* pt_conn;
|
2008-11-18 18:13:55 +00:00
|
|
|
int sub_netcode;
|
2007-10-17 14:35:59 +00:00
|
|
|
D_PAD* pt_pad;
|
|
|
|
TRACK* pt_autre_piste;
|
|
|
|
BOARD_ITEM* PtStruct;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* Clear variables used in computations */
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_conn = pt_start_conn;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pt_conn != NULL; pt_conn = pt_conn->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_conn->SetSubNet( 0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
PtStruct = pt_conn->start;
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct && (PtStruct->Type() == TYPE_PAD) )
|
2009-03-16 19:51:23 +00:00
|
|
|
( (D_PAD*) PtStruct )->SetSubNet( 0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
PtStruct = pt_conn->end;
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct && (PtStruct->Type() == TYPE_PAD) )
|
2009-03-16 19:51:23 +00:00
|
|
|
( (D_PAD*) PtStruct )->SetSubNet( 0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( pt_conn == pt_end_conn )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
sub_netcode = 1;
|
|
|
|
pt_start_conn->SetSubNet( sub_netcode );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
/* Start of calculation */
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_conn = pt_start_conn;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pt_conn != NULL; pt_conn = pt_conn->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-11-27 17:42:15 +00:00
|
|
|
/* First: handling connections to pads */
|
2007-08-23 04:28:46 +00:00
|
|
|
PtStruct = pt_conn->start;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
/* The segment starts on a pad */
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct && (PtStruct->Type() == TYPE_PAD) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
pt_pad = (D_PAD*) PtStruct;
|
2007-11-27 17:42:15 +00:00
|
|
|
if( pt_conn->GetSubNet() ) /* the track segment is already a cluster member */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-03-16 19:51:23 +00:00
|
|
|
if( pt_pad->GetSubNet() > 0 ) /* The pad is already a cluster member, so we can merge the 2 clusters */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
Merge_Two_SubNets( pt_start_conn, pt_end_conn,
|
2009-03-16 19:51:23 +00:00
|
|
|
pt_pad->GetSubNet(), pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-11-27 17:42:15 +00:00
|
|
|
else /* The pad is not yet attached to a cluster , so we can add this pad to the cluster */
|
2008-11-18 18:13:55 +00:00
|
|
|
pt_pad->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-11-27 17:42:15 +00:00
|
|
|
else /* the track segment is not attached to a cluster */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-03-16 19:51:23 +00:00
|
|
|
if( pt_pad->GetSubNet() > 0 ) /* it is connected to a pad in a cluster, merge this track */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
pt_conn->SetSubNet( pt_pad->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-11-27 17:42:15 +00:00
|
|
|
else /* it is connected to a pad not in a cluster, so we must create a new cluster (only with the 2 items: the track and the pad) */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
sub_netcode++;
|
|
|
|
pt_conn->SetSubNet( sub_netcode );
|
|
|
|
pt_pad->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PtStruct = pt_conn->end;
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct && (PtStruct->Type() == TYPE_PAD) )
|
2007-11-27 17:42:15 +00:00
|
|
|
/* The segment end on a pad */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
pt_pad = (D_PAD*) PtStruct;
|
2007-10-13 06:18:44 +00:00
|
|
|
if( pt_conn->GetSubNet() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
if( pt_pad->GetSubNet() > 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
Merge_Two_SubNets( pt_start_conn, pt_end_conn,
|
2009-03-16 19:51:23 +00:00
|
|
|
pt_pad->GetSubNet(), pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
2008-11-18 18:13:55 +00:00
|
|
|
pt_pad->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
if( pt_pad->GetSubNet() > 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
pt_conn->SetSubNet( pt_pad->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
sub_netcode++;
|
|
|
|
pt_conn->SetSubNet( sub_netcode );
|
|
|
|
pt_pad->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
/* Test connections between segments */
|
2007-08-23 04:28:46 +00:00
|
|
|
PtStruct = pt_conn->start;
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct && (PtStruct->Type() != TYPE_PAD) )
|
2007-10-17 14:35:59 +00:00
|
|
|
{
|
2007-11-27 17:42:15 +00:00
|
|
|
/* The segment starts on an other track */
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_autre_piste = (TRACK*) PtStruct;
|
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
if( pt_conn->GetSubNet() ) /* the track segment is already a cluster member */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-11-27 17:42:15 +00:00
|
|
|
if( pt_autre_piste->GetSubNet() ) /* The other track is already a cluster member, so we can merge the 2 clusters */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
Merge_Two_SubNets( pt_start_conn, pt_end_conn,
|
2009-03-16 19:51:23 +00:00
|
|
|
pt_autre_piste->GetSubNet(), pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-11-27 17:42:15 +00:00
|
|
|
else /* The other track is not yet attached to a cluster , so we can add this other track to the cluster */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_autre_piste->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-27 17:42:15 +00:00
|
|
|
else /* the track segment is not yet attached to a cluster */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-11-27 17:42:15 +00:00
|
|
|
if( pt_autre_piste->GetSubNet() ) /* The other track is already a cluster member, so we can add the segment to the cluster */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_conn->SetSubNet( pt_autre_piste->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-11-27 17:42:15 +00:00
|
|
|
else /* it is connected to an other segment not in a cluster, so we must create a new cluster (only with the 2 track segments) */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
sub_netcode++;
|
|
|
|
pt_conn->SetSubNet( sub_netcode );
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_autre_piste->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
PtStruct = pt_conn->end; // Do the same calculations for the segment end point
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct && (PtStruct->Type() != TYPE_PAD) )
|
2007-10-17 14:35:59 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_autre_piste = (TRACK*) PtStruct;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
if( pt_conn->GetSubNet() ) /* the track segment is already a cluster member */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
if( pt_autre_piste->GetSubNet() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
Merge_Two_SubNets( pt_start_conn, pt_end_conn,
|
2009-03-16 19:51:23 +00:00
|
|
|
pt_autre_piste->GetSubNet(), pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_autre_piste->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-11-27 17:42:15 +00:00
|
|
|
else /* the track segment is not yet attached to a cluster */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
if( pt_autre_piste->GetSubNet() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_conn->SetSubNet( pt_autre_piste->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
sub_netcode++;
|
|
|
|
pt_conn->SetSubNet( sub_netcode );
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_autre_piste->SetSubNet( pt_conn->GetSubNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( pt_conn == pt_end_conn )
|
|
|
|
break;
|
|
|
|
}
|
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::test_connexions( wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
/** Function testing the connections relative to all nets
|
2008-10-29 15:26:53 +00:00
|
|
|
* This function update the status of the ratsnest ( flag CH_ACTIF = 0 if a connection is found, = 1 else)
|
2007-11-27 17:42:15 +00:00
|
|
|
* track segments are assumed to be sorted by net codes.
|
2008-10-29 15:26:53 +00:00
|
|
|
* This is the case because when a new track is added, it is inserted in the linked list according to its net code.
|
2007-11-27 17:42:15 +00:00
|
|
|
* and when nets are changed (when a new netlist is read) tracks are sorted before using this function
|
|
|
|
* @param DC = current Device Context
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
// Clear the cluster identifier for all pads
|
|
|
|
for( unsigned i = 0; i< m_Pcb->m_Pads.size(); ++i )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
D_PAD* pad = m_Pcb->m_Pads[i];
|
|
|
|
|
|
|
|
pad->SetZoneSubNet( 0 );
|
|
|
|
pad->SetSubNet( 0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
m_Pcb->Test_Connections_To_Copper_Areas();
|
2008-11-18 18:13:55 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
// Test existing connections net by net
|
|
|
|
for( TRACK* track = m_Pcb->m_Track; track; )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
// this is the current net because pt_start_conn is the first segment of the net
|
2009-03-16 19:51:23 +00:00
|
|
|
int current_net_code = track->GetNet();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
// this is the last segment of the current net
|
|
|
|
TRACK* pt_end_conn = track->GetEndNetCode( current_net_code );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
Build_Pads_Info_Connections_By_Tracks( track, pt_end_conn );
|
|
|
|
|
|
|
|
track = pt_end_conn->Next(); // this is now the first segment of the next net
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
Merge_SubNets_Connected_By_CopperAreas( m_Pcb );
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
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::test_1_net_connexion( wxDC* DC, int net_code )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
/** Function testing the connections relative to a given net
|
|
|
|
* track segments are assumed to be sorted by net codes
|
|
|
|
* @param DC = current Device Context
|
|
|
|
* @param net_code = net code to test
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-03-16 19:51:23 +00:00
|
|
|
wxString msg;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( net_code == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( (m_Pcb->m_Status_Pcb & LISTE_CHEVELU_OK) == 0 )
|
|
|
|
Compile_Ratsnest( DC, TRUE );
|
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
for( unsigned i = 0; i<m_Pcb->m_Pads.size(); ++i )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
D_PAD* pad = m_Pcb->m_Pads[i];
|
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
int pad_net_code = pad->GetNet();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( pad_net_code < net_code )
|
|
|
|
continue;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( pad_net_code > net_code )
|
|
|
|
break;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
pad->SetSubNet( 0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
m_Pcb->Test_Connections_To_Copper_Areas( net_code );
|
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
/* Search for the first and the last segment relative to the given net code */
|
2007-08-23 04:28:46 +00:00
|
|
|
if( m_Pcb->m_Track )
|
|
|
|
{
|
2009-03-16 19:51:23 +00:00
|
|
|
TRACK* pt_start_conn;
|
|
|
|
TRACK* pt_end_conn = NULL;
|
2008-12-04 04:28:11 +00:00
|
|
|
pt_start_conn = m_Pcb->m_Track.GetFirst()->GetStartNetCode( net_code );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( pt_start_conn )
|
|
|
|
pt_end_conn = pt_start_conn->GetEndNetCode( net_code );
|
|
|
|
|
|
|
|
if( pt_start_conn && pt_end_conn ) // c.a.d. s'il y a des segments
|
|
|
|
{
|
2008-11-18 18:13:55 +00:00
|
|
|
Build_Pads_Info_Connections_By_Tracks( pt_start_conn, pt_end_conn );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-18 18:13:55 +00:00
|
|
|
Merge_SubNets_Connected_By_CopperAreas( m_Pcb, net_code );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
/* Test the rastnest for this net */
|
2008-12-04 04:28:11 +00:00
|
|
|
int nb_net_noconnect = Test_1_Net_Ratsnest( DC, net_code );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
/* Display results */
|
2007-08-23 04:28:46 +00:00
|
|
|
msg.Printf( wxT( "links %d nc %d net:nc %d" ),
|
|
|
|
m_Pcb->m_NbLinks, m_Pcb->GetNumNoconnect(),
|
|
|
|
nb_net_noconnect );
|
|
|
|
|
|
|
|
Affiche_Message( msg );
|
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
/*******************************************************************************************/
|
|
|
|
static void Build_Pads_Info_Connections_By_Tracks( TRACK* pt_start_conn, TRACK* pt_end_conn )
|
|
|
|
/*******************************************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/** Used after a track change (delete a track ou add a track)
|
|
|
|
* Compute connections (initialize the .start and .end members) for a single net.
|
|
|
|
* tracks must be sorted by net, as usual
|
|
|
|
* @param pt_start_conn = first segment of the net
|
|
|
|
* @param pt_end_conn = last segment of the net
|
|
|
|
* Connections to pads are assumed to be already initialized.
|
|
|
|
* If a track is deleted, the other pointers to pads do not change.
|
|
|
|
* When a track is added, its pointers to pads are already initialized
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
TRACK* Track;
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* Reset the old connections type track to track */
|
2008-11-24 06:53:43 +00:00
|
|
|
for( Track = pt_start_conn; Track != NULL; Track = Track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
Track->SetSubNet( 0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( Track->GetState( BEGIN_ONPAD ) == 0 )
|
|
|
|
Track->start = NULL;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( Track->GetState( END_ONPAD ) == 0 )
|
|
|
|
Track->end = NULL;
|
|
|
|
|
|
|
|
if( Track == pt_end_conn )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* Update connections type track to track */
|
2008-11-24 06:53:43 +00:00
|
|
|
for( Track = pt_start_conn; Track != NULL; Track = Track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( Track->Type() == TYPE_VIA ) // A via can connect many tracks, we must search for all track segments in this net
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
TRACK* pt_segm;
|
|
|
|
int layermask = Track->ReturnMaskLayer();
|
2008-11-24 06:53:43 +00:00
|
|
|
for( pt_segm = pt_start_conn; pt_segm != NULL; pt_segm = pt_segm->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
int curlayermask = pt_segm->ReturnMaskLayer();
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( !pt_segm->start && (pt_segm->m_Start == Track->m_Start)
|
|
|
|
&& ( layermask & curlayermask ) )
|
|
|
|
{
|
|
|
|
pt_segm->start = Track;
|
|
|
|
}
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( !pt_segm->end && (pt_segm->m_End == Track->m_Start)
|
|
|
|
&& (layermask & curlayermask) )
|
|
|
|
{
|
|
|
|
pt_segm->end = Track;
|
|
|
|
}
|
|
|
|
if( pt_segm == pt_end_conn )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
if( Track->start == NULL ) // end track not already connected, search a connection
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-19 08:32:10 +00:00
|
|
|
Track->start = Locate_Piste_Connectee( Track, Track, pt_end_conn, START );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
if( Track->end == NULL ) // end track not already connected, search a connection
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-19 08:32:10 +00:00
|
|
|
Track->end = Locate_Piste_Connectee( Track, Track, pt_end_conn, END );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-03-05 15:58:06 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( Track == pt_end_conn )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-11-18 18:13:55 +00:00
|
|
|
/* Creates sub nets (cluster) for the current net: */
|
|
|
|
Propagate_SubNet( pt_start_conn, pt_end_conn );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define POS_AFF_CHREF 62
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
/**
|
|
|
|
* Function SuperFast_Locate_Pad_Connecte
|
|
|
|
* locates the pad connected to a track ended at coord px, py.
|
|
|
|
* A track is seen as connected if the px, py position is same as the pad position.
|
|
|
|
*
|
2008-10-29 15:26:53 +00:00
|
|
|
* @param aPcb = the board.
|
2007-11-27 17:42:15 +00:00
|
|
|
* @param pt_liste = Pointers to pads buffer
|
|
|
|
* This buffer is a list like the list created by build_liste_pad, but sorted by increasing X pad coordinate
|
2008-10-29 15:26:53 +00:00
|
|
|
* @param posref = reference coordinate
|
|
|
|
* @param masque_layer = Layers (bit to bit) to consider
|
2007-11-27 17:42:15 +00:00
|
|
|
* @return : pointer on the connected pad
|
|
|
|
* This function uses a fast search in this sorted pad list and it is faster than Fast_Locate_Pad_connecte(),
|
|
|
|
* But this sorted pad list must be built before calling this function.
|
2007-10-17 14:35:59 +00:00
|
|
|
*
|
2007-11-27 17:42:15 +00:00
|
|
|
* (Note: The usual pad list (created by build_liste_pad) m_Pcb->m_Pads is sorted by increasing netcodes )
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
static D_PAD* SuperFast_Locate_Pad_Connecte( BOARD* aPcb, LISTE_PAD* pt_liste,
|
|
|
|
const wxPoint& posref, int masque_layer )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
D_PAD* pad;
|
|
|
|
int ii;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
int nb_pad = aPcb->m_Pads.size();
|
|
|
|
LISTE_PAD* ptr_pad = pt_liste;
|
2009-03-16 19:51:23 +00:00
|
|
|
LISTE_PAD* lim = pt_liste + nb_pad - 1;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
ptr_pad = pt_liste;
|
|
|
|
while( nb_pad )
|
|
|
|
{
|
|
|
|
pad = *ptr_pad;
|
|
|
|
ii = nb_pad;
|
2007-10-13 06:18:44 +00:00
|
|
|
nb_pad >>= 1;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
if( (ii & 1) && ( ii > 1 ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
nb_pad++;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2008-10-29 15:26:53 +00:00
|
|
|
if( pad->m_Pos.x < posref.x ) /* Must search after this item */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-17 14:35:59 +00:00
|
|
|
ptr_pad += nb_pad;
|
2007-10-13 06:18:44 +00:00
|
|
|
if( ptr_pad > lim )
|
2007-08-23 04:28:46 +00:00
|
|
|
ptr_pad = lim;
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-29 15:26:53 +00:00
|
|
|
if( pad->m_Pos.x > posref.x ) /* Must search before this item */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
ptr_pad -= nb_pad;
|
|
|
|
if( ptr_pad < pt_liste )
|
|
|
|
ptr_pad = pt_liste;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-10-29 15:26:53 +00:00
|
|
|
if( pad->m_Pos.x == posref.x ) /* A suitable block is found (X coordinate matches the px reference: but wue must matches the Y coordinate */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-11-27 17:42:15 +00:00
|
|
|
/* Search the beginning of the block */
|
2007-08-23 04:28:46 +00:00
|
|
|
while( ptr_pad >= pt_liste )
|
|
|
|
{
|
|
|
|
pad = *ptr_pad;
|
2008-10-29 15:26:53 +00:00
|
|
|
if( pad->m_Pos.x == posref.x )
|
2007-08-23 04:28:46 +00:00
|
|
|
ptr_pad--;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
ptr_pad++; /* ptr_pad = first pad which have pad->m_Pos.x = px */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
for( ; ; ptr_pad++ )
|
|
|
|
{
|
|
|
|
if( ptr_pad > lim )
|
2007-11-27 17:42:15 +00:00
|
|
|
return NULL; /* outside suitable block */
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
pad = *ptr_pad;
|
2008-10-29 15:26:53 +00:00
|
|
|
if( pad->m_Pos.x != posref.x )
|
2007-11-27 17:42:15 +00:00
|
|
|
return NULL; /* outside suitable block */
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2008-10-29 15:26:53 +00:00
|
|
|
if( pad->m_Pos.y != posref.y )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-11-27 17:42:15 +00:00
|
|
|
/* A Pad if found here: but it must mach the layer */
|
|
|
|
if( pad->m_Masque_Layer & masque_layer ) // Matches layer => a connected pad is found !
|
2007-08-23 04:28:46 +00:00
|
|
|
return pad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
/**
|
|
|
|
* Function SortPadsByXCoord
|
|
|
|
* is used to Sort a pad list by x coordinate value.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
static int SortPadsByXCoord( const void* pt_ref, const void* pt_comp )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
D_PAD* ref = *(LISTE_PAD*) pt_ref;
|
|
|
|
D_PAD* comp = *(LISTE_PAD*) pt_comp;
|
|
|
|
|
|
|
|
return ref->m_Pos.x - comp->m_Pos.x;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-03-18 04:04:17 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
void CreateSortedPadListByXCoord( BOARD* aBoard, std::vector<D_PAD*>* aVector )
|
|
|
|
/*****************************************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
aVector->insert( aVector->end(), aBoard->m_Pads.begin(), aBoard->m_Pads.end() );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
qsort( &(*aVector)[0], aBoard->m_Pads.size(), sizeof( D_PAD*), SortPadsByXCoord );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/********************************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
void WinEDA_BasePcbFrame::reattribution_reference_piste( int affiche )
|
2007-10-17 14:35:59 +00:00
|
|
|
/********************************************************************/
|
|
|
|
|
|
|
|
/* search connections between tracks and pads, and propagate pad net codes to the track segments
|
2007-11-27 17:42:15 +00:00
|
|
|
* This is a 2 pass computation.
|
|
|
|
* The pad netcodes are assumed to be initialized.
|
|
|
|
* First:
|
|
|
|
* We search a connection between a track segment and a pad: if found : this segment netcode is set to the pad netcode
|
2007-10-17 14:35:59 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-03-16 19:51:23 +00:00
|
|
|
TRACK* pt_piste;
|
|
|
|
TRACK* pt_next;
|
|
|
|
int a_color;
|
|
|
|
char new_passe_request = 1, flag;
|
|
|
|
|
2008-03-18 04:04:17 +00:00
|
|
|
std::vector<D_PAD*> sortedPads;
|
2009-03-16 19:51:23 +00:00
|
|
|
BOARD_ITEM* PtStruct;
|
|
|
|
int masque_layer;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
if( m_Pcb->m_Pads.size() == 0 ) // If no pad, reset pointers and netcode, and do nothing else
|
|
|
|
{
|
|
|
|
pt_piste = m_Pcb->m_Track;
|
|
|
|
for( ; pt_piste != NULL; pt_piste = pt_piste->Next() )
|
|
|
|
{
|
|
|
|
pt_piste->start = NULL;
|
|
|
|
pt_piste->SetState( BEGIN_ONPAD | END_ONPAD, OFF );
|
|
|
|
pt_piste->SetNet( 0 );
|
|
|
|
pt_piste->end = NULL;
|
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
return;
|
2009-03-16 19:51:23 +00:00
|
|
|
}
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
a_color = CYAN;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( affiche )
|
|
|
|
Affiche_1_Parametre( this, POS_AFF_CHREF, wxT( "DataBase" ), wxT( "Netcodes" ), a_color );
|
|
|
|
|
|
|
|
recalcule_pad_net_code();
|
|
|
|
|
|
|
|
if( affiche )
|
|
|
|
Affiche_1_Parametre( this, -1, wxEmptyString, wxT( "Gen Pads " ), a_color );
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/**************************************************************/
|
|
|
|
/* Pass 1: search the connections between track ends and pads */
|
|
|
|
/**************************************************************/
|
2008-03-18 04:04:17 +00:00
|
|
|
CreateSortedPadListByXCoord( m_Pcb, &sortedPads );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
if( affiche )
|
|
|
|
Affiche_1_Parametre( this, -1, wxEmptyString, wxT( "Conn Pads" ), a_color );
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* Reset variables and flags used in computation */
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_piste = m_Pcb->m_Track;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pt_piste != NULL; pt_piste = pt_piste->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
pt_piste->SetState( BUSY | EDIT | BEGIN_ONPAD | END_ONPAD, OFF );
|
2008-11-18 18:13:55 +00:00
|
|
|
pt_piste->SetZoneSubNet( 0 );
|
2007-10-17 14:35:59 +00:00
|
|
|
pt_piste->SetNet( 0 ); // net code = 0 means not connected
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* First pass: search connection between a track segment and a pad.
|
2007-11-27 17:42:15 +00:00
|
|
|
* if found, set the track net code to the pad netcode
|
2007-10-17 14:35:59 +00:00
|
|
|
*/
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_piste = m_Pcb->m_Track;
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pt_piste != NULL; pt_piste = pt_piste->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
flag = 0;
|
|
|
|
masque_layer = g_TabOneLayerMask[pt_piste->GetLayer()];
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* Search for a pad on the segment starting point */
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_piste->start = SuperFast_Locate_Pad_Connecte( m_Pcb,
|
2008-03-18 04:04:17 +00:00
|
|
|
&sortedPads[0],
|
2008-10-29 15:26:53 +00:00
|
|
|
pt_piste->m_Start,
|
2007-08-23 04:28:46 +00:00
|
|
|
masque_layer );
|
|
|
|
if( pt_piste->start != NULL )
|
|
|
|
{
|
|
|
|
pt_piste->SetState( BEGIN_ONPAD, ON );
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_piste->SetNet( ( (D_PAD*) (pt_piste->start) )->GetNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* Search for a pad on the segment ending point */
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_piste->end = SuperFast_Locate_Pad_Connecte( m_Pcb,
|
2008-03-18 04:04:17 +00:00
|
|
|
&sortedPads[0],
|
2008-10-29 15:26:53 +00:00
|
|
|
pt_piste->m_End,
|
2007-08-23 04:28:46 +00:00
|
|
|
masque_layer );
|
|
|
|
|
|
|
|
if( pt_piste->end != NULL )
|
|
|
|
{
|
|
|
|
pt_piste->SetState( END_ONPAD, ON );
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_piste->SetNet( ( (D_PAD*) (pt_piste->end) )->GetNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/*****************************************************/
|
|
|
|
/* Pass 2: search the connections between track ends */
|
|
|
|
/*****************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* the .start et .end member pointers are updated, only if NULLs
|
|
|
|
* (if not nuls, the end is already connected to a pad).
|
|
|
|
* the connection (if found) is between segments
|
2007-11-27 17:42:15 +00:00
|
|
|
* when a track has a net code and the other has a null net code, the null net code is changed
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
|
|
|
if( affiche )
|
|
|
|
Affiche_1_Parametre( this, POS_AFF_CHREF, wxEmptyString, wxT( "Conn Segm" ), a_color );
|
|
|
|
|
|
|
|
for( pt_piste = m_Pcb->m_Track; pt_piste != NULL; pt_piste = pt_piste->Next() )
|
|
|
|
{
|
|
|
|
if( pt_piste->start == NULL )
|
|
|
|
{
|
|
|
|
pt_piste->start = Locate_Piste_Connectee( pt_piste, m_Pcb->m_Track, NULL, START );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pt_piste->end == NULL )
|
|
|
|
{
|
|
|
|
pt_piste->end = Locate_Piste_Connectee( pt_piste, m_Pcb->m_Track, NULL, END );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/**********************************************************/
|
|
|
|
/* Propagate net codes from a segment to an other segment */
|
|
|
|
/**********************************************************/
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
a_color = YELLOW;
|
|
|
|
|
|
|
|
while( new_passe_request )
|
|
|
|
{
|
|
|
|
bool reset_flag = FALSE;
|
|
|
|
new_passe_request = 0;
|
|
|
|
if( affiche )
|
|
|
|
{
|
|
|
|
msg.Printf( wxT( "Net->Segm pass %d " ), new_passe_request + 1 );
|
|
|
|
Affiche_1_Parametre( this, POS_AFF_CHREF, wxEmptyString, msg, a_color );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for vias which could be connect many tracks */
|
|
|
|
for( TRACK* via = m_Pcb->m_Track; via != NULL; via = via->Next() )
|
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( via->Type() != TYPE_VIA )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
2007-10-13 06:18:44 +00:00
|
|
|
if( via->GetNet() > 0 )
|
2007-10-17 14:35:59 +00:00
|
|
|
continue; // Netcode already known
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
// Lock for a connection to a track with a known netcode
|
|
|
|
pt_next = m_Pcb->m_Track;
|
|
|
|
while( ( pt_next = Locate_Piste_Connectee( via, pt_next, NULL, START ) ) != NULL )
|
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
if( pt_next->GetNet() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
via->SetNet( pt_next->GetNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
pt_next->SetState( BUSY, ON );
|
|
|
|
reset_flag = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reset_flag )
|
|
|
|
for( pt_piste = m_Pcb->m_Track; pt_piste != NULL; pt_piste = pt_piste->Next() )
|
|
|
|
{
|
|
|
|
pt_piste->SetState( BUSY, OFF );
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* set the netcode of connected tracks: if at track is connected to a pad, its net code is already set.
|
|
|
|
* if the current track is connected to an other track:
|
|
|
|
* if a track has a net code, it is used for the other track.
|
|
|
|
* Thus there is a propagation of the netcode from a track to an other.
|
|
|
|
* if none of the 2 track has a net code we do nothing
|
|
|
|
* the iteration is stopped when no new change occurs
|
|
|
|
*/
|
2007-08-23 04:28:46 +00:00
|
|
|
for( pt_piste = m_Pcb->m_Track; pt_piste != NULL; pt_piste = pt_piste->Next() )
|
|
|
|
{
|
2007-10-17 14:35:59 +00:00
|
|
|
/* look for the connection to the current segment starting point */
|
2007-08-23 04:28:46 +00:00
|
|
|
PtStruct = (BOARD_ITEM*) pt_piste->start;
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct && (PtStruct->Type() != TYPE_PAD) )
|
2007-10-17 14:35:59 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
// Begin on an other track segment
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_next = (TRACK*) PtStruct;
|
2007-10-13 06:18:44 +00:00
|
|
|
if( pt_piste->GetNet() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-17 14:35:59 +00:00
|
|
|
if( pt_next->GetNet() == 0 ) // the current track has a netcode, we use it for the other track
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-17 14:35:59 +00:00
|
|
|
new_passe_request = 1; // A change is made: a new iteration is requested.
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_next->SetNet( pt_piste->GetNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-17 14:35:59 +00:00
|
|
|
if( pt_next->GetNet() != 0 ) // the other track has a netcode, we use it for the current track
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_piste->SetNet( pt_next->GetNet() );
|
2007-10-17 14:35:59 +00:00
|
|
|
new_passe_request = 1;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* look for the connection to the current segment ending point */
|
2007-08-23 04:28:46 +00:00
|
|
|
PtStruct = pt_piste->end;
|
2008-12-04 04:28:11 +00:00
|
|
|
if( PtStruct &&(PtStruct->Type() != TYPE_PAD) )
|
2007-10-17 14:35:59 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
pt_next = (TRACK*) PtStruct;
|
2007-10-17 14:35:59 +00:00
|
|
|
|
|
|
|
// End on an other track: propagate netcode if possible
|
2007-10-13 06:18:44 +00:00
|
|
|
if( pt_piste->GetNet() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
if( pt_next->GetNet() == 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-17 14:35:59 +00:00
|
|
|
new_passe_request = 1;
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_next->SetNet( pt_piste->GetNet() );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
if( pt_next->GetNet() != 0 )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
pt_piste->SetNet( pt_next->GetNet() );
|
2007-10-17 14:35:59 +00:00
|
|
|
new_passe_request = 1;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-17 14:35:59 +00:00
|
|
|
/* Sort the track list by net codes: */
|
2007-08-23 04:28:46 +00:00
|
|
|
if( affiche )
|
|
|
|
Affiche_1_Parametre( this, -1, wxEmptyString, wxT( "Reorder " ), a_color );
|
|
|
|
RebuildTrackChain( m_Pcb );
|
|
|
|
|
|
|
|
if( affiche )
|
|
|
|
Affiche_1_Parametre( this, -1, wxEmptyString, wxT( " " ), a_color );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
/**
|
|
|
|
* Function Sort_By_NetCode
|
|
|
|
* sorts track segments used in RebuildTrackChain() (for the qsort C function)
|
|
|
|
* The sorting is made by net code.
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
static int Sort_By_NetCode( const void* left, const void* right )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-03-16 19:51:23 +00:00
|
|
|
TRACK* pt_ref = *(TRACK**) left;
|
2008-12-04 04:28:11 +00:00
|
|
|
TRACK* pt_compare = *(TRACK**) right;
|
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
int ret = pt_ref->GetNet() - pt_compare->GetNet();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
return ret;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
/**
|
|
|
|
* Function RebuildTrackChain
|
|
|
|
* rebuilds the track segment linked list in order to have a chain
|
|
|
|
* sorted by increasing netcodes.
|
2007-11-27 17:42:15 +00:00
|
|
|
* @param pcb = board to rebuild
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
static void RebuildTrackChain( BOARD* pcb )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
if( pcb->m_Track == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
int nbsegm = pcb->m_Track.GetCount();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
TRACK** array = (TRACK**) MyZMalloc( nbsegm * sizeof(TRACK*) );
|
|
|
|
|
2009-03-16 19:51:23 +00:00
|
|
|
for( int i = 0; i<nbsegm; ++i )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
array[i] = pcb->m_Track.PopFront();
|
|
|
|
wxASSERT( array[i] );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
// the list is empty now
|
|
|
|
wxASSERT( pcb->m_Track == NULL && pcb->m_Track.GetCount()==0 );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
qsort( array, nbsegm, sizeof(TRACK*), Sort_By_NetCode );
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
// add them back to the list
|
2009-03-16 19:51:23 +00:00
|
|
|
for( int i = 0; i<nbsegm; ++i )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
pcb->m_Track.PushBack( array[i] );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
MyFree( array );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|