diff --git a/pcbnew/kicad_clipboard.cpp b/pcbnew/kicad_clipboard.cpp index ba19dfe93d..3148bab202 100644 --- a/pcbnew/kicad_clipboard.cpp +++ b/pcbnew/kicad_clipboard.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -234,6 +235,10 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri { copy = static_cast( boardItem )->DeepClone(); } + else if( boardItem->Type() == PCB_GENERATOR_T ) + { + copy = static_cast( boardItem )->DeepClone(); + } else { copy = static_cast( boardItem->Clone() ); @@ -248,7 +253,7 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri Format( copy, 1 ); - if( copy->Type() == PCB_GROUP_T ) + if( copy->Type() == PCB_GROUP_T || copy->Type() == PCB_GENERATOR_T ) { copy->RunOnDescendants( [&]( BOARD_ITEM* titem ) diff --git a/pcbnew/pcb_generator.cpp b/pcbnew/pcb_generator.cpp index 3a8c2563ce..91d455c2f4 100644 --- a/pcbnew/pcb_generator.cpp +++ b/pcbnew/pcb_generator.cpp @@ -36,6 +36,24 @@ PCB_GENERATOR::~PCB_GENERATOR() } +PCB_GENERATOR* PCB_GENERATOR::DeepClone() const +{ + // Use copy constructor to get the same uuid and other fields + PCB_GENERATOR* newGenerator = static_cast( Clone() ); + newGenerator->m_items.clear(); + + for( BOARD_ITEM* member : m_items ) + { + if( member->Type() == PCB_GROUP_T ) + newGenerator->AddItem( static_cast( member )->DeepClone() ); + else + newGenerator->AddItem( static_cast( member->Clone() ) ); + } + + return newGenerator; +} + + void PCB_GENERATOR::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ) { aCommit->Modify( this ); diff --git a/pcbnew/pcb_generator.h b/pcbnew/pcb_generator.h index 553e8bc227..d95bf6ddbb 100644 --- a/pcbnew/pcb_generator.h +++ b/pcbnew/pcb_generator.h @@ -47,6 +47,11 @@ public: virtual ~PCB_GENERATOR(); + /* + * Clone() this and all descendants + */ + PCB_GENERATOR* DeepClone() const; + virtual void EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit ); virtual void EditPush( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit, diff --git a/pcbnew/tools/pcb_control.cpp b/pcbnew/tools/pcb_control.cpp index 3a4f507075..1b617123cf 100644 --- a/pcbnew/tools/pcb_control.cpp +++ b/pcbnew/tools/pcb_control.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -1140,6 +1141,8 @@ bool PCB_CONTROL::placeBoardItems( BOARD_COMMIT* aCommit, BOARD* aBoard, bool aA // selection created aBoard that has the group and all descendants in it. moveUnflaggedItems( aBoard->Groups(), items, isNew ); + moveUnflaggedItems( aBoard->Generators(), items, isNew ); + pruneItemLayers( items ); return placeBoardItems( aCommit, items, isNew, aAnchorAtOrigin, aReannotateDuplicates ); @@ -1167,6 +1170,8 @@ bool PCB_CONTROL::placeBoardItems( BOARD_COMMIT* aCommit, std::vectorGetEnteredGroup() && !item->GetParentGroup() ) selectionTool->GetEnteredGroup()->AddItem( item ); + + item->SetParent( board() ); } // Update item attributes if needed