diff --git a/eeschema/sim/sim_plot_tab.cpp b/eeschema/sim/sim_plot_tab.cpp index 156f764b82..94e6338c3c 100644 --- a/eeschema/sim/sim_plot_tab.cpp +++ b/eeschema/sim/sim_plot_tab.cpp @@ -978,36 +978,34 @@ bool SIM_PLOT_TAB::DeleteTrace( const wxString& aVectorName, int aTraceType ) } -void SIM_PLOT_TAB::EnableCursor( const wxString& aVectorName, int aType, int aCursorId, - bool aEnable, const wxString& aSignalName ) +void SIM_PLOT_TAB::EnableCursor( TRACE* aTrace, int aCursorId, const wxString& aSignalName ) { - TRACE* t = GetTrace( aVectorName, aType ); + CURSOR* cursor = new CURSOR( aTrace, this ); + mpWindow* win = GetPlotWin(); + int width = win->GetXScreen() - win->GetMarginLeft() - win->GetMarginRight(); + int center = win->GetMarginLeft() + KiROUND( width * ( aCursorId == 1 ? 0.4 : 0.6 ) ); - if( t == nullptr || t->HasCursor( aCursorId ) == aEnable ) - return; + cursor->SetName( aSignalName ); + cursor->SetX( center ); - if( aEnable ) - { - CURSOR* cursor = new CURSOR( t, this ); - mpWindow* win = GetPlotWin(); - int width = win->GetXScreen() - win->GetMarginLeft() - win->GetMarginRight(); - int center = win->GetMarginLeft() + KiROUND( width * ( aCursorId == 1 ? 0.4 : 0.6 ) ); + aTrace->SetCursor( aCursorId, cursor ); + m_plotWin->AddLayer( cursor ); - cursor->SetName( aSignalName ); - cursor->SetX( center ); + // Notify the parent window about the changes + wxQueueEvent( this, new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) ); +} - t->SetCursor( aCursorId, cursor ); - m_plotWin->AddLayer( cursor ); - } - else + +void SIM_PLOT_TAB::DisableCursor( TRACE* aTrace, int aCursorId ) +{ + if( CURSOR* cursor = aTrace->GetCursor( aCursorId ) ) { - CURSOR* cursor = t->GetCursor( aCursorId ); - t->SetCursor( aCursorId, nullptr ); - m_plotWin->DelLayer( cursor, true ); - } + aTrace->SetCursor( aCursorId, nullptr ); + GetPlotWin()->DelLayer( cursor, true ); - // Notify the parent window about the changes - wxQueueEvent( GetParent(), new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) ); + // Notify the parent window about the changes + wxQueueEvent( this, new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) ); + } } diff --git a/eeschema/sim/sim_plot_tab.h b/eeschema/sim/sim_plot_tab.h index 6dba50b8db..e45b5b3b1f 100644 --- a/eeschema/sim/sim_plot_tab.h +++ b/eeschema/sim/sim_plot_tab.h @@ -331,9 +331,9 @@ public: return m_dotted_cp; } - ///< Toggle cursor for a particular trace. - void EnableCursor( const wxString& aVectorName, int aType, int aCursorId, bool aEnable, - const wxString& aSignalName ); + ///< Turn on/off the cursor for a particular trace. + void EnableCursor( TRACE* aTrace, int aCursorId, const wxString& aSignalName ); + void DisableCursor( TRACE* aTrace, int aCursorId ); ///< Reset scale ranges to fit the current traces. void ResetScales( bool aIncludeX ); diff --git a/eeschema/sim/simulator_frame_ui.cpp b/eeschema/sim/simulator_frame_ui.cpp index d93b7da662..d05b6cfad1 100644 --- a/eeschema/sim/simulator_frame_ui.cpp +++ b/eeschema/sim/simulator_frame_ui.cpp @@ -1141,18 +1141,29 @@ void SIMULATOR_FRAME_UI::onSignalsGridCellChanged( wxGridEvent& aEvent ) } else if( col == COL_CURSOR_1 || col == COL_CURSOR_2 ) { - for( int ii = 0; ii < m_signalsGrid->GetNumberRows(); ++ii ) + int id = col == COL_CURSOR_1 ? 1 : 2; + TRACE* activeTrace = nullptr; + + if( text == wxS( "1" ) ) { - signalName = m_signalsGrid->GetCellValue( ii, COL_SIGNAL_NAME ); + signalName = m_signalsGrid->GetCellValue( row, COL_SIGNAL_NAME ); vectorName = vectorNameFromSignalName( plotTab, signalName, &traceType ); - int id = col == COL_CURSOR_1 ? 1 : 2; - bool enable = ii == row && text == wxS( "1" ); - - plotTab->EnableCursor( vectorName, traceType, id, enable, signalName ); + activeTrace = plotTab->GetTrace( vectorName, traceType ); + plotTab->EnableCursor( activeTrace, id, signalName ); OnModify(); } + // Turn off cursor on other signals. + for( const auto& [name, trace] : plotTab->GetTraces() ) + { + if( trace != activeTrace && trace->HasCursor( id ) ) + { + plotTab->DisableCursor( trace, id ); + OnModify(); + } + } + // Update cursor checkboxes (which are really radio buttons) updateSignalsGrid(); }