From aa5e979b8a3c5889864019c14f4ebcd50b82aac5 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Thu, 29 Sep 2016 18:31:43 -0400 Subject: [PATCH] Eeschema: add delete symbol method to schematic I/O plugin. --- eeschema/sch_io_mgr.h | 22 ++++++++++++++++++++++ eeschema/sch_legacy_plugin.cpp | 32 ++++++++++++++++++++++++++++++++ eeschema/sch_legacy_plugin.h | 3 +++ eeschema/sch_plugin.cpp | 8 ++++++++ 4 files changed, 65 insertions(+) diff --git a/eeschema/sch_io_mgr.h b/eeschema/sch_io_mgr.h index 6cbf23c679..7d699eb22c 100644 --- a/eeschema/sch_io_mgr.h +++ b/eeschema/sch_io_mgr.h @@ -351,6 +351,28 @@ public: virtual void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName, const PROPERTIES* aProperties = NULL ); + /** + * Function DeleteSymbol + * deletes the entire #LIB_PART associated with @a aAliasName from the library + * @a aLibraryPath. + * + * @param aLibraryPath is a locator for the "library", usually a directory, file, + * or URL containing several symbols. + * + * @param aAliasName is the name of a #LIB_ALIAS associated with it's root #LIB_PART + * object 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. + * + * @throw IO_ERROR if there is a problem finding the alias or the library or deleting it. + */ + virtual void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName, + const PROPERTIES* aProperties = NULL ); + /** * Function SymbolLibCreate * creates a new empty footprint library at @a aLibraryPath empty. It is an diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index 6b6b0a745f..155a8f8aef 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -1948,6 +1948,8 @@ public: void DeleteAlias( const wxString& aAliasName ); + void DeleteSymbol( const wxString& aAliasName ); + wxDateTime GetLibModificationTime(); bool IsFile( const wxString& aFullPathAndFileName ) const; @@ -3237,6 +3239,25 @@ void SCH_LEGACY_PLUGIN_CACHE::DeleteAlias( const wxString& aAliasName ) } +void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol( 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(); + + wxArrayString aliasNames = part->GetAliasNames(); + + // Deleting all of the aliases deletes the symbol from the library. + for( size_t i = 0; i < aliasNames.Count(); i++ ) + DeleteAlias( aliasNames[i] ); +} + + void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName ) { if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() ) @@ -3323,3 +3344,14 @@ void SCH_LEGACY_PLUGIN::DeleteAlias( const wxString& aLibraryPath, const wxStrin m_cache->DeleteAlias( aAliasName ); } + + +void SCH_LEGACY_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName, + const PROPERTIES* aProperties ) +{ + m_props = aProperties; + + cacheLib( aLibraryPath ); + + m_cache->DeleteSymbol( aAliasName ); +} diff --git a/eeschema/sch_legacy_plugin.h b/eeschema/sch_legacy_plugin.h index d65b6f1af5..f873dac052 100644 --- a/eeschema/sch_legacy_plugin.h +++ b/eeschema/sch_legacy_plugin.h @@ -93,6 +93,9 @@ public: void DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName, const PROPERTIES* aProperties = NULL ) override; + void DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName, + const PROPERTIES* aProperties = NULL ) override; + // Temporary for testing using PART_LIB instead of SCH_PLUGIN. void TransferCache( PART_LIB& aTarget ) override; diff --git a/eeschema/sch_plugin.cpp b/eeschema/sch_plugin.cpp index 7db17e7d50..8243875396 100644 --- a/eeschema/sch_plugin.cpp +++ b/eeschema/sch_plugin.cpp @@ -99,6 +99,14 @@ void SCH_PLUGIN::DeleteAlias( const wxString& aLibraryPath, const wxString& aAli } +void SCH_PLUGIN::DeleteSymbol( 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__ ); +} + + void SCH_PLUGIN::SymbolLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.