From 24f6c4be219de23ec93721e31bc413fbf6fa9974 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 3 Sep 2016 14:28:17 -0400 Subject: [PATCH] Eeschema: add code to plugin manager to load a symbol from a library. --- eeschema/sch_io_mgr.h | 37 ++++++++++++++++++---------------- eeschema/sch_legacy_plugin.cpp | 19 ++++++++++++++++- eeschema/sch_legacy_plugin.h | 3 +++ eeschema/sch_plugin.cpp | 4 ++-- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/eeschema/sch_io_mgr.h b/eeschema/sch_io_mgr.h index 66679c8cdb..74017c7962 100644 --- a/eeschema/sch_io_mgr.h +++ b/eeschema/sch_io_mgr.h @@ -32,13 +32,14 @@ class SCH_SCREEN; class SCH_PLUGIN; class KIWAY; class LIB_PART; +class LIB_ALIAS; class PART_LIB; class PROPERTIES; /** * Class SCH_IO_MGR - * is a factory which returns an instance of a SCH_PLUGIN. + * is a factory which returns an instance of a #SCH_PLUGIN. */ class SCH_IO_MGR { @@ -112,7 +113,7 @@ public: /** * Function Load - * finds the requested SCH_PLUGIN and if found, calls the SCH_PLUGIN->Load(..) funtion + * finds the requested SCH_PLUGIN and if found, calls the SCH_PLUGIN->Load(..) function * on it using the arguments passed to this function. After the SCH_PLUGIN->Load() * function returns, the SCH_PLUGIN is Released() as part of this call. * @@ -276,28 +277,30 @@ public: virtual void TransferCache( PART_LIB& aTarget ); /** - * Function SymbolLoad - * loads a footprint having @a aSymbolName from the @a aLibraryPath containing - * a library format that this SCH_PLUGIN knows about. + * 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. * * @param aLibraryPath is a locator for the "library", usually a directory, file, - * or URL containing several footprints. + * or URL containing several footprints. * - * @param aSymbolName is the name of the footprint to load. + * @param aAliasName is the alias name of the #LIB_PART to load. * - * @param aProperties is an associative array that can be used to tell the - * loader implementation to do something 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 loader + * implementation to do something 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 MODULE* - if found caller owns it, else NULL if not found. + * @return LIB_ALIAS* - if found caller shares it, else NULL if not found. * * @throw IO_ERROR if the library cannot be found or read. No exception - * is thrown in the case where aSymbolName cannot be found. + * is thrown in the case where aAliasName cannot be found. */ - virtual LIB_PART* SymbolLoad( const wxString& aLibraryPath, const wxString& aSymbolName, - const PROPERTIES* aProperties = NULL ); + virtual LIB_ALIAS* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName, + const PROPERTIES* aProperties = NULL ); /** * Function SymbolSave @@ -385,7 +388,7 @@ public: /** * Function IsSymbolLibWritable - * returns true iff the library at @a aLibraryPath is writable. (Often + * returns true if the library at @a aLibraryPath is writable. (Often * system libraries are read only because of where they are installed.) * * @param aLibraryPath is a locator for the "library", usually a directory, file, diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index 7b92a1de16..b925a06922 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include #include @@ -3143,3 +3142,21 @@ void SCH_LEGACY_PLUGIN::TransferCache( PART_LIB& aTarget ) delete m_cache; m_cache = NULL; } + + +LIB_ALIAS* SCH_LEGACY_PLUGIN::LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName, + const PROPERTIES* aProperties ) +{ + LOCALE_IO toggle; // toggles on, then off, the C locale. + + m_props = aProperties; + + cacheLib( aLibraryPath ); + + LIB_ALIAS_MAP::const_iterator it = m_cache->m_aliases.find( TO_UTF8( aAliasName ) ); + + if( it == m_cache->m_aliases.end() ) + return NULL; + + return it->second; +} diff --git a/eeschema/sch_legacy_plugin.h b/eeschema/sch_legacy_plugin.h index d45ac0c880..1439c1fad2 100644 --- a/eeschema/sch_legacy_plugin.h +++ b/eeschema/sch_legacy_plugin.h @@ -42,6 +42,7 @@ class PROPERTIES; class SCH_LEGACY_PLUGIN_CACHE; class LIB_PART; class PART_LIB; +class LIB_ALIAS; /** @@ -85,6 +86,8 @@ public: void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL ); + LIB_ALIAS* LoadSymbol( 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 ); diff --git a/eeschema/sch_plugin.cpp b/eeschema/sch_plugin.cpp index ffcfc570a6..3df4e3530d 100644 --- a/eeschema/sch_plugin.cpp +++ b/eeschema/sch_plugin.cpp @@ -74,8 +74,8 @@ void SCH_PLUGIN::TransferCache( PART_LIB& aTarget ) } -LIB_PART* SCH_PLUGIN::SymbolLoad( const wxString& aLibraryPath, const wxString& aSymbolName, - const PROPERTIES* aProperties ) +LIB_ALIAS* SCH_PLUGIN::LoadSymbol( const wxString& aLibraryPath, const wxString& aSymbolName, + const PROPERTIES* aProperties ) { // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface. not_implemented( this, __FUNCTION__ );