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_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 ),
80 {
83 
84  m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
86 
87  Layout();
88 
89  // Now all widgets have the size fixed, call FinishDialogSettings
91 }
92 
93 
95 {
96  // Validate new settings
97  if( !m_gridOriginX.Validate( true ) )
98  return false;
99 
100  if( !m_gridOriginY.Validate( true ) )
101  return false;
102 
103  if( !m_userGridX.Validate( true ) )
104  return false;
105 
106  if( !m_userGridY.Validate( true ) )
107  return false;
108 
109  // Apply the new settings
110 
111  // Because grid origin is saved in board, show as modified
112  m_parent->OnModify();
115  m_parent->m_FastGrid1 = m_comboBoxGrid1->GetSelection();
116  m_parent->m_FastGrid2 = m_comboBoxGrid2->GetSelection();
117 
118  // User grid
119  BASE_SCREEN* screen = m_parent->GetScreen();
121 
122  // If the user grid is the current option, recall SetGrid()
123  // to force new values put in list as current grid value
124  if( screen->GetGridCmdId() == ID_POPUP_GRID_USER )
125  screen->SetGrid( ID_POPUP_GRID_USER );
126 
127  // Notify GAL
129 
130  if( mgr && m_parent->IsGalCanvasActive() )
131  {
132  mgr->RunAction( "common.Control.gridPreset", true,
134 
135  TOOL_EVENT gridOriginUpdate = ACTIONS::gridSetOrigin.MakeEvent();
136  gridOriginUpdate.SetParameter( new VECTOR2D( m_parent->GetGridOrigin() ) );
137  mgr->ProcessEvent( gridOriginUpdate );
138  }
139 
140  return wxDialog::TransferDataFromWindow();
141 }
142 
143 
145 {
148 
151 
152  m_comboBoxGrid1->SetSelection( m_parent->m_FastGrid1 );
153  m_comboBoxGrid2->SetSelection( m_parent->m_FastGrid2 );
154 
157  m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
158  m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
159 
160  return wxDialog::TransferDataToWindow();
161 }
162 
163 
164 void DIALOG_SET_GRID::OnResetGridOrgClick( wxCommandEvent& event )
165 {
166  m_gridOriginX.SetValue( 0 );
167  m_gridOriginY.SetValue( 0 );
168 }
169 
170 
172 {
173  DIALOG_SET_GRID dlg( this, m_gridSelectBox->GetStrings() );
174  return dlg.ShowModal();
175 }
virtual bool Validate(bool setFocusOnError=false)
Function Validate Validates the control, informing the user of any errors found.
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:120
void SetGridOrigin(const wxPoint &aPoint) override
static const int MIN_GRID_SIZE
Implementation of conversion functions that require both schematic and board internal units...
int GetGridCmdId() const
Return the command ID of the currently selected grid.
Definition: base_screen.h:403
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
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:115
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.
Classes used in Pcbnew, CvPcb and GerbView.
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.
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
bool IsGalCanvasActive() const
Function IsGalCanvasActive is used to check which canvas (GAL-based or standard) is currently in use...
Definition: draw_frame.h:911
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...
TOOL_MANAGER * GetToolManager() const
Return the tool manager instance, if any.
Definition: draw_frame.h:924
void AddGrid(const GRID_TYPE &grid)
TOOL_EVENT MakeEvent() const
Function HasHotKey() Checks if the action has a hot key assigned.
Definition: tool_action.h:104
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...
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 ...
Class DIALOG_SET_GRID_BASE.
static TOOL_ACTION gridSetOrigin
Definition: actions.h:86
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...