From 2f8f92cf0a681ec1ad5d7cf1b224bca771935635 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 11 Aug 2016 14:42:07 +0200 Subject: [PATCH] Closing tabs with middle button click I could not find a way to make tab close button work in wxWidgets.. --- eeschema/sim/sim_plot_frame.cpp | 66 ++++++++++++++++++++-------- eeschema/sim/sim_plot_frame.h | 11 ++++- eeschema/sim/sim_plot_frame_base.cpp | 12 ++--- eeschema/sim/sim_plot_frame_base.fbp | 56 +++++++++++++---------- eeschema/sim/sim_plot_frame_base.h | 7 +-- 5 files changed, 100 insertions(+), 52 deletions(-) diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index e6bd931005..72c50f42b8 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -134,8 +134,6 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) m_toolBar->Realize(); m_plotNotebook->SetPageText(0, _("Welcome!") ); - - //relayout(); } @@ -171,12 +169,6 @@ void SIM_PLOT_FRAME::StartSimulation() m_simulator->LoadNetlist( formatter.GetString() ); m_simulator->Run(); - if ( m_welcomePanel ) - { - m_plotNotebook->DeletePage( 0 ); - m_welcomePanel = nullptr; - } - Layout(); } @@ -198,6 +190,12 @@ SIM_PLOT_PANEL* SIM_PLOT_FRAME::NewPlotPanel( SIM_TYPE aSimType ) { SIM_PLOT_PANEL* plot = new SIM_PLOT_PANEL( aSimType, m_plotNotebook, wxID_ANY ); + if( m_welcomePanel ) + { + m_plotNotebook->DeletePage( 0 ); + m_welcomePanel = nullptr; + } + m_plotNotebook->AddPage( plot, wxString::Format( wxT( "Plot%u" ), (unsigned int) m_plotNotebook->GetPageCount() + 1 ), true ); @@ -286,7 +284,7 @@ void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const // Create a new plot if the current one displays a different type SIM_PLOT_PANEL* plotPanel = CurrentPlot(); - if( plotPanel == nullptr || plotPanel->GetType() != simType ) + if( !plotPanel || plotPanel->GetType() != simType ) plotPanel = NewPlotPanel( simType ); TRACE_DESC descriptor( *m_exporter, aName, aType, aParam ); @@ -314,6 +312,7 @@ void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const } } + void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName ) { SIM_PLOT_PANEL* plotPanel = CurrentPlot(); @@ -440,7 +439,7 @@ void SIM_PLOT_FRAME::updateTuners() m_tuneSizer->Clear(); - for( auto tuner : m_plots[plotPanel].m_tuners ) + for( auto& tuner : m_plots[plotPanel].m_tuners ) { m_tuneSizer->Add( tuner ); tuner->Show(); @@ -598,7 +597,27 @@ void SIM_PLOT_FRAME::menuShowCoordsUpdate( wxUpdateUIEvent& event ) } #endif -void SIM_PLOT_FRAME::onPlotChanged( wxNotebookEvent& event ) + +void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event ) +{ + int idx = event.GetSelection(); + + if( idx == wxNOT_FOUND ) + return; + + SIM_PLOT_PANEL* plotPanel = dynamic_cast( m_plotNotebook->GetPage( idx ) ); + + if( !plotPanel ) + return; + + m_plots.erase( plotPanel ); + updateSignalList(); + updateTuners(); + updateCursors(); +} + + +void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event ) { updateSignalList(); updateTuners(); @@ -697,13 +716,17 @@ void SIM_PLOT_FRAME::onClose( wxCloseEvent& aEvent ) void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event ) { wxSize size = m_cursors->GetClientSize(); + SIM_PLOT_PANEL* plotPanel = CurrentPlot(); 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 ); + if( !plotPanel ) + return; - wxString labelY1 = CurrentPlot()->GetLabelY1(); - wxString labelY2 = CurrentPlot()->GetLabelY2(); + const long SIGNAL_COL = m_cursors->AppendColumn( wxT( "Signal" ), wxLIST_FORMAT_LEFT, size.x / 2 ); + const long X_COL = m_cursors->AppendColumn( plotPanel->GetLabelX(), wxLIST_FORMAT_LEFT, size.x / 4 ); + + wxString labelY1 = plotPanel->GetLabelY1(); + wxString labelY2 = plotPanel->GetLabelY2(); wxString labelY; if( !labelY2.IsEmpty() ) @@ -714,7 +737,7 @@ void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event ) const long Y_COL = m_cursors->AppendColumn( labelY, wxLIST_FORMAT_LEFT, size.x / 4 ); // Update cursor values - for( const auto& trace : CurrentPlot()->GetTraces() ) + for( const auto& trace : plotPanel->GetTraces() ) { if( CURSOR* cursor = trace.second->GetCursor() ) { @@ -746,7 +769,7 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent ) SIM_PLOT_PANEL* plotPanel = CurrentPlot(); - if( plotPanel == nullptr || plotPanel->GetType() != simType ) + if( !plotPanel || plotPanel->GetType() != simType ) plotPanel = NewPlotPanel( simType ); // If there are any signals plotted, update them @@ -784,7 +807,7 @@ void SIM_PLOT_FRAME::onSimUpdate( wxCommandEvent& aEvent ) // Apply tuned values if( SIM_PLOT_PANEL* plotPanel = CurrentPlot() ) { - for( auto tuner : m_plots[plotPanel].m_tuners ) + for( auto& tuner : m_plots[plotPanel].m_tuners ) { /// @todo no ngspice hardcoding std::string command( "alter @" + tuner->GetSpiceName() @@ -807,6 +830,13 @@ void SIM_PLOT_FRAME::onSimReport( wxCommandEvent& aEvent ) } +SIM_PLOT_FRAME::PLOT_INFO::~PLOT_INFO() +{ + for( auto& t : m_tuners ) + t->Destroy(); +} + + SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame ) : m_signal( aSignal ), m_plotFrame( aPlotFrame ) diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index e984564152..6b6286b3f9 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -200,7 +200,8 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE //void menuShowCoordsUpdate( wxUpdateUIEvent& event ) override; // Event handlers - void onPlotChanged( wxNotebookEvent& event ) override; + void onPlotChanged( wxAuiNotebookEvent& event ) override; + void onPlotClose( wxAuiNotebookEvent& event ) override; void onSignalDblClick( wxCommandEvent& event ) override; void onSignalRClick( wxMouseEvent& event ) override; @@ -232,9 +233,15 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE typedef std::map TRACE_MAP; typedef std::list TUNER_LIST; - struct PLOT_INFO + class PLOT_INFO { + public: + ~PLOT_INFO(); + + ///> List of component value tuners TUNER_LIST m_tuners; + + ///> Map of the traces displayed on the plot TRACE_MAP m_traces; }; diff --git a/eeschema/sim/sim_plot_frame_base.cpp b/eeschema/sim/sim_plot_frame_base.cpp index 531e93fa9a..a227c96e9e 100644 --- a/eeschema/sim/sim_plot_frame_base.cpp +++ b/eeschema/sim/sim_plot_frame_base.cpp @@ -122,7 +122,7 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_plotPanel = new wxPanel( m_splitterConsole, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_sizer5 = new wxBoxSizer( wxHORIZONTAL ); - m_plotNotebook = new wxNotebook( m_plotPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); + m_plotNotebook = new wxAuiNotebook( m_plotPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_MIDDLE_CLICK_CLOSE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT|wxAUI_NB_TOP ); m_welcomePanel = new wxPanel( m_plotNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_sizer8 = new wxBoxSizer( wxVERTICAL ); @@ -155,9 +155,9 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_welcomePanel->SetSizer( m_sizer8 ); m_welcomePanel->Layout(); m_sizer8->Fit( m_welcomePanel ); - m_plotNotebook->AddPage( m_welcomePanel, _("a page"), false ); + m_plotNotebook->AddPage( m_welcomePanel, _("a page"), false, wxNullBitmap ); - m_sizer5->Add( m_plotNotebook, 3, wxEXPAND | wxALL, 5 ); + m_sizer5->Add( m_plotNotebook, 1, wxEXPAND | wxALL, 5 ); m_plotPanel->SetSizer( m_sizer5 ); @@ -245,7 +245,8 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const 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 ) ); - m_plotNotebook->Connect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this ); + m_plotNotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this ); + m_plotNotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClose ), 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 ); } @@ -271,7 +272,8 @@ SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE() 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 ) ); - m_plotNotebook->Disconnect( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this ); + m_plotNotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this ); + m_plotNotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClose ), 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 714cd890e4..793009961f 100644 --- a/eeschema/sim/sim_plot_frame_base.fbp +++ b/eeschema/sim/sim_plot_frame_base.fbp @@ -240,7 +240,7 @@ - + Simulation m_simulationMenu protected @@ -328,7 +328,7 @@ - + View m_viewMenu protected @@ -418,11 +418,11 @@ m_sizer1 wxVERTICAL protected - + 5 wxEXPAND 0 - + 1 1 1 @@ -834,16 +834,16 @@ - + m_sizer5 wxHORIZONTAL protected - + 5 wxEXPAND | wxALL - 3 - + 1 + 1 1 1 @@ -854,7 +854,6 @@ - 1 0 @@ -877,7 +876,7 @@ 0 - -1,-1 + 1 m_plotNotebook 1 @@ -889,13 +888,24 @@ Resizable 1 - + wxAUI_NB_MIDDLE_CLICK_CLOSE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT|wxAUI_NB_TOP + -1 0 + + + + + + + onPlotChanged + + onPlotClose + @@ -912,8 +922,6 @@ - onPlotChanged - @@ -921,7 +929,7 @@ - + a page 0 @@ -1146,8 +1154,8 @@ - - + + 1 1 1 @@ -1221,7 +1229,7 @@ - + m_sizer13 wxVERTICAL @@ -1325,8 +1333,8 @@ - - + + 1 1 1 @@ -1400,16 +1408,16 @@ - + m_sideSizer wxVERTICAL protected - + 5 wxEXPAND 1 - + wxID_ANY Signals @@ -1508,11 +1516,11 @@ - + 5 wxEXPAND 1 - + wxID_ANY Cursors diff --git a/eeschema/sim/sim_plot_frame_base.h b/eeschema/sim/sim_plot_frame_base.h index 6343e3413d..aad625bb50 100644 --- a/eeschema/sim/sim_plot_frame_base.h +++ b/eeschema/sim/sim_plot_frame_base.h @@ -27,7 +27,7 @@ class KIWAY_PLAYER; #include #include #include -#include +#include #include #include #include @@ -58,7 +58,7 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER wxSplitterWindow* m_splitterConsole; wxPanel* m_plotPanel; wxBoxSizer* m_sizer5; - wxNotebook* m_plotNotebook; + wxAuiNotebook* m_plotNotebook; wxPanel* m_welcomePanel; wxBoxSizer* m_sizer8; wxStaticText* m_staticText2; @@ -86,7 +86,8 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER virtual void menuShowGridUpdate( wxUpdateUIEvent& event ) { event.Skip(); } virtual void menuShowLegend( wxCommandEvent& event ) { event.Skip(); } virtual void menuShowLegendUpdate( wxUpdateUIEvent& event ) { event.Skip(); } - virtual void onPlotChanged( wxNotebookEvent& event ) { event.Skip(); } + virtual void onPlotChanged( wxAuiNotebookEvent& event ) { event.Skip(); } + virtual void onPlotClose( wxAuiNotebookEvent& event ) { event.Skip(); } virtual void onSignalDblClick( wxCommandEvent& event ) { event.Skip(); } virtual void onSignalRClick( wxMouseEvent& event ) { event.Skip(); }