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
* creates a copy of a BOARD_ITEM.
*/
BOARD_ITEM* Duplicate() const
virtual BOARD_ITEM* Duplicate() const
{
EDA_ITEM* dupe = Clone();
const_cast<KIID&>( dupe->m_Uuid ) = KIID();

View File

@ -144,10 +144,11 @@ void ARRAY_CREATOR::Invoke()
if( this_item->Type() == PCB_MODULE_T )
{
static_cast<MODULE*>( this_item )->RunOnChildren( [&] ( BOARD_ITEM* aItem )
{
aItem->ClearSelected();
});
static_cast<MODULE*>( this_item )->RunOnChildren(
[&]( BOARD_ITEM* aItem )
{
aItem->ClearSelected();
});
}
commit.Add( new_item );

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* new_item = NULL;
@ -1374,6 +1388,7 @@ BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule )
case PCB_PAD_T:
{
D_PAD* new_pad = new D_PAD( *static_cast<const D_PAD*>( aItem ) );
const_cast<KIID&>( new_pad->m_Uuid ) = KIID();
if( aAddToModule )
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:
{
new_zone = new MODULE_ZONE_CONTAINER( *static_cast<const MODULE_ZONE_CONTAINER*>( aItem ) );
const_cast<KIID&>( new_zone->m_Uuid ) = KIID();
if( aAddToModule )
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:
{
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 )
{
@ -1419,6 +1436,7 @@ BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule )
case PCB_MODULE_EDGE_T:
{
EDGE_MODULE* new_edge = new EDGE_MODULE( *static_cast<const EDGE_MODULE*>(aItem) );
const_cast<KIID&>( new_edge->m_Uuid ) = KIID();
if( aAddToModule )
Add( new_edge );

View File

@ -566,6 +566,8 @@ public:
int GetPlacementCost90() const { return m_CntRot90; }
void SetPlacementCost90( int aCost ) { m_CntRot90 = aCost; }
BOARD_ITEM* Duplicate() const override;
/**
* Function DuplicateItem
* 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
MODULE* m = new MODULE( *mi->second );
const_cast<KIID&>( m->m_Uuid ) = KIID();
m_board->Add( m, ADD_MODE::APPEND );
// 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
MODULE* newmodule = new MODULE( *module_in_edit );
const_cast<KIID&>( newmodule->m_Uuid ) = KIID();
newmodule->SetParent( mainpcb );
newmodule->SetLink( niluuid );

View File

@ -452,6 +452,7 @@ MODULE* MICROWAVE_TOOL::createMicrowaveInductor( MICROWAVE_INDUCTOR_PATTERN& aIn
pad->SetShape( PAD_SHAPE_CIRCLE );
D_PAD* newpad = new D_PAD( *pad );
const_cast<KIID&>( newpad->m_Uuid ) = KIID();
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.
module = new MODULE( *module );
const_cast<KIID&>( module->m_Uuid ) = KIID();
}
if( module )

View File

@ -182,10 +182,10 @@ void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem )
if( lastItem->Type() == PCB_MODULE_T )
{
static_cast<MODULE*>( lastItem )->RunOnChildren( [&] ( BOARD_ITEM* child )
{
child->ClearBrightened();
});
static_cast<MODULE*>( lastItem )->RunOnChildren( [&]( BOARD_ITEM* child )
{
child->ClearBrightened();
});
}
GetCanvas()->GetView()->Update( lastItem );
@ -199,10 +199,10 @@ void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem )
if( aItem->Type() == PCB_MODULE_T )
{
static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* child )
{
child->SetBrightened();
});
static_cast<MODULE*>( aItem )->RunOnChildren( [&]( BOARD_ITEM* child )
{
child->SetBrightened();
});
}
GetCanvas()->GetView()->Update( aItem );

View File

@ -1944,21 +1944,22 @@ void SELECTION_TOOL::highlight( BOARD_ITEM* aItem, int aMode, PCBNEW_SELECTION*
// highlight all the parts that make the module, not the module itself
if( aItem->Type() == PCB_MODULE_T )
{
static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
{
if( aMode == SELECTED )
item->SetSelected();
else if( aMode == BRIGHTENED )
{
item->SetBrightened();
static_cast<MODULE*>( aItem )->RunOnChildren(
[&]( BOARD_ITEM* item )
{
if( aMode == SELECTED )
item->SetSelected();
else if( aMode == BRIGHTENED )
{
item->SetBrightened();
if( aGroup )
aGroup->Add( item );
}
if( aGroup )
aGroup->Add( item );
}
if( aGroup )
view()->Hide( item, true );
});
if( aGroup )
view()->Hide( item, true );
});
}
view()->Update( aItem );
@ -1989,23 +1990,24 @@ void SELECTION_TOOL::unhighlight( BOARD_ITEM* aItem, int aMode, PCBNEW_SELECTION
// highlight all the parts that make the module, not the module itself
if( aItem->Type() == PCB_MODULE_T )
{
static_cast<MODULE*>( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item )
{
if( aMode == SELECTED )
item->ClearSelected();
else if( aMode == BRIGHTENED )
item->ClearBrightened();
static_cast<MODULE*>( aItem )->RunOnChildren(
[&]( BOARD_ITEM* item )
{
if( aMode == SELECTED )
item->ClearSelected();
else if( aMode == BRIGHTENED )
item->ClearBrightened();
// N.B. if we clear the selection flag for sub-elements, we need to also
// remove the element from the selection group (if it exists)
if( aGroup )
{
aGroup->Remove( item );
// N.B. if we clear the selection flag for sub-elements, we need to also
// remove the element from the selection group (if it exists)
if( aGroup )
{
aGroup->Remove( item );
view()->Hide( item, false );
view()->Update( item );
}
});
view()->Hide( item, false );
view()->Update( item );
}
});
}
view()->Update( aItem );