From c44855a647502cd3d0332495876e41155947319d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 26 Oct 2020 22:44:57 +0000 Subject: [PATCH] More performance enhancements for Cleanup Tracks and Vias. --- pcbnew/tracks_cleaner.cpp | 40 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/pcbnew/tracks_cleaner.cpp b/pcbnew/tracks_cleaner.cpp index 243d2833dd..1082892045 100644 --- a/pcbnew/tracks_cleaner.cpp +++ b/pcbnew/tracks_cleaner.cpp @@ -176,23 +176,19 @@ bool TRACKS_CLEANER::deleteDanglingTracks( bool aVia ) for( TRACK* track : temp_tracks ) { - bool flag_erase = false; // Start without a good reason to erase it - - if( aVia && track->Type() != PCB_VIA_T ) - continue; - else if( !aVia && track->Type() == PCB_VIA_T ) + if( ( aVia && track->Type() != PCB_VIA_T ) || ( !aVia && track->Type() == PCB_VIA_T ) ) continue; - // Tst if a track (or a via) endpoint is not connected to another track or to a zone. + // Test if a track (or a via) endpoint is not connected to another track or zone. if( m_brd->GetConnectivity()->TestTrackEndpointDangling( track ) ) - flag_erase = true; - - if( flag_erase ) { - int errorCode = - ( track->Type() != PCB_VIA_T ) ? - CLEANUP_DANGLING_TRACK : CLEANUP_DANGLING_VIA; - std::shared_ptr item = std::make_shared( errorCode ); + std::shared_ptr item; + + if( track->Type() == PCB_VIA_T ) + item = std::make_shared( CLEANUP_DANGLING_VIA ); + else + item = std::make_shared( CLEANUP_DANGLING_TRACK ); + item->SetItems( track ); m_itemsList->push_back( item ); @@ -266,7 +262,7 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment for( TRACK* track : m_brd->Tracks() ) { - track->ClearFlags( IS_DELETED ); + track->ClearFlags( IS_DELETED | SKIP_STRUCT ); rtree.insert( track ); } @@ -287,11 +283,14 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment rtree.QueryColliding( via, via->GetLayer(), via->GetLayer(), nullptr, [&]( BOARD_ITEM* aItem, int ) -> bool { - if( aItem->Type() != PCB_VIA_T || aItem->HasFlag( IS_DELETED ) ) + if( aItem->Type() != PCB_VIA_T ) return true; VIA* other = static_cast( aItem ); + if( other->HasFlag( SKIP_STRUCT ) || other->HasFlag( IS_DELETED ) ) + return true; + if( via->GetPosition() == other->GetPosition() && via->GetViaType() == other->GetViaType() && via->GetLayerSet() == other->GetLayerSet() ) @@ -324,6 +323,8 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment break; } } + + via->SetFlags( SKIP_STRUCT ); } if( aDeleteNullSegments && track->Type() != PCB_VIA_T ) @@ -344,11 +345,14 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment rtree.QueryColliding( track, track->GetLayer(), track->GetLayer(), nullptr, [&]( BOARD_ITEM* aItem, int ) -> bool { - if( aItem->Type() != PCB_TRACE_T || aItem->HasFlag( IS_DELETED ) ) + if( aItem->Type() != PCB_TRACE_T ) return true; TRACK* other = static_cast( aItem ); + if( other->HasFlag( SKIP_STRUCT )|| other->HasFlag( IS_DELETED ) ) + return true; + if( track->IsPointOnEnds( other->GetStart() ) && track->IsPointOnEnds( other->GetEnd() ) && track->GetWidth() == other->GetWidth() @@ -364,6 +368,8 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment return true; } ); + + track->SetFlags( SKIP_STRUCT ); } } @@ -423,7 +429,7 @@ void TRACKS_CLEANER::cleanup( bool aDeleteDuplicateVias, bool aDeleteNullSegment } for( TRACK* track : m_brd->Tracks() ) - track->ClearFlags( IS_DELETED ); + track->ClearFlags( IS_DELETED | SKIP_STRUCT ); }