KiCad PCB EDA Suite
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 
36 void WIDGET_SAVE_RESTORE::Add( wxRadioBox& ctrl, long& dest )
37 {
38  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBOX, ctrl, dest );
39 }
40 
41 
42 void WIDGET_SAVE_RESTORE::Add( wxRadioButton& ctrl, bool& dest )
43 {
44  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBUTTON, ctrl, dest );
45 }
46 
47 
48 void WIDGET_SAVE_RESTORE::Add( wxCheckBox& ctrl, bool& dest )
49 {
50  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHECKBOX, ctrl, dest );
51 }
52 
53 
54 void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, wxString& dest )
55 {
56  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT, ctrl, dest );
57 }
58 
59 
60 void 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 
66 void 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 
72 void 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 
78 void WIDGET_SAVE_RESTORE::Add( wxChoice& ctrl, long& dest )
79 {
80  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHOICE, ctrl, dest );
81 }
82 
83 
84 void WIDGET_SAVE_RESTORE::Add( wxNotebook& ctrl, long& dest )
85 {
86  m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TAB, ctrl, dest );
87 }
88 
89 
91 {
93  {
94  switch( ctrl.m_type )
95  {
97  *ctrl.m_dest.m_bool = ctrl.m_control.m_checkbox->GetValue();
98  break;
99 
101  *ctrl.m_dest.m_bool = ctrl.m_control.m_radiobutton->GetValue();
102  break;
103 
105  *ctrl.m_dest.m_str = ctrl.m_control.m_textctrl->GetValue();
106  break;
107 
109  ctrl.m_control.m_textctrl->GetValue().ToLong( ctrl.m_dest.m_long );
110  break;
111 
113  ctrl.m_control.m_textctrl->GetValue().ToDouble( ctrl.m_dest.m_double );
114  break;
115 
117  *ctrl.m_dest.m_long = ctrl.m_control.m_unit_binder->GetValue();
118  break;
119 
121  *ctrl.m_dest.m_long = ctrl.m_control.m_choice->GetSelection();
122  break;
123 
125  *ctrl.m_dest.m_long = ctrl.m_control.m_radiobox->GetSelection();
126  break;
127 
129  *ctrl.m_dest.m_long = ctrl.m_control.m_notebook->GetSelection();
130  break;
131  }
132  }
133 
134  m_valid = true;
135 }
136 
137 
139 {
140  if( !m_valid )
141  return;
142 
144  {
145  switch( ctrl.m_type )
146  {
148  ctrl.m_control.m_checkbox->SetValue( *ctrl.m_dest.m_bool );
149  break;
150 
152  ctrl.m_control.m_radiobutton->SetValue( *ctrl.m_dest.m_bool );
153  break;
154 
156  ctrl.m_control.m_textctrl->SetValue( *ctrl.m_dest.m_str );
157  break;
158 
160  ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%ld", *ctrl.m_dest.m_long ) );
161  break;
162 
164  ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%f", *ctrl.m_dest.m_double ) );
165  break;
166 
168  ctrl.m_control.m_unit_binder->SetValue( *ctrl.m_dest.m_long );
169  break;
170 
172  ctrl.m_control.m_choice->SetSelection( *ctrl.m_dest.m_long );
173  break;
174 
176  ctrl.m_control.m_radiobox->SetSelection( *ctrl.m_dest.m_long );
177  break;
178 
180  ctrl.m_control.m_notebook->SetSelection( *ctrl.m_dest.m_long );
181  break;
182  }
183  }
184 }
Struct that represents a single bound control.
std::vector< WIDGET_CTRL_T > m_ctrls
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.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void Add(wxRadioBox &ctrl, long &dest)
Bind a radiobox to a choice.