Implement copy/paste for generators.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16613
This commit is contained in:
Jeff Young 2024-01-16 23:37:12 +00:00
parent 9077c9fb80
commit 322ad1af45
4 changed files with 34 additions and 1 deletions

View File

@ -31,6 +31,7 @@
#include <core/ignore.h>
#include <pad.h>
#include <pcb_group.h>
#include <pcb_generator.h>
#include <pcb_shape.h>
#include <pcb_text.h>
#include <pcb_textbox.h>
@ -234,6 +235,10 @@ void CLIPBOARD_IO::SaveSelection( const PCB_SELECTION& aSelected, bool isFootpri
{
copy = static_cast<PCB_GROUP*>( boardItem )->DeepClone();
}
else if( boardItem->Type() == PCB_GENERATOR_T )
{
copy = static_cast<PCB_GENERATOR*>( boardItem )->DeepClone();
}
else
{
copy = static_cast<BOARD_ITEM*>( 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 )

View File

@ -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<PCB_GENERATOR*>( Clone() );
newGenerator->m_items.clear();
for( BOARD_ITEM* member : m_items )
{
if( member->Type() == PCB_GROUP_T )
newGenerator->AddItem( static_cast<PCB_GROUP*>( member )->DeepClone() );
else
newGenerator->AddItem( static_cast<BOARD_ITEM*>( member->Clone() ) );
}
return newGenerator;
}
void PCB_GENERATOR::EditStart( GENERATOR_TOOL* aTool, BOARD* aBoard, BOARD_COMMIT* aCommit )
{
aCommit->Modify( this );

View File

@ -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,

View File

@ -45,6 +45,7 @@
#include <pcb_group.h>
#include <pcb_textbox.h>
#include <pcb_track.h>
#include <pcb_generator.h>
#include <wildcards_and_files_ext.h>
#include <zone.h>
#include <confirm.h>
@ -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::vector<BOARD_ITEM
// items that aren't in the entered group.
if( selectionTool->GetEnteredGroup() && !item->GetParentGroup() )
selectionTool->GetEnteredGroup()->AddItem( item );
item->SetParent( board() );
}
// Update item attributes if needed