2011-12-12 14:02:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2010 Jean-Pierre Charras, jean-pierre.charras@gpisa-lab.inpg.fr
|
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
/**
|
|
|
|
* @file clean.cpp
|
2011-11-24 19:57:41 +00:00
|
|
|
* @brief functions to clean tracks: remove null lenght and redundant segments
|
2010-11-21 18:28:32 +00:00
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <pcbcommon.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <pcbnew.h>
|
|
|
|
#include <class_board.h>
|
|
|
|
#include <class_track.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// local functions :
|
2011-11-24 19:57:41 +00:00
|
|
|
static void clean_segments( PCB_EDIT_FRAME* aFrame );
|
2011-11-15 19:21:16 +00:00
|
|
|
static void clean_vias( BOARD* aPcb );
|
2011-11-24 19:57:41 +00:00
|
|
|
static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* aFrame );
|
2011-12-12 14:02:37 +00:00
|
|
|
static TRACK* MergeColinearSegmentIfPossible( BOARD* aPcb, TRACK* aTrackRef,
|
|
|
|
TRACK* aCandidate, int aEndType );
|
2011-11-24 19:57:41 +00:00
|
|
|
static void CleanupTracks( PCB_EDIT_FRAME* aFrame,
|
2011-03-01 19:26:17 +00:00
|
|
|
bool aCleanVias, bool aMergeSegments,
|
|
|
|
bool aDeleteUnconnectedSegm, bool aConnectToPads );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_cleaning_options.h>
|
2007-06-14 05:31:55 +00:00
|
|
|
|
|
|
|
#define CONN2PAD_ENBL
|
|
|
|
|
|
|
|
#ifdef CONN2PAD_ENBL
|
2011-11-15 19:21:16 +00:00
|
|
|
static void ConnectDanglingEndToPad( PCB_EDIT_FRAME* frame );
|
2007-10-19 23:02:11 +00:00
|
|
|
static void ConnectDanglingEndToVia( BOARD* pcb );
|
2007-06-14 05:31:55 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
|
2007-10-27 18:05:50 +00:00
|
|
|
/* Install the track operation dialog frame
|
|
|
|
*/
|
2011-09-07 19:41:04 +00:00
|
|
|
void PCB_EDIT_FRAME::Clean_Pcb( wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-11-21 18:28:32 +00:00
|
|
|
DIALOG_CLEANING_OPTIONS::connectToPads = false;
|
|
|
|
DIALOG_CLEANING_OPTIONS dlg( this );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
2011-11-15 19:21:16 +00:00
|
|
|
CleanupTracks( this, dlg.cleanVias, dlg.mergeSegments,
|
2011-12-12 14:02:37 +00:00
|
|
|
dlg.deleteUnconnectedSegm, dlg.connectToPads );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh( true );
|
2007-06-14 05:31:55 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2007-10-27 18:05:50 +00:00
|
|
|
/* Main cleaning function.
|
|
|
|
* Delete
|
|
|
|
* - Redundant points on tracks (merge aligned segments)
|
|
|
|
* - vias on pad
|
2011-11-24 19:57:41 +00:00
|
|
|
* - null lenght segments
|
2011-09-15 17:58:35 +00:00
|
|
|
* Create segments when track ends are incorrectly connected:
|
2007-10-27 18:05:50 +00:00
|
|
|
* i.e. when a track end covers a pad or a via but is not exactly on the pad or the via center
|
|
|
|
*/
|
2011-11-24 19:57:41 +00:00
|
|
|
void CleanupTracks( PCB_EDIT_FRAME* aFrame,
|
2011-12-12 14:02:37 +00:00
|
|
|
bool aCleanVias, bool aMergeSegments,
|
|
|
|
bool aDeleteUnconnectedSegm, bool aConnectToPads )
|
2007-06-14 05:31:55 +00:00
|
|
|
{
|
2010-11-21 18:28:32 +00:00
|
|
|
wxBusyCursor( dummy );
|
|
|
|
|
2011-12-12 14:02:37 +00:00
|
|
|
aFrame->ClearMsgPanel();
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->GetBoard()->GetNumSegmTrack(); // update the count
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2009-08-03 07:55:08 +00:00
|
|
|
// Clear undo and redo lists to avoid inconsistencies between lists
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->GetScreen()->ClearUndoRedoList();
|
|
|
|
aFrame->SetCurItem( NULL );
|
2009-08-03 07:55:08 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Rebuild the pad infos (pad list and netcodes) to ensure an up to date info
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->GetBoard()->m_Status_Pcb = 0;
|
2011-12-10 05:33:24 +00:00
|
|
|
aFrame->GetBoard()->BuildListOfNets();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
if( aCleanVias ) // delete redundant vias
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->SetStatusText( _( "Clean vias" ) );
|
|
|
|
clean_vias( aFrame->GetBoard() );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-06-14 05:31:55 +00:00
|
|
|
|
|
|
|
#ifdef CONN2PAD_ENBL
|
2008-03-10 15:00:22 +00:00
|
|
|
/* Create missing segments when a track end covers a pad or a via,
|
2011-09-15 17:58:35 +00:00
|
|
|
* but is not on the pad or the via center */
|
2010-11-21 18:28:32 +00:00
|
|
|
if( aConnectToPads )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->SetStatusText( _( "Reconnect pads" ) );
|
2011-09-15 17:58:35 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Create missing segments when a track end covers a pad, but is not on the pad center
|
2011-11-24 19:57:41 +00:00
|
|
|
ConnectDanglingEndToPad( aFrame );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Create missing segments when a track end covers a via, but is not on the via center
|
2011-11-24 19:57:41 +00:00
|
|
|
ConnectDanglingEndToVia( aFrame->GetBoard() );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Remove null segments and intermediate points on aligned segments
|
2010-11-21 18:28:32 +00:00
|
|
|
if( aMergeSegments )
|
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->SetStatusText( _( "Merge track segments" ) );
|
|
|
|
clean_segments( aFrame );
|
2010-11-21 18:28:32 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Delete dangling tracks
|
2010-11-21 18:28:32 +00:00
|
|
|
if( aDeleteUnconnectedSegm )
|
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->SetStatusText( _( "Delete unconnected tracks" ) );
|
|
|
|
DeleteUnconnectedTracks( aFrame );
|
2010-11-21 18:28:32 +00:00
|
|
|
}
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->SetStatusText( _( "Cleanup finished" ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->Compile_Ratsnest( NULL, true );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->OnModify();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
void clean_vias( BOARD * aPcb )
|
|
|
|
{
|
|
|
|
TRACK* track;
|
|
|
|
TRACK* next_track;
|
|
|
|
|
|
|
|
for( track = aPcb->m_Track; track; track = track->Next() )
|
|
|
|
{
|
2011-12-14 04:29:25 +00:00
|
|
|
if( track->GetShape() != VIA_THROUGH )
|
2010-11-21 18:28:32 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Search and delete others vias at same location
|
|
|
|
TRACK* alt_track = track->Next();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
for( ; alt_track != NULL; alt_track = next_track )
|
|
|
|
{
|
|
|
|
next_track = alt_track->Next();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
if( alt_track->m_Shape != VIA_THROUGH )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( alt_track->m_Start != track->m_Start )
|
|
|
|
continue;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// delete via
|
2010-11-21 18:28:32 +00:00
|
|
|
alt_track->UnLink();
|
|
|
|
delete alt_track;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Delete Via on pads at same location
|
2010-11-21 18:28:32 +00:00
|
|
|
for( track = aPcb->m_Track; track != NULL; track = next_track )
|
|
|
|
{
|
|
|
|
next_track = track->Next();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
if( track->m_Shape != VIA_THROUGH )
|
|
|
|
continue;
|
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
D_PAD* pad = aPcb->GetPadFast( track->m_Start, ALL_CU_LAYERS );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( pad && (pad->GetLayerMask() & EXTERNAL_LAYERS) == EXTERNAL_LAYERS ) // redundant Via
|
2010-11-21 18:28:32 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
// delete via
|
2010-11-21 18:28:32 +00:00
|
|
|
track->UnLink();
|
|
|
|
delete track;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/*
|
2007-10-27 12:24:09 +00:00
|
|
|
* Delete dangling tracks
|
|
|
|
* Vias:
|
|
|
|
* If a via is only connected to a dangling track, it also will be removed
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2011-11-24 19:57:41 +00:00
|
|
|
static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* aFrame )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
TRACK* segment;
|
|
|
|
TRACK* other;
|
|
|
|
TRACK* startNetcode;
|
|
|
|
TRACK* next;
|
2008-11-27 10:12:46 +00:00
|
|
|
ZONE_CONTAINER* zone;
|
2007-08-10 19:14:51 +00:00
|
|
|
int masklayer, oldnetcode;
|
|
|
|
int type_end, flag_erase;
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
if( aFrame->GetBoard()->m_Track == NULL )
|
2010-11-21 18:28:32 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
aFrame->GetCanvas()->SetAbortRequest( false );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2008-12-04 04:28:11 +00:00
|
|
|
// correct via m_End defects
|
2011-11-24 19:57:41 +00:00
|
|
|
for( segment = aFrame->GetBoard()->m_Track; segment; segment = next )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
next = segment->Next();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( segment->Type() == PCB_VIA_T )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segment->m_Start != segment->m_End )
|
|
|
|
segment->m_End = segment->m_Start;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
// removal of unconnected tracks
|
2011-11-24 19:57:41 +00:00
|
|
|
segment = startNetcode = aFrame->GetBoard()->m_Track;
|
2010-11-21 18:28:32 +00:00
|
|
|
oldnetcode = segment->GetNet();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
for( int ii = 0; segment ; segment = next, ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
next = segment->Next();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
if( aFrame->GetCanvas()->GetAbortRequest() )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
if( segment->GetNet() != oldnetcode )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2008-03-10 15:00:22 +00:00
|
|
|
startNetcode = segment;
|
2007-10-19 19:58:31 +00:00
|
|
|
oldnetcode = segment->GetNet();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-27 10:12:46 +00:00
|
|
|
flag_erase = 0; //Not connected indicator
|
2007-10-19 19:58:31 +00:00
|
|
|
type_end = 0;
|
2007-10-27 12:24:09 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Is a pad found on a track end ?
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
masklayer = segment->ReturnMaskLayer();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
D_PAD* pad;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
pad = aFrame->GetBoard()->GetPadFast( segment->m_Start, masklayer );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( pad != NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
segment->start = pad;
|
|
|
|
type_end |= START_ON_PAD;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
pad = aFrame->GetBoard()->GetPadFast( segment->m_End, masklayer );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( pad != NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
segment->end = pad;
|
|
|
|
type_end |= END_ON_PAD;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
// if not connected to a pad, test if segment's START is connected to another track
|
2008-11-27 10:12:46 +00:00
|
|
|
// For via tests, an enhancement could to test if connected to 2 items on different layers.
|
2011-09-15 17:58:35 +00:00
|
|
|
// Currently a via must be connected to 2 items, that can be on the same layer
|
2008-11-27 10:12:46 +00:00
|
|
|
int top_layer, bottom_layer;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( (type_end & START_ON_PAD ) == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
other = segment->GetTrace( aFrame->GetBoard()->m_Track, NULL, START );
|
2008-11-27 10:12:46 +00:00
|
|
|
|
|
|
|
if( other == NULL ) // Test a connection to zones
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
if( segment->Type() != PCB_VIA_T )
|
2008-11-27 10:12:46 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
zone = aFrame->GetBoard()->HitTestForAnyFilledArea( segment->m_Start,
|
2011-09-07 19:41:04 +00:00
|
|
|
segment->GetLayer() );
|
2008-11-27 10:12:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((SEGVIA*)segment)->ReturnLayerPair( &top_layer, &bottom_layer );
|
2011-11-24 19:57:41 +00:00
|
|
|
zone = aFrame->GetBoard()->HitTestForAnyFilledArea( segment->m_Start,
|
2011-09-07 19:41:04 +00:00
|
|
|
top_layer, bottom_layer );
|
2008-11-27 10:12:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (other == NULL) && (zone == NULL) )
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
flag_erase |= 1;
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2008-11-27 10:12:46 +00:00
|
|
|
else // segment, via or zone connected to this end
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
segment->start = other;
|
2008-11-27 10:12:46 +00:00
|
|
|
// If a via is connected to this end, test if this via has a second item connected
|
|
|
|
// if no, remove it with the current segment
|
2011-10-01 19:24:27 +00:00
|
|
|
|
|
|
|
if( other && other->Type() == PCB_VIA_T )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
// search for another segment following the via
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
segment->SetState( BUSY, ON );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2008-11-27 10:12:46 +00:00
|
|
|
SEGVIA* via = (SEGVIA*) other;
|
2011-11-24 19:57:41 +00:00
|
|
|
other = via->GetTrace( aFrame->GetBoard()->m_Track, NULL, START );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( other == NULL )
|
2008-11-27 10:12:46 +00:00
|
|
|
{
|
|
|
|
via->ReturnLayerPair( &top_layer, &bottom_layer );
|
2011-11-24 19:57:41 +00:00
|
|
|
zone = aFrame->GetBoard()->HitTestForAnyFilledArea( via->m_Start,
|
2011-09-07 19:41:04 +00:00
|
|
|
bottom_layer,
|
|
|
|
top_layer );
|
2008-11-27 10:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( (other == NULL) && (zone == NULL) )
|
2007-08-10 19:14:51 +00:00
|
|
|
flag_erase |= 2;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
segment->SetState( BUSY, OFF );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
// if not connected to a pad, test if segment's END is connected to another track
|
|
|
|
if( (type_end & END_ON_PAD ) == 0 )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
other = segment->GetTrace( aFrame->GetBoard()->m_Track, NULL, END );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2008-11-27 10:12:46 +00:00
|
|
|
if( other == NULL ) // Test a connection to zones
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
if( segment->Type() != PCB_VIA_T )
|
2011-09-15 17:58:35 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
zone = aFrame->GetBoard()->HitTestForAnyFilledArea( segment->m_End,
|
2011-09-07 19:41:04 +00:00
|
|
|
segment->GetLayer() );
|
2011-09-15 17:58:35 +00:00
|
|
|
}
|
2008-11-27 10:12:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
((SEGVIA*)segment)->ReturnLayerPair( &top_layer, &bottom_layer );
|
2011-11-24 19:57:41 +00:00
|
|
|
zone = aFrame->GetBoard()->HitTestForAnyFilledArea( segment->m_End,
|
2011-09-07 19:41:04 +00:00
|
|
|
top_layer, bottom_layer );
|
2008-11-27 10:12:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (other == NULL) && (zone == NULL) )
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
flag_erase |= 0x10;
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2008-11-27 10:12:46 +00:00
|
|
|
else // segment, via or zone connected to this end
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
segment->end = other;
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2008-11-27 10:12:46 +00:00
|
|
|
// If a via is connected to this end, test if this via has a second item connected
|
|
|
|
// if no, remove it with the current segment
|
2011-10-01 19:24:27 +00:00
|
|
|
|
|
|
|
if( other && other->Type() == PCB_VIA_T )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
// search for another segment following the via
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
segment->SetState( BUSY, ON );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2008-11-27 10:12:46 +00:00
|
|
|
SEGVIA* via = (SEGVIA*) other;
|
2011-11-24 19:57:41 +00:00
|
|
|
other = via->GetTrace( aFrame->GetBoard()->m_Track, NULL, END );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( other == NULL )
|
2008-11-27 10:12:46 +00:00
|
|
|
{
|
|
|
|
via->ReturnLayerPair( &top_layer, &bottom_layer );
|
2011-11-24 19:57:41 +00:00
|
|
|
zone = aFrame->GetBoard()->HitTestForAnyFilledArea( via->m_End,
|
2011-09-07 19:41:04 +00:00
|
|
|
bottom_layer,
|
|
|
|
top_layer );
|
2008-11-27 10:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( (other == NULL) && (zone == NULL) )
|
2007-08-10 19:14:51 +00:00
|
|
|
flag_erase |= 0x20;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
segment->SetState( BUSY, OFF );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( flag_erase )
|
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
// update the pointer to start of the contiguous netcode group
|
|
|
|
if( segment == startNetcode )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
next = segment->Next();
|
|
|
|
startNetcode = next;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
next = startNetcode;
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-11-15 19:21:16 +00:00
|
|
|
// remove segment from board
|
2007-10-15 03:26:38 +00:00
|
|
|
segment->DeleteStructure();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( next == NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Delete null length segments, and intermediate points ..
|
2011-11-24 19:57:41 +00:00
|
|
|
static void clean_segments( PCB_EDIT_FRAME* aFrame )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-06-11 18:30:03 +00:00
|
|
|
TRACK* segment, * nextsegment;
|
2007-10-19 19:58:31 +00:00
|
|
|
TRACK* other;
|
2010-11-21 18:28:32 +00:00
|
|
|
int ii;
|
|
|
|
int flag, no_inc;
|
2007-08-10 19:14:51 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
aFrame->GetCanvas()->SetAbortRequest( false );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
// Delete null segments
|
2011-11-24 19:57:41 +00:00
|
|
|
for( segment = aFrame->GetBoard()->m_Track; segment; segment = nextsegment )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-06-11 18:30:03 +00:00
|
|
|
nextsegment = segment->Next();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
if( !segment->IsNull() )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Length segment = 0; delete it
|
2007-10-15 03:26:38 +00:00
|
|
|
segment->DeleteStructure();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Delete redundant segments
|
2011-11-24 19:57:41 +00:00
|
|
|
for( segment = aFrame->GetBoard()->m_Track, ii = 0; segment; segment = segment->Next(), ii++ )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-06-11 18:30:03 +00:00
|
|
|
for( other = segment->Next(); other; other = nextsegment )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2009-06-11 18:30:03 +00:00
|
|
|
nextsegment = other->Next();
|
2007-08-10 19:14:51 +00:00
|
|
|
int erase = 0;
|
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segment->Type() != other->Type() )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segment->GetLayer() != other->GetLayer() )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segment->GetNet() != other->GetNet() )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segment->m_Start == other->m_Start )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segment->m_End == other->m_End )
|
2007-08-10 19:14:51 +00:00
|
|
|
erase = 1;
|
|
|
|
}
|
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segment->m_Start == other->m_End )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segment->m_End == other->m_Start )
|
2007-08-10 19:14:51 +00:00
|
|
|
erase = 1;
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// Delete redundant point
|
2007-08-10 19:14:51 +00:00
|
|
|
if( erase )
|
|
|
|
{
|
|
|
|
ii--;
|
2007-10-19 19:58:31 +00:00
|
|
|
other->DeleteStructure();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// delete intermediate points
|
2007-08-10 19:14:51 +00:00
|
|
|
ii = 0;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
for( segment = aFrame->GetBoard()->m_Track; segment; segment = nextsegment )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
TRACK* segStart;
|
|
|
|
TRACK* segEnd;
|
2007-10-19 23:02:11 +00:00
|
|
|
TRACK* segDelete;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2009-06-11 18:30:03 +00:00
|
|
|
nextsegment = segment->Next();
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
if( aFrame->GetCanvas()->GetAbortRequest() )
|
2010-11-21 18:28:32 +00:00
|
|
|
return;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( segment->Type() != PCB_TRACE_T )
|
2007-08-10 19:14:51 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
flag = no_inc = 0;
|
|
|
|
|
2007-10-27 18:05:50 +00:00
|
|
|
// search for a possible point that connects on the START point of the segment
|
2007-10-19 23:02:11 +00:00
|
|
|
for( segStart = segment->Next(); ; )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-09-16 14:13:02 +00:00
|
|
|
segStart = segment->GetTrace( segStart, NULL, START );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segStart )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
// the two segments must have the same width
|
|
|
|
if( segment->m_Width != segStart->m_Width )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
// it cannot be a via
|
2011-10-01 19:24:27 +00:00
|
|
|
if( segStart->Type() != PCB_TRACE_T )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// We must have only one segment connected
|
2007-10-19 19:58:31 +00:00
|
|
|
segStart->SetState( BUSY, ON );
|
2011-11-24 19:57:41 +00:00
|
|
|
other = segment->GetTrace( aFrame->GetBoard()->m_Track, NULL, START );
|
2007-10-19 19:58:31 +00:00
|
|
|
segStart->SetState( BUSY, OFF );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( other == NULL )
|
2012-02-19 04:02:19 +00:00
|
|
|
flag = 1; // OK
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
if( flag ) // We have the starting point of the segment is connected to an other segment
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-12-12 14:02:37 +00:00
|
|
|
segDelete = MergeColinearSegmentIfPossible( aFrame->GetBoard(), segment, segStart,
|
|
|
|
START );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
if( segDelete )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2010-11-21 18:28:32 +00:00
|
|
|
no_inc = 1;
|
2007-10-19 23:02:11 +00:00
|
|
|
segDelete->DeleteStructure();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// search for a possible point that connects on the END point of the segment:
|
2007-10-19 23:02:11 +00:00
|
|
|
for( segEnd = segment->Next(); ; )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-09-16 14:13:02 +00:00
|
|
|
segEnd = segment->GetTrace( segEnd, NULL, END );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segEnd )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
if( segment->m_Width != segEnd->m_Width )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( segEnd->Type() != PCB_TRACE_T )
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
// We must have only one segment connected
|
2007-10-19 19:58:31 +00:00
|
|
|
segEnd->SetState( BUSY, ON );
|
2011-11-24 19:57:41 +00:00
|
|
|
other = segment->GetTrace( aFrame->GetBoard()->m_Track, NULL, END );
|
2007-10-19 19:58:31 +00:00
|
|
|
segEnd->SetState( BUSY, OFF );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 19:58:31 +00:00
|
|
|
if( other == NULL )
|
2012-02-19 04:02:19 +00:00
|
|
|
flag |= 2; // Ok
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2007-08-10 19:14:51 +00:00
|
|
|
break;
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
if( flag & 2 ) // We have the ending point of the segment is connected to an other segment
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
segDelete = MergeColinearSegmentIfPossible( aFrame->GetBoard(), segment, segEnd, END );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
if( segDelete )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-19 19:58:31 +00:00
|
|
|
no_inc = 1;
|
2007-10-19 23:02:11 +00:00
|
|
|
segDelete->DeleteStructure();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
if( no_inc ) // The current segment was modified, retry to merge it
|
2009-06-11 18:30:03 +00:00
|
|
|
nextsegment = segment->Next();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
/** Function used by clean_segments.
|
2011-11-15 19:21:16 +00:00
|
|
|
* Test alignment of aTrackRef and aCandidate (which must have a common end).
|
2007-10-27 18:05:50 +00:00
|
|
|
* and see if the common point is not on a pad (i.e. if this common point can be removed).
|
2011-11-15 19:21:16 +00:00
|
|
|
* the ending point of pt_ref is the start point (aEndType == START)
|
|
|
|
* or the end point (aEndType != START)
|
|
|
|
* if the common point can be deleted, this function
|
|
|
|
* change the common point coordinate of the aTrackRef segm
|
2007-10-27 18:05:50 +00:00
|
|
|
* (and therefore connect the 2 other ending points)
|
2011-11-15 19:21:16 +00:00
|
|
|
* and return aCandidate (which can be deleted).
|
2007-10-27 18:05:50 +00:00
|
|
|
* else return NULL
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2011-12-12 14:02:37 +00:00
|
|
|
TRACK* MergeColinearSegmentIfPossible( BOARD* aPcb, TRACK* aTrackRef, TRACK* aCandidate,
|
|
|
|
int aEndType )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-11-15 19:21:16 +00:00
|
|
|
if( aTrackRef->m_Width != aCandidate->m_Width )
|
|
|
|
return NULL;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-11-15 19:21:16 +00:00
|
|
|
bool is_colinear = false;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-11-15 19:21:16 +00:00
|
|
|
// Trivial case: superimposed tracks ( tracks, not vias ):
|
|
|
|
if( aTrackRef->Type() == PCB_TRACE_T && aCandidate->Type() == PCB_TRACE_T )
|
|
|
|
{
|
|
|
|
if( aTrackRef->m_Start == aCandidate->m_Start )
|
|
|
|
if( aTrackRef->m_End == aCandidate->m_End )
|
|
|
|
return aCandidate;
|
|
|
|
|
|
|
|
if( aTrackRef->m_Start == aCandidate->m_End )
|
|
|
|
if( aTrackRef->m_End == aCandidate->m_Start )
|
|
|
|
return aCandidate;
|
|
|
|
}
|
|
|
|
|
|
|
|
int refdx = aTrackRef->m_End.x - aTrackRef->m_Start.x;
|
|
|
|
int refdy = aTrackRef->m_End.y - aTrackRef->m_Start.y;
|
|
|
|
|
|
|
|
int segmdx = aCandidate->m_End.x - aCandidate->m_Start.x;
|
|
|
|
int segmdy = aCandidate->m_End.y - aCandidate->m_Start.y;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2007-10-27 18:05:50 +00:00
|
|
|
// test for vertical alignment (easy to handle)
|
2007-08-10 19:14:51 +00:00
|
|
|
if( refdx == 0 )
|
|
|
|
{
|
|
|
|
if( segmdx != 0 )
|
|
|
|
return NULL;
|
|
|
|
else
|
2011-11-15 19:21:16 +00:00
|
|
|
is_colinear = true;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-27 18:05:50 +00:00
|
|
|
// test for horizontal alignment (easy to handle)
|
2007-08-10 19:14:51 +00:00
|
|
|
if( refdy == 0 )
|
|
|
|
{
|
|
|
|
if( segmdy != 0 )
|
|
|
|
return NULL;
|
|
|
|
else
|
2011-11-15 19:21:16 +00:00
|
|
|
is_colinear = true;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
/* test if alignment in other cases
|
2011-11-24 19:57:41 +00:00
|
|
|
* We must have refdy/refdx == segmdy/segmdx, (i.e. same slope)
|
|
|
|
* or refdy * segmdx == segmdy * refdx
|
|
|
|
*/
|
2011-11-15 19:21:16 +00:00
|
|
|
if( is_colinear == false )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
if( ( double)refdy * segmdx != (double)refdx * segmdy )
|
2007-08-10 19:14:51 +00:00
|
|
|
return NULL;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-11-15 19:21:16 +00:00
|
|
|
is_colinear = true;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-27 18:05:50 +00:00
|
|
|
/* Here we have 2 aligned segments:
|
2011-09-15 17:58:35 +00:00
|
|
|
* We must change the pt_ref common point only if not on a pad
|
|
|
|
* (this function) is called when there is only 2 connected segments,
|
|
|
|
*and if this point is not on a pad, it can be removed and the 2 segments will be merged
|
|
|
|
*/
|
2011-11-15 19:21:16 +00:00
|
|
|
if( aEndType == START )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-15 19:21:16 +00:00
|
|
|
// We must not have a pad, which is a always terminal point for a track
|
2011-12-03 14:04:17 +00:00
|
|
|
if( aPcb->GetPadFast( aTrackRef->m_Start, aTrackRef->ReturnMaskLayer() ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
/* change the common point coordinate of pt_segm to use the other point
|
|
|
|
* of pt_segm (pt_segm will be removed later) */
|
2011-11-15 19:21:16 +00:00
|
|
|
if( aTrackRef->m_Start == aCandidate->m_Start )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-15 19:21:16 +00:00
|
|
|
aTrackRef->m_Start = aCandidate->m_End;
|
|
|
|
return aCandidate;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-10-27 18:05:50 +00:00
|
|
|
else
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-15 19:21:16 +00:00
|
|
|
aTrackRef->m_Start = aCandidate->m_Start;
|
|
|
|
return aCandidate;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-15 19:21:16 +00:00
|
|
|
else // aEndType == END
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-15 19:21:16 +00:00
|
|
|
// We must not have a pad, which is a always terminal point for a track
|
2011-12-03 14:04:17 +00:00
|
|
|
if( aPcb->GetPadFast( aTrackRef->m_End, aTrackRef->ReturnMaskLayer() ) )
|
2007-08-10 19:14:51 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
/* change the common point coordinate of pt_segm to use the other point
|
|
|
|
* of pt_segm (pt_segm will be removed later) */
|
2011-11-15 19:21:16 +00:00
|
|
|
if( aTrackRef->m_End == aCandidate->m_Start )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-15 19:21:16 +00:00
|
|
|
aTrackRef->m_End = aCandidate->m_End;
|
|
|
|
return aCandidate;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-10-27 18:05:50 +00:00
|
|
|
else
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-15 19:21:16 +00:00
|
|
|
aTrackRef->m_End = aCandidate->m_Start;
|
|
|
|
return aCandidate;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
return NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
bool PCB_EDIT_FRAME::RemoveMisConnectedTracks()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-01-26 09:37:36 +00:00
|
|
|
/* finds all track segments which are mis-connected (to more than one net).
|
|
|
|
* When such a bad segment is found, it is flagged to be removed.
|
|
|
|
* All tracks having at least one flagged segment are removed.
|
|
|
|
*/
|
2007-10-15 03:26:38 +00:00
|
|
|
TRACK* segment;
|
|
|
|
TRACK* other;
|
|
|
|
TRACK* next;
|
2007-08-10 19:14:51 +00:00
|
|
|
int net_code_s, net_code_e;
|
2010-11-21 18:28:32 +00:00
|
|
|
bool isModified = false;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2010-04-16 16:28:35 +00:00
|
|
|
for( segment = GetBoard()->m_Track; segment; segment = (TRACK*) segment->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-15 03:26:38 +00:00
|
|
|
segment->SetState( FLAG0, OFF );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
// find the netcode for segment using anything connected to the "start" of "segment"
|
2007-08-10 19:14:51 +00:00
|
|
|
net_code_s = -1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( segment->start && segment->start->Type()==PCB_PAD_T )
|
2007-10-15 03:26:38 +00:00
|
|
|
{
|
|
|
|
// get the netcode of the pad to propagate.
|
|
|
|
net_code_s = ((D_PAD*)(segment->start))->GetNet();
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
|
|
|
{
|
2011-09-16 14:13:02 +00:00
|
|
|
other = segment->GetTrace( GetBoard()->m_Track, NULL, START );
|
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
if( other )
|
|
|
|
net_code_s = other->GetNet();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-08-10 19:14:51 +00:00
|
|
|
if( net_code_s < 0 )
|
2007-10-15 03:26:38 +00:00
|
|
|
continue; // the "start" of segment is not connected
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
// find the netcode for segment using anything connected to the "end" of "segment"
|
2007-08-10 19:14:51 +00:00
|
|
|
net_code_e = -1;
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( segment->end && segment->end->Type()==PCB_PAD_T )
|
2007-10-15 03:26:38 +00:00
|
|
|
{
|
|
|
|
net_code_e = ((D_PAD*)(segment->end))->GetNet();
|
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
else
|
|
|
|
{
|
2011-09-16 14:13:02 +00:00
|
|
|
other = segment->GetTrace( GetBoard()->m_Track, NULL, END );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
if( other )
|
|
|
|
net_code_e = other->GetNet();
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( net_code_e < 0 )
|
2007-10-15 03:26:38 +00:00
|
|
|
continue; // the "end" of segment is not connected
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
// Netcodes do not agree, so mark the segment as "to be removed"
|
2007-08-10 19:14:51 +00:00
|
|
|
if( net_code_s != net_code_e )
|
|
|
|
{
|
2007-10-15 03:26:38 +00:00
|
|
|
segment->SetState( FLAG0, ON );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
// Remove tracks having a flagged segment
|
2010-04-16 16:28:35 +00:00
|
|
|
for( segment = GetBoard()->m_Track; segment; segment = next )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-15 03:26:38 +00:00
|
|
|
next = (TRACK*) segment->Next();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
if( segment->GetState( FLAG0 ) ) // Segment is flagged to be removed
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-15 03:26:38 +00:00
|
|
|
segment->SetState( FLAG0, OFF );
|
2010-11-21 18:28:32 +00:00
|
|
|
isModified = true;
|
2010-04-16 16:28:35 +00:00
|
|
|
GetBoard()->m_Status_Pcb = 0;
|
2012-01-26 09:37:36 +00:00
|
|
|
Remove_One_Track( NULL, segment );
|
2011-09-15 17:58:35 +00:00
|
|
|
|
2012-01-26 09:37:36 +00:00
|
|
|
// the current segment is deleted,
|
|
|
|
// we do not know the next "not yet tested" segment,
|
|
|
|
// so restart to the beginning
|
2010-11-21 18:28:32 +00:00
|
|
|
next = GetBoard()->m_Track;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-21 18:28:32 +00:00
|
|
|
return isModified;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-22 07:13:27 +00:00
|
|
|
#if defined(CONN2PAD_ENBL)
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
/**
|
|
|
|
* Function ConnectDanglingEndToPad
|
|
|
|
* looks for vias which have no netcode and which are in electrical contact
|
|
|
|
* with a track to the degree that the track's end point falls on the via.
|
|
|
|
* Note that this is not a rigorous electrical check, but is better than
|
|
|
|
* testing for the track endpoint equaling the via center. When such a via
|
|
|
|
* is found, then add a small track to bridge from the overlapping track to
|
2008-03-10 15:00:22 +00:00
|
|
|
* the via and change the via's netcode so that subsequent continuity checks
|
|
|
|
* can be done with the faster equality algorithm.
|
2007-10-19 23:02:11 +00:00
|
|
|
*/
|
|
|
|
static void ConnectDanglingEndToVia( BOARD* pcb )
|
|
|
|
{
|
|
|
|
for( TRACK* track = pcb->m_Track; track; track = track->Next() )
|
|
|
|
{
|
|
|
|
SEGVIA* via;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
if( track->Type()!=PCB_VIA_T || (via = (SEGVIA*)track)->GetNet()!=0 )
|
2007-10-19 23:02:11 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for( TRACK* other = pcb->m_Track; other; other = other->Next() )
|
|
|
|
{
|
|
|
|
if( other == track )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !via->IsOnLayer( other->GetLayer() ) )
|
|
|
|
continue;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
// if the other track's m_End does not match the via position, and the track's
|
|
|
|
// m_Start is within the bounds of the via, and the other track has no start
|
|
|
|
if( other->m_End != via->GetPosition() && via->HitTest( other->m_Start )
|
|
|
|
&& !other->start )
|
2007-10-19 23:02:11 +00:00
|
|
|
{
|
2012-01-14 19:50:32 +00:00
|
|
|
TRACK* newTrack = (TRACK*)other->Clone();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
pcb->m_Track.Insert( newTrack, other->Next() );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-12-01 03:42:52 +00:00
|
|
|
newTrack->m_End = via->GetPosition();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
newTrack->start = other;
|
|
|
|
newTrack->end = via;
|
|
|
|
other->start = newTrack;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
via->SetNet( other->GetNet() );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
if( !via->start )
|
|
|
|
via->start = other;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
if( !via->end )
|
|
|
|
via->end = other;
|
|
|
|
}
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
// if the other track's m_Start does not match the via position, and the track's
|
|
|
|
// m_End is within the bounds of the via, and the other track has no end
|
|
|
|
else if( other->m_Start != via->GetPosition() && via->HitTest( other->m_End )
|
|
|
|
&& !other->end )
|
2007-10-19 23:02:11 +00:00
|
|
|
{
|
2012-01-14 19:50:32 +00:00
|
|
|
TRACK* newTrack = (TRACK*)other->Clone();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
|
|
|
pcb->m_Track.Insert( newTrack, other->Next() );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-12-01 03:42:52 +00:00
|
|
|
newTrack->m_Start = via->GetPosition();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
newTrack->start = via;
|
|
|
|
newTrack->end = other;
|
|
|
|
other->end = newTrack;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
via->SetNet( other->GetNet() );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
if( !via->start )
|
|
|
|
via->start = other;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-19 23:02:11 +00:00
|
|
|
if( !via->end )
|
|
|
|
via->end = other;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
/**
|
|
|
|
* Function ConnectDanglingEndToPad
|
|
|
|
* possibly adds a segment to the end of any and all tracks if their end is not exactly
|
2008-03-10 15:00:22 +00:00
|
|
|
* connected into the center of the pad. This allows faster control of
|
2007-10-15 03:26:38 +00:00
|
|
|
* connections.
|
2007-08-10 19:14:51 +00:00
|
|
|
*/
|
2011-11-24 19:57:41 +00:00
|
|
|
void ConnectDanglingEndToPad( PCB_EDIT_FRAME* aFrame )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-10-15 03:26:38 +00:00
|
|
|
TRACK* segment;
|
2011-09-07 19:41:04 +00:00
|
|
|
int nb_new_trace = 0;
|
2007-08-10 19:14:51 +00:00
|
|
|
wxString msg;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
aFrame->GetCanvas()->SetAbortRequest( false );
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
for( segment = aFrame->GetBoard()->m_Track; segment; segment = segment->Next() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2007-10-15 03:26:38 +00:00
|
|
|
D_PAD* pad;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
if( aFrame->GetCanvas()->GetAbortRequest() )
|
2010-11-21 18:28:32 +00:00
|
|
|
return;
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
pad = aFrame->GetBoard()->GetPad( segment, START );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
if( pad )
|
2008-03-10 15:00:22 +00:00
|
|
|
{
|
2011-11-15 19:21:16 +00:00
|
|
|
// test if the track start point is not exactly starting on the pad
|
2012-02-19 04:02:19 +00:00
|
|
|
if( segment->m_Start != pad->GetPosition() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
if( segment->GetTrace( aFrame->GetBoard()->m_Track, NULL, START ) == NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-02-19 04:02:19 +00:00
|
|
|
TRACK* newTrack = (TRACK*) segment->Clone();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->GetBoard()->m_Track.Insert( newTrack, segment->Next() );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
newTrack->m_End = pad->GetPosition();
|
2007-10-15 03:26:38 +00:00
|
|
|
newTrack->start = segment;
|
|
|
|
newTrack->end = pad;
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
nb_new_trace++;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
pad = aFrame->GetBoard()->GetPad( segment, END );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
if( pad )
|
2008-03-10 15:00:22 +00:00
|
|
|
{
|
2011-11-15 19:21:16 +00:00
|
|
|
// test if the track end point is not exactly on the pad
|
2012-02-19 04:02:19 +00:00
|
|
|
if( segment->m_End != pad->GetPosition() )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2011-11-24 19:57:41 +00:00
|
|
|
if( segment->GetTrace( aFrame->GetBoard()->m_Track, NULL, END ) == NULL )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-01-14 19:50:32 +00:00
|
|
|
TRACK* newTrack = (TRACK*)segment->Clone();
|
2008-12-04 04:28:11 +00:00
|
|
|
|
2011-11-24 19:57:41 +00:00
|
|
|
aFrame->GetBoard()->m_Track.Insert( newTrack, segment->Next() );
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2012-02-19 04:02:19 +00:00
|
|
|
newTrack->m_Start = pad->GetPosition();
|
2008-03-10 15:00:22 +00:00
|
|
|
|
2007-10-15 03:26:38 +00:00
|
|
|
newTrack->start = pad;
|
|
|
|
newTrack->end = segment;
|
2011-09-07 19:41:04 +00:00
|
|
|
nb_new_trace++;
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|