Better selection heuristics for highlight tool

Fixes https://gitlab.com/kicad/code/kicad/-/issues/4011
This commit is contained in:
Jon Evans 2020-10-12 21:07:57 -04:00
parent f9cff177a2
commit 2abce40553
4 changed files with 26 additions and 13 deletions

View File

@ -537,16 +537,15 @@ int PCB_INSPECTION_TOOL::HighlightItem( const TOOL_EVENT& aEvent )
*/ */
bool PCB_INSPECTION_TOOL::highlightNet( const VECTOR2D& aPosition, bool aUseSelection ) bool PCB_INSPECTION_TOOL::highlightNet( const VECTOR2D& aPosition, bool aUseSelection )
{ {
BOARD* board = static_cast<BOARD*>( m_toolMgr->GetModel() ); BOARD* board = static_cast<BOARD*>( m_toolMgr->GetModel() );
KIGFX::RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings(); KIGFX::RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings();
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
int net = -1; int net = -1;
bool enableHighlight = false; bool enableHighlight = false;
if( aUseSelection ) if( aUseSelection )
{ {
SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
const PCBNEW_SELECTION& selection = selectionTool->GetSelection(); const PCBNEW_SELECTION& selection = selectionTool->GetSelection();
for( auto item : selection ) for( auto item : selection )
@ -568,21 +567,35 @@ int PCB_INSPECTION_TOOL::HighlightItem( const TOOL_EVENT& aEvent )
// If we didn't get a net to highlight from the selection, use the cursor // If we didn't get a net to highlight from the selection, use the cursor
if( net < 0 ) if( net < 0 )
{ {
auto guide = m_frame->GetCollectorsGuide(); GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide();
GENERAL_COLLECTOR collector; GENERAL_COLLECTOR collector;
PCB_LAYER_ID activeLayer = static_cast<PCB_LAYER_ID>( view()->GetTopLayer() );
guide.SetPreferredLayer( activeLayer );
// Find a connected item for which we are going to highlight a net // Find a connected item for which we are going to highlight a net
collector.Collect( board, GENERAL_COLLECTOR::PadsOrTracks, (wxPoint) aPosition, guide ); collector.Collect( board, GENERAL_COLLECTOR::PadsOrTracks, (wxPoint) aPosition, guide );
if( collector.GetCount() == 0 ) if( collector.GetCount() == 0 )
collector.Collect( board, GENERAL_COLLECTOR::Zones, (wxPoint) aPosition, guide ); collector.Collect( board, GENERAL_COLLECTOR::Zones, (wxPoint) aPosition, guide );
// Apply the active selection filter
selectionTool->FilterCollectedItems( collector );
// Clear the previous highlight // Clear the previous highlight
m_frame->SendMessageToEESCHEMA( nullptr ); m_frame->SendMessageToEESCHEMA( nullptr );
bool highContrast = settings->GetHighContrast();
PCB_LAYER_ID contrastLayer = settings->GetPrimaryHighContrastLayer();
for( int i = 0; i < collector.GetCount(); i++ ) for( int i = 0; i < collector.GetCount(); i++ )
{ {
if( ( collector[i]->GetLayerSet() & LSET::AllCuMask() ).none() ) LSET itemLayers = collector[i]->GetLayerSet();
if( ( itemLayers & LSET::AllCuMask() ).none() )
collector.Remove( i );
if( highContrast && !itemLayers.Contains( contrastLayer ) )
collector.Remove( i ); collector.Remove( i );
if( collector[i]->Type() == PCB_PAD_T ) if( collector[i]->Type() == PCB_PAD_T )

View File

@ -548,7 +548,7 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag,
aClientFilter( aWhere, collector, this ); aClientFilter( aWhere, collector, this );
// Apply the stateful filter // Apply the stateful filter
filterCollectedItems( collector ); FilterCollectedItems( collector );
FilterCollectorForGroups( collector ); FilterCollectorForGroups( collector );
@ -715,7 +715,7 @@ bool SELECTION_TOOL::selectMultiple()
} }
// Apply the stateful filter // Apply the stateful filter
filterCollectedItems( collector ); FilterCollectedItems( collector );
FilterCollectorForGroups( collector ); FilterCollectorForGroups( collector );
@ -1481,7 +1481,7 @@ int SELECTION_TOOL::filterSelection( const TOOL_EVENT& aEvent )
} }
void SELECTION_TOOL::filterCollectedItems( GENERAL_COLLECTOR& aCollector ) void SELECTION_TOOL::FilterCollectedItems( GENERAL_COLLECTOR& aCollector )
{ {
if( aCollector.GetCount() == 0 ) if( aCollector.GetCount() == 0 )
return; return;

View File

@ -197,6 +197,9 @@ public:
PCB_GROUP* GetEnteredGroup() { return m_enteredGroup; } PCB_GROUP* GetEnteredGroup() { return m_enteredGroup; }
///> Applies the SELECTION_FILTER_OPTIONS to a collection of items
void FilterCollectedItems( GENERAL_COLLECTOR& aCollector );
private: private:
/** /**
@ -307,9 +310,6 @@ private:
///> Invoke filter dialog and modify current selection ///> Invoke filter dialog and modify current selection
int filterSelection( const TOOL_EVENT& aEvent ); int filterSelection( const TOOL_EVENT& aEvent );
///> Applies the SELECTION_FILTER_OPTIONS to a collection of items
void filterCollectedItems( GENERAL_COLLECTOR& aCollector );
///> Returns true if the given item passes the current SELECTION_FILTER_OPTIONS ///> Returns true if the given item passes the current SELECTION_FILTER_OPTIONS
bool itemPassesFilter( BOARD_ITEM* aItem ); bool itemPassesFilter( BOARD_ITEM* aItem );

View File

@ -734,7 +734,7 @@ int SELECTION_TOOL::filterSelection( const TOOL_EVENT& aEvent )
} }
void SELECTION_TOOL::filterCollectedItems( GENERAL_COLLECTOR& aCollector ) void SELECTION_TOOL::FilterCollectedItems( GENERAL_COLLECTOR& aCollector )
{ {
} }