KiCad PCB EDA Suite
pcbnew/dialogs/dialog_set_grid.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-2018 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 
29 #include <dialog_set_grid_base.h>
30 
31 #include <base_units.h>
32 #include <common.h>
33 #include <widgets/unit_binder.h>
34 #include <hotkeys.h>
35 #include <pcb_base_edit_frame.h>
36 #include <class_drawpanel.h>
37 #include <class_draw_panel_gal.h>
38 
40 #include <tools/pcb_actions.h>
41 #include <tool/tool_manager.h>
42 
43 // Max values for grid size
44 static const int MAX_GRID_SIZE = KiROUND( 1000.0 * IU_PER_MM );
45 static const int MIN_GRID_SIZE = KiROUND( 0.001 * IU_PER_MM );
46 
47 
49 {
51  wxArrayString m_fast_grid_opts;
52 
53 public:
55  DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices );
56 
57  bool TransferDataFromWindow() override;
58  bool TransferDataToWindow() override;
59 
60 private:
61  void OnResetGridOrgClick( wxCommandEvent& event ) override;
62 
67 };
68 
69 
70 DIALOG_SET_GRID::DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices ):
71  DIALOG_SET_GRID_BASE( aParent ),
72  m_parent( aParent ),
73  m_fast_grid_opts( aGridChoices ),
74  m_gridOriginX( aParent, m_staticTextGridPosX, m_GridOriginXCtrl, m_TextPosXUnits ),
75  m_gridOriginY( aParent, m_staticTextGridPosY, m_GridOriginYCtrl, m_TextPosYUnits ),
76  m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits ),
77  m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits )
78 {
81 
82  m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
84 
85  Layout();
86 
87  // Now all widgets have the size fixed, call FinishDialogSettings
89 }
90 
91 
93 {
94  // Validate new settings
96  return false;
97 
99  return false;
100 
101  // Apply the new settings
102 
103  // Because grid origin is saved in board, show as modified
104  m_parent->OnModify();
107  m_parent->m_FastGrid1 = m_comboBoxGrid1->GetSelection();
108  m_parent->m_FastGrid2 = m_comboBoxGrid2->GetSelection();
109 
110  // User grid
111  BASE_SCREEN* screen = m_parent->GetScreen();
113 
114  // If the user grid is the current option, recall SetGrid()
115  // to force new values put in list as current grid value
116  if( screen->GetGridCmdId() == ID_POPUP_GRID_USER )
117  screen->SetGrid( ID_POPUP_GRID_USER );
118 
119  // Notify GAL
121 
122  if( mgr && m_parent->IsGalCanvasActive() )
123  {
124  mgr->RunAction( "common.Control.gridPreset", true,
126 
127  TOOL_EVENT gridOriginUpdate = ACTIONS::gridSetOrigin.MakeEvent();
128  gridOriginUpdate.SetParameter( new VECTOR2D( m_parent->GetGridOrigin() ) );
129  mgr->ProcessEvent( gridOriginUpdate );
130  }
131 
133 
134  return wxDialog::TransferDataFromWindow();
135 }
136 
137 
139 {
142 
145 
146  m_comboBoxGrid1->SetSelection( m_parent->m_FastGrid1 );
147  m_comboBoxGrid2->SetSelection( m_parent->m_FastGrid2 );
148 
151  m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
152  m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
153 
154  return wxDialog::TransferDataToWindow();
155 }
156 
157 
158 void DIALOG_SET_GRID::OnResetGridOrgClick( wxCommandEvent& event )
159 {
160  m_gridOriginX.SetValue( 0 );
161  m_gridOriginY.SetValue( 0 );
162 }
163 
164 
166 {
167  DIALOG_SET_GRID dlg( this, m_gridSelectBox->GetStrings() );
168  return dlg.ShowModal();
169 }
170 
171 
172 void PCB_BASE_EDIT_FRAME::OnGridSettings( wxCommandEvent& event )
173 {
175 }
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:121
void SetGridOrigin(const wxPoint &aPoint) override
static const int MIN_GRID_SIZE
Implementation of conversion functions that require both schematic and board internal units.
virtual bool Validate(int aMin, int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
const wxPoint & GetGridOrigin() const override
Return the absolute coordinates of the origin of the snap grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
void OnResetGridOrgClick(wxCommandEvent &event) override
wxChoice * m_gridSelectBox
Definition: draw_frame.h:151
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:116
DIALOG_SET_GRID(PCB_BASE_FRAME *aParent, const wxArrayString &aGridChoices)
This has no dependencies on calling wxFrame derivative, such as PCB_BASE_FRAME.
Pcbnew hotkeys.
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
Definition: draw_frame.h:941
virtual EDA_HOTKEY * GetHotKeyDescription(int aCommand) const =0
Search lists of hot key identifiers (HK_xxx) used in the frame to find a matching hot key descriptor.
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use.
Definition: draw_frame.h:928
Class TOOL_MANAGER.
Definition: tool_manager.h:49
void SetParameter(T aParam)
Function SetParameter() Sets a non-standard parameter assigned to the event.
Definition: tool_event.h:399
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:76
Class TOOL_EVENT.
Definition: tool_event.h:168
wxPoint m_UserGridSize
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
void AddGrid(const GRID_TYPE &grid)
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
static const int MAX_GRID_SIZE
virtual void SetValue(int aValue)
Function SetValue Sets new value (in Internal Units) for the text field, taking care of units convers...
TOOL_EVENT MakeEvent() const
Function HasHotKey() Checks if the action has a hot key assigned.
Definition: tool_action.h:104
The common library.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Function KeyNameFromKeyCode return the key name from the key code Only some wxWidgets key values are ...
void OnGridSettings(wxCommandEvent &aEvent) override
static TOOL_ACTION gridSetOrigin
Definition: actions.h:86
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
int GetGridCmdId() const
Return the command ID of the currently selected grid.
Definition: base_screen.h:403
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.