KiCad PCB EDA Suite
Loading...
Searching...
No Matches
widget_save_restore.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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <wx/checkbox.h>
23#include <wx/choice.h>
24#include <wx/notebook.h>
25#include <wx/radiobox.h>
26#include <wx/radiobut.h>
27#include <wx/textctrl.h>
28
29#include <widgets/unit_binder.h>
30
31
32void WIDGET_SAVE_RESTORE::Add( wxRadioBox& ctrl, long& dest )
33{
34 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBOX, ctrl, dest );
35}
36
37
38void WIDGET_SAVE_RESTORE::Add( wxRadioButton& ctrl, bool& dest )
39{
40 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBUTTON, ctrl, dest );
41}
42
43
44void WIDGET_SAVE_RESTORE::Add( wxCheckBox& ctrl, bool& dest )
45{
46 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHECKBOX, ctrl, dest );
47}
48
49
50void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, wxString& dest )
51{
52 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT, ctrl, dest );
53}
54
55
56void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, long& dest )
57{
58 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_INTEGER, ctrl, dest );
59}
60
61
62void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, double& dest )
63{
64 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_DOUBLE, ctrl, dest );
65}
66
67
68void WIDGET_SAVE_RESTORE::Add( UNIT_BINDER& ctrl, long& dest )
69{
70 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER, ctrl, dest );
71}
72
73
75{
76 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER_ANGLE, ctrl, dest );
77}
78
79void WIDGET_SAVE_RESTORE::Add( wxChoice& ctrl, long& dest )
80{
81 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHOICE, ctrl, dest );
82}
83
84
85void WIDGET_SAVE_RESTORE::Add( wxNotebook& ctrl, long& dest )
86{
87 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TAB, ctrl, dest );
88}
89
90
92{
94 {
95 switch( ctrl.m_type )
96 {
98 *ctrl.m_dest.m_bool = ctrl.m_control.m_checkbox->GetValue();
99 break;
100
102 *ctrl.m_dest.m_bool = ctrl.m_control.m_radiobutton->GetValue();
103 break;
104
106 *ctrl.m_dest.m_str = ctrl.m_control.m_textctrl->GetValue();
107 break;
108
110 ctrl.m_control.m_textctrl->GetValue().ToLong( ctrl.m_dest.m_long );
111 break;
112
114 ctrl.m_control.m_textctrl->GetValue().ToDouble( ctrl.m_dest.m_double );
115 break;
116
118 *ctrl.m_dest.m_long = ctrl.m_control.m_unit_binder->GetValue();
119 break;
120
122 *ctrl.m_dest.m_angle = ctrl.m_control.m_unit_binder->GetAngleValue();
123 break;
124
126 *ctrl.m_dest.m_long = ctrl.m_control.m_choice->GetSelection();
127 break;
128
130 *ctrl.m_dest.m_long = ctrl.m_control.m_radiobox->GetSelection();
131 break;
132
134 *ctrl.m_dest.m_long = ctrl.m_control.m_notebook->GetSelection();
135 break;
136 }
137 }
138
139 m_valid = true;
140}
141
142
144{
145 if( !m_valid )
146 return;
147
149 {
150 switch( ctrl.m_type )
151 {
153 ctrl.m_control.m_checkbox->SetValue( *ctrl.m_dest.m_bool );
154 break;
155
157 ctrl.m_control.m_radiobutton->SetValue( *ctrl.m_dest.m_bool );
158 break;
159
161 ctrl.m_control.m_textctrl->SetValue( *ctrl.m_dest.m_str );
162 break;
163
165 ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%ld", *ctrl.m_dest.m_long ) );
166 break;
167
169 ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%f", *ctrl.m_dest.m_double ) );
170 break;
171
173 ctrl.m_control.m_unit_binder->SetValue( *ctrl.m_dest.m_long );
174 break;
175
177 ctrl.m_control.m_unit_binder->SetAngleValue( *ctrl.m_dest.m_angle );
178 break;
179
181 ctrl.m_control.m_choice->SetSelection( *ctrl.m_dest.m_long );
182 break;
183
185 ctrl.m_control.m_radiobox->SetSelection( *ctrl.m_dest.m_long );
186 break;
187
189 ctrl.m_control.m_notebook->SetSelection( *ctrl.m_dest.m_long );
190 break;
191 }
192 }
193}
void Add(wxRadioBox &ctrl, long &dest)
Bind a radiobox to a choice.
void RestoreConfigToControls()
Restore the values from the internally-stored references to the underlying data to each bound control...
void ReadConfigFromControls()
Read values of all bound controls into the internally-stored references to the underlying data.
std::vector< WIDGET_CTRL_T > m_ctrls
Struct that represents a single bound control.