32#include <wx/tokenzr.h>
41static bool empty(
const wxTextEntryBase* aCtrl )
43 return aCtrl->GetValue().IsEmpty();
49 aCtrl->SetSelection( aCtrl->FindString( aStr ) );
55 return aCtrl->GetString( aCtrl->GetSelection() );
60 std::shared_ptr<NGSPICE_CIRCUIT_MODEL> aCircuitModel,
61 std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& aSettings ) :
63 m_circuitModel( aCircuitModel ),
64 m_settings( aSettings ),
65 m_spiceEmptyValidator( true )
106 wxTextCtrl* aDcStop, wxTextCtrl* aDcIncr )
109 wxWindow* ctrlWithError =
nullptr;
111 if( aDcSource->GetSelection() >= 0 )
112 dcSource = aDcSource->GetString( aDcSource->GetSelection() );
114 if( dcSource.IsEmpty() )
117 ctrlWithError = aDcSource;
121 else if( !aDcStart->Validate() )
122 ctrlWithError = aDcStart;
123 else if( !aDcStop->Validate() )
124 ctrlWithError = aDcStop;
125 else if( !aDcIncr->Validate() )
126 ctrlWithError = aDcIncr;
130 ctrlWithError->SetFocus();
131 return wxEmptyString;
137 if( dcSource.Cmp(
"TEMP" ) )
138 dcSource =
m_circuitModel->GetItemName( std::string( dcSource.ToUTF8() ) );
145 catch( std::exception& e )
148 return wxEmptyString;
153 return wxEmptyString;
157 return wxEmptyString;
164 if( !wxDialog::TransferDataFromWindow() )
171 if( ngspiceSettings )
185 wxWindow* page =
m_simPages->GetCurrentPage();
200 wxString simCmd = wxString(
".dc " );
216 simCmd +=
" " + src2;
220 DisplayError(
this,
_(
"Source 1 and Source 2 must be different" ) );
282 KIDIALOG dlg(
this,
_(
"No valid simulation is configured." ),
_(
"Warning" ),
283 wxOK | wxCANCEL | wxICON_EXCLAMATION | wxCENTER );
285 dlg.SetExtendedMessage(
_(
"A valid simulation can be configured by selecting a "
286 "simulation tab, setting the simulation parameters and "
287 "clicking the OK button with the tab selected." ) );
289 wxMessageDialog::ButtonLabel(
_(
"Exit Without Valid Simulation" ) ),
290 wxMessageDialog::ButtonLabel(
_(
"Configure Valid Simulation" ) ) );
320 if( ngspiceSettings )
360 std::map<wxComboBox*, wxString> cmbNet = {
365 for(
const std::pair<wxComboBox* const, wxString>& c : cmbNet )
370 for(
const std::pair<wxComboBox* const, wxString>& c : cmbNet )
371 c.first->Append( net );
375 for(
const std::pair<wxComboBox* const, wxString>& c : cmbNet )
377 int idx = c.first->FindString( c.second );
379 if( idx != wxNOT_FOUND )
380 c.first->SetSelection( idx );
383 return DIALOG_SIM_COMMAND_BASE::ShowModal();
389 wxString prevSelection;
391 if( !aSource->IsEmpty() )
392 prevSelection = aSource->GetString( aSource->GetSelection() );
394 std::set<wxString> sourcesList;
395 bool enableSrcSelection =
true;
401 if( ( aType ==
'R' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::R )
402 || ( aType ==
'V' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::V )
405 sourcesList.insert( item.refName );
410 enableSrcSelection =
false;
414 prevSelection = wxT(
"TEMP" );
415 sourcesList.insert( prevSelection );
416 enableSrcSelection =
false;
419 aSource->Enable( enableSrcSelection );
423 for(
const wxString& src : sourcesList )
424 aSource->Append( src );
427 aSource->SetStringSelection( prevSelection );
433 if( aCommand.IsEmpty() )
436 wxStringTokenizer tokenizer( aCommand,
" " );
437 wxString tkn = tokenizer.GetNextToken().Lower();
445 tkn = tokenizer.GetNextToken().Lower();
449 else if( tkn ==
"oct" )
451 else if( tkn ==
"lin" )
461 else if( tkn ==
".dc" )
471 if( src1.
m_source.IsSameAs( wxT(
"TEMP" ),
false ) )
484 if( src2.
m_source.IsSameAs( wxT(
"TEMP" ),
false ) )
500 else if( tkn ==
".tran" )
509 tkn = tokenizer.GetNextToken();
514 else if( tkn ==
".op" )
539 for(
auto& couple : textCtrl )
541 wxString tmp = couple.first->GetValue();
542 couple.first->SetValue( couple.second->GetValue() );
543 couple.second->SetValue( tmp );
572 m_dcSource2->Enable( is2ndSrcEnabled && type !=
'T' );
580 wxStaticText* aStartValUnit, wxStaticText* aEndValUnit,
581 wxStaticText* aStepUnit )
587 case 'V': unit =
_(
"Volts" );
break;
588 case 'I': unit =
_(
"Amperes" );
break;
589 case 'R': unit =
_(
"Ohms" );
break;
590 case 'T': unit = wxT(
"\u00B0C" );
break;
593 aStartValUnit->SetLabel( unit );
594 aEndValUnit->SetLabel( unit );
595 aStepUnit->SetLabel( unit );
void SetupStandardButtons(std::map< int, wxString > aLabels={})
Class DIALOG_SIM_COMMAND_BASE.
wxTextCtrl * m_noisePointsNumber
wxChoice * m_dcSourceType2
wxStaticText * m_src1DCStartValUnit
wxBoxSizer * m_compatibilityMode
wxTextCtrl * m_transFinal
wxTextCtrl * m_noiseFreqStart
wxStaticText * m_src1DCStepUnit
wxChoice * m_compatibilityModeChoice
wxPanel * m_pgSensitivity
wxChoice * m_dcSourceType1
wxStaticText * m_src2DCStepUnit
wxPanel * m_pgTransferFunction
wxStaticText * m_src2DCStartValUnit
wxTextCtrl * m_acFreqStart
wxTextCtrl * m_noiseFreqStop
wxCheckBox * m_fixIncludePaths
wxStaticText * m_src2DCEndValUnit
wxTextCtrl * m_transInitial
wxStaticText * m_src1DCEndValUnit
wxTextCtrl * m_acFreqStop
wxTextCtrl * m_acPointsNumber
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 onSwapDCSources(wxCommandEvent &event) override
static wxString scaleToString(int aOption)
std::shared_ptr< NGSPICE_CIRCUIT_MODEL > m_circuitModel
wxIntegerValidator< int > m_posIntValidator
bool TransferDataFromWindow() override
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > m_settings
void updateDCSources(wxChar aType, wxChoice *aSource)
Update DC sweep source with symbols from schematic.
DIALOG_SIM_COMMAND(wxWindow *aParent, std::shared_ptr< NGSPICE_CIRCUIT_MODEL > aCircuitModel, std::shared_ptr< SPICE_SIMULATOR_SETTINGS > &aSettings)
SPICE_VALIDATOR m_spiceValidator
void onDCEnableSecondSource(wxCommandEvent &event) override
bool TransferDataToWindow() override
void updateDCUnits(wxChar aType, wxChoice *aSource, wxStaticText *aStartValUnit, wxStaticText *aEndValUnit, wxStaticText *aStepUnit)
Update units on labels depending on selected source.
bool parseCommand(const wxString &aCommand)
Parse a Spice directive.
SPICE_VALIDATOR m_spiceEmptyValidator
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
void DoNotShowCheckbox(wxString file, int line)
Checks the 'do not show again' setting for the dialog.
bool SetOKCancelLabels(const ButtonLabel &ok, const ButtonLabel &cancel) override
Shows the 'do not show again' checkbox.
Hold a translatable error message and may be used when throwing exceptions containing a translated er...
Container for Ngspice simulator settings.
void SetModelMode(NGSPICE_MODEL_MODE aMode)
NGSPICE_MODEL_MODE GetModelMode() const
Helper class to recognize Spice formatted values.
wxString ToSpiceString() const
Return string value in Spice format (e.g.
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
This file is part of the common library.
static void setStringSelection(wxChoice *aCtrl, const wxString &aStr)
static wxString getStringSelection(const wxChoice *aCtrl)
static bool empty(const wxTextEntryBase *aCtrl)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.