From 7cc55d2d3a69b908f21360495ea2a27c65fc78f6 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 22 May 2023 16:52:01 +0100 Subject: [PATCH] Manual reimplementation of 84c72b087c548829908d7fbbecfd2fa5968cc98b --- 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, 80 insertions(+), 55 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_command.cpp b/eeschema/dialogs/dialog_sim_command.cpp index 593ec513f7..2428b8e099 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->GetSheetSimCommand() ); + m_customTxt->SetValue( m_circuitModel->GetSchTextSimCommand() ); } diff --git a/eeschema/sim/ngspice_circuit_model.cpp b/eeschema/sim/ngspice_circuit_model.cpp index 1fa84e2a5f..7eaad1d716 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::GetSheetSimCommand() +wxString NGSPICE_CIRCUIT_MODEL::GetSchTextSimCommand() { wxString simCmd; diff --git a/eeschema/sim/ngspice_circuit_model.h b/eeschema/sim/ngspice_circuit_model.h index faecc687a7..9cff7002af 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_lastSheetSimCommand = GetSheetSimCommand(); + m_lastSchTextSimCommand = GetSchTextSimCommand(); m_simCommand = aCmd; } } @@ -90,7 +90,7 @@ public: */ wxString GetSimCommand() { - return m_simCommand.IsEmpty() ? GetSheetSimCommand() : m_simCommand; + return m_simCommand.IsEmpty() ? GetSchTextSimCommand() : m_simCommand; } /** @@ -109,14 +109,14 @@ public: /** * Return simulation command directives placed in schematic sheets (if any). */ - wxString GetSheetSimCommand(); + wxString GetSchTextSimCommand(); /** * Return the sim command present as a sheet directive when the sim command override was last * updated. * @return */ - wxString GetLastSheetSimCommand() const { return m_lastSheetSimCommand; } + wxString GetLastSchTextSimCommand() const { return m_lastSchTextSimCommand; } /** * 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_lastSheetSimCommand; + wxString m_lastSchTextSimCommand; int m_options; }; diff --git a/eeschema/sim/sim_panel_base.h b/eeschema/sim/sim_panel_base.h index eed03acfee..8dc7d5c0c2 100644 --- a/eeschema/sim/sim_panel_base.h +++ b/eeschema/sim/sim_panel_base.h @@ -48,14 +48,8 @@ public: SIM_TYPE GetType() const; -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 ) + 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" ); @@ -63,8 +57,8 @@ protected: m_simCommand = aSimCommand; } - const int getSimOptions() const { return m_simOptions; } - void setSimOptions( int aOptions ) { m_simOptions = aOptions; } + 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 b4fccb0e03..1f20804e1c 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -446,15 +446,41 @@ void SIM_PLOT_FRAME::setSubWindowsSashSize() } -void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand ) +void SIM_PLOT_FRAME::StartSimulation() { - wxCHECK_RET( m_circuitModel->CommandToSimType( getCurrentSimCommand() ) != ST_UNKNOWN, - wxT( "Unknown simulation type" ) ); + if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN ) + { + if( !EditSimCommand() ) + return; - m_simConsole->Clear(); + if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN ) + return; + } - if( aSimCommand != wxEmptyString ) - m_circuitModel->SetSimCommandOverride( aSimCommand ); + 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 ); + } + } + } m_circuitModel->SetSimOptions( getCurrentOptions() ); @@ -475,33 +501,14 @@ void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand ) 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 @@ -1024,7 +1031,7 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) } NewPlotPanel( simCommand, simOptions ); - StartSimulation( simCommand ); + StartSimulation(); // Perform simulation, so plots can be added with values do @@ -1558,7 +1565,7 @@ void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event ) } -void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) +bool SIM_PLOT_FRAME::EditSimCommand() { SIM_PANEL_BASE* plotPanelWindow = getCurrentPlotWindow(); DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() ); @@ -1570,7 +1577,7 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) { DisplayErrorMessage( this, _( "Errors during netlist generation; simulation aborted.\n\n" ) + errors ); - return; + return false; } if( m_workbook->GetPageIndex( plotPanelWindow ) != wxNOT_FOUND ) @@ -1621,7 +1628,10 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) } m_simulator->Init(); + return true; } + + return false; } diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index 21e0f5ce51..eafb10fb56 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( const wxString& aSimCommand = wxEmptyString ); + void StartSimulation(); /** * Create a new plot panel for a given simulation type and adds it to the main notebook. @@ -137,9 +137,27 @@ 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, @@ -235,7 +253,7 @@ private: wxString getCurrentSimCommand() const { if( getCurrentPlotWindow() == nullptr ) - return m_circuitModel->GetSheetSimCommand(); + return m_circuitModel->GetSchTextSimCommand(); else return m_workbook->GetSimCommand( getCurrentPlotWindow() ); } @@ -296,7 +314,10 @@ private: void onWorkbookClrModified( wxCommandEvent& event ); void onSimulate( wxCommandEvent& event ); - void onSettings( wxCommandEvent& event ); + void onSettings( wxCommandEvent& event ) + { + EditSimCommand(); + } 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 fe43ad13a6..3ec6257210 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 3b731849f4..618911a4f5 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();