33#include <wx/tokenzr.h>
40static bool empty(
const wxTextEntryBase* aCtrl )
42 return aCtrl->GetValue().IsEmpty();
48 aCtrl->SetSelection( aCtrl->FindString( aStr ) );
54 if( aCtrl->GetSelection() >= 0 )
55 return aCtrl->GetString( aCtrl->GetSelection() );
62 std::shared_ptr<SPICE_CIRCUIT_MODEL> aCircuitModel,
63 std::shared_ptr<SPICE_SETTINGS>& aSettings ) :
65 m_simulatorFrame( aParent ),
66 m_circuitModel( aCircuitModel ),
67 m_settings( aSettings ),
68 m_spiceEmptyValidator( true )
123 if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::V )
130 int minWidth = GetTextExtent( wxS(
"XXX.XXXXXXX" ) ).x;
131 m_y1Min->SetMinSize( wxSize( minWidth, -1 ) );
132 m_y1Max->SetMinSize( wxSize( minWidth, -1 ) );
133 m_y2Min->SetMinSize( wxSize( minWidth, -1 ) );
134 m_y2Max->SetMinSize( wxSize( minWidth, -1 ) );
135 m_y3Min->SetMinSize( wxSize( minWidth, -1 ) );
136 m_y3Max->SetMinSize( wxSize( minWidth, -1 ) );
155 switch( settings->GetCompatibilityMode() )
157 case NGSPICE_COMPATIBILITY_MODE::USER_CONFIG:
m_compatibilityMode->SetSelection( 0 );
break;
163 default: wxFAIL_MSG( wxString::Format(
"Unknown NGSPICE_COMPATIBILITY_MODE %d.",
164 settings->GetCompatibilityMode() ) );
break;
174 event.Enable(
m_lockY1->GetValue() );
180 event.Enable(
m_lockY2->GetValue() );
186 event.Enable(
m_lockY3->GetValue() );
194 if( !plotTab->GetLabelY1().IsEmpty() )
197 m_lockY1->SetLabel( wxString::Format(
m_lockY1->GetLabel(), plotTab->GetLabelY1() ) );
198 m_y1Units->SetLabel( plotTab->GetUnitsY1() );
200 double min = 0.0, max = 0.0;
201 bool locked = plotTab->GetY1Scale( &min, &max );
204 if( !std::isnan( min ) )
207 if( !std::isnan( max ) )
211 if( !plotTab->GetLabelY2().IsEmpty() )
214 m_lockY2->SetLabel( wxString::Format(
m_lockY2->GetLabel(), plotTab->GetLabelY2() ) );
215 m_y2Units->SetLabel( plotTab->GetUnitsY2() );
217 double min = 0.0, max = 0.0;
218 bool locked = plotTab->GetY2Scale( &min, &max );
221 if( !std::isnan( min ) )
224 if( !std::isnan( max ) )
228 if( !plotTab->GetLabelY3().IsEmpty() )
231 m_lockY3->SetLabel( wxString::Format(
m_lockY3->GetLabel(), plotTab->GetLabelY3() ) );
232 m_y3Units->SetLabel( plotTab->GetUnitsY3() );
234 double min = 0.0, max = 0.0;
235 bool locked = plotTab->GetY3Scale( &min, &max );
238 if( !std::isnan( min ) )
241 if( !std::isnan( max ) )
245 m_grid->SetValue( plotTab->IsGridShown() );
246 m_legend->SetValue( plotTab->IsLegendShown() );
249#define GET_STR( val ) EDA_UNIT_UTILS::UI::MessageTextFromValue( unityScale, EDA_UNITS::UNSCALED, \
261 wxTextCtrl* aDcStop, wxTextCtrl* aDcIncr )
264 wxWindow* ctrlWithError =
nullptr;
266 if( aDcSource->GetSelection() >= 0 )
267 dcSource = aDcSource->GetString( aDcSource->GetSelection() );
269 if( dcSource.IsEmpty() )
272 ctrlWithError = aDcSource;
274 else if( !aDcStart->Validate() )
275 ctrlWithError = aDcStart;
276 else if( !aDcStop->Validate() )
277 ctrlWithError = aDcStop;
278 else if( !aDcIncr->Validate() )
279 ctrlWithError = aDcIncr;
283 ctrlWithError->SetFocus();
284 return wxEmptyString;
288 if( dcSource.Cmp(
"TEMP" ) )
289 dcSource =
m_circuitModel->GetItemName( std::string( dcSource.ToUTF8() ) );
291 return wxString::Format(
"%s %s %s %s", dcSource,
300 if( !wxDialog::TransferDataFromWindow() )
308 case 0: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::USER_CONFIG );
break;
309 case 1: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::NGSPICE );
break;
310 case 2: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::PSPICE );
break;
311 case 3: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::LTSPICE );
break;
312 case 4: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::LT_PSPICE );
break;
313 case 5: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::HSPICE );
break;
318 wxWindow* page =
m_simPages->GetCurrentPage();
344 wxString simCmd = wxString(
".dc " );
360 simCmd +=
" " + src2;
364 DisplayError(
this,
_(
"Source 1 and Source 2 must be different." ) );
383 m_simCommand = wxT(
"linearize" ) + vectors + wxS(
"\n" );
389 wxString input =
m_pzInput->GetStringSelection();
391 wxString output =
m_pzOutput->GetStringSelection();
393 wxString transferFunction = wxS(
"vol" );
394 wxString analyses = wxS(
"pz" );
397 transferFunction = wxS(
"cur" );
400 analyses = wxS(
"pol" );
402 analyses = wxS(
"zer" );
414 wxString output =
m_noiseMeas->GetStringSelection();
415 wxString ref =
m_noiseRef->GetStringSelection();
416 wxString noiseSource =
m_noiseSrc->GetStringSelection();
420 DisplayError(
this,
_(
"A frequency range must be specified." ) );
427 + wxString(
m_circuitModel->GetItemName( std::string( ref.ToUTF8() ) ) );
430 m_simCommand.Printf(
".noise v(%s%s) %s %s %s %s %s %s",
449 const wxString spc = wxS(
" " );
461 optionals = wxS(
"uic" );
467 else if( !optionals.IsEmpty() )
469 SPICE_VALUE maxStep = ( finalTime - startTime ) / 50.0;
471 if( maxStep > timeStep )
479 else if( !optionals.IsEmpty() )
480 optionals = wxS(
"0 " ) + optionals;
522#define TO_INT( ctrl ) (int) EDA_UNIT_UTILS::UI::ValueFromString( unityScale, EDA_UNITS::UNSCALED, \
527 if( !plotTab->GetLabelY1().IsEmpty() )
529 plotTab->SetY1Scale(
m_lockY1->GetValue(),
534 if( !plotTab->GetLabelY2().IsEmpty() )
536 plotTab->SetY2Scale(
m_lockY2->GetValue(),
541 if( !plotTab->GetLabelY3().IsEmpty() )
543 plotTab->SetY3Scale(
m_lockY3->GetValue(),
548 plotTab->GetPlotWin()->LockY(
m_lockY1->GetValue()
552 plotTab->ShowGrid(
m_grid->GetValue() );
553 plotTab->ShowLegend(
m_legend->GetValue() );
561 plotTab->GetPlotWin()->AdjustLimitedView();
562 plotTab->GetPlotWin()->UpdateAll();
569 wxString prevSelection;
571 if( !aSource->IsEmpty() )
572 prevSelection = aSource->GetString( aSource->GetSelection() );
574 std::set<wxString> sourcesList;
575 bool enableSrcSelection =
true;
581 if( ( aType ==
'R' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::R )
582 || ( aType ==
'V' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::V )
583 || ( aType ==
'I' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::I ) )
585 sourcesList.insert( item.refName );
590 enableSrcSelection =
false;
594 prevSelection = wxT(
"TEMP" );
595 sourcesList.insert( prevSelection );
596 enableSrcSelection =
false;
599 aSource->Enable( enableSrcSelection );
603 for(
const wxString& src : sourcesList )
604 aSource->Append( src );
607 aSource->SetStringSelection( prevSelection );
613 if( aCommand.IsEmpty() )
616 if( aCommand == wxT(
"*" ) )
618 SetTitle(
_(
"New Simulation Tab" ) );
644 wxStringTokenizer tokenizer( aCommand, wxS(
" \t\n\r" ), wxTOKEN_STRTOK );
645 wxString token = tokenizer.GetNextToken().Lower();
652 token = tokenizer.GetNextToken().Lower();
671 token = tokenizer.GetNextToken().Lower();
686 if( tokenizer.HasMoreTokens() )
700 if( src1.
m_source.IsSameAs( wxT(
"TEMP" ),
false ) )
713 if( src2.
m_source.IsSameAs( wxT(
"TEMP" ),
false ) )
734 wxString transferFunction;
735 wxString input, inputRef;
736 wxString output, outputRef;
739 m_circuitModel->ParsePZCommand( aCommand, &transferFunction, &input, &inputRef, &output,
740 &outputRef, &analyses );
747 m_pzFunctionType->SetSelection( transferFunction.Lower() ==
"cur" ? 1 : 0 );
773 &fStart, &fStop, &saveAll );
804 token = tokenizer.GetNextToken();
806 if( !token.IsEmpty() )
810 token = tokenizer.GetNextToken();
812 if( !token.IsEmpty() )
816 token = tokenizer.GetNextToken();
818 if( token.IsSameAs( wxS(
"uic" ) ) )
831 while( tokenizer.HasMoreTokens() )
849 wxString str =
m_commandType->GetString( event.GetSelection() );
878 for(
auto& couple : textCtrl )
880 wxString tmp = couple.first->GetValue();
881 couple.first->SetValue( couple.second->GetValue() );
882 couple.second->SetValue( tmp );
926 if( is2ndSrcEnabled )
930 if( fullType.Length() > 0 )
931 type = fullType.GetChar( 0 );
935 m_dcSource2->Enable( is2ndSrcEnabled && type !=
'T' );
943 wxStaticText* aEndValUnit, wxStaticText* aStepUnit )
949 case 'V': unit = wxS(
"V" );
break;
950 case 'I': unit = wxS(
"A" );
break;
951 case 'R': unit = wxS(
"Ω" );
break;
952 case 'T': unit = wxS(
"°C" );
break;
955 aStartValUnit->SetLabel( unit );
956 aEndValUnit->SetLabel( unit );
957 aStepUnit->SetLabel( unit );
984 if( aFilter.IsEmpty() )
985 aFilter = wxS(
"*" );
991 if( matcher.
Find( signal.Upper() ) )
1004 wxPoint pos = aEvent.GetPosition();
1006 int buttonWidth = ctrlRect.GetHeight();
1009 SetCursor( wxCURSOR_ARROW );
1010 else if(
m_inputSignalsFilter->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
1011 SetCursor( wxCURSOR_ARROW );
1013 SetCursor( wxCURSOR_IBEAM );
void SetupStandardButtons(std::map< int, wxString > aLabels={})
Class DIALOG_SIM_COMMAND_BASE.
wxTextCtrl * m_transMaxStep
wxTextCtrl * m_marginLeft
wxBoxSizer * m_compatibilityModeSizer
wxCheckListBox * m_inputSignalsList
wxTextCtrl * m_noisePointsNumber
wxChoice * m_dcSourceType2
wxRadioBox * m_noiseScale
wxStaticText * m_src1DCStartValUnit
wxTextCtrl * m_transFinal
wxTextCtrl * m_spPointsNumber
wxTextCtrl * m_noiseFreqStart
wxStaticText * m_src1DCStepUnit
wxSimplebook * m_simPages
wxCheckBox * m_dottedSecondary
wxCheckBox * m_useInitialConditions
wxTextCtrl * m_spFreqStop
wxChoice * m_dcSourceType1
wxBoxSizer * m_commandTypeSizer
wxSearchCtrl * m_inputSignalsFilter
wxStaticText * m_src2DCStepUnit
wxStaticText * m_src2DCStartValUnit
wxTextCtrl * m_acFreqStart
wxChoice * m_compatibilityMode
wxTextCtrl * m_marginBottom
wxTextCtrl * m_marginRight
wxCheckBox * m_saveAllNoise
wxTextCtrl * m_spFreqStart
wxTextCtrl * m_noiseFreqStop
wxCheckBox * m_fixIncludePaths
wxStaticText * m_src2DCEndValUnit
wxCheckBox * m_saveAllCurrents
wxChoice * m_pzFunctionType
wxCheckBox * m_saveAllVoltages
wxTextCtrl * m_transInitial
wxCheckBox * m_saveAllDissipations
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)
void SetPlotSettings(const SIM_TAB *aSimTab)
void OnCommandType(wxCommandEvent &event) override
void OnFilterMouseMoved(wxMouseEvent &event) override
wxIntegerValidator< int > m_posIntValidator
void onDCSource2Selected(wxCommandEvent &event) override
void OnUpdateUILockY3(wxUpdateUIEvent &event) override
bool TransferDataFromWindow() override
void updateDCSources(wxChar aType, wxChoice *aSource)
Update DC sweep source with symbols from schematic.
void OnUpdateUILockY1(wxUpdateUIEvent &event) override
std::set< wxString > m_fftInputSignals
SPICE_VALIDATOR m_spiceValidator
void onDCEnableSecondSource(wxCommandEvent &event) override
void ApplySettings(SIM_TAB *aTab)
SIMULATOR_FRAME * m_simulatorFrame
void onDCSource1Selected(wxCommandEvent &event) override
void parseCommand(const wxString &aCommand)
Parse a Spice directive.
bool TransferDataToWindow() override
void updateDCUnits(wxChar aType, wxStaticText *aStartValUnit, wxStaticText *aEndValUnit, wxStaticText *aStepUnit)
Update units on labels depending on selected source.
void OnFilterText(wxCommandEvent &event) override
std::shared_ptr< SPICE_CIRCUIT_MODEL > m_circuitModel
DIALOG_SIM_COMMAND(SIMULATOR_FRAME *aParent, std::shared_ptr< SPICE_CIRCUIT_MODEL > aCircuitModel, std::shared_ptr< SPICE_SETTINGS > &aSettings)
std::shared_ptr< SPICE_SETTINGS > m_settings
void OnUpdateUILockY2(wxUpdateUIEvent &event) override
SPICE_VALIDATOR m_spiceEmptyValidator
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
Container for Ngspice simulator settings.
The SIMULATOR_FRAME holds the main user-interface for running simulations.
const std::vector< wxString > Signals()
void ReloadSimulator(const wxString &aSimCommand, unsigned aSimOptions)
Re-send the current command and settings to the simulator.
void SetSimOptions(int aOptions)
static std::string Normalize(double aValue)
static double ToDouble(const std::string &aString, double aDefault=NAN)
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Return simulation type basing on a simulation command directive.
static wxString TypeToName(SIM_TYPE aType, bool aShortName)
Return a string with simulation name based on enum.
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)
SIM_TYPE
< Possible simulation types