Don't allow duplication of footprint items outside of footprint editor.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15487
This commit is contained in:
Jeff Young 2023-09-03 22:04:00 +01:00
parent e7d6c84aef
commit 9bba8e5956
4 changed files with 8 additions and 11 deletions

View File

@ -2207,6 +2207,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
const PCB_SELECTION& selection = m_selectionTool->RequestSelection( const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
[]( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool ) []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
{ {
sTool->FilterCollectorForFreePads( aCollector, true );
sTool->FilterCollectorForMarkers( aCollector ); sTool->FilterCollectorForMarkers( aCollector );
sTool->FilterCollectorForHierarchy( aCollector, true ); sTool->FilterCollectorForHierarchy( aCollector, true );
} ); } );
@ -2250,18 +2251,12 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
} }
else if( FOOTPRINT* parentFootprint = orig_item->GetParentFootprint() ) else if( FOOTPRINT* parentFootprint = orig_item->GetParentFootprint() )
{ {
commit.Modify( parentFootprint ); // No sub-footprint modifications allowed outside of footprint editor
dupe_item = parentFootprint->DuplicateItem( orig_item, true /* add to parent */ );
} }
else else
{ {
switch( orig_item->Type() ) switch( orig_item->Type() )
{ {
case PCB_FIELD_T:
// Todo: these should probably be duplicated into new text items that
// have variables that reference the field values
break;
case PCB_FOOTPRINT_T: case PCB_FOOTPRINT_T:
case PCB_TEXT_T: case PCB_TEXT_T:
case PCB_TEXTBOX_T: case PCB_TEXTBOX_T:

View File

@ -171,7 +171,7 @@ int EDIT_TOOL::PackAndMoveFootprints( const TOOL_EVENT& aEvent )
{ {
sTool->FilterCollectorForMarkers( aCollector ); sTool->FilterCollectorForMarkers( aCollector );
sTool->FilterCollectorForHierarchy( aCollector, true ); sTool->FilterCollectorForHierarchy( aCollector, true );
sTool->FilterCollectorForFreePads( aCollector ); sTool->FilterCollectorForFreePads( aCollector, true );
// Iterate from the back so we don't have to worry about removals. // Iterate from the back so we don't have to worry about removals.
for( int i = aCollector.GetCount() - 1; i >= 0; --i ) for( int i = aCollector.GetCount() - 1; i >= 0; --i )

View File

@ -3281,7 +3281,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<BOARD_ITEM*> to_add; std::set<BOARD_ITEM*> to_add;
@ -3291,7 +3292,7 @@ void PCB_SELECTION_TOOL::FilterCollectorForFreePads( GENERAL_COLLECTOR& aCollect
BOARD_ITEM* item = aCollector[i]; BOARD_ITEM* item = aCollector[i];
if( !m_isFootprintEditor && item->Type() == PCB_PAD_T if( !m_isFootprintEditor && item->Type() == PCB_PAD_T
&& !frame()->GetPcbNewSettings()->m_AllowFreePads ) && ( !frame()->GetPcbNewSettings()->m_AllowFreePads || aForcePromotion ) )
{ {
if( !aCollector.HasItem( item->GetParent() ) ) if( !aCollector.HasItem( item->GetParent() ) )
to_add.insert( item->GetParent() ); to_add.insert( item->GetParent() );

View File

@ -199,7 +199,8 @@ public:
* Check the "allow free pads" setting and if disabled, replace any pads in the collector * Check the "allow free pads" setting and if disabled, replace any pads in the collector
* with their parent footprints. * 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. * Drop any PCB_MARKERs from the collector.