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.

467 lines
13 KiB

* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
  1. /**
  2. * @file regulators_funct.cpp
  3. */
  4. /*
  5. * This program source code file is part of KICAD, a free EDA CAD application.
  6. *
  7. * Copyright (C) 1992-2011 jean-pierre.charras
  8. * Copyright (C) 1992-2011 Kicad Developers, see change_log.txt for contributors.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. * or you may search the http://www.gnu.org website for the version 2 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #include <wx/wx.h>
  28. #include <wx/config.h>
  29. #include <macros.h>
  30. #include <pcb_calculator.h>
  31. #include <class_regulator_data.h>
  32. #include <dialog_regulator_data_base.h>
  33. extern double DoubleFromString( const wxString& TextValue );
  34. class DIALOG_EDITOR_DATA: public DIALOG_EDITOR_DATA_BASE
  35. {
  36. public:
  37. DIALOG_EDITOR_DATA( PCB_CALCULATOR_FRAME * parent, const wxString & aRegName )
  38. : DIALOG_EDITOR_DATA_BASE( parent )
  39. {
  40. m_textCtrlName->SetValue( aRegName );
  41. m_textCtrlName->Enable( aRegName.IsEmpty() );
  42. UpdateDialog();
  43. }
  44. ~DIALOG_EDITOR_DATA() {};
  45. // Event called functions:
  46. void OnOKClick( wxCommandEvent& event ) override;
  47. /**
  48. * Function IsOK()
  49. * @return true if regulator parameters are acceptable
  50. */
  51. bool IsOK();
  52. /**
  53. * Function CopyRegulatorDataToDialog
  54. * Transfert data from dialog to aItem
  55. * @param aItem = a pointer to the REGULATOR_DATA
  56. */
  57. void CopyRegulatorDataToDialog( REGULATOR_DATA * aItem );
  58. /**
  59. * Function BuildRegulatorFromData
  60. * Creates a new REGULATOR_DATA from dialog
  61. * @return a pointer to the new REGULATOR_DATA
  62. */
  63. REGULATOR_DATA * BuildRegulatorFromData();
  64. /**
  65. * Enable/disable Iadj realted widgets, according to
  66. * the regulator type
  67. */
  68. void UpdateDialog()
  69. {
  70. bool enbl = m_choiceRegType->GetSelection() == 1;
  71. m_RegulIadjValue->Enable( enbl );
  72. m_RegulIadjTitle->Enable( enbl );
  73. m_IadjUnitLabel->Enable( enbl );
  74. }
  75. /**
  76. * called when the current regulator type is changed
  77. */
  78. void OnRegTypeSelection( wxCommandEvent& event ) override
  79. {
  80. UpdateDialog();
  81. }
  82. };
  83. void DIALOG_EDITOR_DATA::OnOKClick( wxCommandEvent& event )
  84. {
  85. if( !IsOK() )
  86. {
  87. wxMessageBox( _("Bad or missing parameters!") );
  88. return;
  89. }
  90. EndModal( wxID_OK );
  91. }
  92. bool DIALOG_EDITOR_DATA::IsOK()
  93. {
  94. bool success = true;
  95. if( m_textCtrlName->GetValue().IsEmpty() )
  96. success = false;
  97. if( m_textCtrlVref->GetValue().IsEmpty() )
  98. success = false;
  99. else
  100. {
  101. double vref = DoubleFromString( m_textCtrlVref->GetValue() );
  102. if( fabs(vref) < 0.01 )
  103. success = false;
  104. }
  105. if( m_choiceRegType->GetSelection() == 1 )
  106. {
  107. if( m_RegulIadjValue->GetValue().IsEmpty() )
  108. success = false;
  109. }
  110. return success;
  111. }
  112. void DIALOG_EDITOR_DATA::CopyRegulatorDataToDialog( REGULATOR_DATA * aItem )
  113. {
  114. m_textCtrlName->SetValue( aItem->m_Name );
  115. wxString value;
  116. value.Printf( wxT("%g"), aItem->m_Vref );
  117. m_textCtrlVref->SetValue( value );
  118. value.Printf( wxT("%g"), aItem->m_Iadj );
  119. m_RegulIadjValue->SetValue( value );
  120. m_choiceRegType->SetSelection( aItem->m_Type );
  121. UpdateDialog();
  122. }
  123. REGULATOR_DATA * DIALOG_EDITOR_DATA::BuildRegulatorFromData()
  124. {
  125. double vref = DoubleFromString( m_textCtrlVref->GetValue() );
  126. double iadj = DoubleFromString( m_RegulIadjValue->GetValue() );
  127. int type = m_choiceRegType->GetSelection();
  128. if( type != 1 )
  129. iadj = 0.0;
  130. REGULATOR_DATA * item = new REGULATOR_DATA( m_textCtrlName->GetValue(),
  131. vref, type, iadj );
  132. return item;
  133. }
  134. void PCB_CALCULATOR_FRAME::OnRegulatorCalcButtonClick( wxCommandEvent& event )
  135. {
  136. RegulatorsSolve();
  137. }
  138. void PCB_CALCULATOR_FRAME::RegulatorPageUpdate()
  139. {
  140. switch( m_choiceRegType->GetSelection() )
  141. {
  142. default:
  143. case 0:
  144. m_bitmapRegul4pins->Show( true );
  145. m_bitmapRegul3pins->Show( false );
  146. m_RegulIadjValue->Enable( false );
  147. m_RegulIadjTitle->Enable( false );
  148. m_IadjUnitLabel->Enable( false );
  149. m_RegulFormula->SetLabel( wxT("Vout = Vref * (R1 + R2) / R2") );
  150. break;
  151. case 1:
  152. m_bitmapRegul4pins->Show( false );
  153. m_bitmapRegul3pins->Show( true );
  154. m_RegulIadjValue->Enable( true );
  155. m_RegulIadjTitle->Enable( true );
  156. m_IadjUnitLabel->Enable( true );
  157. m_RegulFormula->SetLabel( wxT("Vout = Vref * (R1 + R2) / R1 + Iadj * R2") );
  158. break;
  159. }
  160. // The new icon size must be taken in account
  161. m_panelRegulators->GetSizer()->Layout();
  162. // Enable/disable buttons:
  163. bool enbl = m_choiceRegulatorSelector->GetCount() > 0;
  164. m_buttonEditItem->Enable( enbl );
  165. m_buttonRemoveItem->Enable( enbl );
  166. m_panelRegulators->Refresh();
  167. }
  168. void PCB_CALCULATOR_FRAME::OnRegulTypeSelection( wxCommandEvent& event )
  169. {
  170. RegulatorPageUpdate();
  171. }
  172. void PCB_CALCULATOR_FRAME::OnRegulatorSelection( wxCommandEvent& event )
  173. {
  174. wxString name = m_choiceRegulatorSelector->GetStringSelection();
  175. REGULATOR_DATA * item = m_RegulatorList.GetReg( name );
  176. if( item )
  177. {
  178. m_lastSelectedRegulatorName = item->m_Name;
  179. m_choiceRegType->SetSelection( item->m_Type );
  180. wxString value;
  181. value.Printf( wxT("%g"), item->m_Vref );
  182. m_RegulVrefValue->SetValue( value );
  183. value.Printf( wxT("%g"), item->m_Iadj );
  184. m_RegulIadjValue->SetValue( value );
  185. }
  186. // Call RegulatorPageUpdate to enable/sisable tools,
  187. // even if no item selected
  188. RegulatorPageUpdate();
  189. }
  190. /*
  191. * Called when ckicking on button Browse:
  192. * Select a new data file, and load it on request
  193. */
  194. void PCB_CALCULATOR_FRAME::OnDataFileSelection( wxCommandEvent& event )
  195. {
  196. wxString fullfilename = GetDataFilename();
  197. wxString wildcard;
  198. wildcard.Printf( _("PCB Calculator data file (*.%s)|*.%s"),
  199. GetChars( DataFileNameExt ),
  200. GetChars( DataFileNameExt ) );
  201. wxFileDialog dlg( m_panelRegulators,
  202. _("Select PCB Calculator Data File"),
  203. wxEmptyString, fullfilename,
  204. wildcard, wxFD_OPEN );
  205. if (dlg.ShowModal() == wxID_CANCEL)
  206. return;
  207. fullfilename = dlg.GetPath();
  208. if( fullfilename == GetDataFilename() )
  209. return;
  210. SetDataFilename( fullfilename );
  211. if( wxFileExists( fullfilename ) && m_RegulatorList.GetCount() > 0 ) // Read file
  212. {
  213. if( wxMessageBox( _("Do you want to load this file and replace current regulator list?" ) )
  214. != wxID_OK )
  215. return;
  216. }
  217. if( ReadDataFile() )
  218. {
  219. m_RegulatorListChanged = false;
  220. m_choiceRegulatorSelector->Clear();
  221. m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
  222. SelectLastSelectedRegulator();
  223. }
  224. else
  225. {
  226. wxString msg;
  227. msg.Printf( _("Unable to read data file \"%s\""), GetChars( fullfilename ) );
  228. wxMessageBox( msg );
  229. }
  230. }
  231. void PCB_CALCULATOR_FRAME::OnAddRegulator( wxCommandEvent& event )
  232. {
  233. DIALOG_EDITOR_DATA dlg( this, wxEmptyString );
  234. if( dlg.ShowModal() != wxID_OK )
  235. return;
  236. if( !dlg.IsOK() )
  237. {
  238. wxMessageBox( _("Bad or missing parameters!") );
  239. return;
  240. }
  241. REGULATOR_DATA * new_item = dlg.BuildRegulatorFromData();
  242. // Add new item, if not existing
  243. if( m_RegulatorList.GetReg( new_item->m_Name ) == NULL )
  244. {
  245. // Add item in list
  246. m_RegulatorList.Add( new_item );
  247. m_RegulatorListChanged = true;
  248. m_choiceRegulatorSelector->Clear();
  249. m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
  250. m_lastSelectedRegulatorName = new_item->m_Name;
  251. SelectLastSelectedRegulator();
  252. }
  253. else
  254. {
  255. wxMessageBox( _("This regulator is already in list. Aborted") );
  256. delete new_item;
  257. }
  258. }
  259. void PCB_CALCULATOR_FRAME::OnEditRegulator( wxCommandEvent& event )
  260. {
  261. wxString name = m_choiceRegulatorSelector->GetStringSelection();
  262. REGULATOR_DATA * item = m_RegulatorList.GetReg( name );
  263. if( item == NULL )
  264. return;
  265. DIALOG_EDITOR_DATA dlg( this, name );
  266. dlg.CopyRegulatorDataToDialog( item );
  267. if( dlg.ShowModal() != wxID_OK )
  268. return;
  269. REGULATOR_DATA * new_item = dlg.BuildRegulatorFromData();
  270. m_RegulatorList.Replace( new_item );
  271. m_RegulatorListChanged = true;
  272. SelectLastSelectedRegulator();
  273. }
  274. void PCB_CALCULATOR_FRAME::OnRemoveRegulator( wxCommandEvent& event )
  275. {
  276. wxString name = wxGetSingleChoice( _("Remove Regulator"), wxEmptyString,
  277. m_RegulatorList.GetRegList() );
  278. if( name.IsEmpty() )
  279. return;
  280. m_RegulatorList.Remove( name );
  281. m_RegulatorListChanged = true;
  282. m_choiceRegulatorSelector->Clear();
  283. m_choiceRegulatorSelector->Append( m_RegulatorList.GetRegList() );
  284. if( m_lastSelectedRegulatorName == name )
  285. m_lastSelectedRegulatorName.Empty();
  286. SelectLastSelectedRegulator();
  287. }
  288. void PCB_CALCULATOR_FRAME::SelectLastSelectedRegulator()
  289. {
  290. // Find last selected in regulator list:
  291. int idx = -1;
  292. if( ! m_lastSelectedRegulatorName.IsEmpty() )
  293. {
  294. for( unsigned ii = 0; ii < m_RegulatorList.GetCount(); ii++ )
  295. if( m_RegulatorList.m_List[ii]->m_Name == m_lastSelectedRegulatorName )
  296. {
  297. idx = ii;
  298. break;
  299. }
  300. }
  301. m_choiceRegulatorSelector->SetSelection( idx );
  302. wxCommandEvent event;
  303. OnRegulatorSelection( event );
  304. }
  305. // Calculate a value from the 3 other values
  306. // Vref is given by the regulator properties, so
  307. // we can calculate only R1, R2 or Vout
  308. void PCB_CALCULATOR_FRAME::RegulatorsSolve()
  309. {
  310. int id;
  311. if( m_rbRegulR1->GetValue() )
  312. id = 0; // for R1 calculation
  313. else if( m_rbRegulR2->GetValue() )
  314. id = 1; // for R2 calculation
  315. else if( m_rbRegulVout->GetValue() )
  316. id = 2; // for Vout calculation
  317. else
  318. {
  319. wxMessageBox( wxT("Selection error" ) );
  320. return;
  321. }
  322. double r1, r2, vref, vout;
  323. wxString txt;
  324. m_RegulMessage->SetLabel( wxEmptyString);
  325. // Convert r1 and r2 in ohms
  326. int r1scale = 1000;
  327. int r2scale = 1000;
  328. // Read values from panel:
  329. txt = m_RegulR1Value->GetValue();
  330. r1 = DoubleFromString(txt) * r1scale;
  331. txt = m_RegulR2Value->GetValue();
  332. r2 = DoubleFromString(txt) * r2scale;
  333. txt = m_RegulVrefValue->GetValue();
  334. vref = DoubleFromString(txt);
  335. txt = m_RegulVoutValue->GetValue();
  336. vout = DoubleFromString(txt);
  337. // Some tests:
  338. if( vout < vref && id != 2)
  339. {
  340. m_RegulMessage->SetLabel( _("Vout must be greater than vref" ) );
  341. return;
  342. }
  343. if( vref == 0.0 )
  344. {
  345. m_RegulMessage->SetLabel( _("Vref set to 0 !" ) );
  346. return;
  347. }
  348. if( (r1 < 0 && id != 0 ) || (r2 <= 0 && id != 1) )
  349. {
  350. m_RegulMessage->SetLabel( _("Incorrect value for R1 R2" ) );
  351. return;
  352. }
  353. // Calculate
  354. if( m_choiceRegType->GetSelection() == 1)
  355. {
  356. // 3 terminal regulator
  357. txt = m_RegulIadjValue->GetValue();
  358. double iadj = DoubleFromString(txt);
  359. // iadj is given in micro amp, so convert it in amp.
  360. iadj /= 1000000;
  361. switch( id )
  362. {
  363. case 0:
  364. r1 = vref * r2 / ( vout - vref - (r2 * iadj) );
  365. break;
  366. case 1:
  367. r2 = ( vout - vref ) / ( iadj + (vref/r1) );
  368. break;
  369. case 2:
  370. vout = vref * (r1 + r2) / r1;
  371. vout += r2 * iadj;
  372. break;
  373. }
  374. }
  375. else
  376. { // Standard 4 terminal regulator
  377. switch( id )
  378. {
  379. case 0:
  380. r1 = ( vout / vref - 1 ) * r2;
  381. break;
  382. case 1:
  383. r2 = r1 / ( vout / vref - 1);
  384. break;
  385. case 2:
  386. vout = vref * (r1 + r2) / r2;
  387. break;
  388. }
  389. }
  390. // write values to panel:
  391. txt.Printf(wxT("%g"), r1 / r1scale );
  392. m_RegulR1Value->SetValue(txt);
  393. txt.Printf(wxT("%g"), r2 / r2scale);
  394. m_RegulR2Value->SetValue(txt);
  395. txt.Printf(wxT("%g"), vref);
  396. m_RegulVrefValue->SetValue(txt);
  397. txt.Printf(wxT("%g"), vout);
  398. m_RegulVoutValue->SetValue(txt);
  399. }