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  // Configure display origin transforms
45 
46  wxArrayString grids;
48  m_currentGridCtrl->Append( grids );
49  m_grid1Ctrl->Append( grids );
50  m_grid2Ctrl->Append( grids );
51 
52  if( m_parent->IsType( FRAME_SCH )
57  {
58  m_book->SetSelection( 1 );
59  }
60  else
61  {
62  m_book->SetSelection( 0 );
63  }
64 
65  m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
67 
68  Layout();
69 
70  // Now all widgets have the size fixed, call FinishDialogSettings
72 }
73 
74 
76 {
77  // Validate new settings
78  if( !m_userGridX.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
79  return false;
80 
81  if( !m_userGridY.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
82  return false;
83 
84  // Apply the new settings
85  GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid;
86 
87  gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
91  gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
92  gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
93 
94  // Notify TOOLS
97 
98  // Notify GAL
99  mgr->RunAction( ACTIONS::gridPreset, true, gridCfg.last_size_idx );
101 
103 
104  return wxDialog::TransferDataFromWindow();
105 }
106 
107 
109 {
110  GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid;
111 
113 
116 
119 
120  m_grid1Ctrl->SetSelection( gridCfg.fast_grid_1 );
121  m_grid2Ctrl->SetSelection( gridCfg.fast_grid_2 );
122 
123  int hk1 = ACTIONS::gridFast1.GetHotKey();
124  int hk2 = ACTIONS::gridFast2.GetHotKey();
125  m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
126  m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
127 
128  return wxDialog::TransferDataToWindow();
129 }
130 
131 
132 void DIALOG_GRID_SETTINGS::OnResetGridOriginClick( wxCommandEvent& event )
133 {
134  m_gridOriginX.SetValue( 0 );
135  m_gridOriginY.SetValue( 0 );
136 }
137 
138 
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:141
static TOOL_ACTION gridFast1
Definition: actions.h:131
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:132
static TOOL_ACTION gridPreset
Definition: actions.h:137
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
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:468
GRID_SETTINGS grid
Definition: app_settings.h:89
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
WINDOW_SETTINGS m_Window
Definition: app_settings.h:173
virtual bool Validate(double aMin, double aMax, EDA_UNITS aUnits=EDA_UNITS::UNSCALED)
Function Validate Validates the control against the given range, informing the user of any errors fou...
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:201
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
static void BuildChoiceList(wxArrayString *aGridsList, APP_SETTINGS_BASE *aCfg, EDA_DRAW_FRAME *aParent)
Definition: grid_menu.cpp:79
The common library.
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
wxString StringFromValue(EDA_UNITS aUnits, double aValue, bool aAddUnitSymbol, EDA_DATA_TYPE aType)
Function StringFromValue returns the string from aValue according to units (inch, mm ....
Definition: base_units.cpp:244
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.
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Function SetOriginTransform Sets the current origin transform mode.
Definition: unit_binder.h:168
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:76
static TOOL_ACTION gridSetOrigin
Definition: actions.h:135
virtual void SetGridOrigin(const wxPoint &aPosition)=0
int GetHotKey() const
Returns the hotkey keycode which initiates the action.
Definition: tool_action.h:85
EDA_DRAW_FRAME * m_parent
Common grid settings, available to every frame.
Definition: app_settings.h:49