KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_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-2023 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 <bitmaps.h>
25#include <confirm.h>
26#include <wx/textdlg.h>
30#include <common.h>
32#include <eda_draw_frame.h>
33#include <tool/tool_manager.h>
34#include <tool/actions.h>
35#include <tool/grid_menu.h>
36#include <tool/common_tools.h>
37#include <pgm_base.h>
39
40PANEL_GRID_SETTINGS::PANEL_GRID_SETTINGS( wxWindow* aParent, UNITS_PROVIDER* aUnitsProvider,
41 wxWindow* aEventSource, APP_SETTINGS_BASE* aCfg,
42 FRAME_T aFrameType ) :
43 PANEL_GRID_SETTINGS_BASE( aParent ),
44 m_unitsProvider( aUnitsProvider ),
45 m_cfg( aCfg ),
46 m_frameType( aFrameType ),
47 m_eventSource( aEventSource )
48{
50
52 {
53 m_checkGridOverrideConnected->SetLabel( wxT( "Footprints/pads:" ) );
54 m_checkGridOverrideWires->SetLabel( wxT( "Tracks:" ) );
55 }
56 else
57 {
58 m_gridOverrideViasChoice->SetSelection( 0 );
59 m_gridOverrideViasChoice->Show( false );
60 m_checkGridOverrideVias->Show( false );
61
66 {
67 m_checkGridOverrideConnected->Show( false );
68 m_gridOverrideConnectedChoice->Show( false );
69
70 m_checkGridOverrideWires->Show( false );
71 m_gridOverrideWiresChoice->Show( false );
72 }
73 }
74
75 int hk1 = ACTIONS::gridFast1.GetHotKey();
76 int hk2 = ACTIONS::gridFast2.GetHotKey();
77 m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
78 m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
79
80 m_addGridButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
81 m_removeGridButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
82 m_moveUpButton->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
83 m_moveDownButton->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
84
85 Layout();
86}
87
88
90{
94}
95
96
98{
99 wxString savedCurrentGrid = m_currentGridCtrl->GetStringSelection();
100
101 wxString savedGrid1 = m_grid1Ctrl->GetStringSelection();
102 wxString savedGrid2 = m_grid2Ctrl->GetStringSelection();
103
104 wxString savedConnectables = m_gridOverrideConnectedChoice->GetStringSelection();
105 wxString savedWires = m_gridOverrideWiresChoice->GetStringSelection();
106 wxString savedVias = m_gridOverrideViasChoice->GetStringSelection();
107 wxString savedText = m_gridOverrideTextChoice->GetStringSelection();
108 wxString savedGraphics = m_gridOverrideGraphicsChoice->GetStringSelection();
109
110 wxArrayString grids;
111 wxString msg;
113 EDA_UNITS primaryUnit;
114 EDA_UNITS secondaryUnit;
115
116 m_unitsProvider->GetUnitPair( primaryUnit, secondaryUnit );
117
118 for( const struct GRID& grid : m_cfg->m_Window.grid.grids )
119 {
120 wxString name = grid.name;
121
122 if( !name.IsEmpty() )
123 name += wxT( ": " );
124
125 msg.Printf( _( "%s%s (%s)" ), name, grid.MessageText( scale, primaryUnit, true ),
126 grid.MessageText( scale, secondaryUnit, true ) );
127
128 grids.Add( msg );
129 }
130
131 m_currentGridCtrl->Set( grids );
132
133 m_grid1Ctrl->Set( grids );
134 m_grid2Ctrl->Set( grids );
135
136 m_gridOverrideConnectedChoice->Set( grids );
137 m_gridOverrideWiresChoice->Set( grids );
138 m_gridOverrideViasChoice->Set( grids );
139 m_gridOverrideTextChoice->Set( grids );
140 m_gridOverrideGraphicsChoice->Set( grids );
141
142 if( !m_currentGridCtrl->SetStringSelection( savedCurrentGrid ) )
143 m_currentGridCtrl->SetStringSelection( grids.front() );
144
145 if( !m_grid1Ctrl->SetStringSelection( savedGrid1 ) )
146 m_grid1Ctrl->SetStringSelection( grids.front() );
147
148 if( !m_grid2Ctrl->SetStringSelection( savedGrid2 ) )
149 m_grid2Ctrl->SetStringSelection( grids.back() );
150
151 if( !m_gridOverrideConnectedChoice->SetStringSelection( savedConnectables ) )
152 m_gridOverrideConnectedChoice->SetStringSelection( grids.front() );
153
154 if( !m_gridOverrideWiresChoice->SetStringSelection( savedWires ) )
155 m_gridOverrideWiresChoice->SetStringSelection( grids.front() );
156
157 if( !m_gridOverrideViasChoice->SetStringSelection( savedVias ) )
158 m_gridOverrideViasChoice->SetStringSelection( grids.front() );
159
160 if( !m_gridOverrideTextChoice->SetStringSelection( savedText ) )
161 m_gridOverrideTextChoice->SetStringSelection( grids.front() );
162
163 if( !m_gridOverrideGraphicsChoice->SetStringSelection( savedGraphics ) )
164 m_gridOverrideGraphicsChoice->SetStringSelection( grids.front() );
165}
166
167
169{
170 // Apply the new settings
171 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
172
173 gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
174
175 gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
176 gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
177
180 gridCfg.override_wires = m_checkGridOverrideWires->GetValue();
181 gridCfg.override_wires_idx = m_gridOverrideWiresChoice->GetSelection();
182 gridCfg.override_vias = m_checkGridOverrideVias->GetValue();
183 gridCfg.override_vias_idx = m_gridOverrideViasChoice->GetSelection();
184 gridCfg.override_text = m_checkGridOverrideText->GetValue();
185 gridCfg.override_text_idx = m_gridOverrideTextChoice->GetSelection();
187 gridCfg.override_graphics_idx = m_gridOverrideGraphicsChoice->GetSelection();
188
189 return RESETTABLE_PANEL::TransferDataFromWindow();
190}
191
192
194{
195 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
196
197 // lambda that gives us a safe index into grids regardless of config idx
198 auto safeGrid = [&gridCfg]( int idx ) -> int
199 {
200 if( idx < 0 || idx >= (int) gridCfg.grids.size() )
201 return 0;
202
203 return idx;
204 };
205
206 Layout();
207
208 m_currentGridCtrl->SetSelection( safeGrid( gridCfg.last_size_idx ) );
209
210 m_grid1Ctrl->SetSelection( safeGrid( gridCfg.fast_grid_1 ) );
211 m_grid2Ctrl->SetSelection( safeGrid( gridCfg.fast_grid_2 ) );
212
213 m_gridOverrideConnectedChoice->SetSelection( safeGrid( gridCfg.override_connected_idx ) );
214 m_gridOverrideWiresChoice->SetSelection( safeGrid( gridCfg.override_wires_idx ) );
215 m_gridOverrideViasChoice->SetSelection( safeGrid( gridCfg.override_vias_idx ) );
216 m_gridOverrideTextChoice->SetSelection( safeGrid( gridCfg.override_text_idx ) );
217 m_gridOverrideGraphicsChoice->SetSelection( safeGrid( gridCfg.override_graphics_idx ) );
218
219 m_checkGridOverrideConnected->SetValue( safeGrid( gridCfg.override_connected ) );
220 m_checkGridOverrideWires->SetValue( safeGrid( gridCfg.override_wires ) );
221 m_checkGridOverrideVias->SetValue( safeGrid( gridCfg.override_vias ) );
222 m_checkGridOverrideText->SetValue( safeGrid( gridCfg.override_text ) );
223 m_checkGridOverrideGraphics->SetValue( safeGrid( gridCfg.override_graphics ) );
224
225 return RESETTABLE_PANEL::TransferDataToWindow();
226}
227
228
229void PANEL_GRID_SETTINGS::OnAddGrid( wxCommandEvent& event )
230{
231 GRID newGrid = GRID{ wxEmptyString, "", "" };
232 DIALOG_GRID_SETTINGS dlg( this->GetParent(), m_eventSource, m_unitsProvider, newGrid );
233
234 if( dlg.ShowModal() != wxID_OK )
235 return;
236
237 int row = m_currentGridCtrl->GetSelection();
238 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
239
240 for( GRID& g : gridCfg.grids )
241 {
242 if( newGrid == g )
243 {
244 DisplayError( this, wxString::Format( _( "Grid size '%s' already exists." ),
246 return;
247 }
248 }
249
250 gridCfg.grids.insert( gridCfg.grids.begin() + row, newGrid );
252 m_currentGridCtrl->SetSelection( row );
253}
254
255
256void PANEL_GRID_SETTINGS::OnRemoveGrid( wxCommandEvent& event )
257{
258 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
259 int row = m_currentGridCtrl->GetSelection();
260
261 if( gridCfg.grids.size() <= 1 )
262 {
263 DisplayError( this, wxString::Format( _( "At least one grid size is required." ) ) );
264 return;
265 }
266
267 gridCfg.grids.erase( gridCfg.grids.begin() + row );
269
270 if( row != 0 )
271 m_currentGridCtrl->SetSelection( row - 1 );
272}
273
274
275void PANEL_GRID_SETTINGS::OnMoveGridUp( wxCommandEvent& event )
276{
277 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
278 int row = m_currentGridCtrl->GetSelection();
279
280 if( gridCfg.grids.size() <= 1 || row == 0 )
281 return;
282
283 std::swap( gridCfg.grids[row], gridCfg.grids[row - 1] );
285
286 if( row != 0 )
287 m_currentGridCtrl->SetSelection( row - 1 );
288}
289
290
291void PANEL_GRID_SETTINGS::OnMoveGridDown( wxCommandEvent& event )
292{
293 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
294 int row = m_currentGridCtrl->GetSelection();
295
296 if( gridCfg.grids.size() <= 1 || row == ( (int) gridCfg.grids.size() - 1 ) )
297 return;
298
299 std::swap( gridCfg.grids[row], gridCfg.grids[row + 1] );
301
302 if( row != 0 )
303 m_currentGridCtrl->SetSelection( row + 1 );
304}
const char * name
Definition: DXF_plotter.cpp:57
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
static TOOL_ACTION gridFast1
Definition: actions.h:140
static TOOL_ACTION gridFast2
Definition: actions.h:141
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
WINDOW_SETTINGS m_Window
Definition: app_settings.h:169
const std::vector< GRID > DefaultGridSizeList() const
Class PANEL_GRID_SETTINGS_BASE.
STD_BITMAP_BUTTON * m_removeGridButton
STD_BITMAP_BUTTON * m_moveDownButton
STD_BITMAP_BUTTON * m_addGridButton
STD_BITMAP_BUTTON * m_moveUpButton
void ResetPanel() override
Reset the contents of this panel.
bool TransferDataToWindow() override
void OnRemoveGrid(wxCommandEvent &event) override
void OnMoveGridDown(wxCommandEvent &event) override
bool TransferDataFromWindow() override
APP_SETTINGS_BASE * m_cfg
void OnMoveGridUp(wxCommandEvent &event) override
PANEL_GRID_SETTINGS(wxWindow *aParent, UNITS_PROVIDER *aUnitsProvider, wxWindow *aEventSource, APP_SETTINGS_BASE *aCfg, FRAME_T aFrameType)
This has no dependencies on calling wxFrame derivative, such as PCB_BASE_FRAME.
UNITS_PROVIDER * m_unitsProvider
void OnAddGrid(wxCommandEvent &event) override
void SetBitmap(const wxBitmapBundle &aBmp)
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:313
const EDA_IU_SCALE & GetIuScale() const
virtual void GetUnitPair(EDA_UNITS &aPrimaryUnit, EDA_UNITS &aSecondaryUnits)
The common library.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
This file is part of the common library.
#define _(s)
EDA_UNITS
Definition: eda_units.h:46
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
@ FRAME_PCB_EDITOR
Definition: frame_type.h:42
@ 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_SIMULATOR
Definition: frame_type.h:38
@ FRAME_FOOTPRINT_EDITOR
Definition: frame_type.h:43
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
see class PGM_BASE
const int scale
int override_connected_idx
Definition: grid_settings.h:80
bool override_graphics
Definition: grid_settings.h:87
bool override_connected
Definition: grid_settings.h:79
std::vector< GRID > grids
Definition: grid_settings.h:66
int override_graphics_idx
Definition: grid_settings.h:88
int override_wires_idx
Definition: grid_settings.h:82
Common grid settings, available to every frame.
Definition: grid_settings.h:34
wxString UserUnitsMessageText(UNITS_PROVIDER *aProvider, bool aDisplayUnits=true) const
Returns a string representation of the grid in the user's units.
GRID_SETTINGS grid
Definition: app_settings.h:81