From b3601bd540761e050c9f51b34e7ef6869bc50557 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 6 Mar 2018 11:40:03 +0100 Subject: [PATCH] SCH_LEGACY_PLUGIN_CACHE: Rename conflicting aliases --- eeschema/sch_legacy_plugin.cpp | 37 +++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index 02f9a1d87f..3bce6595fd 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -2630,7 +2630,42 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::loadPart( FILE_LINE_READER& aReader ) { // Add aliases for( size_t ii = 0; ii < part->GetAliasCount(); ++ii ) - m_aliases[ part->GetAlias( ii )->GetName() ] = part->GetAlias( ii ); + { + LIB_ALIAS* alias = part->GetAlias( ii ); + const wxString& aliasName = alias->GetName(); + auto it = m_aliases.find( aliasName ); + + if( it != m_aliases.end() ) + { + // Find a new name for the alias + wxString newName; + int idx = 0; + LIB_ALIAS_MAP::const_iterator jt; + + do + { + newName = wxString::Format( "%s_%d", aliasName, idx ); + jt = m_aliases.find( newName ); + ++idx; + } + while( jt != m_aliases.end() ); + + wxLogWarning( "Symbol name conflict in library:\n%s\n" + "'%s' has been renamed to '%s'", + m_fileName, aliasName, newName ); + + if( alias->IsRoot() ) + part->SetName( newName ); + else + alias->SetName( newName ); + + m_aliases[newName] = alias; + } + else + { + m_aliases[aliasName] = alias; + } + } return part.release(); }