Eagle Schematic Import: try harder to generate a meaningful library name

The previous implementation relied only on the project name. When it is
set, the imported library was named '-eagle-import'. Now it tries
the project name and then the file name, using 'noname-eagle-import'
as fallback.

The library name is stored in the plugin to avoid changing the library
name after the project name has been set.
This commit is contained in:
Maciej Suminski 2017-12-12 15:25:49 +01:00
parent a13c89c83d
commit 7665a839cd
2 changed files with 24 additions and 5 deletions

View File

@ -90,13 +90,31 @@ static int countChildren( wxXmlNode* aCurrentNode, const std::string& aName )
}
wxString SCH_EAGLE_PLUGIN::getLibName() const
wxString SCH_EAGLE_PLUGIN::getLibName()
{
return m_kiway->Prj().GetProjectName() + "-eagle-import";
if( m_libName.IsEmpty() )
{
// Try to come up with a meaningful name
m_libName = m_kiway->Prj().GetProjectName();
if( m_libName.IsEmpty() )
{
wxFileName fn( m_rootSheet->GetFileName() );
m_libName = fn.GetName();
}
if( m_libName.IsEmpty() )
m_libName = "noname";
m_libName += "-eagle-import";
m_libName = LIB_ID::FixIllegalChars( m_libName );
}
return m_libName;
}
wxFileName SCH_EAGLE_PLUGIN::getLibFileName() const
wxFileName SCH_EAGLE_PLUGIN::getLibFileName()
{
wxFileName fn( m_kiway->Prj().GetProjectPath(), getLibName(), SchematicLibraryFileExtension );

View File

@ -172,14 +172,15 @@ private:
void loadTextAttributes( EDA_TEXT* aText, const ETEXT& aAttribs ) const;
void loadFieldAttributes( LIB_FIELD* aField, const LIB_TEXT* aText ) const;
wxString getLibName() const;
wxFileName getLibFileName() const;
wxString getLibName();
wxFileName getLibFileName();
KIWAY* m_kiway; ///< For creating sub sheets.
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
SCH_SHEET* m_currentSheet; ///< The current sheet of the schematic being loaded..
wxString m_version; ///< Eagle file version.
wxFileName m_filename;
wxString m_libName; ///< Library name to save symbols
EPART_MAP m_partlist;
std::map<std::string, EAGLE_LIBRARY> m_eagleLibs;