From cfd67163a1efad304a321f8c9c483322826446a9 Mon Sep 17 00:00:00 2001 From: Jon Evans 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 2f962d41b8..af3c3ff578 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( 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 8c10031c71..f888ea7ec3 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& 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& aFileSet, in GetBoard()->SetFileName( fname ); } - UpdateTitle(); - if( !converted ) UpdateFileHistory( GetBoard()->GetFileName() ); @@ -582,27 +575,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector& 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 cf622859c3..80d25795ea 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 bc8bf5be4d..b2f05f0a6f 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.