From 0691e942f47dc866fabafc236f96922791cc67dd Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Mon, 23 Nov 2020 20:34:57 +0000 Subject: [PATCH] CADSTAR Archive Importer: Fix duplicate KIID for loaded elements Don't use clone to copy an EDA_ITEM. Use Duplicate(). Even if you give the clone a new KIID, all its children will still be clones. Create Duplicate() in LIB_PART --- eeschema/class_libentry.h | 15 +++++++++++++++ .../cadstar/cadstar_sch_archive_loader.cpp | 2 +- .../cadstar/cadstar_pcb_archive_loader.cpp | 9 ++++----- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 188399190f..26cc7bd0b0 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -144,6 +144,21 @@ public: PART_SPTR SharedPtr() { return m_me; } + /** + * Function Duplicate + * Creates a copy of a LIB_PART and assigns unique KIIDs to the copy and its children + */ + virtual LIB_PART* Duplicate() const + { + LIB_PART* dupe = new LIB_PART( *this, m_library ); + const_cast( dupe->m_Uuid ) = KIID(); + + for( LIB_ITEM& item : dupe->m_drawings ) + const_cast( item.m_Uuid ) = KIID(); + + return dupe; + } + private: // We create a different set parent function for this class, so we hide // the inherited one. diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 972da01389..38283befa4 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -1007,7 +1007,7 @@ SCH_COMPONENT* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol( component->SetOrientation( compOrientation ); LIB_ID libId( mLibraryFileName.GetName(), aKiCadPart->GetName() ); component->SetLibId( libId ); - component->SetLibSymbol( new LIB_PART( *aKiCadPart ) ); + component->SetLibSymbol( aKiCadPart->Duplicate() ); component->SetUnit( getKiCadUnitNumberFromGate( aCadstarSymbol.GateID ) ); if( mSheetMap.find( aCadstarSymbol.LayerID ) == mSheetMap.end() ) diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index 2c399f3649..86c464d526 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -1209,9 +1209,8 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadComponents() FOOTPRINT* libFootprint = fpIter->second; - // copy constructor to clone the footprint from the library - FOOTPRINT* footprint = new FOOTPRINT( *libFootprint ); - const_cast( footprint->m_Uuid ) = KIID(); + // Use Duplicate() to ensure unique KIID for all objects + FOOTPRINT* footprint = static_cast( libFootprint->Duplicate() ); mBoard->Add( footprint, ADD_MODE::APPEND ); @@ -1885,7 +1884,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarText( const TEXT& aCadstarText, for( PCB_LAYER_ID layer : layers ) { txt->SetLayer( layer ); - newtxt = new PCB_TEXT( *txt ); + newtxt = static_cast( txt->Duplicate() ); mBoard->Add( newtxt, ADD_MODE::APPEND ); if( !aCadstarGroupID.IsEmpty() ) @@ -2383,7 +2382,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::addAttribute( const ATTRIBUTE_LOCATION& aCadsta if( !aFootprint->Value().GetText().IsEmpty() ) { //copy the object - aFootprint->Add( new FP_TEXT( aFootprint->Value() ) ); + aFootprint->Add( aFootprint->Value().Duplicate() ); } aFootprint->SetValue( aAttributeValue );