2011-10-17 20:01:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-06-08 09:56:42 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-17 20:01:27 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file tr_modif.cpp
|
2012-02-04 20:30:00 +00:00
|
|
|
* @brief Trace editing: detects an removes a track which is become redunding,
|
|
|
|
* after a new track is craeted.
|
2011-09-23 13:57:12 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <wxPcbStruct.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_track.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <protos.h>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2011-03-23 15:18:44 +00:00
|
|
|
static void ListSetState( EDA_ITEM* Start, int NbItem, int State, int onoff );
|
|
|
|
|
|
|
|
|
2012-02-04 20:30:00 +00:00
|
|
|
/*
|
|
|
|
* This function try to remove an old track, when a new track is created,
|
|
|
|
* and the old track is no more needed
|
|
|
|
*/
|
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
|
|
|
|
2011-09-14 20:04:58 +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.
|
|
|
|
*/
|
2011-10-01 19:24:27 +00:00
|
|
|
if( aNewTrack->Type() == PCB_VIA_T && ( aNewTrackSegmentsCount > 1 ) )
|
2009-08-08 06:07:08 +00:00
|
|
|
aNewTrack = aNewTrack->Next();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2011-09-16 15:54:50 +00:00
|
|
|
aNewTrack = GetBoard()->MarkTrace( 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)
|
2012-02-19 04:02:19 +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
|
2011-09-16 14:13:02 +00:00
|
|
|
TRACK* bufEnd = bufStart->GetEndNetCode( netcode ); // End of tracks of the net
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2012-02-19 04:02:19 +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
|
|
|
{
|
2012-01-21 15:02:49 +00:00
|
|
|
// D( std::cout<<"track "<<pt_del<<" turning off BUSY | IN_EDIT | IS_LINKED"<<std::endl; )
|
2011-02-13 17:53:48 +00:00
|
|
|
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-16 14:13:02 +00:00
|
|
|
if( aNewTrack->GetEndSegments( 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;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// The start and end points cannot be the same.
|
2008-02-08 00:16:59 +00:00
|
|
|
if( start == end )
|
|
|
|
return 0;
|
|
|
|
|
2012-02-19 04:02:19 +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
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// There may be a via or a pad on the end points.
|
2011-09-14 20:04:58 +00:00
|
|
|
pt_segm = m_Pcb->m_Track->GetVia( 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
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( StartTrack->start && ( StartTrack->start->Type() == PCB_PAD_T ) )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// Start on pad.
|
|
|
|
D_PAD* pad = (D_PAD*) StartTrack->start;
|
|
|
|
startmasklayer |= pad->GetLayerMask();
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-14 20:04:58 +00:00
|
|
|
pt_segm = m_Pcb->m_Track->GetVia( 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
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( EndTrack->end && ( EndTrack->end->Type() == PCB_PAD_T ) )
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
D_PAD* pad = (D_PAD*) EndTrack->end;
|
|
|
|
endmasklayer |= pad->GetLayerMask();
|
2008-02-08 00:16:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-16 14:13:02 +00:00
|
|
|
// Mark as deleted a new track (which is not involved in the search for other connections)
|
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-14 15:08:44 +00:00
|
|
|
pt_segm = GetTrace( bufStart, bufEnd, start, startmasklayer );
|
2008-02-08 00:16:59 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( pt_segm == NULL ) // Not connected to the track starting point.
|
2008-02-08 00:16:59 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +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-14 15:08:44 +00:00
|
|
|
pt_segm = GetTrace( pt_del, bufEnd, end, endmasklayer );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-02-08 00:16:59 +00:00
|
|
|
if( pt_segm == NULL )
|
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( pt_segm->Type() != PCB_VIA_T )
|
2008-12-04 04:28:11 +00:00
|
|
|
{
|
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 )
|
|
|
|
{
|
2012-02-19 04:02:19 +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;
|
|
|
|
}
|
|
|
|
|
2011-09-14 20:04:58 +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
|
|
|
|
2012-02-19 04:02:19 +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-16 15:54:50 +00:00
|
|
|
pt_del = GetBoard()->MarkTrace( 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 )
|
|
|
|
{
|
2012-02-19 04:02:19 +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
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawTraces( m_canvas, aDC, pt_del, nb_segm, GR_XOR | GR_HIGHLIGHT );
|
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 );
|
2011-12-21 13:42:02 +00:00
|
|
|
pt_del->ClearFlags();
|
2009-08-08 06:07:08 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +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 )
|
2011-12-22 13:28:11 +00:00
|
|
|
pt_del->Draw( m_canvas, 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-16 14:13:02 +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 );
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +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
|
|
|
|
|
|
|
|
2012-02-04 20:30:00 +00:00
|
|
|
/* Set the bits of .m_State member to on/off value, using bit mask State
|
2011-03-23 15:18:44 +00:00
|
|
|
* of a list of EDA_ITEM
|
|
|
|
*/
|
|
|
|
static void ListSetState( EDA_ITEM* Start, int NbItem, int State, int onoff )
|
|
|
|
{
|
|
|
|
for( ; (Start != NULL ) && ( NbItem > 0 ); NbItem--, Start = Start->Next() )
|
|
|
|
{
|
|
|
|
Start->SetState( State, onoff );
|
|
|
|
}
|
|
|
|
}
|