Fix a bunch of usages of copy ctor that really meant duplicate.

In particular, "duplicate" means "with a new KIID".

Fixes https://gitlab.com/kicad/code/kicad/issues/5127
This commit is contained in:
Jeff Young 2020-08-10 14:22:02 +01:00
parent 827138f6b4
commit 692aeff334
10 changed files with 70 additions and 41 deletions

View File

@ -207,7 +207,7 @@ public:
* Function Duplicate * Function Duplicate
* creates a copy of a BOARD_ITEM. * creates a copy of a BOARD_ITEM.
*/ */
BOARD_ITEM* Duplicate() const virtual BOARD_ITEM* Duplicate() const
{ {
EDA_ITEM* dupe = Clone(); EDA_ITEM* dupe = Clone();
const_cast<KIID&>( dupe->m_Uuid ) = KIID(); const_cast<KIID&>( dupe->m_Uuid ) = KIID();

View File

@ -144,7 +144,8 @@ void ARRAY_CREATOR::Invoke()
if( this_item->Type() == PCB_MODULE_T ) if( this_item->Type() == PCB_MODULE_T )
{ {
static_cast<MODULE*>( this_item )->RunOnChildren( [&] ( BOARD_ITEM* aItem ) static_cast<MODULE*>( this_item )->RunOnChildren(
[&]( BOARD_ITEM* aItem )
{ {
aItem->ClearSelected(); aItem->ClearSelected();
}); });

View File

@ -1364,6 +1364,20 @@ void MODULE::SetOrientation( double newangle )
} }
BOARD_ITEM* MODULE::Duplicate() const
{
MODULE* dupe = (MODULE*) Clone();
const_cast<KIID&>( dupe->m_Uuid ) = KIID();
dupe->RunOnChildren( [&]( BOARD_ITEM* child )
{
const_cast<KIID&>( child->m_Uuid ) = KIID();
});
return static_cast<BOARD_ITEM*>( dupe );
}
BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule ) BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule )
{ {
BOARD_ITEM* new_item = NULL; BOARD_ITEM* new_item = NULL;
@ -1374,6 +1388,7 @@ BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule )
case PCB_PAD_T: case PCB_PAD_T:
{ {
D_PAD* new_pad = new D_PAD( *static_cast<const D_PAD*>( aItem ) ); D_PAD* new_pad = new D_PAD( *static_cast<const D_PAD*>( aItem ) );
const_cast<KIID&>( new_pad->m_Uuid ) = KIID();
if( aAddToModule ) if( aAddToModule )
m_pads.push_back( new_pad ); m_pads.push_back( new_pad );
@ -1385,6 +1400,7 @@ BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule )
case PCB_MODULE_ZONE_AREA_T: case PCB_MODULE_ZONE_AREA_T:
{ {
new_zone = new MODULE_ZONE_CONTAINER( *static_cast<const MODULE_ZONE_CONTAINER*>( aItem ) ); new_zone = new MODULE_ZONE_CONTAINER( *static_cast<const MODULE_ZONE_CONTAINER*>( aItem ) );
const_cast<KIID&>( new_zone->m_Uuid ) = KIID();
if( aAddToModule ) if( aAddToModule )
m_fp_zones.push_back( new_zone ); m_fp_zones.push_back( new_zone );
@ -1396,6 +1412,7 @@ BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule )
case PCB_MODULE_TEXT_T: case PCB_MODULE_TEXT_T:
{ {
TEXTE_MODULE* new_text = new TEXTE_MODULE( *static_cast<const TEXTE_MODULE*>( aItem ) ); TEXTE_MODULE* new_text = new TEXTE_MODULE( *static_cast<const TEXTE_MODULE*>( aItem ) );
const_cast<KIID&>( new_text->m_Uuid ) = KIID();
if( new_text->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE ) if( new_text->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
{ {
@ -1419,6 +1436,7 @@ BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule )
case PCB_MODULE_EDGE_T: case PCB_MODULE_EDGE_T:
{ {
EDGE_MODULE* new_edge = new EDGE_MODULE( *static_cast<const EDGE_MODULE*>(aItem) ); EDGE_MODULE* new_edge = new EDGE_MODULE( *static_cast<const EDGE_MODULE*>(aItem) );
const_cast<KIID&>( new_edge->m_Uuid ) = KIID();
if( aAddToModule ) if( aAddToModule )
Add( new_edge ); Add( new_edge );

View File

@ -566,6 +566,8 @@ public:
int GetPlacementCost90() const { return m_CntRot90; } int GetPlacementCost90() const { return m_CntRot90; }
void SetPlacementCost90( int aCost ) { m_CntRot90 = aCost; } void SetPlacementCost90( int aCost ) { m_CntRot90 = aCost; }
BOARD_ITEM* Duplicate() const override;
/** /**
* Function DuplicateItem * Function DuplicateItem
* Duplicate a given item within the module, optionally adding it to the board * Duplicate a given item within the module, optionally adding it to the board

View File

@ -1047,6 +1047,8 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements )
// copy constructor to clone the template // copy constructor to clone the template
MODULE* m = new MODULE( *mi->second ); MODULE* m = new MODULE( *mi->second );
const_cast<KIID&>( m->m_Uuid ) = KIID();
m_board->Add( m, ADD_MODE::APPEND ); m_board->Add( m, ADD_MODE::APPEND );
// update the nets within the pads of the clone // update the nets within the pads of the clone

View File

@ -821,6 +821,8 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew )
// Create the "new" module // Create the "new" module
MODULE* newmodule = new MODULE( *module_in_edit ); MODULE* newmodule = new MODULE( *module_in_edit );
const_cast<KIID&>( newmodule->m_Uuid ) = KIID();
newmodule->SetParent( mainpcb ); newmodule->SetParent( mainpcb );
newmodule->SetLink( niluuid ); newmodule->SetLink( niluuid );

View File

@ -452,6 +452,7 @@ MODULE* MICROWAVE_TOOL::createMicrowaveInductor( MICROWAVE_INDUCTOR_PATTERN& aIn
pad->SetShape( PAD_SHAPE_CIRCLE ); pad->SetShape( PAD_SHAPE_CIRCLE );
D_PAD* newpad = new D_PAD( *pad ); D_PAD* newpad = new D_PAD( *pad );
const_cast<KIID&>( newpad->m_Uuid ) = KIID();
module->Add( newpad ); module->Add( newpad );

View File

@ -238,6 +238,7 @@ void PCB_EDIT_FRAME::LoadFootprints( NETLIST& aNetlist, REPORTER& aReporter )
continue; // Module does not exist in any library. continue; // Module does not exist in any library.
module = new MODULE( *module ); module = new MODULE( *module );
const_cast<KIID&>( module->m_Uuid ) = KIID();
} }
if( module ) if( module )

View File

@ -1944,7 +1944,8 @@ void SELECTION_TOOL::highlight( BOARD_ITEM* aItem, int aMode, PCBNEW_SELECTION*
// highlight all the parts that make the module, not the module itself // highlight all the parts that make the module, not the module itself
if( aItem->Type() == PCB_MODULE_T ) if( aItem->Type() == PCB_MODULE_T )
{ {
static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item ) static_cast<MODULE*>( aItem )->RunOnChildren(
[&]( BOARD_ITEM* item )
{ {
if( aMode == SELECTED ) if( aMode == SELECTED )
item->SetSelected(); item->SetSelected();
@ -1989,7 +1990,8 @@ void SELECTION_TOOL::unhighlight( BOARD_ITEM* aItem, int aMode, PCBNEW_SELECTION
// highlight all the parts that make the module, not the module itself // highlight all the parts that make the module, not the module itself
if( aItem->Type() == PCB_MODULE_T ) if( aItem->Type() == PCB_MODULE_T )
{ {
static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item ) static_cast<MODULE*>( aItem )->RunOnChildren(
[&]( BOARD_ITEM* item )
{ {
if( aMode == SELECTED ) if( aMode == SELECTED )
item->ClearSelected(); item->ClearSelected();