From 61ef88a0ac9cf333e29ff95a02259e9112f17ad2 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 3 Sep 2023 22:04:00 +0100 Subject: [PATCH] Don't allow duplication of footprint items outside of footprint editor. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15487 (cherry picked from commit 9bba8e59566fa423c795a43408b115e05c05af4a) --- pcbnew/tools/edit_tool.cpp | 6 ++---- pcbnew/tools/edit_tool_move_fct.cpp | 2 +- pcbnew/tools/pcb_selection_tool.cpp | 5 +++-- pcbnew/tools/pcb_selection_tool.h | 3 ++- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index bb8744f3fb..01d968f090 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -2217,6 +2217,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) const PCB_SELECTION& selection = m_selectionTool->RequestSelection( []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool ) { + sTool->FilterCollectorForFreePads( aCollector, true ); sTool->FilterCollectorForMarkers( aCollector ); sTool->FilterCollectorForHierarchy( aCollector, true ); } ); @@ -2257,10 +2258,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) } else if( orig_item->GetParent() && orig_item->GetParent()->Type() == PCB_FOOTPRINT_T ) { - FOOTPRINT* parentFootprint = static_cast( orig_item->GetParent() ); - - m_commit->Modify( parentFootprint ); - dupe_item = parentFootprint->DuplicateItem( orig_item, true /* add to parent */ ); + // No sub-footprint modifications allowed outside of footprint editor } else { diff --git a/pcbnew/tools/edit_tool_move_fct.cpp b/pcbnew/tools/edit_tool_move_fct.cpp index 933612f682..bd82cc23a1 100644 --- a/pcbnew/tools/edit_tool_move_fct.cpp +++ b/pcbnew/tools/edit_tool_move_fct.cpp @@ -201,7 +201,7 @@ int EDIT_TOOL::PackAndMoveFootprints( const TOOL_EVENT& aEvent ) { sTool->FilterCollectorForMarkers( aCollector ); sTool->FilterCollectorForHierarchy( aCollector, true ); - sTool->FilterCollectorForFreePads( aCollector ); + sTool->FilterCollectorForFreePads( aCollector, true ); // Iterate from the back so we don't have to worry about removals. for( int i = aCollector.GetCount() - 1; i >= 0; --i ) diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 55bb08c0d0..80ec950b10 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -3161,7 +3161,8 @@ void PCB_SELECTION_TOOL::FilterCollectorForHierarchy( GENERAL_COLLECTOR& aCollec } -void PCB_SELECTION_TOOL::FilterCollectorForFreePads( GENERAL_COLLECTOR& aCollector ) const +void PCB_SELECTION_TOOL::FilterCollectorForFreePads( GENERAL_COLLECTOR& aCollector, + bool aForcePromotion ) const { std::set to_add; @@ -3171,7 +3172,7 @@ void PCB_SELECTION_TOOL::FilterCollectorForFreePads( GENERAL_COLLECTOR& aCollect BOARD_ITEM* item = aCollector[i]; if( !m_isFootprintEditor && item->Type() == PCB_PAD_T - && !frame()->GetPcbNewSettings()->m_AllowFreePads ) + && ( !frame()->GetPcbNewSettings()->m_AllowFreePads || aForcePromotion ) ) { if( !aCollector.HasItem( item->GetParent() ) ) to_add.insert( item->GetParent() ); diff --git a/pcbnew/tools/pcb_selection_tool.h b/pcbnew/tools/pcb_selection_tool.h index 2789860420..61238ea7ec 100644 --- a/pcbnew/tools/pcb_selection_tool.h +++ b/pcbnew/tools/pcb_selection_tool.h @@ -199,7 +199,8 @@ public: * Check the "allow free pads" setting and if disabled, replace any pads in the collector * with their parent footprints. */ - void FilterCollectorForFreePads( GENERAL_COLLECTOR& aCollector ) const; + void FilterCollectorForFreePads( GENERAL_COLLECTOR& aCollector, + bool aForcePromotion = false ) const; /** * Drop any PCB_MARKERs from the collector.