Eeschema: add delete symbol library code to schematic legacy plugin.

This commit is contained in:
Wayne Stambaugh 2016-10-09 08:29:44 -04:00
parent f14dc8f2be
commit 213ceaa280
4 changed files with 89 additions and 51 deletions

View File

@ -191,6 +191,7 @@ public:
//-----<PUBLIC SCH_PLUGIN API>-------------------------------------------------
/**
*
* Function GetName
* returns a brief hard coded name for this SCH_PLUGIN.
*/
@ -204,50 +205,53 @@ public:
/**
* Function Load
*
* loads information from some input file format that this SCH_PLUGIN implementation
* knows about, into either a new SCHEMATIC or an existing one. This may be used to load an
* entire new SCHEMATIC, or to augment an existing one if @a aAppendToMe is not NULL.
*
* @param aFileName is the name of the file to use as input and may be foreign in
* nature or native in nature.
* nature or native in nature.
*
* @param aAppendToMe is an existing SCHEMATIC to append to, but if NULL then
* this means "do not append, rather load anew".
* @param aAppendToMe is an existing SCHEMATIC to append to, but if NULL then this means
* "do not append, rather load anew".
*
* @param aProperties is an associative array that can be used to tell the
* loader how to load the file, because it can take any number of
* additional named arguments that the plugin is known to support. These are
* tuning parameters for the import or load. The caller continues to own
* this object (plugin may not delete it), and plugins should expect it to
* be optionally NULL.
* @param aProperties is an associative array that can be used to tell the loader how to
* load the file, because it can take any number of additional named
* arguments that the plugin is known to support. These are tuning
* parameters for the import or load. The caller continues to own
* this object (plugin may not delete it), and plugins should expect
* it to be optionally NULL.
*
* @return SCHEMATIC* - the successfully loaded schematic, or the same one as \a aAppendToMe
* if \a aAppendToMe was not NULL, and the caller owns it.
* if \a aAppendToMe was not NULL, and the caller owns it.
*
* @throw IO_ERROR if there is a problem loading, and its contents should
* say what went wrong, using line number and character offsets of the
* input file if possible.
* @throw IO_ERROR if there is a problem loading, and its contents should say what went
* wrong, using line number and character offsets of the input file if
* possible.
*/
virtual SCH_SHEET* Load( const wxString& aFileName, KIWAY* aKiway,
SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL );
/**
* Function Save
*
* will write @a aSchematic to a storage file in a format that this
* SCH_PLUGIN implementation knows about, or it can be used to write a portion of
* aSchematic to a special kind of export file.
*
* @param aFileName is the name of a file to save to on disk.
*
* @param aSchematic is the class SCHEMATIC in memory document tree from which to
* extract information when writing to \a aFileName. The caller continues to
* own the SCHEMATIC, and the plugin should refrain from modifying the SCHEMATIC if possible.
* @param aSchematic is the class SCHEMATIC in memory document tree from which to extract
* information when writing to \a aFileName. The caller continues to
* own the SCHEMATIC, and the plugin should refrain from modifying the
* SCHEMATIC if possible.
*
* @param aProperties is an associative array that can be used to tell the
* saver how to save the file, because it can take any number of
* additional named tuning arguments that the plugin is known to support.
* The caller continues to own this object (plugin may not delete it),
* and plugins should expect it to be optionally NULL.
* @param aProperties is an associative array that can be used to tell the saver how to
* save the file, because it can take any number of additional named
* tuning arguments that the plugin is known to support. The caller
* continues to own this object (plugin may not delete it), and plugins
* should expect it to be optionally NULL.
*
* @throw IO_ERROR if there is a problem saving or exporting.
*/
@ -256,6 +260,7 @@ public:
/**
* Function EnumerateSymbolLib
*
* returns a list of #LIB_PART alias names contained within the library @a aLibraryPath.
*
* @param aAliasNameList is an array to populate with the #LIB_ALIAS names associated with
@ -278,6 +283,7 @@ public:
/**
* Function LoadSymbol
*
* loads a #LIB_ALIAS object having @a aAliasName from the @a aLibraryPath containing
* a library format that this SCH_PLUGIN knows about. The #LIB_PART should be accessed
* indirectly using the #LIB_ALIAS it is associated with.
@ -330,6 +336,7 @@ public:
/**
* Function DeleteAlias
*
* deletes @a aAliasName from the library at @a aLibraryPath.
*
* If @a aAliasName refers the the root #LIB_PART object, the part is renamed to
@ -355,6 +362,7 @@ public:
/**
* Function DeleteSymbol
*
* deletes the entire #LIB_PART associated with @a aAliasName from the library
* @a aLibraryPath.
*
@ -377,6 +385,7 @@ public:
/**
* Function CreateSymbolLib
*
* creates a new empty symbol library at @a aLibraryPath. It is an error to attempt
* to create an existing library or to attempt to create on a "read only" location.
*
@ -395,25 +404,27 @@ public:
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolLibDelete
* deletes an existing footprint library and returns true, or if library does not
* exist returns false, or throws an exception if library exists but is read only or
* cannot be deleted for some other reason.
* Function DeleteSymbolLib
*
* @param aLibraryPath is a locator for the "library", usually a directory
* or file which will contain footprints.
* deletes an existing symbol library and returns true if successful, or if library
* does not exist returns false, or throws an exception if library exists but is read
* only or cannot be deleted for some other reason.
*
* @param aProperties is an associative array that can be used to tell the
* library delete implementation function anything special, because it can
* take any number of additional named tuning arguments that the plugin is
* known to support. The caller continues to own this object (plugin may
* not delete it), and plugins should expect it to be optionally NULL.
* @param aLibraryPath is a locator for the "library", usually a directory or file
* which will contain symbols.
*
* @param aProperties is an associative array that can be used to tell the library
* delete implementation function anything special, because it can
* take any number of additional named tuning arguments that the
* plugin is known to support. The caller continues to own this
* object (plugin may not delete it), and plugins should expect
* it to be optionally NULL.
*
* @return bool - true if library deleted, false if library did not exist.
*
* @throw IO_ERROR if there is a problem deleting an existing library.
*/
virtual bool SymbolLibDelete( const wxString& aLibraryPath,
virtual bool DeleteSymbolLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL );
/**
@ -422,7 +433,7 @@ public:
* system libraries are read only because of where they are installed.)
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
* or URL containing several symbols.
*
* @throw IO_ERROR if no library at aLibraryPath exists.
*/
@ -430,13 +441,13 @@ public:
/**
* Function SymbolLibOptions
* appends supported SCH_PLUGIN options to @a aListToAppenTo along with
* internationalized descriptions. Options are typically appended so
* that a derived SCH_PLUGIN can call its base class
* function by the same name first, thus inheriting options declared there.
* (Some base class options could pertain to all Symbol*() functions
* in all derived SCH_PLUGINs.) Note that since aListToAppendTo is a PROPERTIES
* object, all options will be unique and last guy wins.
*
* appends supported SCH_PLUGIN options to @a aListToAppenTo along with internationalized
* descriptions. Options are typically appended so that a derived SCH_PLUGIN can call
* its base class function by the same name first, thus inheriting options declared there.
* (Some base class options could pertain to all Symbol*() functions in all derived
* SCH_PLUGINs.) Note that since aListToAppendTo is a PROPERTIES object, all options
* will be unique and last guy wins.
*
* @param aListToAppendTo holds a tuple of
* <dl>
@ -471,6 +482,7 @@ public:
/**
* Class SCH_PLUGIN_RELEASER
*
* releases a SCH_PLUGIN in the context of a potential thrown exception, through
* its destructor.
*/

