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  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, wxEXPAND | wxALL, 0 );
104 
105  l_gridLineWidthUnits = new wxStaticText( sGridSettings->GetStaticBox(),
106  wxID_ANY, _( "px" ) );
107  l_gridLineWidthUnits->Wrap( -1 );
108  sGridSettingsGrid->Add( l_gridLineWidthUnits, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
109 
110  l_gridMinSpacing = new wxStaticText( sGridSettings->GetStaticBox(),
111  wxID_ANY, _( "Min grid spacing:" ) );
112  l_gridMinSpacing->Wrap( -1 );
113  sGridSettingsGrid->Add( l_gridMinSpacing, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
114 
115  m_gridMinSpacing = new wxTextCtrl( sGridSettings->GetStaticBox(), wxID_ANY);
116  sGridSettingsGrid->Add( m_gridMinSpacing, 0, wxEXPAND | wxTOP | wxBOTTOM, 5 );
117 
118  m_gridMinSpacingSpinBtn = new wxSpinButton( sGridSettings->GetStaticBox(),
119  wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS );
120  sGridSettingsGrid->Add( m_gridMinSpacingSpinBtn, 0, wxEXPAND | wxALL, 0 );
121 
122  l_gridMinSpacingUnits = new wxStaticText( sGridSettings->GetStaticBox(),
123  wxID_ANY, _( "px" ) );
124  l_gridMinSpacingUnits->Wrap( -1 );
125  sGridSettingsGrid->Add( l_gridMinSpacingUnits, 0, wxALL, 5 );
126 
127  sGridSettings->Add( sGridSettingsGrid, 1, wxALL|wxEXPAND, 5 );
128 
129  sLeftSizer->Add( sGridSettings, 0, wxTOP | wxBOTTOM | wxRIGHT | wxEXPAND, 5 );
130 
131  // bind the spin buttons and text boxes
132  m_gridSizeIncrementer = std::make_unique<SPIN_INCREMENTAL_TEXT_CTRL>(
134 
137  m_gridSizeIncrementer->SetPrecision( 1 );
138 
139  m_gridMinSpacingIncrementer = std::make_unique<SPIN_INCREMENTAL_TEXT_CTRL>(
141 
144  m_gridMinSpacingIncrementer->SetPrecision( 0 ); // restrict to ints
145  }
146 
147  /*
148  * Cursor settings subpanel
149  */
150  {
151  wxString cursorDisplayTitle = _( "Cursor Options" );
152 
153  // cursor is not shown in legacy on OSX
154  // @todo LEGACY remove this
155 #ifdef __APPLE__
156  cursorDisplayTitle += galOnlySuffix;
157 #endif
158 
159  auto sCursorSettings = new wxStaticBoxSizer( new wxStaticBox( this,
160  wxID_ANY, cursorDisplayTitle ), wxVERTICAL );
161 
162  sLeftSizer->Add( sCursorSettings, 1, wxTOP | wxRIGHT | wxEXPAND, 5 );
163 
164  wxString m_CursorShapeChoices[] = {
165  _( "Small crosshair" ),
166  _( "Full window crosshair" )
167  };
168 
169  int m_CursorShapeNChoices = sizeof( m_CursorShapeChoices ) / sizeof( wxString );
170  m_cursorShape = new wxRadioBox( this, wxID_ANY,
171  _( "Cursor shape:" ), wxDefaultPosition, wxDefaultSize,
172  m_CursorShapeNChoices, m_CursorShapeChoices, 1,
173  wxRA_SPECIFY_COLS );
174 
175  m_cursorShape->SetSelection( 0 );
176  m_cursorShape->SetToolTip( _( "Cursor shape for drawing, placement and movement tools" ) );
177 
178  sCursorSettings->Add( m_cursorShape, 0, wxALL | wxEXPAND, 5 );
179 
180 #ifdef __APPLE__
181  // Whole section is galOnly on OSX; no need for further qualifier here
182  m_forceCursorDisplay = new wxCheckBox( this, wxID_ANY, _( "Always show crosshairs" ) );
183 #else
184  // User a shorter galOnly qualifier as otherwise the label is obnoxiously long
185  // @todo LEGACY remove this
186  m_forceCursorDisplay = new wxCheckBox( this, wxID_ANY,
187  _( "Always show crosshairs (not in Legacy)" ) );
188 #endif
189 
190  sCursorSettings->Add( m_forceCursorDisplay, 0, wxALL | wxEXPAND, 5 );
191  }
192 }
193 
194 
196 {
197  m_gridStyle->SetSelection( UTIL::GetConfigForVal(
199 
201 
203 
205 
207 
208  return true;
209 }
210 
211 
213 {
215  gridStyleSelectMap, m_gridStyle->GetSelection() );
216 
218 
220 
222 
224 
226 
227  return true;
228 }
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.