2009-11-20 14:55:20 +00:00
|
|
|
/*****************
|
2009-10-10 17:27:53 +00:00
|
|
|
* track.cpp
|
2009-11-20 14:55:20 +00:00
|
|
|
*****************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "pcbnew.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Functions to recognize a track.
|
2009-10-10 17:27:53 +00:00
|
|
|
* A track is a list of connected segments (or/and vias)
|
|
|
|
* from a starting to an ending point
|
2009-11-20 14:55:20 +00:00
|
|
|
* starting and ending points are a pad or a point with more than 2 segments
|
|
|
|
*connected
|
|
|
|
* (and obviously a dangling segment end)
|
2009-10-10 17:27:53 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
typedef std::vector<TRACK*> TRACK_PTRS; // buffer of item candidates when
|
|
|
|
// search for items on the same track
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
/* Local functions */
|
2009-11-20 14:55:20 +00:00
|
|
|
static void Marque_Chaine_segments( BOARD* Pcb,
|
|
|
|
wxPoint ref_pos,
|
|
|
|
int masklayer,
|
|
|
|
TRACK_PTRS* aList );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Marque_Une_Piste
|
2009-10-10 17:27:53 +00:00
|
|
|
* marks a chain of track segments, connected to aTrackList.
|
2009-11-20 14:55:20 +00:00
|
|
|
* Each segment is marked by setting the BUSY bit into m_Flags. Electrical
|
|
|
|
* continuity is detected by walking each segment, and finally the segments
|
|
|
|
* are rearranged into a contiguous chain within the given list.
|
|
|
|
* @param aPcb = the board to analyze
|
|
|
|
* @param aStartSegm - The first interesting segment within a list of track
|
|
|
|
* segment of aPcb
|
|
|
|
* @param aSegmCount = a pointer to an integer where to return the number of
|
|
|
|
* interesting segments
|
|
|
|
* @param aTrackLen = a pointer to an integer where to return the length of the
|
|
|
|
* track
|
2009-10-10 17:27:53 +00:00
|
|
|
* @param aReorder = bool:
|
2009-11-20 14:55:20 +00:00
|
|
|
* true for reorder the interesting segments (useful for track
|
|
|
|
*edition/deletion)
|
|
|
|
* in this case the flag BUSY is set (the user is responsible of flag
|
|
|
|
*clearing)
|
|
|
|
* false for no reorder : useful when we want just calculate the track length
|
2009-10-10 17:27:53 +00:00
|
|
|
* in this case, flags are reset
|
2008-12-04 04:28:11 +00:00
|
|
|
* @return TRACK* the first in the chain of interesting segments.
|
|
|
|
*/
|
2009-10-10 17:27:53 +00:00
|
|
|
TRACK* Marque_Une_Piste( BOARD* aPcb,
|
|
|
|
TRACK* aStartSegm,
|
|
|
|
int* aSegmCount,
|
|
|
|
int* aTrackLen,
|
|
|
|
bool aReorder )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
int NbSegmBusy;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
TRACK_PTRS trackList;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( aSegmCount )
|
|
|
|
*aSegmCount = 0;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-10-14 18:14:58 +00:00
|
|
|
if( aTrackLen )
|
|
|
|
*aTrackLen = 0;
|
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( aStartSegm == NULL )
|
|
|
|
return NULL;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
// Ensure the flag BUSY of all tracks of the board is cleared
|
|
|
|
// because we use it to mark segments of the track
|
|
|
|
for( TRACK* track = aPcb->m_Track; track; track = track->Next() )
|
|
|
|
track->SetState( BUSY, OFF );
|
2009-03-05 13:41:34 +00:00
|
|
|
|
|
|
|
/* Set flags of the initial track segment */
|
2009-10-10 17:27:53 +00:00
|
|
|
aStartSegm->SetState( BUSY, ON );
|
|
|
|
int masque_layer = aStartSegm->ReturnMaskLayer();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
trackList.push_back( aStartSegm );
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Examine the initial track segment : if it is really a segment, this is
|
|
|
|
* easy.
|
2009-03-05 13:41:34 +00:00
|
|
|
* If it is a via, one must search for connected segments.
|
2009-11-20 14:55:20 +00:00
|
|
|
* If <=2, this via connect 2 segments (or is connected to only one
|
|
|
|
* segment) and this via and these 2 segments are a part of a track.
|
2009-03-05 13:41:34 +00:00
|
|
|
* If > 2 only this via is flagged (the track has only this via)
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-10-10 17:27:53 +00:00
|
|
|
if( aStartSegm->Type() == TYPE_VIA )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
TRACK* Segm1, * Segm2 = NULL, * Segm3 = NULL;
|
2009-10-10 17:27:53 +00:00
|
|
|
Segm1 = Fast_Locate_Piste( aPcb->m_Track, NULL,
|
|
|
|
aStartSegm->m_Start, masque_layer );
|
2007-08-23 04:28:46 +00:00
|
|
|
if( Segm1 )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
Segm2 = Fast_Locate_Piste( Segm1->Next(), NULL,
|
2009-10-10 17:27:53 +00:00
|
|
|
aStartSegm->m_Start, masque_layer );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
if( Segm2 )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
Segm3 = Fast_Locate_Piste( Segm2->Next(), NULL,
|
2009-10-10 17:27:53 +00:00
|
|
|
aStartSegm->m_Start, masque_layer );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-11-20 14:55:20 +00:00
|
|
|
if( Segm3 ) // More than 2 segments are connected to this via. the
|
|
|
|
// "track" is only this via
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
if( aSegmCount )
|
|
|
|
*aSegmCount = 1;
|
|
|
|
return aStartSegm;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-11-20 14:55:20 +00:00
|
|
|
if( Segm1 ) // search for others segments connected to the initial
|
|
|
|
// segment start point
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
masque_layer = Segm1->ReturnMaskLayer();
|
2009-11-20 14:55:20 +00:00
|
|
|
Marque_Chaine_segments( aPcb, aStartSegm->m_Start, masque_layer,
|
|
|
|
&trackList );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-11-20 14:55:20 +00:00
|
|
|
if( Segm2 ) // search for others segments connected to the initial
|
|
|
|
// segment end point
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
masque_layer = Segm2->ReturnMaskLayer();
|
2009-11-20 14:55:20 +00:00
|
|
|
Marque_Chaine_segments( aPcb, aStartSegm->m_Start, masque_layer,
|
|
|
|
&trackList );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-04 04:28:11 +00:00
|
|
|
else // mark the chain using both ends of the initial segment
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
Marque_Chaine_segments( aPcb,
|
|
|
|
aStartSegm->m_Start,
|
|
|
|
masque_layer,
|
|
|
|
&trackList );
|
|
|
|
Marque_Chaine_segments( aPcb,
|
|
|
|
aStartSegm->m_End,
|
|
|
|
masque_layer,
|
|
|
|
&trackList );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
// Now examine selected vias and flag them if they are on the track
|
|
|
|
// If a via is connected to only one or 2 segments, it is flagged (is on
|
|
|
|
// the track)
|
|
|
|
// If a via is connected to more than 2 segments, it is a track end, and it
|
|
|
|
// is removed from the list
|
2008-12-04 04:28:11 +00:00
|
|
|
// go through the list backwards.
|
2009-10-10 17:27:53 +00:00
|
|
|
for( int i = trackList.size() - 1; i>=0; --i )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
TRACK* via = trackList[i];
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
if( via->Type() != TYPE_VIA )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( via == aStartSegm )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
via->SetState( BUSY, ON ); // Try to flag it. the flag will be cleared
|
|
|
|
// later if needed
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
masque_layer = via->ReturnMaskLayer();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
TRACK* track = Fast_Locate_Piste( aPcb->m_Track,
|
|
|
|
NULL,
|
|
|
|
via->m_Start,
|
|
|
|
masque_layer );
|
2009-10-10 17:27:53 +00:00
|
|
|
|
|
|
|
// Fast_Locate_Piste does not consider tracks flagged BUSY.
|
2009-11-20 14:55:20 +00:00
|
|
|
// So if no connected track found, this via is on the current track
|
|
|
|
// only: keep it
|
2008-12-04 04:28:11 +00:00
|
|
|
if( track == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* If a track is found, this via connects also others segments of an
|
|
|
|
* other track. This case happens when the vias ends the selected
|
|
|
|
* track but must we consider this via is on the selected track, or
|
|
|
|
* on an other track.
|
|
|
|
* (this is important when selecting a track for deletion: must this
|
|
|
|
* via be deleted or not?)
|
|
|
|
* We consider here this via on the track if others segment connected
|
|
|
|
* to this via remain connected when removing this via.
|
2009-10-10 17:27:53 +00:00
|
|
|
* We search for all others segment connected together:
|
|
|
|
* if there are on the same layer, the via is on the selected track
|
|
|
|
* if there are on different layers, the via is on an other track
|
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
int layer = track->GetLayer();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
while( ( track = Fast_Locate_Piste( track->Next(), NULL,
|
2009-11-20 14:55:20 +00:00
|
|
|
via->m_Start,
|
|
|
|
masque_layer ) ) != NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( layer != track->GetLayer() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
// The via connects segments of an other track: it is removed
|
|
|
|
// from list because it is member of an other track
|
2008-12-04 04:28:11 +00:00
|
|
|
via->SetState( BUSY, OFF );
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Rearrange the track list in order to have flagged segments linked
|
|
|
|
* from firstTrack so the NbSegmBusy segments are consecutive segments
|
|
|
|
* in list, the first item in the full track list is firstTrack, and
|
|
|
|
* the NbSegmBusy-1 next items (NbSegmBusy when including firstTrack)
|
|
|
|
* are the flagged segments
|
2009-10-10 17:27:53 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
NbSegmBusy = 0;
|
|
|
|
TRACK* firstTrack;
|
2009-11-20 14:55:20 +00:00
|
|
|
for( firstTrack = aPcb->m_Track;
|
|
|
|
firstTrack;
|
|
|
|
firstTrack = firstTrack->Next() )
|
2008-03-10 15:00:22 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
// Search for the first flagged BUSY segments
|
2008-12-04 04:28:11 +00:00
|
|
|
if( firstTrack->GetState( BUSY ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-03-10 15:00:22 +00:00
|
|
|
NbSegmBusy = 1;
|
|
|
|
break;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( firstTrack == NULL )
|
|
|
|
return NULL;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
double full_len = 0;
|
|
|
|
if( aReorder )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
DLIST<TRACK>* list = (DLIST<TRACK>*)firstTrack->GetList();
|
2009-10-10 17:27:53 +00:00
|
|
|
wxASSERT( list );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
/* Rearrange the chain starting at firstTrack
|
|
|
|
* All others flagged items are moved from their position to the end
|
|
|
|
* of the flagged list
|
2008-12-04 04:28:11 +00:00
|
|
|
*/
|
|
|
|
TRACK* next;
|
|
|
|
for( TRACK* track = firstTrack->Next(); track; track = next )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
next = track->Next();
|
2009-10-10 17:27:53 +00:00
|
|
|
if( track->GetState( BUSY ) ) // move it!
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
|
|
|
NbSegmBusy++;
|
|
|
|
track->UnLink();
|
|
|
|
list->Insert( track, firstTrack->Next() );
|
2009-10-10 17:27:53 +00:00
|
|
|
if( aTrackLen )
|
|
|
|
full_len += track->GetLength();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( aTrackLen )
|
|
|
|
{
|
|
|
|
NbSegmBusy = 0;
|
|
|
|
for( TRACK* track = firstTrack; track; track = track->Next() )
|
|
|
|
{
|
|
|
|
if( track->GetState( BUSY ) )
|
|
|
|
{
|
|
|
|
NbSegmBusy++;
|
|
|
|
track->SetState( BUSY, OFF );
|
|
|
|
full_len += track->GetLength();
|
2008-12-04 04:28:11 +00:00
|
|
|
}
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( aTrackLen )
|
|
|
|
*aTrackLen = wxRound( full_len );
|
|
|
|
if( aSegmCount )
|
|
|
|
*aSegmCount = NbSegmBusy;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
return firstTrack;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
/**
|
2010-11-12 16:59:16 +00:00
|
|
|
* Function used by Marque_Une_Piste
|
2009-10-10 17:27:53 +00:00
|
|
|
* - Set the BUSY flag of connected segments, the first search point is
|
|
|
|
* ref_pos on layers allowed in masque_layer
|
|
|
|
* - Put segments fount in aList
|
|
|
|
* Vias are put in list but their flags BUSY is not set
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aPcb = the board
|
2009-10-10 17:27:53 +00:00
|
|
|
* @param aRef_pos = the reference coordinate of the starting search
|
|
|
|
* @param aLayerMask = the allowed layers for segments to search
|
2009-11-20 14:55:20 +00:00
|
|
|
* (1 layer when starting point is on a segment, but more than one when
|
|
|
|
* starting point is on a via)
|
2009-10-10 17:27:53 +00:00
|
|
|
* @param aList = the track list to fill with points of segments flagged
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-20 14:55:20 +00:00
|
|
|
static void Marque_Chaine_segments( BOARD* aPcb,
|
|
|
|
wxPoint aRef_pos,
|
|
|
|
int aLayerMask,
|
|
|
|
TRACK_PTRS* aList )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
TRACK* pt_segm, // The current segment being analyzed.
|
|
|
|
* pt_via, // The via identified, eventually destroy
|
|
|
|
|
|
|
|
* SegmentCandidate; // The end segment to destroy (or NULL =
|
|
|
|
// pt_segm
|
|
|
|
int NbSegm;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( aPcb->m_Track == NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Set the BUSY flag of all connected segments, first search starting at
|
|
|
|
* aRef_pos
|
2009-10-10 17:27:53 +00:00
|
|
|
* Search ends when:
|
|
|
|
* - a pad is found (end of a track)
|
|
|
|
* - a segment end has more than one other segment end connected
|
|
|
|
* - and obviously when no connected item found
|
2009-11-20 14:55:20 +00:00
|
|
|
* Vias are a special case, because we must see others segment connected
|
|
|
|
* on others layers and they change the layer mask. They can be a track
|
|
|
|
* end or not
|
|
|
|
* They will be analyzer later, and vias on terminal points of the track
|
|
|
|
* will be considered as part of this track if they do not connect segments
|
|
|
|
* of an other track together and will be considered as part of an other
|
|
|
|
* track if when removing the via, the segments of that other track are
|
|
|
|
* disconnected
|
2009-10-10 17:27:53 +00:00
|
|
|
*/
|
2007-08-23 04:28:46 +00:00
|
|
|
for( ; ; )
|
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
if( Fast_Locate_Pad_Connecte( aPcb, aRef_pos, aLayerMask ) != NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
return;
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Test for a via: a via changes the layer mask and can connect a lot
|
|
|
|
* of segments at location aRef_pos. When found, the via is just
|
|
|
|
* pushed in list. Vias will be examined later, when all connected
|
|
|
|
* segment are found and push in list. This is because when a via
|
|
|
|
* is found we do not know at this time the number of connected items
|
2009-10-10 17:27:53 +00:00
|
|
|
* and we do not know if this via is on the track or finish the track
|
|
|
|
*/
|
|
|
|
pt_via = Fast_Locate_Via( aPcb->m_Track, NULL, aRef_pos, aLayerMask );
|
2007-08-23 04:28:46 +00:00
|
|
|
if( pt_via )
|
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
aLayerMask = pt_via->ReturnMaskLayer();
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
aList->push_back( pt_via );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
/* Now we search all segments connected to point aRef_pos
|
|
|
|
* if only 1 segment: this segment is candidate
|
|
|
|
* if > 1 segment:
|
|
|
|
* end of track (more than 2 segment connected at this location)
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-10-10 17:27:53 +00:00
|
|
|
pt_segm = aPcb->m_Track; SegmentCandidate = NULL;
|
2007-08-23 04:28:46 +00:00
|
|
|
NbSegm = 0;
|
|
|
|
while( ( pt_segm = Fast_Locate_Piste( pt_segm, NULL,
|
2009-10-10 17:27:53 +00:00
|
|
|
aRef_pos, aLayerMask ) ) != NULL )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
if( pt_segm->GetState( BUSY ) ) // already found and selected: skip
|
|
|
|
// it
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
pt_segm = pt_segm->Next();
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( pt_segm == pt_via ) // just previously found: skip it
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
pt_segm = pt_segm->Next();
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NbSegm++;
|
2009-11-20 14:55:20 +00:00
|
|
|
if( NbSegm == 1 ) /* First time we found a connected item: pt_segm
|
|
|
|
* is candidate */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
SegmentCandidate = pt_segm;
|
|
|
|
pt_segm = pt_segm->Next();
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
2009-11-20 14:55:20 +00:00
|
|
|
else /* More than 1 segment connected -> this location is an end of
|
|
|
|
* the track */
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
if( SegmentCandidate ) // A candidate is found: flag it an push it
|
|
|
|
// in list
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Initialize parameters to search items connected to this
|
|
|
|
* candidate:
|
|
|
|
* we must analyze connections to its other end
|
2009-10-10 17:27:53 +00:00
|
|
|
*/
|
|
|
|
aLayerMask = SegmentCandidate->ReturnMaskLayer();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
if( aRef_pos == SegmentCandidate->m_Start )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
aRef_pos = SegmentCandidate->m_End;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-10 17:27:53 +00:00
|
|
|
aRef_pos = SegmentCandidate->m_Start;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
pt_segm = aPcb->m_Track; /* restart list of tracks to analyze */
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-10-10 17:27:53 +00:00
|
|
|
/* flag this item an push it in list of selected items */
|
|
|
|
aList->push_back( SegmentCandidate );
|
|
|
|
SegmentCandidate->SetState( BUSY, ON );
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Calculate the end points coordinates of a track (a list of connected
|
|
|
|
* segments)
|
2009-10-10 17:27:53 +00:00
|
|
|
* RefTrack is a segment of the track
|
|
|
|
* return 1 if OK, 0 when a track is a closed loop
|
|
|
|
* and the beginning and the end of the track in *StartTrack and *EndTrack
|
|
|
|
* Modify *StartTrack en *EndTrack :
|
|
|
|
* (*StartTrack)->m_Start coordinate is the beginning of the track
|
|
|
|
* (*EndTrack)->m_End coordinate is the end of the track
|
2009-11-20 14:55:20 +00:00
|
|
|
* Segments connected must be consecutive in list
|
2007-08-23 04:28:46 +00:00
|
|
|
*/
|
2009-11-20 14:55:20 +00:00
|
|
|
int ReturnEndsTrack( TRACK* RefTrack, int NbSegm,
|
|
|
|
TRACK** StartTrack, TRACK** EndTrack )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
TRACK* Track, * via, * segm, * TrackListEnd;
|
|
|
|
int NbEnds, masque_layer, ii, ok = 0;
|
|
|
|
|
|
|
|
if( NbSegm <= 1 )
|
|
|
|
{
|
|
|
|
*StartTrack = *EndTrack = RefTrack;
|
2009-11-20 14:55:20 +00:00
|
|
|
return 1;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Calculation of the limit analysis. */
|
2007-08-23 04:28:46 +00:00
|
|
|
*StartTrack = *EndTrack = NULL;
|
|
|
|
TrackListEnd = Track = RefTrack; ii = 0;
|
2009-11-20 14:55:20 +00:00
|
|
|
for( ; ( Track != NULL ) && ( ii < NbSegm ); ii++, Track = Track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
|
|
|
TrackListEnd = Track;
|
|
|
|
Track->m_Param = 0;
|
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Calculate the extremes. */
|
2007-08-23 04:28:46 +00:00
|
|
|
NbEnds = 0; Track = RefTrack; ii = 0;
|
2009-11-20 14:55:20 +00:00
|
|
|
for( ; ( Track != NULL ) && ( ii < NbSegm ); ii++, Track = Track->Next() )
|
2007-08-23 04:28:46 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( Track->Type() == TYPE_VIA )
|
2007-08-23 04:28:46 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
masque_layer = Track->ReturnMaskLayer();
|
|
|
|
via = Fast_Locate_Via( RefTrack, TrackListEnd,
|
|
|
|
Track->m_Start, masque_layer );
|
|
|
|
if( via )
|
|
|
|
{
|
|
|
|
masque_layer |= via->ReturnMaskLayer();
|
|
|
|
via->SetState( BUSY, ON );
|
|
|
|
}
|
|
|
|
|
|
|
|
Track->SetState( BUSY, ON );
|
|
|
|
segm = Fast_Locate_Piste( RefTrack, TrackListEnd,
|
|
|
|
Track->m_Start, masque_layer );
|
|
|
|
Track->SetState( BUSY, OFF );
|
|
|
|
if( via )
|
|
|
|
via->SetState( BUSY, OFF );
|
|
|
|
|
|
|
|
if( segm == NULL )
|
|
|
|
{
|
|
|
|
switch( NbEnds )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
*StartTrack = Track; NbEnds++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
int BeginPad, EndPad;
|
|
|
|
*EndTrack = Track;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Swap ox, oy with fx, fy */
|
2007-08-23 04:28:46 +00:00
|
|
|
BeginPad = Track->GetState( BEGIN_ONPAD );
|
|
|
|
EndPad = Track->GetState( END_ONPAD );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
Track->SetState( BEGIN_ONPAD | END_ONPAD, OFF );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( BeginPad )
|
|
|
|
Track->SetState( END_ONPAD, ON );
|
|
|
|
if( EndPad )
|
|
|
|
Track->SetState( BEGIN_ONPAD, ON );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
EXCHG( Track->m_Start, Track->m_End );
|
|
|
|
EXCHG( Track->start, Track->end );
|
2008-12-04 04:28:11 +00:00
|
|
|
ok = 1;
|
|
|
|
return ok;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
masque_layer = Track->ReturnMaskLayer();
|
|
|
|
via = Fast_Locate_Via( RefTrack, TrackListEnd,
|
|
|
|
Track->m_End, masque_layer );
|
|
|
|
if( via )
|
|
|
|
{
|
|
|
|
masque_layer |= via->ReturnMaskLayer();
|
|
|
|
via->SetState( BUSY, ON );
|
|
|
|
}
|
|
|
|
|
|
|
|
Track->SetState( BUSY, ON );
|
|
|
|
segm = Fast_Locate_Piste( RefTrack, TrackListEnd,
|
|
|
|
Track->m_End, masque_layer );
|
|
|
|
Track->SetState( BUSY, OFF );
|
|
|
|
if( via )
|
|
|
|
via->SetState( BUSY, OFF );
|
|
|
|
if( segm == NULL )
|
|
|
|
{
|
|
|
|
switch( NbEnds )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
int BeginPad, EndPad;
|
2008-12-04 04:28:11 +00:00
|
|
|
*StartTrack = Track;
|
|
|
|
NbEnds++;
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Swap ox, oy with fx, fy */
|
2007-08-23 04:28:46 +00:00
|
|
|
BeginPad = Track->GetState( BEGIN_ONPAD );
|
|
|
|
EndPad = Track->GetState( END_ONPAD );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
Track->SetState( BEGIN_ONPAD | END_ONPAD, OFF );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
if( BeginPad )
|
|
|
|
Track->SetState( END_ONPAD, ON );
|
|
|
|
if( EndPad )
|
|
|
|
Track->SetState( BEGIN_ONPAD, ON );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
EXCHG( Track->m_Start, Track->m_End );
|
|
|
|
EXCHG( Track->start, Track->end );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
*EndTrack = Track;
|
2008-12-04 04:28:11 +00:00
|
|
|
ok = 1;
|
|
|
|
return ok;
|
2007-08-23 04:28:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|