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
This commit is contained in:
Roberto Fernandez Bautista 2020-11-23 20:34:57 +00:00 committed by jean-pierre charras
parent d2fbe12cfd
commit 0691e942f4
3 changed files with 20 additions and 6 deletions

View File

@ -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<KIID&>( dupe->m_Uuid ) = KIID();
for( LIB_ITEM& item : dupe->m_drawings )
const_cast<KIID&>( item.m_Uuid ) = KIID();
return dupe;
}
private:
// We create a different set parent function for this class, so we hide
// the inherited one.

View File

@ -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() )

View File

@ -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<KIID&>( footprint->m_Uuid ) = KIID();
// Use Duplicate() to ensure unique KIID for all objects
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( 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<PCB_TEXT*>( 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 );