kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #34325
[PATCH] Fix regression in GerbView display settings; some optimization too
The attached fixes a regression where the view would not be updated
immediately when changing some GerbView display settings. It also
introduces a new method to VIEW that allows quick updating of a subset of
flags on all items, which speeds up toggling of transparency and
high-contrast mode in GerbView.
-Jon
From 47b143f347d55c7608afd8aba087ed324cfb74da Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Sun, 25 Feb 2018 12:38:35 -0500
Subject: [PATCH] Fix regression in GerbView display settings; some
optimization too
---
common/view/view.cpp | 14 ++++++++++++++
gerbview/events_called_functions.cpp | 30 ++++++++++++++++++++----------
gerbview/gerbview_painter.cpp | 9 ++++-----
include/view/view.h | 6 ++++++
4 files changed, 44 insertions(+), 15 deletions(-)
diff --git a/common/view/view.cpp b/common/view/view.cpp
index 673a3ab21..b2d5a87e1 100644
--- a/common/view/view.cpp
+++ b/common/view/view.cpp
@@ -1288,6 +1288,20 @@ void VIEW::UpdateItems()
}
+void VIEW::UpdateAllItems( int aUpdateFlags )
+{
+ for( VIEW_ITEM* item : m_allItems )
+ {
+ auto viewData = item->viewPrivData();
+
+ if( !viewData )
+ continue;
+
+ viewData->m_requiredUpdate |= aUpdateFlags;
+ }
+}
+
+
struct VIEW::extentsVisitor
{
BOX2I extents;
diff --git a/gerbview/events_called_functions.cpp b/gerbview/events_called_functions.cpp
index 72d47f890..bca5f36c6 100644
--- a/gerbview/events_called_functions.cpp
+++ b/gerbview/events_called_functions.cpp
@@ -450,6 +450,8 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
{
int id = event.GetId();
bool state;
+ bool needs_refresh = false;
+ bool needs_repaint = false;
switch( id )
{
@@ -471,20 +473,17 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH:
m_DisplayOptions.m_DisplayFlashedItemsFill = not state;
- applyDisplaySettingsToGAL();
- m_canvas->Refresh( true );
+ needs_refresh = needs_repaint = true;
break;
case ID_TB_OPTIONS_SHOW_LINES_SKETCH:
m_DisplayOptions.m_DisplayLinesFill = not state;
- applyDisplaySettingsToGAL();
- m_canvas->Refresh( true );
+ needs_refresh = needs_repaint = true;
break;
case ID_TB_OPTIONS_SHOW_POLYGONS_SKETCH:
m_DisplayOptions.m_DisplayPolygonsFill = not state;
- applyDisplaySettingsToGAL();
- m_canvas->Refresh( true );
+ needs_refresh = needs_repaint = true;
break;
case ID_TB_OPTIONS_SHOW_DCODES:
@@ -499,14 +498,12 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
case ID_TB_OPTIONS_DIFF_MODE:
m_DisplayOptions.m_DiffMode = state;
- applyDisplaySettingsToGAL();
- m_canvas->Refresh( true );
+ needs_refresh = true;
break;
case ID_TB_OPTIONS_HIGH_CONTRAST_MODE:
m_DisplayOptions.m_HighContrastMode = state;
- applyDisplaySettingsToGAL();
- m_canvas->Refresh( true );
+ needs_refresh = true;
break;
case ID_TB_OPTIONS_SHOW_LAYERS_MANAGER_VERTICAL_TOOLBAR:
@@ -529,6 +526,19 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event )
wxMessageBox( wxT( "GERBVIEW_FRAME::OnSelectOptionToolbar error" ) );
break;
}
+
+ if( needs_refresh )
+ {
+ applyDisplaySettingsToGAL();
+ auto view = GetGalCanvas()->GetView();
+
+ if( needs_repaint )
+ view->UpdateAllItems( KIGFX::GEOMETRY );
+ else
+ view->UpdateAllItems( KIGFX::COLOR );
+
+ m_canvas->Refresh( true );
+ }
}
diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp
index ada045a9f..8293a1c5e 100644
--- a/gerbview/gerbview_painter.cpp
+++ b/gerbview/gerbview_painter.cpp
@@ -56,6 +56,10 @@ void GERBVIEW_RENDER_SETTINGS::ImportLegacyColors( const COLORS_DESIGN_SETTINGS*
i < GERBVIEW_LAYER_ID_START + GERBER_DRAWLAYERS_COUNT; i++ )
{
COLOR4D baseColor = aSettings->GetLayerColor( i );
+
+ if( m_diffMode )
+ baseColor.a = 0.75;
+
m_layerColors[i] = baseColor;
m_layerColorsHi[i] = baseColor.Brightened( 0.5 );
m_layerColorsSel[i] = baseColor.Brightened( 0.8 );
@@ -225,11 +229,6 @@ void GERBVIEW_PAINTER::draw( /*const*/ GERBER_DRAW_ITEM* aItem, int aLayer )
if( aItem->IsBrightened() )
color = COLOR4D( 0.0, 1.0, 0.0, 0.75 );
- if( m_gerbviewSettings.m_diffMode )
- {
- color.a = 0.75;
- }
-
m_gal->SetNegativeDrawMode( isNegative );
m_gal->SetStrokeColor( color );
m_gal->SetFillColor( color );
diff --git a/include/view/view.h b/include/view/view.h
index 30bb6df39..15f851e13 100644
--- a/include/view/view.h
+++ b/include/view/view.h
@@ -610,6 +610,12 @@ public:
*/
void UpdateItems();
+ /**
+ * Updates all items in the view according to the given flags
+ * @param aUpdateFlags is is according to KIGFX::VIEW_UPDATE_FLAGS
+ */
+ void UpdateAllItems( int aUpdateFlags );
+
const BOX2I CalculateExtents() ;
/**
--
2.14.1
Follow ups