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-2019 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 
33 
34 #include <common.h>
35 
36 #include <config_map.h>
37 
38 /*
39  * Spin control parameters
40  */
41 static const double gridThicknessMin = 1.0;
42 static const double gridThicknessMax = 10.0;
43 static const double gridThicknessStep = 0.5;
44 
45 static const double gridMinSpacingMin = 5;
46 static const double gridMinSpacingMax = 200;
47 static const double gridMinSpacingStep = 5;
48 
51 {
52  { KIGFX::GRID_STYLE::DOTS, 0 }, // Default
55 };
56 
58 {
62 };
63 
65  wxPanel( aParent, wxID_ANY ),
66  m_galOptions( aGalOpts )
67 {
68  // the main sizer that holds "columns" of settings
69  m_mainSizer = new wxBoxSizer( wxHORIZONTAL );
70  SetSizer( m_mainSizer );
71 
72  // second-level sizers that are one "column" of settings each
73  wxBoxSizer* sLeftSizer = new wxBoxSizer( wxVERTICAL );
74  m_mainSizer->Add( sLeftSizer, 1, wxALL | wxEXPAND, 0 );
75 
76  /*
77  * Grid settings subpanel
78  */
79  {
80  wxStaticBox* sGridOpts = new wxStaticBox( this, wxID_ANY, _( "Grid Options" ) );
81  wxStaticBoxSizer* sGridSettings;
82  sGridSettings = new wxStaticBoxSizer( sGridOpts, wxVERTICAL );
83 
84  wxString m_gridStyleChoices[] = {
85  _( "Dots" ),
86  _( "Lines" ),
87  _( "Small crosses" )
88  };
89  int m_gridStyleNChoices = sizeof( m_gridStyleChoices ) / sizeof( wxString );
90  m_gridStyle = new wxRadioBox( sGridSettings->GetStaticBox(),
91  wxID_ANY, _( "Grid Style" ),
92  wxDefaultPosition, wxDefaultSize,
93  m_gridStyleNChoices, m_gridStyleChoices, 1, wxRA_SPECIFY_COLS );
94  sGridSettings->Add( m_gridStyle, 0, wxALL|wxEXPAND, 5 );
95 
96  wxFlexGridSizer* sGridSettingsGrid;
97  sGridSettingsGrid = new wxFlexGridSizer( 0, 3, 0, 0 );
98  sGridSettingsGrid->AddGrowableCol( 1 );
99  sGridSettingsGrid->SetFlexibleDirection( wxBOTH );
100  sGridSettingsGrid->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
101 
102  l_gridLineWidth = new wxStaticText( sGridSettings->GetStaticBox(),
103  wxID_ANY, _( "Grid thickness:" ) );
104  l_gridLineWidth->Wrap( -1 );
105  sGridSettingsGrid->Add( l_gridLineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
106 
107  m_gridLineWidth = new wxSpinCtrlDouble( sGridSettings->GetStaticBox(), wxID_ANY );
109  m_gridLineWidth->SetIncrement( gridThicknessStep );
110  m_gridLineWidth->SetDigits( 1 );
111  sGridSettingsGrid->Add( m_gridLineWidth, 0, wxEXPAND | wxTOP | wxBOTTOM, 5 );
112 
113  l_gridLineWidthUnits = new wxStaticText( sGridSettings->GetStaticBox(),
114  wxID_ANY, _( "px" ) );
115  l_gridLineWidthUnits->Wrap( -1 );
116  sGridSettingsGrid->Add( l_gridLineWidthUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
117 
118  l_gridMinSpacing = new wxStaticText( sGridSettings->GetStaticBox(),
119  wxID_ANY, _( "Min grid spacing:" ) );
120  l_gridMinSpacing->Wrap( -1 );
121  sGridSettingsGrid->Add( l_gridMinSpacing, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
122 
123  m_gridMinSpacing = new wxSpinCtrlDouble( sGridSettings->GetStaticBox(), wxID_ANY);
125  m_gridMinSpacing->SetIncrement( gridMinSpacingStep );
126  m_gridMinSpacing->SetDigits( 0 );
127  sGridSettingsGrid->Add( m_gridMinSpacing, 0, wxEXPAND | wxTOP | wxBOTTOM, 5 );
128 
129  l_gridMinSpacingUnits = new wxStaticText( sGridSettings->GetStaticBox(),
130  wxID_ANY, _( "px" ) );
131  l_gridMinSpacingUnits->Wrap( -1 );
132  sGridSettingsGrid->Add( l_gridMinSpacingUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
133 
134  l_gridSnapOptions = new wxStaticText( sGridSettings->GetStaticBox(), wxID_ANY, _( "Snap to Grid:" ) );
135  l_gridSnapOptions->Wrap( -1 );
136  sGridSettingsGrid->Add( l_gridSnapOptions, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
137 
138  wxString gridSnapChoices[] = { _( "Always"), _("When grid shown"), _("Never") };
139  int gridSnapNChoices = sizeof( gridSnapChoices ) / sizeof( wxString );
140  m_gridSnapOptions = new wxChoice( sGridSettings->GetStaticBox(), wxID_ANY,
141  wxDefaultPosition, wxDefaultSize, gridSnapNChoices, gridSnapChoices );
142  m_gridSnapOptions->Select( 0 );
143  sGridSettingsGrid->Add( m_gridSnapOptions, 0, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxALL, 5 );
144 
145  l_gridSnapSpace = new wxStaticText( sGridSettings->GetStaticBox(),
146  wxID_ANY, _( "px" ) );
147  l_gridSnapSpace->Wrap( -1 );
148  l_gridSnapSpace->Hide();
149  sGridSettingsGrid->Add( l_gridSnapSpace, 0,
150  wxALIGN_CENTER_VERTICAL | wxALL | wxRESERVE_SPACE_EVEN_IF_HIDDEN, 5 );
151 
152 
153  sGridSettings->Add( sGridSettingsGrid, 1, wxALL | wxEXPAND, 5 );
154 
155  sLeftSizer->Add( sGridSettings, 0, wxTOP | wxBOTTOM | wxRIGHT | wxEXPAND, 5 );
156  }
157 
158  /*
159  * Cursor settings subpanel
160  */
161  {
162  auto sCursorSettings = new wxStaticBoxSizer( new wxStaticBox( this,
163  wxID_ANY, _( "Cursor Options" ) ), wxVERTICAL );
164 
165  sLeftSizer->Add( sCursorSettings, 1, wxTOP | wxRIGHT | wxEXPAND, 5 );
166 
167  wxString m_CursorShapeChoices[] = {
168  _( "Small crosshair" ),
169  _( "Full window crosshair" )
170  };
171 
172  int m_CursorShapeNChoices = sizeof( m_CursorShapeChoices ) / sizeof( wxString );
173  m_cursorShape = new wxRadioBox( this, wxID_ANY,
174  _( "Cursor Shape" ), wxDefaultPosition, wxDefaultSize,
175  m_CursorShapeNChoices, m_CursorShapeChoices, 1,
176  wxRA_SPECIFY_COLS );
177 
178  m_cursorShape->SetSelection( 0 );
179  m_cursorShape->SetToolTip( _( "Cursor shape for drawing, placement and movement tools" ) );
180  sCursorSettings->Add( m_cursorShape, 0, wxALL | wxEXPAND, 5 );
181 
182  m_forceCursorDisplay = new wxCheckBox( this, wxID_ANY, _( "Always show crosshairs" ) );
183  sCursorSettings->Add( m_forceCursorDisplay, 0, wxALL | wxEXPAND, 5 );
184  }
185 }
186 
187 
189 {
190  m_gridSnapOptions->SetSelection(
192 
193  m_gridStyle->SetSelection( UTIL::GetConfigForVal(
195 
197 
199 
201 
203 
204  return true;
205 }
206 
207 
209 {
211  m_gridSnapOptions->GetSelection() );
212 
214  gridStyleSelectMap, m_gridStyle->GetSelection() );
215 
217 
219 
221 
223 
225 
226  return true;
227 }
GAL_OPTIONS_PANEL(wxWindow *aParent, KIGFX::GAL_DISPLAY_OPTIONS &aGalOpts)
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
The grid style to draw the grid in
wxStaticText * l_gridSnapOptions
wxBoxSizer * m_mainSizer
static const UTIL::CFG_MAP< KIGFX::GRID_SNAPPING > gridSnapConfigVals
static const double gridMinSpacingMax
KIGFX::GAL_DISPLAY_OPTIONS & m_galOptions
The GAL options to read/write
bool m_forceDisplayCursor
Force cursor display
double m_gridMinSpacing
Minimum pixel distance between displayed grid lines
wxRadioBox * m_gridStyle
wxStaticText * l_gridMinSpacing
static const double gridThicknessMin
wxStaticText * l_gridSnapSpace
wxSpinCtrlDouble * m_gridMinSpacing
wxCheckBox * m_forceCursorDisplay
GRID_SNAPPING m_gridSnapping
Snapping options for the grid
bool TransferDataToWindow() override
Load the panel controls from the given opt.
wxChoice * m_gridSnapOptions
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
#define _(s)
Definition: 3d_actions.cpp:33
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
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.