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>
35 #include <eda_draw_frame.h>
36 
37 #include <config_map.h>
38 
39 /*
40  * Spin control parameters
41  */
42 static const double gridThicknessMin = 1.0;
43 static const double gridThicknessMax = 10.0;
44 static const double gridThicknessStep = 0.5;
45 
46 static const double gridMinSpacingMin = 5;
47 static const double gridMinSpacingMax = 200;
48 static const double gridMinSpacingStep = 5;
49 
50 
53 {
54  { KIGFX::GRID_STYLE::DOTS, 0 }, // Default
57 };
58 
59 
61 {
65 };
66 
67 
68 GAL_OPTIONS_PANEL::GAL_OPTIONS_PANEL( wxWindow* aParent, EDA_DRAW_FRAME* aDrawFrame ) :
69  wxPanel( aParent, wxID_ANY ),
70  m_drawFrame( aDrawFrame ),
71  m_galOptions( aDrawFrame->GetGalDisplayOptions() )
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__
219  m_renderingEngine->SetSelection( 0 );
220  else
221  m_renderingEngine->SetSelection( 1 );
222 #else
224 #endif
225 
228 
231 
233 
235 
237 
239 
240  return true;
241 }
242 
243 
245 {
247  m_gridSnapOptions->GetSelection() );
248 
250  m_gridStyle->GetSelection() );
251 
253 
255 
257 
259 
260 #ifndef __WXMAC__
261  EDA_DRAW_PANEL_GAL::GAL_TYPE wantedType = m_renderingEngine->GetSelection() == 0 ?
265 
266  if( wantedType != currentType )
267  m_drawFrame->GetCanvas()->SwitchBackend( wantedType );
268 #endif
269 
270  return true;
271 }
static const UTIL::CFG_MAP< KIGFX::GRID_STYLE > gridStyleSelectMap
TODO: These are duplicated in gal_display_options - Unify!
wxStaticText * l_gridMinSpacingUnits
Use lines for the grid.
wxRadioBox * m_cursorShape
KIGFX::GRID_STYLE m_gridStyle
Snapping options for the grid.
wxRadioBox * m_renderingEngine
wxStaticText * l_gridSnapOptions
wxBoxSizer * m_mainSizer
virtual bool SwitchBackend(GAL_TYPE aGalType)
Switch method of rendering graphics.
static const UTIL::CFG_MAP< KIGFX::GRID_SNAPPING > gridSnapConfigVals
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
static const double gridMinSpacingMax
KIGFX::GAL_DISPLAY_OPTIONS & m_galOptions
bool m_forceDisplayCursor
The pixel scale factor (>1 for hi-DPI scaled displays)
The base class for create windows for drawing purpose.
double m_gridMinSpacing
Whether or not to draw the coordinate system axes.
wxRadioBox * m_gridStyle
wxStaticText * l_gridMinSpacing
static const double gridThicknessMin
wxStaticText * l_gridSnapSpace
EDA_DRAW_FRAME * m_drawFrame
wxSpinCtrlDouble * m_gridMinSpacing
wxCheckBox * m_forceCursorDisplay
The GAL options to read/write.
GRID_SNAPPING m_gridSnapping
Thickness to render grid lines/dots.
bool TransferDataToWindow() override
Load the panel controls from the given opt.
wxChoice * m_gridSnapOptions
#define _(s)
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
wxSpinCtrlDouble * m_gridLineWidth
wxStaticText * l_gridLineWidth
static const double gridThicknessStep
static const double gridThicknessMax
double m_gridLineWidth
Minimum pixel distance between displayed grid lines.
void ignore_unused(const T &)
Definition: ignore.h:24
static const double gridMinSpacingStep
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
GAL_OPTIONS_PANEL(wxWindow *aParent, EDA_DRAW_FRAME *aDrawFrame)
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
bool m_fullscreenCursor
Force cursor display.
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.