From c15a9e60d4cfc59126d756364be888cbf7f29e53 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 25 Feb 2021 15:42:12 -0800 Subject: [PATCH] Used cached footprints without check in preview Between the time the user loads the footprint preview in cvpcb or Add Footprint in pcbnew, we don't need to verify cache integrity to display the footprint. We use the cache copy when displaying until we close the selection window and re-open. This limits our need to iterate over the full directory on every footprint display. Alternate solutions for v7 should include looking into libfswatch for change detection --- cvpcb/display_footprints_frame.cpp | 5 ++++- pcbnew/footprint_preview_panel.cpp | 7 ++++++- pcbnew/generate_footprint_info.cpp | 7 ++++--- pcbnew/plugins/kicad/kicad_plugin.cpp | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 08a526c5f4..8d2ce8033c 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -405,7 +405,10 @@ FOOTPRINT* DISPLAY_FOOTPRINTS_FRAME::GetFootprint( const wxString& aFootprintNam try { - footprint = fpTable->FootprintLoad( libNickname, fpName ); + const FOOTPRINT* fp = fpTable->GetEnumeratedFootprint( libNickname, fpName ); + + if( fp ) + footprint = static_cast( fp->Duplicate() ); } catch( const IO_ERROR& ioe ) { diff --git a/pcbnew/footprint_preview_panel.cpp b/pcbnew/footprint_preview_panel.cpp index fe50e4d888..d85654444f 100644 --- a/pcbnew/footprint_preview_panel.cpp +++ b/pcbnew/footprint_preview_panel.cpp @@ -138,7 +138,12 @@ bool FOOTPRINT_PREVIEW_PANEL::DisplayFootprint( const LIB_ID& aFPID ) try { - m_currentFootprint.reset( fptbl->FootprintLoadWithOptionalNickname( aFPID ) ); + const FOOTPRINT* fp = fptbl->GetEnumeratedFootprint( aFPID.GetLibNickname(), aFPID.GetLibItemName() ); + + if( fp ) + m_currentFootprint.reset( static_cast( fp->Duplicate() ) ); + else + m_currentFootprint.reset(); } catch( ... ) { diff --git a/pcbnew/generate_footprint_info.cpp b/pcbnew/generate_footprint_info.cpp index 24ec9e135c..91fbab6800 100644 --- a/pcbnew/generate_footprint_info.cpp +++ b/pcbnew/generate_footprint_info.cpp @@ -49,7 +49,8 @@ class FOOTPRINT_INFO_GENERATOR wxString m_html; FP_LIB_TABLE* m_fp_lib_table; LIB_ID const m_lib_id; - FOOTPRINT* m_footprint; + + const FOOTPRINT* m_footprint; public: FOOTPRINT_INFO_GENERATOR( FP_LIB_TABLE* aFpLibTable, LIB_ID const& aLibId ) @@ -71,8 +72,8 @@ public: try { - m_footprint = m_fp_lib_table->FootprintLoad( m_lib_id.GetLibNickname(), - m_lib_id.GetLibItemName() ); + m_footprint = m_fp_lib_table->GetEnumeratedFootprint( m_lib_id.GetLibNickname(), + m_lib_id.GetLibItemName() ); } catch( const IO_ERROR& ioe ) { diff --git a/pcbnew/plugins/kicad/kicad_plugin.cpp b/pcbnew/plugins/kicad/kicad_plugin.cpp index c3fa91f0b7..b3906ff578 100644 --- a/pcbnew/plugins/kicad/kicad_plugin.cpp +++ b/pcbnew/plugins/kicad/kicad_plugin.cpp @@ -2284,7 +2284,7 @@ FOOTPRINT* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& if( footprint ) { - FOOTPRINT* copy = (FOOTPRINT*) footprint->Duplicate(); + FOOTPRINT* copy = static_cast( footprint->Duplicate() ); copy->SetParent( nullptr ); return copy; }