KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 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
20#ifndef WIDGETS_WIDGET_SAVE_RESTORE__H
21#define WIDGETS_WIDGET_SAVE_RESTORE__H
22
23#include <base_units.h>
24#include <vector>
25
26class wxCheckBox;
27class wxChoice;
28class wxNotebook;
29class wxRadioBox;
30class wxRadioButton;
31class wxString;
32class wxTextCtrl;
33
34class UNIT_BINDER;
35class EDA_ANGLE;
36
38{
39public:
40 WIDGET_SAVE_RESTORE( const EDA_IU_SCALE& aIuScale, bool& aValidFlag ) :
41 m_valid( aValidFlag )
42 {
43 }
44
48 void Add( wxRadioBox& ctrl, long& dest );
49
53 void Add( wxRadioButton& ctrl, bool& dest );
54
58 void Add( wxCheckBox& ctrl, bool& dest );
59
64 void Add( wxTextCtrl& ctrl, wxString& dest );
65
70 void Add( wxTextCtrl& ctrl, long& dest );
71
76 void Add( wxTextCtrl& ctrl, double& dest );
77
81 void Add( UNIT_BINDER& ctrl, long& dest );
82
86 void Add( UNIT_BINDER& ctrl, EDA_ANGLE& dest );
87
92 void Add( wxChoice& ctrl, long& dest );
93
97 void Add( wxNotebook& ctrl, long& dest );
98
104
110
111private:
129
130 union CONTROL {
131 CONTROL( wxCheckBox* aCtrl ) :
132 m_checkbox( aCtrl )
133 {
134 }
135
136 CONTROL( wxRadioButton* aCtrl ) :
137 m_radiobutton( aCtrl )
138 {
139 }
140
141 CONTROL( wxChoice* aCtrl ) :
142 m_choice( aCtrl )
143 {
144 }
145
146 CONTROL( wxNotebook* aCtrl ) :
147 m_notebook( aCtrl )
148 {
149 }
150
151 CONTROL( wxRadioBox* aCtrl ) :
152 m_radiobox( aCtrl )
153 {
154 }
155
156 CONTROL( wxTextCtrl* aCtrl ) :
157 m_textctrl( aCtrl )
158 {
159 }
160
162 m_unit_binder( aCtrl )
163 {
164 }
165
166 wxCheckBox* m_checkbox;
167 wxChoice* m_choice;
168 wxNotebook* m_notebook;
169 wxRadioBox* m_radiobox;
170 wxRadioButton* m_radiobutton;
171 wxTextCtrl* m_textctrl;
173 };
174
175 union DATA {
176 DATA( long* aDest ) :
177 m_long( aDest )
178 {
179 }
180
181 DATA( bool* aDest ) :
182 m_bool( aDest )
183 {
184 }
185
186 DATA( wxString* aDest ) :
187 m_str( aDest )
188 {
189 }
190
191 DATA( double* aDest ) :
192 m_double( aDest )
193 {
194 }
195
196 DATA( EDA_ANGLE* aDest ) :
197 m_angle( aDest )
198 {
199 }
200
201 long* m_long;
202 bool* m_bool;
203 wxString* m_str;
204 double* m_double;
206 };
207
212 {
213 template <typename CTRL_T, typename DEST_T>
214 WIDGET_CTRL_T( WIDGET_CTRL_TYPE_T aType, CTRL_T& aCtrl, DEST_T& aDest ) :
215 m_type( aType ),
216 m_control( &aCtrl ),
217 m_dest( &aDest )
218 {
219 }
220
224 };
225
226 std::vector<WIDGET_CTRL_T> m_ctrls;
227 bool& m_valid;
228};
229
230#endif // WIDGETS_WIDGET_SAVE_RESTORE__H
void Add(wxRadioBox &ctrl, long &dest)
Bind a radiobox to a choice.
WIDGET_SAVE_RESTORE(const EDA_IU_SCALE &aIuScale, 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).
WIDGET_CTRL_T(WIDGET_CTRL_TYPE_T aType, CTRL_T &aCtrl, DEST_T &aDest)