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>
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
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
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 int hk1 = ACTIONS::gridFast1.GetHotKey();
63 int hk2 = ACTIONS::gridFast2.GetHotKey();
64 m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
65 m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
66
69
70 Layout();
71
72 // Now all widgets have the size fixed, call FinishDialogSettings
74
75 m_buttonResetSizes->Bind( wxEVT_BUTTON,
76 [&]( wxCommandEvent& )
77 {
78 APP_SETTINGS_BASE* settings = m_parent->config();
79 settings->m_Window.grid.sizes = settings->DefaultGridSizeList();
81 settings->m_Window.grid.last_size_idx = m_currentGridCtrl->GetSelection();
82 } );
83}
84
85
87{
88 APP_SETTINGS_BASE* settings = m_parent->config();
89
90 wxString savedCurrentGrid = m_currentGridCtrl->GetStringSelection();
91 wxString savedGrid1 = m_grid1Ctrl->GetStringSelection();
92 wxString savedGrid2 = m_grid2Ctrl->GetStringSelection();
93
94 wxArrayString grids;
95 GRID_MENU::BuildChoiceList( &grids, settings, m_parent );
96
97 m_currentGridCtrl->Set( grids );
98 m_grid1Ctrl->Set( grids );
99 m_grid2Ctrl->Set( grids );
100
101 m_currentGridCtrl->SetStringSelection( savedCurrentGrid );
102 m_grid1Ctrl->SetStringSelection( savedGrid1 );
103 m_grid2Ctrl->SetStringSelection( savedGrid2 );
104}
105
106
108{
109 // Validate new settings
110 if( !m_userGridX.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
111 return false;
112
113 if( !m_userGridY.Validate( 0.001, 1000.0, EDA_UNITS::MILLIMETRES ) )
114 return false;
115
116 // Apply the new settings
118
119 gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
123 gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
124 gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
125
126 // Notify TOOLS
129
130 // Notify GAL
131 mgr->RunAction( ACTIONS::gridPreset, true, static_cast<intptr_t>( gridCfg.last_size_idx ) );
133
135
136 return wxDialog::TransferDataFromWindow();
137}
138
139
141{
142 APP_SETTINGS_BASE* settings = m_parent->config();
143
144 GRID_SETTINGS& gridCfg = settings->m_Window.grid;
145
146 m_buttonResetSizes->Show( gridCfg.sizes != settings->DefaultGridSizeList() );
147 Layout();
148
149 m_currentGridCtrl->SetSelection( settings->m_Window.grid.last_size_idx );
150
153
156
157 m_grid1Ctrl->SetSelection( gridCfg.fast_grid_1 );
158 m_grid2Ctrl->SetSelection( gridCfg.fast_grid_2 );
159
160 return wxDialog::TransferDataToWindow();
161}
162
163
165{
168}
169
170
static TOOL_ACTION gridFast1
Definition: actions.h:136
static TOOL_ACTION gridPreset
Definition: actions.h:142
static TOOL_ACTION gridSetOrigin
Definition: actions.h:140
static TOOL_ACTION gridFast2
Definition: actions.h:137
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:101
WINDOW_SETTINGS m_Window
Definition: app_settings.h:184
virtual const std::vector< wxString > DefaultGridSizeList() const
By default, this returns the list of grids available in PcbNew-based applications.
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.
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:90
VECTOR2< double > VECTOR2D
Definition: vector2d.h:617