From ddc6ecf7be29e8e23bdb7475f1a90373b12072fd Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 11 May 2023 01:24:06 +0100 Subject: [PATCH] Lazy loading of Schematic Setup panels. --- common/dialogs/panel_setup_netclasses.cpp | 16 ++- .../dialogs/panel_setup_netclasses_base.cpp | 2 +- .../dialogs/panel_setup_netclasses_base.fbp | 2 +- common/widgets/wx_treebook.cpp | 2 +- eeschema/dialogs/dialog_schematic_setup.cpp | 117 ++++++++++++------ eeschema/dialogs/dialog_schematic_setup.h | 20 +-- include/widgets/wx_treebook.h | 2 +- pcbnew/dialogs/dialog_board_setup.cpp | 17 +-- pcbnew/dialogs/dialog_board_setup.h | 20 ++- 9 files changed, 119 insertions(+), 79 deletions(-) diff --git a/common/dialogs/panel_setup_netclasses.cpp b/common/dialogs/panel_setup_netclasses.cpp index bcf94faf38..8936855808 100644 --- a/common/dialogs/panel_setup_netclasses.cpp +++ b/common/dialogs/panel_setup_netclasses.cpp @@ -119,10 +119,8 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA // as this initial width is sometimes strange depending on the language (wxGrid bug?) int const min_width = m_netclassGrid->GetVisibleWidth( i, true, true ); - int const weighted_min_best_width = - ( i == GRID_LINESTYLE ) - ? min_best_width * 3 / 2 - : min_best_width; + int const weighted_min_best_width = ( i == GRID_LINESTYLE ) ? min_best_width * 3 / 2 + : min_best_width; m_netclassGrid->SetColMinimalWidth( i, min_width ); @@ -172,7 +170,6 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRA m_netclassGrid->SetAutoEvalCols( { GRID_WIREWIDTH, GRID_BUSWIDTH, - GRID_CLEARANCE, GRID_TRACKSIZE, GRID_VIASIZE, @@ -325,6 +322,8 @@ bool PANEL_SETUP_NETCLASSES::TransferDataToWindow() row++; } + AdjustAssignmentGridColumns( GetSize().x * 3 / 5 ); + return true; } @@ -650,16 +649,15 @@ void PANEL_SETUP_NETCLASSES::AdjustAssignmentGridColumns( int aWidth ) // Account for scroll bars aWidth -= ( m_assignmentGrid->GetSize().x - m_assignmentGrid->GetClientSize().x ); - // Set className column width to original className width from netclasses grid - int classNameWidth = m_originalColWidths[ 0 ]; - m_assignmentGrid->SetColSize( 1, m_originalColWidths[ 0 ] ); + int classNameWidth = 160; + m_assignmentGrid->SetColSize( 1, classNameWidth ); m_assignmentGrid->SetColSize( 0, std::max( aWidth - classNameWidth, classNameWidth ) ); } void PANEL_SETUP_NETCLASSES::OnSizeAssignmentGrid( wxSizeEvent& event ) { - AdjustAssignmentGridColumns( event.GetSize().GetX()); + AdjustAssignmentGridColumns( event.GetSize().GetX() ); event.Skip(); } diff --git a/common/dialogs/panel_setup_netclasses_base.cpp b/common/dialogs/panel_setup_netclasses_base.cpp index cd0545f7ca..a39b152837 100644 --- a/common/dialogs/panel_setup_netclasses_base.cpp +++ b/common/dialogs/panel_setup_netclasses_base.cpp @@ -129,7 +129,7 @@ PANEL_SETUP_NETCLASSES_BASE::PANEL_SETUP_NETCLASSES_BASE( wxWindow* parent, wxWi m_assignmentGrid->SetMargins( 0, 0 ); // Columns - m_assignmentGrid->SetColSize( 0, 400 ); + m_assignmentGrid->SetColSize( 0, 360 ); m_assignmentGrid->SetColSize( 1, 160 ); m_assignmentGrid->EnableDragColMove( false ); m_assignmentGrid->EnableDragColSize( true ); diff --git a/common/dialogs/panel_setup_netclasses_base.fbp b/common/dialogs/panel_setup_netclasses_base.fbp index 05582983d2..991b9f3784 100644 --- a/common/dialogs/panel_setup_netclasses_base.fbp +++ b/common/dialogs/panel_setup_netclasses_base.fbp @@ -766,7 +766,7 @@ "Pattern" "Net Class" wxALIGN_CENTER 2 - 400,160 + 360,160 1 0 diff --git a/common/widgets/wx_treebook.cpp b/common/widgets/wx_treebook.cpp index bc4f32ba05..5207da231d 100644 --- a/common/widgets/wx_treebook.cpp +++ b/common/widgets/wx_treebook.cpp @@ -90,7 +90,7 @@ bool WX_TREEBOOK::AddLazySubPage( std::function } -wxWindow* WX_TREEBOOK::ResolvePage( int aPage ) +wxWindow* WX_TREEBOOK::ResolvePage( size_t aPage ) { wxWindow* page = GetPage( aPage ); diff --git a/eeschema/dialogs/dialog_schematic_setup.cpp b/eeschema/dialogs/dialog_schematic_setup.cpp index 0851b75d82..a7fa200c9d 100644 --- a/eeschema/dialogs/dialog_schematic_setup.cpp +++ b/eeschema/dialogs/dialog_schematic_setup.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -34,60 +34,88 @@ #include #include "dialog_schematic_setup.h" #include "panel_template_fieldnames.h" -#include DIALOG_SCHEMATIC_SETUP::DIALOG_SCHEMATIC_SETUP( SCH_EDIT_FRAME* aFrame ) : PAGED_DIALOG( aFrame, _( "Schematic Setup" ), true, _( "Import Settings from Another Project..." ) ), - m_frame( aFrame ), - m_severities( nullptr ) + m_frame( aFrame ) { - PROJECT_FILE& project = aFrame->Prj().GetProjectFile(); - SCHEMATIC& schematic = aFrame->Schematic(); - SCHEMATIC_SETTINGS& settings = schematic.Settings(); - SetEvtHandlerEnabled( false ); - m_formatting = new PANEL_SETUP_FORMATTING( m_treebook, aFrame ); - - m_fieldNameTemplates = new PANEL_TEMPLATE_FIELDNAMES( m_treebook, - &settings.m_TemplateFieldNames ); - - m_pinMap = new PANEL_SETUP_PINMAP( m_treebook, aFrame ); - m_pinToPinError = ERC_ITEM::Create( ERCE_PIN_TO_PIN_WARNING ); - m_severities = new PANEL_SETUP_SEVERITIES( this, ERC_ITEM::GetItemsWithSeverities(), - schematic.ErcSettings().m_ERCSeverities, - m_pinToPinError.get() ); - - m_textVars = new PANEL_TEXT_VARIABLES( m_treebook, &Prj() ); - - m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, project.NetSettings(), - schematic.GetNetClassAssignmentCandidates(), true ); - - m_buses = new PANEL_SETUP_BUSES( m_treebook, aFrame ); /* * WARNING: If you change page names you MUST update calls to ShowSchematicSetupDialog(). */ m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "General" ) ); - m_treebook->AddSubPage( m_formatting, _( "Formatting" ) ); - m_treebook->AddSubPage( m_fieldNameTemplates, _( "Field Name Templates" ) ); + + m_formattingPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_FORMATTING( aParent, m_frame ); + }, _( "Formatting" ) ); + + m_fieldNameTemplatesPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + SCHEMATIC_SETTINGS& settings = m_frame->Schematic().Settings(); + return new PANEL_TEMPLATE_FIELDNAMES( aParent, &settings.m_TemplateFieldNames ); + }, _( "Field Name Templates" ) ); m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Electrical Rules" ) ); - m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) ); - m_treebook->AddSubPage( m_pinMap, _( "Pin Conflicts Map" ) ); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + ERC_SETTINGS& ercSettings = m_frame->Schematic().ErcSettings(); + return new PANEL_SETUP_SEVERITIES( aParent, ERC_ITEM::GetItemsWithSeverities(), + ercSettings.m_ERCSeverities, + m_pinToPinError.get() ); + }, _( "Violation Severity" ) ); + + m_pinMapPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_PINMAP( aParent, m_frame ); + }, _( "Pin Conflicts Map" ) ); m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Project" ) ); - m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) ); - m_treebook->AddSubPage( m_buses, _( "Bus Alias Definitions" ) ); - m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) ); + + m_netclassesPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + SCHEMATIC& schematic = m_frame->Schematic(); + return new PANEL_SETUP_NETCLASSES( aParent, m_frame, + m_frame->Prj().GetProjectFile().NetSettings(), + schematic.GetNetClassAssignmentCandidates(), + true ); + }, _( "Net Classes" ) ); + + m_busesPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_BUSES( aParent, m_frame ); + }, _( "Bus Alias Definitions" ) ); + + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_TEXT_VARIABLES( aParent, &Prj() ); + }, _( "Text Variables" ) ); for( size_t i = 0; i < m_treebook->GetPageCount(); ++i ) m_treebook->ExpandNode( i ); + // This is unfortunate, but it's the cost of lazy-loading the panels + m_treebook->SetMinSize( wxSize( 920, 460 ) ); + m_treebook->SetInitialSize( wxSize( 920, 460 ) ); + SetEvtHandlerEnabled( true ); finishDialogSettings(); @@ -148,19 +176,34 @@ void DIALOG_SCHEMATIC_SETUP::onAuxiliaryAction( wxCommandEvent& event ) file.m_SchematicSettings->LoadFromFile(); if( importDlg.m_FormattingOpt->GetValue() ) - m_formatting->ImportSettingsFrom( *file.m_SchematicSettings ); + { + static_cast( m_treebook->ResolvePage( m_formattingPage ) ) + ->ImportSettingsFrom( *file.m_SchematicSettings ); + } if( importDlg.m_FieldNameTemplatesOpt->GetValue() ) - m_fieldNameTemplates->ImportSettingsFrom( &otherSch.Settings().m_TemplateFieldNames ); + { + static_cast( m_treebook->ResolvePage( m_fieldNameTemplatesPage ) ) + ->ImportSettingsFrom( &otherSch.Settings().m_TemplateFieldNames ); + } if( importDlg.m_PinMapOpt->GetValue() ) - m_pinMap->ImportSettingsFrom( file.m_ErcSettings->m_PinMap ); + { + static_cast( m_treebook->ResolvePage( m_pinMapPage ) ) + ->ImportSettingsFrom( file.m_ErcSettings->m_PinMap ); + } if( importDlg.m_SeveritiesOpt->GetValue() ) - m_severities->ImportSettingsFrom( file.m_ErcSettings->m_ERCSeverities ); + { + static_cast( m_treebook->ResolvePage( m_severitiesPage ) ) + ->ImportSettingsFrom( file.m_ErcSettings->m_ERCSeverities ); + } if( importDlg.m_NetClassesOpt->GetValue() ) - m_netclasses->ImportSettingsFrom( file.m_NetSettings ); + { + static_cast( m_treebook->ResolvePage( m_netclassesPage ) ) + ->ImportSettingsFrom( file.m_NetSettings ); + } m_frame->GetSettingsManager()->UnloadProject( otherPrj, false ); } diff --git a/eeschema/dialogs/dialog_schematic_setup.h b/eeschema/dialogs/dialog_schematic_setup.h index a65ae5d111..47b7a4154a 100644 --- a/eeschema/dialogs/dialog_schematic_setup.h +++ b/eeschema/dialogs/dialog_schematic_setup.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -45,16 +45,16 @@ protected: void onPageChanged( wxBookCtrlEvent& aEvent ) override; void onAuxiliaryAction( wxCommandEvent& aEvent ) override; - SCH_EDIT_FRAME* m_frame; + SCH_EDIT_FRAME* m_frame; - PANEL_SETUP_FORMATTING* m_formatting; - PANEL_TEMPLATE_FIELDNAMES* m_fieldNameTemplates; - PANEL_SETUP_PINMAP* m_pinMap; - PANEL_SETUP_SEVERITIES* m_severities; - PANEL_SETUP_NETCLASSES* m_netclasses; - PANEL_SETUP_BUSES* m_buses; - PANEL_TEXT_VARIABLES* m_textVars; - std::shared_ptr m_pinToPinError; + std::shared_ptr m_pinToPinError; + + size_t m_formattingPage; + size_t m_fieldNameTemplatesPage; + size_t m_pinMapPage; + size_t m_busesPage; + size_t m_severitiesPage; + size_t m_netclassesPage; }; diff --git a/include/widgets/wx_treebook.h b/include/widgets/wx_treebook.h index 7d353888eb..45c794e8f2 100644 --- a/include/widgets/wx_treebook.h +++ b/include/widgets/wx_treebook.h @@ -39,7 +39,7 @@ public: bool AddLazySubPage( std::function aLazyCtor, const wxString& text, bool bSelect = false, int imageId = NO_IMAGE ); - wxWindow* ResolvePage( int aPage ); + wxWindow* ResolvePage( size_t aPage ); }; diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index f7aaacc754..3e70972daf 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include "dialog_board_setup.h" @@ -102,7 +101,6 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : return new PANEL_SETUP_FORMATTING( aParent, m_frame ); }, _( "Formatting" ) ); - m_textVarsPage = m_treebook->GetPageCount(); m_treebook->AddLazySubPage( [this]( wxWindow* aParent ) -> wxWindow* { @@ -129,13 +127,13 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : m_treebook->AddLazySubPage( [this]( wxWindow* aParent ) -> wxWindow* { + BOARD* board = m_frame->GetBoard(); return new PANEL_SETUP_NETCLASSES( aParent, m_frame, m_frame->Prj().GetProjectFile().NetSettings(), - m_frame->GetBoard()->GetNetClassAssignmentCandidates(), + board->GetNetClassAssignmentCandidates(), false ); }, _( "Net Classes" ) ); - m_rulesPage = m_treebook->GetPageCount(); m_treebook->AddLazySubPage( [this]( wxWindow* aParent ) -> wxWindow* { @@ -146,15 +144,18 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : m_treebook->AddLazySubPage( [this]( wxWindow* aParent ) -> wxWindow* { + BOARD* board = m_frame->GetBoard(); return new PANEL_SETUP_SEVERITIES( aParent, DRC_ITEM::GetItemsWithSeverities(), - m_frame->GetBoard()->GetDesignSettings().m_DRCSeverities ); + board->GetDesignSettings().m_DRCSeverities ); }, _( "Violation Severity" ) ); for( size_t i = 0; i < m_treebook->GetPageCount(); ++i ) m_treebook->ExpandNode( i ); - m_treebook->SetMinSize( wxSize( -1, 580 ) ); - m_treebook->SetInitialSize( wxSize( -1, 700 ) ); + // This is unfortunate, but it's the cost of lazy-loading the panels + m_treebook->SetMinSize( wxSize( 980, 600 ) ); + m_treebook->SetInitialSize( wxSize( 980, 600 ) ); + SetEvtHandlerEnabled( true ); finishDialogSettings(); @@ -180,7 +181,7 @@ void DIALOG_BOARD_SETUP::onPageChanged( wxBookCtrlEvent& aEvent ) { PAGED_DIALOG::onPageChanged( aEvent ); - int page = aEvent.GetSelection(); + size_t page = aEvent.GetSelection(); // Ensure layer page always gets updated even if we aren't moving towards it if( m_currentPage == m_physicalStackupPage ) diff --git a/pcbnew/dialogs/dialog_board_setup.h b/pcbnew/dialogs/dialog_board_setup.h index ab0829b6bf..c5621c4e6b 100644 --- a/pcbnew/dialogs/dialog_board_setup.h +++ b/pcbnew/dialogs/dialog_board_setup.h @@ -60,17 +60,15 @@ public: static std::mutex g_Mutex; // Mutex to prevent multiple windows opening private: - int m_currentPage; // the current page index - int m_textAndGraphicsPage; - int m_constraintsPage; - int m_formattingPage; - int m_physicalStackupPage; - int m_tracksAndViasPage; - int m_netclassesPage; - int m_maskAndPagePage; - int m_rulesPage; - int m_severitiesPage; - int m_textVarsPage; + size_t m_currentPage; // the current page index + size_t m_textAndGraphicsPage; + size_t m_constraintsPage; + size_t m_formattingPage; + size_t m_physicalStackupPage; + size_t m_tracksAndViasPage; + size_t m_netclassesPage; + size_t m_maskAndPagePage; + size_t m_severitiesPage; };