View File

@ -3394,3 +3394,29 @@ void SCH_LEGACY_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath,
m_cache->Save();
m_cache->Load(); // update m_writable and m_mod_time
}
bool SCH_LEGACY_PLUGIN::DeleteSymbolLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties )
{
wxFileName fn = aLibraryPath;
if( !fn.FileExists() )
return false;
// Some of the more elaborate wxRemoveFile() crap puts up its own wxLog dialog
// we don't want that. we want bare metal portability with no UI here.
if( wxRemove( aLibraryPath ) )
{
THROW_IO_ERROR( wxString::Format( _( "library '%s' cannot be deleted" ),
aLibraryPath.GetData() ) );
}
if( m_cache && m_cache->IsFile( aLibraryPath ) )
{
delete m_cache;
m_cache = 0;
}
return true;
}

View File

@ -96,6 +96,8 @@ public:
const PROPERTIES* aProperties = NULL ) override;
void CreateSymbolLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override;
bool DeleteSymbolLib( const wxString& aLibraryPath,
const PROPERTIES* aProperties = NULL ) override;
// Temporary for testing using PART_LIB instead of SCH_PLUGIN.
void TransferCache( PART_LIB& aTarget ) override;

View File

@ -36,9 +36,8 @@
static void not_implemented( SCH_PLUGIN* aPlugin, const char* aCaller )
{
THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED,
aPlugin->GetName().GetData(),
wxString::FromUTF8( aCaller ).GetData() )
);
aPlugin->GetName().GetData(),
wxString::FromUTF8( aCaller ).GetData() ) );
}
@ -114,7 +113,7 @@ void SCH_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath, const PROPERTIES
}
bool SCH_PLUGIN::SymbolLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
bool SCH_PLUGIN::DeleteSymbolLib( const wxString& aLibraryPath, const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );
@ -136,16 +135,16 @@ void SCH_PLUGIN::SymbolLibOptions( PROPERTIES* aListToAppendTo ) const
#if 1
(*aListToAppendTo)["debug_level"] = UTF8( _(
"Enable <b>debug</b> logging for Symbol*() functions in this SCH_PLUGIN."
));
) );
(*aListToAppendTo)["read_filter_regex"] = UTF8( _(
"Regular expression <b>symbol name</b> filter."
));
) );
(*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
"Enable transaction logging. The mere presence of this option turns on the "
"logging, no need to set a Value."
));
) );
(*aListToAppendTo)["username"] = UTF8( _(
"User name for <b>login</b> to some special library server."
@ -153,7 +152,7 @@ void SCH_PLUGIN::SymbolLibOptions( PROPERTIES* aListToAppendTo ) const
(*aListToAppendTo)["password"] = UTF8( _(
"Password for <b>login</b> to some special library server."
));
) );
#endif
#if 1
@ -161,7 +160,6 @@ void SCH_PLUGIN::SymbolLibOptions( PROPERTIES* aListToAppendTo ) const
// if and when implemented.
(*aListToAppendTo)["python_symbol_plugin"] = UTF8( _(
"Enter the python symbol which implements the SCH_PLUGIN::Symbol*() functions."
));
) );
#endif
}