From 8c138312fb658d559d669ea8652eddb5d7525934 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 11 Aug 2016 14:41:27 +0200 Subject: [PATCH] Cursors are updated on request instead of using update UI events Previously CPU was busy updating the list of cursors even though nothing was changing. --- eeschema/sim/sim_plot_frame.cpp | 54 +++++++++++++++++++-------------- eeschema/sim/sim_plot_frame.h | 4 ++- eeschema/sim/sim_plot_panel.cpp | 8 +++++ eeschema/sim/sim_plot_panel.h | 2 ++ 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index e67d591353..bf1df67e2a 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -86,6 +86,7 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) Connect( EVT_SIM_REPORT, wxCommandEventHandler( SIM_PLOT_FRAME::onSimReport ), NULL, this ); Connect( EVT_SIM_STARTED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimStarted ), NULL, this ); Connect( EVT_SIM_FINISHED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimFinished ), NULL, this ); + Connect( EVT_SIM_CURSOR_UPDATE, wxCommandEventHandler( SIM_PLOT_FRAME::onCursorUpdate ), NULL, this ); NewPlotPanel(); } @@ -216,6 +217,12 @@ void SIM_PLOT_FRAME::menuShowGridState( wxUpdateUIEvent& event ) } +void SIM_PLOT_FRAME::onPlotChanged( wxNotebookEvent& event ) +{ + wxQueueEvent( this, new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) ); +} + + void SIM_PLOT_FRAME::onSignalDblClick( wxCommandEvent& event ) { int idx = m_signals->GetSelection(); @@ -253,29 +260,6 @@ void SIM_PLOT_FRAME::onSignalRClick( wxMouseEvent& event ) } -void SIM_PLOT_FRAME::onCursorsUpdate( wxUpdateUIEvent& event ) -{ - wxSize size = m_cursors->GetClientSize(); - m_cursors->ClearAll(); - - const long SIGNAL_COL = m_cursors->AppendColumn( wxT( "Signal" ), wxLIST_FORMAT_LEFT, size.x / 2 ); - const long X_COL = m_cursors->AppendColumn( CurrentPlot()->GetLabelX(), wxLIST_FORMAT_LEFT, size.x / 4 ); - const long Y_COL = m_cursors->AppendColumn( CurrentPlot()->GetLabelY(), wxLIST_FORMAT_LEFT, size.x / 4 ); - - // Update cursor values - for( const auto& trace : CurrentPlot()->GetTraces() ) - { - if( CURSOR* cursor = trace.second->GetCursor() ) - { - const wxRealPoint coords = cursor->GetCoords(); - long idx = m_cursors->InsertItem( SIGNAL_COL, trace.first ); - m_cursors->SetItem( idx, X_COL, wxString::Format( "%f", coords.x ) ); - m_cursors->SetItem( idx, Y_COL, wxString::Format( "%f", coords.y ) ); - } - } -} - - void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event ) { if( isSimulationRunning() ) @@ -304,6 +288,29 @@ void SIM_PLOT_FRAME::onClose( wxCloseEvent& aEvent ) } +void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event ) +{ + wxSize size = m_cursors->GetClientSize(); + m_cursors->ClearAll(); + + const long SIGNAL_COL = m_cursors->AppendColumn( wxT( "Signal" ), wxLIST_FORMAT_LEFT, size.x / 2 ); + const long X_COL = m_cursors->AppendColumn( CurrentPlot()->GetLabelX(), wxLIST_FORMAT_LEFT, size.x / 4 ); + const long Y_COL = m_cursors->AppendColumn( CurrentPlot()->GetLabelY(), wxLIST_FORMAT_LEFT, size.x / 4 ); + + // Update cursor values + for( const auto& trace : CurrentPlot()->GetTraces() ) + { + if( CURSOR* cursor = trace.second->GetCursor() ) + { + const wxRealPoint coords = cursor->GetCoords(); + long idx = m_cursors->InsertItem( SIGNAL_COL, trace.first ); + m_cursors->SetItem( idx, X_COL, wxString::Format( "%f", coords.x ) ); + m_cursors->SetItem( idx, Y_COL, wxString::Format( "%f", coords.y ) ); + } + } +} + + void SIM_PLOT_FRAME::onSimStarted( wxCommandEvent& aEvent ) { m_simulateBtn->SetLabel( wxT( "Stop" ) ); @@ -377,6 +384,7 @@ void SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent ) { case SHOW_SIGNAL: m_plotFrame->AddVoltagePlot( m_signal ); + plot->Fit(); break; break; diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index d934e930c4..6fe74d97b5 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -98,15 +98,17 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE void menuShowGridState( wxUpdateUIEvent& event ) override; // Event handlers + void onPlotChanged( wxNotebookEvent& event ) override; + void onSignalDblClick( wxCommandEvent& event ) override; void onSignalRClick( wxMouseEvent& event ) override; - void onCursorsUpdate( wxUpdateUIEvent& event ) override; void onSimulate( wxCommandEvent& event ) override; void onPlaceProbe( wxCommandEvent& event ) override; void onClose( wxCloseEvent& aEvent ); + void onCursorUpdate( wxCommandEvent& aEvent ); void onSimStarted( wxCommandEvent& aEvent ); void onSimFinished( wxCommandEvent& aEvent ); void onSimReport( wxCommandEvent& aEvent ); diff --git a/eeschema/sim/sim_plot_panel.cpp b/eeschema/sim/sim_plot_panel.cpp index c960615965..b433924a20 100644 --- a/eeschema/sim/sim_plot_panel.cpp +++ b/eeschema/sim/sim_plot_panel.cpp @@ -73,6 +73,9 @@ void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow ) m_coords.y = leftY + ( rightY - leftY ) / ( rightX - leftX ) * ( m_coords.x - leftX ); m_updateRequired = false; + + // Notify the parent window about the changes + wxQueueEvent( aWindow.GetParent(), new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) ); } else { @@ -228,6 +231,9 @@ void SIM_PLOT_PANEL::EnableCursor( const wxString& aName, bool aEnable ) t->SetCursor( NULL ); DelLayer( c, true ); } + + // Notify the parent window about the changes + wxQueueEvent( GetParent(), new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) ); } @@ -252,3 +258,5 @@ wxColour SIM_PLOT_PANEL::generateColor() /// @todo generate shades to avoid repeating colors return wxColour( colors[m_colorIdx++ % colorCount] ); } + +wxDEFINE_EVENT( EVT_SIM_CURSOR_UPDATE, wxCommandEvent ); diff --git a/eeschema/sim/sim_plot_panel.h b/eeschema/sim/sim_plot_panel.h index e7b0db256b..07ea3c2f67 100644 --- a/eeschema/sim/sim_plot_panel.h +++ b/eeschema/sim/sim_plot_panel.h @@ -204,4 +204,6 @@ private: //mpInfoCoords* m_coords; }; +wxDECLARE_EVENT( EVT_SIM_CURSOR_UPDATE, wxCommandEvent ); + #endif