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.

182 lines
6.2 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016-2022 CERN
  5. * Copyright The 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_COMMAND_H
  27. #define DIALOG_SIM_COMMAND_H
  28. #include "dialog_sim_command_base.h"
  29. #include <netlist_exporter_spice.h>
  30. #include <sim/spice_value.h>
  31. #include <wx/valnum.h>
  32. class SPICE_CIRCUIT_MODEL;
  33. class SPICE_SETTINGS;
  34. class SIMULATOR_FRAME;
  35. class SIM_TAB;
  36. class DIALOG_SIM_COMMAND : public DIALOG_SIM_COMMAND_BASE
  37. {
  38. public:
  39. DIALOG_SIM_COMMAND( SIMULATOR_FRAME* aParent,
  40. std::shared_ptr<SPICE_CIRCUIT_MODEL> aCircuitModel,
  41. std::shared_ptr<SPICE_SETTINGS>& aSettings );
  42. const wxString& GetSimCommand() const
  43. {
  44. return m_simCommand;
  45. }
  46. void SetSimCommand( const wxString& aCommand )
  47. {
  48. parseCommand( aCommand );
  49. m_simCommand = aCommand;
  50. refreshUIControls();
  51. }
  52. void SetSimOptions( int aOptions )
  53. {
  54. m_fixIncludePaths->SetValue( aOptions &
  55. NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS );
  56. m_saveAllVoltages->SetValue( aOptions & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES );
  57. m_saveAllCurrents->SetValue( aOptions & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS );
  58. m_saveAllDissipations->SetValue( aOptions &
  59. NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS );
  60. m_saveAllEvents->SetValue( aOptions & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_EVENTS );
  61. }
  62. void SetPlotSettings( const SIM_TAB* aSimTab );
  63. bool TransferDataFromWindow() override;
  64. bool TransferDataToWindow() override;
  65. // The default dialog Validate() calls the validators of all widgets.
  66. // This is not what we want; We want only validators of the selected page
  67. // of the notebooks. So disable the wxDialog::Validate(), and let our
  68. // TransferDataFromWindow doing the job.
  69. virtual bool Validate() override
  70. {
  71. return true;
  72. }
  73. void ApplySettings( SIM_TAB* aTab );
  74. private:
  75. enum SCALE_TYPE
  76. {
  77. DECADE,
  78. OCTAVE,
  79. LINEAR
  80. };
  81. /// Generate events to update UI state.
  82. void refreshUIControls()
  83. {
  84. wxQueueEvent( m_dcEnable2, new wxCommandEvent( wxEVT_CHECKBOX ) );
  85. wxQueueEvent( m_dcSourceType1, new wxCommandEvent( wxEVT_RADIOBOX ) );
  86. wxQueueEvent( m_dcSourceType2, new wxCommandEvent( wxEVT_RADIOBOX ) );
  87. wxQueueEvent( m_inputSignalsFilter, new wxCommandEvent( wxEVT_TEXT ) );
  88. }
  89. /**
  90. * Read values from one DC sweep source to form a part of simulation command.
  91. *
  92. * @return string of four SPICE values if values are correct, empty string upon error.
  93. */
  94. wxString evaluateDCControls( wxChoice* aDcSource, wxTextCtrl* aDcStart, wxTextCtrl* aDcStop,
  95. wxTextCtrl* aDcIncr );
  96. /**
  97. * Update DC sweep source with symbols from schematic.
  98. */
  99. void updateDCSources( wxChar aType, wxChoice* aSource );
  100. /**
  101. * Update units on labels depending on selected source.
  102. */
  103. void updateDCUnits( wxChar aType, wxStaticText* aStartValUnit, wxStaticText* aEndValUnit,
  104. wxStaticText* aStepUnit );
  105. virtual void onInitDlg( wxInitDialogEvent& event ) override
  106. {
  107. // Call the default wxDialog handler of a wxInitDialogEvent
  108. TransferDataToWindow();
  109. // Now all widgets have the size fixed, call FinishDialogSettings
  110. finishDialogSettings();
  111. }
  112. /**
  113. * Parse a Spice directive.
  114. *
  115. * @param aCommand is the directive to be parsed (e.g. ".tran 10n 1000n").
  116. */
  117. void parseCommand( const wxString& aCommand );
  118. void onLoadDirectives( wxCommandEvent& event ) override
  119. {
  120. loadDirectives();
  121. }
  122. void onDCEnableSecondSource( wxCommandEvent& event ) override;
  123. void onSwapDCSources( wxCommandEvent& event ) override;
  124. void onDCSource1Selected( wxCommandEvent& event ) override;
  125. void onDCSource2Selected( wxCommandEvent& event ) override;
  126. void OnUpdateUILockY1( wxUpdateUIEvent& event ) override;
  127. void OnUpdateUILockY2( wxUpdateUIEvent& event ) override;
  128. void OnUpdateUILockY3( wxUpdateUIEvent& event ) override;
  129. static wxString scaleToString( int aOption )
  130. {
  131. switch( aOption )
  132. {
  133. case DECADE: return wxString( "dec" );
  134. case OCTAVE: return wxString( "oct" );
  135. case LINEAR: return wxString( "lin" );
  136. default: wxFAIL_MSG( "Unhandled scale type" ); return wxEmptyString;
  137. }
  138. }
  139. void OnCommandType( wxCommandEvent& event ) override;
  140. void OnFilterMouseMoved( wxMouseEvent& event ) override;
  141. void OnFilterText( wxCommandEvent& event ) override;
  142. void loadDirectives();
  143. private:
  144. SIMULATOR_FRAME* m_simulatorFrame;
  145. wxString m_simCommand;
  146. std::shared_ptr<SPICE_CIRCUIT_MODEL> m_circuitModel;
  147. std::shared_ptr<SPICE_SETTINGS> m_settings;
  148. SPICE_VALIDATOR m_spiceValidator;
  149. SPICE_VALIDATOR m_spiceEmptyValidator;
  150. wxIntegerValidator<int> m_posIntValidator;
  151. std::set<wxString> m_fftInputSignals;
  152. };
  153. #endif /* DIALOG_SIM_COMMAND_H */