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 
24 #include <dialog_set_grid_base.h>
25 #include <base_units.h>
26 #include <common.h>
27 #include <widgets/unit_binder.h>
28 #include <pcb_base_edit_frame.h>
29 #include <tools/pcb_actions.h>
30 #include <tool/tool_manager.h>
31 #include <pcbnew_id.h>
32 #include <tool/common_tools.h>
33 
34 // Max values for grid size
35 static const int MAX_GRID_SIZE = KiROUND( 1000.0 * IU_PER_MM );
36 static const int MIN_GRID_SIZE = KiROUND( 0.001 * IU_PER_MM );
37 
38 
40 {
42  wxArrayString m_fast_grid_opts;
43 
44 public:
46  DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices );
47 
48  bool TransferDataFromWindow() override;
49  bool TransferDataToWindow() override;
50 
51 private:
52  void OnResetGridOrgClick( wxCommandEvent& event ) override;
53 
58 };
59 
60 
61 DIALOG_SET_GRID::DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices ):
62  DIALOG_SET_GRID_BASE( aParent ),
63  m_parent( aParent ),
64  m_fast_grid_opts( aGridChoices ),
65  m_gridOriginX( aParent, m_staticTextGridPosX, m_GridOriginXCtrl, m_TextPosXUnits ),
66  m_gridOriginY( aParent, m_staticTextGridPosY, m_GridOriginYCtrl, m_TextPosYUnits ),
67  m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits ),
68  m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits )
69 {
70  m_grid1Ctrl->Append( m_fast_grid_opts );
71  m_grid2Ctrl->Append( m_fast_grid_opts );
72 
73  m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
75 
76  Layout();
77 
78  // Now all widgets have the size fixed, call FinishDialogSettings
80 }
81 
82 
84 {
85  // Validate new settings
87  return false;
88 
90  return false;
91 
92  // Apply the new settings
93 
94  // Because grid origin is saved in board, show as modified
95  m_parent->OnModify();
98  m_parent->m_FastGrid1 = m_grid1Ctrl->GetSelection();
99  m_parent->m_FastGrid2 = m_grid2Ctrl->GetSelection();
100 
101  // User grid
102  BASE_SCREEN* screen = m_parent->GetScreen();
104 
105  // If the user grid is the current option, recall SetGrid()
106  // to force new values put in list as current grid value
107  if( screen->GetGridCmdId() == ID_POPUP_GRID_USER )
108  screen->SetGrid( ID_POPUP_GRID_USER );
109 
110  // Notify GAL
112  mgr->GetTool<COMMON_TOOLS>()->GridPreset( screen->GetGridCmdId() - ID_POPUP_GRID_LEVEL_1000 );
114 
116 
117  return wxDialog::TransferDataFromWindow();
118 }
119 
120 
122 {
125 
128 
129  m_grid1Ctrl->SetSelection( m_parent->m_FastGrid1 );
130  m_grid2Ctrl->SetSelection( m_parent->m_FastGrid2 );
131 
132  int hk1 = ACTIONS::gridFast1.GetHotKey();
133  int hk2 = ACTIONS::gridFast2.GetHotKey();
134  m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
135  m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
136 
137  return wxDialog::TransferDataToWindow();
138 }
139 
140 
141 void DIALOG_SET_GRID::OnResetGridOrgClick( wxCommandEvent& event )
142 {
143  m_gridOriginX.SetValue( 0 );
144  m_gridOriginY.SetValue( 0 );
145 }
146 
147 
148 void PCB_BASE_EDIT_FRAME::OnGridSettings( wxCommandEvent& event )
149 {
150  DIALOG_SET_GRID dlg( this, m_gridSelectBox->GetStrings() );
151 
152  dlg.ShowModal();
153 
154  UpdateStatusBar();
155  GetCanvas()->Refresh();
156 }
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
static int KiROUND(double v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:115
void SetGridOrigin(const wxPoint &aPoint) override
static const int MIN_GRID_SIZE
Implementation of conversion functions that require both schematic and board internal units.
void AddGrid(const GRID_TYPE &aGrid)
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
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:109
static TOOL_ACTION gridFast1
Definition: actions.h:124
void OnResetGridOrgClick(wxCommandEvent &event) override
wxChoice * m_gridSelectBox
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:118
DIALOG_SET_GRID(PCB_BASE_FRAME *aParent, const wxArrayString &aGridChoices)
This has no dependencies on calling wxFrame derivative, such as PCB_BASE_FRAME.
virtual int GetValue()
Function GetValue Returns the current value in Internal Units.
Class TOOL_MANAGER.
Definition: tool_manager.h:50
static TOOL_ACTION gridFast2
Definition: actions.h:125
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
wxPoint m_UserGridSize
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
Class COMMON_TOOLS.
Definition: common_tools.h:38
void UpdateGridSelectBox()
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
virtual void UpdateStatusBar() override
Update the status bar information.
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 ...
void OnGridSettings(wxCommandEvent &aEvent) override
static TOOL_ACTION gridSetOrigin
Definition: actions.h:128
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:272
int GetHotKey() const
Function GetHotKey() Returns the hotkey keycode which initiates the action.
Definition: tool_action.h:90
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.