diff --git a/common/widgets/footprint_select_widget.cpp b/common/widgets/footprint_select_widget.cpp index 129f0540d0..fe844cf6bd 100644 --- a/common/widgets/footprint_select_widget.cpp +++ b/common/widgets/footprint_select_widget.cpp @@ -101,15 +101,17 @@ void FOOTPRINT_SELECT_WIDGET::Load( KIWAY& aKiway, PROJECT& aProject ) try { auto fp_lib_table = aProject.PcbFootprintLibs( aKiway ); + m_fp_list = FOOTPRINT_LIST::GetInstance( aKiway ); - if( m_fp_loader.GetProgress() == 0 || !m_fp_loader.IsSameTable( fp_lib_table ) ) + if( m_fp_list->RequiresLoading( fp_lib_table ) ) { - m_fp_list = FOOTPRINT_LIST::GetInstance( aKiway ); m_fp_loader.SetList( &*m_fp_list ); m_fp_loader.Start( fp_lib_table ); - } - m_progress_timer->Start( 200 ); + m_progress_timer->Start( 200 ); + } + else + FootprintsLoaded(); } catch( ... ) { @@ -128,18 +130,27 @@ void FOOTPRINT_SELECT_WIDGET::OnProgressTimer( wxTimerEvent& aEvent ) wxBusyCursor busy; m_fp_loader.Join(); - m_fp_filter.SetList( *m_fp_list ); m_progress_timer->Stop(); - m_book->SetSelection( PAGE_SELECT ); - m_finished_loading = true; - - if( m_update ) - UpdateList(); + FootprintsLoaded(); } } +void FOOTPRINT_SELECT_WIDGET::FootprintsLoaded() +{ + m_progress_ctrl->SetValue( 100 ); + + m_fp_filter.SetList( *m_fp_list ); + + m_book->SetSelection( PAGE_SELECT ); + m_finished_loading = true; + + if( m_update ) + UpdateList(); +} + + void FOOTPRINT_SELECT_WIDGET::OnComboBox( wxCommandEvent& aEvent ) { wxCommandEvent evt( EVT_FOOTPRINT_SELECTED ); diff --git a/include/footprint_info.h b/include/footprint_info.h index cf63ec6e65..f45b19aae3 100644 --- a/include/footprint_info.h +++ b/include/footprint_info.h @@ -242,6 +242,15 @@ public: return error; } + /** + * Indicates whether or not the table requires loading for the given \a aNickname. + */ + virtual bool RequiresLoading( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr ) + { + return true; // Implementations which support caching should implement this. + } + + /** * Read all the footprints provided by the combination of aTable and aNickname. * diff --git a/include/widgets/footprint_select_widget.h b/include/widgets/footprint_select_widget.h index f973a08e53..2d55a9f950 100644 --- a/include/widgets/footprint_select_widget.h +++ b/include/widgets/footprint_select_widget.h @@ -149,6 +149,7 @@ private: FOOTPRINT_FILTER m_fp_filter; bool m_zero_filter; + void FootprintsLoaded(); void OnProgressTimer( wxTimerEvent& aEvent ); void OnComboBox( wxCommandEvent& aEvent ); void OnComboInteractive( wxCommandEvent& aEvent ); diff --git a/pcbnew/footprint_info_impl.cpp b/pcbnew/footprint_info_impl.cpp index d67bc1779f..aa49e4e4a4 100644 --- a/pcbnew/footprint_info_impl.cpp +++ b/pcbnew/footprint_info_impl.cpp @@ -115,6 +115,12 @@ void FOOTPRINT_LIST_IMPL::loader_job() } +bool FOOTPRINT_LIST_IMPL::RequiresLoading( FP_LIB_TABLE* aTable, const wxString* aNickname ) +{ + return m_list_timestamp != aTable->GenerateTimestamp( aNickname ); +} + + bool FOOTPRINT_LIST_IMPL::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname, WX_PROGRESS_REPORTER* aProgressReporter ) { @@ -166,7 +172,6 @@ bool FOOTPRINT_LIST_IMPL::ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxStri ( _( "Loading incomplete; cancelled by user." ), nullptr, nullptr, 0 ) ); } - m_list_timestamp = aTable->GenerateTimestamp( aNickname );; m_progress_reporter = nullptr; return m_errors.empty(); @@ -178,6 +183,7 @@ void FOOTPRINT_LIST_IMPL::StartWorkers( FP_LIB_TABLE* aTable, wxString const* aN { m_loader = aLoader; m_lib_table = aTable; + m_library = aNickname; // Clear data before reading files m_count_finished.store( 0 ); @@ -292,6 +298,11 @@ bool FOOTPRINT_LIST_IMPL::JoinWorkers() []( std::unique_ptr const& lhs, std::unique_ptr const& rhs ) -> bool { return *lhs < *rhs; } ); + if( m_cancelled ) + m_list_timestamp = 0; // God knows what we got before we were cancelled + else + m_list_timestamp = m_lib_table->GenerateTimestamp( m_library );; + return m_errors.empty(); } diff --git a/pcbnew/footprint_info_impl.h b/pcbnew/footprint_info_impl.h index 6865848ea6..c08a41bee9 100644 --- a/pcbnew/footprint_info_impl.h +++ b/pcbnew/footprint_info_impl.h @@ -58,6 +58,7 @@ protected: class FOOTPRINT_LIST_IMPL : public FOOTPRINT_LIST { FOOTPRINT_ASYNC_LOADER* m_loader; + const wxString* m_library; std::vector m_threads; SYNC_QUEUE m_queue_in; SYNC_QUEUE m_queue_out; @@ -89,8 +90,10 @@ public: FOOTPRINT_LIST_IMPL(); virtual ~FOOTPRINT_LIST_IMPL(); - virtual bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr, - WX_PROGRESS_REPORTER* aProgressReporter = nullptr ) override; + bool RequiresLoading( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr ) override; + + bool ReadFootprintFiles( FP_LIB_TABLE* aTable, const wxString* aNickname = nullptr, + WX_PROGRESS_REPORTER* aProgressReporter = nullptr ) override; }; extern FOOTPRINT_LIST_IMPL GFootprintList; // KIFACE scope.