KiCad PCB EDA Suite
dialog_sim_settings.h
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) 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 
27 #ifndef DIALOG_SIM_SETTINGS_BASE_H
28 #define DIALOG_SIM_SETTINGS_BASE_H
29 
31 #include <sim/spice_value.h>
32 
33 #include <wx/valnum.h>
34 
37 
38 
40 {
41 public:
42  DIALOG_SIM_SETTINGS( wxWindow* aParent, std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& aSettings );
43 
44  const wxString& GetSimCommand() const
45  {
46  return m_simCommand;
47  }
48 
49  bool SetSimCommand( const wxString& aCommand )
50  {
51  bool res = parseCommand( aCommand );
52 
53  if( res )
54  m_simCommand = aCommand;
55 
56  return res;
57  }
58 
59  int GetNetlistOptions() const
60  {
61  return m_netlistOpts;
62  }
63 
65  {
66  m_exporter = aExporter;
67  }
68 
69  bool TransferDataFromWindow() override;
70  bool TransferDataToWindow() override;
71 
72  // The default dialog Validate() calls the validators of all widgets.
73  // This is not what we want; We want only validators of the selected page
74  // of the notebooks. So disable the wxDialog::Validate(), and let our
75  // TransferDataFromWindow doing the job.
76  virtual bool Validate() override
77  {
78  return true;
79  }
80 
81  int ShowModal() override;
82 
83 private:
85  {
89  };
90 
93  {
94  wxQueueEvent( m_dcEnable2, new wxCommandEvent( wxEVT_CHECKBOX ) );
95  wxQueueEvent( m_dcSourceType1, new wxCommandEvent( wxEVT_RADIOBOX ) );
96  wxQueueEvent( m_dcSourceType2, new wxCommandEvent( wxEVT_RADIOBOX ) );
97  }
98 
104  wxString evaluateDCControls( wxChoice* aDcSource, wxTextCtrl* aDcStart, wxTextCtrl* aDcStop,
105  wxTextCtrl* aDcIncr );
106 
110  void updateDCSources( wxChar aType, wxChoice* aSource );
111 
115  void updateDCUnits( wxChar aType, wxChoice* aSource, wxStaticText* aStartValUnit,
116  wxStaticText* aEndValUnit, wxStaticText* aStepUnit );
117 
118  virtual void onInitDlg( wxInitDialogEvent& event ) override
119  {
120  // Call the default wxDialog handler of a wxInitDialogEvent
122 
123  // Now all widgets have the size fixed, call FinishDialogSettings
125  }
126 
133  bool parseCommand( const wxString& aCommand );
134 
135  void onLoadDirectives( wxCommandEvent& event ) override
136  {
137  loadDirectives();
138  }
139 
140  void onDCEnableSecondSource( wxCommandEvent& event ) override;
141  void onSwapDCSources( wxCommandEvent& event ) override;
142  void onDCSource1Selected( wxCommandEvent& event ) override
143  {
144  wxChar type =
145  m_dcSourceType1->GetString( m_dcSourceType1->GetSelection() ).Upper().GetChar( 0 );
146  updateDCSources( type, m_dcSource1 );
149  }
150 
151  void onDCSource2Selected( wxCommandEvent& event ) override
152  {
153  wxChar type =
154  m_dcSourceType2->GetString( m_dcSourceType2->GetSelection() ).Upper().GetChar( 0 );
155  updateDCSources( type, m_dcSource2 );
158  }
159 
160  static wxString scaleToString( int aOption )
161  {
162  switch( aOption )
163  {
164  case DECADE:
165  return wxString( "dec" );
166 
167  case OCTAVE:
168  return wxString( "oct" );
169 
170  case LINEAR:
171  return wxString( "lin" );
172  }
173 
174  wxASSERT_MSG( false, "Unhandled scale type" );
175 
176  return wxEmptyString;
177  }
178 
179  void loadDirectives();
180  void updateNetlistOpts();
181 
182  wxString m_simCommand;
185  std::shared_ptr<SPICE_SIMULATOR_SETTINGS> m_settings;
188  wxIntegerValidator<int> m_posIntValidator;
189 };
190 
191 #endif /* DIALOG_SIM_SETTINGS_BASE_H */
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > m_settings
bool SetSimCommand(const wxString &aCommand)
SPICE_VALIDATOR m_spiceEmptyValidator
wxString evaluateDCControls(wxChoice *aDcSource, wxTextCtrl *aDcStart, wxTextCtrl *aDcStop, wxTextCtrl *aDcIncr)
Read values from one DC sweep source to form a part of simulation command.
void onDCSource2Selected(wxCommandEvent &event) override
static wxString scaleToString(int aOption)
Class DIALOG_SIM_SETTINGS_BASE.
void onDCSource1Selected(wxCommandEvent &event) override
void onSwapDCSources(wxCommandEvent &event) override
const wxString & GetSimCommand() const
SPICE_VALIDATOR m_spiceValidator
DIALOG_SIM_SETTINGS(wxWindow *aParent, std::shared_ptr< SPICE_SIMULATOR_SETTINGS > &aSettings)
void updateDCSources(wxChar aType, wxChoice *aSource)
Update DC sweep source with symbols from schematic.
bool parseCommand(const wxString &aCommand)
Parse a Spice directive.
void SetNetlistExporter(NETLIST_EXPORTER_PSPICE_SIM *aExporter)
bool TransferDataFromWindow() override
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
void onLoadDirectives(wxCommandEvent &event) override
virtual bool Validate() override
NETLIST_EXPORTER_PSPICE_SIM * m_exporter
bool TransferDataToWindow() override
wxIntegerValidator< int > m_posIntValidator
void updateDCUnits(wxChar aType, wxChoice *aSource, wxStaticText *aStartValUnit, wxStaticText *aEndValUnit, wxStaticText *aStepUnit)
Update units on labels depending on selected source.
virtual void onInitDlg(wxInitDialogEvent &event) override
void onDCEnableSecondSource(wxCommandEvent &event) override
Storage for simulator specific settings.
Special netlist exporter flavor that allows one to override simulation commands.