From 12c8f5b14d89966e2cd76751c09bcb80c3447b7b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 13 Feb 2024 14:38:02 +0000 Subject: [PATCH] Update compatibility mode and save flags in ngspice. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16955 --- eeschema/dialogs/dialog_sim_command.cpp | 1 + eeschema/sim/ngspice.cpp | 12 +++++++++--- eeschema/sim/ngspice.h | 2 ++ eeschema/sim/simulator_frame.cpp | 12 ++++++++++++ eeschema/sim/simulator_frame.h | 5 +++++ 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_command.cpp b/eeschema/dialogs/dialog_sim_command.cpp index f0e0ca9e7c..2e86741e56 100644 --- a/eeschema/dialogs/dialog_sim_command.cpp +++ b/eeschema/dialogs/dialog_sim_command.cpp @@ -511,6 +511,7 @@ void DIALOG_SIM_COMMAND::ApplySettings( SIM_TAB* aTab ) options &= ~NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS; aTab->SetSimOptions( options ); + m_simulatorFrame->ReloadSimulator( m_simCommand, options ); #define TO_INT( ctrl ) (int) EDA_UNIT_UTILS::UI::ValueFromString( unityScale, EDA_UNITS::UNSCALED, \ ctrl->GetValue() ) diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index f67fb6f0d0..2c4bfc5cc5 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -74,10 +74,8 @@ NGSPICE::NGSPICE() : NGSPICE::~NGSPICE() = default; -void NGSPICE::Init( const SPICE_SETTINGS* aSettings ) +void NGSPICE::updateNgspiceSettings() { - Command( "reset" ); - for( const std::string& command : GetSettingCommands() ) { wxLogTrace( traceNgspice, "Sending Ngspice configuration command '%s'.", command ); @@ -86,6 +84,13 @@ void NGSPICE::Init( const SPICE_SETTINGS* aSettings ) } +void NGSPICE::Init( const SPICE_SETTINGS* aSettings ) +{ + Command( "reset" ); + updateNgspiceSettings(); +} + + wxString NGSPICE::CurrentPlotName() const { return wxString( m_ngSpice_CurPlot() ); @@ -277,6 +282,7 @@ bool NGSPICE::Attach( const std::shared_ptr& aModel, const wxS if( model && model->GetNetlist( aSimCommand, aSimOptions, &formatter, aReporter ) ) { SIMULATOR::Attach( aModel, aSimCommand, aSimOptions, aReporter ); + updateNgspiceSettings(); LoadNetlist( formatter.GetString() ); return true; } diff --git a/eeschema/sim/ngspice.h b/eeschema/sim/ngspice.h index acdcc79072..fdde8c4d16 100644 --- a/eeschema/sim/ngspice.h +++ b/eeschema/sim/ngspice.h @@ -163,6 +163,8 @@ private: ///< Execute commands from a file bool loadSpinit( const std::string& aFileName ); + void updateNgspiceSettings(); + ///< Check a few different locations for codemodel files and returns one if it exists. std::string findCmPath() const; diff --git a/eeschema/sim/simulator_frame.cpp b/eeschema/sim/simulator_frame.cpp index 9aea5f4cd5..14bbfa7191 100644 --- a/eeschema/sim/simulator_frame.cpp +++ b/eeschema/sim/simulator_frame.cpp @@ -358,6 +358,18 @@ bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimO } +void SIMULATOR_FRAME::ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions ) +{ + wxString errors; + WX_STRING_REPORTER reporter( &errors ); + + if( !m_simulator->Attach( m_circuitModel, aSimCommand, aSimOptions, reporter ) ) + { + DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" ) + errors ); + } +} + + void SIMULATOR_FRAME::StartSimulation() { SIM_TAB* simTab = m_ui->GetCurrentSimTab(); diff --git a/eeschema/sim/simulator_frame.h b/eeschema/sim/simulator_frame.h index 7032321a4a..4da48bbcf5 100644 --- a/eeschema/sim/simulator_frame.h +++ b/eeschema/sim/simulator_frame.h @@ -80,6 +80,11 @@ public: */ bool LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions ); + /** + * Re-send the current command and settings to the simulator. Use the existing netlist. + */ + void ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions ); + void StartSimulation(); /**