Revert "Manual reimplementation of 84c72b087c548829908d7fbbecfd2fa5968cc98b"

This reverts commit 7cc55d2d3a.
This commit is contained in:
Seth Hillbrand 2023-05-24 08:54:16 -07:00
parent 7cc55d2d3a
commit e2c0c6362f
8 changed files with 55 additions and 80 deletions

View File

@ -601,7 +601,7 @@ void DIALOG_SIM_COMMAND::updateDCUnits( wxChar aType, wxChoice* aSource,
void DIALOG_SIM_COMMAND::loadDirectives() void DIALOG_SIM_COMMAND::loadDirectives()
{ {
if( m_circuitModel ) if( m_circuitModel )
m_customTxt->SetValue( m_circuitModel->GetSchTextSimCommand() ); m_customTxt->SetValue( m_circuitModel->GetSheetSimCommand() );
} }

View File

@ -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; wxString simCmd;

View File

@ -79,7 +79,7 @@ public:
{ {
if( aCmd != m_simCommand ) if( aCmd != m_simCommand )
{ {
m_lastSchTextSimCommand = GetSchTextSimCommand(); m_lastSheetSimCommand = GetSheetSimCommand();
m_simCommand = aCmd; m_simCommand = aCmd;
} }
} }
@ -90,7 +90,7 @@ public:
*/ */
wxString GetSimCommand() 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). * 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 * Return the sim command present as a sheet directive when the sim command override was last
* updated. * updated.
* @return * @return
*/ */
wxString GetLastSchTextSimCommand() const { return m_lastSchTextSimCommand; } wxString GetLastSheetSimCommand() const { return m_lastSheetSimCommand; }
/** /**
* Parse a two-source .dc command directive into its symbols. * Parse a two-source .dc command directive into its symbols.
@ -148,7 +148,7 @@ private:
wxString m_simCommand; wxString m_simCommand;
///< Value of schematic sheet simulation command when override was last updated ///< Value of schematic sheet simulation command when override was last updated
wxString m_lastSchTextSimCommand; wxString m_lastSheetSimCommand;
int m_options; int m_options;
}; };

View File

@ -48,8 +48,14 @@ public:
SIM_TYPE GetType() const; SIM_TYPE GetType() const;
const wxString& GetSimCommand() const { return m_simCommand; } protected:
void SetSimCommand( const wxString& aSimCommand ) // 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 ), wxCHECK_RET( GetType() == NGSPICE_CIRCUIT_MODEL::CommandToSimType( aSimCommand ),
"Cannot change the type of simulation of the existing plot panel" ); "Cannot change the type of simulation of the existing plot panel" );
@ -57,8 +63,8 @@ public:
m_simCommand = aSimCommand; m_simCommand = aSimCommand;
} }
int GetSimOptions() const { return m_simOptions; } const int getSimOptions() const { return m_simOptions; }
void SetSimOptions( int aOptions ) { m_simOptions = aOptions; } void setSimOptions( int aOptions ) { m_simOptions = aOptions; }
private: private:
wxString m_simCommand; wxString m_simCommand;

View File

@ -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 ) wxCHECK_RET( m_circuitModel->CommandToSimType( getCurrentSimCommand() ) != ST_UNKNOWN,
{ wxT( "Unknown simulation type" ) );
if( !EditSimCommand() )
return;
if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN ) m_simConsole->Clear();
return;
}
wxString schTextSimCommand = m_circuitModel->GetSchTextSimCommand(); if( aSimCommand != wxEmptyString )
SIM_TYPE schTextSimType = NGSPICE_CIRCUIT_MODEL::CommandToSimType( schTextSimCommand ); m_circuitModel->SetSimCommandOverride( aSimCommand );
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() ); m_circuitModel->SetSimOptions( getCurrentOptions() );
@ -501,14 +475,33 @@ void SIM_PLOT_FRAME::StartSimulation()
return; 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<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock ); std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
if( simulatorLock.owns_lock() ) if( simulatorLock.owns_lock() )
{ {
wxBusyCursor toggle; wxBusyCursor toggle;
m_simConsole->Clear();
applyTuners(); applyTuners();
// Prevents memory leak on succeding simulations by deleting old vectors // 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 ); NewPlotPanel( simCommand, simOptions );
StartSimulation(); StartSimulation( simCommand );
// Perform simulation, so plots can be added with values // Perform simulation, so plots can be added with values
do 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(); SIM_PANEL_BASE* plotPanelWindow = getCurrentPlotWindow();
DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() ); 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" ) DisplayErrorMessage( this, _( "Errors during netlist generation; simulation aborted.\n\n" )
+ errors ); + errors );
return false; return;
} }
if( m_workbook->GetPageIndex( plotPanelWindow ) != wxNOT_FOUND ) if( m_workbook->GetPageIndex( plotPanelWindow ) != wxNOT_FOUND )
@ -1628,10 +1621,7 @@ bool SIM_PLOT_FRAME::EditSimCommand()
} }
m_simulator->Init(); m_simulator->Init();
return true;
} }
return false;
} }

View File

@ -64,7 +64,7 @@ public:
SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ); SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
~SIM_PLOT_FRAME(); ~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. * 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; 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 // Simulator doesn't host a tool framework
wxWindow* GetToolCanvas() const override { return nullptr; } wxWindow* GetToolCanvas() const override { return nullptr; }
bool EditSimCommand();
private: private:
/** /**
* Load the currently active workbook stored in the project settings. If there is none, * Load the currently active workbook stored in the project settings. If there is none,
@ -253,7 +235,7 @@ private:
wxString getCurrentSimCommand() const wxString getCurrentSimCommand() const
{ {
if( getCurrentPlotWindow() == nullptr ) if( getCurrentPlotWindow() == nullptr )
return m_circuitModel->GetSchTextSimCommand(); return m_circuitModel->GetSheetSimCommand();
else else
return m_workbook->GetSimCommand( getCurrentPlotWindow() ); return m_workbook->GetSimCommand( getCurrentPlotWindow() );
} }
@ -314,10 +296,7 @@ private:
void onWorkbookClrModified( wxCommandEvent& event ); void onWorkbookClrModified( wxCommandEvent& event );
void onSimulate( wxCommandEvent& event ); void onSimulate( wxCommandEvent& event );
void onSettings( wxCommandEvent& event ) void onSettings( wxCommandEvent& event );
{
EditSimCommand();
}
void onAddSignal( wxCommandEvent& event ); void onAddSignal( wxCommandEvent& event );
void onProbe( wxCommandEvent& event ); void onProbe( wxCommandEvent& event );
void onTune( wxCommandEvent& event ); void onTune( wxCommandEvent& event );

View File

@ -400,7 +400,7 @@ void SIM_PLOT_PANEL::updateAxes()
void SIM_PLOT_PANEL::prepareDCAxes() void SIM_PLOT_PANEL::prepareDCAxes()
{ {
wxString sim_cmd = GetSimCommand().Lower(); wxString sim_cmd = getSimCommand().Lower();
wxString rem; wxString rem;
if( sim_cmd.StartsWith( ".dc", &rem ) ) if( sim_cmd.StartsWith( ".dc", &rem ) )

View File

@ -54,24 +54,24 @@ public:
void SetSimCommand( SIM_PANEL_BASE* aPlotPanel, const wxString& aSimCommand ) void SetSimCommand( SIM_PANEL_BASE* aPlotPanel, const wxString& aSimCommand )
{ {
aPlotPanel->SetSimCommand( aSimCommand ); aPlotPanel->setSimCommand( aSimCommand );
setModified(); setModified();
} }
const wxString& GetSimCommand( const SIM_PANEL_BASE* aPlotPanel ) const wxString& GetSimCommand( const SIM_PANEL_BASE* aPlotPanel )
{ {
return aPlotPanel->GetSimCommand(); return aPlotPanel->getSimCommand();
} }
void SetSimOptions( SIM_PANEL_BASE* aPlotPanel, int aOptions ) void SetSimOptions( SIM_PANEL_BASE* aPlotPanel, int aOptions )
{ {
aPlotPanel->SetSimOptions( aOptions ); aPlotPanel->setSimOptions( aOptions );
setModified(); setModified();
} }
int GetSimOptions( const SIM_PANEL_BASE* aPlotPanel ) int GetSimOptions( const SIM_PANEL_BASE* aPlotPanel )
{ {
return aPlotPanel->GetSimOptions(); return aPlotPanel->getSimOptions();
} }
void ClrModified(); void ClrModified();