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; }