From 433f934dc1143c774e26bb0b20a2f3ea721ab121 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 11 Aug 2016 14:41:26 +0200 Subject: [PATCH] Simulation frame displays a list of cursors and their values --- eeschema/sim/sim_plot_frame.cpp | 34 ++++- eeschema/sim/sim_plot_frame.h | 2 + eeschema/sim/sim_plot_frame_base.cpp | 12 +- eeschema/sim/sim_plot_frame_base.fbp | 208 +++++++++++++++++++++++++-- eeschema/sim/sim_plot_frame_base.h | 4 + eeschema/sim/sim_plot_panel.h | 10 ++ 6 files changed, 252 insertions(+), 18 deletions(-) diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 202804f3f1..0641522d2c 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -253,6 +253,29 @@ 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() ) @@ -303,15 +326,12 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent ) } // If there are any signals plotted, update them - for( unsigned int i = 0; i < m_plotNotebook->GetPageCount(); ++i ) - { - SIM_PLOT_PANEL* plotPanel = static_cast( m_plotNotebook->GetPage( i ) ); + SIM_PLOT_PANEL* plotPanel = CurrentPlot(); - for( const auto& trace : plotPanel->GetTraces() ) - updatePlot( trace.second->GetSpiceName(), trace.second->GetName(), plotPanel ); + for( const auto& trace : plotPanel->GetTraces() ) + updatePlot( trace.second->GetSpiceName(), trace.second->GetName(), plotPanel ); - plotPanel->UpdateAll(); - } + plotPanel->UpdateAll(); } diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index cc27d69cd7..d367172bde 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -100,6 +100,8 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE // Event handlers 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; diff --git a/eeschema/sim/sim_plot_frame_base.cpp b/eeschema/sim/sim_plot_frame_base.cpp index 2af6beee43..81440c668e 100644 --- a/eeschema/sim/sim_plot_frame_base.cpp +++ b/eeschema/sim/sim_plot_frame_base.cpp @@ -69,6 +69,7 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_panel61 = new wxPanel( m_panel31, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_panel61->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ) ); + m_panel61->SetMinSize( wxSize( 300,-1 ) ); wxBoxSizer* bSizer6; bSizer6 = new wxBoxSizer( wxVERTICAL ); @@ -96,6 +97,13 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_signals = new wxListBox( m_panel7, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE|wxLB_SORT ); bSizer7->Add( m_signals, 1, wxALL|wxEXPAND, 5 ); + m_staticText21 = new wxStaticText( m_panel7, wxID_ANY, _("Cursors"), wxDefaultPosition, wxDefaultSize, 0 ); + m_staticText21->Wrap( -1 ); + bSizer7->Add( m_staticText21, 0, wxALL, 5 ); + + m_cursors = new wxListCtrl( m_panel7, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_HRULES|wxLC_REPORT|wxLC_SINGLE_SEL ); + bSizer7->Add( m_cursors, 1, wxALL|wxEXPAND, 5 ); + wxFlexGridSizer* fgSizer1; fgSizer1 = new wxFlexGridSizer( 1, 0, 0, 0 ); fgSizer1->SetFlexibleDirection( wxBOTH ); @@ -117,7 +125,7 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_panel7->SetSizer( bSizer7 ); m_panel7->Layout(); bSizer7->Fit( m_panel7 ); - bSizer5->Add( m_panel7, 1, wxEXPAND | wxALL, 5 ); + bSizer5->Add( m_panel7, 0, wxALL|wxEXPAND, 5 ); m_panel31->SetSizer( bSizer5 ); @@ -158,6 +166,7 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const this->Connect( m_menuShowGrid->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridState ) ); m_signals->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), NULL, this ); m_signals->Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( SIM_PLOT_FRAME_BASE::onSignalRClick ), NULL, this ); + m_cursors->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::onCursorsUpdate ), NULL, this ); m_simulateBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSimulate ), NULL, this ); m_probeBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onPlaceProbe ), NULL, this ); m_tuneBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onTune ), NULL, this ); @@ -177,6 +186,7 @@ SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE() this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridState ) ); m_signals->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), NULL, this ); m_signals->Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( SIM_PLOT_FRAME_BASE::onSignalRClick ), NULL, this ); + m_cursors->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::onCursorsUpdate ), NULL, this ); m_simulateBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSimulate ), NULL, this ); m_probeBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onPlaceProbe ), NULL, this ); m_tuneBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onTune ), NULL, this ); diff --git a/eeschema/sim/sim_plot_frame_base.fbp b/eeschema/sim/sim_plot_frame_base.fbp index 6113f943d7..5d610b7804 100644 --- a/eeschema/sim/sim_plot_frame_base.fbp +++ b/eeschema/sim/sim_plot_frame_base.fbp @@ -281,11 +281,11 @@ bSizer1 wxVERTICAL none - + 5 wxEXPAND | wxALL 3 - + 1 1 1 @@ -359,7 +359,7 @@ - + bSizer5 wxHORIZONTAL @@ -401,7 +401,7 @@ 0 - + 300,-1 1 m_panel61 1 @@ -542,11 +542,11 @@ - + 5 - wxEXPAND | wxALL - 1 - + wxALL|wxEXPAND + 0 + 1 1 1 @@ -620,7 +620,7 @@ - + bSizer7 wxVERTICAL @@ -796,6 +796,194 @@ + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Cursors + + 0 + + + 0 + + 1 + m_staticText21 + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + -1 + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxALL|wxEXPAND + 1 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_cursors + 1 + + + protected + 1 + + Resizable + 1 + + wxLC_HRULES|wxLC_REPORT|wxLC_SINGLE_SEL + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + onCursorsUpdate + + 5 wxALL|wxEXPAND @@ -1084,7 +1272,7 @@ - + 5 wxEXPAND | wxALL 1 diff --git a/eeschema/sim/sim_plot_frame_base.h b/eeschema/sim/sim_plot_frame_base.h index 34d9556b10..99ccc930bb 100644 --- a/eeschema/sim/sim_plot_frame_base.h +++ b/eeschema/sim/sim_plot_frame_base.h @@ -28,6 +28,7 @@ class KIWAY_PLAYER; #include #include #include +#include #include #include #include @@ -52,6 +53,8 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER wxPanel* m_panel7; wxStaticText* m_staticText2; wxListBox* m_signals; + wxStaticText* m_staticText21; + wxListCtrl* m_cursors; wxButton* m_simulateBtn; wxButton* m_probeBtn; wxButton* m_tuneBtn; @@ -70,6 +73,7 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER virtual void menuShowGridState( wxUpdateUIEvent& event ) { event.Skip(); } virtual void onSignalDblClick( wxCommandEvent& event ) { event.Skip(); } virtual void onSignalRClick( wxMouseEvent& event ) { event.Skip(); } + virtual void onCursorsUpdate( wxUpdateUIEvent& event ) { event.Skip(); } virtual void onSimulate( wxCommandEvent& event ) { event.Skip(); } virtual void onPlaceProbe( wxCommandEvent& event ) { event.Skip(); } virtual void onTune( wxCommandEvent& event ) { event.Skip(); } diff --git a/eeschema/sim/sim_plot_panel.h b/eeschema/sim/sim_plot_panel.h index 202a9fb5f2..e7b0db256b 100644 --- a/eeschema/sim/sim_plot_panel.h +++ b/eeschema/sim/sim_plot_panel.h @@ -148,6 +148,16 @@ public: ~SIM_PLOT_PANEL(); + const wxString& GetLabelX() const + { + return m_axis_x->GetName(); + } + + const wxString& GetLabelY() const + { + return m_axis_y->GetName(); + } + bool AddTrace( const wxString& aSpiceName, const wxString& aName, int aPoints, const double* aT, const double* aY, int aFlags );