From 5c43924338d74b1e5cc6fa9833a9bd16e603ac04 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 10 Jul 2019 18:59:39 +0100 Subject: [PATCH] Display all "File couldn't be found" messages at the end. Fixes: lp:1810161 * https://bugs.launchpad.net/kicad/+bug/1810161 --- eeschema/class_library.cpp | 43 ----------------------- eeschema/class_library.h | 33 ------------------ eeschema/libedit/lib_manager.cpp | 58 ++++---------------------------- eeschema/libedit/lib_manager.h | 49 +++++++++++++++++---------- eeschema/sch_eagle_plugin.h | 3 -- eeschema/sch_io_mgr.h | 3 -- eeschema/sch_legacy_plugin.cpp | 23 ++----------- eeschema/sch_legacy_plugin.h | 2 -- eeschema/sch_plugin.cpp | 9 ----- eeschema/symbol_lib_table.cpp | 9 ----- eeschema/symbol_lib_table.h | 5 --- 11 files changed, 39 insertions(+), 198 deletions(-) diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index 56c9093e14..bd86e36115 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -164,28 +164,6 @@ void PART_LIB::GetAliases( std::vector& aAliases ) const } -void PART_LIB::GetEntryTypePowerNames( wxArrayString& aNames ) const -{ - std::vector aliases; - - m_plugin->EnumerateSymbolLib( aliases, fileName.GetFullPath() ); - - for( size_t i = 0; i < aliases.size(); i++ ) - { - LIB_ALIAS* alias = aliases[i]; - - LIB_PART* root = alias->GetPart(); - - if( !root || !root->IsPower() ) - continue; - - aNames.Add( alias->GetName() ); - } - - aNames.Sort(); -} - - LIB_ALIAS* PART_LIB::FindAlias( const wxString& aName ) const { LIB_ALIAS* alias = m_plugin->LoadSymbol( fileName.GetFullPath(), aName, m_properties.get() ); @@ -223,27 +201,6 @@ LIB_PART* PART_LIB::FindPart( const LIB_ID& aLibId ) const } -bool PART_LIB::HasPowerParts() const -{ - // return true if at least one power part is found in lib - std::vector aliases; - - m_plugin->EnumerateSymbolLib( aliases, fileName.GetFullPath(), m_properties.get() ); - - for( size_t i = 0; i < aliases.size(); i++ ) - { - LIB_ALIAS* alias = aliases[i]; - - LIB_PART* root = alias->GetPart(); - - if( !root || root->IsPower() ) - return true; - } - - return false; -} - - void PART_LIB::AddPart( LIB_PART* aPart ) { // add a clone, not the caller's copy, the plugin take ownership of the new symbol. diff --git a/eeschema/class_library.h b/eeschema/class_library.h index 821c68d899..e33dee7f98 100644 --- a/eeschema/class_library.h +++ b/eeschema/class_library.h @@ -344,26 +344,6 @@ public: void SetFileName( const wxString& aFileName ) { fileName = aFileName; } - /** - * Get library entry status. - * - * @return True if there are no entries in the library. - */ - bool IsEmpty() const - { - return m_plugin->GetSymbolLibCount( fileName.GetFullPath() ) == 0; - } - - /** - * Return the number of entries in the library. - * - * @return The number of part and alias entries. - */ - int GetCount() const - { - return (int) m_plugin->GetSymbolLibCount( fileName.GetFullPath() ); - } - bool IsModified() const { return isModified; @@ -398,13 +378,6 @@ public: */ void GetAliases( std::vector& aAliases ) const; - /** - * Load a string array with the names of entries of type POWER in this library. - * - * @param aNames - String array to place entry names into. - */ - void GetEntryTypePowerNames( wxArrayString& aNames ) const; - /** * Find #LIB_ALIAS by \a aName. * @@ -501,12 +474,6 @@ public: * @throw IO_ERROR if there's any problem loading the library. */ static PART_LIB* LoadLibrary( const wxString& aFileName ); - - /** - * @return true if at least one power part is found in lib - * Useful to select or list only libs containing power parts - */ - bool HasPowerParts() const; }; diff --git a/eeschema/libedit/lib_manager.cpp b/eeschema/libedit/lib_manager.cpp index 5e84c68f66..d8a4b0849f 100644 --- a/eeschema/libedit/lib_manager.cpp +++ b/eeschema/libedit/lib_manager.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -49,6 +48,8 @@ LIB_MANAGER::LIB_MANAGER( LIB_EDIT_FRAME& aFrame ) : void LIB_MANAGER::Sync( bool aForce, std::function aProgressCallback ) { + m_logger.Activate(); + int libTableHash = symTable()->GetModifyHash(); if( aForce || m_syncHash != libTableHash ) @@ -61,7 +62,7 @@ void LIB_MANAGER::Sync( bool aForce, bool LIB_MANAGER::HasModifications() const { - for( auto lib : m_libs ) + for( const auto& lib : m_libs ) { if( lib.second.IsModified() ) return true; @@ -75,8 +76,8 @@ int LIB_MANAGER::GetHash() const { int hash = symTable()->GetModifyHash(); - for( const auto& libBuf : m_libs ) - hash += libBuf.second.GetHash(); + for( const auto& lib : m_libs ) + hash += lib.second.GetHash(); return hash; } @@ -296,33 +297,6 @@ bool LIB_MANAGER::IsLibraryReadOnly( const wxString& aLibrary ) const } -wxArrayString LIB_MANAGER::GetAliasNames( const wxString& aLibrary ) const -{ - wxArrayString names; - wxCHECK( LibraryExists( aLibrary ), names ); - - auto it = m_libs.find( aLibrary ); - - if( it == m_libs.end() ) - { - try - { - symTable()->EnumerateSymbolLib( aLibrary, names ); - } - catch( const IO_ERROR& e ) - { - wxLogMessage( _( "Cannot enumerate library \"%s\" (%s)" ), aLibrary, e.What() ); - } - } - else - { - names = it->second.GetAliasNames(); - } - - return names; -} - - std::list LIB_MANAGER::GetAliases( const wxString& aLibrary ) const { std::list ret; @@ -348,7 +322,7 @@ std::list LIB_MANAGER::GetAliases( const wxString& aLibrary ) const } catch( const IO_ERROR& e ) { - wxLogMessage( _( "Cannot load aliases from library \"%s\" (%s)" ), aLibrary, e.What() ); + wxLogWarning( e.Problem() ); } std::copy( aliases.begin(), aliases.end(), std::back_inserter( ret ) ); @@ -637,26 +611,6 @@ wxString LIB_MANAGER::GetUniqueLibraryName() const } -wxString LIB_MANAGER::GetUniqueComponentName( const wxString& aLibrary ) const -{ - wxString name = "New_Component"; - - if( !PartExists( name, aLibrary ) ) - return name; - - name += "_"; - - for( unsigned int i = 0; i < std::numeric_limits::max(); ++i ) - { - if( !PartExists( name + wxString::Format( "%u", i ), aLibrary ) ) - return name + wxString::Format( "%u", i ); - } - - wxFAIL; - return wxEmptyString; -} - - wxString LIB_MANAGER::getLibraryName( const wxString& aFilePath ) { wxFileName fn( aFilePath ); diff --git a/eeschema/libedit/lib_manager.h b/eeschema/libedit/lib_manager.h index 009093a6d3..40ea82fbf7 100644 --- a/eeschema/libedit/lib_manager.h +++ b/eeschema/libedit/lib_manager.h @@ -44,6 +44,33 @@ class LIB_EDIT_FRAME; class SYMBOL_LIB_TABLE; class SYMBOL_LIB_TABLE_ROW; + +class LIB_LOGGER : public wxLogGui +{ +public: + void Activate() + { + m_previousLogger = wxLog::GetActiveTarget(); + wxLog::SetActiveTarget( this ); + } + + void Flush() override + { + if( m_bHasMessages ) + { + wxLogMessage( _( "Not all libraries could be loaded. Use the Manage Symbol Libraries dialog \n" + "to adjust paths and add or remove libraries." ) ); + + wxLogGui::Flush(); + wxLog::SetActiveTarget( m_previousLogger ); + } + } + +private: + wxLog* m_previousLogger; +}; + + /** * Class to handle modifications to the symbol libraries. */ @@ -81,11 +108,6 @@ public: */ SYMBOL_LIB_TABLE_ROW* GetLibrary( const wxString& aLibrary ) const; - /** - * Returns a set containing all part names for a specific library. - */ - wxArrayString GetAliasNames( const wxString& aLibrary ) const; - std::list GetAliases( const wxString& aLibrary ) const; /** @@ -233,12 +255,6 @@ public: */ wxString GetUniqueLibraryName() const; - /** - * Returns a component name that is not stored in a library. - * Used for generating names for new components. - */ - wxString GetUniqueComponentName( const wxString& aLibrary ) const; - /** * Returns the adapter object that provides the stored data. */ @@ -449,14 +465,11 @@ private: ///> The library buffers std::map m_libs; - ///> Symbol Lib Table hash value returned during the last synchronization - int m_syncHash; + LIB_LOGGER m_logger; + int m_syncHash; // Symbol Lib Table hash value from the last synchronization - ///> Currently modified part - wxString m_currentLib; - - ///> Currently modified library - wxString m_currentPart; + wxString m_currentLib; // Currently modified part + wxString m_currentPart; // Currently modified library SYMBOL_TREE_SYNCHRONIZING_ADAPTER::PTR m_adapter; SYMBOL_TREE_SYNCHRONIZING_ADAPTER* getAdapter() diff --git a/eeschema/sch_eagle_plugin.h b/eeschema/sch_eagle_plugin.h index 9923217ce1..a7eeba616f 100644 --- a/eeschema/sch_eagle_plugin.h +++ b/eeschema/sch_eagle_plugin.h @@ -103,9 +103,6 @@ public: //void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway, // const PROPERTIES* aProperties = NULL ) override; - //size_t GetSymbolLibCount( const wxString& aLibraryPath, - // const PROPERTIES* aProperties = NULL ) override; - //void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath, // const PROPERTIES* aProperties = NULL ) override; diff --git a/eeschema/sch_io_mgr.h b/eeschema/sch_io_mgr.h index e23d0c52ad..47a667c2d0 100644 --- a/eeschema/sch_io_mgr.h +++ b/eeschema/sch_io_mgr.h @@ -271,9 +271,6 @@ public: virtual void Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway, const PROPERTIES* aProperties = NULL ); - virtual size_t GetSymbolLibCount( const wxString& aLibraryPath, - const PROPERTIES* aProperties = NULL ); - /** * Populate a list of #LIB_PART alias names contained within the library \a aLibraryPath. * diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index c92fd3f8c8..76fe320420 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -2444,14 +2444,8 @@ void SCH_LEGACY_PLUGIN_CACHE::Load() { if( !m_libFileName.FileExists() ) { - wxString msg = wxString::Format( _( "Library file \"%s\" not found.\n\n" - "Use the Manage Symbol Libraries dialog to fix the " - "path (or remove the library)." ), - m_libFileName.GetFullPath() ); - KIDIALOG dlg( Pgm().App().GetTopWindow(), msg, KIDIALOG::KD_ERROR ); - dlg.DoNotShowCheckbox( __FILE__, __LINE__ ); - dlg.ShowModal(); - return; + THROW_IO_ERROR( wxString::Format( _( "Library file \"%s\" not found." ), + m_libFileName.GetFullPath() ) ); } wxCHECK_RET( m_libFileName.IsAbsolute(), @@ -4247,19 +4241,6 @@ int SCH_LEGACY_PLUGIN::GetModifyHash() const } -size_t SCH_LEGACY_PLUGIN::GetSymbolLibCount( const wxString& aLibraryPath, - const PROPERTIES* aProperties ) -{ - LOCALE_IO toggle; - - m_props = aProperties; - - cacheLib( aLibraryPath ); - - return m_cache->m_aliases.size(); -} - - void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath, const PROPERTIES* aProperties ) diff --git a/eeschema/sch_legacy_plugin.h b/eeschema/sch_legacy_plugin.h index 3636610bc6..4035a6f430 100644 --- a/eeschema/sch_legacy_plugin.h +++ b/eeschema/sch_legacy_plugin.h @@ -111,8 +111,6 @@ public: void Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter ); - size_t GetSymbolLibCount( const wxString& aLibraryPath, - const PROPERTIES* aProperties = nullptr ) override; void EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath, const PROPERTIES* aProperties = nullptr ) override; diff --git a/eeschema/sch_plugin.cpp b/eeschema/sch_plugin.cpp index f69d4d9c02..4e1b4c562f 100644 --- a/eeschema/sch_plugin.cpp +++ b/eeschema/sch_plugin.cpp @@ -63,15 +63,6 @@ void SCH_PLUGIN::Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* } -size_t SCH_PLUGIN::GetSymbolLibCount( 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__ ); - return 0; -} - - void SCH_PLUGIN::EnumerateSymbolLib( wxArrayString& aAliasNameList, const wxString& aLibraryPath, const PROPERTIES* aProperties ) diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index cb94e0b947..e87fb17d6f 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -261,15 +261,6 @@ int SYMBOL_LIB_TABLE::GetModifyHash() } -size_t SYMBOL_LIB_TABLE::GetSymbolCount( const wxString& aNickname ) -{ - SYMBOL_LIB_TABLE_ROW* row = dynamic_cast< SYMBOL_LIB_TABLE_ROW* >( findRow( aNickname ) ); - wxCHECK( row && row->plugin, 0 ); - - return row->plugin->GetSymbolLibCount( row->GetFullURI( true ) ); -} - - void SYMBOL_LIB_TABLE::EnumerateSymbolLib( const wxString& aNickname, wxArrayString& aAliasNames, bool aPowerSymbolsOnly ) { diff --git a/eeschema/symbol_lib_table.h b/eeschema/symbol_lib_table.h index 7dcc812883..b883ed831f 100644 --- a/eeschema/symbol_lib_table.h +++ b/eeschema/symbol_lib_table.h @@ -145,11 +145,6 @@ public: //-------------------------------- - /** - * Return the number of symbols in the symbol library mapped to \a aNickname - */ - size_t GetSymbolCount( const wxString& aNickname ); - /** * Return a list of symbol alias names contained within the library given by @a aNickname. *