← Back to team overview

kicad-developers team mailing list archive

Static variables in module editor

 

Hi,

I have found a few static variables in the module editor code that I would like to remove, but I need to know your opinion. The variables are used to keep the last edited module between editor invocations.

If we want to preserve such behaviour, I will need to add a few more static variables (for sure VIEW, maybe VIEW_CONTROLS and some stuff related to the Tool Framework). I would rather avoid such solution.

Furthermore, the footprint stored in the editor is completely independent - it is not bound to anything on board or library. Do we need to keep it? If there is a modification done, the user is asked if he wants to save his work or update a footprint, so there is a little chance of losing data.

The attached patch will give you an idea of proposed changes.

Regards,
Orson
>From b34bac092cbb63fef2182400a43dd34c2a43fcf6 Mon Sep 17 00:00:00 2001
From: Maciej Suminski <maciej.suminski@xxxxxxx>
Date: Tue, 10 Jun 2014 09:41:42 +0200
Subject: [PATCH] Removed static BOARD & PCB_SCREEN from module editor.

---
 pcbnew/module_editor_frame.h |  1 -
 pcbnew/moduleframe.cpp       | 28 +++++-----------------------
 2 files changed, 5 insertions(+), 24 deletions(-)

diff --git a/pcbnew/module_editor_frame.h b/pcbnew/module_editor_frame.h
index 0bc942f..8f54bae 100644
--- a/pcbnew/module_editor_frame.h
+++ b/pcbnew/module_editor_frame.h
@@ -408,7 +408,6 @@ protected:
     /// protected so only friend PCB::IFACE::CreateWindow() can act as sole factory.
     FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent );
 
-    static BOARD*   s_Pcb;      ///< retain board across invocations of module editor
 
     /**
      * Function GetComponentFromUndoList
diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp
index 913ee70..7fd0273 100644
--- a/pcbnew/moduleframe.cpp
+++ b/pcbnew/moduleframe.cpp
@@ -62,10 +62,6 @@
 #include "tools/common_actions.h"
 
 
-static PCB_SCREEN* s_screenModule;      // the PCB_SCREEN used by the footprint editor
-
-BOARD* FOOTPRINT_EDIT_FRAME::s_Pcb;
-
 BEGIN_EVENT_TABLE( FOOTPRINT_EDIT_FRAME, PCB_BASE_FRAME )
     EVT_MENU_RANGE( ID_POPUP_PCB_ITEM_SELECTION_START, ID_POPUP_PCB_ITEM_SELECTION_END,
                     PCB_BASE_FRAME::ProcessItemSelection )
@@ -186,20 +182,15 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
                                                             drawFrame->GetGalCanvas()->GetBackend() );
     SetGalCanvas( drawPanel );
 
-    if( !s_Pcb )
-    {
-        s_Pcb = new BOARD();
+    m_Pcb = new BOARD();
 
-        // Ensure all layers and items are visible:
-        s_Pcb->SetVisibleAlls();
-    }
+    // Ensure all layers and items are visible:
+    m_Pcb->SetVisibleAlls();
 
-    SetBoard( s_Pcb );
+    SetBoard( m_Pcb );
 
-    if( !s_screenModule )
-        s_screenModule = new PCB_SCREEN( GetPageSettings().GetSizeIU() );
 
-    SetScreen( s_screenModule );
+    SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) );
 
     GetScreen()->SetCurItem( NULL );
     LoadSettings( config() );
@@ -286,15 +277,6 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
 
 FOOTPRINT_EDIT_FRAME::~FOOTPRINT_EDIT_FRAME()
 {
-    // When user reopens the Footprint editor, user would like to find the last edited item.
-    // Do not delete PCB_SCREEN (by the destructor of EDA_DRAW_FRAME)
-    SetScreen( NULL );
-
-    // Do not allow PCB_BASE_FRAME::~PCB_BASE_FRAME()
-    // to delete our precious BOARD, which is also in static FOOTPRINT_EDIT_FRAME::s_Pcb.
-    // That function, PCB_BASE_FRAME::~PCB_BASE_FRAME(), runs immediately next
-    // as we return from here.
-    m_Pcb = 0;
 }
 
 
-- 
1.9.1


Follow ups