From d4e5861c62ccdc8e2c6496d7bea085fbf5bc5008 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 5 May 2021 20:26:56 +0200 Subject: [PATCH] Fix a few issue in simulation (noticeable only when the calculation time is high): - Wait for end of simulation before return from "C" locale to current locale (to avoid data files created by ngspice using curr locale instead of "C" locale) - Do not allow changing signal list to plot during simulation calculation (avoid crashes) --- eeschema/sim/ngspice.cpp | 23 ++++++++++++++++++++--- eeschema/sim/sim_plot_frame.cpp | 12 ++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index 31e83fa4b3..4d2c0a6f2c 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -282,8 +282,25 @@ bool NGSPICE::LoadNetlist( const string& aNetlist ) bool NGSPICE::Run() { - LOCALE_IO c_locale; // ngspice works correctly only with C locale - return Command( "bg_run" ); // bg_* commands execute in a separate thread + wxBusyCursor dummy; + + LOCALE_IO c_locale; // ngspice works correctly only with C locale + bool success = Command( "bg_run" ); // bg_* commands execute in a separate thread + + if( success ) + { + // wait for end of simulation. + // calling wxYield() allows printing activity, and stopping ngspice from GUI + // Also note: do not user wxSafeYield, because when using it we cannot stop + // ngspice from the GUI + do + { + wxMilliSleep( 50 ); + wxYield(); + } while( m_ngSpice_Running() ); + } + + return success; } @@ -296,7 +313,7 @@ bool NGSPICE::Stop() bool NGSPICE::IsRunning() { - LOCALE_IO c_locale; // ngspice works correctly only with C locale + // No need to use C locale here return m_ngSpice_Running(); } diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index d7e9f566f7..dd6cc22fba 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -1336,6 +1336,12 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) void SIM_PLOT_FRAME::onAddSignal( wxCommandEvent& event ) { + if( IsSimulationRunning() ) + { + DisplayInfoMessage( this, _( "Simulator is running. Try later" ) ); + return; + } + SIM_PLOT_PANEL* plotPanel = CurrentPlot(); if( !plotPanel || !m_exporter || plotPanel->GetType() != m_exporter->GetSimType() ) @@ -1354,6 +1360,12 @@ void SIM_PLOT_FRAME::onProbe( wxCommandEvent& event ) if( m_schematicFrame == NULL ) return; + if( IsSimulationRunning() ) + { + DisplayInfoMessage( this, _( "Simulator is running. Try later" ) ); + return; + } + m_schematicFrame->GetToolManager()->RunAction( EE_ACTIONS::simProbe ); m_schematicFrame->Raise(); }