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-2024 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 <wx/textdlg.h>
29#include <common.h>
30#include <confirm.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{
49 m_currentGridCtrl->SetMinSize( FromDIP( m_currentGridCtrl->GetMinSize() ) );
51
53 {
54 m_checkGridOverrideConnected->SetLabel( _( "Footprints/pads:" ) );
55 m_checkGridOverrideWires->SetLabel( _( "Tracks:" ) );
56 }
57 else
58 {
59 m_gridOverrideViasChoice->SetSelection( 0 );
60 m_gridOverrideViasChoice->Show( false );
61 m_checkGridOverrideVias->Show( false );
62
67 {
68 m_checkGridOverrideConnected->Show( false );
69 m_gridOverrideConnectedChoice->Show( false );
70
71 m_checkGridOverrideWires->Show( false );
72 m_gridOverrideWiresChoice->Show( false );
73 }
74
76 {
77 m_overridesLabel->Show( false );
78 m_staticline3->Show( false );
79
80 m_checkGridOverrideText->Show( false );
81 m_gridOverrideTextChoice->Show( false );
82
83 m_checkGridOverrideGraphics->Show( false );
84 m_gridOverrideGraphicsChoice->Show( false );
85 }
86 }
87
88 int hk1 = ACTIONS::gridFast1.GetHotKey();
89 int hk2 = ACTIONS::gridFast2.GetHotKey();
90 m_grid1HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk1 ) ) );
91 m_grid2HotKey->SetLabel( wxString::Format( wxT( "(%s)" ), KeyNameFromKeyCode( hk2 ) ) );
92
93 m_addGridButton->SetBitmap( KiBitmapBundle( BITMAPS::small_plus ) );
94 m_removeGridButton->SetBitmap( KiBitmapBundle( BITMAPS::small_trash ) );
95 m_moveUpButton->SetBitmap( KiBitmapBundle( BITMAPS::small_up ) );
96 m_moveDownButton->SetBitmap( KiBitmapBundle( BITMAPS::small_down ) );
97
98 Layout();
99}
100
101
103{
107}
108
109
111{
112 wxString savedCurrentGrid = m_currentGridCtrl->GetStringSelection();
113
114 wxString savedGrid1 = m_grid1Ctrl->GetStringSelection();
115 wxString savedGrid2 = m_grid2Ctrl->GetStringSelection();
116
117 wxString savedConnectables = m_gridOverrideConnectedChoice->GetStringSelection();
118 wxString savedWires = m_gridOverrideWiresChoice->GetStringSelection();
119 wxString savedVias = m_gridOverrideViasChoice->GetStringSelection();
120 wxString savedText = m_gridOverrideTextChoice->GetStringSelection();
121 wxString savedGraphics = m_gridOverrideGraphicsChoice->GetStringSelection();
122
123 wxArrayString grids;
124 wxString msg;
126 EDA_UNITS primaryUnit;
127 EDA_UNITS secondaryUnit;
128
129 m_unitsProvider->GetUnitPair( primaryUnit, secondaryUnit );
130
131 for( const struct GRID& grid : m_cfg->m_Window.grid.grids )
132 {
133 wxString name = grid.name;
134
135 if( !name.IsEmpty() )
136 name += wxT( ": " );
137
138 msg.Printf( _( "%s%s (%s)" ), name, grid.MessageText( scale, primaryUnit, true ),
139 grid.MessageText( scale, secondaryUnit, true ) );
140
141 grids.Add( msg );
142 }
143
144 m_currentGridCtrl->Set( grids );
145
146 m_grid1Ctrl->Set( grids );
147 m_grid2Ctrl->Set( grids );
148
149 m_gridOverrideConnectedChoice->Set( grids );
150 m_gridOverrideWiresChoice->Set( grids );
151 m_gridOverrideViasChoice->Set( grids );
152 m_gridOverrideTextChoice->Set( grids );
153 m_gridOverrideGraphicsChoice->Set( grids );
154
155 if( !m_currentGridCtrl->SetStringSelection( savedCurrentGrid ) )
156 m_currentGridCtrl->SetStringSelection( grids.front() );
157
158 if( !m_grid1Ctrl->SetStringSelection( savedGrid1 ) )
159 m_grid1Ctrl->SetStringSelection( grids.front() );
160
161 if( !m_grid2Ctrl->SetStringSelection( savedGrid2 ) )
162 m_grid2Ctrl->SetStringSelection( grids.back() );
163
164 if( !m_gridOverrideConnectedChoice->SetStringSelection( savedConnectables ) )
165 m_gridOverrideConnectedChoice->SetStringSelection( grids.front() );
166
167 if( !m_gridOverrideWiresChoice->SetStringSelection( savedWires ) )
168 m_gridOverrideWiresChoice->SetStringSelection( grids.front() );
169
170 if( !m_gridOverrideViasChoice->SetStringSelection( savedVias ) )
171 m_gridOverrideViasChoice->SetStringSelection( grids.front() );
172
173 if( !m_gridOverrideTextChoice->SetStringSelection( savedText ) )
174 m_gridOverrideTextChoice->SetStringSelection( grids.front() );
175
176 if( !m_gridOverrideGraphicsChoice->SetStringSelection( savedGraphics ) )
177 m_gridOverrideGraphicsChoice->SetStringSelection( grids.front() );
178}
179
180
182{
183 // Apply the new settings
184 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
185
186 gridCfg.last_size_idx = m_currentGridCtrl->GetSelection();
187
188 gridCfg.fast_grid_1 = m_grid1Ctrl->GetSelection();
189 gridCfg.fast_grid_2 = m_grid2Ctrl->GetSelection();
190
193 gridCfg.override_wires = m_checkGridOverrideWires->GetValue();
194 gridCfg.override_wires_idx = m_gridOverrideWiresChoice->GetSelection();
195 gridCfg.override_vias = m_checkGridOverrideVias->GetValue();
196 gridCfg.override_vias_idx = m_gridOverrideViasChoice->GetSelection();
197 gridCfg.override_text = m_checkGridOverrideText->GetValue();
198 gridCfg.override_text_idx = m_gridOverrideTextChoice->GetSelection();
200 gridCfg.override_graphics_idx = m_gridOverrideGraphicsChoice->GetSelection();
201
202 return RESETTABLE_PANEL::TransferDataFromWindow();
203}
204
205
207{
208 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
209
210 // lambda that gives us a safe index into grids regardless of config idx
211 auto safeGrid = [&gridCfg]( int idx ) -> int
212 {
213 if( idx < 0 || idx >= (int) gridCfg.grids.size() )
214 return 0;
215
216 return idx;
217 };
218
219 Layout();
220
221 m_currentGridCtrl->SetSelection( safeGrid( gridCfg.last_size_idx ) );
222
223 m_grid1Ctrl->SetSelection( safeGrid( gridCfg.fast_grid_1 ) );
224 m_grid2Ctrl->SetSelection( safeGrid( gridCfg.fast_grid_2 ) );
225
226 m_gridOverrideConnectedChoice->SetSelection( safeGrid( gridCfg.override_connected_idx ) );
227 m_gridOverrideWiresChoice->SetSelection( safeGrid( gridCfg.override_wires_idx ) );
228 m_gridOverrideViasChoice->SetSelection( safeGrid( gridCfg.override_vias_idx ) );
229 m_gridOverrideTextChoice->SetSelection( safeGrid( gridCfg.override_text_idx ) );
230 m_gridOverrideGraphicsChoice->SetSelection( safeGrid( gridCfg.override_graphics_idx ) );
231
232 m_checkGridOverrideConnected->SetValue( safeGrid( gridCfg.override_connected ) );
233 m_checkGridOverrideWires->SetValue( safeGrid( gridCfg.override_wires ) );
234 m_checkGridOverrideVias->SetValue( safeGrid( gridCfg.override_vias ) );
235 m_checkGridOverrideText->SetValue( safeGrid( gridCfg.override_text ) );
236 m_checkGridOverrideGraphics->SetValue( safeGrid( gridCfg.override_graphics ) );
237
238 return RESETTABLE_PANEL::TransferDataToWindow();
239}
240
241
242void PANEL_GRID_SETTINGS::OnAddGrid( wxCommandEvent& event )
243{
244 GRID newGrid = GRID{ wxEmptyString, "", "" };
245 DIALOG_GRID_SETTINGS dlg( wxGetTopLevelParent( this ), m_eventSource, m_unitsProvider,
246 newGrid );
247
248 if( dlg.ShowModal() != wxID_OK )
249 return;
250
251 int row = m_currentGridCtrl->GetSelection();
252 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
253
254 for( GRID& g : gridCfg.grids )
255 {
256 if( newGrid == g )
257 {
258 wxWindow* topLevelParent = wxGetTopLevelParent( this );
259
260 DisplayError( topLevelParent,
261 wxString::Format( _( "Grid size '%s' already exists." ),
263 return;
264 }
265 }
266
267 gridCfg.grids.insert( gridCfg.grids.begin() + row, newGrid );
269 m_currentGridCtrl->SetSelection( row );
270}
271
272
273void PANEL_GRID_SETTINGS::OnRemoveGrid( wxCommandEvent& event )
274{
275 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
276 int row = m_currentGridCtrl->GetSelection();
277
278 if( gridCfg.grids.size() <= 1 )
279 {
280 wxWindow* topLevelParent = wxGetTopLevelParent( this );
281
282 DisplayError( topLevelParent,
283 wxString::Format( _( "At least one grid size is required." ) ) );
284 return;
285 }
286
287 gridCfg.grids.erase( gridCfg.grids.begin() + row );
289
290 if( row != 0 )
291 m_currentGridCtrl->SetSelection( row - 1 );
292}
293
294
295void PANEL_GRID_SETTINGS::OnMoveGridUp( wxCommandEvent& event )
296{
297 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
298 int row = m_currentGridCtrl->GetSelection();
299
300 if( gridCfg.grids.size() <= 1 || row == 0 )
301 return;
302
303 std::swap( gridCfg.grids[row], gridCfg.grids[row - 1] );
305
306 if( row != 0 )
307 m_currentGridCtrl->SetSelection( row - 1 );
308}
309
310
311void PANEL_GRID_SETTINGS::OnMoveGridDown( wxCommandEvent& event )
312{
313 GRID_SETTINGS& gridCfg = m_cfg->m_Window.grid;
314 int row = m_currentGridCtrl->GetSelection();
315
316 if( gridCfg.grids.size() <= 1 || row == ( (int) gridCfg.grids.size() - 1 ) )
317 return;
318
319 std::swap( gridCfg.grids[row], gridCfg.grids[row + 1] );
321
322 if( row != 0 )
323 m_currentGridCtrl->SetSelection( row + 1 );
324}
const char * name
Definition: DXF_plotter.cpp:57
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
static TOOL_ACTION gridFast1
Definition: actions.h:164
static TOOL_ACTION gridFast2
Definition: actions.h:165
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:172
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:170
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
@ FRAME_GERBER
Definition: frame_type.h:57
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