From 34a0d1947ad05d30c0bebafa4a93b24af6b8ed11 Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Mon, 6 Dec 2021 14:27:53 +0000 Subject: [PATCH] pcbnew Flip: Filter selection for free pads, select footprint instead Fixes https://gitlab.com/kicad/code/kicad/-/issues/9875 --- pcbnew/tools/edit_tool.cpp | 1 + pcbnew/tools/pcb_selection_tool.cpp | 25 +++++++++++++++++++++++++ pcbnew/tools/pcb_selection_tool.h | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 34d0bf17c4..aebd20b9bc 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1697,6 +1697,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent ) []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool ) { sTool->FilterCollectorForHierarchy( aCollector, true ); + sTool->FilterCollectorForFreePads( aCollector, true ); }, !m_dragging /* prompt user regarding locked items */ ); diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 314ddb826f..f248a97743 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -2656,6 +2656,31 @@ void PCB_SELECTION_TOOL::FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollec } +void PCB_SELECTION_TOOL::FilterCollectorForFreePads( GENERAL_COLLECTOR& aCollector, + bool aMultiselect ) const +{ + std::set to_add; + + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[i]; + + if( !IsFootprintEditor() && item->Type() == PCB_PAD_T + && !frame()->Settings().m_AllowFreePads ) + { + if( !aCollector.HasItem( item->GetParent() ) ) + to_add.insert( item->GetParent() ); + + aCollector.Remove( item ); + } + } + + for( BOARD_ITEM* item : to_add ) + aCollector.Append( item ); +} + + int PCB_SELECTION_TOOL::updateSelection( const TOOL_EVENT& aEvent ) { getView()->Update( &m_selection ); diff --git a/pcbnew/tools/pcb_selection_tool.h b/pcbnew/tools/pcb_selection_tool.h index 050c20ff4d..cc1859aa0c 100644 --- a/pcbnew/tools/pcb_selection_tool.h +++ b/pcbnew/tools/pcb_selection_tool.h @@ -203,6 +203,12 @@ public: */ void FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const; + /** + * Check the "allow free pads" setting and if disabled, upgrade any pad selection to the + * selection of its parent footprint. + */ + void FilterCollectorForFreePads( GENERAL_COLLECTOR& aCollector, bool aMultiselect ) const; + ///< Apply the SELECTION_FILTER_OPTIONS to a collection of items void FilterCollectedItems( GENERAL_COLLECTOR& aCollector, bool aMultiSelect );