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 (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 <base_units.h>
28#include <vector>
29
30class wxCheckBox;
31class wxChoice;
32class wxNotebook;
33class wxRadioBox;
34class wxRadioButton;
35class wxString;
36class wxTextCtrl;
37
38class UNIT_BINDER;
39class EDA_ANGLE;
40
42{
43public:
44 WIDGET_SAVE_RESTORE( const EDA_IU_SCALE& aIuScale, bool& aValidFlag ) :
45 m_valid( aValidFlag )
46 {
47 }
48
52 void Add( wxRadioBox& ctrl, long& dest );
53
57 void Add( wxRadioButton& ctrl, bool& dest );
58
62 void Add( wxCheckBox& ctrl, bool& dest );
63
68 void Add( wxTextCtrl& ctrl, wxString& dest );
69
74 void Add( wxTextCtrl& ctrl, long& dest );
75
80 void Add( wxTextCtrl& ctrl, double& dest );
81
85 void Add( UNIT_BINDER& ctrl, long& dest );
86
90 void Add( UNIT_BINDER& ctrl, EDA_ANGLE& dest );
91
96 void Add( wxChoice& ctrl, long& dest );
97
101 void Add( wxNotebook& ctrl, long& dest );
102
108
114
115private:
121 {
122 TEXT,
127 CHECKBOX,
129 RADIOBOX,
130 CHOICE,
131 TAB
132 };
133
134 union CONTROL {
135 CONTROL( wxCheckBox* aCtrl ) :
136 m_checkbox( aCtrl )
137 {
138 }
139
140 CONTROL( wxRadioButton* aCtrl ) :
141 m_radiobutton( aCtrl )
142 {
143 }
144
145 CONTROL( wxChoice* aCtrl ) :
146 m_choice( aCtrl )
147 {
148 }
149
150 CONTROL( wxNotebook* aCtrl ) :
151 m_notebook( aCtrl )
152 {
153 }
154
155 CONTROL( wxRadioBox* aCtrl ) :
156 m_radiobox( aCtrl )
157 {
158 }
159
160 CONTROL( wxTextCtrl* aCtrl ) :
161 m_textctrl( aCtrl )
162 {
163 }
164
166 m_unit_binder( aCtrl )
167 {
168 }
169
170 wxCheckBox* m_checkbox;
171 wxChoice* m_choice;
172 wxNotebook* m_notebook;
173 wxRadioBox* m_radiobox;
174 wxRadioButton* m_radiobutton;
175 wxTextCtrl* m_textctrl;
177 };
178
179 union DATA {
180 DATA( long* aDest ) :
181 m_long( aDest )
182 {
183 }
184
185 DATA( bool* aDest ) :
186 m_bool( aDest )
187 {
188 }
189
190 DATA( wxString* aDest ) :
191 m_str( aDest )
192 {
193 }
194
195 DATA( double* aDest ) :
196 m_double( aDest )
197 {
198 }
199
200 DATA( EDA_ANGLE* aDest ) :
201 m_angle( aDest )
202 {
203 }
204
205 long* m_long;
206 bool* m_bool;
207 wxString* m_str;
208 double* m_double;
210 };
211
216 {
217 template <typename CTRL_T, typename DEST_T>
218 WIDGET_CTRL_T( WIDGET_CTRL_TYPE_T aType, CTRL_T& aCtrl, DEST_T& aDest ) :
219 m_type( aType ),
220 m_control( &aCtrl ),
221 m_dest( &aDest )
222 {
223 }
224
228 };
229
230 std::vector<WIDGET_CTRL_T> m_ctrls;
231 bool& m_valid;
232};
233
234#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).
Struct that represents a single bound control.
WIDGET_CTRL_T(WIDGET_CTRL_TYPE_T aType, CTRL_T &aCtrl, DEST_T &aDest)