2011-12-12 14:02:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-02-04 13:34:17 +00:00
|
|
|
* Copyright (C) 2004-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-06-22 14:24:07 +00:00
|
|
|
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
2022-03-14 17:12:20 +00:00
|
|
|
* Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-12-12 14:02:37 +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
|
|
|
|
*/
|
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
#include <reporter.h>
|
2016-11-28 14:31:28 +00:00
|
|
|
#include <board_commit.h>
|
2020-06-17 12:46:50 +00:00
|
|
|
#include <cleanup_item.h>
|
2018-10-12 06:17:15 +00:00
|
|
|
#include <connectivity/connectivity_algo.h>
|
|
|
|
#include <connectivity/connectivity_data.h>
|
2018-02-04 13:34:17 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
2019-06-03 20:06:58 +00:00
|
|
|
#include <tools/global_edit_tool.h>
|
2020-10-26 18:36:25 +00:00
|
|
|
#include <drc/drc_rtree.h>
|
2019-03-31 09:37:57 +00:00
|
|
|
#include <tracks_cleaner.h>
|
2007-10-19 23:02:11 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
TRACKS_CLEANER::TRACKS_CLEANER( BOARD* aPcb, BOARD_COMMIT& aCommit ) :
|
|
|
|
m_brd( aPcb ),
|
|
|
|
m_commit( aCommit ),
|
|
|
|
m_dryRun( true ),
|
2022-03-14 17:12:20 +00:00
|
|
|
m_itemsList( nullptr ),
|
|
|
|
m_reporter( nullptr )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
2007-06-14 05:31:55 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2021-06-01 15:13:43 +00:00
|
|
|
/* Main cleaning function.
|
|
|
|
* Delete
|
|
|
|
* - Redundant points on tracks (merge aligned segments)
|
|
|
|
* - vias on pad
|
|
|
|
* - null length segments
|
|
|
|
*/
|
2022-04-23 20:04:43 +00:00
|
|
|
void TRACKS_CLEANER::CleanupBoard( bool aDryRun,
|
|
|
|
std::vector<std::shared_ptr<CLEANUP_ITEM> >* aItemsList,
|
2021-06-01 15:13:43 +00:00
|
|
|
bool aRemoveMisConnected, bool aCleanVias, bool aMergeSegments,
|
2022-04-23 20:04:43 +00:00
|
|
|
bool aDeleteUnconnected, bool aDeleteTracksinPad,
|
|
|
|
bool aDeleteDanglingVias, REPORTER* aReporter )
|
2007-06-14 05:31:55 +00:00
|
|
|
{
|
2022-03-14 17:12:20 +00:00
|
|
|
m_reporter = aReporter;
|
2020-07-31 04:21:25 +00:00
|
|
|
bool has_deleted = false;
|
|
|
|
|
2021-06-01 15:13:43 +00:00
|
|
|
m_dryRun = aDryRun;
|
|
|
|
m_itemsList = aItemsList;
|
2010-11-21 18:28:32 +00:00
|
|
|
|
2022-03-14 17:12:20 +00:00
|
|
|
if( m_reporter )
|
2022-03-18 11:04:17 +00:00
|
|
|
{
|
2022-04-23 20:04:43 +00:00
|
|
|
if( aDryRun )
|
|
|
|
m_reporter->Report( _( "Checking null tracks and vias..." ) );
|
|
|
|
else
|
|
|
|
m_reporter->Report( _( "Removing null tracks and vias..." ) );
|
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
wxSafeYield(); // Timeslice to update UI
|
|
|
|
}
|
2022-03-14 17:12:20 +00:00
|
|
|
|
|
|
|
bool removeNullSegments = aMergeSegments || aRemoveMisConnected;
|
|
|
|
cleanup( aCleanVias, removeNullSegments, aMergeSegments /* dup segments*/, aMergeSegments );
|
|
|
|
|
|
|
|
if( m_reporter )
|
2022-03-18 11:04:17 +00:00
|
|
|
{
|
2022-04-23 20:04:43 +00:00
|
|
|
if( aDryRun )
|
|
|
|
m_reporter->Report( _( "Checking redundant tracks..." ) );
|
|
|
|
else
|
|
|
|
m_reporter->Report( _( "Removing redundant tracks..." ) );
|
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
wxSafeYield(); // Timeslice to update UI
|
|
|
|
}
|
2022-03-14 17:12:20 +00:00
|
|
|
|
2022-04-23 20:04:43 +00:00
|
|
|
cleanup( false, false, true, aMergeSegments );
|
2016-09-30 09:09:17 +00:00
|
|
|
|
2021-06-01 15:13:43 +00:00
|
|
|
if( aRemoveMisConnected )
|
2022-03-14 17:12:20 +00:00
|
|
|
{
|
|
|
|
if( m_reporter )
|
2022-03-18 11:04:17 +00:00
|
|
|
{
|
2022-04-23 20:04:43 +00:00
|
|
|
if( aDryRun )
|
|
|
|
m_reporter->Report( _( "Checking shorting tracks..." ) );
|
|
|
|
else
|
|
|
|
m_reporter->Report( _( "Removing shorting tracks..." ) );
|
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
wxSafeYield(); // Timeslice to update UI
|
|
|
|
}
|
2022-03-14 17:12:20 +00:00
|
|
|
|
2020-08-18 18:32:43 +00:00
|
|
|
removeShortingTrackSegments();
|
2022-03-14 17:12:20 +00:00
|
|
|
}
|
2015-05-01 15:01:09 +00:00
|
|
|
|
2021-06-01 15:13:43 +00:00
|
|
|
if( aDeleteTracksinPad )
|
2022-03-14 17:12:20 +00:00
|
|
|
{
|
|
|
|
if( m_reporter )
|
2022-03-18 11:04:17 +00:00
|
|
|
{
|
2022-04-23 20:04:43 +00:00
|
|
|
if( aDryRun )
|
|
|
|
m_reporter->Report( _( "Checking tracks in pads..." ) );
|
|
|
|
else
|
|
|
|
m_reporter->Report( _( "Removing tracks in pads..." ) );
|
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
wxSafeYield(); // Timeslice to update UI
|
|
|
|
}
|
2022-03-14 17:12:20 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
deleteTracksInPads();
|
2022-03-14 17:12:20 +00:00
|
|
|
}
|
2019-06-01 16:49:33 +00:00
|
|
|
|
2022-04-23 20:04:43 +00:00
|
|
|
if( aDeleteUnconnected || aDeleteDanglingVias )
|
|
|
|
{
|
|
|
|
if( m_reporter )
|
|
|
|
{
|
|
|
|
if( aDryRun )
|
|
|
|
{
|
|
|
|
m_reporter->Report( _( "Checking dangling tracks and vias..." ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( aDeleteUnconnected )
|
|
|
|
m_reporter->Report( _( "Removing dangling tracks..." ) );
|
|
|
|
|
|
|
|
if( aDeleteDanglingVias )
|
|
|
|
m_reporter->Report( _( "Removing dangling vias..." ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSafeYield(); // Timeslice to update UI
|
|
|
|
}
|
|
|
|
|
|
|
|
has_deleted = deleteDanglingTracks( aDeleteUnconnected, aDeleteDanglingVias );
|
|
|
|
}
|
2020-07-31 04:21:25 +00:00
|
|
|
|
2021-06-01 15:13:43 +00:00
|
|
|
if( has_deleted && aMergeSegments )
|
2022-03-14 17:12:20 +00:00
|
|
|
{
|
|
|
|
if( m_reporter )
|
2022-03-18 11:04:17 +00:00
|
|
|
{
|
2022-04-23 20:04:43 +00:00
|
|
|
if( aDryRun )
|
|
|
|
m_reporter->Report( _( "Checking collinear tracks..." ) );
|
|
|
|
else
|
|
|
|
m_reporter->Report( _( "Merging collinear tracks..." ) );
|
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
wxSafeYield(); // Timeslice to update UI
|
|
|
|
}
|
2022-03-14 17:12:20 +00:00
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
cleanup( false, false, false, true );
|
2022-03-14 17:12:20 +00:00
|
|
|
}
|
2012-09-07 19:29:44 +00:00
|
|
|
}
|
2007-06-14 05:31:55 +00:00
|
|
|
|
2011-09-15 17:58:35 +00:00
|
|
|
|
2020-08-18 18:32:43 +00:00
|
|
|
void TRACKS_CLEANER::removeShortingTrackSegments()
|
2016-09-30 16:33:46 +00:00
|
|
|
{
|
2020-06-17 12:46:50 +00:00
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_brd->GetConnectivity();
|
2016-09-30 16:33:46 +00:00
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
std::set<BOARD_ITEM *> toRemove;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* segment : m_brd->Tracks() )
|
2016-09-30 16:33:46 +00:00
|
|
|
{
|
2021-02-16 18:20:03 +00:00
|
|
|
// Assume that the user knows what they are doing
|
|
|
|
if( segment->IsLocked() )
|
|
|
|
continue;
|
|
|
|
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* testedPad : connectivity->GetConnectedPads( segment ) )
|
2016-09-30 16:33:46 +00:00
|
|
|
{
|
2017-03-22 13:51:07 +00:00
|
|
|
if( segment->GetNetCode() != testedPad->GetNetCode() )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
2020-08-18 18:32:43 +00:00
|
|
|
std::shared_ptr<CLEANUP_ITEM> item;
|
|
|
|
|
|
|
|
if( segment->Type() == PCB_VIA_T )
|
|
|
|
item = std::make_shared<CLEANUP_ITEM>( CLEANUP_SHORTING_VIA );
|
|
|
|
else
|
|
|
|
item = std::make_shared<CLEANUP_ITEM>( CLEANUP_SHORTING_TRACK );
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
item->SetItems( segment );
|
2020-03-16 11:05:01 +00:00
|
|
|
m_itemsList->push_back( item );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
toRemove.insert( segment );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2016-09-30 16:33:46 +00:00
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* testedTrack : connectivity->GetConnectedTracks( segment ) )
|
2016-09-30 16:33:46 +00:00
|
|
|
{
|
2020-06-27 16:06:01 +00:00
|
|
|
if( segment->GetNetCode() != testedTrack->GetNetCode() )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
2020-08-18 18:32:43 +00:00
|
|
|
std::shared_ptr<CLEANUP_ITEM> item;
|
|
|
|
|
|
|
|
if( segment->Type() == PCB_VIA_T )
|
|
|
|
item = std::make_shared<CLEANUP_ITEM>( CLEANUP_SHORTING_VIA );
|
|
|
|
else
|
|
|
|
item = std::make_shared<CLEANUP_ITEM>( CLEANUP_SHORTING_TRACK );
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
item->SetItems( segment );
|
2020-03-16 11:05:01 +00:00
|
|
|
m_itemsList->push_back( item );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2017-06-22 14:24:07 +00:00
|
|
|
toRemove.insert( segment );
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
2016-09-30 16:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
if( !m_dryRun )
|
|
|
|
removeItems( toRemove );
|
2016-09-30 16:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
bool TRACKS_CLEANER::testTrackEndpointIsNode( PCB_TRACK* aTrack, bool aTstStart )
|
2019-06-28 18:23:09 +00:00
|
|
|
{
|
|
|
|
// A node is a point where more than 2 items are connected.
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
const std::list<CN_ITEM*>& items =
|
|
|
|
m_brd->GetConnectivity()->GetConnectivityAlgo()->ItemEntry( aTrack ).GetItems();
|
2019-06-28 18:23:09 +00:00
|
|
|
|
|
|
|
if( items.empty() )
|
|
|
|
return false;
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
CN_ITEM* citem = items.front();
|
2019-06-28 18:23:09 +00:00
|
|
|
|
|
|
|
if( !citem->Valid() )
|
|
|
|
return false;
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
const std::vector<std::shared_ptr<CN_ANCHOR>>& anchors = citem->Anchors();
|
2019-06-28 18:23:09 +00:00
|
|
|
|
|
|
|
VECTOR2I refpoint = aTstStart ? aTrack->GetStart() : aTrack->GetEnd();
|
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
for( const std::shared_ptr<CN_ANCHOR>& anchor : anchors )
|
2019-06-28 18:23:09 +00:00
|
|
|
{
|
|
|
|
if( anchor->Pos() != refpoint )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// The right anchor point is found: if more than one other item
|
|
|
|
// (pad, via, track...) is connected, it is a node:
|
|
|
|
return anchor->ConnectedItemsCount() > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-08 16:36:18 +00:00
|
|
|
bool TRACKS_CLEANER::deleteDanglingTracks( bool aTrack, bool aVia )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2017-06-22 14:24:07 +00:00
|
|
|
bool item_erased = false;
|
2012-09-07 19:29:44 +00:00
|
|
|
bool modified = false;
|
2016-09-30 09:09:17 +00:00
|
|
|
|
2021-01-08 16:36:18 +00:00
|
|
|
if( !aTrack && !aVia )
|
|
|
|
return false;
|
|
|
|
|
2014-04-30 19:16:22 +00:00
|
|
|
do // Iterate when at least one track is deleted
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2012-09-07 19:29:44 +00:00
|
|
|
item_erased = false;
|
2021-08-01 14:48:12 +00:00
|
|
|
// Ensure the connectivity is up to date, especially after removing a dangling segment
|
2019-06-28 13:14:17 +00:00
|
|
|
m_brd->BuildConnectivity();
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2020-06-04 17:43:05 +00:00
|
|
|
// Keep a duplicate deque to all deleting in the primary
|
2021-06-11 21:07:02 +00:00
|
|
|
std::deque<PCB_TRACK*> temp_tracks( m_brd->Tracks() );
|
2020-06-04 17:43:05 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : temp_tracks )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2021-08-01 14:48:12 +00:00
|
|
|
if( track->IsLocked() || ( track->GetFlags() & IS_DELETED ) > 0 )
|
2021-02-16 18:20:03 +00:00
|
|
|
continue;
|
|
|
|
|
2021-01-08 16:36:18 +00:00
|
|
|
if( !aVia && track->Type() == PCB_VIA_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !aTrack && ( track->Type() == PCB_TRACE_T || track->Type() == PCB_ARC_T ) )
|
2020-07-31 04:21:25 +00:00
|
|
|
continue;
|
|
|
|
|
2020-10-26 22:44:57 +00:00
|
|
|
// Test if a track (or a via) endpoint is not connected to another track or zone.
|
2020-08-05 20:15:27 +00:00
|
|
|
if( m_brd->GetConnectivity()->TestTrackEndpointDangling( track ) )
|
2011-09-07 19:41:04 +00:00
|
|
|
{
|
2020-10-26 22:44:57 +00:00
|
|
|
std::shared_ptr<CLEANUP_ITEM> item;
|
|
|
|
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
item = std::make_shared<CLEANUP_ITEM>( CLEANUP_DANGLING_VIA );
|
|
|
|
else
|
|
|
|
item = std::make_shared<CLEANUP_ITEM>( CLEANUP_DANGLING_TRACK );
|
|
|
|
|
2020-04-24 13:36:10 +00:00
|
|
|
item->SetItems( track );
|
2020-03-16 11:05:01 +00:00
|
|
|
m_itemsList->push_back( item );
|
2021-08-01 14:48:12 +00:00
|
|
|
track->SetFlags( IS_DELETED );
|
|
|
|
|
|
|
|
// keep iterating, because a track connected to the deleted track
|
|
|
|
// now perhaps is not connected and should be deleted
|
|
|
|
item_erased = true;
|
2016-12-07 15:52:48 +00:00
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
if( !m_dryRun )
|
|
|
|
{
|
|
|
|
m_brd->Remove( track );
|
|
|
|
m_commit.Removed( track );
|
|
|
|
modified = true;
|
|
|
|
}
|
2011-09-07 19:41:04 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2019-06-28 13:14:17 +00:00
|
|
|
} while( item_erased ); // A segment was erased: test for some new dangling segments
|
2012-09-07 19:29:44 +00:00
|
|
|
|
|
|
|
return modified;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
void TRACKS_CLEANER::deleteTracksInPads()
|
2019-06-01 16:49:33 +00:00
|
|
|
{
|
|
|
|
std::set<BOARD_ITEM*> toRemove;
|
|
|
|
|
|
|
|
// Delete tracks that start and end on the same pad
|
2020-06-17 12:46:50 +00:00
|
|
|
std::shared_ptr<CONNECTIVITY_DATA> connectivity = m_brd->GetConnectivity();
|
2019-06-01 16:49:33 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_brd->Tracks() )
|
2019-06-01 16:49:33 +00:00
|
|
|
{
|
2021-02-16 18:20:03 +00:00
|
|
|
if( track->IsLocked() )
|
|
|
|
continue;
|
|
|
|
|
2020-08-05 20:18:47 +00:00
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
continue;
|
|
|
|
|
2019-06-01 16:49:33 +00:00
|
|
|
// Mark track if connected to pads
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : connectivity->GetConnectedPads( track ) )
|
2019-06-01 16:49:33 +00:00
|
|
|
{
|
|
|
|
if( pad->HitTest( track->GetStart() ) && pad->HitTest( track->GetEnd() ) )
|
|
|
|
{
|
2020-08-06 20:52:24 +00:00
|
|
|
SHAPE_POLY_SET poly;
|
2020-10-13 10:55:24 +00:00
|
|
|
track->TransformShapeWithClearanceToPolygon( poly, track->GetLayer(), 0,
|
|
|
|
ARC_HIGH_DEF, ERROR_INSIDE );
|
2020-08-06 20:52:24 +00:00
|
|
|
|
|
|
|
poly.BooleanSubtract( *pad->GetEffectivePolygon(), SHAPE_POLY_SET::PM_FAST );
|
2019-06-01 16:49:33 +00:00
|
|
|
|
2020-08-06 20:52:24 +00:00
|
|
|
if( poly.IsEmpty() )
|
2020-10-13 10:55:24 +00:00
|
|
|
{
|
2021-08-01 14:48:12 +00:00
|
|
|
auto item = std::make_shared<CLEANUP_ITEM>( CLEANUP_TRACK_IN_PAD );
|
2020-10-13 10:55:24 +00:00
|
|
|
item->SetItems( track );
|
|
|
|
m_itemsList->push_back( item );
|
2020-08-06 20:52:24 +00:00
|
|
|
|
2020-10-13 10:55:24 +00:00
|
|
|
toRemove.insert( track );
|
2021-08-01 14:48:12 +00:00
|
|
|
track->SetFlags( IS_DELETED );
|
2020-08-06 20:52:24 +00:00
|
|
|
}
|
2019-06-01 16:49:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
if( !m_dryRun )
|
|
|
|
removeItems( toRemove );
|
2019-06-01 16:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
/**
|
|
|
|
* Geometry-based cleanup: duplicate items, null items, colinear items.
|
|
|
|
*/
|
|
|
|
void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegments,
|
|
|
|
bool aDeleteDuplicateSegments, bool aMergeSegments )
|
2019-05-31 02:30:28 +00:00
|
|
|
{
|
2020-10-26 18:36:25 +00:00
|
|
|
DRC_RTREE rtree;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_brd->Tracks() )
|
2020-10-26 18:36:25 +00:00
|
|
|
{
|
2020-10-26 22:44:57 +00:00
|
|
|
track->ClearFlags( IS_DELETED | SKIP_STRUCT );
|
2021-06-02 13:00:11 +00:00
|
|
|
rtree.Insert( track, track->GetLayer() );
|
2020-10-26 18:36:25 +00:00
|
|
|
}
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2019-05-31 02:30:28 +00:00
|
|
|
std::set<BOARD_ITEM*> toRemove;
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_brd->Tracks() )
|
2014-05-10 12:48:17 +00:00
|
|
|
{
|
2020-10-26 18:36:25 +00:00
|
|
|
if( track->HasFlag( IS_DELETED ) || track->IsLocked() )
|
2019-05-31 02:30:28 +00:00
|
|
|
continue;
|
2014-05-17 17:36:02 +00:00
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
if( aDeleteDuplicateVias && track->Type() == PCB_VIA_T )
|
2019-05-31 02:30:28 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_VIA* via = static_cast<PCB_VIA*>( track );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
if( via->GetStart() != via->GetEnd() )
|
|
|
|
via->SetEnd( via->GetStart() );
|
|
|
|
|
2020-11-02 16:20:00 +00:00
|
|
|
rtree.QueryColliding( via, via->GetLayer(), via->GetLayer(),
|
|
|
|
// Filter:
|
|
|
|
[&]( BOARD_ITEM* aItem ) -> bool
|
|
|
|
{
|
|
|
|
return aItem->Type() == PCB_VIA_T
|
|
|
|
&& !aItem->HasFlag( SKIP_STRUCT )
|
|
|
|
&& !aItem->HasFlag( IS_DELETED );
|
|
|
|
},
|
|
|
|
// Visitor:
|
2020-10-28 13:52:30 +00:00
|
|
|
[&]( BOARD_ITEM* aItem ) -> bool
|
2020-10-26 18:36:25 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_VIA* other = static_cast<PCB_VIA*>( aItem );
|
2020-10-26 18:36:25 +00:00
|
|
|
|
|
|
|
if( via->GetPosition() == other->GetPosition()
|
|
|
|
&& via->GetViaType() == other->GetViaType()
|
|
|
|
&& via->GetLayerSet() == other->GetLayerSet() )
|
|
|
|
{
|
|
|
|
auto item = std::make_shared<CLEANUP_ITEM>( CLEANUP_REDUNDANT_VIA );
|
|
|
|
item->SetItems( via );
|
|
|
|
m_itemsList->push_back( item );
|
|
|
|
|
|
|
|
via->SetFlags( IS_DELETED );
|
|
|
|
toRemove.insert( via );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
|
|
|
|
// To delete through Via on THT pads at same location
|
|
|
|
// Examine the list of connected pads: if a through pad is found, the via is redundant
|
2020-11-12 22:30:02 +00:00
|
|
|
for( PAD* pad : m_brd->GetConnectivity()->GetConnectedPads( via ) )
|
2020-10-26 18:36:25 +00:00
|
|
|
{
|
|
|
|
const LSET all_cu = LSET::AllCuMask();
|
|
|
|
|
|
|
|
if( ( pad->GetLayerSet() & all_cu ) == all_cu )
|
|
|
|
{
|
|
|
|
auto item = std::make_shared<CLEANUP_ITEM>( CLEANUP_REDUNDANT_VIA );
|
|
|
|
item->SetItems( via, pad );
|
|
|
|
m_itemsList->push_back( item );
|
|
|
|
|
|
|
|
via->SetFlags( IS_DELETED );
|
|
|
|
toRemove.insert( via );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-10-26 22:44:57 +00:00
|
|
|
|
|
|
|
via->SetFlags( SKIP_STRUCT );
|
2020-10-26 18:36:25 +00:00
|
|
|
}
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
if( aDeleteNullSegments && track->Type() != PCB_VIA_T )
|
|
|
|
{
|
|
|
|
if( track->IsNull() )
|
2019-05-31 02:30:28 +00:00
|
|
|
{
|
2020-10-26 18:36:25 +00:00
|
|
|
auto item = std::make_shared<CLEANUP_ITEM>( CLEANUP_ZERO_LENGTH_TRACK );
|
|
|
|
item->SetItems( track );
|
2020-03-16 11:05:01 +00:00
|
|
|
m_itemsList->push_back( item );
|
2019-05-31 02:30:28 +00:00
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
track->SetFlags( IS_DELETED );
|
|
|
|
toRemove.insert( track );
|
2014-05-17 17:36:02 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2020-10-26 18:36:25 +00:00
|
|
|
|
2022-01-29 00:31:41 +00:00
|
|
|
if( aDeleteDuplicateSegments && track->Type() == PCB_TRACE_T && !track->IsNull() )
|
2020-10-26 18:36:25 +00:00
|
|
|
{
|
2020-11-02 16:20:00 +00:00
|
|
|
rtree.QueryColliding( track, track->GetLayer(), track->GetLayer(),
|
|
|
|
// Filter:
|
|
|
|
[&]( BOARD_ITEM* aItem ) -> bool
|
|
|
|
{
|
|
|
|
return aItem->Type() == PCB_TRACE_T
|
|
|
|
&& !aItem->HasFlag( SKIP_STRUCT )
|
2022-01-29 00:31:41 +00:00
|
|
|
&& !aItem->HasFlag( IS_DELETED )
|
|
|
|
&& !static_cast<PCB_TRACK*>( aItem )->IsNull();
|
2020-11-02 16:20:00 +00:00
|
|
|
},
|
|
|
|
// Visitor:
|
2020-10-28 13:52:30 +00:00
|
|
|
[&]( BOARD_ITEM* aItem ) -> bool
|
2020-10-26 18:36:25 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK* other = static_cast<PCB_TRACK*>( aItem );
|
2020-10-26 18:36:25 +00:00
|
|
|
|
|
|
|
if( track->IsPointOnEnds( other->GetStart() )
|
|
|
|
&& track->IsPointOnEnds( other->GetEnd() )
|
|
|
|
&& track->GetWidth() == other->GetWidth()
|
|
|
|
&& track->GetLayer() == other->GetLayer() )
|
|
|
|
{
|
|
|
|
auto item = std::make_shared<CLEANUP_ITEM>( CLEANUP_DUPLICATE_TRACK );
|
|
|
|
item->SetItems( track );
|
|
|
|
m_itemsList->push_back( item );
|
|
|
|
|
|
|
|
track->SetFlags( IS_DELETED );
|
|
|
|
toRemove.insert( track );
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
2020-10-26 22:44:57 +00:00
|
|
|
|
|
|
|
track->SetFlags( SKIP_STRUCT );
|
2020-10-26 18:36:25 +00:00
|
|
|
}
|
2014-05-10 12:48:17 +00:00
|
|
|
}
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
if( !m_dryRun )
|
|
|
|
removeItems( toRemove );
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
if( aMergeSegments )
|
2014-05-10 12:48:17 +00:00
|
|
|
{
|
2020-10-26 18:36:25 +00:00
|
|
|
bool merged;
|
2021-05-31 21:36:27 +00:00
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
do
|
2020-07-31 06:03:27 +00:00
|
|
|
{
|
2020-10-26 18:36:25 +00:00
|
|
|
merged = false;
|
|
|
|
m_brd->BuildConnectivity();
|
2022-03-18 11:04:17 +00:00
|
|
|
|
2022-08-03 09:10:23 +00:00
|
|
|
std::shared_ptr<CN_CONNECTIVITY_ALGO> connectivity =
|
|
|
|
m_brd->GetConnectivity()->GetConnectivityAlgo();
|
2021-12-23 11:14:41 +00:00
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
// Keep a duplicate deque to all deleting in the primary
|
2021-06-11 21:07:02 +00:00
|
|
|
std::deque<PCB_TRACK*> temp_segments( m_brd->Tracks() );
|
2011-09-07 19:41:04 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
m_connectedItemsCache.clear();
|
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
// merge collinear segments:
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* segment : temp_segments )
|
2020-10-26 18:36:25 +00:00
|
|
|
{
|
2022-03-18 11:04:17 +00:00
|
|
|
// one can merge only collinear segments, not vias or arcs.
|
|
|
|
if( segment->Type() != PCB_TRACE_T )
|
2020-10-26 18:36:25 +00:00
|
|
|
continue;
|
2019-06-28 18:23:09 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( segment->HasFlag( IS_DELETED ) ) // already taken into account
|
2020-10-26 18:36:25 +00:00
|
|
|
continue;
|
2019-08-27 12:12:34 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
// for each end of the segment:
|
2021-12-23 11:14:41 +00:00
|
|
|
for( CN_ITEM* citem : connectivity->ItemEntry( segment ).GetItems() )
|
2020-10-26 18:36:25 +00:00
|
|
|
{
|
2021-12-23 11:14:41 +00:00
|
|
|
// Do not merge an end which has different width tracks attached -- it's a
|
|
|
|
// common use-case for necking-down a track between pads.
|
|
|
|
std::vector<PCB_TRACK*> sameWidthCandidates;
|
|
|
|
std::vector<PCB_TRACK*> differentWidthCandidates;
|
|
|
|
|
2020-10-26 18:36:25 +00:00
|
|
|
for( CN_ITEM* connected : citem->ConnectedItems() )
|
2020-07-31 06:03:27 +00:00
|
|
|
{
|
2020-10-26 18:36:25 +00:00
|
|
|
if( !connected->Valid() )
|
2020-07-31 06:03:27 +00:00
|
|
|
continue;
|
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
BOARD_CONNECTED_ITEM* candidate = connected->Parent();
|
2020-10-26 18:36:25 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( candidate->Type() == PCB_TRACE_T && !candidate->HasFlag( IS_DELETED ) )
|
2020-10-26 18:36:25 +00:00
|
|
|
{
|
2022-03-18 11:04:17 +00:00
|
|
|
PCB_TRACK* candidateSegment = static_cast<PCB_TRACK*>( candidate );
|
2020-10-26 18:36:25 +00:00
|
|
|
|
2021-12-23 11:14:41 +00:00
|
|
|
if( candidateSegment->GetWidth() == segment->GetWidth() )
|
2022-03-18 11:04:17 +00:00
|
|
|
{
|
2021-12-23 11:14:41 +00:00
|
|
|
sameWidthCandidates.push_back( candidateSegment );
|
2022-03-18 11:04:17 +00:00
|
|
|
}
|
2021-12-23 11:14:41 +00:00
|
|
|
else
|
2022-03-18 11:04:17 +00:00
|
|
|
{
|
2021-12-23 11:14:41 +00:00
|
|
|
differentWidthCandidates.push_back( candidateSegment );
|
2022-03-18 11:04:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-12-23 11:14:41 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-26 18:36:25 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( !differentWidthCandidates.empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for( PCB_TRACK* candidate : sameWidthCandidates )
|
2021-12-23 11:14:41 +00:00
|
|
|
{
|
2022-03-18 11:04:17 +00:00
|
|
|
if( segment->ApproxCollinear( *candidate )
|
|
|
|
&& mergeCollinearSegments( segment, candidate ) )
|
2021-12-23 11:14:41 +00:00
|
|
|
{
|
2022-03-18 11:04:17 +00:00
|
|
|
merged = true;
|
|
|
|
break;
|
2020-10-26 18:36:25 +00:00
|
|
|
}
|
2020-07-31 06:03:27 +00:00
|
|
|
}
|
2019-05-31 02:30:28 +00:00
|
|
|
}
|
2015-05-01 15:01:09 +00:00
|
|
|
}
|
2020-10-26 18:36:25 +00:00
|
|
|
} while( merged );
|
|
|
|
}
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : m_brd->Tracks() )
|
2020-10-26 22:44:57 +00:00
|
|
|
track->ClearFlags( IS_DELETED | SKIP_STRUCT );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 14:08:33 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
const std::vector<BOARD_CONNECTED_ITEM*>& TRACKS_CLEANER::getConnectedItems( PCB_TRACK* aTrack )
|
2014-05-10 12:48:17 +00:00
|
|
|
{
|
2022-03-18 11:04:17 +00:00
|
|
|
const std::shared_ptr<CONNECTIVITY_DATA>& connectivity = m_brd->GetConnectivity();
|
2007-08-10 19:14:51 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( m_connectedItemsCache.count( aTrack ) == 0 )
|
|
|
|
{
|
|
|
|
m_connectedItemsCache[ aTrack ] =
|
|
|
|
connectivity->GetConnectedItems( aTrack, { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
|
|
|
|
PCB_PAD_T, PCB_ZONE_T } );
|
|
|
|
}
|
2022-02-17 23:22:18 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
return m_connectedItemsCache[ aTrack ];
|
|
|
|
}
|
2022-02-17 23:22:18 +00:00
|
|
|
|
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
bool TRACKS_CLEANER::mergeCollinearSegments( PCB_TRACK* aSeg1, PCB_TRACK* aSeg2 )
|
|
|
|
{
|
|
|
|
if( aSeg1->IsLocked() || aSeg2->IsLocked() )
|
|
|
|
return false;
|
2022-02-17 23:22:18 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
// Collect the unique points where the two tracks are connected to other items
|
2022-02-17 23:22:18 +00:00
|
|
|
std::set<VECTOR2I> pts;
|
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
auto collectPts =
|
|
|
|
[&]( BOARD_CONNECTED_ITEM* citem )
|
|
|
|
{
|
|
|
|
if( citem->Type() == PCB_TRACE_T || citem->Type() == PCB_ARC_T
|
|
|
|
|| citem->Type() == PCB_VIA_T )
|
|
|
|
{
|
|
|
|
PCB_TRACK* track = static_cast<PCB_TRACK*>( citem );
|
2022-02-17 23:22:18 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( track->IsPointOnEnds( aSeg1->GetStart() ) )
|
|
|
|
pts.emplace( aSeg1->GetStart() );
|
2022-03-03 20:06:36 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( track->IsPointOnEnds( aSeg1->GetEnd() ) )
|
|
|
|
pts.emplace( aSeg1->GetEnd() );
|
2022-03-03 20:06:36 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( track->IsPointOnEnds( aSeg2->GetStart() ) )
|
|
|
|
pts.emplace( aSeg2->GetStart() );
|
2022-03-03 20:06:36 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( track->IsPointOnEnds( aSeg2->GetEnd() ) )
|
|
|
|
pts.emplace( aSeg2->GetEnd() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( citem->HitTest( aSeg1->GetStart(), ( aSeg1->GetWidth() + 1 ) / 2 ) )
|
|
|
|
pts.emplace( aSeg1->GetStart() );
|
2022-03-03 20:06:36 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( citem->HitTest( aSeg1->GetEnd(), ( aSeg1->GetWidth() + 1 ) / 2 ) )
|
|
|
|
pts.emplace( aSeg1->GetEnd() );
|
2022-02-17 23:22:18 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( citem->HitTest( aSeg2->GetStart(), ( aSeg2->GetWidth() + 1 ) / 2 ) )
|
|
|
|
pts.emplace( aSeg2->GetStart() );
|
2022-02-17 23:22:18 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
if( citem->HitTest( aSeg2->GetEnd(), ( aSeg2->GetWidth() + 1 ) / 2 ) )
|
|
|
|
pts.emplace( aSeg2->GetEnd() );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for( BOARD_CONNECTED_ITEM* item : getConnectedItems( aSeg1 ) )
|
|
|
|
{
|
|
|
|
if( item != aSeg1 && item != aSeg2 )
|
|
|
|
collectPts( item );
|
2022-02-17 23:22:18 +00:00
|
|
|
}
|
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
for( BOARD_CONNECTED_ITEM* item : getConnectedItems( aSeg2 ) )
|
|
|
|
{
|
|
|
|
if( item != aSeg1 && item != aSeg2 )
|
|
|
|
collectPts( item );
|
|
|
|
}
|
2022-03-03 20:06:36 +00:00
|
|
|
|
2022-02-17 23:22:18 +00:00
|
|
|
// This means there is a node in the center
|
|
|
|
if( pts.size() > 2 )
|
|
|
|
return false;
|
2017-06-22 14:24:07 +00:00
|
|
|
|
2019-06-28 18:23:09 +00:00
|
|
|
// Verify the removed point after merging is not a node.
|
|
|
|
// If it is a node (i.e. if more than one other item is connected, the segments cannot be merged
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_TRACK dummy_seg( *aSeg1 );
|
2019-06-28 18:23:09 +00:00
|
|
|
|
|
|
|
// Calculate the new ends of the segment to merge, and store them to dummy_seg:
|
|
|
|
int min_x = std::min( aSeg1->GetStart().x,
|
|
|
|
std::min( aSeg1->GetEnd().x, std::min( aSeg2->GetStart().x, aSeg2->GetEnd().x ) ) );
|
|
|
|
int min_y = std::min( aSeg1->GetStart().y,
|
|
|
|
std::min( aSeg1->GetEnd().y, std::min( aSeg2->GetStart().y, aSeg2->GetEnd().y ) ) );
|
|
|
|
int max_x = std::max( aSeg1->GetStart().x,
|
|
|
|
std::max( aSeg1->GetEnd().x, std::max( aSeg2->GetStart().x, aSeg2->GetEnd().x ) ) );
|
|
|
|
int max_y = std::max( aSeg1->GetStart().y,
|
|
|
|
std::max( aSeg1->GetEnd().y, std::max( aSeg2->GetStart().y, aSeg2->GetEnd().y ) ) );
|
|
|
|
|
|
|
|
if( ( aSeg1->GetStart().x > aSeg1->GetEnd().x )
|
|
|
|
== ( aSeg1->GetStart().y > aSeg1->GetEnd().y ) )
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
dummy_seg.SetStart( VECTOR2I( min_x, min_y ) );
|
|
|
|
dummy_seg.SetEnd( VECTOR2I( max_x, max_y ) );
|
2019-06-28 18:23:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
dummy_seg.SetStart( VECTOR2I( min_x, max_y ) );
|
|
|
|
dummy_seg.SetEnd( VECTOR2I( max_x, min_y ) );
|
2019-06-28 18:23:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-17 23:22:18 +00:00
|
|
|
// If the existing connected points are not the same as the points generated by our
|
|
|
|
// min/max alg, then assign the missing points to the end closest. This ensures that
|
Fix typos in pcbnew sub-directory
Found via `codespell -q 3 -S *.po,./thirdparty,./Documentation/changelogs -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,ba,busses,dout,einstance,leaded,modul,ontext,ot,overide,serie,te,,tesselate,tesselator,tht`
2022-06-29 20:21:10 +00:00
|
|
|
// our replacement track is still connected
|
2022-02-17 23:22:18 +00:00
|
|
|
for( auto pt : pts )
|
2019-06-28 18:23:09 +00:00
|
|
|
{
|
2022-02-17 23:22:18 +00:00
|
|
|
if( !dummy_seg.IsPointOnEnds( wxPoint( pt.x, pt.y ) ) )
|
|
|
|
{
|
|
|
|
if( ( VECTOR2I( dummy_seg.GetStart() ) - pt ).SquaredEuclideanNorm() <
|
|
|
|
( VECTOR2I( dummy_seg.GetEnd() ) - pt ).SquaredEuclideanNorm() )
|
|
|
|
dummy_seg.SetStart( wxPoint( pt.x, pt.y ) );
|
|
|
|
else
|
|
|
|
dummy_seg.SetEnd( wxPoint( pt.x, pt.y ) );
|
|
|
|
}
|
2019-06-28 18:23:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 03:43:04 +00:00
|
|
|
// Now find the removed end(s) and stop merging if it is a node:
|
|
|
|
if( aSeg1->GetStart() != dummy_seg.GetStart() && aSeg1->GetStart() != dummy_seg.GetEnd() )
|
|
|
|
{
|
|
|
|
if( testTrackEndpointIsNode( aSeg1, true ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aSeg1->GetEnd() != dummy_seg.GetStart() && aSeg1->GetEnd() != dummy_seg.GetEnd() )
|
|
|
|
{
|
|
|
|
if( testTrackEndpointIsNode( aSeg1, false ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-26 23:49:11 +00:00
|
|
|
std::shared_ptr<CLEANUP_ITEM> item = std::make_shared<CLEANUP_ITEM>( CLEANUP_MERGE_TRACKS );
|
2020-04-24 13:36:10 +00:00
|
|
|
item->SetItems( aSeg1, aSeg2 );
|
2020-03-16 11:05:01 +00:00
|
|
|
m_itemsList->push_back( item );
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2019-06-29 07:12:19 +00:00
|
|
|
aSeg2->SetFlags( IS_DELETED );
|
|
|
|
|
2019-03-31 09:37:57 +00:00
|
|
|
if( !m_dryRun )
|
2007-08-10 19:14:51 +00:00
|
|
|
{
|
2021-06-01 15:13:43 +00:00
|
|
|
m_commit.Modify( aSeg1 );
|
2019-06-28 18:23:09 +00:00
|
|
|
*aSeg1 = dummy_seg;
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2022-03-18 11:04:17 +00:00
|
|
|
m_brd->GetConnectivity()->Update( aSeg1 );
|
2019-06-01 16:49:33 +00:00
|
|
|
|
|
|
|
// Clear the status flags here after update.
|
2022-03-18 11:04:17 +00:00
|
|
|
for( PAD* pad : m_brd->GetConnectivity()->GetConnectedPads( aSeg1 ) )
|
2019-06-01 16:49:33 +00:00
|
|
|
{
|
|
|
|
aSeg1->SetState( BEGIN_ONPAD, pad->HitTest( aSeg1->GetStart() ) );
|
|
|
|
aSeg1->SetState( END_ONPAD, pad->HitTest( aSeg1->GetEnd() ) );
|
|
|
|
}
|
2019-03-31 09:37:57 +00:00
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Merge successful, seg2 has to go away
|
2019-05-31 02:30:28 +00:00
|
|
|
m_brd->Remove( aSeg2 );
|
2021-06-01 15:13:43 +00:00
|
|
|
m_commit.Removed( aSeg2 );
|
2019-05-31 02:30:28 +00:00
|
|
|
}
|
2020-07-31 06:03:27 +00:00
|
|
|
|
|
|
|
return true;
|
2019-03-31 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
void TRACKS_CLEANER::removeItems( std::set<BOARD_ITEM*>& aItems )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
2022-08-03 09:10:23 +00:00
|
|
|
for( BOARD_ITEM* item : aItems )
|
2019-03-31 09:37:57 +00:00
|
|
|
{
|
|
|
|
m_brd->Remove( item );
|
|
|
|
m_commit.Removed( item );
|
2007-08-10 19:14:51 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|