Simplify (and fix) logic for starting new simulations.

Fixes https://gitlab.com/kicad/code/kicad/issues/13853
This commit is contained in:
Jeff Young 2023-02-11 23:25:32 +00:00
parent 1fb2d138b4
commit 84c72b087c
5 changed files with 40 additions and 45 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->GetSheetSimCommand() ); m_customTxt->SetValue( m_circuitModel->GetSchTextSimCommand() );
} }

View File

@ -72,7 +72,7 @@ SIM_TRACE_TYPE NGSPICE_CIRCUIT_MODEL::VectorToSignal( const std::string& aVector
} }
wxString NGSPICE_CIRCUIT_MODEL::GetSheetSimCommand() wxString NGSPICE_CIRCUIT_MODEL::GetSchTextSimCommand()
{ {
wxString simCmd; wxString simCmd;

View File

@ -79,7 +79,7 @@ public:
{ {
if( aCmd != m_simCommand ) if( aCmd != m_simCommand )
{ {
m_lastSheetSimCommand = GetSheetSimCommand(); m_lastSchTextSimCommand = GetSchTextSimCommand();
m_simCommand = aCmd; m_simCommand = aCmd;
} }
} }
@ -90,7 +90,7 @@ public:
*/ */
wxString GetSimCommand() 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). * 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 * Return the sim command present as a sheet directive when the sim command override was last
* updated. * updated.
* @return * @return
*/ */
wxString GetLastSheetSimCommand() const { return m_lastSheetSimCommand; } wxString GetLastSchTextSimCommand() const { return m_lastSchTextSimCommand; }
/** /**
* 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_lastSheetSimCommand; wxString m_lastSchTextSimCommand;
int m_options; int m_options;
}; };

View File

@ -721,21 +721,41 @@ void SIM_PLOT_FRAME::rebuildSignalsGrid( wxString aFilter )
} }
void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand ) void SIM_PLOT_FRAME::StartSimulation()
{ {
if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN ) if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN )
{ {
if( !EditSimCommand() if( !EditSimCommand() )
|| m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN ) return;
{
if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN )
return; return;
} }
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 ) );
m_simConsole->Clear(); if( plotWindow->GetType() == schTextSimType
&& schTextSimCommand != m_circuitModel->GetLastSchTextSimCommand() )
if( aSimCommand != wxEmptyString ) {
m_circuitModel->SetSimCommandOverride( aSimCommand ); 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() );
@ -750,33 +770,6 @@ void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand )
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 );
}
}
}
if( !plotWindow || plotWindow->GetType() != m_circuitModel->GetSimType() )
{
plotWindow = NewPlotPanel( m_circuitModel->GetSimCommand(),
m_circuitModel->GetSimOptions() );
}
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() )
@ -785,6 +778,8 @@ void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand )
wxString unconnected = wxString( wxS( "unconnected-(" ) ); wxString unconnected = wxString( wxS( "unconnected-(" ) );
unconnected.Replace( '(', '_' ); // Convert to SPICE markup unconnected.Replace( '(', '_' ); // Convert to SPICE markup
m_simConsole->Clear();
m_signals.clear(); m_signals.clear();
int options = m_circuitModel->GetSimOptions(); int options = m_circuitModel->GetSimOptions();
@ -1648,7 +1643,7 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath )
} }
NewPlotPanel( simCommand, simOptions ); NewPlotPanel( simCommand, simOptions );
StartSimulation( simCommand ); StartSimulation();
// Perform simulation, so plots can be added with values // Perform simulation, so plots can be added with values
do do

View File

@ -62,7 +62,7 @@ public:
SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ); SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
~SIM_PLOT_FRAME(); ~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. * Create a new plot panel for a given simulation type and adds it to the main notebook.
@ -209,7 +209,7 @@ public:
wxString GetCurrentSimCommand() const wxString GetCurrentSimCommand() const
{ {
if( getCurrentPlotWindow() == nullptr ) if( getCurrentPlotWindow() == nullptr )
return m_circuitModel->GetSheetSimCommand(); return m_circuitModel->GetSchTextSimCommand();
else else
return m_workbook->GetSimCommand( getCurrentPlotWindow() ); return m_workbook->GetSimCommand( getCurrentPlotWindow() );
} }