KiCad PCB EDA Suite
widget_save_restore.h
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) 2019-2021 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#ifndef WIDGETS_WIDGET_SAVE_RESTORE__H
25#define WIDGETS_WIDGET_SAVE_RESTORE__H
26
27#include <vector>
28
29class wxCheckBox;
30class wxChoice;
31class wxNotebook;
32class wxRadioBox;
33class wxRadioButton;
34class wxString;
35class wxTextCtrl;
36
37class UNIT_BINDER;
38class EDA_ANGLE;
39
41{
42public:
43 WIDGET_SAVE_RESTORE( bool& aValidFlag ) :
44 m_valid( aValidFlag )
45 {
46 }
47
51 void Add( wxRadioBox& ctrl, long& dest );
52
56 void Add( wxRadioButton& ctrl, bool& dest );
57
61 void Add( wxCheckBox& ctrl, bool& dest );
62
67 void Add( wxTextCtrl& ctrl, wxString& dest );
68
73 void Add( wxTextCtrl& ctrl, long& dest );
74
79 void Add( wxTextCtrl& ctrl, double& dest );
80
84 void Add( UNIT_BINDER& ctrl, long& dest );
85
89 void Add( UNIT_BINDER& ctrl, EDA_ANGLE& dest );
90
95 void Add( wxChoice& ctrl, long& dest );
96
100 void Add( wxNotebook& ctrl, long& dest );
101
107
113
114private:
120 {
121 TEXT,
122 TEXT_INTEGER,
123 TEXT_DOUBLE,
125 UNIT_BINDER_ANGLE,
126 CHECKBOX,
127 RADIOBUTTON,
128 RADIOBOX,
129 CHOICE,
130 TAB
131 };
132
133 union CONTROL {
134 CONTROL( wxCheckBox* aCtrl ) :
135 m_checkbox( aCtrl )
136 {
137 }
138
139 CONTROL( wxRadioButton* aCtrl ) :
140 m_radiobutton( aCtrl )
141 {
142 }
143
144 CONTROL( wxChoice* aCtrl ) :
145 m_choice( aCtrl )
146 {
147 }
148
149 CONTROL( wxNotebook* aCtrl ) :
150 m_notebook( aCtrl )
151 {
152 }
153
154 CONTROL( wxRadioBox* aCtrl ) :
155 m_radiobox( aCtrl )
156 {
157 }
158
159 CONTROL( wxTextCtrl* aCtrl ) :
160 m_textctrl( aCtrl )
161 {
162 }
163
165 m_unit_binder( aCtrl )
166 {
167 }
168
169 wxCheckBox* m_checkbox;
170 wxChoice* m_choice;
171 wxNotebook* m_notebook;
172 wxRadioBox* m_radiobox;
173 wxRadioButton* m_radiobutton;
174 wxTextCtrl* m_textctrl;
176 };
177
178 union DATA {
179 DATA( long* aDest ) :
180 m_long( aDest )
181 {
182 }
183
184 DATA( bool* aDest ) :
185 m_bool( aDest )
186 {
187 }
188
189 DATA( wxString* aDest ) :
190 m_str( aDest )
191 {
192 }
193
194 DATA( double* aDest ) :
195 m_double( aDest )
196 {
197 }
198
199 DATA( EDA_ANGLE* aDest ) :
200 m_angle( aDest )
201 {
202 }
203
204 long* m_long;
205 bool* m_bool;
206 wxString* m_str;
207 double* m_double;
209 };
210
215 {
216 template <typename CTRL_T, typename DEST_T>
217 WIDGET_CTRL_T( WIDGET_CTRL_TYPE_T aType, CTRL_T& aCtrl, DEST_T& aDest ) :
218 m_type( aType ),
219 m_control( &aCtrl ),
220 m_dest( &aDest )
221 {
222 }
223
227 };
228
229 std::vector<WIDGET_CTRL_T> m_ctrls;
230 bool& m_valid;
231};
232
233#endif // WIDGETS_WIDGET_SAVE_RESTORE__H
void Add(wxRadioBox &ctrl, long &dest)
Bind a radiobox to a choice.
WIDGET_SAVE_RESTORE(bool &aValidFlag)
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
WIDGET_CTRL_TYPE_T
Recognised parameters types (encodes an implicit widget type, data type and appropriate conversion).
Struct that represents a single bound control.
WIDGET_CTRL_T(WIDGET_CTRL_TYPE_T aType, CTRL_T &aCtrl, DEST_T &aDest)