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 <id.h>
32 #include <tool/common_tools.h>
33 #include <math/util.h> // for KiROUND
34 
35 // Max values for grid size
36 static const int MAX_GRID_SIZE = KiROUND( 1000.0 * IU_PER_MM );
37 static const int MIN_GRID_SIZE = KiROUND( 0.001 * IU_PER_MM );
38 
39 
41 {
43  wxArrayString m_fast_grid_opts;
44 
45 public:
47  DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices );
48 
49  bool TransferDataFromWindow() override;
50  bool TransferDataToWindow() override;
51 
52 private:
53  void OnResetGridOrgClick( wxCommandEvent& event ) override;
54 
59 };
60 
61 
62 DIALOG_SET_GRID::DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices ):
63  DIALOG_SET_GRID_BASE( aParent ),
64  m_parent( aParent ),
65  m_fast_grid_opts( aGridChoices ),
66  m_gridOriginX( aParent, m_staticTextGridPosX, m_GridOriginXCtrl, m_TextPosXUnits ),
67  m_gridOriginY( aParent, m_staticTextGridPosY, m_GridOriginYCtrl, m_TextPosYUnits ),
68  m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits ),
69  m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits )
70 {
71  m_grid1Ctrl->Append( m_fast_grid_opts );
72  m_grid2Ctrl->Append( m_fast_grid_opts );
73 
74  m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key
76 
77  Layout();
78 
79  // Now all widgets have the size fixed, call FinishDialogSettings
81 }
82 
83 
85 {
86  // Validate new settings
88  return false;
89 
91  return false;
92 
93  // Apply the new settings
94 
95  // Because grid origin is saved in board, show as modified
96  m_parent->OnModify();
99  m_parent->m_FastGrid1 = m_grid1Ctrl->GetSelection();
100  m_parent->m_FastGrid2 = m_grid2Ctrl->GetSelection();
101 
102  // User grid
103  BASE_SCREEN* screen = m_parent->GetScreen();
105 
106  // If the user grid is the current option, recall SetGrid()
107  // to force new values put in list as current grid value
108  if( screen->GetGridCmdId() == ID_POPUP_GRID_USER )
109  screen->SetGrid( ID_POPUP_GRID_USER );
110 
111  // Notify GAL
113  mgr->GetTool<COMMON_TOOLS>()->GridPreset( screen->GetGridCmdId() - ID_POPUP_GRID_LEVEL_1000 );
115 
117 
118  return wxDialog::TransferDataFromWindow();
119 }
120 
121 
123 {
126 
129 
130  m_grid1Ctrl->SetSelection( m_parent->m_FastGrid1 );
131  m_grid2Ctrl->SetSelection( m_parent->m_FastGrid2 );
132 
133  int hk1 = ACTIONS::gridFast1.GetHotKey();
134  int hk2 = ACTIONS::gridFast2.GetHotKey();
135  m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
136  m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
137 
138  return wxDialog::TransferDataToWindow();
139 }
140 
141 
142 void DIALOG_SET_GRID::OnResetGridOrgClick( wxCommandEvent& event )
143 {
144  m_gridOriginX.SetValue( 0 );
145  m_gridOriginY.SetValue( 0 );
146 }
147 
148 
149 void PCB_BASE_EDIT_FRAME::OnGridSettings( wxCommandEvent& event )
150 {
151  DIALOG_SET_GRID dlg( this, m_gridSelectBox->GetStrings() );
152 
153  dlg.ShowModal();
154 
155  UpdateStatusBar();
156  GetCanvas()->Refresh();
157 }
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
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.
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:139
static TOOL_ACTION gridFast1
Definition: actions.h:128
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:115
DIALOG_SET_GRID(SCH_BASE_FRAME *aParent)
TOOL_MANAGER.
Definition: tool_manager.h:50
static TOOL_ACTION gridFast2
Definition: actions.h:129
VECTOR2< double > VECTOR2D
Definition: vector2d.h:593
BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
wxPoint m_UserGridSize
virtual bool Validate(long long int aMin, long long int aMax, bool setFocusOnError=true)
Function Validate Validates the control against the given range, informing the user of any errors fou...
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...
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...
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:61
The common library.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual long long int GetValue()
Function GetValue Returns the current value in Internal Units.
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:132
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
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.