Eeschema: fixes about Hierarchy panel/pane handling

This commit is contained in:
jean-pierre charras 2022-06-09 19:39:35 +02:00
parent 80c8cfbbda
commit b712c2c0da
3 changed files with 75 additions and 39 deletions

View File

@ -1,24 +1,20 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2014-2022 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software: you can redistribute it and/or modify it
* modify it under the terms of the GNU General Public License * under the terms of the GNU General Public License as published by the
* as published by the Free Software Foundation; either version 2 * Free Software Foundation, either version 3 of the License, or (at your
* of the License, or (at your option) any later version. * option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful, but
* but WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* GNU General Public License for more details. * General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License along
* along with this program; if not, you may find one here: * with this program. If not, see <http://www.gnu.org/licenses/>.
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#include <mutex> #include <mutex>
@ -155,27 +151,18 @@ void SCH_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
void SCH_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) void SCH_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
{ {
SCH_BASE_FRAME::SaveSettings( eeconfig() ); SCH_BASE_FRAME::SaveSettings( eeconfig() );
wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
m_showHierarchy = hierarchy_pane.IsShown();
// TODO(JE) do we need to keep m_userUnits around? // TODO(JE) do we need to keep m_userUnits around?
if( eeconfig() ) if( eeconfig() )
{ {
eeconfig()->m_System.units = static_cast<int>( m_userUnits ); eeconfig()->m_System.units = static_cast<int>( m_userUnits );
wxAuiPaneInfo& hierarchy = m_auimgr.GetPane( SchematicHierarchyPaneName() );
m_showHierarchy = hierarchy.IsShown();
eeconfig()->m_AuiPanels.show_schematic_hierarchy = m_showHierarchy; eeconfig()->m_AuiPanels.show_schematic_hierarchy = m_showHierarchy;
eeconfig()->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
if( hierarchy.IsFloating() ) // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
{ // and hierarchy_panel_docked_width should have been updated when resizing the
eeconfig()->m_AuiPanels.schematic_hierarchy_float = true; // hierarchy panel
eeconfig()->m_AuiPanels.hierarchy_panel_float_width = hierarchy.floating_size.x;
eeconfig()->m_AuiPanels.hierarchy_panel_float_height = hierarchy.floating_size.y;
}
else
{
eeconfig()->m_AuiPanels.hierarchy_panel_docked_width = m_hierarchy->GetSize().x;
eeconfig()->m_AuiPanels.schematic_hierarchy_float = false;
}
} }
} }

View File

