From 2cbd7b5043b8a837c88af36c3492b3beed0595d1 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 14 Mar 2021 11:29:24 -0400 Subject: [PATCH] Reduce scope of some view repaints to improve performance --- include/pcb_base_frame.h | 8 +++++++- pcbnew/dialogs/panel_display_options.cpp | 16 +++++++++++++++- pcbnew/dialogs/panel_edit_options.cpp | 10 ++++++++-- pcbnew/pcb_base_frame.cpp | 7 ++++--- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 439be8a5df..5cecbc925c 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -175,7 +175,13 @@ public: * (for instance solid or sketch mode). */ const PCB_DISPLAY_OPTIONS& GetDisplayOptions() const { return m_displayOptions; } - void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions ); + + /** + * Updates the current display options from the given options struct + * @param aOptions is the options struct to apply + * @param aRefresh will refresh the view after updating + */ + void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aRefresh = true ); const ZONE_SETTINGS& GetZoneSettings() const; void SetZoneSettings( const ZONE_SETTINGS& aSettings ); diff --git a/pcbnew/dialogs/panel_display_options.cpp b/pcbnew/dialogs/panel_display_options.cpp index 37b6718772..6765e0d95b 100644 --- a/pcbnew/dialogs/panel_display_options.cpp +++ b/pcbnew/dialogs/panel_display_options.cpp @@ -117,9 +117,23 @@ bool PANEL_DISPLAY_OPTIONS::TransferDataFromWindow() crossProbing.center_on_items = m_checkCrossProbeCenter->GetValue(); crossProbing.zoom_to_fit = m_checkCrossProbeZoom->GetValue(); crossProbing.auto_highlight = m_checkCrossProbeAutoHighlight->GetValue(); + + // Mark items with clearance display for repaint + view->UpdateAllItemsConditionally( KIGFX::REPAINT, + []( KIGFX::VIEW_ITEM* aItem ) -> bool + { + if( EDA_ITEM* item = dynamic_cast( aItem ) ) + { + return( item->Type() == PCB_TRACE_T || + item->Type() == PCB_ARC_T || + item->Type() == PCB_VIA_T || + item->Type() == PCB_PAD_T ); + } + + return false; + } ); } - view->RecacheAllItems(); view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); return true; diff --git a/pcbnew/dialogs/panel_edit_options.cpp b/pcbnew/dialogs/panel_edit_options.cpp index 5949e53881..80f4b30615 100644 --- a/pcbnew/dialogs/panel_edit_options.cpp +++ b/pcbnew/dialogs/panel_edit_options.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -140,9 +141,14 @@ bool PANEL_EDIT_OPTIONS::TransferDataFromWindow() KIGFX::PCB_PAINTER* painter = static_cast( view->GetPainter() ); KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings(); - m_frame->SetDisplayOptions( displ_opts ); + m_frame->SetDisplayOptions( displ_opts, false ); settings->LoadDisplayOptions( displ_opts, m_frame->ShowPageLimits() ); - view->RecacheAllItems(); + + view->UpdateAllItemsConditionally( KIGFX::REPAINT, + []( KIGFX::VIEW_ITEM* aItem ) -> bool + { + return dynamic_cast( aItem ); + } ); view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); m_frame->GetCanvas()->Refresh(); diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 63a1f9cd74..355bee3d5d 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -674,7 +674,7 @@ void PCB_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars EDA_DRAW_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged ); GetCanvas()->GetView()->GetPainter()->GetSettings()->LoadColors( GetColorSettings() ); - GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); + GetCanvas()->GetView()->UpdateAllItems( KIGFX::COLOR ); RecreateToolbars(); @@ -732,7 +732,7 @@ void PCB_BASE_FRAME::ActivateGalCanvas() } -void PCB_BASE_FRAME::SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions ) +void PCB_BASE_FRAME::SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aRefresh ) { bool hcChanged = m_displayOptions.m_ContrastModeDisplay != aOptions.m_ContrastModeDisplay; m_displayOptions = aOptions; @@ -760,5 +760,6 @@ void PCB_BASE_FRAME::SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions ) } ); } - canvas->Refresh(); + if( aRefresh ) + canvas->Refresh(); }