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 ) );
157 switch( settings->GetCompatibilityMode() )
159 case NGSPICE_COMPATIBILITY_MODE::USER_CONFIG:
m_compatibilityMode->SetSelection( 0 );
break;
165 default: wxFAIL_MSG( wxString::Format(
"Unknown NGSPICE_COMPATIBILITY_MODE %d.",
166 settings->GetCompatibilityMode() ) );
break;
176 event.Enable(
m_lockY1->GetValue() );
182 event.Enable(
m_lockY2->GetValue() );
188 event.Enable(
m_lockY3->GetValue() );
196 if( !plotTab->GetLabelY1().IsEmpty() )
199 m_lockY1->SetLabel( wxString::Format(
m_lockY1->GetLabel(), plotTab->GetLabelY1() ) );
200 m_y1Units->SetLabel( plotTab->GetUnitsY1() );
202 double min = 0.0, max = 0.0;
203 bool locked = plotTab->GetY1Scale( &min, &max );
206 if( !std::isnan( min ) )
209 if( !std::isnan( max ) )
213 if( !plotTab->GetLabelY2().IsEmpty() )
216 m_lockY2->SetLabel( wxString::Format(
m_lockY2->GetLabel(), plotTab->GetLabelY2() ) );
217 m_y2Units->SetLabel( plotTab->GetUnitsY2() );
219 double min = 0.0, max = 0.0;
220 bool locked = plotTab->GetY2Scale( &min, &max );
223 if( !std::isnan( min ) )
226 if( !std::isnan( max ) )
230 if( !plotTab->GetLabelY3().IsEmpty() )
233 m_lockY3->SetLabel( wxString::Format(
m_lockY3->GetLabel(), plotTab->GetLabelY3() ) );
234 m_y3Units->SetLabel( plotTab->GetUnitsY3() );
236 double min = 0.0, max = 0.0;
237 bool locked = plotTab->GetY3Scale( &min, &max );
240 if( !std::isnan( min ) )
243 if( !std::isnan( max ) )
247 m_grid->SetValue( plotTab->IsGridShown() );
248 m_legend->SetValue( plotTab->IsLegendShown() );
251#define GET_STR( val ) EDA_UNIT_UTILS::UI::MessageTextFromValue( unityScale, EDA_UNITS::UNSCALED, \
263 wxTextCtrl* aDcStop, wxTextCtrl* aDcIncr )
266 wxWindow* ctrlWithError =
nullptr;
268 if( aDcSource->GetSelection() >= 0 )
269 dcSource = aDcSource->GetString( aDcSource->GetSelection() );
271 if( dcSource.IsEmpty() )
274 ctrlWithError = aDcSource;
276 else if( !aDcStart->Validate() )
277 ctrlWithError = aDcStart;
278 else if( !aDcStop->Validate() )
279 ctrlWithError = aDcStop;
280 else if( !aDcIncr->Validate() )
281 ctrlWithError = aDcIncr;
285 ctrlWithError->SetFocus();
286 return wxEmptyString;
290 if( dcSource.Cmp(
"TEMP" ) )
293 return wxString::Format(
"%s %s %s %s", dcSource,
302 if( !wxDialog::TransferDataFromWindow() )
310 case 0: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::USER_CONFIG );
break;
311 case 1: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::NGSPICE );
break;
312 case 2: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::PSPICE );
break;
313 case 3: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::LTSPICE );
break;
314 case 4: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::LT_PSPICE );
break;
315 case 5: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::HSPICE );
break;
320 wxWindow* page =
m_simPages->GetCurrentPage();
346 wxString simCmd = wxString(
".dc " );
362 simCmd +=
" " + src2;
366 DisplayError(
this,
_(
"Source 1 and Source 2 must be different." ) );
385 m_simCommand = wxT(
"linearize" ) + vectors + wxS(
"\n" );
391 wxString input =
m_pzInput->GetStringSelection();
393 wxString output =
m_pzOutput->GetStringSelection();
395 wxString transferFunction = wxS(
"vol" );
396 wxString analyses = wxS(
"pz" );
399 transferFunction = wxS(
"cur" );
402 analyses = wxS(
"pol" );
404 analyses = wxS(
"zer" );
416 wxString output =
m_noiseMeas->GetStringSelection();
417 wxString ref =
m_noiseRef->GetStringSelection();
418 wxString noiseSource =
m_noiseSrc->GetStringSelection();
422 DisplayError(
this,
_(
"A frequency range must be specified." ) );
429 m_simCommand.Printf(
".noise v(%s%s) %s %s %s %s %s %s",
448 const wxString spc = wxS(
" " );
460 optionals = wxS(
"uic" );
466 else if( !optionals.IsEmpty() )
468 SPICE_VALUE maxStep = ( finalTime - startTime ) / 50.0;
470 if( maxStep > timeStep )
478 else if( !optionals.IsEmpty() )
479 optionals = wxS(
"0 " ) + optionals;
524#define TO_INT( ctrl ) (int) EDA_UNIT_UTILS::UI::ValueFromString( unityScale, EDA_UNITS::UNSCALED, \
529 if( !plotTab->GetLabelY1().IsEmpty() )
531 plotTab->SetY1Scale(
m_lockY1->GetValue(),
536 if( !plotTab->GetLabelY2().IsEmpty() )
538 plotTab->SetY2Scale(
m_lockY2->GetValue(),
543 if( !plotTab->GetLabelY3().IsEmpty() )
545 plotTab->SetY3Scale(
m_lockY3->GetValue(),
550 plotTab->GetPlotWin()->LockY(
m_lockY1->GetValue()
554 plotTab->ShowGrid(
m_grid->GetValue() );
555 plotTab->ShowLegend(
m_legend->GetValue() );
563 plotTab->GetPlotWin()->AdjustLimitedView();
564 plotTab->GetPlotWin()->UpdateAll();
571 wxString prevSelection;
573 if( !aSource->IsEmpty() )
574 prevSelection = aSource->GetString( aSource->GetSelection() );
576 std::set<wxString> sourcesList;
577 bool enableSrcSelection =
true;
583 if( ( aType ==
'R' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::R )
584 || ( aType ==
'V' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::V )
585 || ( aType ==
'I' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::I ) )
587 sourcesList.insert( item.refName );
592 enableSrcSelection =
false;
596 prevSelection = wxT(
"TEMP" );
597 sourcesList.insert( prevSelection );
598 enableSrcSelection =
false;
601 aSource->Enable( enableSrcSelection );
605 for(
const wxString& src : sourcesList )
606 aSource->Append( src );
609 aSource->SetStringSelection( prevSelection );
615 if( aCommand.IsEmpty() )
618 if( aCommand == wxT(
"*" ) )
620 SetTitle(
_(
"New Simulation Tab" ) );
646 wxStringTokenizer tokenizer( aCommand, wxS(
" \t\n\r" ), wxTOKEN_STRTOK );
647 wxString token = tokenizer.GetNextToken().Lower();
654 token = tokenizer.GetNextToken().Lower();
673 token = tokenizer.GetNextToken().Lower();
688 if( tokenizer.HasMoreTokens() )
702 if( src1.
m_source.IsSameAs( wxT(
"TEMP" ),
false ) )
715 if( src2.
m_source.IsSameAs( wxT(
"TEMP" ),
false ) )
736 wxString transferFunction;
737 wxString input, inputRef;
738 wxString output, outputRef;
741 m_circuitModel->ParsePZCommand( aCommand, &transferFunction, &input, &inputRef, &output,
742 &outputRef, &analyses );
749 m_pzFunctionType->SetSelection( transferFunction.Lower() ==
"cur" ? 1 : 0 );
775 &fStart, &fStop, &saveAll );
806 token = tokenizer.GetNextToken();
808 if( !token.IsEmpty() )
812 token = tokenizer.GetNextToken();
814 if( !token.IsEmpty() )
818 token = tokenizer.GetNextToken();
820 if( token.IsSameAs( wxS(
"uic" ) ) )
833 while( tokenizer.HasMoreTokens() )
851 wxString str =
m_commandType->GetString( event.GetSelection() );
880 for(
auto& couple : textCtrl )
882 wxString tmp = couple.first->GetValue();
883 couple.first->SetValue( couple.second->GetValue() );
884 couple.second->SetValue( tmp );
928 if( is2ndSrcEnabled )
932 if( fullType.Length() > 0 )
933 type = fullType.GetChar( 0 );
937 m_dcSource2->Enable( is2ndSrcEnabled && type !=
'T' );
945 wxStaticText* aEndValUnit, wxStaticText* aStepUnit )
951 case 'V': unit = wxS(
"V" );
break;
952 case 'I': unit = wxS(
"A" );
break;
953 case 'R': unit = wxS(
"Ω" );
break;
954 case 'T': unit = wxS(
"°C" );
break;
957 aStartValUnit->SetLabel( unit );
958 aEndValUnit->SetLabel( unit );
959 aStepUnit->SetLabel( unit );
986 if( aFilter.IsEmpty() )
987 aFilter = wxS(
"*" );
993 if( matcher.
Find( signal.Upper() ) )
1006 wxPoint pos = aEvent.GetPosition();
1008 int buttonWidth = ctrlRect.GetHeight();
1011 SetCursor( wxCURSOR_ARROW );
1013 && pos.x > ctrlRect.GetWidth() - buttonWidth )
1014 SetCursor( wxCURSOR_ARROW );
1016 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)
Look in all existing matchers, return the earliest match of any of the existing.
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