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/radiobox.h>
28 #include <wx/spinctrl.h>
29 #include <wx/stattext.h>
30 
32 
33 #include <common.h>
34 
35 #include <config_map.h>
36 
37 /*
38  * Spin control parameters
39  */
40 static const double gridThicknessMin = 1.0;
41 static const double gridThicknessMax = 10.0;
42 static const double gridThicknessStep = 0.5;
43 
44 static const double gridMinSpacingMin = 5;
45 static const double gridMinSpacingMax = 200;
46 static const double gridMinSpacingStep = 5;
47 
48 
50 {
51  { KIGFX::GRID_STYLE::DOTS, 0 }, // Default
54 };
55 
56 
58  wxPanel( aParent, wxID_ANY ),
59  m_galOptions( aGalOpts )
60 {
61  // the main sizer that holds "columns" of settings
62  m_mainSizer = new wxBoxSizer( wxHORIZONTAL );
63  SetSizer( m_mainSizer );
64 
65  // second-level sizers that are one "column" of settings each
66  wxBoxSizer* sLeftSizer = new wxBoxSizer( wxVERTICAL );
67  m_mainSizer->Add( sLeftSizer, 1, wxALL | wxEXPAND, 0 );
68 
69  /*
70  * Grid settings subpanel
71  */
72  {
73  wxStaticBox* sGridOpts = new wxStaticBox( this, wxID_ANY, _( "Grid Options" ) );
74  wxStaticBoxSizer* sGridSettings;
75  sGridSettings = new wxStaticBoxSizer( sGridOpts, wxVERTICAL );
76 
77  wxString m_gridStyleChoices[] = {
78  _( "Dots" ),
79  _( "Lines" ),
80  _( "Small crosses" )
81  };
82  int m_gridStyleNChoices = sizeof( m_gridStyleChoices ) / sizeof( wxString );
83  m_gridStyle = new wxRadioBox( sGridSettings->GetStaticBox(),
84  wxID_ANY, _( "Grid Style" ),
85  wxDefaultPosition, wxDefaultSize,
86  m_gridStyleNChoices, m_gridStyleChoices, 1, wxRA_SPECIFY_COLS );
87  sGridSettings->Add( m_gridStyle, 0, wxALL|wxEXPAND, 5 );
88 
89  wxFlexGridSizer* sGridSettingsGrid;
90  sGridSettingsGrid = new wxFlexGridSizer( 0, 3, 0, 0 );
91  sGridSettingsGrid->AddGrowableCol( 1 );
92  sGridSettingsGrid->SetFlexibleDirection( wxBOTH );
93  sGridSettingsGrid->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
94 
95  l_gridLineWidth = new wxStaticText( sGridSettings->GetStaticBox(),
96  wxID_ANY, _( "Grid thickness:" ) );
97  l_gridLineWidth->Wrap( -1 );
98  sGridSettingsGrid->Add( l_gridLineWidth, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
99 
100  m_gridLineWidth = new wxSpinCtrlDouble( sGridSettings->GetStaticBox(), wxID_ANY );
102  m_gridLineWidth->SetIncrement( gridThicknessStep );
103  m_gridLineWidth->SetDigits( 1 );
104  sGridSettingsGrid->Add( m_gridLineWidth, 0, wxEXPAND | wxTOP | wxBOTTOM, 5 );
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 wxSpinCtrlDouble( sGridSettings->GetStaticBox(), wxID_ANY);
118  m_gridMinSpacing->SetIncrement( gridMinSpacingStep );
119  m_gridMinSpacing->SetDigits( 0 );
120  sGridSettingsGrid->Add( m_gridMinSpacing, 0, wxEXPAND | wxTOP | wxBOTTOM, 5 );
121 
122  l_gridMinSpacingUnits = new wxStaticText( sGridSettings->GetStaticBox(),
123  wxID_ANY, _( "px" ) );
124  l_gridMinSpacingUnits->Wrap( -1 );
125  sGridSettingsGrid->Add( l_gridMinSpacingUnits, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
126 
127  sGridSettings->Add( sGridSettingsGrid, 1, wxALL | wxEXPAND, 5 );
128 
129  sLeftSizer->Add( sGridSettings, 0, wxTOP | wxBOTTOM | wxRIGHT | wxEXPAND, 5 );
130  }
131 
132  /*
133  * Cursor settings subpanel
134  */
135  {
136  auto sCursorSettings = new wxStaticBoxSizer( new wxStaticBox( this,
137  wxID_ANY, _( "Cursor Options" ) ), wxVERTICAL );
138 
139  sLeftSizer->Add( sCursorSettings, 1, wxTOP | wxRIGHT | wxEXPAND, 5 );
140 
141  wxString m_CursorShapeChoices[] = {
142  _( "Small crosshair" ),
143  _( "Full window crosshair" )
144  };
145 
146  int m_CursorShapeNChoices = sizeof( m_CursorShapeChoices ) / sizeof( wxString );
147  m_cursorShape = new wxRadioBox( this, wxID_ANY,
148  _( "Cursor Shape" ), wxDefaultPosition, wxDefaultSize,
149  m_CursorShapeNChoices, m_CursorShapeChoices, 1,
150  wxRA_SPECIFY_COLS );
151 
152  m_cursorShape->SetSelection( 0 );
153  m_cursorShape->SetToolTip( _( "Cursor shape for drawing, placement and movement tools" ) );
154  sCursorSettings->Add( m_cursorShape, 0, wxALL | wxEXPAND, 5 );
155 
156  m_forceCursorDisplay = new wxCheckBox( this, wxID_ANY, _( "Always show crosshairs" ) );
157  sCursorSettings->Add( m_forceCursorDisplay, 0, wxALL | wxEXPAND, 5 );
158  }
159 }
160 
161 
163 {
164  m_gridStyle->SetSelection( UTIL::GetConfigForVal(
166 
168 
170 
172 
174 
175  return true;
176 }
177 
178 
180 {
182  gridStyleSelectMap, m_gridStyle->GetSelection() );
183 
185 
187 
189 
191 
193 
194  return true;
195 }
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.
wxRadioBox * m_cursorShape
KIGFX::GRID_STYLE m_gridStyle
The grid style to draw the grid in
wxBoxSizer * m_mainSizer
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
wxSpinCtrlDouble * m_gridMinSpacing
wxCheckBox * m_forceCursorDisplay
bool TransferDataToWindow() override
Load the panel controls from the given opt.
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
#define _(s)
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
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.