2009-11-20 14:55:20 +00:00
|
|
|
/******************/
|
|
|
|
/* Trace editing. */
|
|
|
|
/******************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
|
|
|
#include "pcbnew.h"
|
2009-08-08 06:07:08 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
2011-03-23 15:18:44 +00:00
|
|
|
static void ListSetState( EDA_ITEM* Start, int NbItem, int State, int onoff );
|
|
|
|
extern int ReturnEndsTrack( TRACK* RefTrack, int NbSegm,
|
2011-09-07 19:41:04 +00:00
|
|
|
TRACK** StartTrack, TRACK** EndTrack );
|
2011-03-23 15:18:44 +00:00
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function EraseRedundantTrack
|
2009-08-08 06:07:08 +00:00
|
|
|
* Called after creating a track
|
2009-11-20 14:55:20 +00:00
|
|
|
* Remove (if exists) the old track that have the same starting and the same
|
|
|
|
* ending point as the new created track (this is the redunding track)
|
2009-08-08 06:07:08 +00:00
|
|
|
* @param aDC = the current device context (can be NULL)
|
2009-11-20 14:55:20 +00:00
|
|
|
* @param aNewTrack = the new created track (a pointer to a segment of the
|
|
|
|
* track list)
|
2009-08-08 06:07:08 +00:00
|
|
|
* @param aNewTrackSegmentsCount = number of segments in this new track
|
2009-11-20 14:55:20 +00:00
|
|
|
* @param aItemsListPicker = the list picker to use for an undo command (can
|
|
|
|
* be NULL)
|
2008-02-08 00:16:59 +00:00
|
|
|
*/
|
2011-03-01 19:26:17 +00:00
|
|
|
int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC,
|
|
|
|
TRACK* aNewTrack,
|
|
|
|
int aNewTrackSegmentsCount,
|
|
|
|
PICKED_ITEMS_LIST* aItemsListPicker )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
TRACK* StartTrack, * EndTrack;
|
2008-12-04 04:28:11 +00:00
|
|
|
TRACK* pt_segm;
|
|
|
|
TRACK* pt_del;
|
2008-02-08 00:16:59 +00:00
|
|
|
int ii, jj, nb_segm, nbconnect;
|
2009-11-20 14:55:20 +00:00
|
|
|
wxPoint start;
|
|
|
|
wxPoint end;
|
|
|
|
int startmasklayer, endmasklayer;
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
int netcode = aNewTrack->GetNet();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Reconstruct the complete track (the new track has to start on a
|
|
|
|
* segment of track).
|
2008-12-04 04:28:11 +00:00
|
|
|
*/
|
2009-08-08 06:07:08 +00:00
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, BUSY, OFF );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* If the new track begins with a via, complete the track segment using
|
|
|
|
* the following segment as a reference because a via is often a hub of
|
|
|
|
* segments, and does not characterize track.
|
|
|
|
*/
|
|
|
|
if( aNewTrack->Type() == TYPE_VIA && ( aNewTrackSegmentsCount > 1 ) )
|
2009-08-08 06:07:08 +00:00
|
|
|
aNewTrack = aNewTrack->Next();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
aNewTrack = MarkTrace( GetBoard(), aNewTrack, &aNewTrackSegmentsCount, NULL, NULL, true );
|
2009-08-08 06:07:08 +00:00
|
|
|
wxASSERT( aNewTrack );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
#if 0 && defined(DEBUG)
|
2009-11-20 14:55:20 +00:00
|
|
|
TRACK* EndNewTrack; /* The last segment of the list chained to
|
|
|
|
* the track */
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
EndNewTrack = aNewTrack;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
for( ii = 1; ii < aNewTrackSegmentsCount; ii++ )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
wxASSERT( EndNewTrack->GetState( -1 ) != 0 );
|
2011-09-07 19:41:04 +00:00
|
|
|
D( printf( "track %p is newly part of net %d\n", EndNewTrack, netcode ); )
|
2008-11-24 06:53:43 +00:00
|
|
|
EndNewTrack = EndNewTrack->Next();
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
wxASSERT( EndNewTrack->GetState( -1 ) != 0 );
|
|
|
|
D( printf( "track %p is newly part of net %d\n", EndNewTrack, netcode ); )
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() )
|
2008-12-04 04:28:11 +00:00
|
|
|
track->Show( 0, std::cout );
|
2009-11-20 14:55:20 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
#endif
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
TRACK* bufStart = m_Pcb->m_Track->GetStartNetCode( netcode ); // Beginning of tracks of the net
|
|
|
|
TRACK* bufEnd = bufStart->GetEndNetCode( netcode ); // Enf of tracks of the net
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Flags for cleaning the net. */
|
2011-08-20 14:46:48 +00:00
|
|
|
for( pt_del = bufStart; pt_del; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
//D( printf( "track %p turning off BUSY | IN_EDIT | IS_LINKED\n", pt_del ); )
|
|
|
|
D( std::cout<<"track "<<pt_del<<" turning off BUSY | IN_EDIT | IS_LINKED"<<std::endl; )
|
|
|
|
pt_del->SetState( BUSY | IN_EDIT | IS_LINKED, OFF );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-08-20 14:46:48 +00:00
|
|
|
if( pt_del == bufEnd ) // Last segment reached
|
2009-03-05 15:58:06 +00:00
|
|
|
break;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
if( ReturnEndsTrack( aNewTrack, aNewTrackSegmentsCount, &StartTrack, &EndTrack ) == 0 )
|
2008-02-08 00:16:59 +00:00
|
|
|
return 0;
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
if( ( StartTrack == NULL ) || ( EndTrack == NULL ) )
|
2008-02-08 00:16:59 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
start = StartTrack->m_Start;
|
|
|
|
end = EndTrack->m_End;
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* The start and end points cannot be the same. */
|
2008-02-08 00:16:59 +00:00
|
|
|
if( start == end )
|
|
|
|
return 0;
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Determine layers interconnected these points. */
|
2008-02-08 00:16:59 +00:00
|
|
|
startmasklayer = StartTrack->ReturnMaskLayer();
|
|
|
|
endmasklayer = EndTrack->ReturnMaskLayer();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* There may be a via or a pad on the end points. */
|
2009-08-08 06:07:08 +00:00
|
|
|
pt_segm = Fast_Locate_Via( m_Pcb->m_Track, NULL, start, startmasklayer );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
if( pt_segm )
|
|
|
|
startmasklayer |= pt_segm->ReturnMaskLayer();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
if( StartTrack->start && ( StartTrack->start->Type() == TYPE_PAD ) )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Start on pad. */
|
|
|
|
D_PAD* pt_pad = (D_PAD*)(StartTrack->start);
|
2011-09-07 19:41:04 +00:00
|
|
|
startmasklayer |= pt_pad->m_layerMask;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
pt_segm = Fast_Locate_Via( m_Pcb->m_Track, NULL, end, endmasklayer );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
if( pt_segm )
|
|
|
|
endmasklayer |= pt_segm->ReturnMaskLayer();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
if( EndTrack->end && ( EndTrack->end->Type() == TYPE_PAD ) )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
D_PAD* pt_pad = (D_PAD*)(EndTrack->end);
|
2011-09-07 19:41:04 +00:00
|
|
|
endmasklayer |= pt_pad->m_layerMask;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Mark as deleted a new track (which is not involved in the search for
|
|
|
|
* other connections)
|
2008-12-04 04:28:11 +00:00
|
|
|
*/
|
2011-02-13 17:53:48 +00:00
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, IS_DELETED, ON );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* A segment must be connected to the starting point, otherwise
|
|
|
|
* it is unnecessary to analyze the other point
|
2008-12-04 04:28:11 +00:00
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
pt_segm = GetTrace( bufStart, bufEnd, start, startmasklayer );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
if( pt_segm == NULL ) /* Not connected to the track starting point. */
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Clear the delete flag. */
|
2011-02-13 17:53:48 +00:00
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, IS_DELETED, OFF );
|
2008-02-08 00:16:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Marking a list of candidate segmented connect to endpoint
|
|
|
|
* Note: the vias are not taken into account because they do
|
|
|
|
* not define a track, since they are on an intersection.
|
|
|
|
*/
|
2011-08-20 14:46:48 +00:00
|
|
|
for( pt_del = bufStart, nbconnect = 0; ; )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2011-09-07 19:41:04 +00:00
|
|
|
pt_segm = GetTrace( pt_del, bufEnd, end, endmasklayer );
|
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
if( pt_segm == NULL )
|
|
|
|
break;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( pt_segm->Type() != TYPE_VIA )
|
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
if( pt_segm->GetState( IS_LINKED ) == 0 )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
pt_segm->SetState( IS_LINKED, ON );
|
2008-02-08 00:16:59 +00:00
|
|
|
nbconnect++;
|
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-08-20 14:46:48 +00:00
|
|
|
if( pt_del == bufEnd )
|
2008-02-08 00:16:59 +00:00
|
|
|
break;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
pt_del = pt_segm->Next();
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( nbconnect == 0 )
|
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Clear used flags */
|
2011-08-20 14:46:48 +00:00
|
|
|
for( pt_del = bufStart; pt_del; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
pt_del->SetState( BUSY | IS_DELETED | IN_EDIT | IS_LINKED, OFF );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-08-20 14:46:48 +00:00
|
|
|
if( pt_del == bufEnd ) // Last segment reached
|
2009-03-05 15:58:06 +00:00
|
|
|
break;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Mark trace as edited (which does not involve searching for other
|
|
|
|
* tracks)
|
|
|
|
*/
|
2011-02-13 17:53:48 +00:00
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, IS_DELETED, OFF );
|
|
|
|
ListSetState( aNewTrack, aNewTrackSegmentsCount, IN_EDIT, ON );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Test all marked segments. */
|
2008-02-08 00:16:59 +00:00
|
|
|
while( nbconnect )
|
|
|
|
{
|
2011-08-20 14:46:48 +00:00
|
|
|
for( pt_del = bufStart; pt_del; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
if( pt_del->GetState( IS_LINKED ) )
|
2008-02-08 00:16:59 +00:00
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-08-20 14:46:48 +00:00
|
|
|
if( pt_del == bufEnd ) // Last segment reached
|
2009-03-05 15:58:06 +00:00
|
|
|
break;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
nbconnect--;
|
2011-02-13 17:53:48 +00:00
|
|
|
pt_del->SetState( IS_LINKED, OFF );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
pt_del = MarkTrace( GetBoard(), pt_del, &nb_segm, NULL, NULL, true );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2011-08-20 14:46:48 +00:00
|
|
|
/* Test if the marked track is redundant, i.e. if one of marked segments
|
2009-11-20 14:55:20 +00:00
|
|
|
* is connected to the starting point of the new track.
|
2008-02-08 00:16:59 +00:00
|
|
|
*/
|
2008-12-04 04:28:11 +00:00
|
|
|
ii = 0;
|
|
|
|
pt_segm = pt_del;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
for( ; pt_segm && (ii < nb_segm); pt_segm = pt_segm->Next(), ii++ )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2008-12-04 04:28:11 +00:00
|
|
|
if( pt_segm->GetState( BUSY ) == 0 )
|
2008-02-08 00:16:59 +00:00
|
|
|
break;
|
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
if( pt_segm->m_Start == start || pt_segm->m_End == start )
|
|
|
|
{
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Marked track can be erased. */
|
2008-02-08 00:16:59 +00:00
|
|
|
TRACK* NextS;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
|
|
|
DrawTraces( DrawPanel, aDC, pt_del, nb_segm, GR_XOR | GR_SURBRILL );
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
for( jj = 0; jj < nb_segm; jj++, pt_del = NextS )
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
NextS = pt_del->Next();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
if( aItemsListPicker )
|
|
|
|
{
|
|
|
|
pt_del->UnLink();
|
|
|
|
pt_del->SetStatus( 0 );
|
|
|
|
pt_del->m_Flags = 0;
|
|
|
|
ITEM_PICKER picker( pt_del, UR_DELETED );
|
|
|
|
aItemsListPicker->PushItem( picker );
|
2009-11-20 14:55:20 +00:00
|
|
|
}
|
2009-08-08 06:07:08 +00:00
|
|
|
else
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2009-08-08 06:07:08 +00:00
|
|
|
pt_del->DeleteStructure();
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Clean up flags. */
|
2011-09-07 19:41:04 +00:00
|
|
|
for( pt_del = m_Pcb->m_Track; pt_del != NULL; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
if( pt_del->GetState( IN_EDIT ) )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
pt_del->SetState( IN_EDIT, OFF );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2009-08-08 06:07:08 +00:00
|
|
|
if( aDC )
|
|
|
|
pt_del->Draw( DrawPanel, aDC, GR_OR );
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-02-13 17:53:48 +00:00
|
|
|
pt_del->SetState( IN_EDIT | IS_LINKED, OFF );
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-20 14:55:20 +00:00
|
|
|
/* Clear BUSY flag here because the track did not get marked.
|
|
|
|
*/
|
2008-02-08 00:16:59 +00:00
|
|
|
ListSetState( pt_del, nb_segm, BUSY, OFF );
|
|
|
|
}
|
|
|
|
|
2009-03-05 15:58:06 +00:00
|
|
|
/* Clear used flags */
|
2009-08-08 06:07:08 +00:00
|
|
|
for( pt_del = m_Pcb->m_Track; pt_del; pt_del = pt_del->Next() )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2011-02-13 17:53:48 +00:00
|
|
|
pt_del->SetState( BUSY | IS_DELETED | IN_EDIT | IS_LINKED, OFF );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-08-20 14:46:48 +00:00
|
|
|
if( pt_del == bufEnd ) // Last segment reached
|
2009-03-05 15:58:06 +00:00
|
|
|
break;
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2011-03-23 15:18:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Set the bits of .m_State member to onoff value, using bit mask State
|
|
|
|
* of a list of EDA_ITEM
|
|
|
|
*/
|
|
|
|
static void ListSetState( EDA_ITEM* Start, int NbItem, int State, int onoff )
|
|
|
|
{
|
|
|
|
if( Start == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( ; (Start != NULL ) && ( NbItem > 0 ); NbItem--, Start = Start->Next() )
|
|
|
|
{
|
|
|
|
Start->SetState( State, onoff );
|
|
|
|
}
|
|
|
|
}
|