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.

191 lines
5.7 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 CERN
  5. * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Maciej Suminski <maciej.suminski@cern.ch>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 3
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * https://www.gnu.org/licenses/gpl-3.0.html
  22. * or you may search the http://www.gnu.org website for the version 3 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #ifndef DIALOG_SIM_SETTINGS_BASE_H
  27. #define DIALOG_SIM_SETTINGS_BASE_H
  28. #include "dialog_sim_settings_base.h"
  29. #include <sim/spice_value.h>
  30. #include <wx/valnum.h>
  31. class NETLIST_EXPORTER_PSPICE_SIM;
  32. class SPICE_SIMULATOR_SETTINGS;
  33. class DIALOG_SIM_SETTINGS : public DIALOG_SIM_SETTINGS_BASE
  34. {
  35. public:
  36. DIALOG_SIM_SETTINGS( wxWindow* aParent, std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& aSettings );
  37. const wxString& GetSimCommand() const
  38. {
  39. return m_simCommand;
  40. }
  41. bool SetSimCommand( const wxString& aCommand )
  42. {
  43. bool res = parseCommand( aCommand );
  44. if( res )
  45. m_simCommand = aCommand;
  46. return res;
  47. }
  48. int GetNetlistOptions() const
  49. {
  50. return m_netlistOpts;
  51. }
  52. void SetNetlistExporter( NETLIST_EXPORTER_PSPICE_SIM* aExporter )
  53. {
  54. m_exporter = aExporter;
  55. }
  56. bool TransferDataFromWindow() override;
  57. bool TransferDataToWindow() override;
  58. // The default dialog Validate() calls the validators of all widgets.
  59. // This is not what we want; We want only validators of the selected page
  60. // of the notebooks. So disable the wxDialog::Validate(), and let our
  61. // TransferDataFromWindow doing the job.
  62. virtual bool Validate() override
  63. {
  64. return true;
  65. }
  66. int ShowModal() override;
  67. private:
  68. enum SCALE_TYPE
  69. {
  70. DECADE,
  71. OCTAVE,
  72. LINEAR
  73. };
  74. ///< Generate events to update UI state.
  75. void refreshUIControls()
  76. {
  77. wxQueueEvent( m_dcEnable2, new wxCommandEvent( wxEVT_CHECKBOX ) );
  78. wxQueueEvent( m_dcSourceType1, new wxCommandEvent( wxEVT_RADIOBOX ) );
  79. wxQueueEvent( m_dcSourceType2, new wxCommandEvent( wxEVT_RADIOBOX ) );
  80. }
  81. /**
  82. * Read values from one DC sweep source to form a part of simulation command.
  83. *
  84. * @return string of four SPICE values if values are correct, empty string upon error.
  85. */
  86. wxString evaluateDCControls( wxChoice* aDcSource, wxTextCtrl* aDcStart, wxTextCtrl* aDcStop,
  87. wxTextCtrl* aDcIncr );
  88. /**
  89. * Update DC sweep source with components from schematic.
  90. */
  91. void updateDCSources( wxChar aType, wxChoice* aSource );
  92. /**
  93. * Update units on labels depending on selected source.
  94. */
  95. void updateDCUnits( wxChar aType, wxChoice* aSource, wxStaticText* aStartValUnit,
  96. wxStaticText* aEndValUnit, wxStaticText* aStepUnit );
  97. virtual void onInitDlg( wxInitDialogEvent& event ) override
  98. {
  99. // Call the default wxDialog handler of a wxInitDialogEvent
  100. TransferDataToWindow();
  101. // Now all widgets have the size fixed, call FinishDialogSettings
  102. finishDialogSettings();
  103. }
  104. /**
  105. * Parse a Spice directive.
  106. *
  107. * @param aCommand is the directive to be parsed (e.g. ".tran 10n 1000n").
  108. * @return true if the directive was parsed correctly.
  109. */
  110. bool parseCommand( const wxString& aCommand );
  111. void onLoadDirectives( wxCommandEvent& event ) override
  112. {
  113. loadDirectives();
  114. }
  115. void onDCEnableSecondSource( wxCommandEvent& event ) override;
  116. void onSwapDCSources( wxCommandEvent& event ) override;
  117. void onDCSource1Selected( wxCommandEvent& event ) override
  118. {
  119. wxChar type =
  120. m_dcSourceType1->GetString( m_dcSourceType1->GetSelection() ).Upper().GetChar( 0 );
  121. updateDCSources( type, m_dcSource1 );
  122. updateDCUnits( type, m_dcSource1, m_src1DCStartValUnit, m_src1DCEndValUnit,
  123. m_src1DCStepUnit );
  124. }
  125. void onDCSource2Selected( wxCommandEvent& event ) override
  126. {
  127. wxChar type =
  128. m_dcSourceType2->GetString( m_dcSourceType2->GetSelection() ).Upper().GetChar( 0 );
  129. updateDCSources( type, m_dcSource2 );
  130. updateDCUnits( type, m_dcSource2, m_src2DCStartValUnit, m_src2DCEndValUnit,
  131. m_src2DCStepUnit );
  132. }
  133. static wxString scaleToString( int aOption )
  134. {
  135. switch( aOption )
  136. {
  137. case DECADE:
  138. return wxString( "dec" );
  139. case OCTAVE:
  140. return wxString( "oct" );
  141. case LINEAR:
  142. return wxString( "lin" );
  143. }
  144. wxASSERT_MSG( false, "Unhandled scale type" );
  145. return wxEmptyString;
  146. }
  147. void loadDirectives();
  148. void updateNetlistOpts();
  149. wxString m_simCommand;
  150. int m_netlistOpts;
  151. NETLIST_EXPORTER_PSPICE_SIM* m_exporter;
  152. std::shared_ptr<SPICE_SIMULATOR_SETTINGS> m_settings;
  153. SPICE_VALIDATOR m_spiceValidator;
  154. SPICE_VALIDATOR m_spiceEmptyValidator;
  155. wxIntegerValidator<int> m_posIntValidator;
  156. };
  157. #endif /* DIALOG_SIM_SETTINGS_BASE_H */