Eeschema: add delete alias from library to I/O manager.

Modify base I/O manager class to delete alias from a symbol library.

Add delete alias from legacy symbol library plugin.
This commit is contained in:
Wayne Stambaugh 2016-09-23 13:28:38 -04:00
parent 3a50f7367f
commit 58abb29827
4 changed files with 72 additions and 17 deletions

View File

@ -283,7 +283,7 @@ public:
* indirectly using the #LIB_ALIAS it is associated with.
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
* or URL containing several symbols.
*
* @param aAliasName is the alias name of the #LIB_PART to load.
*
@ -310,7 +310,7 @@ public:
* alias names.
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
* or URL containing several symbols.
*
* @param aSymbol is what to store in the library. The library is refreshed and the
* caller must update any #LIB_PART pointers that may have changed.
@ -327,24 +327,29 @@ public:
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolDelete
* deletes @a aSymbolName from the library at @a aLibraryPath.
* 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
* the next or previous #LIB_ALIAS in the #LIB_PART if one exists. If the #LIB_ALIAS
* is the last alias referring to the root #LIB_PART, the #LIB_PART is also removed
* from the library.
*
* @param aLibraryPath is a locator for the "library", usually a directory, file,
* or URL containing several footprints.
* or URL containing several symbols.
*
* @param aSymbolName is the name of a footprint to delete from the specified library.
* @param aAliasName is the name of a #LIB_ALIAS to delete from the specified library.
*
* @param aProperties is an associative array that can be used to tell the
* library delete 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 aProperties is an associative array that can be used to tell the library
* delete 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.
*
* @throw IO_ERROR if there is a problem finding the footprint or the library, or deleting it.
* @throw IO_ERROR if there is a problem finding the alias or the library or deleting it.
*/
virtual void SymbolDelete( const wxString& aLibraryPath, const wxString& aSymbolName,
const PROPERTIES* aProperties = NULL );
virtual void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
const PROPERTIES* aProperties = NULL );
/**
* Function SymbolLibCreate

View File

@ -1946,7 +1946,9 @@ public:
void AddSymbol( const LIB_PART* aPart );
wxDateTime GetLibModificationTime();
void DeleteAlias( const wxString& aAliasName );
wxDateTime GetLibModificationTime();
bool IsFile( const wxString& aFullPathAndFileName ) const;
@ -3200,6 +3202,41 @@ void SCH_LEGACY_PLUGIN_CACHE::Save()
}
void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias( const wxString& aAliasName )
{
LIB_ALIAS_MAP::iterator it = m_aliases.find( aAliasName );
if( it == m_aliases.end() )
THROW_IO_ERROR( wxString::Format( _( "library %s does not contain an alias %s" ),
m_libFileName.GetFullName(), aAliasName ) );
LIB_ALIAS* alias = it->second;
LIB_PART* part = alias->GetPart();
alias = part->RemoveAlias( alias );
if( !alias )
{
delete part;
if( m_aliases.size() > 1 )
{
LIB_ALIAS_MAP::iterator next = it;
next++;
if( next == m_aliases.end() )
next = m_aliases.begin();
alias = next->second;
}
}
m_aliases.erase( it );
++m_modHash;
m_isModified = true;
}
void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName )
{
if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
@ -3275,3 +3312,14 @@ void SCH_LEGACY_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_PART
m_cache->AddSymbol( aSymbol );
m_cache->Save();
}
void SCH_LEGACY_PLUGIN::DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
const PROPERTIES* aProperties )
{
m_props = aProperties;
cacheLib( aLibraryPath );
m_cache->DeleteAlias( aAliasName );
}

View File

@ -90,6 +90,8 @@ public:
const PROPERTIES* aProperties = NULL );
void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
const PROPERTIES* aProperties = NULL );
void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
const PROPERTIES* aProperties = NULL );
// Temporary for testing using PART_LIB instead of SCH_PLUGIN.
void TransferCache( PART_LIB& aTarget );

View File

@ -91,8 +91,8 @@ void SCH_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymb
}
void SCH_PLUGIN::SymbolDelete( const wxString& aLibraryPath, const wxString& aSymbolName,
const PROPERTIES* aProperties )
void SCH_PLUGIN::DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
const PROPERTIES* aProperties )
{
// not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
not_implemented( this, __FUNCTION__ );