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 
24 #include <dialog_grid_settings.h>
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, true ),
40  m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits, true )
41 {
42  wxArrayString grids;
44  m_currentGridCtrl->Append( grids );
45  m_grid1Ctrl->Append( grids );
46  m_grid2Ctrl->Append( grids );
47 
48  if( m_parent->IsType( FRAME_SCH )
53  {
54  m_book->SetSelection( 1 );
55  }
56  else
57  {
58  m_book->SetSelection( 0 );
59  }
60 
61  m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
63 
64  Layout();
65 
66  // Now all widgets have the size fixed, call FinishDialogSettings
68 }
69 
70 
72 {
73  // Validate new settings
74  if( !m_userGridX.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
75  return false;
76 
77  if( !m_userGridY.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
78  return false;
79 
80  // Apply the new settings
81  GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid;
82 
83  gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
85  gridCfg.user_grid_x = StringFromValue( GetUserUnits(), m_userGridX.GetValue(), true, true );
86  gridCfg.user_grid_y = StringFromValue( GetUserUnits(), m_userGridY.GetValue(), true, true );
87  gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
88  gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
89 
90  // Notify TOOLS
93 
94  // Notify GAL
95  mgr->RunAction( ACTIONS::gridPreset, true, gridCfg.last_size_idx );
97 
99 
100  return wxDialog::TransferDataFromWindow();
101 }
102 
103 
105 {
106  GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid;
107 
109 
112 
115 
116  m_grid1Ctrl->SetSelection( gridCfg.fast_grid_1 );
117  m_grid2Ctrl->SetSelection( gridCfg.fast_grid_2 );
118 
119  int hk1 = ACTIONS::gridFast1.GetHotKey();
120  int hk2 = ACTIONS::gridFast2.GetHotKey();
121  m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
122  m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
123 
124  return wxDialog::TransferDataToWindow();
125 }
126 
127 
128 void DIALOG_GRID_SETTINGS::OnResetGridOriginClick( wxCommandEvent& event )
129 {
130  m_gridOriginX.SetValue( 0 );
131  m_gridOriginY.SetValue( 0 );
132 }
133 
134 
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:82
Implementation of conversion functions that require both schematic and board internal units.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
static TOOL_ACTION gridFast1
Definition: actions.h:129
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:114
EDA_UNITS GetUserUnits() const
Definition: dialog_shim.h:131
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
TOOL_MANAGER.
Definition: tool_manager.h:51
static TOOL_ACTION gridFast2
Definition: actions.h:130
static TOOL_ACTION gridPreset
Definition: actions.h:135
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
GRID_SETTINGS grid
Definition: app_settings.h:82
static void BuildChoiceList(wxArrayString *aGridsList, APP_SETTINGS_BASE *aCfg, bool mmFirst)
Definition: grid_menu.cpp:80
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Function ResetTools() Resets 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
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED, bool aUseMils=false)
Function Validate Validates the control against the given range, informing the user of any errors fou...
WINDOW_SETTINGS m_Window
Definition: app_settings.h:154
bool IsType(FRAME_T aType) const
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
The common library.
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
Class DIALOG_GRID_SETTINGS_BASE.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74
static TOOL_ACTION gridSetOrigin
Definition: actions.h:133
virtual void SetGridOrigin(const wxPoint &aPosition)=0
int GetHotKey() const
Function GetHotKey() Returns the hotkey keycode which initiates the action.
Definition: tool_action.h:90
EDA_DRAW_FRAME * m_parent
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, bool aUseMils, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:233
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, bool aUseMils, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:471
Common grid settings, available to every frame.
Definition: app_settings.h:49