@ -172,8 +172,9 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
.BottomDockable( false ) .BottomDockable( false )
.CloseButton( true ) .CloseButton( true )
.MinSize(120, -1) .MinSize(120, -1)
.BestSize(150, -1) .BestSize(200, -1)
.FloatingSize( 200, 80 ) .FloatingSize( 200, 80 )
.Show( false )
); );
m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" ) m_auimgr.AddPane( m_drawToolBar, EDA_PANE().VToolbar().Name( "ToolsToolbar" )
.Right().Layer( 2 ) ); .Right().Layer( 2 ) );
@ -186,11 +187,12 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
if( eeconfig() ) if( eeconfig() )
{ {
hierarchy_pane.FloatingSize( eeconfig()->m_AuiPanels.hierarchy_panel_float_width, if( eeconfig()->m_AuiPanels.hierarchy_panel_float_width > 0
eeconfig()->m_AuiPanels.hierarchy_panel_float_height ); && eeconfig()->m_AuiPanels.hierarchy_panel_float_height > 0 )
{
if( eeconfig()->m_AuiPanels.schematic_hierarchy_float ) hierarchy_pane.FloatingSize( eeconfig()->m_AuiPanels.hierarchy_panel_float_width,
hierarchy_pane.Float(); eeconfig()->m_AuiPanels.hierarchy_panel_float_height );
}
if( eeconfig()->m_AuiPanels.hierarchy_panel_docked_width > 0 ) if( eeconfig()->m_AuiPanels.hierarchy_panel_docked_width > 0 )
{ {
@ -200,8 +202,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
} }
} }
hierarchy_pane.Show( m_showHierarchy );
FinishAUIInitialization(); FinishAUIInitialization();
resolveCanvasType(); resolveCanvasType();
@ -211,6 +211,11 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
initScreenZoom(); initScreenZoom();
m_hierarchy->Connect( wxEVT_SIZE,
wxSizeEventHandler( SCH_EDIT_FRAME::OnResizeHierarchyNavigator ),
NULL, this );
// This is used temporarily to fix a client size issue on GTK that causes zoom to fit // This is used temporarily to fix a client size issue on GTK that causes zoom to fit
// to calculate the wrong zoom size. See SCH_EDIT_FRAME::onSize(). // to calculate the wrong zoom size. See SCH_EDIT_FRAME::onSize().
Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this ); Bind( wxEVT_SIZE, &SCH_EDIT_FRAME::onSize, this );
@ -241,11 +246,20 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
// to the left top corner of the canvas // to the left top corner of the canvas
wxPoint canvas_pos = GetCanvas()->GetScreenPosition(); wxPoint canvas_pos = GetCanvas()->GetScreenPosition();
hierarchy_pane.FloatingPosition( canvas_pos.x + 10, canvas_pos.y + 10 ); hierarchy_pane.FloatingPosition( canvas_pos.x + 10, canvas_pos.y + 10 );
if( eeconfig() && eeconfig()->m_AuiPanels.schematic_hierarchy_float )
hierarchy_pane.Float();
hierarchy_pane.Show( m_showHierarchy );
} }
SCH_EDIT_FRAME::~SCH_EDIT_FRAME() SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
{ {
m_hierarchy->Disconnect( wxEVT_SIZE,
wxSizeEventHandler( SCH_EDIT_FRAME::OnResizeHierarchyNavigator ),
NULL, this );
// Ensure m_canvasType is up to date, to save it in config // Ensure m_canvasType is up to date, to save it in config
m_canvasType = GetCanvas()->GetBackend(); m_canvasType = GetCanvas()->GetBackend();
@ -289,6 +303,38 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME()
} }
void SCH_EDIT_FRAME::OnResizeHierarchyNavigator( wxSizeEvent& aEvent )
{
aEvent.Skip();
// Called when resizing the Hierarchy Navigator panel
// Store the current pane size
// It allows to retrieve the last defined pane size when switching between
// docked and floating pane state
// Note: *DO NOT* call m_auimgr.Update() here: it crashes Kicad at leat on Windows
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
if( cfg && m_hierarchy->IsShown() )
{
cfg->m_AuiPanels.hierarchy_panel_float_width = hierarchy_pane.floating_size.x;
cfg->m_AuiPanels.hierarchy_panel_float_height = hierarchy_pane.floating_size.y;
// initialize hierarchy_panel_docked_width and best size only if the hierarchy_pane
// width is > 0 (i.e. if its size is already set and has meaning)
// if it is floating, its size is not initialized (only floating_size is initialized)
// initializing hierarchy_pane.best_size is useful when switching to float pane and
// after switching to the docked pane, to retrieve the last docked pane width
if( hierarchy_pane.rect.width > 50 ) // 50 is a good margin
{
cfg->m_AuiPanels.hierarchy_panel_docked_width = hierarchy_pane.rect.width;
hierarchy_pane.best_size.x = hierarchy_pane.rect.width;
}
}
}
void SCH_EDIT_FRAME::setupTools() void SCH_EDIT_FRAME::setupTools()
{ {
// Create the manager and dispatcher & route draw panel events to the dispatcher // Create the manager and dispatcher & route draw panel events to the dispatcher

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras wanadoo.fr * Copyright (C) 2015 Jean-Pierre Charras, jp.charras wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -864,6 +864,9 @@ protected:
void onSize( wxSizeEvent& aEvent ); void onSize( wxSizeEvent& aEvent );
private: private:
// Called when resizing the Hierarchy Navigator panel
void OnResizeHierarchyNavigator( wxSizeEvent& aEvent );
// Sets up the tool framework // Sets up the tool framework
void setupTools(); void setupTools();