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-2021 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
33#include <ignore.h>
36#include <eda_draw_frame.h>
37
38#include <config_map.h>
39
40/*
41 * Spin control parameters
42 */
43static const double gridThicknessMin = 1.0;
44static const double gridThicknessMax = 10.0;
45static const double gridThicknessStep = 0.5;
46
47static const double gridMinSpacingMin = 5;
48static const double gridMinSpacingMax = 200;
49static const double gridMinSpacingStep = 5;
50
51
54{
55 { KIGFX::GRID_STYLE::DOTS, 0 }, // Default
58};
59
60
62{
66};
67
68
69GAL_OPTIONS_PANEL::GAL_OPTIONS_PANEL( wxWindow* aParent, APP_SETTINGS_BASE* aAppSettings ) :
70 wxPanel( aParent, wxID_ANY ),
71 m_cfg( aAppSettings )
72{
73 // the main sizer that holds "columns" of settings
74 m_mainSizer = new wxBoxSizer( wxHORIZONTAL );
75 SetSizer( m_mainSizer );
76
77 // second-level sizers that are one "column" of settings each
78 wxBoxSizer* sLeftSizer = new wxBoxSizer( wxVERTICAL );
79 m_mainSizer->Add( sLeftSizer, 1, wxALL | wxEXPAND, 0 );
80
81 /*
82 * Rendering engine
83 */
84#ifndef __WXMAC__
85 {
86 wxString engineChoices[] = { _( "Accelerated graphics" ), _( "Fallback graphics" ) };
87 m_renderingEngine = new wxRadioBox( this, wxID_ANY, _( "Rendering Engine" ),
88 wxDefaultPosition, wxDefaultSize,
89 sizeof( engineChoices ) / sizeof( wxString ),
90 engineChoices, 1, wxRA_SPECIFY_COLS );
91 m_renderingEngine->SetItemToolTip( 0, _( "Hardware-accelerated graphics (recommended)" ) );
92 m_renderingEngine->SetItemToolTip( 1, _( "Software graphics (for computers which do not "
93 "support KiCad's hardware acceleration "
94 "requirements)" ) );
95
96 sLeftSizer->Add( m_renderingEngine, 0, wxTOP | wxBOTTOM | wxRIGHT | wxEXPAND, 5 );
97 }
98#endif
99
100 /*
101 * Grid settings subpanel
102 */
103 {
104 wxStaticBox* sGridOpts = new wxStaticBox( this, wxID_ANY, _( "Grid Options" ) );
105 wxStaticBoxSizer* sGridSettings;
106 sGridSettings = new wxStaticBoxSizer( sGridOpts, wxVERTICAL );
107
108 wxString m_gridStyleChoices[] = {
109 _( "Dots" ),
110 _( "Lines" ),
111 _( "Small crosses" )
112 };
113
114 int m_gridStyleNChoices = sizeof( m_gridStyleChoices ) / sizeof( wxString );
115 m_gridStyle = new wxRadioBox( sGridSettings->GetStaticBox(), wxID_ANY, _( "Grid Style" ),
116 wxDefaultPosition, wxDefaultSize, m_gridStyleNChoices,
117 m_gridStyleChoices, 1, wxRA_SPECIFY_COLS );
118 sGridSettings->Add( m_gridStyle, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
119
120 wxFlexGridSizer* sGridSettingsGrid;
121 sGridSettingsGrid = new wxFlexGridSizer( 0, 3, 0, 0 );
122 sGridSettingsGrid->AddGrowableCol( 1 );
123 sGridSettingsGrid->SetFlexibleDirection( wxBOTH );
124 sGridSettingsGrid->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
125
126 l_gridLineWidth = new wxStaticText( sGridSettings->GetStaticBox(), wxID_ANY,
127 _( "Grid thickness:" ) );
128 l_gridLineWidth->Wrap( -1 );
129 sGridSettingsGrid->Add( l_gridLineWidth, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
130
131 m_gridLineWidth = new wxSpinCtrlDouble( sGridSettings->GetStaticBox(), wxID_ANY );
133 m_gridLineWidth->SetIncrement( gridThicknessStep );
134 m_gridLineWidth->SetDigits( 1 );
135 sGridSettingsGrid->Add( m_gridLineWidth, 0, wxEXPAND | wxTOP | wxBOTTOM, 5 );
136
137 l_gridLineWidthUnits = new wxStaticText( sGridSettings->GetStaticBox(), wxID_ANY,
138 _( "px" ) );
139 l_gridLineWidthUnits->Wrap( -1 );
140 sGridSettingsGrid->Add( l_gridLineWidthUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
141
142 l_gridMinSpacing = new wxStaticText( sGridSettings->GetStaticBox(), wxID_ANY,
143 _( "Min grid spacing:" ) );
144 l_gridMinSpacing->Wrap( -1 );
145 sGridSettingsGrid->Add( l_gridMinSpacing, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
146
147 m_gridMinSpacing = new wxSpinCtrlDouble( sGridSettings->GetStaticBox(), wxID_ANY);
149 m_gridMinSpacing->SetIncrement( gridMinSpacingStep );
150 m_gridMinSpacing->SetDigits( 0 );
151 sGridSettingsGrid->Add( m_gridMinSpacing, 0, wxEXPAND | wxTOP | wxBOTTOM, 5 );
152
153 l_gridMinSpacingUnits = new wxStaticText( sGridSettings->GetStaticBox(), wxID_ANY,
154 _( "px" ) );
155 l_gridMinSpacingUnits->Wrap( -1 );
156 sGridSettingsGrid->Add( l_gridMinSpacingUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
157
158 l_gridSnapOptions = new wxStaticText( sGridSettings->GetStaticBox(), wxID_ANY,
159 _( "Snap to Grid:" ) );
160 l_gridSnapOptions->Wrap( -1 );
161 sGridSettingsGrid->Add( l_gridSnapOptions, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
162
163 wxString gridSnapChoices[] = { _( "Always" ), _( "When grid shown" ), _( "Never" ) };
164 int gridSnapNChoices = sizeof( gridSnapChoices ) / sizeof( wxString );
165 m_gridSnapOptions = new wxChoice( sGridSettings->GetStaticBox(), wxID_ANY,
166 wxDefaultPosition, wxDefaultSize, gridSnapNChoices,
167 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( sGridSettings->GetStaticBox(), 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, wxALL | wxEXPAND, 5 );
181
182 sLeftSizer->Add( sGridSettings, 0, wxTOP | wxBOTTOM | wxRIGHT | wxEXPAND, 5 );
183 }
184
185 /*
186 * Cursor settings subpanel
187 */
188 {
189 wxStaticBox* sbCursorSettings = new wxStaticBox( this, wxID_ANY, _( "Cursor Options" ) );
190 wxStaticBoxSizer* sCursorSettings = new wxStaticBoxSizer( sbCursorSettings, wxVERTICAL );
191
192 sLeftSizer->Add( sCursorSettings, 1, wxTOP | wxRIGHT | wxEXPAND, 5 );
193
194 wxString m_CursorShapeChoices[] = {
195 _( "Small crosshair" ),
196 _( "Full window crosshair" )
197 };
198
199 int m_CursorShapeNChoices = sizeof( m_CursorShapeChoices ) / sizeof( wxString );
200 m_cursorShape = new wxRadioBox( this, wxID_ANY,
201 _( "Cursor Shape" ), wxDefaultPosition, wxDefaultSize,
202 m_CursorShapeNChoices, m_CursorShapeChoices, 1,
203 wxRA_SPECIFY_COLS );
204
205 m_cursorShape->SetSelection( 0 );
206 m_cursorShape->SetToolTip( _( "Cursor shape for drawing, placement and movement tools" ) );
207 sCursorSettings->Add( m_cursorShape, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxEXPAND, 5 );
208
209 m_forceCursorDisplay = new wxCheckBox( this, wxID_ANY, _( "Always show crosshairs" ) );
210 sCursorSettings->Add( m_forceCursorDisplay, 0, wxALL | wxEXPAND, 5 );
211 }
212}
213
214
216{
217#ifndef __WXMAC__
218 auto canvasType = static_cast<EDA_DRAW_PANEL_GAL::GAL_TYPE>( m_cfg->m_Graphics.canvas_type );
219
220 if( canvasType == EDA_DRAW_PANEL_GAL::GAL_TYPE_OPENGL )
221 m_renderingEngine->SetSelection( 0 );
222 else
223 m_renderingEngine->SetSelection( 1 );
224#endif
225
226 m_gridSnapOptions->SetSelection( m_cfg->m_Window.grid.snap );
227 m_gridStyle->SetSelection( m_cfg->m_Window.grid.style );
230
233
234 return true;
235}
236
237
239{
240 m_cfg->m_Window.grid.snap = m_gridSnapOptions->GetSelection();
241 m_cfg->m_Window.grid.style = m_gridStyle->GetSelection();
244
247
248#ifndef __WXMAC__
249 m_cfg->m_Graphics.canvas_type = m_renderingEngine->GetSelection() == 0 ?
252#endif
253
254 return true;
255}
256
257
259{
260 APP_SETTINGS_BASE* saved = m_cfg;
261
262 m_cfg = aAppSettings;
264 m_cfg = saved;
265
266 return true;
267}
268
269
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:101
WINDOW_SETTINGS m_Window
Definition: app_settings.h:184
@ 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:89
GRID_SETTINGS grid
Definition: app_settings.h:90