When copying groups we must do a deep copy.

This commit is contained in:
Jeff Young 2020-10-20 12:37:38 +01:00
parent 68ec151f28
commit 28ee667080
1 changed files with 16 additions and 1 deletions

View File

@ -102,7 +102,13 @@ void CLIPBOARD_IO::SaveSelection( const PCBNEW_SELECTION& aSelected, bool isModE
for( const EDA_ITEM* item : aSelected )
{
BOARD_ITEM* clone = static_cast<BOARD_ITEM*>( item->Clone() );
const PCB_GROUP* group = dynamic_cast<const PCB_GROUP*>( item );
BOARD_ITEM* clone;
if( group )
clone = static_cast<BOARD_ITEM*>( group->DeepClone() );
else
clone = static_cast<BOARD_ITEM*>( item->Clone() );
// Do not add reference/value - convert them to the common type
if( FP_TEXT* text = dyn_cast<FP_TEXT*>( clone ) )
@ -115,6 +121,15 @@ void CLIPBOARD_IO::SaveSelection( const PCBNEW_SELECTION& aSelected, bool isModE
// Add the pad to the new module before moving to ensure the local coords are correct
partialModule.Add( clone );
if( group )
{
static_cast<PCB_GROUP*>( clone )->RunOnDescendants(
[&]( BOARD_ITEM* descendant )
{
partialModule.Add( descendant );
} );
}
// locate the reference point at (0, 0) in the copied items
clone->Move( (wxPoint) -refPoint );
}