From 2365c1e96fc64b33f7534ac3528be70def476ed5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 4 Feb 2022 14:26:32 +0000 Subject: [PATCH] Add duplicated items to parent group. Fixes https://gitlab.com/kicad/code/kicad/issues/10155 (cherry picked from commit 42917874dd53c73fdcc3ac49978cf06d4bfaf7b1) --- include/board_item.h | 8 +------- pcbnew/board_item.cpp | 12 ++++++++++++ pcbnew/footprint.cpp | 5 ++--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/board_item.h b/include/board_item.h index eec5547d08..d1ca06416e 100644 --- a/include/board_item.h +++ b/include/board_item.h @@ -168,13 +168,7 @@ public: /** * Create a copy of this #BOARD_ITEM. */ - virtual BOARD_ITEM* Duplicate() const - { - EDA_ITEM* dupe = Clone(); - const_cast( dupe->m_Uuid ) = KIID(); - - return static_cast( dupe ); - } + virtual BOARD_ITEM* Duplicate() const; /** * Swap data between \a aItem and \a aImage. diff --git a/pcbnew/board_item.cpp b/pcbnew/board_item.cpp index b30a661443..c1b31437de 100644 --- a/pcbnew/board_item.cpp +++ b/pcbnew/board_item.cpp @@ -141,6 +141,18 @@ void BOARD_ITEM::SwapData( BOARD_ITEM* aImage ) } +BOARD_ITEM* BOARD_ITEM::Duplicate() const +{ + BOARD_ITEM* dupe = static_cast( Clone() ); + const_cast( dupe->m_Uuid ) = KIID(); + + if( dupe->GetParentGroup() ) + dupe->GetParentGroup()->AddItem( dupe ); + + return static_cast( dupe ); +} + + void BOARD_ITEM::TransformShapeWithClearanceToPolygon( SHAPE_POLY_SET& aCornerBuffer, PCB_LAYER_ID aLayer, int aClearanceValue, int aError, ERROR_LOC aErrorLoc, diff --git a/pcbnew/footprint.cpp b/pcbnew/footprint.cpp index 3a7801c724..9ef5cf52c9 100644 --- a/pcbnew/footprint.cpp +++ b/pcbnew/footprint.cpp @@ -1723,15 +1723,14 @@ void FOOTPRINT::SetOrientation( double aNewAngle ) BOARD_ITEM* FOOTPRINT::Duplicate() const { - FOOTPRINT* dupe = (FOOTPRINT*) Clone(); - const_cast( dupe->m_Uuid ) = KIID(); + FOOTPRINT* dupe = static_cast( BOARD_ITEM::Duplicate() ); dupe->RunOnChildren( [&]( BOARD_ITEM* child ) { const_cast( child->m_Uuid ) = KIID(); }); - return static_cast( dupe ); + return dupe; }