KiCad PCB EDA Suite
dialog_grid_settings.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
25 #include <base_units.h>
26 #include <common.h>
27 #include <settings/app_settings.h>
28 #include <eda_draw_frame.h>
29 #include <tool/tool_manager.h>
30 #include <tool/actions.h>
31 #include <tool/grid_menu.h>
32 #include <tool/common_tools.h>
33 
35  DIALOG_GRID_SETTINGS_BASE( aParent ),
36  m_parent( aParent ),
37  m_gridOriginX( aParent, m_staticTextGridPosX, m_GridOriginXCtrl, m_TextPosXUnits ),
38  m_gridOriginY( aParent, m_staticTextGridPosY, m_GridOriginYCtrl, m_TextPosYUnits ),
39  m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits ),
40  m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits )
41 {
42  // Configure display origin transforms
45 
47 
48  if( m_parent->IsType( FRAME_SCH )
53  {
54  m_book->SetSelection( 1 );
55  m_buttonResetOrigin->Hide(); // Eeschema and friends don't use grid origin
56  }
57  else
58  {
59  m_book->SetSelection( 0 );
60  }
61 
62  m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
64 
65  Layout();
66 
67  // Now all widgets have the size fixed, call FinishDialogSettings
69 
70  m_buttonResetSizes->Bind( wxEVT_BUTTON,
71  [&]( wxCommandEvent& )
72  {
73  APP_SETTINGS_BASE* settings = m_parent->config();
74  settings->m_Window.grid.sizes = settings->DefaultGridSizeList();
76  settings->m_Window.grid.last_size_idx = m_currentGridCtrl->GetSelection();
77  } );
78 }
79 
80 
82 {
83  APP_SETTINGS_BASE* settings = m_parent->config();
84 
85  wxString savedCurrentGrid = m_currentGridCtrl->GetStringSelection();
86  wxString savedGrid1 = m_grid1Ctrl->GetStringSelection();
87  wxString savedGrid2 = m_grid2Ctrl->GetStringSelection();
88 
89  wxArrayString grids;
90  GRID_MENU::BuildChoiceList( &grids, settings, m_parent );
91 
92  m_currentGridCtrl->Set( grids );
93  m_grid1Ctrl->Set( grids );
94  m_grid2Ctrl->Set( grids );
95 
96  m_currentGridCtrl->SetStringSelection( savedCurrentGrid );
97  m_grid1Ctrl->SetStringSelection( savedGrid1 );
98  m_grid2Ctrl->SetStringSelection( savedGrid2 );
99 }
100 
101 
103 {
104  // Validate new settings
105  if( !m_userGridX.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
106  return false;
107 
108  if( !m_userGridY.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
109  return false;
110 
111  // Apply the new settings
112  GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid;
113 
114  gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
118  gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
119  gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
120 
121  // Notify TOOLS
124 
125  // Notify GAL
126  mgr->RunAction( ACTIONS::gridPreset, true, static_cast<intptr_t>( gridCfg.last_size_idx ) );
128 
130 
131  return wxDialog::TransferDataFromWindow();
132 }
133 
134 
136 {
137  APP_SETTINGS_BASE* settings = m_parent->config();
138 
139  GRID_SETTINGS& gridCfg = settings->m_Window.grid;
140 
141  m_buttonResetSizes->Show( gridCfg.sizes != settings->DefaultGridSizeList() );
142  Layout();
143 
144  m_currentGridCtrl->SetSelection( settings->m_Window.grid.last_size_idx );
145 
148 
151 
152  m_grid1Ctrl->SetSelection( gridCfg.fast_grid_1 );
153  m_grid2Ctrl->SetSelection( gridCfg.fast_grid_2 );
154 
155  int hk1 = ACTIONS::gridFast1.GetHotKey();
156  int hk2 = ACTIONS::gridFast2.GetHotKey();
157  m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
158  m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
159 
160  return wxDialog::TransferDataToWindow();
161 }
162 
163 
164 void DIALOG_GRID_SETTINGS::OnResetGridOriginClick( wxCommandEvent& event )
165 {
166  m_gridOriginX.SetValue( 0 );
167  m_gridOriginY.SetValue( 0 );
168 }
169 
170 
wxString user_grid_y
Definition: app_settings.h:54
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
wxString user_grid_x
Definition: app_settings.h:53
Model changes (required full reload)
Definition: tool_base.h:80
Implementation of conversion functions that require both schematic and board internal units.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION gridFast1
Definition: actions.h:133
The base class for create windows for drawing purpose.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
EDA_UNITS GetUserUnits() const
Definition: dialog_shim.h:121
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
Master controller class:
Definition: tool_manager.h:54
static TOOL_ACTION gridFast2
Definition: actions.h:134
std::vector< wxString > sizes
Definition: app_settings.h:52
static TOOL_ACTION gridPreset
Definition: actions.h:139
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:411
GRID_SETTINGS grid
Definition: app_settings.h:89
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
virtual const wxPoint & GetGridOrigin() const =0
Return the absolute coordinates of the origin of the snap grid.
bool TransferDataToWindow() override
DIALOG_GRID_SETTINGS(EDA_DRAW_FRAME *aParent)
This has no dependencies on calling wxFrame derivative, such as PCB_BASE_FRAME.
void OnResetGridOriginClick(wxCommandEvent &event) override
bool TransferDataFromWindow() override
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
WINDOW_SETTINGS m_Window
Definition: app_settings.h:181
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Validate the control against the given range, informing the user of any errors found.
bool IsType(FRAME_T aType) const
static void BuildChoiceList(wxArrayString *aGridsList, APP_SETTINGS_BASE *aCfg, EDA_DRAW_FRAME *aParent)
Definition: grid_menu.cpp:85
The common library.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
virtual long long int GetValue()
Return the current value in Internal Units.
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
Definition: base_units.cpp:204
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
Class DIALOG_GRID_SETTINGS_BASE.
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:177
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
static TOOL_ACTION gridSetOrigin
Definition: actions.h:137
virtual void SetGridOrigin(const wxPoint &aPosition)=0
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:111
EDA_DRAW_FRAME * m_parent
virtual const std::vector< wxString > DefaultGridSizeList() const
By default, this returns the list of grids available in PcbNew-based applications.
Common grid settings, available to every frame.
Definition: app_settings.h:49