From 2c217499b51a7140fcc5bed9d4c05e877d2e844d Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 12 Sep 2018 10:10:33 +0200 Subject: [PATCH] Eagle SCH importer: fix slash characters when fixing symbol names Even though slash is a valid character in symbol names, it is a revision separator, but is not the case with Eagle symbol names. Fixes: lp:1791653 * https://bugs.launchpad.net/kicad/+bug/1791653 --- eeschema/sch_eagle_plugin.cpp | 20 +++++++++++++++++--- eeschema/sch_eagle_plugin.h | 9 +++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/eeschema/sch_eagle_plugin.cpp b/eeschema/sch_eagle_plugin.cpp index 5f2f5319cd..e73ab13f5c 100644 --- a/eeschema/sch_eagle_plugin.cpp +++ b/eeschema/sch_eagle_plugin.cpp @@ -1067,7 +1067,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode ) wxString gatename = epart->deviceset + epart->device + einstance.gate; wxString symbolname = wxString( epart->deviceset + epart->device ); symbolname.Replace( "*", "" ); - wxString kisymbolname = LIB_ID::FixIllegalChars( symbolname, LIB_ID::ID_SCH ); + wxString kisymbolname = fixSymbolName( symbolname ); int unit = m_eagleLibs[libraryname].GateUnit[gatename]; @@ -1299,7 +1299,7 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode, wxString symbolName = edeviceset.name + edevice.name; symbolName.Replace( "*", "" ); wxASSERT( !symbolName.IsEmpty() ); - symbolName = LIB_ID::FixIllegalChars( symbolName, LIB_ID::ID_SCH ); + symbolName = fixSymbolName( symbolName ); if( edevice.package ) aEagleLibrary->package[symbolName] = edevice.package.Get(); @@ -1343,7 +1343,7 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode, if( gates_count == 1 && ispower ) kpart->SetPower(); - wxString name = LIB_ID::FixIllegalChars( kpart->GetName(), LIB_ID::ID_SCH ); + wxString name = fixSymbolName( kpart->GetName() ); kpart->SetName( name ); m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_PART( *kpart.get() ), m_properties.get() ); @@ -2615,3 +2615,17 @@ void SCH_EAGLE_PLUGIN::addImplicitConnections( SCH_COMPONENT* aComponent, } } } + + +wxString SCH_EAGLE_PLUGIN::fixSymbolName( const wxString& aName ) +{ + wxString ret = LIB_ID::FixIllegalChars( aName, LIB_ID::ID_ALIAS ); + + for( auto ch = ret.begin(); ch != ret.end(); ++ch ) + { + if( *ch == '/' ) + *ch = '_'; + } + + return ret; +} diff --git a/eeschema/sch_eagle_plugin.h b/eeschema/sch_eagle_plugin.h index bd8f713e2a..7bac73641d 100644 --- a/eeschema/sch_eagle_plugin.h +++ b/eeschema/sch_eagle_plugin.h @@ -250,6 +250,15 @@ private: * @param aUpdateSet decides whether the missing units data should be updated. */ void addImplicitConnections( SCH_COMPONENT* aComponent, SCH_SCREEN* aScreen, bool aUpdateSet ); + + /** + * Fixes invalid characters in Eagle symbol names. It changes invalid characters + * to underscores. + * + * @param aName is the symbol name to be fixed. + * @return Fixed symbol name. + */ + static wxString fixSymbolName( const wxString& aName ); }; #endif // _SCH_EAGLE_PLUGIN_H_