Improve drop-a-knee-selection-to-a-single-segment algorithm.

In particular, don't rely on there being only two items in the
collector at the start.

Fixes https://gitlab.com/kicad/code/kicad/issues/10745
This commit is contained in:
Jeff Young 2022-09-08 13:09:05 +01:00
parent 9f522e1343
commit a619ef9d53
1 changed files with 37 additions and 13 deletions

View File

@ -305,22 +305,46 @@ int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent )
sTool->FilterCollectorForFreePads( aCollector ); sTool->FilterCollectorForFreePads( aCollector );
sTool->FilterCollectorForHierarchy( aCollector, true ); sTool->FilterCollectorForHierarchy( aCollector, true );
// drop a knee between two segments to a single segment // drop a knee between two segments to a single segment, or a via with two
if( aCollector.GetCount() == 2 && dynamic_cast<PCB_TRACK*>( aCollector[0] ) ) // segments attached to the via
std::initializer_list<KICAD_T> trackTypes = { PCB_TRACE_T, PCB_ARC_T };
std::vector<PCB_TRACK*> tracks;
std::vector<PCB_TRACK*> vias;
for( EDA_ITEM* item : aCollector )
{ {
PCB_TRACK* a = static_cast<PCB_TRACK*>( aCollector[0] ); if( item->IsType( trackTypes ) )
PCB_TRACK* b = static_cast<PCB_TRACK*>( aCollector[1] ); tracks.push_back( static_cast<PCB_TRACK*>( item ) );
const auto& c = aCollector[0]->GetBoard()->GetConnectivity(); else if( item->Type() == PCB_VIA_T )
vias.push_back( static_cast<PCB_TRACK*>( item ) );
}
int dist = a->GetWidth() / 2; if( tracks.size() == 2 )
auto connectedItems = c->GetConnectedItemsAtAnchor( a, aPt, {
{ PCB_VIA_T, const BOARD* board = tracks[0]->GetBoard();
PCB_TRACE_T, std::shared_ptr<CONNECTIVITY_DATA> c = board->GetConnectivity();
PCB_ARC_T }, std::vector<BOARD_CONNECTED_ITEM*> cItems;
dist );
if( alg::contains( connectedItems, b ) ) if( vias.size() == 1 )
aCollector.Remove( b ); {
cItems = c->GetConnectedItemsAtAnchor( vias[0], aPt, trackTypes,
vias[0]->GetWidth() / 2 );
if( alg::contains( cItems, tracks[0] )
&& alg::contains( cItems, tracks[1] ) )
{
aCollector.Remove( tracks[0] );
aCollector.Remove( tracks[1] );
}
}
else if( vias.size() == 0 )
{
cItems = c->GetConnectedItemsAtAnchor( tracks[0], aPt, trackTypes,
tracks[0]->GetWidth() / 2 );
if( alg::contains( cItems, tracks[1] ) )
aCollector.Remove( tracks[1] );
}
} }
}, },
true /* prompt user regarding locked items */ ); true /* prompt user regarding locked items */ );