← Back to team overview

kicad-developers team mailing list archive

[PATCH] Refactor post-load actions in PcbNew and apply them consistently

 

Fixes: https://bugs.launchpad.net/kicad/+bug/1751589
From c8e31559693753a6fd9cfaab29c5d77e01122a7b Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Sun, 25 Feb 2018 12:52:52 -0500
Subject: [PATCH] Refactor post-load actions in PcbNew and apply them
 consistently

Fixes: lp:1751589
* https://bugs.launchpad.net/kicad/+bug/1751589
---
 pcbnew/append_board_to_current.cpp |  7 ++-----
 pcbnew/files.cpp                   | 35 ++++-------------------------------
 pcbnew/pcb_edit_frame.cpp          | 29 +++++++++++++++++++++++++++++
 pcbnew/pcb_edit_frame.h            |  5 +++++
 4 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/pcbnew/append_board_to_current.cpp b/pcbnew/append_board_to_current.cpp
index 2f962d41b..af3c3ff57 100644
--- a/pcbnew/append_board_to_current.cpp
+++ b/pcbnew/append_board_to_current.cpp
@@ -197,8 +197,8 @@ bool PCB_EDIT_FRAME::AppendBoardFile( const wxString& aFullFileName, int aCtl )
     enabledLayers |= initialEnabledLayers;
     GetBoard()->SetEnabledLayers( enabledLayers );
     GetBoard()->SetVisibleLayers( enabledLayers );
-    ReCreateLayerBox();
-    ReFillLayerWidget();
+
+    onBoardLoaded();
 
     if( IsGalCanvasActive() )
         static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->SyncLayersVisibility( GetBoard() );
@@ -206,9 +206,6 @@ bool PCB_EDIT_FRAME::AppendBoardFile( const wxString& aFullFileName, int aCtl )
     GetBoard()->BuildListOfNets();
     GetBoard()->SynchronizeNetsAndNetClasses();
 
-    SetStatusText( wxEmptyString );
-    Zoom_Automatique( false );
-
     // Finish block move command:
     wxPoint cpos = GetNearestGridPosition( bbox.Centre() );
     blockmove.SetOrigin( bbox.GetOrigin() );
diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp
index 8c10031c7..f888ea7ec 100644
--- a/pcbnew/files.cpp
+++ b/pcbnew/files.cpp
@@ -329,8 +329,9 @@ void PCB_EDIT_FRAME::Files_io_from_id( int id )
         fn.SetExt( PcbFileExtension );
 
         GetBoard()->SetFileName( fn.GetFullPath() );
-        UpdateTitle();
-        ReCreateLayerBox();
+
+        onBoardLoaded();
+
         OnModify();
         break;
     }
@@ -532,12 +533,6 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
         loadedBoard->BuildListOfNets();
         loadedBoard->SynchronizeNetsAndNetClasses();
 
-        SetStatusText( wxEmptyString );
-        Zoom_Automatique( false );
-
-        // update the layer names in the listbox
-        ReCreateLayerBox( false );
-
         GetScreen()->ClrModify();
 
         {
@@ -567,8 +562,6 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
         GetBoard()->SetFileName( fname );
     }
 
-    UpdateTitle();
-
     if( !converted )
         UpdateFileHistory( GetBoard()->GetFileName() );
 
@@ -582,27 +575,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
     Compile_Ratsnest( NULL, true );
     GetBoard()->BuildConnectivity();
 
-    // Update info shown by the horizontal toolbars
-    ReFillLayerWidget();
-    ReCreateLayerBox();
-
-    // upate the layer widget to match board visibility states, both layers and render columns.
-    syncLayerVisibilities();
-    syncLayerWidgetLayer();
-    syncRenderStates();
-
-    // Update the tracks / vias available sizes list:
-    ReCreateAuxiliaryToolbar();
-
-    // Update the RATSNEST items, which were not loaded at the time
-    // BOARD::SetVisibleElements() was called from within any PLUGIN.
-    // See case LAYER_RATSNEST: in BOARD::SetElementVisibility()
-    GetBoard()->SetVisibleElements( GetBoard()->GetVisibleElements() );
-
-    // Display the loaded board:
-    Zoom_Automatique( false );
-
-    SetMsgPanel( GetBoard() );
+    onBoardLoaded();
 
     // Refresh the 3D view, if any
     EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame();
diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp
index cf622859c..80d25795e 100644
--- a/pcbnew/pcb_edit_frame.cpp
+++ b/pcbnew/pcb_edit_frame.cpp
@@ -946,6 +946,35 @@ void PCB_EDIT_FRAME::SetActiveLayer( PCB_LAYER_ID aLayer )
 }
 
 
+void PCB_EDIT_FRAME::onBoardLoaded()
+{
+    UpdateTitle();
+
+    // Re-create layers manager based on layer info in board
+    ReFillLayerWidget();
+    ReCreateLayerBox();
+
+    // Sync layer and item visibility
+    syncLayerVisibilities();
+    syncLayerWidgetLayer();
+    syncRenderStates();
+
+    // Update the tracks / vias available sizes list:
+    ReCreateAuxiliaryToolbar();
+
+    // Update the RATSNEST items, which were not loaded at the time
+    // BOARD::SetVisibleElements() was called from within any PLUGIN.
+    // See case LAYER_RATSNEST: in BOARD::SetElementVisibility()
+    GetBoard()->SetVisibleElements( GetBoard()->GetVisibleElements() );
+
+    // Display the loaded board:
+    Zoom_Automatique( false );
+
+    SetMsgPanel( GetBoard() );
+    SetStatusText( wxEmptyString );
+}
+
+
 void PCB_EDIT_FRAME::syncLayerWidgetLayer()
 {
     m_Layers->SelectLayer( GetActiveLayer() );
diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h
index bc8bf5be4..b2f05f0a6 100644
--- a/pcbnew/pcb_edit_frame.h
+++ b/pcbnew/pcb_edit_frame.h
@@ -163,6 +163,11 @@ protected:
        return FindWindowByName( pythonConsoleNameId() );
     }
 
+    /**
+     * Updates the state of the GUI after a new board is loaded or created
+     */
+    void onBoardLoaded();
+
     /**
      * Function syncLayerWidgetLayer
      * updates the currently layer "selection" within the PCB_LAYER_WIDGET.
-- 
2.14.1


Follow ups