KiCad PCB EDA Suite
gal_options_panel.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) 2017-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
25#include <wx/sizer.h>
26#include <wx/checkbox.h>
27#include <wx/choice.h>
28#include <wx/radiobox.h>
29#include <wx/spinctrl.h>
30#include <wx/stattext.h>
31#include <wx/statbox.h>
32#include <wx/statline.h>
33
34#include <ignore.h>
37#include <eda_draw_frame.h>
38
39#include <config_map.h>
40
41/*
42 * Spin control parameters
43 */
44static const double gridThicknessMin = 1.0;
45static const double gridThicknessMax = 10.0;
46static const double gridThicknessStep = 0.5;
47
48static const double gridMinSpacingMin = 5;
49static const double gridMinSpacingMax = 200;
50static const double gridMinSpacingStep = 5;
51
52
55{
56 { KIGFX::GRID_STYLE::DOTS, 0 }, // Default
59};
60
61
63{
67};
68
69
70GAL_OPTIONS_PANEL::GAL_OPTIONS_PANEL( wxWindow* aParent, APP_SETTINGS_BASE* aAppSettings ) :
71 wxPanel( aParent, wxID_ANY ),
72 m_cfg( aAppSettings )
73{
74 // the main sizer that holds "columns" of settings
75 m_mainSizer = new wxBoxSizer( wxHORIZONTAL );
76 SetSizer( m_mainSizer );
77
78 // second-level sizers that are one "column" of settings each
79 wxBoxSizer* sLeftSizer = new wxBoxSizer( wxVERTICAL );
80 m_mainSizer->Add( sLeftSizer, 1, wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
81
82 /*
83 * Rendering engine
84 */
85#ifndef __WXMAC__
86 {
87 wxString engineChoices[] = { _( "Accelerated graphics" ), _( "Fallback graphics" ) };
88 m_renderingEngine = new wxRadioBox( this, wxID_ANY, _( "Rendering Engine" ),
89 wxDefaultPosition, wxDefaultSize,
90 sizeof( engineChoices ) / sizeof( wxString ),
91 engineChoices, 1, wxRA_SPECIFY_COLS );
92 m_renderingEngine->SetItemToolTip( 0, _( "Hardware-accelerated graphics (recommended)" ) );
93 m_renderingEngine->SetItemToolTip( 1, _( "Software graphics (for computers which do not "
94 "support KiCad's hardware acceleration "
95 "requirements)" ) );
96
97 sLeftSizer->Add( m_renderingEngine, 0, wxTOP | wxBOTTOM | wxRIGHT | wxEXPAND, 5 );
98 }
99#endif
100
101 /*
102 * Grid settings subpanel
103 */
104 {
105 wxStaticText* gridLabel = new wxStaticText( this, wxID_ANY, _( "Grid Options" ) );
106 sLeftSizer->Add( gridLabel, 0, wxTOP|wxRIGHT|wxLEFT|wxEXPAND, 13 );
107
108 wxStaticLine* staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition,
109 wxDefaultSize, wxLI_HORIZONTAL );
110 sLeftSizer->Add( staticline1, 0, wxEXPAND|wxBOTTOM, 5 );
111
112 wxBoxSizer* sGridSettings = new wxBoxSizer( wxVERTICAL );
113
114 wxString m_gridStyleChoices[] = {
115 _( "Dots" ),
116 _( "Lines" ),
117 _( "Small crosses" )
118 };
119
120 int m_gridStyleNChoices = sizeof( m_gridStyleChoices ) / sizeof( wxString );
121 m_gridStyle = new wxRadioBox( this, wxID_ANY, _( "Grid Style" ), wxDefaultPosition,
122 wxDefaultSize, m_gridStyleNChoices, m_gridStyleChoices, 1,
123 wxRA_SPECIFY_COLS );
124 sGridSettings->Add( m_gridStyle, 0, wxALL | wxEXPAND, 5 );
125
126 wxFlexGridSizer* sGridSettingsGrid;
127 sGridSettingsGrid = new wxFlexGridSizer( 0, 3, 0, 0 );
128 sGridSettingsGrid->AddGrowableCol( 1 );
129 sGridSettingsGrid->SetFlexibleDirection( wxBOTH );
130 sGridSettingsGrid->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
131
132 l_gridLineWidth = new wxStaticText( this, wxID_ANY, _( "Grid thickness:" ) );
133 l_gridLineWidth->Wrap( -1 );
134 sGridSettingsGrid->Add( l_gridLineWidth, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxTOP, 5 );
135
136 m_gridLineWidth = new wxSpinCtrlDouble( this, wxID_ANY );
138 m_gridLineWidth->SetIncrement( gridThicknessStep );
139 m_gridLineWidth->SetDigits( 1 );
140 sGridSettingsGrid->Add( m_gridLineWidth, 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxTOP, 5 );
141
142 l_gridLineWidthUnits = new wxStaticText( this, wxID_ANY, _( "px" ) );
143 l_gridLineWidthUnits->Wrap( -1 );
144 sGridSettingsGrid->Add( l_gridLineWidthUnits, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT | wxTOP, 5 );
145
146 l_gridMinSpacing = new wxStaticText( this, wxID_ANY, _( "Min grid spacing:" ) );
147 l_gridMinSpacing->Wrap( -1 );
148 sGridSettingsGrid->Add( l_gridMinSpacing, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxTOP, 5 );
149
150 m_gridMinSpacing = new wxSpinCtrlDouble( this, wxID_ANY);
152 m_gridMinSpacing->SetIncrement( gridMinSpacingStep );
153 m_gridMinSpacing->SetDigits( 0 );
154 sGridSettingsGrid->Add( m_gridMinSpacing, 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxTOP, 5 );
155
156 l_gridMinSpacingUnits = new wxStaticText( this, wxID_ANY, _( "px" ) );
157 l_gridMinSpacingUnits->Wrap( -1 );
158 sGridSettingsGrid->Add( l_gridMinSpacingUnits, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxLEFT | wxTOP, 5 );
159
160 l_gridSnapOptions = new wxStaticText( this, wxID_ANY, _( "Snap to Grid:" ) );
161 l_gridSnapOptions->Wrap( -1 );
162 sGridSettingsGrid->Add( l_gridSnapOptions, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxTOP, 5 );
163
164 wxString gridSnapChoices[] = { _( "Always" ), _( "When grid shown" ), _( "Never" ) };
165 int gridSnapNChoices = sizeof( gridSnapChoices ) / sizeof( wxString );
166 m_gridSnapOptions = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
167 gridSnapNChoices, gridSnapChoices );
168 m_gridSnapOptions->Select( 0 );
169 sGridSettingsGrid->Add( m_gridSnapOptions, 0,
170 wxALIGN_CENTER_VERTICAL | wxEXPAND | wxTOP | wxBOTTOM, 5 );
171
172 l_gridSnapSpace = new wxStaticText( this, wxID_ANY, _( "px" ) );
173 l_gridSnapSpace->Wrap( -1 );
174 l_gridSnapSpace->Hide();
175 sGridSettingsGrid->Add( l_gridSnapSpace, 0,
176 wxALIGN_CENTER_VERTICAL | wxALL | wxRESERVE_SPACE_EVEN_IF_HIDDEN,
177 5 );
178
179
180 sGridSettings->Add( sGridSettingsGrid, 1, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
181
182 sLeftSizer->Add( sGridSettings, 0, wxEXPAND|wxLEFT, 5 );
183 }
184
185 /*
186 * Cursor settings subpanel
187 */
188 {
189 sLeftSizer->Add( 0, 15, 0, wxEXPAND, 5 );
190
191 wxStaticText* gridLabel = new wxStaticText( this, wxID_ANY, _( "Cursor Options" ) );
192 sLeftSizer->Add( gridLabel, 0, wxTOP|wxRIGHT|wxLEFT|wxEXPAND, 13 );
193
194 wxStaticLine* staticline2 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition,
195 wxDefaultSize, wxLI_HORIZONTAL );
196 sLeftSizer->Add( staticline2, 0, wxEXPAND|wxBOTTOM, 5 );
197
198 wxBoxSizer* sCursorSettings = new wxBoxSizer( wxVERTICAL );
199 sLeftSizer->Add( sCursorSettings, 0, wxEXPAND|wxLEFT, 5 );
200
201 wxString m_CursorShapeChoices[] = {
202 _( "Small crosshair" ),
203 _( "Full window crosshair" )
204 };
205
206 int m_CursorShapeNChoices = sizeof( m_CursorShapeChoices ) / sizeof( wxString );
207 m_cursorShape = new wxRadioBox( this, wxID_ANY, _( "Cursor Shape" ), wxDefaultPosition,
208 wxDefaultSize, m_CursorShapeNChoices, m_CursorShapeChoices,
209 1, wxRA_SPECIFY_COLS );
210
211 m_cursorShape->SetSelection( 0 );
212 m_cursorShape->SetToolTip( _( "Cursor shape for drawing, placement and movement tools" ) );
213 sCursorSettings->Add( m_cursorShape, 0, wxALL | wxEXPAND, 5 );
214
215 m_forceCursorDisplay = new wxCheckBox( this, wxID_ANY, _( "Always show crosshairs" ) );
216 sCursorSettings->Add( m_forceCursorDisplay, 0, wxALL | wxEXPAND, 5 );
217 }
218}
219
220
222{
223#ifndef __WXMAC__
224 auto canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( m_cfg->m_Graphics.canvas_type );
225
226 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL )
227 m_renderingEngine->SetSelection( 0 );
228 else
229 m_renderingEngine->SetSelection( 1 );
230#endif
231
232 m_gridSnapOptions->SetSelection( m_cfg->m_Window.grid.snap );
233 m_gridStyle->SetSelection( m_cfg->m_Window.grid.style );
236
239
240 return true;
241}
242
243
245{
246 m_cfg->m_Window.grid.snap = m_gridSnapOptions->GetSelection();
247 m_cfg->m_Window.grid.style = m_gridStyle->GetSelection();
250
253
254#ifndef __WXMAC__
255 m_cfg->m_Graphics.canvas_type = m_renderingEngine->GetSelection() == 0 ?
258#endif
259
260 return true;
261}
262
263
265{
266 APP_SETTINGS_BASE* saved = m_cfg;
267
268 m_cfg = aAppSettings;
270 m_cfg = saved;
271
272 return true;
273}
274
275
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:110
WINDOW_SETTINGS m_Window
Definition: app_settings.h:187
@ GAL_TYPE_OPENGL
OpenGL implementation.
@ GAL_TYPE_CAIRO
Cairo implementation.
bool ResetPanel(APP_SETTINGS_BASE *aAppSettings)
wxSpinCtrlDouble * m_gridMinSpacing
wxCheckBox * m_forceCursorDisplay
wxStaticText * l_gridMinSpacing
wxRadioBox * m_cursorShape
wxStaticText * l_gridMinSpacingUnits
bool TransferDataToWindow() override
Load the panel controls from the given opt.
wxRadioBox * m_renderingEngine
wxChoice * m_gridSnapOptions
wxStaticText * l_gridLineWidthUnits
bool TransferDataFromWindow() override
Read the options set in the UI into the given options object.
wxRadioBox * m_gridStyle
wxStaticText * l_gridLineWidth
wxStaticText * l_gridSnapSpace
wxBoxSizer * m_mainSizer
wxStaticText * l_gridSnapOptions
wxSpinCtrlDouble * m_gridLineWidth
GAL_OPTIONS_PANEL(wxWindow *aParent, APP_SETTINGS_BASE *aAppSettings)
APP_SETTINGS_BASE * m_cfg
#define _(s)
static const double gridMinSpacingMin
static const UTIL::CFG_MAP< KIGFX::GRID_STYLE > gridStyleSelectMap
TODO: These are duplicated in gal_display_options - Unify!
static const UTIL::CFG_MAP< KIGFX::GRID_SNAPPING > gridSnapConfigVals
static const double gridThicknessStep
static const double gridMinSpacingMax
static const double gridMinSpacingStep
static const double gridThicknessMax
static const double gridThicknessMin
@ SMALL_CROSS
Use small cross instead of dots for the grid.
@ DOTS
Use dots for the grid.
@ LINES
Use lines for the grid.
std::vector< std::pair< T, long > > CFG_MAP
A config value table is a list of native values (usually enums) to a different set of values,...
Definition: config_map.h:49
bool always_show_cursor
Definition: app_settings.h:43
bool fullscreen_cursor
Definition: app_settings.h:44
double line_width
Definition: app_settings.h:59
double min_spacing
Definition: app_settings.h:60
CURSOR_SETTINGS cursor
Definition: app_settings.h:98
GRID_SETTINGS grid
Definition: app_settings.h:99