From c16e86be9a241383cdb25f32b73f8c5986b7e69f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 16 Sep 2022 22:48:33 +0100 Subject: [PATCH] Use router's connectivity algorithm, not CONNECTIVITY_DATA's. Fixes https://gitlab.com/kicad/code/kicad/issues/10745 (cherry picked from commit 107f4091066c370be9cf8ee26688798eab4b3433) --- pcbnew/tools/edit_tool.cpp | 58 ++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index ca3640ec91..092b86c5cf 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -293,47 +293,45 @@ int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent ) if( aCollector.GetCount() > 1 ) sTool->GuessSelectionCandidates( aCollector, aPt ); - // If we have a knee between two segments, or a via attached to two segments, - // then drop the selection to a single item. - static KICAD_T trackTypes[] = { PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT }; + /* + * If we have a knee between two segments, or a via attached to two segments, + * then drop the selection to a single item. + */ + std::vector tracks; std::vector vias; for( EDA_ITEM* item : aCollector ) { - if( item->IsType( trackTypes ) ) - tracks.push_back( static_cast( item ) ); - else if( item->Type() == PCB_VIA_T ) - vias.push_back( static_cast( item ) ); + if( PCB_TRACK* track = dynamic_cast( item ) ) + { + if( track->Type() == PCB_VIA_T ) + vias.push_back( track ); + else + tracks.push_back( track ); + } } - if( tracks.size() == 2 ) + auto connected = []( PCB_TRACK* track, const wxPoint& pt ) + { + return track->GetStart() == pt || track->GetEnd() == pt; + }; + + if( tracks.size() == 2 && vias.size() == 0 ) { - const BOARD* board = tracks[0]->GetBoard(); - std::shared_ptr c = board->GetConnectivity(); - std::vector cItems; - - int accuracy = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() ); - - if( vias.size() == 1 ) + if( connected( tracks[0], tracks[1]->GetStart() ) + || connected( tracks[0], tracks[1]->GetEnd() ) ) { - cItems = c->GetConnectedItemsAtAnchor( vias[0], aPt, trackTypes, - vias[0]->GetWidth() / 2 + accuracy ); - - if( alg::contains( cItems, tracks[0] ) - && alg::contains( cItems, tracks[1] ) ) - { - aCollector.Remove( tracks[0] ); - aCollector.Remove( tracks[1] ); - } + aCollector.Remove( tracks[1] ); } - else if( vias.size() == 0 ) + } + else if( tracks.size() == 2 && vias.size() == 1 ) + { + if( connected( tracks[0], vias[0]->GetPosition() ) + && connected( tracks[1], vias[0]->GetPosition() ) ) { - cItems = c->GetConnectedItemsAtAnchor( tracks[0], aPt, trackTypes, - tracks[0]->GetWidth() / 2 + accuracy ); - - if( alg::contains( cItems, tracks[1] ) ) - aCollector.Remove( tracks[1] ); + aCollector.Remove( tracks[0] ); + aCollector.Remove( tracks[1] ); } } },