From 1ff279bf723daf4940c350b03798d02d4f584f46 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 20 Sep 2023 17:23:08 +0100 Subject: [PATCH] Don't auto-adjust time axis while sim is running. Just use start and end time. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15673 --- eeschema/sim/sim_plot_tab.cpp | 67 +++++++++++++++++++++++------ eeschema/sim/simulator_frame_ui.cpp | 9 ++-- include/widgets/mathplot.h | 2 +- 3 files changed, 58 insertions(+), 20 deletions(-) diff --git a/eeschema/sim/sim_plot_tab.cpp b/eeschema/sim/sim_plot_tab.cpp index ee5a529c77..84885c6d4a 100644 --- a/eeschema/sim/sim_plot_tab.cpp +++ b/eeschema/sim/sim_plot_tab.cpp @@ -191,26 +191,40 @@ class TIME_SCALE : public LIN_SCALE { public: TIME_SCALE( const wxString& name, const wxString& unit, int flags ) : - LIN_SCALE( name, unit, flags ) + LIN_SCALE( name, unit, flags ), + m_startTime( 0.0 ), + m_endTime( 1.0 ) {}; void ExtendDataRange( double minV, double maxV ) override { - if( !m_rangeSet ) - { - m_minV = minV; - m_maxV = maxV; - m_rangeSet = true; - } - else - { - if( minV < m_minV ) - m_minV -= abs( maxV - minV ); + LIN_SCALE::ExtendDataRange( minV, maxV ); - if( maxV > m_maxV ) - m_maxV += abs( maxV - minV ); - } + // Time is never longer than the simulation itself + if( m_minV < m_startTime ) + m_minV = m_startTime; + + if( m_maxV > m_endTime ) + m_maxV = m_endTime; + }; + + void SetStartAndEnd( double aStartTime, double aEndTime ) + { + m_startTime = aStartTime; + m_endTime = aEndTime; + ResetDataRange(); } + + void ResetDataRange() override + { + m_minV = m_startTime; + m_maxV = m_endTime; + m_rangeSet = true; + } + +protected: + double m_startTime; + double m_endTime; }; @@ -975,8 +989,33 @@ void SIM_PLOT_TAB::EnableCursor( const wxString& aVectorName, int aType, int aCu void SIM_PLOT_TAB::ResetScales( bool aIncludeX ) { if( m_axis_x && aIncludeX ) + { m_axis_x->ResetDataRange(); + if( GetSimType() == ST_TRAN ) + { + wxStringTokenizer tokenizer( GetSimCommand(), wxS( " \t\n\r" ), wxTOKEN_STRTOK ); + wxString cmd = tokenizer.GetNextToken().Lower(); + + wxASSERT( cmd == wxS( ".tran" ) ); + + SPICE_VALUE step; + SPICE_VALUE end( 1.0 ); + SPICE_VALUE start( 0.0 ); + + if( tokenizer.HasMoreTokens() ) + step = SPICE_VALUE( tokenizer.GetNextToken() ); + + if( tokenizer.HasMoreTokens() ) + end = SPICE_VALUE( tokenizer.GetNextToken() ); + + if( tokenizer.HasMoreTokens() ) + start = SPICE_VALUE( tokenizer.GetNextToken() ); + + static_cast( m_axis_x )->SetStartAndEnd( start.ToDouble(), end.ToDouble() ); + } + } + if( m_axis_y1 ) m_axis_y1->ResetDataRange(); diff --git a/eeschema/sim/simulator_frame_ui.cpp b/eeschema/sim/simulator_frame_ui.cpp index aa26de4df8..3581ba12c3 100644 --- a/eeschema/sim/simulator_frame_ui.cpp +++ b/eeschema/sim/simulator_frame_ui.cpp @@ -2555,11 +2555,6 @@ void SIMULATOR_FRAME_UI::OnSimUpdate() void SIMULATOR_FRAME_UI::OnSimReport( const wxString& aMsg ) { - // Required in win32 to ensure wxTimer events get scheduled in between other events - // Or else we may stall them out entirely and never get them during actions like rapid - // console updates. - KIPLATFORM::APP::ForceTimerMessagesToBeCreatedIfNecessary(); - m_simConsole->AppendText( aMsg + "\n" ); m_simConsole->SetInsertionPointEnd(); } @@ -2728,6 +2723,10 @@ void SIMULATOR_FRAME_UI::OnSimRefresh( bool aFinal ) case SPT_POWER: value.Append( wxS( "W" ) ); break; + + default: + value.Append( wxS( "?" ) ); + break; } msg.Printf( wxT( "%s%s\n" ), diff --git a/include/widgets/mathplot.h b/include/widgets/mathplot.h index 639da71e07..34b580f8fb 100644 --- a/include/widgets/mathplot.h +++ b/include/widgets/mathplot.h @@ -664,7 +664,7 @@ public: } } - void ResetDataRange() + virtual void ResetDataRange() { m_rangeSet = false; }