diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a1bc1b0373..e0de97a70b 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -217,6 +217,7 @@ set( COMMON_WIDGET_SRCS widgets/wx_panel.cpp widgets/wx_progress_reporters.cpp widgets/wx_splitter_window.cpp + widgets/wx_treebook.cpp ) set( COMMON_DRAWING_SHEET_SRCS diff --git a/common/dialogs/panel_common_settings.cpp b/common/dialogs/panel_common_settings.cpp index 0d76301d10..808b086443 100644 --- a/common/dialogs/panel_common_settings.cpp +++ b/common/dialogs/panel_common_settings.cpp @@ -44,9 +44,8 @@ * Ugly as it all is, it does improve our usability on various platforms. */ -PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS( DIALOG_SHIM* aDialog, wxWindow* aParent ) +PANEL_COMMON_SETTINGS::PANEL_COMMON_SETTINGS( wxWindow* aParent ) : PANEL_COMMON_SETTINGS_BASE( aParent ), - m_dialog( aDialog ), m_iconScaleLabel( nullptr ), m_iconScaleSlider( nullptr ), m_iconScaleAuto( nullptr ), diff --git a/common/dialogs/panel_data_collection.cpp b/common/dialogs/panel_data_collection.cpp index 65a7b880cd..5ffe069abd 100644 --- a/common/dialogs/panel_data_collection.cpp +++ b/common/dialogs/panel_data_collection.cpp @@ -37,8 +37,8 @@ #include -PANEL_DATA_COLLECTION::PANEL_DATA_COLLECTION( PAGED_DIALOG* aDialog, wxWindow* aParent ) : - PANEL_DATA_COLLECTION_BASE( aParent ), m_dialog( aDialog ) +PANEL_DATA_COLLECTION::PANEL_DATA_COLLECTION( wxWindow* aParent ) : + PANEL_DATA_COLLECTION_BASE( aParent ) { } diff --git a/common/dialogs/panel_mouse_settings.cpp b/common/dialogs/panel_mouse_settings.cpp index a610915e64..165ce3c4e0 100644 --- a/common/dialogs/panel_mouse_settings.cpp +++ b/common/dialogs/panel_mouse_settings.cpp @@ -26,9 +26,8 @@ #include -PANEL_MOUSE_SETTINGS::PANEL_MOUSE_SETTINGS( PAGED_DIALOG* aDialog, wxWindow* aParent ) : +PANEL_MOUSE_SETTINGS::PANEL_MOUSE_SETTINGS( wxWindow* aParent ) : PANEL_MOUSE_SETTINGS_BASE( aParent ), - m_dialog( aDialog ), m_currentScrollMod( {} ) { #ifdef __WXOSX_MAC__ @@ -82,8 +81,9 @@ bool PANEL_MOUSE_SETTINGS::TransferDataFromWindow() if( !isScrollModSetValid( m_currentScrollMod ) ) { - m_dialog->SetError( _( "Only one action can be assigned to each vertical scroll setting" ), - this, nullptr ); + PAGED_DIALOG::GetDialog( this )->SetError( _( "Only one action can be assigned to each " + "vertical scroll setting" ), + this, nullptr ); return false; } diff --git a/common/dialogs/panel_setup_netclasses.cpp b/common/dialogs/panel_setup_netclasses.cpp index ec98a13383..bcf94faf38 100644 --- a/common/dialogs/panel_setup_netclasses.cpp +++ b/common/dialogs/panel_setup_netclasses.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include @@ -70,13 +69,12 @@ std::vector g_lineStyleIcons; wxArrayString g_lineStyleNames; -PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, EDA_DRAW_FRAME* aFrame, +PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRAW_FRAME* aFrame, std::shared_ptr aNetSettings, const std::set& aNetNames, bool aIsEEschema ) : - PANEL_SETUP_NETCLASSES_BASE( aParent->GetTreebook() ), + PANEL_SETUP_NETCLASSES_BASE( aParentWindow ), m_frame( aFrame ), - m_parent( aParent ), m_isEEschema( aIsEEschema ), m_netSettings( aNetSettings ), m_netNames( aNetNames ), @@ -158,8 +156,8 @@ PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, EDA_DRAW_ } wxGridCellAttr* attr = new wxGridCellAttr; - attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( aParent ) ); - attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( aParent, m_netclassGrid ) ); + attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( PAGED_DIALOG::GetDialog( this ) ) ); + attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( PAGED_DIALOG::GetDialog( this ), m_netclassGrid ) ); m_netclassGrid->SetColAttr( GRID_SCHEMATIC_COLOR, attr ); attr = new wxGridCellAttr; @@ -427,7 +425,7 @@ bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aNa if( tmp.IsEmpty() ) { wxString msg = _( "Netclass must have a name." ); - m_parent->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME ); + PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, aRow, GRID_NAME ); return false; } @@ -436,7 +434,8 @@ bool PANEL_SETUP_NETCLASSES::validateNetclassName( int aRow, const wxString& aNa if( ii != aRow && m_netclassGrid->GetCellValue( ii, GRID_NAME ).CmpNoCase( tmp ) == 0 ) { wxString msg = _( "Netclass name already in use." ); - m_parent->SetError( msg, this, m_netclassGrid, focusFirst ? aRow : ii, GRID_NAME ); + PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_netclassGrid, + focusFirst ? aRow : ii, GRID_NAME ); return false; } } diff --git a/common/dialogs/panel_setup_severities.cpp b/common/dialogs/panel_setup_severities.cpp index bfd5446187..6bdc4bd6e5 100644 --- a/common/dialogs/panel_setup_severities.cpp +++ b/common/dialogs/panel_setup_severities.cpp @@ -28,14 +28,13 @@ #include #include #include -#include -PANEL_SETUP_SEVERITIES::PANEL_SETUP_SEVERITIES( PAGED_DIALOG* aParent, +PANEL_SETUP_SEVERITIES::PANEL_SETUP_SEVERITIES( wxWindow* aParentWindow, std::vector> aItems, std::map& aSeverities, RC_ITEM* aPinMapSpecialCase ) : - wxPanel( aParent->GetTreebook() ), + wxPanel( aParentWindow ), m_severities( aSeverities ), m_items( aItems ), m_pinMapSpecialCase( aPinMapSpecialCase ) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index c0b250063f..6193910ec7 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -56,12 +56,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include @@ -1012,23 +1012,42 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent PAGED_DIALOG dlg( this, _( "Preferences" ), true ); dlg.SetEvtHandlerEnabled( false ); - wxTreebook* book = dlg.GetTreebook(); + WX_TREEBOOK* book = dlg.GetTreebook(); PANEL_HOTKEYS_EDITOR* hotkeysPanel = new PANEL_HOTKEYS_EDITOR( this, book, false ); KIFACE* kiface = nullptr; std::vector expand; Kiway().GetActions( hotkeysPanel->ActionsList() ); - book->AddPage( new PANEL_COMMON_SETTINGS( &dlg, book ), _( "Common" ) ); - book->AddPage( new PANEL_MOUSE_SETTINGS( &dlg, book ), _( "Mouse and Touchpad" ) ); + book->AddLazyPage( + []( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_COMMON_SETTINGS( aParent ); + }, + _( "Common" ) ); + + book->AddLazyPage( + []( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_MOUSE_SETTINGS( aParent ); + }, _( "Mouse and Touchpad" ) ); + book->AddPage( hotkeysPanel, _( "Hotkeys" ) ); #ifdef KICAD_USE_SENTRY - book->AddPage( new PANEL_DATA_COLLECTION( &dlg, book ), _( "Data Collection" ) ); + book->AddLazyPage( + []( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_DATA_COLLECTION( aParent ); + }, _( "Data Collection" ) ); #endif -#define CREATE_PANEL( key ) kiface->CreateKiWindow( book, key, &Kiway() ) +#define LAZY_CTOR( key ) \ + [=]( wxWindow* aParent ) \ + { \ + return kiface->CreateKiWindow( aParent, key, &Kiway() ); \ + } // If a dll is not loaded, the loader will show an error message. @@ -1042,20 +1061,19 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent expand.push_back( book->GetPageCount() ); book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_SYM_DISP_OPTIONS ), _( "Display Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_SYM_EDIT_OPTIONS ), _( "Editing Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_SYM_COLORS ), _( "Colors" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_DISP_OPTIONS ), _( "Display Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_EDIT_OPTIONS ), _( "Editing Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_SYM_COLORS ), _( "Colors" ) ); if( GetFrameType() == FRAME_SCH ) expand.push_back( book->GetPageCount() ); book->AddPage( new wxPanel( book ), _( "Schematic Editor" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_SCH_DISP_OPTIONS ), _( "Display Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_SCH_EDIT_OPTIONS ), _( "Editing Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_SCH_ANNO_OPTIONS ), _( "Annotation Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_SCH_COLORS ), _( "Colors" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_SCH_FIELD_NAME_TEMPLATES ), - _( "Field Name Templates" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_DISP_OPTIONS ), _( "Display Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_EDIT_OPTIONS ), _( "Editing Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_ANNO_OPTIONS ), _( "Annotation Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_COLORS ), _( "Colors" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_SCH_FIELD_NAME_TEMPLATES ), _( "Field Name Templates" ) ); } catch( ... ) { @@ -1071,29 +1089,29 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent expand.push_back( book->GetPageCount() ); book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_FP_DISPLAY_OPTIONS ), _( "Display Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_FP_COLORS ), _( "Colors" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_FP_DEFAULT_VALUES ), _( "Default Values" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DISPLAY_OPTIONS ), _( "Display Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_FP_COLORS ), _( "Colors" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_VALUES ), _( "Default Values" ) ); if( GetFrameType() == FRAME_PCB_EDITOR ) expand.push_back( book->GetPageCount() ); book->AddPage( new wxPanel( book ), _( "PCB Editor" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_PCB_DISPLAY_OPTIONS ), _( "Display Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_PCB_EDIT_OPTIONS ), _( "Editing Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_PCB_COLORS ), _( "Colors" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_PCB_ACTION_PLUGINS ), _( "Action Plugins" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_DISPLAY_OPTIONS ), _( "Display Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_EDIT_OPTIONS ), _( "Editing Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_COLORS ), _( "Colors" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ACTION_PLUGINS ), _( "Action Plugins" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) ); if( GetFrameType() == FRAME_PCB_DISPLAY3D ) expand.push_back( book->GetPageCount() ); book->AddPage( new wxPanel( book ), _( "3D Viewer" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_3DV_OPENGL ), _( "Realtime Renderer" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_3DV_RAYTRACING ), _( "Raytracing Renderer" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_3DV_COLORS ), _( "Colors" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_OPENGL ), _( "Realtime Renderer" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_RAYTRACING ), _( "Raytracing Renderer" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_3DV_COLORS ), _( "Colors" ) ); } catch( ... ) { @@ -1109,9 +1127,9 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent expand.push_back( book->GetPageCount() ); book->AddPage( new wxPanel( book ), _( "Gerber Viewer" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_GBR_COLORS ), _( "Colors" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_GBR_EXCELLON_OPTIONS ), _( "Excellon Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_COLORS ), _( "Colors" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_GBR_EXCELLON_OPTIONS ), _( "Excellon Options" ) ); } catch( ... ) { @@ -1126,10 +1144,14 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent expand.push_back( book->GetPageCount() ); book->AddPage( new wxPanel( book ), _( "Drawing Sheet Editor" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_DS_DISPLAY_OPTIONS ), _( "Display Options" ) ); - book->AddSubPage( CREATE_PANEL( PANEL_DS_COLORS ), _( "Colors" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_DS_DISPLAY_OPTIONS ), _( "Display Options" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_DS_COLORS ), _( "Colors" ) ); - book->AddPage( new PANEL_PCM_SETTINGS( book ), _( "Plugin and Content Manager" ) ); + book->AddLazyPage( + []( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_PCM_SETTINGS( aParent ); + }, _( "Plugin and Content Manager" ) ); } catch( ... ) { @@ -1157,7 +1179,7 @@ void EDA_BASE_FRAME::ShowPreferences( wxString aStartPage, wxString aStartParent dlg.Kiway().CommonSettingsChanged( false, false ); } -#undef CREATE_PANEL +#undef LAZY_CTOR } diff --git a/common/widgets/paged_dialog.cpp b/common/widgets/paged_dialog.cpp index 6fc5ede601..ceb78ff91e 100644 --- a/common/widgets/paged_dialog.cpp +++ b/common/widgets/paged_dialog.cpp @@ -19,19 +19,20 @@ #include #include +#include +#include +#include +#include + #include #include #include #include #include - -#include -#include +#include #include #include -#include "wx/listctrl.h" -#include "widgets/wx_panel.h" // Maps from dialogTitle <-> pageTitle for keeping track of last-selected pages. // This is not a simple page index because some dialogs have dynamic page sets. @@ -60,7 +61,7 @@ PAGED_DIALOG::PAGED_DIALOG( wxWindow* aParent, const wxString& aTitle, bool aSho wxBoxSizer* treebookSizer = new wxBoxSizer( wxVERTICAL ); treebookPanel->SetSizer( treebookSizer ); - m_treebook = new wxTreebook( treebookPanel, wxID_ANY ); + m_treebook = new WX_TREEBOOK( treebookPanel, wxID_ANY ); m_treebook->SetFont( KIUI::GetControlFont( this ) ); long treeCtrlFlags = m_treebook->GetTreeCtrl()->GetWindowStyleFlag(); @@ -269,6 +270,20 @@ bool PAGED_DIALOG::TransferDataFromWindow() } +PAGED_DIALOG* PAGED_DIALOG::GetDialog( wxWindow* aParent ) +{ + while( aParent ) + { + if( PAGED_DIALOG* parentDialog = dynamic_cast( aParent ) ) + return parentDialog; + + aParent = aParent->GetParent(); + } + + return nullptr; +} + + void PAGED_DIALOG::SetError( const wxString& aMessage, const wxString& aPageName, int aCtrlId, int aRow, int aCol ) { @@ -279,39 +294,36 @@ void PAGED_DIALOG::SetError( const wxString& aMessage, const wxString& aPageName void PAGED_DIALOG::SetError( const wxString& aMessage, wxWindow* aPage, wxWindow* aCtrl, int aRow, int aCol ) { - if( aCtrl ) + m_infoBar->ShowMessageFor( aMessage, 10000, wxICON_WARNING ); + + if( wxTextCtrl* textCtrl = dynamic_cast( aCtrl ) ) { - m_infoBar->ShowMessageFor( aMessage, 10000, wxICON_WARNING ); + textCtrl->SetSelection( -1, -1 ); + textCtrl->SetFocus(); + return; + } - if( wxTextCtrl* textCtrl = dynamic_cast( aCtrl ) ) + if( wxStyledTextCtrl* scintilla = dynamic_cast( aCtrl ) ) + { + if( aRow > 0 ) { - textCtrl->SetSelection( -1, -1 ); - textCtrl->SetFocus(); - return; + int pos = scintilla->PositionFromLine( aRow - 1 ) + ( aCol - 1 ); + scintilla->GotoPos( pos ); } - if( wxStyledTextCtrl* scintilla = dynamic_cast( aCtrl ) ) - { - if( aRow > 0 ) - { - int pos = scintilla->PositionFromLine( aRow - 1 ) + ( aCol - 1 ); - scintilla->GotoPos( pos ); - } + scintilla->SetFocus(); + return; + } - scintilla->SetFocus(); - return; - } + if( wxGrid* grid = dynamic_cast( aCtrl ) ) + { + grid->SetFocus(); + grid->MakeCellVisible( aRow, aCol ); + grid->SetGridCursor( aRow, aCol ); - if( wxGrid* grid = dynamic_cast( aCtrl ) ) - { - grid->SetFocus(); - grid->MakeCellVisible( aRow, aCol ); - grid->SetGridCursor( aRow, aCol ); - - grid->EnableCellEditControl( true ); - grid->ShowCellEditControl(); - return; - } + grid->EnableCellEditControl( true ); + grid->ShowCellEditControl(); + return; } } diff --git a/common/widgets/wx_treebook.cpp b/common/widgets/wx_treebook.cpp new file mode 100644 index 0000000000..bc4f32ba05 --- /dev/null +++ b/common/widgets/wx_treebook.cpp @@ -0,0 +1,101 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 Free Software Foundation; either version 3 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * 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 +#include +#include + + +class LAZY_PAGE : public wxPanel +{ +public: + LAZY_PAGE( wxWindow* aParent, std::function aLazyCtor ) : + wxPanel( aParent, wxID_ANY ), + m_lazyCtor( std::move( aLazyCtor ) ), + m_mainSizer( nullptr ), + m_contents( nullptr ) + { + m_mainSizer = new wxBoxSizer( wxVERTICAL ); + SetSizer( m_mainSizer ); + } + + wxWindow* Resolve() + { + if( !m_contents ) + { + m_contents = m_lazyCtor( this ); + m_mainSizer->Add( m_contents, 1, wxEXPAND, 5 ); + m_mainSizer->Layout(); + + m_contents->TransferDataToWindow(); + } + + return m_contents; + } + + bool Show( bool show ) override + { + if( show ) + Resolve(); + + return wxPanel::Show( show ); + } + +private: + std::function m_lazyCtor; + + wxSizer* m_mainSizer; + wxWindow* m_contents; +}; + + +WX_TREEBOOK::WX_TREEBOOK( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, + long style, const wxString& name ) : + wxTreebook( parent, id, pos, size, style, name ) +{ +} + + +bool WX_TREEBOOK::AddLazyPage( std::function aLazyCtor, + const wxString& text, bool bSelect, int imageId ) +{ + return AddPage( new LAZY_PAGE( this, std::move( aLazyCtor ) ), text, bSelect, imageId ); +} + + +bool WX_TREEBOOK::AddLazySubPage( std::function aLazyCtor, + const wxString& text, bool bSelect, int imageId ) +{ + return AddSubPage( new LAZY_PAGE( this, std::move( aLazyCtor ) ), text, bSelect, imageId ); +} + + +wxWindow* WX_TREEBOOK::ResolvePage( int aPage ) +{ + wxWindow* page = GetPage( aPage ); + + if( LAZY_PAGE* lazyPage = dynamic_cast( page ) ) + return lazyPage->Resolve(); + + return page; +} diff --git a/eeschema/dialogs/panel_eeschema_display_options_base.cpp b/eeschema/dialogs/panel_eeschema_display_options_base.cpp index 12b79465c5..7d97b9ab74 100644 --- a/eeschema/dialogs/panel_eeschema_display_options_base.cpp +++ b/eeschema/dialogs/panel_eeschema_display_options_base.cpp @@ -29,7 +29,7 @@ PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE::PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE( wxWind bRightColumn->Add( m_appearanceLabel, 0, wxTOP|wxRIGHT|wxLEFT, 13 ); m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bRightColumn->Add( m_staticline1, 0, wxEXPAND|wxBOTTOM, 5 ); + bRightColumn->Add( m_staticline1, 0, wxEXPAND|wxBOTTOM, 7 ); wxBoxSizer* bAppearanceSizer; bAppearanceSizer = new wxBoxSizer( wxVERTICAL ); @@ -48,7 +48,7 @@ PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE::PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE( wxWind bSizer4->Add( m_defaultFontCtrl, 0, wxALIGN_CENTER_VERTICAL, 5 ); - bAppearanceSizer->Add( bSizer4, 1, wxEXPAND|wxTOP, 5 ); + bAppearanceSizer->Add( bSizer4, 1, wxEXPAND, 5 ); m_checkShowHiddenPins = new wxCheckBox( this, wxID_ANY, _("S&how hidden pins"), wxDefaultPosition, wxDefaultSize, 0 ); bAppearanceSizer->Add( m_checkShowHiddenPins, 0, wxEXPAND|wxALL, 5 ); @@ -79,20 +79,20 @@ PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE::PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE( wxWind bRightColumn->Add( bAppearanceSizer, 0, wxEXPAND|wxTOP|wxLEFT, 5 ); - bRightColumn->Add( 0, 15, 0, wxEXPAND, 5 ); + bRightColumn->Add( 0, 7, 0, wxEXPAND, 5 ); m_selectionLabel = new wxStaticText( this, wxID_ANY, _("Selection && Highlighting"), wxDefaultPosition, wxDefaultSize, 0 ); m_selectionLabel->Wrap( -1 ); bRightColumn->Add( m_selectionLabel, 0, wxTOP|wxRIGHT|wxLEFT|wxEXPAND, 13 ); m_staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bRightColumn->Add( m_staticline2, 0, wxEXPAND|wxBOTTOM, 5 ); + bRightColumn->Add( m_staticline2, 0, wxEXPAND|wxBOTTOM, 7 ); wxBoxSizer* bSelectionSizer; bSelectionSizer = new wxBoxSizer( wxVERTICAL ); m_checkSelDrawChildItems = new wxCheckBox( this, wxID_ANY, _("Draw selected child items"), wxDefaultPosition, wxDefaultSize, 0 ); - bSelectionSizer->Add( m_checkSelDrawChildItems, 0, wxEXPAND|wxALL, 5 ); + bSelectionSizer->Add( m_checkSelDrawChildItems, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_checkSelFillShapes = new wxCheckBox( this, wxID_ANY, _("Fill selected shapes"), wxDefaultPosition, wxDefaultSize, 0 ); bSelectionSizer->Add( m_checkSelFillShapes, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); @@ -130,14 +130,14 @@ PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE::PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE( wxWind bRightColumn->Add( bSelectionSizer, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); - bRightColumn->Add( 0, 15, 0, wxEXPAND, 5 ); + bRightColumn->Add( 0, 7, 0, wxEXPAND, 5 ); m_crossprobeLabel = new wxStaticText( this, wxID_ANY, _("Cross-probing"), wxDefaultPosition, wxDefaultSize, 0 ); m_crossprobeLabel->Wrap( -1 ); bRightColumn->Add( m_crossprobeLabel, 0, wxTOP|wxRIGHT|wxLEFT|wxEXPAND, 13 ); m_staticline3 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); - bRightColumn->Add( m_staticline3, 0, wxEXPAND|wxBOTTOM, 5 ); + bRightColumn->Add( m_staticline3, 0, wxEXPAND|wxBOTTOM, 7 ); wxBoxSizer* bCrossProbingSizer; bCrossProbingSizer = new wxBoxSizer( wxVERTICAL ); @@ -146,7 +146,7 @@ PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE::PANEL_EESCHEMA_DISPLAY_OPTIONS_BASE( wxWind m_checkCrossProbeOnSelection->SetValue(true); m_checkCrossProbeOnSelection->SetToolTip( _("Highlight symbols corresponding to selected footprints") ); - bCrossProbingSizer->Add( m_checkCrossProbeOnSelection, 0, wxALL, 5 ); + bCrossProbingSizer->Add( m_checkCrossProbeOnSelection, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_checkCrossProbeCenter = new wxCheckBox( this, wxID_ANY, _("Center view on cross-probed items"), wxDefaultPosition, wxDefaultSize, 0 ); m_checkCrossProbeCenter->SetValue(true); diff --git a/eeschema/dialogs/panel_eeschema_display_options_base.fbp b/eeschema/dialogs/panel_eeschema_display_options_base.fbp index 2b59a947b5..eca2c87e89 100644 --- a/eeschema/dialogs/panel_eeschema_display_options_base.fbp +++ b/eeschema/dialogs/panel_eeschema_display_options_base.fbp @@ -139,7 +139,7 @@ - 5 + 7 wxEXPAND|wxBOTTOM 0 @@ -207,7 +207,7 @@ none 5 - wxEXPAND|wxTOP + wxEXPAND 1 @@ -860,7 +860,7 @@ wxEXPAND 0 - 15 + 7 protected 0 @@ -927,7 +927,7 @@ - 5 + 7 wxEXPAND|wxBOTTOM 0 @@ -995,7 +995,7 @@ none 5 - wxEXPAND|wxALL + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT 0 1 @@ -1471,7 +1471,7 @@ wxEXPAND 0 - 15 + 7 protected 0 @@ -1538,7 +1538,7 @@ - 5 + 7 wxEXPAND|wxBOTTOM 0 @@ -1606,7 +1606,7 @@ none 5 - wxALL + wxBOTTOM|wxRIGHT|wxLEFT 0 1 diff --git a/include/dialogs/panel_common_settings.h b/include/dialogs/panel_common_settings.h index ebf741f82e..094dfe7fbc 100644 --- a/include/dialogs/panel_common_settings.h +++ b/include/dialogs/panel_common_settings.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-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 @@ -35,7 +35,7 @@ class STEPPED_SLIDER; class PANEL_COMMON_SETTINGS : public PANEL_COMMON_SETTINGS_BASE { public: - PANEL_COMMON_SETTINGS( DIALOG_SHIM* aDialog, wxWindow* aParent ); + PANEL_COMMON_SETTINGS( wxWindow* aParent ); ~PANEL_COMMON_SETTINGS() override; void ResetPanel() override; @@ -66,8 +66,6 @@ private: void setPdfViewerPathState(); protected: - DIALOG_SHIM* m_dialog; - wxStaticText* m_iconScaleLabel; STEPPED_SLIDER* m_iconScaleSlider; wxCheckBox* m_iconScaleAuto; diff --git a/include/dialogs/panel_data_collection.h b/include/dialogs/panel_data_collection.h index 39d9dc1a61..21e986f6a7 100644 --- a/include/dialogs/panel_data_collection.h +++ b/include/dialogs/panel_data_collection.h @@ -34,7 +34,7 @@ class PAGED_DIALOG; class PANEL_DATA_COLLECTION : public PANEL_DATA_COLLECTION_BASE { public: - PANEL_DATA_COLLECTION( PAGED_DIALOG* aDialog, wxWindow* aParent ); + PANEL_DATA_COLLECTION( wxWindow* aParent ); void ResetPanel() override; @@ -46,9 +46,6 @@ protected: private: void applySettingsToPanel(); - -protected: - PAGED_DIALOG* m_dialog; }; #endif //PANEL_DATA_COLLECTION_H diff --git a/include/dialogs/panel_mouse_settings.h b/include/dialogs/panel_mouse_settings.h index 0617599936..4352f94231 100644 --- a/include/dialogs/panel_mouse_settings.h +++ b/include/dialogs/panel_mouse_settings.h @@ -39,7 +39,7 @@ struct SCROLL_MOD_SET class PANEL_MOUSE_SETTINGS : public PANEL_MOUSE_SETTINGS_BASE { public: - PANEL_MOUSE_SETTINGS( PAGED_DIALOG* aDialog, wxWindow* aParent ); + PANEL_MOUSE_SETTINGS( wxWindow* aParent ); ~PANEL_MOUSE_SETTINGS(); @@ -63,9 +63,6 @@ private: bool isScrollModSetValid( const SCROLL_MOD_SET& aSet ); -protected: - PAGED_DIALOG* m_dialog; - private: SCROLL_MOD_SET m_currentScrollMod; }; diff --git a/include/dialogs/panel_setup_netclasses.h b/include/dialogs/panel_setup_netclasses.h index 7652af08d8..44daaa11ab 100644 --- a/include/dialogs/panel_setup_netclasses.h +++ b/include/dialogs/panel_setup_netclasses.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-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 @@ -35,7 +35,7 @@ class NET_SETTINGS; class PANEL_SETUP_NETCLASSES : public PANEL_SETUP_NETCLASSES_BASE { public: - PANEL_SETUP_NETCLASSES( PAGED_DIALOG* aParent, EDA_DRAW_FRAME* aFrame, + PANEL_SETUP_NETCLASSES( wxWindow* aParentWindow, EDA_DRAW_FRAME* aFrame, std::shared_ptr aSettings, const std::set& aNetNames, bool isEEschema ); ~PANEL_SETUP_NETCLASSES( ) override; @@ -69,7 +69,6 @@ private: private: EDA_DRAW_FRAME* m_frame; - PAGED_DIALOG* m_parent; bool m_isEEschema; std::shared_ptr m_netSettings; std::set m_netNames; diff --git a/include/dialogs/panel_setup_severities.h b/include/dialogs/panel_setup_severities.h index 698af0df63..acf0435eec 100644 --- a/include/dialogs/panel_setup_severities.h +++ b/include/dialogs/panel_setup_severities.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020 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 @@ -50,12 +50,11 @@ private: public: /** * Creates the severities setup panel - * @param aParent is the dialog parent * @param aItems is a list of error types that can have a severity. Must have one or more! * @param aSeverities is a map of error code to severity * @param aPinMapSpecialCase is used to special-case the ERCE_PIN_TO_PIN_WARNING */ - PANEL_SETUP_SEVERITIES( PAGED_DIALOG* aParent, + PANEL_SETUP_SEVERITIES( wxWindow* aParentWindow, std::vector> aItems, std::map& aSeverities, RC_ITEM* aPinMapSpecialCase = nullptr ); diff --git a/include/widgets/paged_dialog.h b/include/widgets/paged_dialog.h index 80aa4ae5f8..ecdcb786de 100644 --- a/include/widgets/paged_dialog.h +++ b/include/widgets/paged_dialog.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-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 @@ -22,10 +22,11 @@ #define PAGED_DIALOG_H #include +#include class WX_INFOBAR; -class wxTreebook; +class WX_TREEBOOK; class PAGED_DIALOG : public DIALOG_SHIM { @@ -34,7 +35,7 @@ public: const wxString& aAuxiliaryAction = wxEmptyString ); ~PAGED_DIALOG() override; - wxTreebook* GetTreebook() { return m_treebook; } + WX_TREEBOOK* GetTreebook() { return m_treebook; } void SetInitialPage( const wxString& aPage, const wxString& aParentPage = wxEmptyString ); @@ -48,6 +49,8 @@ public: void UpdateResetButton( int aPage ); + static PAGED_DIALOG* GetDialog( wxWindow* aWindow ); + protected: void finishInitialization(); @@ -60,11 +63,11 @@ protected: virtual void onPageChanging( wxBookCtrlEvent& aEvent ); virtual void onCharHook( wxKeyEvent& aEvent ); - wxTreebook* m_treebook; - wxButton* m_auxiliaryButton; - wxButton* m_resetButton; - wxButton* m_cancelButton; - WX_INFOBAR* m_infoBar; + WX_TREEBOOK* m_treebook; + wxButton* m_auxiliaryButton; + wxButton* m_resetButton; + wxButton* m_cancelButton; + WX_INFOBAR* m_infoBar; private: wxString m_title; diff --git a/include/widgets/wx_treebook.h b/include/widgets/wx_treebook.h new file mode 100644 index 0000000000..7d353888eb --- /dev/null +++ b/include/widgets/wx_treebook.h @@ -0,0 +1,46 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 Free Software Foundation; either version 3 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * 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 + */ + +#ifndef WX_TREEBOOK_H +#define WX_TREEBOOK_H + +#include + +class WX_TREEBOOK : public wxTreebook +{ +public: + WX_TREEBOOK( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = wxBK_DEFAULT, + const wxString& name = wxEmptyString ); + + bool AddLazyPage( std::function aLazyCtor, + const wxString& text, bool bSelect = false, int imageId = NO_IMAGE ); + + bool AddLazySubPage( std::function aLazyCtor, + const wxString& text, bool bSelect = false, int imageId = NO_IMAGE ); + + wxWindow* ResolvePage( int aPage ); +}; + + +#endif // WX_TREEBOOK_H diff --git a/pagelayout_editor/dialogs/panel_pl_editor_color_settings.cpp b/pagelayout_editor/dialogs/panel_pl_editor_color_settings.cpp index e46852eaa7..f6ed4bbf7a 100644 --- a/pagelayout_editor/dialogs/panel_pl_editor_color_settings.cpp +++ b/pagelayout_editor/dialogs/panel_pl_editor_color_settings.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2021 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 @@ -62,12 +62,14 @@ bool PANEL_PL_EDITOR_COLOR_SETTINGS::TransferDataToWindow() bool PANEL_PL_EDITOR_COLOR_SETTINGS::TransferDataFromWindow() { - SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); - PL_EDITOR_SETTINGS* cfg = mgr.GetAppSettings(); - int sel = m_themes->GetSelection(); - COLOR_SETTINGS* colors = static_cast( m_themes->GetClientData( sel ) ); + int sel = m_themes->GetSelection(); - cfg->m_ColorTheme = colors->GetFilename(); + if( sel >= 0 ) + { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + COLOR_SETTINGS* colors = static_cast( m_themes->GetClientData( sel ) ); + mgr.GetAppSettings()->m_ColorTheme = colors->GetFilename(); + } return true; } diff --git a/pcbnew/dialogs/dialog_board_setup.cpp b/pcbnew/dialogs/dialog_board_setup.cpp index 14fcbd6415..f7aaacc754 100644 --- a/pcbnew/dialogs/dialog_board_setup.cpp +++ b/pcbnew/dialogs/dialog_board_setup.cpp @@ -38,12 +38,12 @@ #include #include #include +#include #include #include "dialog_board_setup.h" #include "panel_setup_rules.h" -#include std::mutex DIALOG_BOARD_SETUP::g_Mutex; @@ -54,27 +54,12 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : m_frame( aFrame ) { SetEvtHandlerEnabled( false ); - PROJECT_FILE& project = aFrame->Prj().GetProjectFile(); - BOARD* board = aFrame->GetBoard(); - BOARD_DESIGN_SETTINGS& bds = board->GetDesignSettings(); - m_layers = new PANEL_SETUP_LAYERS( this, aFrame ); - m_textAndGraphics = new PANEL_SETUP_TEXT_AND_GRAPHICS( this, aFrame ); - m_formatting = new PANEL_SETUP_FORMATTING( this, aFrame ); - m_constraints = new PANEL_SETUP_CONSTRAINTS( this, aFrame ); - m_rules = new PANEL_SETUP_RULES( this, aFrame ); - m_tracksAndVias = new PANEL_SETUP_TRACKS_AND_VIAS( this, aFrame ); - m_maskAndPaste = new PANEL_SETUP_MASK_AND_PASTE( this, aFrame ); - m_physicalStackup = new PANEL_SETUP_BOARD_STACKUP( this, aFrame, m_layers ); - m_boardFinish = new PANEL_SETUP_BOARD_FINISH( this, aFrame ); + m_layers = new PANEL_SETUP_LAYERS( this, m_frame ); + m_physicalStackup = new PANEL_SETUP_BOARD_STACKUP( this, m_frame, m_layers ); + m_boardFinish = new PANEL_SETUP_BOARD_FINISH( this, m_frame ); - m_severities = new PANEL_SETUP_SEVERITIES( this, DRC_ITEM::GetItemsWithSeverities(), - bds.m_DRCSeverities ); - - m_netclasses = new PANEL_SETUP_NETCLASSES( this, aFrame, project.NetSettings(), - board->GetNetClassAssignmentCandidates(), false ); - - m_textVars = new PANEL_TEXT_VARIABLES( m_treebook, &Prj() ); + m_currentPage = -1; /* * WARNING: If you change page names you MUST update calls to ShowBoardSetupDialog(). @@ -82,8 +67,6 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Board Stackup" ) ); - m_currentPage = -1; - /* * WARNING: Code currently relies on the layers setup coming before the physical stackup panel, * and thus transferring data to the board first. See comment in @@ -91,27 +74,81 @@ DIALOG_BOARD_SETUP::DIALOG_BOARD_SETUP( PCB_EDIT_FRAME* aFrame ) : * that the order of these pages should be changed. */ m_treebook->AddSubPage( m_layers, _( "Board Editor Layers" ) ); - m_layerSetupPage = 1; + m_physicalStackupPage = m_treebook->GetPageCount(); m_treebook->AddSubPage( m_physicalStackup, _( "Physical Stackup" ) ); - - // Change this value if m_physicalStackup is not the page 2 of m_treebook - m_physicalStackupPage = 2; // The page number (from 0) to select the m_physicalStackup panel - m_treebook->AddSubPage( m_boardFinish, _( "Board Finish" ) ); - m_treebook->AddSubPage( m_maskAndPaste, _( "Solder Mask/Paste" ) ); + + m_maskAndPagePage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_MASK_AND_PASTE( aParent, m_frame ); + }, _( "Solder Mask/Paste" ) ); m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Text & Graphics" ) ); - m_treebook->AddSubPage( m_textAndGraphics, _( "Defaults" ) ); - m_treebook->AddSubPage( m_formatting, _( "Formatting" ) ); - m_treebook->AddSubPage( m_textVars, _( "Text Variables" ) ); + + m_textAndGraphicsPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_TEXT_AND_GRAPHICS( aParent, m_frame ); + }, _( "Defaults" ) ); + + m_formattingPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_FORMATTING( aParent, m_frame ); + }, _( "Formatting" ) ); + + m_textVarsPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_TEXT_VARIABLES( aParent, &Prj() ); + }, _( "Text Variables" ) ); m_treebook->AddPage( new wxPanel( GetTreebook() ), _( "Design Rules" ) ); - m_treebook->AddSubPage( m_constraints, _( "Constraints" ) ); - m_treebook->AddSubPage( m_tracksAndVias, _( "Pre-defined Sizes" ) ); - m_treebook->AddSubPage( m_netclasses, _( "Net Classes" ) ); - m_treebook->AddSubPage( m_rules, _( "Custom Rules" ) ); - m_treebook->AddSubPage( m_severities, _( "Violation Severity" ) ); + + m_constraintsPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_CONSTRAINTS( aParent, m_frame ); + }, _( "Constraints" ) ); + + m_tracksAndViasPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_TRACKS_AND_VIAS( aParent, m_frame ); + }, _( "Pre-defined Sizes" ) ); + + m_netclassesPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_NETCLASSES( aParent, m_frame, + m_frame->Prj().GetProjectFile().NetSettings(), + m_frame->GetBoard()->GetNetClassAssignmentCandidates(), + false ); + }, _( "Net Classes" ) ); + + m_rulesPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_RULES( aParent, m_frame ); + }, _( "Custom Rules" ) ); + + m_severitiesPage = m_treebook->GetPageCount(); + m_treebook->AddLazySubPage( + [this]( wxWindow* aParent ) -> wxWindow* + { + return new PANEL_SETUP_SEVERITIES( aParent, DRC_ITEM::GetItemsWithSeverities(), + m_frame->GetBoard()->GetDesignSettings().m_DRCSeverities ); + }, _( "Violation Severity" ) ); for( size_t i = 0; i < m_treebook->GetPageCount(); ++i ) m_treebook->ExpandNode( i ); @@ -245,25 +282,46 @@ void DIALOG_BOARD_SETUP::onAuxiliaryAction( wxCommandEvent& aEvent ) } if( importDlg.m_TextAndGraphicsOpt->GetValue() ) - m_textAndGraphics->ImportSettingsFrom( otherBoard ); + { + static_cast( m_treebook->ResolvePage( m_textAndGraphicsPage ) ) + ->ImportSettingsFrom( otherBoard ); + } if( importDlg.m_FormattingOpt->GetValue() ) - m_formatting->ImportSettingsFrom( otherBoard ); + { + static_cast( m_treebook->ResolvePage( m_formattingPage ) ) + ->ImportSettingsFrom( otherBoard ); + } if( importDlg.m_ConstraintsOpt->GetValue() ) - m_constraints->ImportSettingsFrom( otherBoard ); + { + static_cast( m_treebook->ResolvePage( m_constraintsPage ) ) + ->ImportSettingsFrom( otherBoard ); + } if( importDlg.m_NetclassesOpt->GetValue() ) - m_netclasses->ImportSettingsFrom( otherPrj->GetProjectFile().m_NetSettings ); + { + static_cast( m_treebook->ResolvePage( m_netclassesPage ) ) + ->ImportSettingsFrom( otherPrj->GetProjectFile().m_NetSettings ); + } if( importDlg.m_TracksAndViasOpt->GetValue() ) - m_tracksAndVias->ImportSettingsFrom( otherBoard ); + { + static_cast( m_treebook->ResolvePage( m_tracksAndViasPage ) ) + ->ImportSettingsFrom( otherBoard ); + } if( importDlg.m_MaskAndPasteOpt->GetValue() ) - m_maskAndPaste->ImportSettingsFrom( otherBoard ); + { + static_cast( m_treebook->ResolvePage( m_maskAndPagePage ) ) + ->ImportSettingsFrom( otherBoard ); + } if( importDlg.m_SeveritiesOpt->GetValue() ) - m_severities->ImportSettingsFrom( otherBoard->GetDesignSettings().m_DRCSeverities ); + { + static_cast( m_treebook->ResolvePage( m_severitiesPage ) ) + ->ImportSettingsFrom( otherBoard->GetDesignSettings().m_DRCSeverities ); + } if( otherPrj != &m_frame->Prj() ) otherBoard->ClearProject(); diff --git a/pcbnew/dialogs/dialog_board_setup.h b/pcbnew/dialogs/dialog_board_setup.h index 934125972c..ab0829b6bf 100644 --- a/pcbnew/dialogs/dialog_board_setup.h +++ b/pcbnew/dialogs/dialog_board_setup.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2017-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 @@ -52,26 +52,25 @@ protected: PCB_EDIT_FRAME* m_frame; - PANEL_SETUP_CONSTRAINTS* m_constraints; PANEL_SETUP_LAYERS* m_layers; - PANEL_SETUP_TEXT_AND_GRAPHICS* m_textAndGraphics; - PANEL_SETUP_FORMATTING* m_formatting; - PANEL_SETUP_NETCLASSES* m_netclasses; - PANEL_SETUP_RULES* m_rules; - PANEL_SETUP_TRACKS_AND_VIAS* m_tracksAndVias; - PANEL_SETUP_MASK_AND_PASTE* m_maskAndPaste; PANEL_SETUP_BOARD_STACKUP* m_physicalStackup; PANEL_SETUP_BOARD_FINISH* m_boardFinish; - PANEL_SETUP_SEVERITIES* m_severities; - PANEL_TEXT_VARIABLES* m_textVars; public: static std::mutex g_Mutex; // Mutex to prevent multiple windows opening private: int m_currentPage; // the current page index - int m_physicalStackupPage; // the page index of the PANEL_SETUP_BOARD_STACKUP page - int m_layerSetupPage; // the page index of the PANEL_SETUP_LAYERS page + 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; }; diff --git a/pcbnew/dialogs/panel_setup_constraints.cpp b/pcbnew/dialogs/panel_setup_constraints.cpp index 9818c4c03c..2db0f29235 100644 --- a/pcbnew/dialogs/panel_setup_constraints.cpp +++ b/pcbnew/dialogs/panel_setup_constraints.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-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 @@ -32,8 +32,8 @@ #include -PANEL_SETUP_CONSTRAINTS::PANEL_SETUP_CONSTRAINTS( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ) : - PANEL_SETUP_CONSTRAINTS_BASE( aParent->GetTreebook() ), +PANEL_SETUP_CONSTRAINTS::PANEL_SETUP_CONSTRAINTS( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ) : + PANEL_SETUP_CONSTRAINTS_BASE( aParentWindow ), m_minClearance( aFrame, m_clearanceTitle, m_clearanceCtrl, m_clearanceUnits ), m_minConn( aFrame, m_MinConnTitle, m_MinConnCtrl, m_MinConnUnits ), m_trackMinWidth( aFrame, m_TrackMinWidthTitle, m_TrackMinWidthCtrl, m_TrackMinWidthUnits ), diff --git a/pcbnew/dialogs/panel_setup_constraints.h b/pcbnew/dialogs/panel_setup_constraints.h index 1cb0b2c5e9..28d2b147a5 100644 --- a/pcbnew/dialogs/panel_setup_constraints.h +++ b/pcbnew/dialogs/panel_setup_constraints.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-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 @@ -38,7 +38,7 @@ class wxCommandEvent; class PANEL_SETUP_CONSTRAINTS : public PANEL_SETUP_CONSTRAINTS_BASE { public: - PANEL_SETUP_CONSTRAINTS( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ); + PANEL_SETUP_CONSTRAINTS( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ); ~PANEL_SETUP_CONSTRAINTS( ) override { }; void ImportSettingsFrom( BOARD* aBoard ); diff --git a/pcbnew/dialogs/panel_setup_formatting.cpp b/pcbnew/dialogs/panel_setup_formatting.cpp index e7dd0921d4..729650033b 100644 --- a/pcbnew/dialogs/panel_setup_formatting.cpp +++ b/pcbnew/dialogs/panel_setup_formatting.cpp @@ -30,8 +30,8 @@ #include -PANEL_SETUP_FORMATTING::PANEL_SETUP_FORMATTING( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ) : - PANEL_SETUP_FORMATTING_BASE( aParent->GetTreebook() ), +PANEL_SETUP_FORMATTING::PANEL_SETUP_FORMATTING( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ) : + PANEL_SETUP_FORMATTING_BASE( aParentWindow ), m_frame( aFrame ) { wxSize minSize = m_dashLengthCtrl->GetMinSize(); diff --git a/pcbnew/dialogs/panel_setup_formatting.h b/pcbnew/dialogs/panel_setup_formatting.h index b703fc63b0..1fe27b34d3 100644 --- a/pcbnew/dialogs/panel_setup_formatting.h +++ b/pcbnew/dialogs/panel_setup_formatting.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-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 @@ -31,7 +31,7 @@ class PAGED_DIALOG; class PANEL_SETUP_FORMATTING : public PANEL_SETUP_FORMATTING_BASE { public: - PANEL_SETUP_FORMATTING( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ); + PANEL_SETUP_FORMATTING( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ); bool TransferDataToWindow() override; bool TransferDataFromWindow() override; diff --git a/pcbnew/dialogs/panel_setup_mask_and_paste.cpp b/pcbnew/dialogs/panel_setup_mask_and_paste.cpp index 2fedcf1568..02a559e03b 100644 --- a/pcbnew/dialogs/panel_setup_mask_and_paste.cpp +++ b/pcbnew/dialogs/panel_setup_mask_and_paste.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-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 @@ -26,12 +26,11 @@ #include #include #include -#include -PANEL_SETUP_MASK_AND_PASTE::PANEL_SETUP_MASK_AND_PASTE( PAGED_DIALOG* aParent, +PANEL_SETUP_MASK_AND_PASTE::PANEL_SETUP_MASK_AND_PASTE( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ) : - PANEL_SETUP_MASK_AND_PASTE_BASE( aParent->GetTreebook() ), + PANEL_SETUP_MASK_AND_PASTE_BASE( aParentWindow ), m_maskExpansion( aFrame, m_maskMarginLabel, m_maskMarginCtrl, m_maskMarginUnits ), m_maskMinWidth( aFrame, m_maskMinWidthLabel, m_maskMinWidthCtrl, m_maskMinWidthUnits ), m_maskToCopperClearance( aFrame, m_maskToCopperClearanceLabel, m_maskToCopperClearanceCtrl, diff --git a/pcbnew/dialogs/panel_setup_mask_and_paste.h b/pcbnew/dialogs/panel_setup_mask_and_paste.h index 2319cddd79..86b6ae536d 100644 --- a/pcbnew/dialogs/panel_setup_mask_and_paste.h +++ b/pcbnew/dialogs/panel_setup_mask_and_paste.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2018-2023 KiCad Developers, see change_log.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 @@ -48,7 +48,7 @@ private: UNIT_BINDER m_pasteMarginRatio; public: - PANEL_SETUP_MASK_AND_PASTE( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ); + PANEL_SETUP_MASK_AND_PASTE( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ); ~PANEL_SETUP_MASK_AND_PASTE( ) { }; bool TransferDataToWindow() override; diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index 4096b6f05a..65444063ea 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -33,16 +33,14 @@ #include #include #include -#include #include #include #include #include #include -PANEL_SETUP_RULES::PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ) : - PANEL_SETUP_RULES_BASE( aParent->GetTreebook() ), - m_Parent( aParent ), +PANEL_SETUP_RULES::PANEL_SETUP_RULES( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ) : + PANEL_SETUP_RULES_BASE( aParentWindow ), m_frame( aFrame ), m_scintillaTricks( nullptr ), m_helpWindow( nullptr ) @@ -50,7 +48,8 @@ PANEL_SETUP_RULES::PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFr m_scintillaTricks = new SCINTILLA_TRICKS( m_textEditor, wxT( "()" ), false, [this]() { - wxPostEvent( m_Parent, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) ); + wxPostEvent( PAGED_DIALOG::GetDialog( this ), + wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) ); } ); m_textEditor->AutoCompSetSeparator( '|' ); @@ -170,7 +169,7 @@ void PANEL_SETUP_RULES::OnContextMenu(wxMouseEvent &event) void PANEL_SETUP_RULES::onScintillaCharAdded( wxStyledTextEvent &aEvent ) { - m_Parent->SetModified(); + PAGED_DIALOG::GetDialog( this )->SetModified(); m_textEditor->SearchAnchor(); wxString rules = m_textEditor->GetText(); diff --git a/pcbnew/dialogs/panel_setup_rules.h b/pcbnew/dialogs/panel_setup_rules.h index 9ceac5702e..bd97f761d5 100644 --- a/pcbnew/dialogs/panel_setup_rules.h +++ b/pcbnew/dialogs/panel_setup_rules.h @@ -38,7 +38,7 @@ class HTML_MESSAGE_BOX; class PANEL_SETUP_RULES : public PANEL_SETUP_RULES_BASE { public: - PANEL_SETUP_RULES( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ); + PANEL_SETUP_RULES( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ); ~PANEL_SETUP_RULES( ) override; private: @@ -53,7 +53,6 @@ private: bool TransferDataToWindow() override; bool TransferDataFromWindow() override; - PAGED_DIALOG* m_Parent; PCB_EDIT_FRAME* m_frame; SCINTILLA_TRICKS* m_scintillaTricks; wxString m_originalText; diff --git a/pcbnew/dialogs/panel_setup_text_and_graphics.cpp b/pcbnew/dialogs/panel_setup_text_and_graphics.cpp index 3b9a8c8fd3..8c708f19ab 100644 --- a/pcbnew/dialogs/panel_setup_text_and_graphics.cpp +++ b/pcbnew/dialogs/panel_setup_text_and_graphics.cpp @@ -54,9 +54,9 @@ enum }; -PANEL_SETUP_TEXT_AND_GRAPHICS::PANEL_SETUP_TEXT_AND_GRAPHICS( PAGED_DIALOG* aParent, +PANEL_SETUP_TEXT_AND_GRAPHICS::PANEL_SETUP_TEXT_AND_GRAPHICS( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ) : - PANEL_SETUP_TEXT_AND_GRAPHICS_BASE( aParent->GetTreebook() ), + PANEL_SETUP_TEXT_AND_GRAPHICS_BASE( aParentWindow ), m_arrowLength( aFrame, m_lblArrowLength, m_dimensionArrowLength, m_arrowLengthUnits ), m_extensionOffset( aFrame, m_lblExtensionOffset, m_dimensionExtensionOffset, m_dimensionExtensionOffsetUnits ) diff --git a/pcbnew/dialogs/panel_setup_text_and_graphics.h b/pcbnew/dialogs/panel_setup_text_and_graphics.h index c87aa519e4..f9baf25965 100644 --- a/pcbnew/dialogs/panel_setup_text_and_graphics.h +++ b/pcbnew/dialogs/panel_setup_text_and_graphics.h @@ -38,7 +38,7 @@ class BOARD_DESIGN_SETTINGS; class PANEL_SETUP_TEXT_AND_GRAPHICS : public PANEL_SETUP_TEXT_AND_GRAPHICS_BASE { public: - PANEL_SETUP_TEXT_AND_GRAPHICS( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ); + PANEL_SETUP_TEXT_AND_GRAPHICS( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ); ~PANEL_SETUP_TEXT_AND_GRAPHICS( ) override; bool TransferDataToWindow() override; diff --git a/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp b/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp index 71656d8883..4397ebe433 100644 --- a/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp +++ b/pcbnew/dialogs/panel_setup_tracks_and_vias.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -52,11 +51,10 @@ enum DIFF_VAR_GRID_COLUMNS }; -PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS( PAGED_DIALOG* aParent, +PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ) : - PANEL_SETUP_TRACKS_AND_VIAS_BASE( aParent->GetTreebook() ) + PANEL_SETUP_TRACKS_AND_VIAS_BASE( aParentWindow ) { - m_Parent = aParent; m_Frame = aFrame; m_Pcb = m_Frame->GetBoard(); m_BrdSettings = &m_Pcb->GetDesignSettings(); @@ -369,7 +367,7 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::Validate() if( !viaDia.IsEmpty() && viaDrill.IsEmpty() ) { msg = _( "No via hole size defined." ); - m_Parent->SetError( msg, this, m_viaSizesGrid, row, VIA_DRILL_COL ); + PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_viaSizesGrid, row, VIA_DRILL_COL ); return false; } } @@ -383,7 +381,7 @@ bool PANEL_SETUP_TRACKS_AND_VIAS::Validate() if( !dpWidth.IsEmpty() && dpGap.IsEmpty() ) { msg = _( "No differential pair gap defined." ); - m_Parent->SetError( msg, this, m_diffPairsGrid, row, 1 ); + PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_diffPairsGrid, row, 1 ); return false; } } diff --git a/pcbnew/dialogs/panel_setup_tracks_and_vias.h b/pcbnew/dialogs/panel_setup_tracks_and_vias.h index ce4a7268ec..d264994416 100644 --- a/pcbnew/dialogs/panel_setup_tracks_and_vias.h +++ b/pcbnew/dialogs/panel_setup_tracks_and_vias.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018-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 @@ -39,7 +39,7 @@ class BOARD_DESIGN_SETTINGS; class PANEL_SETUP_TRACKS_AND_VIAS : public PANEL_SETUP_TRACKS_AND_VIAS_BASE { public: - PANEL_SETUP_TRACKS_AND_VIAS( PAGED_DIALOG* aParent, PCB_EDIT_FRAME* aFrame ); + PANEL_SETUP_TRACKS_AND_VIAS( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame ); ~PANEL_SETUP_TRACKS_AND_VIAS() override; bool TransferDataToWindow() override; @@ -67,7 +67,6 @@ protected: void AppendDiffPairs( int aWidth, int aGap, int aViaGap ); private: - PAGED_DIALOG* m_Parent; PCB_EDIT_FRAME* m_Frame; BOARD* m_Pcb; BOARD_DESIGN_SETTINGS* m_BrdSettings;