From 6fa0ac45af4c31c6c3f64a793e167261120b900b Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 21 Feb 2021 15:32:52 -0500 Subject: [PATCH] Re-enable custom grid settings for Pcbnew Add a reset button that will only show up if the user edits the JSON configuration for grids. This is a temporary measure until we have a real grid editor GUI in V7. Fixes https://gitlab.com/kicad/code/kicad/-/issues/7595 --- common/dialogs/dialog_grid_settings.cpp | 47 ++++++++++--- common/dialogs/dialog_grid_settings_base.cpp | 14 ++-- common/dialogs/dialog_grid_settings_base.fbp | 74 +++++++++++++++++++- common/dialogs/dialog_grid_settings_base.h | 3 +- common/settings/app_settings.cpp | 2 +- common/settings/json_settings.cpp | 12 ++++ include/dialogs/dialog_grid_settings.h | 4 +- include/settings/app_settings.h | 3 + include/settings/json_settings.h | 7 ++ include/settings/parameters.h | 2 +- pcbnew/footprint_preview_panel.cpp | 29 +------- pcbnew/pcb_base_frame.cpp | 29 +------- pcbnew/pcbnew_settings.cpp | 27 +++++++ pcbnew/pcbnew_settings.h | 2 + 14 files changed, 184 insertions(+), 71 deletions(-) diff --git a/common/dialogs/dialog_grid_settings.cpp b/common/dialogs/dialog_grid_settings.cpp index ab061537bd..3bec9c93f4 100644 --- a/common/dialogs/dialog_grid_settings.cpp +++ b/common/dialogs/dialog_grid_settings.cpp @@ -43,11 +43,7 @@ DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( EDA_DRAW_FRAME* aParent ): m_gridOriginX.SetCoordType( ORIGIN_TRANSFORMS::ABS_X_COORD ); m_gridOriginY.SetCoordType( ORIGIN_TRANSFORMS::ABS_Y_COORD ); - wxArrayString grids; - GRID_MENU::BuildChoiceList( &grids, m_parent->config(), m_parent ); - m_currentGridCtrl->Append( grids ); - m_grid1Ctrl->Append( grids ); - m_grid2Ctrl->Append( grids ); + RebuildGridSizes(); if( m_parent->IsType( FRAME_SCH ) || m_parent->IsType( FRAME_SCH_SYMBOL_EDITOR ) @@ -56,7 +52,7 @@ DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( EDA_DRAW_FRAME* aParent ): || m_parent->IsType( FRAME_SIMULATOR ) ) { m_book->SetSelection( 1 ); - m_buttonReset->Hide(); // Eeschema and friends don't use grid origin + m_buttonResetOrigin->Hide(); // Eeschema and friends don't use grid origin } else { @@ -70,6 +66,36 @@ DIALOG_GRID_SETTINGS::DIALOG_GRID_SETTINGS( EDA_DRAW_FRAME* aParent ): // Now all widgets have the size fixed, call FinishDialogSettings finishDialogSettings(); + + m_buttonResetSizes->Bind( wxEVT_BUTTON, + [&]( wxCommandEvent ) + { + APP_SETTINGS_BASE* settings = m_parent->config(); + settings->m_Window.grid.sizes = settings->DefaultGridSizeList(); + RebuildGridSizes(); + settings->m_Window.grid.last_size_idx = m_currentGridCtrl->GetSelection(); + } ); +} + + +void DIALOG_GRID_SETTINGS::RebuildGridSizes() +{ + APP_SETTINGS_BASE* settings = m_parent->config(); + + wxString savedCurrentGrid = m_currentGridCtrl->GetStringSelection(); + wxString savedGrid1 = m_grid1Ctrl->GetStringSelection(); + wxString savedGrid2 = m_grid2Ctrl->GetStringSelection(); + + wxArrayString grids; + GRID_MENU::BuildChoiceList( &grids, settings, m_parent ); + + m_currentGridCtrl->Set( grids ); + m_grid1Ctrl->Set( grids ); + m_grid2Ctrl->Set( grids ); + + m_currentGridCtrl->SetStringSelection( savedCurrentGrid ); + m_grid1Ctrl->SetStringSelection( savedGrid1 ); + m_grid2Ctrl->SetStringSelection( savedGrid2 ); } @@ -108,9 +134,14 @@ bool DIALOG_GRID_SETTINGS::TransferDataFromWindow() bool DIALOG_GRID_SETTINGS::TransferDataToWindow() { - GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid; + APP_SETTINGS_BASE* settings = m_parent->config(); - m_currentGridCtrl->SetSelection( m_parent->config()->m_Window.grid.last_size_idx ); + GRID_SETTINGS& gridCfg = settings->m_Window.grid; + + m_buttonResetSizes->Show( gridCfg.sizes != settings->DefaultGridSizeList() ); + Layout(); + + m_currentGridCtrl->SetSelection( settings->m_Window.grid.last_size_idx ); m_userGridX.SetValue( ValueFromString( GetUserUnits(), gridCfg.user_grid_x ) ); m_userGridY.SetValue( ValueFromString( GetUserUnits(), gridCfg.user_grid_y ) ); diff --git a/common/dialogs/dialog_grid_settings_base.cpp b/common/dialogs/dialog_grid_settings_base.cpp index 0472e755df..6e87785acb 100644 --- a/common/dialogs/dialog_grid_settings_base.cpp +++ b/common/dialogs/dialog_grid_settings_base.cpp @@ -170,8 +170,14 @@ DIALOG_GRID_SETTINGS_BASE::DIALOG_GRID_SETTINGS_BASE( wxWindow* parent, wxWindow wxBoxSizer* bButtonSizer; bButtonSizer = new wxBoxSizer( wxHORIZONTAL ); - m_buttonReset = new wxButton( this, wxID_ANY, _("Reset Grid Origin"), wxDefaultPosition, wxDefaultSize, 0 ); - bButtonSizer->Add( m_buttonReset, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + m_buttonResetOrigin = new wxButton( this, wxID_ANY, _("Reset Grid Origin"), wxDefaultPosition, wxDefaultSize, 0 ); + bButtonSizer->Add( m_buttonResetOrigin, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); + + m_buttonResetSizes = new wxButton( this, wxID_ANY, _("Reset Grid Sizes"), wxDefaultPosition, wxDefaultSize, 0 ); + m_buttonResetSizes->Hide(); + m_buttonResetSizes->SetToolTip( _("Resets the list of grid sizes to default values") ); + + bButtonSizer->Add( m_buttonResetSizes, 0, wxALL, 5 ); bButtonSizer->Add( 0, 0, 1, wxEXPAND, 5 ); @@ -195,7 +201,7 @@ DIALOG_GRID_SETTINGS_BASE::DIALOG_GRID_SETTINGS_BASE( wxWindow* parent, wxWindow // Connect Events this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_GRID_SETTINGS_BASE::OnInitDlg ) ); - m_buttonReset->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnResetGridOriginClick ), NULL, this ); + m_buttonResetOrigin->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnResetGridOriginClick ), NULL, this ); m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnCancelClick ), NULL, this ); m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnOkClick ), NULL, this ); } @@ -204,7 +210,7 @@ DIALOG_GRID_SETTINGS_BASE::~DIALOG_GRID_SETTINGS_BASE() { // Disconnect Events this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_GRID_SETTINGS_BASE::OnInitDlg ) ); - m_buttonReset->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnResetGridOriginClick ), NULL, this ); + m_buttonResetOrigin->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnResetGridOriginClick ), NULL, this ); m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnCancelClick ), NULL, this ); m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GRID_SETTINGS_BASE::OnOkClick ), NULL, this ); diff --git a/common/dialogs/dialog_grid_settings_base.fbp b/common/dialogs/dialog_grid_settings_base.fbp index 6a95edfc55..a0541956e1 100644 --- a/common/dialogs/dialog_grid_settings_base.fbp +++ b/common/dialogs/dialog_grid_settings_base.fbp @@ -1633,7 +1633,7 @@ 0 1 - m_buttonReset + m_buttonResetOrigin 1 @@ -1659,6 +1659,78 @@ OnResetGridOriginClick + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + + 1 + 0 + 1 + + 1 + + 0 + 0 + + Dock + 0 + Left + 1 + + 1 + + + 0 + 1 + wxID_ANY + Reset Grid Sizes + + 0 + + 0 + + + 0 + + 1 + m_buttonResetSizes + 1 + + + protected + 1 + + + + Resizable + 1 + + + ; ; forward_declare + 0 + Resets the list of grid sizes to default values + + wxFILTER_NONE + wxDefaultValidator + + + + + + 5 wxEXPAND diff --git a/common/dialogs/dialog_grid_settings_base.h b/common/dialogs/dialog_grid_settings_base.h index fd7babfa26..10cb0bb881 100644 --- a/common/dialogs/dialog_grid_settings_base.h +++ b/common/dialogs/dialog_grid_settings_base.h @@ -62,7 +62,8 @@ class DIALOG_GRID_SETTINGS_BASE : public DIALOG_SHIM wxChoice* m_grid2Ctrl; wxStaticText* m_grid2HotKey; wxStaticLine* m_staticline1; - wxButton* m_buttonReset; + wxButton* m_buttonResetOrigin; + wxButton* m_buttonResetSizes; wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; diff --git a/common/settings/app_settings.cpp b/common/settings/app_settings.cpp index 2a31f48ab0..69fc87c8d8 100644 --- a/common/settings/app_settings.cpp +++ b/common/settings/app_settings.cpp @@ -287,7 +287,7 @@ void APP_SETTINGS_BASE::addParamsForWindow( WINDOW_SETTINGS* aWindow, const std: &aWindow->grid.axes_enabled, false ) ); m_params.emplace_back( new PARAM_LIST( aJsonPath + ".grid.sizes", - &aWindow->grid.sizes, {} ) ); + &aWindow->grid.sizes, DefaultGridSizeList() ) ); // pcbnew default grid doesn't matter much, but eeschema does, so default to the index // of the 50mil grid in eeschema diff --git a/common/settings/json_settings.cpp b/common/settings/json_settings.cpp index dc7c0ca366..406b4bd37f 100644 --- a/common/settings/json_settings.cpp +++ b/common/settings/json_settings.cpp @@ -320,6 +320,18 @@ void JSON_SETTINGS::ResetToDefaults() } +bool JSON_SETTINGS::IsDefault( const std::string& aParamName ) +{ + for( const PARAM_BASE* param : m_params ) + { + if( param->GetJsonPath() == aParamName ) + return param->IsDefault(); + } + + return false; +} + + bool JSON_SETTINGS::SaveToFile( const wxString& aDirectory, bool aForce ) { if( !m_writeFile ) diff --git a/include/dialogs/dialog_grid_settings.h b/include/dialogs/dialog_grid_settings.h index 652b25692e..10dc9b5552 100644 --- a/include/dialogs/dialog_grid_settings.h +++ b/include/dialogs/dialog_grid_settings.h @@ -42,10 +42,12 @@ public: private: void OnResetGridOriginClick( wxCommandEvent& event ) override; + void RebuildGridSizes(); + UNIT_BINDER m_gridOriginX; UNIT_BINDER m_gridOriginY; UNIT_BINDER m_userGridX; UNIT_BINDER m_userGridY; }; -#endif // DIALOG_GRID_SETTINGS_H \ No newline at end of file +#endif // DIALOG_GRID_SETTINGS_H diff --git a/include/settings/app_settings.h b/include/settings/app_settings.h index 3f7dfcd6fb..f7fd2f4563 100644 --- a/include/settings/app_settings.h +++ b/include/settings/app_settings.h @@ -155,6 +155,9 @@ public: virtual bool MigrateFromLegacy( wxConfigBase* aCfg ) override; + /// Override in child classes to define the default for the window.grid.sizes parameter + virtual const std::vector DefaultGridSizeList() const { return {}; } + public: CROSS_PROBING_SETTINGS m_CrossProbing; diff --git a/include/settings/json_settings.h b/include/settings/json_settings.h index b6665437b1..04a12ad4a5 100644 --- a/include/settings/json_settings.h +++ b/include/settings/json_settings.h @@ -105,6 +105,13 @@ c * @return true if the file was saved */ void ResetToDefaults(); + /** + * Checks if the current state of a parameter matches its default value + * @param aParamName is the JSON path to the parameter + * @return true if the given parameter is at its default value + */ + bool IsDefault( const std::string& aParamName ); + /** * Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the * form "key1.key2.key3" to refer to nested objects. diff --git a/include/settings/parameters.h b/include/settings/parameters.h index 3294c195df..7132442a53 100644 --- a/include/settings/parameters.h +++ b/include/settings/parameters.h @@ -71,7 +71,7 @@ public: * @return the path name of the parameter used to store it in the json file * mainly usefull in error messages */ - const std::string& GetJsonPath() { return m_path; } + const std::string& GetJsonPath() const { return m_path; } protected: /** diff --git a/pcbnew/footprint_preview_panel.cpp b/pcbnew/footprint_preview_panel.cpp index 7c534689fc..fe50e4d888 100644 --- a/pcbnew/footprint_preview_panel.cpp +++ b/pcbnew/footprint_preview_panel.cpp @@ -162,33 +162,8 @@ FOOTPRINT_PREVIEW_PANEL* FOOTPRINT_PREVIEW_PANEL::New( KIWAY* aKiway, wxWindow* { PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); - // Currently values read from config file are not used because the user cannot - // change this config - // if( cfg->m_Window.grid.sizes.empty() ) - { - cfg->m_Window.grid.sizes = { "1000 mil", - "500 mil", - "250 mil", - "200 mil", - "100 mil", - "50 mil", - "25 mil", - "20 mil", - "10 mil", - "5 mil", - "2 mil", - "1 mil", - "5.0 mm", - "2.5 mm", - "1.0 mm", - "0.5 mm", - "0.25 mm", - "0.2 mm", - "0.1 mm", - "0.05 mm", - "0.025 mm", - "0.01 mm" }; - } + if( cfg->m_Window.grid.sizes.empty() ) + cfg->m_Window.grid.sizes = cfg->DefaultGridSizeList(); // Currently values read from config file are not used because the user cannot // change this config diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index e3cf341e4b..cc9ce8fa2a 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -590,33 +590,8 @@ void PCB_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { EDA_DRAW_FRAME::LoadSettings( aCfg ); - // Currently values read from config file are not used because the user cannot - // change this config - // if( aCfg->m_Window.grid.sizes.empty() ) - { - aCfg->m_Window.grid.sizes = { "1000 mil", - "500 mil", - "250 mil", - "200 mil", - "100 mil", - "50 mil", - "25 mil", - "20 mil", - "10 mil", - "5 mil", - "2 mil", - "1 mil", - "5.0 mm", - "2.5 mm", - "1.0 mm", - "0.5 mm", - "0.25 mm", - "0.2 mm", - "0.1 mm", - "0.05 mm", - "0.025 mm", - "0.01 mm" }; - } + if( aCfg->m_Window.grid.sizes.empty() ) + aCfg->m_Window.grid.sizes = aCfg->DefaultGridSizeList(); // Currently values read from config file are not used because the user cannot // change this config diff --git a/pcbnew/pcbnew_settings.cpp b/pcbnew/pcbnew_settings.cpp index 5252d094cd..78d77c5c71 100644 --- a/pcbnew/pcbnew_settings.cpp +++ b/pcbnew/pcbnew_settings.cpp @@ -790,3 +790,30 @@ bool PCBNEW_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg ) return ret; } + + +const std::vector PCBNEW_SETTINGS::DefaultGridSizeList() const +{ + return { "1000 mil", + "500 mil", + "250 mil", + "200 mil", + "100 mil", + "50 mil", + "25 mil", + "20 mil", + "10 mil", + "5 mil", + "2 mil", + "1 mil", + "5.0 mm", + "2.5 mm", + "1.0 mm", + "0.5 mm", + "0.25 mm", + "0.2 mm", + "0.1 mm", + "0.05 mm", + "0.025 mm", + "0.01 mm" }; +} diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h index 81600b53f6..bbf0c6002a 100644 --- a/pcbnew/pcbnew_settings.h +++ b/pcbnew/pcbnew_settings.h @@ -234,6 +234,8 @@ public: virtual bool MigrateFromLegacy( wxConfigBase* aLegacyConfig ) override; + const std::vector DefaultGridSizeList() const override; + AUI_PANELS m_AuiPanels; DIALOG_CLEANUP m_Cleanup;