Use router's connectivity algorithm, not CONNECTIVITY_DATA's.

Fixes https://gitlab.com/kicad/code/kicad/issues/10745

(cherry picked from commit 107f409106)
This commit is contained in:
Jeff Young 2022-09-16 22:48:33 +01:00
parent b0e2aeb972
commit c16e86be9a
1 changed files with 28 additions and 30 deletions

View File

@ -293,46 +293,44 @@ int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent )
if( aCollector.GetCount() > 1 ) if( aCollector.GetCount() > 1 )
sTool->GuessSelectionCandidates( aCollector, aPt ); 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. * If we have a knee between two segments, or a via attached to two segments,
static KICAD_T trackTypes[] = { PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT }; * then drop the selection to a single item.
*/
std::vector<PCB_TRACK*> tracks; std::vector<PCB_TRACK*> tracks;
std::vector<PCB_TRACK*> vias; std::vector<PCB_TRACK*> vias;
for( EDA_ITEM* item : aCollector ) for( EDA_ITEM* item : aCollector )
{ {
if( item->IsType( trackTypes ) ) if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item ) )
tracks.push_back( static_cast<PCB_TRACK*>( item ) ); {
else if( item->Type() == PCB_VIA_T ) if( track->Type() == PCB_VIA_T )
vias.push_back( static_cast<PCB_TRACK*>( item ) ); vias.push_back( track );
else
tracks.push_back( track );
}
} }
if( tracks.size() == 2 ) auto connected = []( PCB_TRACK* track, const wxPoint& pt )
{ {
const BOARD* board = tracks[0]->GetBoard(); return track->GetStart() == pt || track->GetEnd() == pt;
std::shared_ptr<CONNECTIVITY_DATA> c = board->GetConnectivity(); };
std::vector<BOARD_CONNECTED_ITEM*> cItems;
int accuracy = KiROUND( 5 * aCollector.GetGuide()->OnePixelInIU() ); if( tracks.size() == 2 && vias.size() == 0 )
if( vias.size() == 1 )
{ {
cItems = c->GetConnectedItemsAtAnchor( vias[0], aPt, trackTypes, if( connected( tracks[0], tracks[1]->GetStart() )
vias[0]->GetWidth() / 2 + accuracy ); || connected( tracks[0], tracks[1]->GetEnd() ) )
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 )
{ {
cItems = c->GetConnectedItemsAtAnchor( tracks[0], aPt, trackTypes, if( connected( tracks[0], vias[0]->GetPosition() )
tracks[0]->GetWidth() / 2 + accuracy ); && connected( tracks[1], vias[0]->GetPosition() ) )
{
if( alg::contains( cItems, tracks[1] ) ) aCollector.Remove( tracks[0] );
aCollector.Remove( tracks[1] ); aCollector.Remove( tracks[1] );
} }
} }