diff --git a/eeschema/sch_io_mgr.h b/eeschema/sch_io_mgr.h index 7d699eb22c..0a7e6b93bb 100644 --- a/eeschema/sch_io_mgr.h +++ b/eeschema/sch_io_mgr.h @@ -304,10 +304,12 @@ public: /** * 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 - * alias names, an exception is thrown. Symbol libraries cannot have duplicate - * alias names. + * + * 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 alias names, the new + * #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, * or URL containing several symbols. @@ -321,7 +323,7 @@ public: * 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 duplicate alias names. + * @throw IO_ERROR if there is a problem saving. */ virtual void SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol, const PROPERTIES* aProperties = NULL ); @@ -374,23 +376,22 @@ public: const PROPERTIES* aProperties = NULL ); /** - * Function SymbolLibCreate - * creates a new empty footprint library at @a aLibraryPath empty. It is an - * error to attempt to create an existing library or to attempt to create - * on a "read only" location. + * 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. * * @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 - * library create 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 + * create 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 library, or creating it. */ - virtual void SymbolLibCreate( const wxString& aLibraryPath, + virtual void CreateSymbolLib( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL ); /** diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index c91e45a6de..2beeece702 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -3373,3 +3373,24 @@ void SCH_LEGACY_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxStri 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 +} diff --git a/eeschema/sch_legacy_plugin.h b/eeschema/sch_legacy_plugin.h index f873dac052..6cc396800a 100644 --- a/eeschema/sch_legacy_plugin.h +++ b/eeschema/sch_legacy_plugin.h @@ -92,9 +92,10 @@ public: const PROPERTIES* aProperties = NULL ) override; 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; + void CreateSymbolLib( const wxString& aLibraryPath, + 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 8243875396..e8b5d9b5eb 100644 --- a/eeschema/sch_plugin.cpp +++ b/eeschema/sch_plugin.cpp @@ -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_implemented( this, __FUNCTION__ );