From e2c0c6362ffed1f0badf57ec35054161d6c71c43 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 24 May 2023 08:54:16 -0700 Subject: [PATCH] Revert "Manual reimplementation of 84c72b087c548829908d7fbbecfd2fa5968cc98b" This reverts commit 7cc55d2d3a69b908f21360495ea2a27c65fc78f6. --- eeschema/dialogs/dialog_sim_command.cpp | 2 +- eeschema/sim/ngspice_circuit_model.cpp | 2 +- eeschema/sim/ngspice_circuit_model.h | 10 ++-- eeschema/sim/sim_panel_base.h | 14 +++-- eeschema/sim/sim_plot_frame.cpp | 70 +++++++++++-------------- eeschema/sim/sim_plot_frame.h | 27 ++-------- eeschema/sim/sim_plot_panel.cpp | 2 +- eeschema/sim/sim_workbook.h | 8 +-- 8 files changed, 55 insertions(+), 80 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_command.cpp b/eeschema/dialogs/dialog_sim_command.cpp index 2428b8e099..593ec513f7 100644 --- a/eeschema/dialogs/dialog_sim_command.cpp +++ b/eeschema/dialogs/dialog_sim_command.cpp @@ -601,7 +601,7 @@ void DIALOG_SIM_COMMAND::updateDCUnits( wxChar aType, wxChoice* aSource, void DIALOG_SIM_COMMAND::loadDirectives() { if( m_circuitModel ) - m_customTxt->SetValue( m_circuitModel->GetSchTextSimCommand() ); + m_customTxt->SetValue( m_circuitModel->GetSheetSimCommand() ); } diff --git a/eeschema/sim/ngspice_circuit_model.cpp b/eeschema/sim/ngspice_circuit_model.cpp index 7eaad1d716..1fa84e2a5f 100644 --- a/eeschema/sim/ngspice_circuit_model.cpp +++ b/eeschema/sim/ngspice_circuit_model.cpp @@ -72,7 +72,7 @@ SIM_PLOT_TYPE NGSPICE_CIRCUIT_MODEL::VectorToSignal( const std::string& aVector, } -wxString NGSPICE_CIRCUIT_MODEL::GetSchTextSimCommand() +wxString NGSPICE_CIRCUIT_MODEL::GetSheetSimCommand() { wxString simCmd; diff --git a/eeschema/sim/ngspice_circuit_model.h b/eeschema/sim/ngspice_circuit_model.h index 9cff7002af..faecc687a7 100644 --- a/eeschema/sim/ngspice_circuit_model.h +++ b/eeschema/sim/ngspice_circuit_model.h @@ -79,7 +79,7 @@ public: { if( aCmd != m_simCommand ) { - m_lastSchTextSimCommand = GetSchTextSimCommand(); + m_lastSheetSimCommand = GetSheetSimCommand(); m_simCommand = aCmd; } } @@ -90,7 +90,7 @@ public: */ wxString GetSimCommand() { - return m_simCommand.IsEmpty() ? GetSchTextSimCommand() : m_simCommand; + return m_simCommand.IsEmpty() ? GetSheetSimCommand() : m_simCommand; } /** @@ -109,14 +109,14 @@ public: /** * Return simulation command directives placed in schematic sheets (if any). */ - wxString GetSchTextSimCommand(); + wxString GetSheetSimCommand(); /** * Return the sim command present as a sheet directive when the sim command override was last * updated. * @return */ - wxString GetLastSchTextSimCommand() const { return m_lastSchTextSimCommand; } + wxString GetLastSheetSimCommand() const { return m_lastSheetSimCommand; } /** * Parse a two-source .dc command directive into its symbols. @@ -148,7 +148,7 @@ private: wxString m_simCommand; ///< Value of schematic sheet simulation command when override was last updated - wxString m_lastSchTextSimCommand; + wxString m_lastSheetSimCommand; int m_options; }; diff --git a/eeschema/sim/sim_panel_base.h b/eeschema/sim/sim_panel_base.h index 8dc7d5c0c2..eed03acfee 100644 --- a/eeschema/sim/sim_panel_base.h +++ b/eeschema/sim/sim_panel_base.h @@ -48,8 +48,14 @@ public: SIM_TYPE GetType() const; - const wxString& GetSimCommand() const { return m_simCommand; } - void SetSimCommand( const wxString& aSimCommand ) +protected: + // We use `protected` here because members should be accessible from outside only through a + // workbook object, to prevent anyone from modifying the state without its knowledge. Otherwise + // we risk some things not getting saved. + + const wxString& getSimCommand() const { return m_simCommand; } + + void setSimCommand( const wxString& aSimCommand ) { wxCHECK_RET( GetType() == NGSPICE_CIRCUIT_MODEL::CommandToSimType( aSimCommand ), "Cannot change the type of simulation of the existing plot panel" ); @@ -57,8 +63,8 @@ public: m_simCommand = aSimCommand; } - int GetSimOptions() const { return m_simOptions; } - void SetSimOptions( int aOptions ) { m_simOptions = aOptions; } + const int getSimOptions() const { return m_simOptions; } + void setSimOptions( int aOptions ) { m_simOptions = aOptions; } private: wxString m_simCommand; diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 1f20804e1c..b4fccb0e03 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -446,41 +446,15 @@ void SIM_PLOT_FRAME::setSubWindowsSashSize() } -void SIM_PLOT_FRAME::StartSimulation() +void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand ) { - if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN ) - { - if( !EditSimCommand() ) - return; + wxCHECK_RET( m_circuitModel->CommandToSimType( getCurrentSimCommand() ) != ST_UNKNOWN, + wxT( "Unknown simulation type" ) ); - if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN ) - return; - } + m_simConsole->Clear(); - wxString schTextSimCommand = m_circuitModel->GetSchTextSimCommand(); - SIM_TYPE schTextSimType = NGSPICE_CIRCUIT_MODEL::CommandToSimType( schTextSimCommand ); - SIM_PANEL_BASE* plotWindow = getCurrentPlotWindow(); - - if( !plotWindow ) - { - plotWindow = NewPlotPanel( schTextSimCommand, m_circuitModel->GetSimOptions() ); - m_workbook->SetSimCommand( plotWindow, schTextSimCommand ); - } - else - { - m_circuitModel->SetSimCommandOverride( m_workbook->GetSimCommand( plotWindow ) ); - - if( plotWindow->GetType() == schTextSimType - && schTextSimCommand != m_circuitModel->GetLastSchTextSimCommand() ) - { - if( IsOK( this, _( "Schematic sheet simulation command directive has changed. " - "Do you wish to update the Simulation Command?" ) ) ) - { - m_circuitModel->SetSimCommandOverride( wxEmptyString ); - m_workbook->SetSimCommand( plotWindow, schTextSimCommand ); - } - } - } + if( aSimCommand != wxEmptyString ) + m_circuitModel->SetSimCommandOverride( aSimCommand ); m_circuitModel->SetSimOptions( getCurrentOptions() ); @@ -501,14 +475,33 @@ void SIM_PLOT_FRAME::StartSimulation() return; } + SIM_PANEL_BASE* plotWindow = getCurrentPlotWindow(); + wxString sheetSimCommand = m_circuitModel->GetSheetSimCommand(); + + if( plotWindow + && plotWindow->GetType() == NGSPICE_CIRCUIT_MODEL::CommandToSimType( sheetSimCommand ) ) + { + if( m_circuitModel->GetSimCommandOverride().IsEmpty() ) + { + m_workbook->SetSimCommand( plotWindow, sheetSimCommand ); + } + else if( sheetSimCommand != m_circuitModel->GetLastSheetSimCommand() ) + { + if( IsOK( this, _( "Schematic sheet simulation command directive has changed. Do you " + "wish to update the Simulation Command?" ) ) ) + { + m_circuitModel->SetSimCommandOverride( wxEmptyString ); + m_workbook->SetSimCommand( plotWindow, sheetSimCommand ); + } + } + } + std::unique_lock simulatorLock( m_simulator->GetMutex(), std::try_to_lock ); if( simulatorLock.owns_lock() ) { wxBusyCursor toggle; - m_simConsole->Clear(); - applyTuners(); // Prevents memory leak on succeding simulations by deleting old vectors @@ -1031,7 +1024,7 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) } NewPlotPanel( simCommand, simOptions ); - StartSimulation(); + StartSimulation( simCommand ); // Perform simulation, so plots can be added with values do @@ -1565,7 +1558,7 @@ void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event ) } -bool SIM_PLOT_FRAME::EditSimCommand() +void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) { SIM_PANEL_BASE* plotPanelWindow = getCurrentPlotWindow(); DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() ); @@ -1577,7 +1570,7 @@ bool SIM_PLOT_FRAME::EditSimCommand() { DisplayErrorMessage( this, _( "Errors during netlist generation; simulation aborted.\n\n" ) + errors ); - return false; + return; } if( m_workbook->GetPageIndex( plotPanelWindow ) != wxNOT_FOUND ) @@ -1628,10 +1621,7 @@ bool SIM_PLOT_FRAME::EditSimCommand() } m_simulator->Init(); - return true; } - - return false; } diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index eafb10fb56..21e0f5ce51 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -64,7 +64,7 @@ public: SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ); ~SIM_PLOT_FRAME(); - void StartSimulation(); + void StartSimulation( const wxString& aSimCommand = wxEmptyString ); /** * Create a new plot panel for a given simulation type and adds it to the main notebook. @@ -137,27 +137,9 @@ public: WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg ) override; - wxString GetCurrentSimCommand() const - { - if( getCurrentPlotWindow() ) - return getCurrentPlotWindow()->GetSimCommand(); - else - return m_circuitModel->GetSchTextSimCommand(); - } - - int GetCurrentOptions() const - { - if( getCurrentPlotWindow() ) - return getCurrentPlotWindow()->GetSimOptions(); - else - return m_circuitModel->GetSimOptions(); - } - // Simulator doesn't host a tool framework wxWindow* GetToolCanvas() const override { return nullptr; } - bool EditSimCommand(); - private: /** * Load the currently active workbook stored in the project settings. If there is none, @@ -253,7 +235,7 @@ private: wxString getCurrentSimCommand() const { if( getCurrentPlotWindow() == nullptr ) - return m_circuitModel->GetSchTextSimCommand(); + return m_circuitModel->GetSheetSimCommand(); else return m_workbook->GetSimCommand( getCurrentPlotWindow() ); } @@ -314,10 +296,7 @@ private: void onWorkbookClrModified( wxCommandEvent& event ); void onSimulate( wxCommandEvent& event ); - void onSettings( wxCommandEvent& event ) - { - EditSimCommand(); - } + void onSettings( wxCommandEvent& event ); void onAddSignal( wxCommandEvent& event ); void onProbe( wxCommandEvent& event ); void onTune( wxCommandEvent& event ); diff --git a/eeschema/sim/sim_plot_panel.cpp b/eeschema/sim/sim_plot_panel.cpp index 3ec6257210..fe43ad13a6 100644 --- a/eeschema/sim/sim_plot_panel.cpp +++ b/eeschema/sim/sim_plot_panel.cpp @@ -400,7 +400,7 @@ void SIM_PLOT_PANEL::updateAxes() void SIM_PLOT_PANEL::prepareDCAxes() { - wxString sim_cmd = GetSimCommand().Lower(); + wxString sim_cmd = getSimCommand().Lower(); wxString rem; if( sim_cmd.StartsWith( ".dc", &rem ) ) diff --git a/eeschema/sim/sim_workbook.h b/eeschema/sim/sim_workbook.h index 618911a4f5..3b731849f4 100644 --- a/eeschema/sim/sim_workbook.h +++ b/eeschema/sim/sim_workbook.h @@ -54,24 +54,24 @@ public: void SetSimCommand( SIM_PANEL_BASE* aPlotPanel, const wxString& aSimCommand ) { - aPlotPanel->SetSimCommand( aSimCommand ); + aPlotPanel->setSimCommand( aSimCommand ); setModified(); } const wxString& GetSimCommand( const SIM_PANEL_BASE* aPlotPanel ) { - return aPlotPanel->GetSimCommand(); + return aPlotPanel->getSimCommand(); } void SetSimOptions( SIM_PANEL_BASE* aPlotPanel, int aOptions ) { - aPlotPanel->SetSimOptions( aOptions ); + aPlotPanel->setSimOptions( aOptions ); setModified(); } int GetSimOptions( const SIM_PANEL_BASE* aPlotPanel ) { - return aPlotPanel->GetSimOptions(); + return aPlotPanel->getSimOptions(); } void ClrModified();