From 8b0041bf9a7defe9442ad69659e8e8a1206dc761 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 22 Nov 2017 12:06:17 +0100 Subject: [PATCH] Library Editor: progress dialog when loading libraries --- eeschema/cmp_tree_model_adapter_base.h | 8 ++++++++ eeschema/lib_manager.cpp | 4 ++-- eeschema/lib_manager.h | 3 ++- eeschema/lib_manager_adapter.cpp | 22 ++++++++++++++++++++-- eeschema/lib_manager_adapter.h | 5 ++++- eeschema/libeditframe.cpp | 16 +++++++++++++++- eeschema/libeditframe.h | 5 +++++ eeschema/widgets/cmp_tree_pane.cpp | 2 +- eeschema/widgets/cmp_tree_pane.h | 1 - 9 files changed, 57 insertions(+), 9 deletions(-) diff --git a/eeschema/cmp_tree_model_adapter_base.h b/eeschema/cmp_tree_model_adapter_base.h index 66d2b9285f..d7e6c04f9b 100644 --- a/eeschema/cmp_tree_model_adapter_base.h +++ b/eeschema/cmp_tree_model_adapter_base.h @@ -233,6 +233,14 @@ public: */ int GetComponentsCount() const; + /** + * Return the number of libraries loaded in the tree. + */ + virtual int GetLibrariesCount() const + { + return m_tree.Children.size(); + } + /** * Returns tree item corresponding to part. * diff --git a/eeschema/lib_manager.cpp b/eeschema/lib_manager.cpp index 072e71f248..2ce013ba4c 100644 --- a/eeschema/lib_manager.cpp +++ b/eeschema/lib_manager.cpp @@ -42,13 +42,13 @@ LIB_MANAGER::LIB_MANAGER( LIB_EDIT_FRAME& aFrame ) } -void LIB_MANAGER::Sync( bool aForce ) +void LIB_MANAGER::Sync( bool aForce, std::function aProgressCallback ) { int libTableHash = m_symbolTable->GetModifyHash(); if( aForce || m_syncHash != libTableHash ) { - getAdapter()->Sync( aForce ); + getAdapter()->Sync( aForce, aProgressCallback ); m_syncHash = libTableHash; } } diff --git a/eeschema/lib_manager.h b/eeschema/lib_manager.h index 2b82eda263..ea609fa111 100644 --- a/eeschema/lib_manager.h +++ b/eeschema/lib_manager.h @@ -53,7 +53,8 @@ public: /** * Updates the LIB_MANAGER data to synchronize with Symbol Library Table. */ - void Sync( bool aForce = false ); + void Sync( bool aForce = false, std::function aProgressCallback + = [](int, int, const wxString&){} ); int GetHash() const; diff --git a/eeschema/lib_manager_adapter.cpp b/eeschema/lib_manager_adapter.cpp index 7dca13b50a..304e3e80e4 100644 --- a/eeschema/lib_manager_adapter.cpp +++ b/eeschema/lib_manager_adapter.cpp @@ -80,20 +80,21 @@ bool LIB_MANAGER_ADAPTER::IsContainer( const wxDataViewItem& aItem ) const } -void LIB_MANAGER_ADAPTER::Sync( bool aForce ) +void LIB_MANAGER_ADAPTER::Sync( bool aForce, std::function aProgressCallback ) { - wxBusyCursor cursor; int libMgrHash = m_libMgr->GetHash(); if( !aForce && m_lastSyncHash == libMgrHash ) return; m_lastSyncHash = libMgrHash; + int i = 0, max = GetLibrariesCount(); // Process already stored libraries for( auto it = m_tree.Children.begin(); it != m_tree.Children.end(); /* iteration inside */ ) { const wxString& name = it->get()->Name; + aProgressCallback( i++, max, name ); if( !m_libMgr->LibraryExists( name ) ) { @@ -112,13 +113,30 @@ void LIB_MANAGER_ADAPTER::Sync( bool aForce ) for( const auto& libName : m_libMgr->GetLibraryNames() ) { if( m_libHashes.count( libName ) == 0 ) + { + aProgressCallback( i++, max, libName ); AddLibrary( libName ); + } } finishUpdate(); } +int LIB_MANAGER_ADAPTER::GetLibrariesCount() const +{ + int count = CMP_TREE_MODEL_ADAPTER_BASE::GetLibrariesCount(); + + for( const auto& libName : m_libMgr->GetLibraryNames() ) + { + if( m_libHashes.count( libName ) == 0 ) + ++count; + } + + return count; +} + + void LIB_MANAGER_ADAPTER::updateLibrary( CMP_TREE_NODE_LIB& aLibNode ) { if( m_libHashes.count( aLibNode.Name ) == 0 ) diff --git a/eeschema/lib_manager_adapter.h b/eeschema/lib_manager_adapter.h index 1485773f26..c64cd5035e 100644 --- a/eeschema/lib_manager_adapter.h +++ b/eeschema/lib_manager_adapter.h @@ -45,7 +45,10 @@ public: void UpdateLibrary( const wxString& aLibraryName ); - void Sync( bool aForce = false ); + void Sync( bool aForce = false, std::function aProgressCallback + = [](int, int, const wxString&){} ); + + int GetLibrariesCount() const override; protected: void updateLibrary( CMP_TREE_NODE_LIB& aLibNode ); diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index 93a927c464..7eed1c41f7 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -61,6 +61,7 @@ #include #include +#include wxString LIB_EDIT_FRAME:: m_aliasName; @@ -483,7 +484,7 @@ void LIB_EDIT_FRAME::OnToggleSearchTree( wxCommandEvent& event ) void LIB_EDIT_FRAME::OnEditSymbolLibTable( wxCommandEvent& aEvent ) { SCH_BASE_FRAME::OnEditSymbolLibTable( aEvent ); - m_libMgr->Sync( true ); + SyncLibraries(); m_treePane->Refresh(); } @@ -1613,6 +1614,19 @@ SYMBOL_LIB_TABLE* LIB_EDIT_FRAME::SelectSymLibTable() } +void LIB_EDIT_FRAME::SyncLibraries() +{ + wxBusyCursor cursor; + + wxProgressDialog progressDlg( _( "Loading symbol libraries" ), + wxEmptyString, m_libMgr->GetAdapter()->GetLibrariesCount(), this ); + + m_libMgr->Sync( true, [&]( int progress, int max, const wxString& libName ) { + progressDlg.Update( progress, wxString::Format( _( "Loading library '%s'" ), libName ) ); + } ); +} + + bool LIB_EDIT_FRAME::backupFile( const wxFileName& aOriginalFile, const wxString& aBackupExt ) { if( aOriginalFile.FileExists() ) diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index 07ff983b26..972bb870eb 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -692,6 +692,11 @@ public: */ SYMBOL_LIB_TABLE* SelectSymLibTable(); + /** + * Synchronize the library manager and the symbol library table. Displays a progress dialog. + */ + void SyncLibraries(); + private: ///> Helper screen used when no part is loaded SCH_SCREEN* m_dummyScreen; diff --git a/eeschema/widgets/cmp_tree_pane.cpp b/eeschema/widgets/cmp_tree_pane.cpp index c1b229b105..0147fb5930 100644 --- a/eeschema/widgets/cmp_tree_pane.cpp +++ b/eeschema/widgets/cmp_tree_pane.cpp @@ -38,7 +38,7 @@ CMP_TREE_PANE::CMP_TREE_PANE( LIB_EDIT_FRAME* aParent, LIB_MANAGER* aLibMgr ) // Create widgets wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL ); - m_libMgr->Sync(); + m_libEditFrame->SyncLibraries(); m_tree = new COMPONENT_TREE( this, &SYMBOL_LIB_TABLE::GetGlobalLibTable(), m_libMgr->GetAdapter(), COMPONENT_TREE::SEARCH ); diff --git a/eeschema/widgets/cmp_tree_pane.h b/eeschema/widgets/cmp_tree_pane.h index da76d88173..8800e8a681 100644 --- a/eeschema/widgets/cmp_tree_pane.h +++ b/eeschema/widgets/cmp_tree_pane.h @@ -46,7 +46,6 @@ public: } protected: - void onSymLibTableSelected( wxCommandEvent& aEvent ); void onComponentSelected( wxCommandEvent& aEvent ); LIB_EDIT_FRAME* m_libEditFrame;