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 (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
25
26#include <wx/checkbox.h>
27#include <wx/choice.h>
28#include <wx/notebook.h>
29#include <wx/radiobox.h>
30#include <wx/radiobut.h>
31#include <wx/textctrl.h>
32
33#include <widgets/unit_binder.h>
34
35
36void WIDGET_SAVE_RESTORE::Add( wxRadioBox& ctrl, long& dest )
37{
38 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBOX, ctrl, dest );
39}
40
41
42void WIDGET_SAVE_RESTORE::Add( wxRadioButton& ctrl, bool& dest )
43{
44 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBUTTON, ctrl, dest );
45}
46
47
48void WIDGET_SAVE_RESTORE::Add( wxCheckBox& ctrl, bool& dest )
49{
50 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHECKBOX, ctrl, dest );
51}
52
53
54void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, wxString& dest )
55{
56 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT, ctrl, dest );
57}
58
59
60void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, long& dest )
61{
62 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_INTEGER, ctrl, dest );
63}
64
65
66void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, double& dest )
67{
68 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_DOUBLE, ctrl, dest );
69}
70
71
72void WIDGET_SAVE_RESTORE::Add( UNIT_BINDER& ctrl, long& dest )
73{
74 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER, ctrl, dest );
75}
76
77
79{
80 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER_ANGLE, ctrl, dest );
81}
82
83void WIDGET_SAVE_RESTORE::Add( wxChoice& ctrl, long& dest )
84{
85 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHOICE, ctrl, dest );
86}
87
88
89void WIDGET_SAVE_RESTORE::Add( wxNotebook& ctrl, long& dest )
90{
91 m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TAB, ctrl, dest );
92}
93
94
96{
98 {
99 switch( ctrl.m_type )
100 {
102 *ctrl.m_dest.m_bool = ctrl.m_control.m_checkbox->GetValue();
103 break;
104
106 *ctrl.m_dest.m_bool = ctrl.m_control.m_radiobutton->GetValue();
107 break;
108
110 *ctrl.m_dest.m_str = ctrl.m_control.m_textctrl->GetValue();
111 break;
112
114 ctrl.m_control.m_textctrl->GetValue().ToLong( ctrl.m_dest.m_long );
115 break;
116
118 ctrl.m_control.m_textctrl->GetValue().ToDouble( ctrl.m_dest.m_double );
119 break;
120
122 *ctrl.m_dest.m_long = ctrl.m_control.m_unit_binder->GetValue();
123 break;
124
126 *ctrl.m_dest.m_angle = ctrl.m_control.m_unit_binder->GetAngleValue();
127 break;
128
130 *ctrl.m_dest.m_long = ctrl.m_control.m_choice->GetSelection();
131 break;
132
134 *ctrl.m_dest.m_long = ctrl.m_control.m_radiobox->GetSelection();
135 break;
136
138 *ctrl.m_dest.m_long = ctrl.m_control.m_notebook->GetSelection();
139 break;
140 }
141 }
142
143 m_valid = true;
144}
145
146
148{
149 if( !m_valid )
150 return;
151
153 {
154 switch( ctrl.m_type )
155 {
157 ctrl.m_control.m_checkbox->SetValue( *ctrl.m_dest.m_bool );
158 break;
159
161 ctrl.m_control.m_radiobutton->SetValue( *ctrl.m_dest.m_bool );
162 break;
163
165 ctrl.m_control.m_textctrl->SetValue( *ctrl.m_dest.m_str );
166 break;
167
169 ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%ld", *ctrl.m_dest.m_long ) );
170 break;
171
173 ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%f", *ctrl.m_dest.m_double ) );
174 break;
175
177 ctrl.m_control.m_unit_binder->SetValue( *ctrl.m_dest.m_long );
178 break;
179
181 ctrl.m_control.m_unit_binder->SetAngleValue( *ctrl.m_dest.m_angle );
182 break;
183
185 ctrl.m_control.m_choice->SetSelection( *ctrl.m_dest.m_long );
186 break;
187
189 ctrl.m_control.m_radiobox->SetSelection( *ctrl.m_dest.m_long );
190 break;
191
193 ctrl.m_control.m_notebook->SetSelection( *ctrl.m_dest.m_long );
194 break;
195 }
196 }
197}
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.