From 0dca0e752b9a80bccf333eaf6e9a9df39cec4b07 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Thu, 25 Feb 2021 12:13:42 -0800 Subject: [PATCH] Reduce the number of built-up calls to DisplayFootprint When updating the libtree, we modify the tree multiple times to avoid crashes on Linux. These generated events that buffered while the widget was frozen and resulted in redrawing the same footprint 4-10x. This reduces the buffering by discarding events that are generated during the freeze and only redrawing when there is a new footprint to draw --- common/widgets/footprint_preview_widget.cpp | 9 ++++++++- common/widgets/lib_tree.cpp | 12 ++++++++---- include/widgets/footprint_preview_widget.h | 3 ++- include/widgets/lib_tree.h | 2 ++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/common/widgets/footprint_preview_widget.cpp b/common/widgets/footprint_preview_widget.cpp index 764348fdaa..d531a535e6 100644 --- a/common/widgets/footprint_preview_widget.cpp +++ b/common/widgets/footprint_preview_widget.cpp @@ -19,6 +19,7 @@ */ #include +#include #include #include #include @@ -87,15 +88,21 @@ void FOOTPRINT_PREVIEW_WIDGET::ClearStatus() void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint( const LIB_ID& aFPID ) { - if( !m_prev_panel ) + if( !m_prev_panel || m_libid == aFPID ) return; wxBusyCursor busy; if( m_prev_panel->DisplayFootprint( aFPID ) ) + { ClearStatus(); + m_libid = aFPID; + } else + { SetStatusText( _( "Footprint not found." ) ); + m_libid.clear(); + } } diff --git a/common/widgets/lib_tree.cpp b/common/widgets/lib_tree.cpp index 8e8f3ddc4c..e0184f1a5b 100644 --- a/common/widgets/lib_tree.cpp +++ b/common/widgets/lib_tree.cpp @@ -117,9 +117,12 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, LIB_TABLE* aLibTable, // Force an update of the adapter with the empty text to ensure preselect is done Regenerate( false ); } - - // There may be a part preselected in the model. Make sure it is displayed. - postPreselectEvent(); + else + { + // There may be a part preselected in the model. Make sure it is displayed. + // Regenerate does this in the other branch + postPreselectEvent(); + } Layout(); sizer->Fit( this ); @@ -374,7 +377,8 @@ void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke ) void LIB_TREE::onTreeSelect( wxDataViewEvent& aEvent ) { - postPreselectEvent(); + if( !m_tree_ctrl->IsFrozen() ) + postPreselectEvent(); } diff --git a/include/widgets/footprint_preview_widget.h b/include/widgets/footprint_preview_widget.h index c9f262500a..5990a7130f 100644 --- a/include/widgets/footprint_preview_widget.h +++ b/include/widgets/footprint_preview_widget.h @@ -24,12 +24,12 @@ #include #include #include +#include #include class FOOTPRINT_LOAD_EVENT; class FOOTPRINT_PREVIEW_PANEL_BASE; -class LIB_ID; class KIWAY; class wxStaticText; class wxSizer; @@ -77,6 +77,7 @@ private: wxPanel* m_statusPanel; wxSizer* m_statusSizer; wxSizer* m_outerSizer; + LIB_ID m_libid; }; diff --git a/include/widgets/lib_tree.h b/include/widgets/lib_tree.h index 814c916224..81b9401ffd 100644 --- a/include/widgets/lib_tree.h +++ b/include/widgets/lib_tree.h @@ -174,6 +174,8 @@ protected: wxTextCtrl* m_query_ctrl; wxDataViewCtrl* m_tree_ctrl; wxHtmlWindow* m_details_ctrl; + + LIB_ID m_last_libid; }; ///< Custom event sent when a new component is preselected