From 2abce405534ca72e91300c356bdb3eb285d4f17f Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Mon, 12 Oct 2020 21:07:57 -0400 Subject: [PATCH] Better selection heuristics for highlight tool Fixes https://gitlab.com/kicad/code/kicad/-/issues/4011 --- pcbnew/tools/pcb_inspection_tool.cpp | 25 +++++++++++++++++++------ pcbnew/tools/selection_tool.cpp | 6 +++--- pcbnew/tools/selection_tool.h | 6 +++--- qa/qa_utils/mocks.cpp | 2 +- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/pcbnew/tools/pcb_inspection_tool.cpp b/pcbnew/tools/pcb_inspection_tool.cpp index 09dafdef34..678bddfd48 100644 --- a/pcbnew/tools/pcb_inspection_tool.cpp +++ b/pcbnew/tools/pcb_inspection_tool.cpp @@ -537,16 +537,15 @@ int PCB_INSPECTION_TOOL::HighlightItem( const TOOL_EVENT& aEvent ) */ bool PCB_INSPECTION_TOOL::highlightNet( const VECTOR2D& aPosition, bool aUseSelection ) { - BOARD* board = static_cast( m_toolMgr->GetModel() ); - KIGFX::RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings(); + BOARD* board = static_cast( m_toolMgr->GetModel() ); + KIGFX::RENDER_SETTINGS* settings = getView()->GetPainter()->GetSettings(); + SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); int net = -1; bool enableHighlight = false; if( aUseSelection ) { - SELECTION_TOOL* selectionTool = m_toolMgr->GetTool(); - const PCBNEW_SELECTION& selection = selectionTool->GetSelection(); 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( net < 0 ) { - auto guide = m_frame->GetCollectorsGuide(); + GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide(); GENERAL_COLLECTOR collector; + PCB_LAYER_ID activeLayer = static_cast( view()->GetTopLayer() ); + guide.SetPreferredLayer( activeLayer ); + // Find a connected item for which we are going to highlight a net collector.Collect( board, GENERAL_COLLECTOR::PadsOrTracks, (wxPoint) aPosition, guide ); if( collector.GetCount() == 0 ) collector.Collect( board, GENERAL_COLLECTOR::Zones, (wxPoint) aPosition, guide ); + // Apply the active selection filter + selectionTool->FilterCollectedItems( collector ); + // Clear the previous highlight m_frame->SendMessageToEESCHEMA( nullptr ); + bool highContrast = settings->GetHighContrast(); + PCB_LAYER_ID contrastLayer = settings->GetPrimaryHighContrastLayer(); + 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 ); if( collector[i]->Type() == PCB_PAD_T ) diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index 2385260511..ffe5bff00f 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -548,7 +548,7 @@ bool SELECTION_TOOL::selectPoint( const VECTOR2I& aWhere, bool aOnDrag, aClientFilter( aWhere, collector, this ); // Apply the stateful filter - filterCollectedItems( collector ); + FilterCollectedItems( collector ); FilterCollectorForGroups( collector ); @@ -715,7 +715,7 @@ bool SELECTION_TOOL::selectMultiple() } // Apply the stateful filter - filterCollectedItems( collector ); + FilterCollectedItems( 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 ) return; diff --git a/pcbnew/tools/selection_tool.h b/pcbnew/tools/selection_tool.h index 82e41b4e77..6e9cd452bb 100644 --- a/pcbnew/tools/selection_tool.h +++ b/pcbnew/tools/selection_tool.h @@ -197,6 +197,9 @@ public: PCB_GROUP* GetEnteredGroup() { return m_enteredGroup; } + ///> Applies the SELECTION_FILTER_OPTIONS to a collection of items + void FilterCollectedItems( GENERAL_COLLECTOR& aCollector ); + private: /** @@ -307,9 +310,6 @@ private: ///> Invoke filter dialog and modify current selection 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 bool itemPassesFilter( BOARD_ITEM* aItem ); diff --git a/qa/qa_utils/mocks.cpp b/qa/qa_utils/mocks.cpp index 1049923c86..1f2c9e26a8 100644 --- a/qa/qa_utils/mocks.cpp +++ b/qa/qa_utils/mocks.cpp @@ -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 ) { }