From a1f510ef6a6d2095020dd7084139c317f156d2d0 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 16 Feb 2021 12:48:18 +0000 Subject: [PATCH] Make sure migrated aliases get hooked up to migrated parents. Fixes https://gitlab.com/kicad/code/kicad/issues/7322 --- eeschema/dialogs/panel_sym_lib_table.cpp | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index 630bf3c009..5c231a74a2 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -774,6 +774,7 @@ bool PANEL_SYM_LIB_TABLE::convertLibrary( const wxString& aLibrary, const wxStri SCH_PLUGIN::SCH_PLUGIN_RELEASER kicadPI( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD ) ); std::vector parts; std::vector newParts; + std::map partMap; try { @@ -788,8 +789,31 @@ bool PANEL_SYM_LIB_TABLE::convertLibrary( const wxString& aLibrary, const wxStri legacyPI->EnumerateSymbolLib( parts, legacyFilepath ); + // Copy non-aliases first so we can build a map from parts to newParts for( LIB_PART* part : parts ) - kicadPI->SaveSymbol( newFilepath, new LIB_PART( *part ) ); + { + if( part->IsAlias() ) + continue; + + newParts.push_back( new LIB_PART( *part ) ); + partMap[part] = newParts.back(); + } + + // Now do the aliases using the map to hook them up to their newPart parents + for( LIB_PART* part : parts ) + { + if( !part->IsAlias() ) + continue; + + newParts.push_back( new LIB_PART( *part ) ); + newParts.back()->SetParent( partMap[ part->GetParent().lock().get() ] ); + } + + // Finally write out newParts + for( LIB_PART* part : newParts ) + { + kicadPI->SaveSymbol( newFilepath, part ); + } } catch( ... ) {