diff --git a/eeschema/libraries/symbol_library_manager_adapter.cpp b/eeschema/libraries/symbol_library_manager_adapter.cpp index 6b27b43aa0..730c415bf7 100644 --- a/eeschema/libraries/symbol_library_manager_adapter.cpp +++ b/eeschema/libraries/symbol_library_manager_adapter.cpp @@ -79,6 +79,8 @@ LIBRARY_RESULT SYMBOL_LIBRARY_MANAGER_ADAPTER::loadIfNeeded( const wx SCH_IO* plugin = SCH_IO_MGR::FindPlugin( type ); wxCHECK( plugin, tl::unexpected( LIBRARY_ERROR( _( "Internal error" ) ) ) ); + plugin->SetLibraryManagerAdapter( this ); + std::lock_guard lock( aMutex ); aTarget[ row->Nickname() ].row = row; @@ -90,8 +92,6 @@ LIBRARY_RESULT SYMBOL_LIBRARY_MANAGER_ADAPTER::loadIfNeeded( const wx return &aTarget.at( aNickname ); } - wxLogTrace( traceLibraries, "Library %s not found in library table (%s)", - aNickname, magic_enum::enum_name( aScope ) ); return nullptr; } @@ -389,3 +389,20 @@ std::vector> SYMBOL_LIBRARY_MANAGER_ADAPTER::Get return ret; } + + +int SYMBOL_LIBRARY_MANAGER_ADAPTER::GetModifyHash() const +{ + int hash = 0; + + for( const LIBRARY_TABLE_ROW* row : m_manager.Rows( LIBRARY_TABLE_TYPE::SYMBOL ) ) + { + if( std::optional result = fetchIfLoaded( row->Nickname() ); + const LIB_DATA* rowData = *result ) + { + hash += rowData->plugin->GetModifyHash(); + } + } + + return hash; +} diff --git a/eeschema/libraries/symbol_library_manager_adapter.h b/eeschema/libraries/symbol_library_manager_adapter.h index 4f76a638ae..75adba6e1e 100644 --- a/eeschema/libraries/symbol_library_manager_adapter.h +++ b/eeschema/libraries/symbol_library_manager_adapter.h @@ -161,6 +161,8 @@ public: static std::optional ParseLibType( const wxString& aType ); + int GetModifyHash() const override; + protected: void doPreload() override {} diff --git a/eeschema/sch_io/database/sch_io_database.cpp b/eeschema/sch_io/database/sch_io_database.cpp index 00f26a2b33..61beef1687 100644 --- a/eeschema/sch_io/database/sch_io_database.cpp +++ b/eeschema/sch_io/database/sch_io_database.cpp @@ -26,9 +26,11 @@ #include +#include #include #include #include +#include #include #include #include @@ -36,8 +38,11 @@ #include "sch_io_database.h" -SCH_IO_DATABASE::SCH_IO_DATABASE() : SCH_IO( wxS( "Database library" ) ), - m_libTable( nullptr ), + + +SCH_IO_DATABASE::SCH_IO_DATABASE() : + SCH_IO( wxS( "Database library" ) ), + m_adapter( nullptr ), m_settings(), m_conn() { @@ -67,7 +72,7 @@ void SCH_IO_DATABASE::EnumerateSymbolLib( std::vector& aSymbolList, const wxString& aLibraryPath, const std::map* aProperties ) { - wxCHECK_RET( m_libTable, "Database plugin missing library table handle!" ); + wxCHECK_RET( m_adapter, "Database plugin missing library manager adapter handle!" ); ensureSettings( aLibraryPath ); ensureConnection(); cacheLib(); @@ -91,7 +96,7 @@ LIB_SYMBOL* SCH_IO_DATABASE::LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName, const std::map* aProperties ) { - wxCHECK( m_libTable, nullptr ); + wxCHECK_MSG( m_adapter, nullptr, "Database plugin missing library manager adapter handle!" ); ensureSettings( aLibraryPath ); ensureConnection(); @@ -219,7 +224,7 @@ void SCH_IO_DATABASE::cacheLib() { long long currentTimestampSeconds = wxDateTime::Now().GetValue().GetValue() / 1000; - if( m_libTable->GetModifyHash() == m_cacheModifyHash + if( m_adapter->GetModifyHash() == m_cacheModifyHash && ( currentTimestampSeconds - m_cacheTimestamp ) < m_settings->m_Cache.max_age ) { return; @@ -269,7 +274,7 @@ void SCH_IO_DATABASE::cacheLib() m_sanitizedNameMap = std::move( newSanitizedNameMap ); m_cacheTimestamp = currentTimestampSeconds; - m_cacheModifyHash = m_libTable->GetModifyHash(); + m_cacheModifyHash = m_adapter->GetModifyHash(); } void SCH_IO_DATABASE::ensureSettings( const wxString& aSettingsPath ) @@ -455,7 +460,7 @@ std::unique_ptr SCH_IO_DATABASE::loadSymbolFromRow( const wxString& symbolId.Parse( std::any_cast( aRow.at( aTable.symbols_col ) ) ); if( symbolId.IsValid() ) - originalSymbol = m_libTable->LoadSymbol( symbolId ); + originalSymbol = m_adapter->LoadSymbol( symbolId ); if( originalSymbol ) { diff --git a/eeschema/sch_io/database/sch_io_database.h b/eeschema/sch_io/database/sch_io_database.h index 41603954e1..4c6e34b496 100644 --- a/eeschema/sch_io/database/sch_io_database.h +++ b/eeschema/sch_io/database/sch_io_database.h @@ -28,6 +28,7 @@ #include +class LIBRARY_MANAGER_ADAPTER; class DATABASE_LIB_SETTINGS; struct DATABASE_LIB_TABLE; @@ -76,9 +77,9 @@ public: // Database libraries can never be written using the symbol editing API bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; } - void SetLibTable( SYMBOL_LIB_TABLE* aTable ) override + void SetLibraryManagerAdapter( SYMBOL_LIBRARY_MANAGER_ADAPTER* aAdapter ) override { - m_libTable = aTable; + m_adapter = aAdapter; } DATABASE_LIB_SETTINGS* Settings() const { return m_settings.get(); } @@ -100,7 +101,7 @@ private: static std::optional boolFromAny( const std::any& aVal ); - SYMBOL_LIB_TABLE* m_libTable; + SYMBOL_LIBRARY_MANAGER_ADAPTER* m_adapter; std::unique_ptr m_settings; diff --git a/eeschema/sch_io/http_lib/sch_io_http_lib.cpp b/eeschema/sch_io/http_lib/sch_io_http_lib.cpp index f42cec3784..3f98a57685 100644 --- a/eeschema/sch_io/http_lib/sch_io_http_lib.cpp +++ b/eeschema/sch_io/http_lib/sch_io_http_lib.cpp @@ -25,13 +25,14 @@ #include #include +#include #include #include "sch_io_http_lib.h" SCH_IO_HTTP_LIB::SCH_IO_HTTP_LIB() : SCH_IO( wxS( "HTTP library" ) ), - m_libTable( nullptr ) + m_adapter( nullptr ) { } @@ -50,7 +51,7 @@ void SCH_IO_HTTP_LIB::EnumerateSymbolLib( wxArrayString& aSymbolNameList, const void SCH_IO_HTTP_LIB::EnumerateSymbolLib( std::vector& aSymbolList, const wxString& aLibraryPath, const std::map* aProperties ) { - wxCHECK_RET( m_libTable, _( "httplib plugin missing library table handle!" ) ); + wxCHECK_RET( m_adapter, "HTTP plugin missing library manager adapter handle!" ); ensureSettings( aLibraryPath ); ensureConnection(); @@ -95,7 +96,7 @@ void SCH_IO_HTTP_LIB::EnumerateSymbolLib( std::vector& aSymbolList, LIB_SYMBOL* SCH_IO_HTTP_LIB::LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName, const std::map* aProperties ) { - wxCHECK( m_libTable, nullptr ); + wxCHECK_MSG( m_adapter, nullptr, "HTTP plugin missing library manager adapter handle!" ); ensureSettings( aLibraryPath ); ensureConnection(); @@ -354,7 +355,7 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbolName, symbolId.Parse( symbolIdStr ); if( symbolId.IsValid() ) - originalSymbol = m_libTable->LoadSymbol( symbolId ); + originalSymbol = m_adapter->LoadSymbol( symbolId ); if( originalSymbol ) { diff --git a/eeschema/sch_io/http_lib/sch_io_http_lib.h b/eeschema/sch_io/http_lib/sch_io_http_lib.h index 5244706774..b0c01a9dad 100644 --- a/eeschema/sch_io/http_lib/sch_io_http_lib.h +++ b/eeschema/sch_io/http_lib/sch_io_http_lib.h @@ -27,6 +27,8 @@ #include #include +class LIBRARY_MANAGER_ADAPTER; + /** * A KiCad HTTP library provides both symbol and footprint metadata, so there are "shim" plugins * on both the symbol and footprint side of things that expose the database contents to the @@ -68,7 +70,10 @@ public: bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; } - void SetLibTable( SYMBOL_LIB_TABLE* aTable ) override { m_libTable = aTable; } + void SetLibraryManagerAdapter( SYMBOL_LIBRARY_MANAGER_ADAPTER* aAdapter ) override + { + m_adapter = aAdapter; + } HTTP_LIB_SETTINGS* Settings() const { return m_settings.get(); } @@ -92,7 +97,7 @@ private: const HTTP_LIB_PART& aPart ); private: - SYMBOL_LIB_TABLE* m_libTable; + SYMBOL_LIBRARY_MANAGER_ADAPTER* m_adapter; /// Generally will be null if no valid connection is established std::unique_ptr m_conn; diff --git a/eeschema/sch_io/sch_io.h b/eeschema/sch_io/sch_io.h index a5e4f64804..18e85722b0 100644 --- a/eeschema/sch_io/sch_io.h +++ b/eeschema/sch_io/sch_io.h @@ -32,6 +32,8 @@ #include #include +class SYMBOL_LIBRARY_MANAGER_ADAPTER; + /** * Base class that schematic file and library loading and saving plugins should derive from. * Implementations can provide either LoadSchematicFile() or SaveSchematicFile() functions, @@ -351,10 +353,10 @@ public: virtual const wxString& GetError() const; /** - * Some library plugins need to have access to their parent library table. - * @param aTable is the table this plugin is registered within. + * Some library plugins need to interface with other loaded libraries. + * To do this, they receive a reference to the project-specific manager adapter. */ - virtual void SetLibTable( SYMBOL_LIB_TABLE* aTable ) {} + virtual void SetLibraryManagerAdapter( SYMBOL_LIBRARY_MANAGER_ADAPTER* aAdapter ) {} //----------------------------------------------------- diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 596cfc2613..e3916f1cd0 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -81,7 +81,6 @@ bool SYMBOL_LIB_TABLE_ROW::Refresh() plugin.reset( SCH_IO_MGR::FindPlugin( type ) ); SetLoaded( false ); - plugin->SetLibTable( static_cast( GetParent() ) ); plugin->EnumerateSymbolLib( dummyList, GetFullURI( true ), GetProperties() ); SetLoaded( true ); return true; @@ -366,8 +365,6 @@ SYMBOL_LIB_TABLE_ROW* SYMBOL_LIB_TABLE::FindRow( const wxString& aNickname, bool if( !row->plugin ) row->setPlugin( SCH_IO_MGR::FindPlugin( row->type ) ); - row->plugin->SetLibTable( this ); - return row; } @@ -388,7 +385,6 @@ void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector& aSymbolList, row->SetOptions( row->GetOptions() + " " + PropPowerSymsOnly ); row->SetLoaded( false ); - row->plugin->SetLibTable( this ); row->plugin->EnumerateSymbolLib( aSymbolList, row->GetFullURI( true ), row->GetProperties() ); row->SetLoaded( true ); diff --git a/include/libraries/library_manager.h b/include/libraries/library_manager.h index 925ff6fedf..6eb2f4d7a3 100644 --- a/include/libraries/library_manager.h +++ b/include/libraries/library_manager.h @@ -98,6 +98,8 @@ public: ~LIBRARY_MANAGER_ADAPTER() override = default; + virtual int GetModifyHash() const { return 0; }; + protected: virtual void doPreload() = 0;