← Back to team overview

kicad-developers team mailing list archive

[Patch] Move pcbnew layer toolbar icon values to member struct

 

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 ee05e8c32b789d72d95df422b0d6d71ae78bd0f8 Mon Sep 17 00:00:00 2001
From: Ian McInerney <Ian.S.McInerney@xxxxxxxx>
Date: Mon, 5 Aug 2019 12:16:32 +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..1dee81613 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 abad13918..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