From 24bccb00d62420891153b5ab266878c3702aaf91 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 11 Aug 2016 14:41:22 +0200 Subject: [PATCH] Menu event handlers for simulation plot frame --- eeschema/sim/sim_plot_frame.cpp | 33 +++++++++++++ eeschema/sim/sim_plot_frame.h | 15 +++++- eeschema/sim/sim_plot_frame_base.cpp | 72 +++++++++++++++++----------- eeschema/sim/sim_plot_frame_base.fbp | 46 +++++++++--------- eeschema/sim/sim_plot_frame_base.h | 16 +++++-- eeschema/sim/sim_plot_panel.cpp | 15 ++++++ eeschema/sim/sim_plot_panel.h | 4 ++ 7 files changed, 145 insertions(+), 56 deletions(-) diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index f2046ae0e6..3f54ecdf09 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -129,6 +129,7 @@ void SIM_PLOT_FRAME::StopSimulation() void SIM_PLOT_FRAME::NewPlotPanel() { SIM_PLOT_PANEL* plot = new SIM_PLOT_PANEL( this, wxID_ANY ); + m_plotNotebook->AddPage( plot, wxString::Format( wxT( "Plot%lu" ), m_plotNotebook->GetPageCount() + 1 ), true ); } @@ -183,6 +184,38 @@ int SIM_PLOT_FRAME::getNodeNumber( const wxString& aNetName ) } +void SIM_PLOT_FRAME::menuZoomIn( wxCommandEvent& event ) +{ + currentPlot()->ZoomIn(); +} + + +void SIM_PLOT_FRAME::menuZoomOut( wxCommandEvent& event ) +{ + currentPlot()->ZoomOut(); +} + + +void SIM_PLOT_FRAME::menuZoomFit( wxCommandEvent& event ) +{ + currentPlot()->Fit(); +} + + +void SIM_PLOT_FRAME::menuShowGrid( wxCommandEvent& event ) +{ + currentPlot()->ShowGrid( !currentPlot()->IsGridShown() ); +} + + +void SIM_PLOT_FRAME::menuShowGridState( wxUpdateUIEvent& event ) +{ + SIM_PLOT_PANEL* plotPanel = currentPlot(); + + event.Check( plotPanel ? plotPanel->IsGridShown() : false ); +} + + void SIM_PLOT_FRAME::onSignalDblClick( wxCommandEvent& event ) { int idx = m_signals->GetSelection(); diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index 65e8ce5009..b3c4197c43 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -80,11 +80,24 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE */ int getNodeNumber( const wxString& aNetName ); - void onNewPlot( wxCommandEvent& aEvent ) override + // Menu handlers + void menuNewPlot( wxCommandEvent& aEvent ) override { NewPlotPanel(); } + void menuExit( wxCommandEvent& event ) override + { + Close(); + } + + 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; + + // Event handlers void onSignalDblClick( wxCommandEvent& 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 6eb3b205e7..e6e8f2193c 100644 --- a/eeschema/sim/sim_plot_frame_base.cpp +++ b/eeschema/sim/sim_plot_frame_base.cpp @@ -13,52 +13,52 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - m_menubar1 = new wxMenuBar( 0 ); - m_menu1 = new wxMenu(); + m_mainMenu = new wxMenuBar( 0 ); + m_fileMenu = new wxMenu(); wxMenuItem* m_menuItem7; - m_menuItem7 = new wxMenuItem( m_menu1, wxID_ANY, wxString( _("New Plot") ) , wxEmptyString, wxITEM_NORMAL ); - m_menu1->Append( m_menuItem7 ); + m_menuItem7 = new wxMenuItem( m_fileMenu, wxID_NEW, wxString( _("New Plot") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_menuItem7 ); - m_menu1->AppendSeparator(); + m_fileMenu->AppendSeparator(); wxMenuItem* m_menuItem8; - m_menuItem8 = new wxMenuItem( m_menu1, wxID_ANY, wxString( _("Open Workbook") ) , wxEmptyString, wxITEM_NORMAL ); - m_menu1->Append( m_menuItem8 ); + m_menuItem8 = new wxMenuItem( m_fileMenu, wxID_OPEN, wxString( _("Open Workbook") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_menuItem8 ); wxMenuItem* m_menuItem2; - m_menuItem2 = new wxMenuItem( m_menu1, wxID_ANY, wxString( _("Save Workbook") ) , wxEmptyString, wxITEM_NORMAL ); - m_menu1->Append( m_menuItem2 ); + m_menuItem2 = new wxMenuItem( m_fileMenu, wxID_SAVE, wxString( _("Save Workbook") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_menuItem2 ); - m_menu1->AppendSeparator(); + m_fileMenu->AppendSeparator(); wxMenuItem* m_menuItem1; - m_menuItem1 = new wxMenuItem( m_menu1, wxID_ANY, wxString( _("Exit Simulation") ) , wxEmptyString, wxITEM_NORMAL ); - m_menu1->Append( m_menuItem1 ); + m_menuItem1 = new wxMenuItem( m_fileMenu, wxID_CLOSE, wxString( _("Exit Simulation") ) , wxEmptyString, wxITEM_NORMAL ); + m_fileMenu->Append( m_menuItem1 ); - m_menubar1->Append( m_menu1, _("File") ); + m_mainMenu->Append( m_fileMenu, _("File") ); - m_menu2 = new wxMenu(); + m_viewMenu = new wxMenu(); wxMenuItem* m_menuItem3; - m_menuItem3 = new wxMenuItem( m_menu2, wxID_ANY, wxString( _("Zoom In") ) , wxEmptyString, wxITEM_NORMAL ); - m_menu2->Append( m_menuItem3 ); + m_menuItem3 = new wxMenuItem( m_viewMenu, wxID_ZOOM_IN, wxString( _("Zoom In") ) , wxEmptyString, wxITEM_NORMAL ); + m_viewMenu->Append( m_menuItem3 ); wxMenuItem* m_menuItem4; - m_menuItem4 = new wxMenuItem( m_menu2, wxID_ANY, wxString( _("Zoom Out") ) , wxEmptyString, wxITEM_NORMAL ); - m_menu2->Append( m_menuItem4 ); + m_menuItem4 = new wxMenuItem( m_viewMenu, wxID_ZOOM_OUT, wxString( _("Zoom Out") ) , wxEmptyString, wxITEM_NORMAL ); + m_viewMenu->Append( m_menuItem4 ); wxMenuItem* m_menuItem5; - m_menuItem5 = new wxMenuItem( m_menu2, wxID_ANY, wxString( _("Fit on Screen") ) , wxEmptyString, wxITEM_NORMAL ); - m_menu2->Append( m_menuItem5 ); + m_menuItem5 = new wxMenuItem( m_viewMenu, wxID_ZOOM_FIT, wxString( _("Fit on Screen") ) , wxEmptyString, wxITEM_NORMAL ); + m_viewMenu->Append( m_menuItem5 ); - m_menu2->AppendSeparator(); + m_viewMenu->AppendSeparator(); - wxMenuItem* m_menuItem6; - m_menuItem6 = new wxMenuItem( m_menu2, wxID_ANY, wxString( _("Show grid") ) , wxEmptyString, wxITEM_CHECK ); - m_menu2->Append( m_menuItem6 ); + wxMenuItem* m_menuShowGrid; + m_menuShowGrid = new wxMenuItem( m_viewMenu, wxID_ANY, wxString( _("Show grid") ) , wxEmptyString, wxITEM_CHECK ); + m_viewMenu->Append( m_menuShowGrid ); - m_menubar1->Append( m_menu2, _("View") ); + m_mainMenu->Append( m_viewMenu, _("View") ); - this->SetMenuBar( m_menubar1 ); + this->SetMenuBar( m_mainMenu ); wxBoxSizer* bSizer1; bSizer1 = new wxBoxSizer( wxVERTICAL ); @@ -154,7 +154,15 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const this->Centre( wxBOTH ); // Connect Events - this->Connect( m_menuItem7->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onNewPlot ) ); + this->Connect( m_menuItem7->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuNewPlot ) ); + 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 ) ); m_signals->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), 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 ); @@ -164,7 +172,15 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE() { // Disconnect Events - this->Disconnect( wxID_ANY, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onNewPlot ) ); + this->Disconnect( wxID_NEW, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuNewPlot ) ); + this->Disconnect( wxID_OPEN, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuOpenWorkbook ) ); + this->Disconnect( wxID_SAVE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuSaveWorkbook ) ); + this->Disconnect( wxID_CLOSE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuExit ) ); + this->Disconnect( wxID_ZOOM_IN, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuZoomIn ) ); + 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 ) ); m_signals->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), 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 ); diff --git a/eeschema/sim/sim_plot_frame_base.fbp b/eeschema/sim/sim_plot_frame_base.fbp index 7679c9c661..100d9c50ca 100644 --- a/eeschema/sim/sim_plot_frame_base.fbp +++ b/eeschema/sim/sim_plot_frame_base.fbp @@ -88,7 +88,7 @@ - + 1 @@ -100,7 +100,7 @@ MyMenuBar - m_menubar1 + m_mainMenu protected @@ -133,23 +133,23 @@ - + File - m_menu1 + m_fileMenu protected 0 1 - wxID_ANY + wxID_NEW wxITEM_NORMAL New Plot m_menuItem7 none - onNewPlot + menuNewPlot @@ -161,14 +161,14 @@ 0 1 - wxID_ANY + wxID_OPEN wxITEM_NORMAL Open Workbook m_menuItem8 none - + menuOpenWorkbook @@ -176,14 +176,14 @@ 0 1 - wxID_ANY + wxID_SAVE wxITEM_NORMAL Save Workbook m_menuItem2 none - + menuSaveWorkbook @@ -195,34 +195,34 @@ 0 1 - wxID_ANY + wxID_CLOSE wxITEM_NORMAL Exit Simulation m_menuItem1 none - + menuExit - + View - m_menu2 + m_viewMenu protected 0 1 - wxID_ANY + wxID_ZOOM_IN wxITEM_NORMAL Zoom In m_menuItem3 none - + menuZoomIn @@ -230,14 +230,14 @@ 0 1 - wxID_ANY + wxID_ZOOM_OUT wxITEM_NORMAL Zoom Out m_menuItem4 none - + menuZoomOut @@ -245,14 +245,14 @@ 0 1 - wxID_ANY + wxID_ZOOM_FIT wxITEM_NORMAL Fit on Screen m_menuItem5 none - + menuZoomFit @@ -267,12 +267,12 @@ wxID_ANY wxITEM_CHECK Show grid - m_menuItem6 + m_menuShowGrid none - - + menuShowGrid + menuShowGridState diff --git a/eeschema/sim/sim_plot_frame_base.h b/eeschema/sim/sim_plot_frame_base.h index 514f9e4ddf..f6e5873060 100644 --- a/eeschema/sim/sim_plot_frame_base.h +++ b/eeschema/sim/sim_plot_frame_base.h @@ -43,9 +43,9 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER private: protected: - wxMenuBar* m_menubar1; - wxMenu* m_menu1; - wxMenu* m_menu2; + wxMenuBar* m_mainMenu; + wxMenu* m_fileMenu; + wxMenu* m_viewMenu; wxPanel* m_panel31; wxPanel* m_panel61; wxAuiNotebook* m_plotNotebook; @@ -61,7 +61,15 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER wxRichTextCtrl* m_simConsole; // Virtual event handlers, overide them in your derived class - virtual void onNewPlot( wxCommandEvent& event ) { event.Skip(); } + virtual void menuNewPlot( wxCommandEvent& event ) { event.Skip(); } + virtual void menuOpenWorkbook( wxCommandEvent& event ) { event.Skip(); } + virtual void menuSaveWorkbook( wxCommandEvent& event ) { event.Skip(); } + virtual void menuExit( wxCommandEvent& event ) { event.Skip(); } + virtual void menuZoomIn( wxCommandEvent& event ) { event.Skip(); } + 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 onSignalDblClick( wxCommandEvent& event ) { event.Skip(); } virtual void onSimulate( wxCommandEvent& event ) { event.Skip(); } virtual void onPlaceProbe( wxCommandEvent& event ) { event.Skip(); } diff --git a/eeschema/sim/sim_plot_panel.cpp b/eeschema/sim/sim_plot_panel.cpp index cd8ccaa3a6..0369e5800a 100644 --- a/eeschema/sim/sim_plot_panel.cpp +++ b/eeschema/sim/sim_plot_panel.cpp @@ -99,6 +99,21 @@ void SIM_PLOT_PANEL::DeleteTraces() } +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(); +} + + wxColour SIM_PLOT_PANEL::generateColor() { /// @todo have a look at: diff --git a/eeschema/sim/sim_plot_panel.h b/eeschema/sim/sim_plot_panel.h index c3f7a568f4..b484d8ef0e 100644 --- a/eeschema/sim/sim_plot_panel.h +++ b/eeschema/sim/sim_plot_panel.h @@ -65,6 +65,10 @@ public: return m_traces; } + void ShowGrid( bool aEnable = true ); + + bool IsGridShown() const; + private: wxColour generateColor();