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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * https://www.gnu.org/licenses/gpl-3.0.html
20  * or you may search the http://www.gnu.org website for the version 3 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef DIALOG_SIM_SETTINGS_BASE_H
26 #define DIALOG_SIM_SETTINGS_BASE_H
27 
29 #include <sim/spice_value.h>
30 
31 #include <wx/valnum.h>
32 
34 
36 {
37 public:
38  DIALOG_SIM_SETTINGS( wxWindow* aParent );
39 
40  const wxString& GetSimCommand() const
41  {
42  return m_simCommand;
43  }
44 
45  bool SetSimCommand( const wxString& aCommand )
46  {
47  bool res = parseCommand( aCommand );
48 
49  if( res )
50  m_simCommand = aCommand;
51 
52  return res;
53  }
54 
55  int GetNetlistOptions() const
56  {
57  return m_netlistOpts;
58  }
59 
61  {
62  m_exporter = aExporter;
63  }
64 
65  bool TransferDataFromWindow() override;
66  bool TransferDataToWindow() override;
67 
68  // The default dialog Validate() calls the validators of all widgets.
69  // This is not what we want; We want only validators of the selected page
70  // of the notbooks. So disable the wxDialog::Validate(), and let our
71  // TransferDataFromWindow doing the job.
72  virtual bool Validate() override
73  {
74  return true;
75  }
76 
77  int ShowModal() override;
78 
79 private:
81  {
85  };
86 
89  {
90  wxQueueEvent( m_dcEnable2, new wxCommandEvent( wxEVT_CHECKBOX ) );
91  wxQueueEvent( m_dcSourceType1, new wxCommandEvent( wxEVT_RADIOBOX ) );
92  wxQueueEvent( m_dcSourceType2, new wxCommandEvent( wxEVT_RADIOBOX ) );
93  }
94 
99  wxString evaluateDCControls( wxChoice* aDcSource, wxTextCtrl* aDcStart, wxTextCtrl* aDcStop,
100  wxTextCtrl* aDcIncr );
101 
105  void updateDCSources( wxChar aType, wxChoice* aSource );
106 
110  void updateDCUnits( wxChar aType, wxChoice* aSource, wxStaticText* aStartValUnit,
111  wxStaticText* aEndValUnit, wxStaticText* aStepUnit );
112 
113  virtual void onInitDlg( wxInitDialogEvent& event ) override
114  {
115  // Call the default wxDialog handler of a wxInitDialogEvent
117 
118  // Now all widgets have the size fixed, call FinishDialogSettings
120  }
121 
127  bool parseCommand( const wxString& aCommand );
128 
129  void onLoadDirectives( wxCommandEvent& event ) override
130  {
131  loadDirectives();
132  }
133 
134  void onDCEnableSecondSource( wxCommandEvent& event ) override;
135  void onSwapDCSources( wxCommandEvent& event ) override;
136  void onDCSource1Selected( wxCommandEvent& event ) override
137  {
138  wxChar type =
139  m_dcSourceType1->GetString( m_dcSourceType1->GetSelection() ).Upper().GetChar( 0 );
140  updateDCSources( type, m_dcSource1 );
143  }
144 
145  void onDCSource2Selected( wxCommandEvent& event ) override
146  {
147  wxChar type =
148  m_dcSourceType2->GetString( m_dcSourceType2->GetSelection() ).Upper().GetChar( 0 );
149  updateDCSources( type, m_dcSource2 );
152  }
153 
154  static wxString scaleToString( int aOption )
155  {
156  switch( aOption )
157  {
158  case DECADE:
159  return wxString( "dec" );
160 
161  case OCTAVE:
162  return wxString( "oct" );
163 
164  case LINEAR:
165  return wxString( "lin" );
166  }
167 
168  wxASSERT_MSG( false, "Unhandled scale type" );
169 
170  return wxEmptyString;
171  }
172 
173  void loadDirectives();
174  void updateNetlistOpts();
175 
176  wxString m_simCommand;
179 
182  wxIntegerValidator<int> m_posIntValidator;
183 };
184 
185 #endif /* DIALOG_SIM_SETTINGS_BASE_H */
bool SetSimCommand(const wxString &aCommand)
SPICE_VALIDATOR m_spiceEmptyValidator
wxString evaluateDCControls(wxChoice *aDcSource, wxTextCtrl *aDcStart, wxTextCtrl *aDcStop, wxTextCtrl *aDcIncr)
Reads values from one DC sweep source to form a part of sim 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
void updateDCSources(wxChar aType, wxChoice *aSource)
Updates DC sweep source with components from schematic.
bool parseCommand(const wxString &aCommand)
Parses 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
DIALOG_SIM_SETTINGS(wxWindow *aParent)
bool TransferDataToWindow() override
wxIntegerValidator< int > m_posIntValidator
void updateDCUnits(wxChar aType, wxChoice *aSource, wxStaticText *aStartValUnit, wxStaticText *aEndValUnit, wxStaticText *aStepUnit)
Updates units on labels depending on selected source.
void refreshUIControls()
!> Generates events to update UI state
virtual void onInitDlg(wxInitDialogEvent &event) override
void onDCEnableSecondSource(wxCommandEvent &event) override
Special netlist exporter flavor that allows one to override simulation commands.