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 <common.h>
27#include <eda_draw_frame.h>
28#include <tool/tool_manager.h>
29#include <tool/actions.h>
30#include <tool/grid_menu.h>
31#include <tool/common_tools.h>
32#include <pgm_base.h>
34
37 m_parent( aParent ),
38 m_gridOriginX( aParent, m_staticTextGridPosX, m_GridOriginXCtrl, m_TextPosXUnits ),
39 m_gridOriginY( aParent, m_staticTextGridPosY, m_GridOriginYCtrl, m_TextPosYUnits ),
40 m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits ),
41 m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits )
42{
43 // Configure display origin transforms
46
48
54 {
55 m_book->SetSelection( 1 );
56 m_buttonResetOrigin->Hide(); // Eeschema and friends don't use grid origin
57 }
58 else
59 {
60 m_book->SetSelection( 0 );
61 }
62
63 int hk1 = ACTIONS::gridFast1.GetHotKey();
64 int hk2 = ACTIONS::gridFast2.GetHotKey();
65 m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
66 m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
67
70
71 Layout();
72
73 // Now all widgets have the size fixed, call FinishDialogSettings
75
76 m_buttonResetSizes->Bind( wxEVT_BUTTON,
77 [&]( wxCommandEvent& )
78 {
79 APP_SETTINGS_BASE* settings = m_parent->config();
80 settings->m_Window.grid.sizes = settings->DefaultGridSizeList();
82 settings->m_Window.grid.last_size_idx = m_currentGridCtrl->GetSelection();
83 } );
84}
85
86
88{
89 APP_SETTINGS_BASE* settings = m_parent->config();
90
91 wxString savedCurrentGrid = m_currentGridCtrl->GetStringSelection();
92 wxString savedGrid1 = m_grid1Ctrl->GetStringSelection();
93 wxString savedGrid2 = m_grid2Ctrl->GetStringSelection();
94
95 wxArrayString grids;
96 GRID_MENU::BuildChoiceList( &grids, settings, m_parent );
97
98 m_currentGridCtrl->Set( grids );
99 m_grid1Ctrl->Set( grids );
100 m_grid2Ctrl->Set( grids );
101
102 m_currentGridCtrl->SetStringSelection( savedCurrentGrid );
103 m_grid1Ctrl->SetStringSelection( savedGrid1 );
104 m_grid2Ctrl->SetStringSelection( savedGrid2 );
105}
106
107
109{
110 // Validate new settings
111 if( !m_userGridX.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
112 return false;
113
114 if( !m_userGridY.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
115 return false;
116
117 // Apply the new settings
119 GRID_SETTINGS& gridCfg = cfg->m_Window.grid;
120
121 gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
125 gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
126 gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
127
128 // Notify TOOLS
131
132 // Notify GAL
133 mgr->RunAction( ACTIONS::gridPreset, true, static_cast<intptr_t>( gridCfg.last_size_idx ) );
135
137
138 return wxDialog::TransferDataFromWindow();
139}
140
141
143{
144 APP_SETTINGS_BASE* settings = m_parent->config();
145
146 GRID_SETTINGS& gridCfg = settings->m_Window.grid;
147
148 m_buttonResetSizes->Show( gridCfg.sizes != settings->DefaultGridSizeList() );
149 Layout();
150
151 m_currentGridCtrl->SetSelection( settings->m_Window.grid.last_size_idx );
152
155
158
159 m_grid1Ctrl->SetSelection( gridCfg.fast_grid_1 );
160 m_grid2Ctrl->SetSelection( gridCfg.fast_grid_2 );
161
162 return wxDialog::TransferDataToWindow();
163}
164
165
167{
170}
171
172
static TOOL_ACTION gridFast1
Definition: actions.h:137
static TOOL_ACTION gridPreset
Definition: actions.h:143
static TOOL_ACTION gridSetOrigin
Definition: actions.h:141
static TOOL_ACTION gridFast2
Definition: actions.h:138
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:110
WINDOW_SETTINGS m_Window
Definition: app_settings.h:187
const std::vector< wxString > DefaultGridSizeList() const
Class DIALOG_GRID_SETTINGS_BASE.
bool TransferDataFromWindow() override
void OnResetGridOriginClick(wxCommandEvent &event) override
EDA_DRAW_FRAME * m_parent
bool TransferDataToWindow() override
DIALOG_GRID_SETTINGS(EDA_DRAW_FRAME *aParent)
This has no dependencies on calling wxFrame derivative, such as PCB_BASE_FRAME.
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
bool IsType(FRAME_T aType) const
The base class for create windows for drawing purpose.
void UpdateGridSelectBox()
Rebuild the grid combobox to respond to any changes in the GUI (units, user grid changes,...
virtual void SetGridOrigin(const VECTOR2I &aPosition)=0
virtual const VECTOR2I & GetGridOrigin() const =0
Return the absolute coordinates of the origin of the snap grid.
static void BuildChoiceList(wxArrayString *aGridsList, APP_SETTINGS_BASE *aCfg, EDA_DRAW_FRAME *aParent)
Definition: grid_menu.cpp:85
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:111
@ MODEL_RELOAD
Model changes (required full reload)
Definition: tool_base.h:80
Master controller class:
Definition: tool_manager.h:55
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
void ResetTools(TOOL_BASE::RESET_REASON aReason)
Reset all tools (i.e.
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aValue in internal units into a united string.
int ValueFromString(const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aTextValue in aUnits to internal units used by the frame.
virtual long long int GetValue()
Return the current value in Internal Units.
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.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void SetCoordType(ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
Set the current origin transform mode.
Definition: unit_binder.h:187
The common library.
@ FRAME_SCH_SYMBOL_EDITOR
Definition: frame_type.h:35
@ FRAME_SCH_VIEWER
Definition: frame_type.h:36
@ FRAME_SCH
Definition: frame_type.h:34
@ FRAME_SCH_VIEWER_MODAL
Definition: frame_type.h:37
@ FRAME_SIMULATOR
Definition: frame_type.h:38
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
see class PGM_BASE
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
Common grid settings, available to every frame.
Definition: app_settings.h:51
wxString user_grid_x
Definition: app_settings.h:54
wxString user_grid_y
Definition: app_settings.h:55
std::vector< wxString > sizes
Definition: app_settings.h:53
GRID_SETTINGS grid
Definition: app_settings.h:99
VECTOR2< double > VECTOR2D
Definition: vector2d.h:589
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590