From 1d4fe279db23a9a263728c80435177d96d865238 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 11 Aug 2016 14:41:27 +0200 Subject: [PATCH] Menu entries to toggle legend & coordinates --- eeschema/sim/sim_plot_frame.cpp | 36 ++++++++++++++++-- eeschema/sim/sim_plot_frame.h | 8 +++- eeschema/sim/sim_plot_frame_base.cpp | 56 ++++++++++++++++++---------- eeschema/sim/sim_plot_frame_base.fbp | 46 +++++++++++++++++++---- eeschema/sim/sim_plot_frame_base.h | 6 ++- eeschema/sim/sim_plot_panel.cpp | 35 +++++++---------- eeschema/sim/sim_plot_panel.h | 39 +++++++++++++++++-- 7 files changed, 167 insertions(+), 59 deletions(-) diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index bf1df67e2a..e73fce831b 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -205,15 +205,43 @@ void SIM_PLOT_FRAME::menuZoomFit( wxCommandEvent& event ) void SIM_PLOT_FRAME::menuShowGrid( wxCommandEvent& event ) { - CurrentPlot()->ShowGrid( !CurrentPlot()->IsGridShown() ); + SIM_PLOT_PANEL* plot = CurrentPlot(); + plot->ShowGrid( !plot->IsGridShown() ); } -void SIM_PLOT_FRAME::menuShowGridState( wxUpdateUIEvent& event ) +void SIM_PLOT_FRAME::menuShowGridUpdate( wxUpdateUIEvent& event ) { - SIM_PLOT_PANEL* plotPanel = CurrentPlot(); + SIM_PLOT_PANEL* plot = CurrentPlot(); + event.Check( plot ? plot->IsGridShown() : false ); +} - event.Check( plotPanel ? plotPanel->IsGridShown() : false ); + +void SIM_PLOT_FRAME::menuShowLegend( wxCommandEvent& event ) +{ + SIM_PLOT_PANEL* plot = CurrentPlot(); + plot->ShowLegend( !plot->IsLegendShown() ); +} + + +void SIM_PLOT_FRAME::menuShowLegendUpdate( wxUpdateUIEvent& event ) +{ + SIM_PLOT_PANEL* plot = CurrentPlot(); + event.Check( plot ? plot->IsLegendShown() : false ); +} + + +void SIM_PLOT_FRAME::menuShowCoords( wxCommandEvent& event ) +{ + SIM_PLOT_PANEL* plot = CurrentPlot(); + plot->ShowCoords( !plot->IsCoordsShown() ); +} + + +void SIM_PLOT_FRAME::menuShowCoordsUpdate( wxUpdateUIEvent& event ) +{ + SIM_PLOT_PANEL* plot = CurrentPlot(); + event.Check( plot ? plot->IsCoordsShown() : false ); } diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index 6fe74d97b5..be3a664256 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -91,13 +91,17 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE Close(); } + // Event handlers void menuZoomIn( wxCommandEvent& event ) override; void menuZoomOut( wxCommandEvent& event ) override; void menuZoomFit( wxCommandEvent& event ) override; void menuShowGrid( wxCommandEvent& event ) override; - void menuShowGridState( wxUpdateUIEvent& event ) override; + void menuShowGridUpdate( wxUpdateUIEvent& event ) override; + void menuShowLegend( wxCommandEvent& event ) override; + void menuShowLegendUpdate( wxUpdateUIEvent& event ) override; + void menuShowCoords( wxCommandEvent& event ) override; + void menuShowCoordsUpdate( wxUpdateUIEvent& event ) override; - // Event handlers void onPlotChanged( wxNotebookEvent& event ) override; void onSignalDblClick( wxCommandEvent& event ) override; diff --git a/eeschema/sim/sim_plot_frame_base.cpp b/eeschema/sim/sim_plot_frame_base.cpp index d6f1aa2f28..a13990e4b1 100644 --- a/eeschema/sim/sim_plot_frame_base.cpp +++ b/eeschema/sim/sim_plot_frame_base.cpp @@ -38,23 +38,31 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_mainMenu->Append( m_fileMenu, _("File") ); m_viewMenu = new wxMenu(); - wxMenuItem* m_menuItem3; - m_menuItem3 = new wxMenuItem( m_viewMenu, wxID_ZOOM_IN, wxString( _("Zoom In") ) , wxEmptyString, wxITEM_NORMAL ); - m_viewMenu->Append( m_menuItem3 ); + wxMenuItem* m_zoomIn; + m_zoomIn = new wxMenuItem( m_viewMenu, wxID_ZOOM_IN, wxString( _("Zoom In") ) , wxEmptyString, wxITEM_NORMAL ); + m_viewMenu->Append( m_zoomIn ); - wxMenuItem* m_menuItem4; - m_menuItem4 = new wxMenuItem( m_viewMenu, wxID_ZOOM_OUT, wxString( _("Zoom Out") ) , wxEmptyString, wxITEM_NORMAL ); - m_viewMenu->Append( m_menuItem4 ); + wxMenuItem* m_zoomOut; + m_zoomOut = new wxMenuItem( m_viewMenu, wxID_ZOOM_OUT, wxString( _("Zoom Out") ) , wxEmptyString, wxITEM_NORMAL ); + m_viewMenu->Append( m_zoomOut ); - wxMenuItem* m_menuItem5; - m_menuItem5 = new wxMenuItem( m_viewMenu, wxID_ZOOM_FIT, wxString( _("Fit on Screen") ) , wxEmptyString, wxITEM_NORMAL ); - m_viewMenu->Append( m_menuItem5 ); + wxMenuItem* m_zoomFit; + m_zoomFit = new wxMenuItem( m_viewMenu, wxID_ZOOM_FIT, wxString( _("Fit on Screen") ) , wxEmptyString, wxITEM_NORMAL ); + m_viewMenu->Append( m_zoomFit ); m_viewMenu->AppendSeparator(); - wxMenuItem* m_menuShowGrid; - m_menuShowGrid = new wxMenuItem( m_viewMenu, wxID_ANY, wxString( _("Show grid") ) , wxEmptyString, wxITEM_CHECK ); - m_viewMenu->Append( m_menuShowGrid ); + wxMenuItem* m_showGrid; + m_showGrid = new wxMenuItem( m_viewMenu, wxID_ANY, wxString( _("Show &grid") ) , wxEmptyString, wxITEM_CHECK ); + m_viewMenu->Append( m_showGrid ); + + wxMenuItem* m_showLegend; + m_showLegend = new wxMenuItem( m_viewMenu, wxID_ANY, wxString( _("Show &legend") ) , wxEmptyString, wxITEM_CHECK ); + m_viewMenu->Append( m_showLegend ); + + wxMenuItem* m_showCoords; + m_showCoords = new wxMenuItem( m_viewMenu, wxID_ANY, wxString( _("Show &coordinates") ) , wxEmptyString, wxITEM_CHECK ); + m_viewMenu->Append( m_showCoords ); m_mainMenu->Append( m_viewMenu, _("View") ); @@ -67,8 +75,10 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const bSizer5 = new wxBoxSizer( wxHORIZONTAL ); m_plotNotebook = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + m_plotNotebook->SetMinSize( wxSize( 400,-1 ) ); - bSizer5->Add( m_plotNotebook, 4, wxEXPAND | wxALL, 5 ); + + bSizer5->Add( m_plotNotebook, 6, wxEXPAND | wxALL, 5 ); wxBoxSizer* bSizer7; bSizer7 = new wxBoxSizer( wxVERTICAL ); @@ -126,11 +136,15 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const this->Connect( m_menuItem8->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuOpenWorkbook ) ); this->Connect( m_menuItem2->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveWorkbook ) ); this->Connect( m_menuItem1->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuExit ) ); - this->Connect( m_menuItem3->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomIn ) ); - this->Connect( m_menuItem4->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomOut ) ); - this->Connect( m_menuItem5->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomFit ) ); - this->Connect( m_menuShowGrid->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowGrid ) ); - this->Connect( m_menuShowGrid->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridState ) ); + this->Connect( m_zoomIn->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomIn ) ); + this->Connect( m_zoomOut->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomOut ) ); + this->Connect( m_zoomFit->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomFit ) ); + this->Connect( m_showGrid->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowGrid ) ); + this->Connect( m_showGrid->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridUpdate ) ); + this->Connect( m_showLegend->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegend ) ); + this->Connect( m_showLegend->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegendUpdate ) ); + this->Connect( m_showCoords->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowCoords ) ); + this->Connect( m_showCoords->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowCoordsUpdate ) ); m_plotNotebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this ); 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 ); @@ -150,7 +164,11 @@ SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE() this->Disconnect( wxID_ZOOM_OUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomOut ) ); this->Disconnect( wxID_ZOOM_FIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomFit ) ); this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowGrid ) ); - this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridState ) ); + this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowGridUpdate ) ); + this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegend ) ); + this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegendUpdate ) ); + this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuShowCoords ) ); + this->Disconnect( wxID_ANY, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowCoordsUpdate ) ); m_plotNotebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this ); 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 ); diff --git a/eeschema/sim/sim_plot_frame_base.fbp b/eeschema/sim/sim_plot_frame_base.fbp index 384d95aa24..9c941424c4 100644 --- a/eeschema/sim/sim_plot_frame_base.fbp +++ b/eeschema/sim/sim_plot_frame_base.fbp @@ -218,7 +218,7 @@ wxID_ZOOM_IN wxITEM_NORMAL Zoom In - m_menuItem3 + m_zoomIn none @@ -233,7 +233,7 @@ wxID_ZOOM_OUT wxITEM_NORMAL Zoom Out - m_menuItem4 + m_zoomOut none @@ -248,7 +248,7 @@ wxID_ZOOM_FIT wxITEM_NORMAL Fit on Screen - m_menuItem5 + m_zoomFit none @@ -266,13 +266,43 @@ wxID_ANY wxITEM_CHECK - Show grid - m_menuShowGrid + Show &grid + m_showGrid none menuShowGrid - menuShowGridState + menuShowGridUpdate + + + + 0 + 1 + + wxID_ANY + wxITEM_CHECK + Show &legend + m_showLegend + none + + + menuShowLegend + menuShowLegendUpdate + + + + 0 + 1 + + wxID_ANY + wxITEM_CHECK + Show &coordinates + m_showCoords + none + + + menuShowCoords + menuShowCoordsUpdate @@ -293,7 +323,7 @@ 5 wxEXPAND | wxALL - 4 + 6 1 1 @@ -328,7 +358,7 @@ 0 - + 400,-1 1 m_plotNotebook 1 diff --git a/eeschema/sim/sim_plot_frame_base.h b/eeschema/sim/sim_plot_frame_base.h index 03dc4dd9b6..2aba38d4e9 100644 --- a/eeschema/sim/sim_plot_frame_base.h +++ b/eeschema/sim/sim_plot_frame_base.h @@ -65,7 +65,11 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER virtual void menuZoomOut( wxCommandEvent& event ) { event.Skip(); } virtual void menuZoomFit( wxCommandEvent& event ) { event.Skip(); } virtual void menuShowGrid( wxCommandEvent& event ) { event.Skip(); } - virtual void menuShowGridState( wxUpdateUIEvent& event ) { event.Skip(); } + virtual void menuShowGridUpdate( wxUpdateUIEvent& event ) { event.Skip(); } + virtual void menuShowLegend( wxCommandEvent& event ) { event.Skip(); } + virtual void menuShowLegendUpdate( wxUpdateUIEvent& event ) { event.Skip(); } + virtual void menuShowCoords( wxCommandEvent& event ) { event.Skip(); } + virtual void menuShowCoordsUpdate( wxUpdateUIEvent& event ) { event.Skip(); } virtual void onPlotChanged( wxNotebookEvent& event ) { event.Skip(); } virtual void onSignalDblClick( wxCommandEvent& event ) { event.Skip(); } virtual void onSignalRClick( wxMouseEvent& event ) { event.Skip(); } diff --git a/eeschema/sim/sim_plot_panel.cpp b/eeschema/sim/sim_plot_panel.cpp index b433924a20..428da31ccd 100644 --- a/eeschema/sim/sim_plot_panel.cpp +++ b/eeschema/sim/sim_plot_panel.cpp @@ -110,11 +110,13 @@ SIM_PLOT_PANEL::SIM_PLOT_PANEL( wxWindow* parent, wxWindowID id, const wxPoint& m_axis_y->SetTicks( false ); AddLayer( m_axis_y ); - m_legend = new mpInfoLegend( wxRect( 0, 0, 40, 40 ), wxWHITE_BRUSH ); - AddLayer( m_legend ); + m_coords = new mpInfoCoords( wxRect( 0, 0, 100, 40 ), wxWHITE_BRUSH ); + AddLayer( m_coords ); + m_topLevel.push_back( m_coords ); - //m_coords = new mpInfoCoords( wxRect( 80, 20, 10, 10 ), wxWHITE_BRUSH ); - //AddLayer( m_coords ); + m_legend = new mpInfoLegend( wxRect( 0, 40, 40, 40 ), wxWHITE_BRUSH ); + AddLayer( m_legend ); + m_topLevel.push_back( m_legend ); } @@ -140,10 +142,14 @@ bool SIM_PLOT_PANEL::AddTrace( const wxString& aSpiceName, const wxString& aName t->SetPen( wxPen( generateColor(), 1, wxSOLID ) ); m_traces[aName] = t; - // It is a trick to keep legend always on the top - DelLayer( m_legend ); + // It is a trick to keep legend & coords always on the top + for( mpLayer* l : m_topLevel ) + DelLayer( l ); + AddLayer( t ); - AddLayer( m_legend ); + + for( mpLayer* l : m_topLevel ) + AddLayer( l ); } else { @@ -189,21 +195,6 @@ void SIM_PLOT_PANEL::DeleteAllTraces() } -void SIM_PLOT_PANEL::ShowGrid( bool aEnable ) -{ - m_axis_x->SetTicks( !aEnable ); - m_axis_y->SetTicks( !aEnable ); - UpdateAll(); -} - - -bool SIM_PLOT_PANEL::IsGridShown() const -{ - assert( m_axis_x->GetTicks() == m_axis_y->GetTicks() ); - return !m_axis_x->GetTicks(); -} - - bool SIM_PLOT_PANEL::HasCursorEnabled( const wxString& aName ) const { TRACE* t = GetTrace( aName ); diff --git a/eeschema/sim/sim_plot_panel.h b/eeschema/sim/sim_plot_panel.h index 07ea3c2f67..9ba09a32c4 100644 --- a/eeschema/sim/sim_plot_panel.h +++ b/eeschema/sim/sim_plot_panel.h @@ -182,9 +182,40 @@ public: return trace == m_traces.end() ? NULL : trace->second; } - void ShowGrid( bool aEnable = true ); + void ShowGrid( bool aEnable ) + { + m_axis_x->SetTicks( !aEnable ); + m_axis_y->SetTicks( !aEnable ); + UpdateAll(); + } - bool IsGridShown() const; + bool IsGridShown() const + { + assert( m_axis_x->GetTicks() == m_axis_y->GetTicks() ); + return !m_axis_x->GetTicks(); + } + + void ShowLegend( bool aEnable ) + { + m_legend->SetVisible( aEnable ); + UpdateAll(); + } + + bool IsLegendShown() const + { + return m_legend->IsVisible(); + } + + void ShowCoords( bool aEnable ) + { + m_coords->SetVisible( aEnable ); + UpdateAll(); + } + + bool IsCoordsShown() const + { + return m_coords->IsVisible(); + } bool HasCursorEnabled( const wxString& aName ) const; @@ -201,7 +232,9 @@ private: mpScaleX* m_axis_x; mpScaleY* m_axis_y; mpInfoLegend* m_legend; - //mpInfoCoords* m_coords; + mpInfoCoords* m_coords; + + std::vector m_topLevel; }; wxDECLARE_EVENT( EVT_SIM_CURSOR_UPDATE, wxCommandEvent );