34#include <wx/tokenzr.h>
41static bool empty(
const wxTextEntryBase* aCtrl )
43 return aCtrl->GetValue().IsEmpty();
49 aCtrl->SetSelection( aCtrl->FindString( aStr ) );
55 if( aCtrl->GetSelection() >= 0 )
56 return aCtrl->GetString( aCtrl->GetSelection() );
63 std::shared_ptr<SPICE_CIRCUIT_MODEL> aCircuitModel,
64 std::shared_ptr<SPICE_SETTINGS>& aSettings ) :
66 m_simulatorFrame( aParent ),
67 m_circuitModel( aCircuitModel ),
68 m_settings( aSettings ),
69 m_spiceEmptyValidator( true )
124 if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::V )
131 int minWidth = GetTextExtent( wxS(
"XXX.XXXXXXX" ) ).x;
132 m_y1Min->SetMinSize( wxSize( minWidth, -1 ) );
133 m_y1Max->SetMinSize( wxSize( minWidth, -1 ) );
134 m_y2Min->SetMinSize( wxSize( minWidth, -1 ) );
135 m_y2Max->SetMinSize( wxSize( minWidth, -1 ) );
136 m_y3Min->SetMinSize( wxSize( minWidth, -1 ) );
137 m_y3Max->SetMinSize( wxSize( minWidth, -1 ) );
156 switch( settings->GetCompatibilityMode() )
158 case NGSPICE_COMPATIBILITY_MODE::USER_CONFIG:
m_compatibilityMode->SetSelection( 0 );
break;
164 default: wxFAIL_MSG( wxString::Format(
"Unknown NGSPICE_COMPATIBILITY_MODE %d.",
165 settings->GetCompatibilityMode() ) );
break;
175 event.Enable(
m_lockY1->GetValue() );
181 event.Enable(
m_lockY2->GetValue() );
187 event.Enable(
m_lockY3->GetValue() );
195 if( !plotTab->GetLabelY1().IsEmpty() )
198 m_lockY1->SetLabel( wxString::Format(
m_lockY1->GetLabel(), plotTab->GetLabelY1() ) );
199 m_y1Units->SetLabel( plotTab->GetUnitsY1() );
201 double min = 0.0, max = 0.0;
202 bool locked = plotTab->GetY1Scale( &min, &max );
205 if( !std::isnan( min ) )
208 if( !std::isnan( max ) )
212 if( !plotTab->GetLabelY2().IsEmpty() )
215 m_lockY2->SetLabel( wxString::Format(
m_lockY2->GetLabel(), plotTab->GetLabelY2() ) );
216 m_y2Units->SetLabel( plotTab->GetUnitsY2() );
218 double min = 0.0, max = 0.0;
219 bool locked = plotTab->GetY2Scale( &min, &max );
222 if( !std::isnan( min ) )
225 if( !std::isnan( max ) )
229 if( !plotTab->GetLabelY3().IsEmpty() )
232 m_lockY3->SetLabel( wxString::Format(
m_lockY3->GetLabel(), plotTab->GetLabelY3() ) );
233 m_y3Units->SetLabel( plotTab->GetUnitsY3() );
235 double min = 0.0, max = 0.0;
236 bool locked = plotTab->GetY3Scale( &min, &max );
239 if( !std::isnan( min ) )
242 if( !std::isnan( max ) )
246 m_grid->SetValue( plotTab->IsGridShown() );
247 m_legend->SetValue( plotTab->IsLegendShown() );
250#define GET_STR( val ) EDA_UNIT_UTILS::UI::MessageTextFromValue( unityScale, EDA_UNITS::UNSCALED, \
262 wxTextCtrl* aDcStop, wxTextCtrl* aDcIncr )
265 wxWindow* ctrlWithError =
nullptr;
267 if( aDcSource->GetSelection() >= 0 )
268 dcSource = aDcSource->GetString( aDcSource->GetSelection() );
270 if( dcSource.IsEmpty() )
273 ctrlWithError = aDcSource;
275 else if( !aDcStart->Validate() )
276 ctrlWithError = aDcStart;
277 else if( !aDcStop->Validate() )
278 ctrlWithError = aDcStop;
279 else if( !aDcIncr->Validate() )
280 ctrlWithError = aDcIncr;
284 ctrlWithError->SetFocus();
285 return wxEmptyString;
289 if( dcSource.Cmp(
"TEMP" ) )
292 return wxString::Format(
"%s %s %s %s", dcSource,
301 if( !wxDialog::TransferDataFromWindow() )
309 case 0: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::USER_CONFIG );
break;
310 case 1: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::NGSPICE );
break;
311 case 2: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::PSPICE );
break;
312 case 3: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::LTSPICE );
break;
313 case 4: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::LT_PSPICE );
break;
314 case 5: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::HSPICE );
break;
319 wxWindow* page =
m_simPages->GetCurrentPage();
345 wxString simCmd = wxString(
".dc " );
361 simCmd +=
" " + src2;
365 DisplayError(
this,
_(
"Source 1 and Source 2 must be different." ) );
384 m_simCommand = wxT(
"linearize" ) + vectors + wxS(
"\n" );
390 wxString input =
m_pzInput->GetStringSelection();
392 wxString output =
m_pzOutput->GetStringSelection();
394 wxString transferFunction = wxS(
"vol" );
395 wxString analyses = wxS(
"pz" );
398 transferFunction = wxS(
"cur" );
401 analyses = wxS(
"pol" );
403 analyses = wxS(
"zer" );
415 wxString output =
m_noiseMeas->GetStringSelection();
416 wxString ref =
m_noiseRef->GetStringSelection();
417 wxString noiseSource =
m_noiseSrc->GetStringSelection();
421 DisplayError(
this,
_(
"A frequency range must be specified." ) );
428 m_simCommand.Printf(
".noise v(%s%s) %s %s %s %s %s %s",
447 const wxString spc = wxS(
" " );
459 optionals = wxS(
"uic" );
465 else if( !optionals.IsEmpty() )
467 SPICE_VALUE maxStep = ( finalTime - startTime ) / 50.0;
469 if( maxStep > timeStep )
477 else if( !optionals.IsEmpty() )
478 optionals = wxS(
"0 " ) + optionals;
523#define TO_INT( ctrl ) (int) EDA_UNIT_UTILS::UI::ValueFromString( unityScale, EDA_UNITS::UNSCALED, \
528 if( !plotTab->GetLabelY1().IsEmpty() )
530 plotTab->SetY1Scale(
m_lockY1->GetValue(),
535 if( !plotTab->GetLabelY2().IsEmpty() )
537 plotTab->SetY2Scale(
m_lockY2->GetValue(),
542 if( !plotTab->GetLabelY3().IsEmpty() )
544 plotTab->SetY3Scale(
m_lockY3->GetValue(),
549 plotTab->GetPlotWin()->LockY(
m_lockY1->GetValue()
553 plotTab->ShowGrid(
m_grid->GetValue() );
554 plotTab->ShowLegend(
m_legend->GetValue() );
562 plotTab->GetPlotWin()->AdjustLimitedView();
563 plotTab->GetPlotWin()->UpdateAll();
570 wxString prevSelection;
572 if( !aSource->IsEmpty() )
573 prevSelection = aSource->GetString( aSource->GetSelection() );
575 std::set<wxString> sourcesList;
576 bool enableSrcSelection =
true;
582 if( ( aType ==
'R' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::R )
583 || ( aType ==
'V' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::V )
584 || ( aType ==
'I' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::I ) )
586 sourcesList.insert( item.refName );
591 enableSrcSelection =
false;
595 prevSelection = wxT(
"TEMP" );
596 sourcesList.insert( prevSelection );
597 enableSrcSelection =
false;
600 aSource->Enable( enableSrcSelection );
604 for(
const wxString& src : sourcesList )
605 aSource->Append( src );
608 aSource->SetStringSelection( prevSelection );
614 if( aCommand.IsEmpty() )
617 if( aCommand == wxT(
"*" ) )
619 SetTitle(
_(
"New Simulation Tab" ) );
645 wxStringTokenizer tokenizer( aCommand, wxS(
" \t\n\r" ), wxTOKEN_STRTOK );
646 wxString token = tokenizer.GetNextToken().Lower();
653 token = tokenizer.GetNextToken().Lower();
672 token = tokenizer.GetNextToken().Lower();
687 if( tokenizer.HasMoreTokens() )
701 if( src1.
m_source.IsSameAs( wxT(
"TEMP" ),
false ) )
714 if( src2.
m_source.IsSameAs( wxT(
"TEMP" ),
false ) )
735 wxString transferFunction;
736 wxString input, inputRef;
737 wxString output, outputRef;
740 m_circuitModel->ParsePZCommand( aCommand, &transferFunction, &input, &inputRef, &output,
741 &outputRef, &analyses );
748 m_pzFunctionType->SetSelection( transferFunction.Lower() ==
"cur" ? 1 : 0 );
774 &fStart, &fStop, &saveAll );
805 token = tokenizer.GetNextToken();
807 if( !token.IsEmpty() )
811 token = tokenizer.GetNextToken();
813 if( !token.IsEmpty() )
817 token = tokenizer.GetNextToken();
819 if( token.IsSameAs( wxS(
"uic" ) ) )
832 while( tokenizer.HasMoreTokens() )
850 wxString str =
m_commandType->GetString( event.GetSelection() );
879 for(
auto& couple : textCtrl )
881 wxString tmp = couple.first->GetValue();
882 couple.first->SetValue( couple.second->GetValue() );
883 couple.second->SetValue( tmp );
927 if( is2ndSrcEnabled )
931 if( fullType.Length() > 0 )
932 type = fullType.GetChar( 0 );
936 m_dcSource2->Enable( is2ndSrcEnabled && type !=
'T' );
944 wxStaticText* aEndValUnit, wxStaticText* aStepUnit )
950 case 'V': unit = wxS(
"V" );
break;
951 case 'I': unit = wxS(
"A" );
break;
952 case 'R': unit = wxS(
"Ω" );
break;
953 case 'T': unit = wxS(
"°C" );
break;
956 aStartValUnit->SetLabel( unit );
957 aEndValUnit->SetLabel( unit );
958 aStepUnit->SetLabel( unit );
985 if( aFilter.IsEmpty() )
986 aFilter = wxS(
"*" );
992 if( matcher.
Find( signal.Upper() ) )
1005 wxPoint pos = aEvent.GetPosition();
1007 int buttonWidth = ctrlRect.GetHeight();
1010 SetCursor( wxCURSOR_ARROW );
1011 else if(
m_inputSignalsFilter->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
1012 SetCursor( wxCURSOR_ARROW );
1014 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
wxCheckBox * m_saveAllEvents
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)
Abstract pattern-matching tool and implementations.
SIM_TYPE
< Possible simulation types