From 33480ecad19804572897f60bc83ff78c2a70c5dd Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 17 Jul 2020 18:32:16 +0100 Subject: [PATCH] Show all symbol libraries by default. Also fixes an issue where the plugin wasn't getting reset if the library type was changed. --- common/fp_lib_table.cpp | 2 + common/wildcards_and_files_ext.cpp | 13 ++++- eeschema/dialogs/panel_sym_lib_table.cpp | 49 +++++++++++++++---- eeschema/symbol_lib_table.cpp | 17 +++++++ eeschema/symbol_lib_table.h | 7 +++ .../symbol_tree_synchronizing_adapter.cpp | 9 ++-- include/wildcards_and_files_ext.h | 1 + 7 files changed, 83 insertions(+), 15 deletions(-) diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index 01364a6851..a451c65870 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -56,6 +56,8 @@ void FP_LIB_TABLE_ROW::SetType( const wxString& aType ) if( IO_MGR::PCB_FILE_T( -1 ) == type ) type = IO_MGR::KICAD_SEXP; + + plugin.release(); } diff --git a/common/wildcards_and_files_ext.cpp b/common/wildcards_and_files_ext.cpp index 462b38dec4..53f351bc22 100644 --- a/common/wildcards_and_files_ext.cpp +++ b/common/wildcards_and_files_ext.cpp @@ -91,9 +91,12 @@ wxString AddFileExtListToFilter( const std::vector& aExts ) wxString files_filter = " ("; // Add extensions to the info message: - for( const auto& ext : aExts ) + for( const std::string& ext : aExts ) { - files_filter << " *." << ext; + if( files_filter.length() > 2 ) + files_filter << "; "; + + files_filter << "*." << ext; } files_filter << ")|*."; @@ -190,6 +193,12 @@ wxString LegacySymbolLibFileWildcard() } +wxString AllSymbolLibFilesWildcard() +{ + return _( "All KiCad symbol library files" ) + AddFileExtListToFilter( { "kicad_sym", "lib" } ); +} + + wxString ProjectFileWildcard() { return _( "KiCad project files" ) + AddFileExtListToFilter( { "kicad_pro" } ); diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index c9f660a565..9c379871fe 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -397,6 +397,39 @@ bool PANEL_SYM_LIB_TABLE::verifyTables() } } + for( SYMBOL_LIB_TABLE* table : { global_model(), project_model() } ) + { + for( unsigned int r = 0; r < table->GetCount(); ++r ) + { + SYMBOL_LIB_TABLE_ROW& row = dynamic_cast( table->At( r ) ); + + if( !row.GetIsEnabled() ) + continue; + + try + { + if( row.Refresh() ) + { + if( table == global_model() ) + m_parent->m_GlobalTableChanged = true; + else + m_parent->m_ProjectTableChanged = true; + } + } + catch( const IO_ERROR& ioe ) + { + wxString msg = wxString::Format( _( "Symbol library \"%s\" failed to load.\n %s" ), + row.GetNickName(), + ioe.What() ); + + wxMessageDialog errdlg( this, msg, _( "Error Loading Library" ) ); + errdlg.ShowModal(); + + return false; + } + } + } + return true; } @@ -410,12 +443,11 @@ void PANEL_SYM_LIB_TABLE::pageChangedHandler( wxAuiNotebookEvent& event ) void PANEL_SYM_LIB_TABLE::browseLibrariesHandler( wxCommandEvent& event ) { - wxString wildcards = KiCadSymbolLibFileWildcard(); + wxString wildcards = AllSymbolLibFilesWildcard() + + "|" + KiCadSymbolLibFileWildcard() + + "|" + LegacySymbolLibFileWildcard(); - wildcards += "|" + LegacySymbolLibFileWildcard(); - - wxFileDialog dlg( this, _( "Select Library" ), m_lastBrowseDir, - wxEmptyString, wildcards, + wxFileDialog dlg( this, _( "Select Library" ), m_lastBrowseDir, wxEmptyString, wildcards, wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE ); auto result = dlg.ShowModal(); @@ -646,7 +678,7 @@ bool PANEL_SYM_LIB_TABLE::TransferDataFromWindow() m_globalTable->Clear(); m_globalTable->rows.transfer( m_globalTable->rows.end(), global_model()->rows.begin(), - global_model()->rows.end(), global_model()->rows ); + global_model()->rows.end(), global_model()->rows ); m_globalTable->reindex(); } @@ -656,7 +688,7 @@ bool PANEL_SYM_LIB_TABLE::TransferDataFromWindow() m_projectTable->Clear(); m_projectTable->rows.transfer( m_projectTable->rows.end(), project_model()->rows.begin(), - project_model()->rows.end(), project_model()->rows ); + project_model()->rows.end(), project_model()->rows ); m_projectTable->reindex(); } @@ -847,8 +879,7 @@ void InvokeSchEditSymbolLibTable( KIWAY* aKiway, wxWindow *aParent ) if( libEditor ) { // Check if the currently selected symbol library been removed or disabled. - if( !currentLib.empty() - && !projectTable->HasLibrary( currentLib, true ) ) + if( !currentLib.empty() && !projectTable->HasLibrary( currentLib, true ) ) { libEditor->SetCurLib( wxEmptyString ); libEditor->emptyScreen(); diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index cbde2fb41b..b6c40ae117 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -66,6 +66,23 @@ void SYMBOL_LIB_TABLE_ROW::SetType( const wxString& aType ) if( SCH_IO_MGR::SCH_FILE_T( -1 ) == type ) type = SCH_IO_MGR::SCH_LEGACY; + + plugin.release(); +} + + +bool SYMBOL_LIB_TABLE_ROW::Refresh() +{ + if( !plugin ) + { + wxArrayString dummyList; + + plugin.set( SCH_IO_MGR::FindPlugin( type ) ); + plugin->EnumerateSymbolLib( dummyList, GetFullURI( true ), GetProperties() ); + return true; + } + + return false; } diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index f7a16b1a54..09a1d59ed7 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -75,6 +75,13 @@ public: */ void SetType( const wxString& aType ) override; + /** + * Attempt to reload the library. + * @return true if a reload was required. + * @throws IO_ERROR if the reload was unsuccessful. + */ + bool Refresh(); + protected: SYMBOL_LIB_TABLE_ROW( const SYMBOL_LIB_TABLE_ROW& aRow ) : LIB_TABLE_ROW( aRow ), diff --git a/eeschema/symbol_tree_synchronizing_adapter.cpp b/eeschema/symbol_tree_synchronizing_adapter.cpp index 589353cb09..3fe648936b 100644 --- a/eeschema/symbol_tree_synchronizing_adapter.cpp +++ b/eeschema/symbol_tree_synchronizing_adapter.cpp @@ -95,7 +95,7 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync( bool aForce, it = deleteLibrary( it ); continue; } - else if( m_libMgr->GetLibraryHash( name ) != m_libHashes[name] ) + else if( aForce || m_libMgr->GetLibraryHash( name ) != m_libHashes[name] ) { updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() ); } @@ -159,9 +159,10 @@ void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary( LIB_TREE_NODE_LIB& aLibNo for( auto nodeIt = aLibNode.m_Children.begin(); nodeIt != aLibNode.m_Children.end(); /**/ ) { auto aliasIt = std::find_if( aliases.begin(), aliases.end(), - [&] ( const LIB_PART* a ) { - return a->GetName() == (*nodeIt)->m_Name; - } ); + [&] ( const LIB_PART* a ) + { + return a->GetName() == (*nodeIt)->m_Name; + } ); if( aliasIt != aliases.end() ) { diff --git a/include/wildcards_and_files_ext.h b/include/wildcards_and_files_ext.h index 6c351ea58c..4de8c40311 100644 --- a/include/wildcards_and_files_ext.h +++ b/include/wildcards_and_files_ext.h @@ -178,6 +178,7 @@ extern wxString PageLayoutDescrFileWildcard(); extern wxString SchematicSymbolFileWildcard(); extern wxString KiCadSymbolLibFileWildcard(); extern wxString LegacySymbolLibFileWildcard(); +extern wxString AllSymbolLibFilesWildcard(); extern wxString ProjectFileWildcard(); extern wxString LegacyProjectFileWildcard(); extern wxString AllProjectFilesWildcard();