You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
5.8 KiB

  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, 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. #include <widgets/widget_save_restore.h>
  24. #include <wx/checkbox.h>
  25. #include <wx/choice.h>
  26. #include <wx/notebook.h>
  27. #include <wx/radiobox.h>
  28. #include <wx/radiobut.h>
  29. #include <wx/textctrl.h>
  30. #include <widgets/unit_binder.h>
  31. void WIDGET_SAVE_RESTORE::Add( wxRadioBox& ctrl, long& dest )
  32. {
  33. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBOX, ctrl, dest );
  34. }
  35. void WIDGET_SAVE_RESTORE::Add( wxRadioButton& ctrl, bool& dest )
  36. {
  37. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::RADIOBUTTON, ctrl, dest );
  38. }
  39. void WIDGET_SAVE_RESTORE::Add( wxCheckBox& ctrl, bool& dest )
  40. {
  41. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHECKBOX, ctrl, dest );
  42. }
  43. void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, wxString& dest )
  44. {
  45. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT, ctrl, dest );
  46. }
  47. void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, long& dest )
  48. {
  49. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_INTEGER, ctrl, dest );
  50. }
  51. void WIDGET_SAVE_RESTORE::Add( wxTextCtrl& ctrl, double& dest )
  52. {
  53. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TEXT_DOUBLE, ctrl, dest );
  54. }
  55. void WIDGET_SAVE_RESTORE::Add( UNIT_BINDER& ctrl, long& dest )
  56. {
  57. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER, ctrl, dest );
  58. }
  59. void WIDGET_SAVE_RESTORE::Add( UNIT_BINDER& ctrl, EDA_ANGLE& dest )
  60. {
  61. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::UNIT_BINDER_ANGLE, ctrl, dest );
  62. }
  63. void WIDGET_SAVE_RESTORE::Add( wxChoice& ctrl, long& dest )
  64. {
  65. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::CHOICE, ctrl, dest );
  66. }
  67. void WIDGET_SAVE_RESTORE::Add( wxNotebook& ctrl, long& dest )
  68. {
  69. m_ctrls.emplace_back( WIDGET_CTRL_TYPE_T::TAB, ctrl, dest );
  70. }
  71. void WIDGET_SAVE_RESTORE::ReadConfigFromControls()
  72. {
  73. for( WIDGET_SAVE_RESTORE::WIDGET_CTRL_T& ctrl : m_ctrls )
  74. {
  75. switch( ctrl.m_type )
  76. {
  77. case WIDGET_CTRL_TYPE_T::CHECKBOX:
  78. *ctrl.m_dest.m_bool = ctrl.m_control.m_checkbox->GetValue();
  79. break;
  80. case WIDGET_CTRL_TYPE_T::RADIOBUTTON:
  81. *ctrl.m_dest.m_bool = ctrl.m_control.m_radiobutton->GetValue();
  82. break;
  83. case WIDGET_CTRL_TYPE_T::TEXT:
  84. *ctrl.m_dest.m_str = ctrl.m_control.m_textctrl->GetValue();
  85. break;
  86. case WIDGET_CTRL_TYPE_T::TEXT_INTEGER:
  87. ctrl.m_control.m_textctrl->GetValue().ToLong( ctrl.m_dest.m_long );
  88. break;
  89. case WIDGET_CTRL_TYPE_T::TEXT_DOUBLE:
  90. ctrl.m_control.m_textctrl->GetValue().ToDouble( ctrl.m_dest.m_double );
  91. break;
  92. case WIDGET_CTRL_TYPE_T::UNIT_BINDER:
  93. *ctrl.m_dest.m_long = ctrl.m_control.m_unit_binder->GetValue();
  94. break;
  95. case WIDGET_CTRL_TYPE_T::UNIT_BINDER_ANGLE:
  96. *ctrl.m_dest.m_angle = ctrl.m_control.m_unit_binder->GetAngleValue();
  97. break;
  98. case WIDGET_CTRL_TYPE_T::CHOICE:
  99. *ctrl.m_dest.m_long = ctrl.m_control.m_choice->GetSelection();
  100. break;
  101. case WIDGET_CTRL_TYPE_T::RADIOBOX:
  102. *ctrl.m_dest.m_long = ctrl.m_control.m_radiobox->GetSelection();
  103. break;
  104. case WIDGET_CTRL_TYPE_T::TAB:
  105. *ctrl.m_dest.m_long = ctrl.m_control.m_notebook->GetSelection();
  106. break;
  107. }
  108. }
  109. m_valid = true;
  110. }
  111. void WIDGET_SAVE_RESTORE::RestoreConfigToControls()
  112. {
  113. if( !m_valid )
  114. return;
  115. for( WIDGET_SAVE_RESTORE::WIDGET_CTRL_T& ctrl : m_ctrls )
  116. {
  117. switch( ctrl.m_type )
  118. {
  119. case WIDGET_CTRL_TYPE_T::CHECKBOX:
  120. ctrl.m_control.m_checkbox->SetValue( *ctrl.m_dest.m_bool );
  121. break;
  122. case WIDGET_CTRL_TYPE_T::RADIOBUTTON:
  123. ctrl.m_control.m_radiobutton->SetValue( *ctrl.m_dest.m_bool );
  124. break;
  125. case WIDGET_CTRL_TYPE_T::TEXT:
  126. ctrl.m_control.m_textctrl->SetValue( *ctrl.m_dest.m_str );
  127. break;
  128. case WIDGET_CTRL_TYPE_T::TEXT_INTEGER:
  129. ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%ld", *ctrl.m_dest.m_long ) );
  130. break;
  131. case WIDGET_CTRL_TYPE_T::TEXT_DOUBLE:
  132. ctrl.m_control.m_textctrl->SetValue( wxString::Format( "%f", *ctrl.m_dest.m_double ) );
  133. break;
  134. case WIDGET_CTRL_TYPE_T::UNIT_BINDER:
  135. ctrl.m_control.m_unit_binder->SetValue( *ctrl.m_dest.m_long );
  136. break;
  137. case WIDGET_CTRL_TYPE_T::UNIT_BINDER_ANGLE:
  138. ctrl.m_control.m_unit_binder->SetAngleValue( *ctrl.m_dest.m_angle );
  139. break;
  140. case WIDGET_CTRL_TYPE_T::CHOICE:
  141. ctrl.m_control.m_choice->SetSelection( *ctrl.m_dest.m_long );
  142. break;
  143. case WIDGET_CTRL_TYPE_T::RADIOBOX:
  144. ctrl.m_control.m_radiobox->SetSelection( *ctrl.m_dest.m_long );
  145. break;
  146. case WIDGET_CTRL_TYPE_T::TAB:
  147. ctrl.m_control.m_notebook->SetSelection( *ctrl.m_dest.m_long );
  148. break;
  149. }
  150. }
  151. }