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
This commit is contained in:
Maciej Suminski 2018-09-12 10:10:33 +02:00
parent c120ae9e9d
commit 2c217499b5
2 changed files with 26 additions and 3 deletions

View File

@ -1067,7 +1067,7 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
wxString gatename = epart->deviceset + epart->device + einstance.gate; wxString gatename = epart->deviceset + epart->device + einstance.gate;
wxString symbolname = wxString( epart->deviceset + epart->device ); wxString symbolname = wxString( epart->deviceset + epart->device );
symbolname.Replace( "*", "" ); symbolname.Replace( "*", "" );
wxString kisymbolname = LIB_ID::FixIllegalChars( symbolname, LIB_ID::ID_SCH ); wxString kisymbolname = fixSymbolName( symbolname );
int unit = m_eagleLibs[libraryname].GateUnit[gatename]; 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; wxString symbolName = edeviceset.name + edevice.name;
symbolName.Replace( "*", "" ); symbolName.Replace( "*", "" );
wxASSERT( !symbolName.IsEmpty() ); wxASSERT( !symbolName.IsEmpty() );
symbolName = LIB_ID::FixIllegalChars( symbolName, LIB_ID::ID_SCH ); symbolName = fixSymbolName( symbolName );
if( edevice.package ) if( edevice.package )
aEagleLibrary->package[symbolName] = edevice.package.Get(); aEagleLibrary->package[symbolName] = edevice.package.Get();
@ -1343,7 +1343,7 @@ EAGLE_LIBRARY* SCH_EAGLE_PLUGIN::loadLibrary( wxXmlNode* aLibraryNode,
if( gates_count == 1 && ispower ) if( gates_count == 1 && ispower )
kpart->SetPower(); kpart->SetPower();
wxString name = LIB_ID::FixIllegalChars( kpart->GetName(), LIB_ID::ID_SCH ); wxString name = fixSymbolName( kpart->GetName() );
kpart->SetName( name ); kpart->SetName( name );
m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_PART( *kpart.get() ), m_pi->SaveSymbol( getLibFileName().GetFullPath(), new LIB_PART( *kpart.get() ),
m_properties.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;
}

View File

@ -250,6 +250,15 @@ private:
* @param aUpdateSet decides whether the missing units data should be updated. * @param aUpdateSet decides whether the missing units data should be updated.
*/ */
void addImplicitConnections( SCH_COMPONENT* aComponent, SCH_SCREEN* aScreen, bool aUpdateSet ); 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_ #endif // _SCH_EAGLE_PLUGIN_H_