kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #41809
Re: [Patch] Move pcbnew layer toolbar icon values to member struct
Here is an updated version of this patch that goes with the constexpr color
definitions instead of the initialize-on-first-use.
-Ian
On Mon, Aug 5, 2019 at 12:20 PM Ian McInerney <Ian.S.McInerney@xxxxxxxx>
wrote:
> This patch moves the static variables in the toolbar icon creation
> function into a member struct of the PCB_EDIT_FRAME class. These statics
> had posed some issues on Linux before, and are also not very good for
> having multiple PCB_EDIT_FRAME instances at one time.
>
> This patch is dependent upon the prior patch I just sent to fix the
> initialization of the COLOR4D static variables.
>
From 8ca5a3a0f77f42c63d441655a7904276db802f85 Mon Sep 17 00:00:00 2001
From: Ian McInerney <Ian.S.McInerney@xxxxxxxx>
Date: Mon, 5 Aug 2019 17:10:58 +0200
Subject: [PATCH] pcbnew: Move layer toolbar icon previous values to struct
The static variables posed problems on Linux, and also were
not as portable for multiple instances of PCB_EDIT_FRAME.
---
pcbnew/pcb_edit_frame.h | 26 ++++++++++++++++++++++++++
pcbnew/toolbars_pcb_editor.cpp | 33 +++++++++++++--------------------
2 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h
index f246160bf..d00fa5033 100644
--- a/pcbnew/pcb_edit_frame.h
+++ b/pcbnew/pcb_edit_frame.h
@@ -109,6 +109,32 @@ protected:
wxString m_lastPath[ LAST_PATH_SIZE ];
+
+ /**
+ * Store the previous layer toolbar icon state information
+ */
+ struct LAYER_TOOLBAR_ICON_VALUES
+ {
+ int previous_requested_scale;
+ COLOR4D previous_active_layer_color;
+ COLOR4D previous_Route_Layer_TOP_color;
+ COLOR4D previous_Route_Layer_BOTTOM_color;
+ COLOR4D previous_via_color;
+ COLOR4D previous_background_color;
+
+ LAYER_TOOLBAR_ICON_VALUES()
+ : previous_requested_scale( 0 ),
+ previous_active_layer_color( COLOR4D::UNSPECIFIED ),
+ previous_Route_Layer_TOP_color( COLOR4D::UNSPECIFIED ),
+ previous_Route_Layer_BOTTOM_color( COLOR4D::UNSPECIFIED ),
+ previous_via_color( COLOR4D::UNSPECIFIED ),
+ previous_background_color( COLOR4D::UNSPECIFIED )
+ {
+ }
+ };
+
+ LAYER_TOOLBAR_ICON_VALUES m_prevIconVal;
+
// The Tool Framework initalization
void setupTools();
diff --git a/pcbnew/toolbars_pcb_editor.cpp b/pcbnew/toolbars_pcb_editor.cpp
index f7c8e0526..d8b0edab4 100644
--- a/pcbnew/toolbars_pcb_editor.cpp
+++ b/pcbnew/toolbars_pcb_editor.cpp
@@ -90,60 +90,53 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator( bool aForceRebuild )
COLOR4D active_layer_color, top_color, bottom_color, via_color, background_color;
bool change = aForceRebuild;
- static int previous_requested_scale;
- static COLOR4D previous_active_layer_color = COLOR4D::UNSPECIFIED;
- static COLOR4D previous_Route_Layer_TOP_color = COLOR4D::UNSPECIFIED;
- static COLOR4D previous_Route_Layer_BOTTOM_color = COLOR4D::UNSPECIFIED;
- static COLOR4D previous_via_color = COLOR4D::UNSPECIFIED;
- static COLOR4D previous_background_color = COLOR4D::UNSPECIFIED;
-
int requested_scale;
Pgm().CommonSettings()->Read( ICON_SCALE_KEY, &requested_scale, 0 );
- if( requested_scale != previous_requested_scale )
+ if( m_prevIconVal.previous_requested_scale != requested_scale )
{
- previous_requested_scale = requested_scale;
+ m_prevIconVal.previous_requested_scale = requested_scale;
change = true;
}
- active_layer_color = Settings().Colors().GetLayerColor(GetActiveLayer());
+ active_layer_color = Settings().Colors().GetLayerColor( GetActiveLayer() );
- if( previous_active_layer_color != active_layer_color )
+ if( m_prevIconVal.previous_active_layer_color != active_layer_color )
{
- previous_active_layer_color = active_layer_color;
+ m_prevIconVal.previous_active_layer_color = active_layer_color;
change = true;
}
top_color = Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_TOP );
- if( previous_Route_Layer_TOP_color != top_color )
+ if( m_prevIconVal.previous_Route_Layer_TOP_color != top_color )
{
- previous_Route_Layer_TOP_color = top_color;
+ m_prevIconVal.previous_Route_Layer_TOP_color = top_color;
change = true;
}
bottom_color = Settings().Colors().GetLayerColor( GetScreen()->m_Route_Layer_BOTTOM );
- if( previous_Route_Layer_BOTTOM_color != bottom_color )
+ if( m_prevIconVal.previous_Route_Layer_BOTTOM_color != bottom_color )
{
- previous_Route_Layer_BOTTOM_color = bottom_color;
+ m_prevIconVal.previous_Route_Layer_BOTTOM_color = bottom_color;
change = true;
}
int via_type = GetDesignSettings().m_CurrentViaType;
via_color = Settings().Colors().GetItemColor( LAYER_VIAS + via_type );
- if( previous_via_color != via_color )
+ if( m_prevIconVal.previous_via_color != via_color )
{
- previous_via_color = via_color;
+ m_prevIconVal.previous_via_color = via_color;
change = true;
}
background_color = Settings().Colors().GetItemColor( LAYER_PCB_BACKGROUND );
- if( previous_background_color != background_color )
+ if( m_prevIconVal.previous_background_color != background_color )
{
- previous_background_color = background_color;
+ m_prevIconVal.previous_background_color = background_color;
change = true;
}
--
2.21.0
Follow ups
References