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 
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 = 1.0;
36 static const double gridThicknessMax = 10.0;
37 static const double gridThicknessStep = 1.0;
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  wxPanel( aParent, wxID_ANY ),
54  m_galOptions( aGalOpts )
55 {
56  // the main sizer that holds "columns" of settings
57  m_mainSizer = new wxBoxSizer( wxHORIZONTAL );
58  SetSizer( m_mainSizer );
59 
60  // second-level sizers that are one "column" of settings each
61  wxBoxSizer* sLeftSizer = new wxBoxSizer( wxVERTICAL );
62  m_mainSizer->Add( sLeftSizer, 1, wxALL | wxEXPAND, 0 );
63 
64  // @todo LEGACY: not required when legacy is gone
65  const wxString galOnlySuffix = _( " (not supported in Legacy Toolset)" );
66 
67  /*
68  * Grid settings subpanel
69  */
70  {
71  wxStaticBoxSizer* sGridSettings;
72  sGridSettings = new wxStaticBoxSizer( new wxStaticBox( this,
73  wxID_ANY, _( "Grid Options" ) + galOnlySuffix ), wxVERTICAL );
74 
75  wxString m_gridStyleChoices[] = {
76  _( "Dots" ),
77  _( "Lines" ),
78  _( "Small crosses" )
79  };
80  int m_gridStyleNChoices = sizeof( m_gridStyleChoices ) / sizeof( wxString );
81  m_gridStyle = new wxRadioBox( sGridSettings->GetStaticBox(),
82  wxID_ANY, _( "Grid Style" ),
83  wxDefaultPosition, wxDefaultSize,
84  m_gridStyleNChoices, m_gridStyleChoices, 1, wxRA_SPECIFY_COLS );
85  sGridSettings->Add( m_gridStyle, 0, wxALL|wxEXPAND, 5 );
86 
87  wxFlexGridSizer* sGridSettingsGrid;
88  sGridSettingsGrid = new wxFlexGridSizer( 0, 4, 0, 0 );
89  sGridSettingsGrid->AddGrowableCol( 1 );
90  sGridSettingsGrid->SetFlexibleDirection( wxBOTH );
91  sGridSettingsGrid->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
92 
93  l_gridLineWidth = new wxStaticText( sGridSettings->GetStaticBox(),
94  wxID_ANY, _( "Grid thickness:" ) );
95  l_gridLineWidth->Wrap( -1 );
96  sGridSettingsGrid->Add( l_gridLineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
97 
98  m_gridLineWidth = new wxTextCtrl( sGridSettings->GetStaticBox(), wxID_ANY );
99  sGridSettingsGrid->Add( m_gridLineWidth, 0, wxEXPAND | wxTOP | wxBOTTOM, 5 );
100 
101  m_gridLineWidthSpinBtn = new wxSpinButton( sGridSettings->GetStaticBox(),
102  wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS );
103  sGridSettingsGrid->Add( m_gridLineWidthSpinBtn, 0,
104  wxEXPAND | wxTOP | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 3 );
105 
106  l_gridLineWidthUnits = new wxStaticText( sGridSettings->GetStaticBox(),
107  wxID_ANY, _( "px" ) );
108  l_gridLineWidthUnits->Wrap( -1 );
109  sGridSettingsGrid->Add( l_gridLineWidthUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
110 
111  l_gridMinSpacing = new wxStaticText( sGridSettings->GetStaticBox(),
112  wxID_ANY, _( "Min grid spacing:" ) );
113  l_gridMinSpacing->Wrap( -1 );
114  sGridSettingsGrid->Add( l_gridMinSpacing, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
115 
116  m_gridMinSpacing = new wxTextCtrl( sGridSettings->GetStaticBox(), wxID_ANY);
117  sGridSettingsGrid->Add( m_gridMinSpacing, 0, wxEXPAND | wxTOP | wxBOTTOM, 5 );
118 
119  m_gridMinSpacingSpinBtn = new wxSpinButton( sGridSettings->GetStaticBox(),
120  wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS );
121  sGridSettingsGrid->Add( m_gridMinSpacingSpinBtn, 0,
122  wxEXPAND | wxTOP | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 3 );
123 
124  l_gridMinSpacingUnits = new wxStaticText( sGridSettings->GetStaticBox(),
125  wxID_ANY, _( "px" ) );
126  l_gridMinSpacingUnits->Wrap( -1 );
127  sGridSettingsGrid->Add( l_gridMinSpacingUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
128 
129  sGridSettings->Add( sGridSettingsGrid, 1, wxALL | wxEXPAND, 5 );
130 
131  sLeftSizer->Add( sGridSettings, 0, wxTOP | wxBOTTOM | wxRIGHT | wxEXPAND, 5 );
132 
133  // bind the spin buttons and text boxes
134  m_gridSizeIncrementer = std::make_unique<SPIN_INCREMENTAL_TEXT_CTRL>(
136 
139  m_gridSizeIncrementer->SetPrecision( 0 );
140 
141  m_gridMinSpacingIncrementer = std::make_unique<SPIN_INCREMENTAL_TEXT_CTRL>(
143 
146  m_gridMinSpacingIncrementer->SetPrecision( 0 ); // restrict to ints
147  }
148 
149  /*
150  * Cursor settings subpanel
151  */
152  {
153  wxString cursorDisplayTitle = _( "Cursor Options" );
154 
155  // cursor is not shown in legacy on OSX
156  // @todo LEGACY remove this
157 #ifdef __APPLE__
158  cursorDisplayTitle += galOnlySuffix;
159 #endif
160 
161  auto sCursorSettings = new wxStaticBoxSizer( new wxStaticBox( this,
162  wxID_ANY, cursorDisplayTitle ), wxVERTICAL );
163 
164  sLeftSizer->Add( sCursorSettings, 1, wxTOP | wxRIGHT | wxEXPAND, 5 );
165 
166  wxString m_CursorShapeChoices[] = {
167  _( "Small crosshair" ),
168  _( "Full window crosshair" )
169  };
170 
171  int m_CursorShapeNChoices = sizeof( m_CursorShapeChoices ) / sizeof( wxString );
172  m_cursorShape = new wxRadioBox( this, wxID_ANY,
173  _( "Cursor Shape:" ), wxDefaultPosition, wxDefaultSize,
174  m_CursorShapeNChoices, m_CursorShapeChoices, 1,
175  wxRA_SPECIFY_COLS );
176 
177  m_cursorShape->SetSelection( 0 );
178  m_cursorShape->SetToolTip( _( "Cursor shape for drawing, placement and movement tools" ) );
179 
180  sCursorSettings->Add( m_cursorShape, 0, wxALL | wxEXPAND, 5 );
181 
182 #ifdef __APPLE__
183  // Whole section is galOnly on OSX; no need for further qualifier here
184  m_forceCursorDisplay = new wxCheckBox( this, wxID_ANY, _( "Always show crosshairs" ) );
185 #else
186  // User a shorter galOnly qualifier as otherwise the label is obnoxiously long
187  // @todo LEGACY remove this
188  m_forceCursorDisplay = new wxCheckBox( this, wxID_ANY,
189  _( "Always show crosshairs (not in Legacy)" ) );
190 #endif
191 
192  sCursorSettings->Add( m_forceCursorDisplay, 0, wxALL | wxEXPAND, 5 );
193  }
194 }
195 
196 
198 {
199  m_gridStyle->SetSelection( UTIL::GetConfigForVal(
201 
203 
205 
207 
209 
210  return true;
211 }
212 
213 
215 {
217  gridStyleSelectMap, m_gridStyle->GetSelection() );
218 
219  m_galOptions.m_gridLineWidth = std::floor( m_gridSizeIncrementer->GetValue() + 0.5 );
220 
222 
224 
226 
228 
229  return true;
230 }
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 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
static const double gridThicknessMin
wxCheckBox * m_forceCursorDisplay
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.