Eeschema: add create symbol library to legacy schematic I/O plugin.

This commit is contained in:
Wayne Stambaugh 2016-10-05 19:28:56 -04:00
parent fdebcd8a6d
commit 4f0c2ad083
4 changed files with 41 additions and 18 deletions

View File

@ -304,10 +304,12 @@ public:
/** /**
* Function SaveSymbol * Function SaveSymbol
* will write @a aSymbol to an existing library located at @a aLibraryPath. *
* If a #LIB_PART by the same name already exists or there are any conflicting * will write @a aSymbol to an existing library located at @a aLibraryPath. If a #LIB_PART
* alias names, an exception is thrown. Symbol libraries cannot have duplicate * by the same name already exists or there are any conflicting alias names, the new
* alias names. * #LIB_PART will silently overwrite any existing aliases and/or part becaue libraries
* cannot have duplicate alias names. It is the responsibility of the caller to check
* the library for conflicts before saving.
* *
* @param aLibraryPath is a locator for the "library", usually a directory, file, * @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several symbols. * or URL containing several symbols.
@ -321,7 +323,7 @@ public:
* The caller continues to own this object (plugin may not delete it), and * The caller continues to own this object (plugin may not delete it), and
* plugins should expect it to be optionally NULL. * plugins should expect it to be optionally NULL.
* *
* @throw IO_ERROR if there is a problem saving or duplicate alias names. * @throw IO_ERROR if there is a problem saving.
*/ */
virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol, virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
const PROPERTIES* aProperties = NULL ); const PROPERTIES* aProperties = NULL );
@ -374,23 +376,22 @@ public:
const PROPERTIES* aProperties = NULL ); const PROPERTIES* aProperties = NULL );
/** /**
* Function SymbolLibCreate * Function CreateSymbolLib
* creates a new empty footprint library at @a aLibraryPath empty. It is an * creates a new empty symbol library at @a aLibraryPath. It is an error to attempt
* error to attempt to create an existing library or to attempt to create * to create an existing library or to attempt to create on a "read only" location.
* on a "read only" location.
* *
* @param aLibraryPath is a locator for the "library", usually a directory, file, * @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints. * or URL containing several footprints.
* *
* @param aProperties is an associative array that can be used to tell the * @param aProperties is an associative array that can be used to tell the library
* library create function anything special, because it can take any number of * create function anything special, because it can take any number
* additional named tuning arguments that the plugin is known to support. * of additional named tuning arguments that the plugin is known to
* The caller continues to own this object (plugin may not delete it), and * support. The caller continues to own this object (plugin may not
* plugins should expect it to be optionally NULL. * delete it), and plugins should expect it to be optionally NULL.
* *
* @throw IO_ERROR if there is a problem finding the library, or creating it. * @throw IO_ERROR if there is a problem finding the library, or creating it.
*/ */
virtual void SymbolLibCreate( const wxString& aLibraryPath, virtual void CreateSymbolLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ); const PROPERTIES* aProperties = NULL );
/** /**

View File

@ -3373,3 +3373,24 @@ void SCH_LEGACY_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxStri
m_cache->DeleteSymbol( aAliasName ); m_cache->DeleteSymbol( aAliasName );
} }
void SCH_LEGACY_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
if( wxFileExists( aLibraryPath ) )
{
THROW_IO_ERROR( wxString::Format(
_( "symbol library '%s' already exists, cannot create a new library" ),
aLibraryPath.GetData() ) );
}
LOCALE_IO toggle;
m_props = aProperties;
delete m_cache;
m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
m_cache->Save();
m_cache->Load(); // update m_writable and m_mod_time
}

View File

@ -92,9 +92,10 @@ public:
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;
void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName, void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;
void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName, void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
const PROPERTIES* aProperties = NULL ) override; const PROPERTIES* aProperties = NULL ) override;
void CreateSymbolLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override;
// Temporary for testing using PART_LIB instead of SCH_PLUGIN. // Temporary for testing using PART_LIB instead of SCH_PLUGIN.
void TransferCache( PART_LIB& aTarget ) override; void TransferCache( PART_LIB& aTarget ) override;

View File

@ -107,7 +107,7 @@ void SCH_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxString& aAl
} }
void SCH_PLUGIN::SymbolLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties ) void SCH_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath, const PROPERTIES* aProperties )
{ {
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface. // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ ); not_implemented( this, __FUNCTION__ );