diff --git a/include/class_board_item.h b/include/class_board_item.h index 5836f75486..eb0959f49b 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -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( dupe->m_Uuid ) = KIID(); diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index 41bd1274d3..6c7d314b6c 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -144,10 +144,11 @@ void ARRAY_CREATOR::Invoke() if( this_item->Type() == PCB_MODULE_T ) { - static_cast( this_item )->RunOnChildren( [&] ( BOARD_ITEM* aItem ) - { - aItem->ClearSelected(); - }); + static_cast( this_item )->RunOnChildren( + [&]( BOARD_ITEM* aItem ) + { + aItem->ClearSelected(); + }); } commit.Add( new_item ); diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index c988d6a30b..e759eb2fd8 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1364,6 +1364,20 @@ void MODULE::SetOrientation( double newangle ) } +BOARD_ITEM* MODULE::Duplicate() const +{ + MODULE* dupe = (MODULE*) Clone(); + const_cast( dupe->m_Uuid ) = KIID(); + + dupe->RunOnChildren( [&]( BOARD_ITEM* child ) + { + const_cast( child->m_Uuid ) = KIID(); + }); + + return static_cast( 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( aItem ) ); + const_cast( 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( aItem ) ); + const_cast( 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( aItem ) ); + const_cast( 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(aItem) ); + const_cast( new_edge->m_Uuid ) = KIID(); if( aAddToModule ) Add( new_edge ); diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index aaf822e4c8..8c3623894a 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -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 diff --git a/pcbnew/eagle_plugin.cpp b/pcbnew/eagle_plugin.cpp index bf6b64d8b4..9815b9b0d6 100644 --- a/pcbnew/eagle_plugin.cpp +++ b/pcbnew/eagle_plugin.cpp @@ -1047,6 +1047,8 @@ void EAGLE_PLUGIN::loadElements( wxXmlNode* aElements ) // copy constructor to clone the template MODULE* m = new MODULE( *mi->second ); + const_cast( m->m_Uuid ) = KIID(); + m_board->Add( m, ADD_MODE::APPEND ); // update the nets within the pads of the clone diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index 48bfe209a1..fbb2f1cac4 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -821,6 +821,8 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew ) // Create the "new" module MODULE* newmodule = new MODULE( *module_in_edit ); + const_cast( newmodule->m_Uuid ) = KIID(); + newmodule->SetParent( mainpcb ); newmodule->SetLink( niluuid ); diff --git a/pcbnew/microwave/microwave_inductor.cpp b/pcbnew/microwave/microwave_inductor.cpp index ac0ef8cff4..4fcaf0e132 100644 --- a/pcbnew/microwave/microwave_inductor.cpp +++ b/pcbnew/microwave/microwave_inductor.cpp @@ -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( newpad->m_Uuid ) = KIID(); module->Add( newpad ); diff --git a/pcbnew/netlist_reader/netlist.cpp b/pcbnew/netlist_reader/netlist.cpp index 483d1c889e..f83c16cb86 100644 --- a/pcbnew/netlist_reader/netlist.cpp +++ b/pcbnew/netlist_reader/netlist.cpp @@ -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( module->m_Uuid ) = KIID(); } if( module ) diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 12db18ca78..7893bb9cde 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -182,10 +182,10 @@ void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem ) if( lastItem->Type() == PCB_MODULE_T ) { - static_cast( lastItem )->RunOnChildren( [&] ( BOARD_ITEM* child ) - { - child->ClearBrightened(); - }); + static_cast( 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( aItem )->RunOnChildren( [&] ( BOARD_ITEM* child ) - { - child->SetBrightened(); - }); + static_cast( aItem )->RunOnChildren( [&]( BOARD_ITEM* child ) + { + child->SetBrightened(); + }); } GetCanvas()->GetView()->Update( aItem ); diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index b59eb5efd9..db5ce43b0c 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -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( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item ) - { - if( aMode == SELECTED ) - item->SetSelected(); - else if( aMode == BRIGHTENED ) - { - item->SetBrightened(); + static_cast( 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( aItem )->RunOnChildren( [&] ( BOARD_ITEM* item ) - { - if( aMode == SELECTED ) - item->ClearSelected(); - else if( aMode == BRIGHTENED ) - item->ClearBrightened(); + static_cast( 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 );