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 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 
26 
27 #include <common.h>
28 
29 #include <incremental_text_ctrl.h>
30 #include <config_map.h>
31 
32 /*
33  * Spin control parameters
34  */
35 static const double gridThicknessMin = 0.5;
36 static const double gridThicknessMax = 10.0;
37 static const double gridThicknessStep = 0.5;
38 
39 static const double gridMinSpacingMin = 5;
40 static const double gridMinSpacingMax = 200;
41 static const double gridMinSpacingStep = 5;
42 
43 
45 {
46  { KIGFX::GRID_STYLE::DOTS, 0 }, // Default
49 };
50 
51 
53 {
54  { KIGFX::OPENGL_ANTIALIASING_MODE::NONE, 0 }, // Default
59 };
60 
61 
63  wxPanel( aParent, wxID_ANY ),
64  m_galOptions( aGalOpts )
65 {
66  // the main sizer that holds "columns" of settings
67  m_mainSizer = new wxBoxSizer( wxHORIZONTAL );
68  SetSizer( m_mainSizer );
69 
70  // second-level sizers that are one "column" of settings each
71  wxBoxSizer* sLeftSizer = new wxBoxSizer( wxVERTICAL );
72  m_mainSizer->Add( sLeftSizer, 1, wxALL | wxEXPAND, 0 );
73 
74  // @todo LEGACY: not required when legacy is gone
75  const wxString galOnlySuffix = _( " (OpenGL && Cairo)" );
76 
77  /*
78  * Anti-aliasing subpanel
79  */
80  {
81  wxStaticBoxSizer* sOpenGLRenderingSizer;
82  sOpenGLRenderingSizer = new wxStaticBoxSizer( new wxStaticBox( this,
83  wxID_ANY, _( "OpenGL Rendering:" ) ), wxVERTICAL );
84 
85  wxString m_choiceAntialiasingChoices[] = {
86  _( "No Antialiasing" ),
87  _( "Subpixel Antialiasing (High Quality)" ),
88  _( "Subpixel Antialiasing (Ultra Quality)" ),
89  _( "Supersampling (2x)" ),
90  _( "Supersampling (4x)" )
91  };
92  int m_choiceAntialiasingNChoices = sizeof( m_choiceAntialiasingChoices ) / sizeof( wxString );
93  m_choiceAntialiasing = new wxChoice( sOpenGLRenderingSizer->GetStaticBox(),
94  wxID_ANY, wxDefaultPosition, wxDefaultSize,
95  m_choiceAntialiasingNChoices, m_choiceAntialiasingChoices, 0 );
96  sOpenGLRenderingSizer->Add( m_choiceAntialiasing, 0, wxALL|wxEXPAND, 5 );
97 
98  sLeftSizer->Add( sOpenGLRenderingSizer, 0, wxALL|wxEXPAND, 5 );
99  }
100 
101  /*
102  * Grid setting subpanel
103  */
104  {
105  wxStaticBoxSizer* sGridSettings;
106  sGridSettings = new wxStaticBoxSizer( new wxStaticBox( this,
107  wxID_ANY, _( "Grid Display" ) + galOnlySuffix ), wxVERTICAL );
108 
109  wxString m_gridStyleChoices[] = {
110  _( "Dots" ),
111  _( "Lines" ),
112  _( "Small crosses" )
113  };
114  int m_gridStyleNChoices = sizeof( m_gridStyleChoices ) / sizeof( wxString );
115  m_gridStyle = new wxRadioBox( sGridSettings->GetStaticBox(),
116  wxID_ANY, _( "Grid Style" ),
117  wxDefaultPosition, wxDefaultSize,
118  m_gridStyleNChoices, m_gridStyleChoices, 1, wxRA_SPECIFY_COLS );
119  sGridSettings->Add( m_gridStyle, 0, wxALL|wxEXPAND, 5 );
120 
121  wxFlexGridSizer* sGridSettingsGrid;
122  sGridSettingsGrid = new wxFlexGridSizer( 0, 4, 0, 0 );
123  sGridSettingsGrid->AddGrowableCol( 1 );
124  sGridSettingsGrid->SetFlexibleDirection( wxBOTH );
125  sGridSettingsGrid->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
126 
127  l_gridLineWidth = new wxStaticText( sGridSettings->GetStaticBox(),
128  wxID_ANY, _( "Grid thickness:" ) );
129  l_gridLineWidth->Wrap( -1 );
130  sGridSettingsGrid->Add( l_gridLineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
131 
132  m_gridLineWidth = new wxTextCtrl( sGridSettings->GetStaticBox(), wxID_ANY );
133  sGridSettingsGrid->Add( m_gridLineWidth, 0, wxEXPAND, 5 );
134 
135  m_gridLineWidthSpinBtn = new wxSpinButton( sGridSettings->GetStaticBox(),
136  wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS );
137  sGridSettingsGrid->Add( m_gridLineWidthSpinBtn, 0, wxEXPAND | wxALL, 0 );
138 
139  l_gridLineWidthUnits = new wxStaticText( sGridSettings->GetStaticBox(),
140  wxID_ANY, _( "px" ) );
141  l_gridLineWidthUnits->Wrap( -1 );
142  sGridSettingsGrid->Add( l_gridLineWidthUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
143 
144  l_gridMinSpacing = new wxStaticText( sGridSettings->GetStaticBox(),
145  wxID_ANY, _( "Min grid spacing:" ) );
146  l_gridMinSpacing->Wrap( -1 );
147  sGridSettingsGrid->Add( l_gridMinSpacing, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
148 
149  m_gridMinSpacing = new wxTextCtrl( sGridSettings->GetStaticBox(), wxID_ANY);
150  sGridSettingsGrid->Add( m_gridMinSpacing, 0, wxEXPAND, 5 );
151 
152  m_gridMinSpacingSpinBtn = new wxSpinButton( sGridSettings->GetStaticBox(),
153  wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS );
154  sGridSettingsGrid->Add( m_gridMinSpacingSpinBtn, 0, wxEXPAND | wxALL, 0 );
155 
156  l_gridMinSpacingUnits = new wxStaticText( sGridSettings->GetStaticBox(),
157  wxID_ANY, _( "px" ) );
158  l_gridMinSpacingUnits->Wrap( -1 );
159  sGridSettingsGrid->Add( l_gridMinSpacingUnits, 0, wxALL, 5 );
160 
161  sGridSettings->Add( sGridSettingsGrid, 1, wxALL|wxEXPAND, 5 );
162 
163  sLeftSizer->Add( sGridSettings, 0, wxALL | wxEXPAND, 5 );
164 
165  // bind the spin buttons and text boxes
166  m_gridSizeIncrementer = std::make_unique<SPIN_INCREMENTAL_TEXT_CTRL>(
168 
171  m_gridSizeIncrementer->SetPrecision( 1 );
172 
173  m_gridMinSpacingIncrementer = std::make_unique<SPIN_INCREMENTAL_TEXT_CTRL>(
175 
178  m_gridMinSpacingIncrementer->SetPrecision( 0 ); // restrict to ints
179  }
180 
181  {
182  auto sCursorSettings = new wxStaticBoxSizer( new wxStaticBox( this,
183  wxID_ANY, _( "Cursor Display" ) ), wxVERTICAL );
184 
185  sLeftSizer->Add( sCursorSettings, 1, wxALL | wxEXPAND, 5 );
186 
187  wxString m_CursorShapeChoices[] = {
188  _( "Small cross" ),
189  _( "Full screen cursor" )
190  };
191 
192  wxString cursorShapeTitle = _( "Cursor Shape" );
193 
194  // cursor is not shown in legacy on OSX, so this setting won't
195  // do anything there
196  // @todo LEGACY remove this
197 #ifdef __APPLE__
198  cursorShapeTitle += galOnlySuffix;
199 #endif
200 
201  int m_CursorShapeNChoices = sizeof( m_CursorShapeChoices ) / sizeof( wxString );
202  m_cursorShape = new wxRadioBox( this, wxID_ANY,
203  cursorShapeTitle, wxDefaultPosition, wxDefaultSize,
204  m_CursorShapeNChoices, m_CursorShapeChoices, 1, wxRA_SPECIFY_COLS );
205 
206  m_cursorShape->SetSelection( 0 );
207  m_cursorShape->SetToolTip( _( "Main cursor shape selection (small cross or large cursor)" ) );
208 
209  sCursorSettings->Add( m_cursorShape, 0, wxALL | wxEXPAND, 5 );
210 
211  m_forceCursorDisplay = new wxCheckBox( this, wxID_ANY, _( "Always display cursor" ) + galOnlySuffix );
212 
213  sCursorSettings->Add( m_forceCursorDisplay, 0, wxALL | wxEXPAND, 5 );
214  }
215 }
216 
217 
219 {
222 
223  m_gridStyle->SetSelection( UTIL::GetConfigForVal(
225 
227 
229 
231 
233 
234  return true;
235 }
236 
237 
239 {
241  aaModeSelectMap, m_choiceAntialiasing->GetSelection() );
242 
244  gridStyleSelectMap, m_gridStyle->GetSelection() );
245 
247 
249 
251 
253 
255 
256  return true;
257 }
GAL_OPTIONS_PANEL(wxWindow *aParent, KIGFX::GAL_DISPLAY_OPTIONS &aGalOpts)
static const UTIL::CFG_MAP< KIGFX::GRID_STYLE > gridStyleSelectMap
wxStaticText * l_gridMinSpacingUnits
Use lines for the grid.
wxTextCtrl * m_gridLineWidth
wxRadioBox * m_cursorShape
KIGFX::GRID_STYLE m_gridStyle
The grid style to draw the grid in
wxBoxSizer * m_mainSizer
static const UTIL::CFG_MAP< KIGFX::OPENGL_ANTIALIASING_MODE > aaModeSelectMap
static const double gridMinSpacingMax
wxTextCtrl * m_gridMinSpacing
std::unique_ptr< INCREMENTAL_TEXT_CTRL > m_gridMinSpacingIncrementer
KIGFX::GAL_DISPLAY_OPTIONS & m_galOptions
The GAL options to read/write
bool m_forceDisplayCursor
Force cursor display
std::unique_ptr< INCREMENTAL_TEXT_CTRL > m_gridSizeIncrementer
double m_gridMinSpacing
Minimum pixel distance between displayed grid lines
wxRadioBox * m_gridStyle
wxStaticText * l_gridMinSpacing
OPENGL_ANTIALIASING_MODE gl_antialiasing_mode
static const double gridThicknessMin
wxCheckBox * m_forceCursorDisplay
wxChoice * m_choiceAntialiasing
bool TransferDataToWindow() override
Load the panel controls from the given opt.
wxSpinButton * m_gridLineWidthSpinBtn
static CFG_NATIVE_VAL< MAP > GetValFromConfig(const MAP &aMap, long aConf)
Get the native value corresponding to the config value (read from file or UI, probably) and find it i...
Definition: config_map.h:96
Use dots for the grid.
Use small cross instead of dots for the grid.
wxStaticText * l_gridLineWidthUnits
wxStaticText * l_gridLineWidth
static const double gridThicknessStep
static const double gridThicknessMax
double m_gridLineWidth
Thickness to render grid lines/dots
The common library.
static const double gridMinSpacingStep
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
static const double gridMinSpacingMin
wxSpinButton * m_gridMinSpacingSpinBtn
bool m_fullscreenCursor
Fullscreen crosshair or small cross
static long GetConfigForVal(const MAP &aMap, CFG_NATIVE_VAL< MAP > aVal)
Get the mapped config value (the one to write to file, or use in an index) from the given native (pro...
Definition: config_map.h:69
bool TransferDataFromWindow() override
Read the options set in the UI into the given options object.