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
This commit is contained in:
Seth Hillbrand 2021-02-25 12:13:42 -08:00
parent ac8fa140b7
commit 0dca0e752b
4 changed files with 20 additions and 6 deletions

View File

@ -19,6 +19,7 @@
*/ */
#include <widgets/footprint_preview_widget.h> #include <widgets/footprint_preview_widget.h>
#include <lib_id.h>
#include <wx/stattext.h> #include <wx/stattext.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <kiway.h> #include <kiway.h>
@ -87,15 +88,21 @@ void FOOTPRINT_PREVIEW_WIDGET::ClearStatus()
void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint( const LIB_ID& aFPID ) void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint( const LIB_ID& aFPID )
{ {
if( !m_prev_panel ) if( !m_prev_panel || m_libid == aFPID )
return; return;
wxBusyCursor busy; wxBusyCursor busy;
if( m_prev_panel->DisplayFootprint( aFPID ) ) if( m_prev_panel->DisplayFootprint( aFPID ) )
{
ClearStatus(); ClearStatus();
m_libid = aFPID;
}
else else
{
SetStatusText( _( "Footprint not found." ) ); SetStatusText( _( "Footprint not found." ) );
m_libid.clear();
}
} }

View File

@ -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 // Force an update of the adapter with the empty text to ensure preselect is done
Regenerate( false ); Regenerate( false );
} }
else
// There may be a part preselected in the model. Make sure it is displayed. {
postPreselectEvent(); // There may be a part preselected in the model. Make sure it is displayed.
// Regenerate does this in the other branch
postPreselectEvent();
}
Layout(); Layout();
sizer->Fit( this ); sizer->Fit( this );
@ -374,7 +377,8 @@ void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
void LIB_TREE::onTreeSelect( wxDataViewEvent& aEvent ) void LIB_TREE::onTreeSelect( wxDataViewEvent& aEvent )
{ {
postPreselectEvent(); if( !m_tree_ctrl->IsFrozen() )
postPreselectEvent();
} }

View File

@ -24,12 +24,12 @@
#include <wx/panel.h> #include <wx/panel.h>
#include <functional> #include <functional>
#include <import_export.h> #include <import_export.h>
#include <lib_id.h>
#include <gal/color4d.h> #include <gal/color4d.h>
class FOOTPRINT_LOAD_EVENT; class FOOTPRINT_LOAD_EVENT;
class FOOTPRINT_PREVIEW_PANEL_BASE; class FOOTPRINT_PREVIEW_PANEL_BASE;
class LIB_ID;
class KIWAY; class KIWAY;
class wxStaticText; class wxStaticText;
class wxSizer; class wxSizer;
@ -77,6 +77,7 @@ private:
wxPanel* m_statusPanel; wxPanel* m_statusPanel;
wxSizer* m_statusSizer; wxSizer* m_statusSizer;
wxSizer* m_outerSizer; wxSizer* m_outerSizer;
LIB_ID m_libid;
}; };

View File

@ -174,6 +174,8 @@ protected:
wxTextCtrl* m_query_ctrl; wxTextCtrl* m_query_ctrl;
wxDataViewCtrl* m_tree_ctrl; wxDataViewCtrl* m_tree_ctrl;
wxHtmlWindow* m_details_ctrl; wxHtmlWindow* m_details_ctrl;
LIB_ID m_last_libid;
}; };
///< Custom event sent when a new component is preselected ///< Custom event sent when a new component is preselected