From 28531a982d86fc95c1105cdb6d8a87fea1212a1c Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Wed, 30 Jun 2021 02:13:10 +0200 Subject: [PATCH] Simulator: Use SIM_WORKBOOK in place of wxAuiNotebook SIM_WORKBOOK is now a subclass of wxAuiNotebook, removing the problem of having to maintain two separate workbook states. --- eeschema/sim/sim_panel_base.h | 10 ++-- eeschema/sim/sim_plot_frame.cpp | 84 ++++++++++------------------ eeschema/sim/sim_plot_frame.h | 15 +---- eeschema/sim/sim_plot_frame_base.cpp | 22 ++++---- eeschema/sim/sim_plot_frame_base.fbp | 50 ++++++++--------- eeschema/sim/sim_plot_frame_base.h | 3 +- eeschema/sim/sim_plot_panel.cpp | 12 ++-- eeschema/sim/sim_plot_panel.h | 17 +++--- eeschema/sim/sim_workbook.cpp | 56 ++++++++----------- eeschema/sim/sim_workbook.h | 61 +++++++++----------- 10 files changed, 141 insertions(+), 189 deletions(-) diff --git a/eeschema/sim/sim_panel_base.h b/eeschema/sim/sim_panel_base.h index 494d3b1fa3..90c320d8db 100644 --- a/eeschema/sim/sim_panel_base.h +++ b/eeschema/sim/sim_panel_base.h @@ -50,13 +50,13 @@ public: SIM_TYPE GetType() const; protected: - // Some members should be accessible from outside only through a workbook object, to prevent - // anyone from modifying the state without its knowledge. Otherwise we risk some things not - // getting saved. + // We use `protected` here because members should be accessible from outside only through a + // workbook object, to prevent anyone from modifying the state without its knowledge. Otherwise + // we risk some things not getting saved. - const wxString& GetSimCommand() const { return m_simCommand; } + const wxString& getSimCommand() const { return m_simCommand; } - void SetSimCommand( const wxString& aSimCommand ) + void setSimCommand( const wxString& aSimCommand ) { wxCHECK_RET( GetType() == NETLIST_EXPORTER_PSPICE_SIM::CommandToSimType( aSimCommand ), "Cannot change the type of simulation of the existing plot panel" ); diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index f6442dbd79..e0c6070e42 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -206,7 +206,7 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : #ifndef wxHAS_NATIVE_TABART // Non-native default tab art has ulgy gradients we don't want - m_plotNotebook->SetArtProvider( new wxAuiSimpleTabArt() ); + m_workbook->SetArtProvider( new wxAuiSimpleTabArt() ); #endif // Ensure new items are taken in account by sizers: @@ -304,7 +304,7 @@ WINDOW_SETTINGS* SIM_PLOT_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg ) void SIM_PLOT_FRAME::initWorkbook() { - m_workbook = std::make_unique(); + m_workbook->DeleteAllPages(); if( !m_simulator->Settings()->GetWorkbookFilename().IsEmpty() ) { @@ -352,15 +352,6 @@ void SIM_PLOT_FRAME::updateTitle() } -void SIM_PLOT_FRAME::updateWorkbook() -{ - // We need to keep track of the plot panel positions - for( unsigned int i = 0; i < m_plotNotebook->GetPageCount(); i++ ) - m_workbook->SetPlotPanelPosition( - dynamic_cast( m_plotNotebook->GetPage( i ) ), i ); -} - - void SIM_PLOT_FRAME::updateFrame() { updateTitle(); @@ -471,7 +462,7 @@ void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand ) { SIM_PANEL_BASE* plotPanel = currentPlotWindow(); - if( plotPanel && m_workbook->HasPlotPanel( plotPanel ) ) + if( plotPanel && m_workbook->GetPageIndex( plotPanel ) != wxNOT_FOUND ) m_exporter->SetSimCommand( m_workbook->GetSimCommand( plotPanel ) ); } else @@ -518,7 +509,7 @@ SIM_PANEL_BASE* SIM_PLOT_FRAME::NewPlotPanel( wxString aSimCommand ) if( SIM_PANEL_BASE::IsPlottable( simType ) ) { SIM_PLOT_PANEL* panel; - panel = new SIM_PLOT_PANEL( aSimCommand, m_plotNotebook, this, wxID_ANY ); + panel = new SIM_PLOT_PANEL( aSimCommand, m_workbook, this, wxID_ANY ); panel->GetPlotWin()->EnableMouseWheelPan( Pgm().GetCommonSettings()->m_Input.scroll_modifier_zoom != 0 ); @@ -528,16 +519,14 @@ SIM_PANEL_BASE* SIM_PLOT_FRAME::NewPlotPanel( wxString aSimCommand ) else { SIM_NOPLOT_PANEL* panel; - panel = new SIM_NOPLOT_PANEL( aSimCommand, m_plotNotebook, wxID_ANY ); + panel = new SIM_NOPLOT_PANEL( aSimCommand, m_workbook, wxID_ANY ); plotPanel = dynamic_cast( panel ); } wxString pageTitle( m_simulator->TypeToName( simType, true ) ); pageTitle.Prepend( wxString::Format( _( "Plot%u - " ), (unsigned int) ++m_plotNumber ) ); - m_workbook->AddPlotPanel( plotPanel ); - - m_plotNotebook->AddPage( dynamic_cast( plotPanel ), pageTitle, true ); + m_workbook->AddPage( dynamic_cast( plotPanel ), pageTitle, true ); updateFrame(); return plotPanel; @@ -687,18 +676,15 @@ void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const } -void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName, bool aErase ) +void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName ) { SIM_PLOT_PANEL* plotPanel = CurrentPlot(); if( !plotPanel ) return; - if( aErase ) - m_workbook->RemoveTrace( plotPanel, aPlotName ); - wxASSERT( plotPanel->TraceShown( aPlotName ) ); - plotPanel->DeleteTrace( aPlotName ); + m_workbook->DeleteTrace( plotPanel, aPlotName ); plotPanel->GetPlotWin()->Fit(); updateSignalList(); @@ -718,7 +704,7 @@ void SIM_PLOT_FRAME::updateNetlistExporter() bool SIM_PLOT_FRAME::updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam, - SIM_PLOT_PANEL* aPanel ) + SIM_PLOT_PANEL* aPlotPanel ) { SIM_TYPE simType = m_exporter->GetSimType(); wxString spiceVector = m_exporter->ComponentToVector( aName, aType, aParam ); @@ -803,8 +789,9 @@ bool SIM_PLOT_FRAME::updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, con std::vector sub_y( data_y.begin() + offset, data_y.begin() + offset + inner ); - if( aPanel->AddTrace( name, inner, sub_x.data(), sub_y.data(), aType, aParam ) ) - m_workbook->AddTrace( aPanel, name ); + //if( aPlotPanel->AddTrace( name, inner, sub_x.data(), sub_y.data(), aType, aParam ) ) + m_workbook->AddTrace( aPlotPanel, name, inner, sub_x.data(), sub_y.data(), aType, + aParam ); v = v + source2.m_vincrement; offset += inner; @@ -814,9 +801,8 @@ bool SIM_PLOT_FRAME::updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, con return true; } } - - if( aPanel->AddTrace( aName, size, data_x.data(), data_y.data(), aType, aParam ) ) - m_workbook->AddTrace( aPanel, aName ); + + m_workbook->AddTrace( aPlotPanel, aName, size, data_x.data(), data_y.data(), aType, aParam ); updateFrame(); return true; @@ -930,8 +916,7 @@ void SIM_PLOT_FRAME::applyTuners() bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) { - m_workbook->Clear(); - m_plotNotebook->DeleteAllPages(); + m_workbook->DeleteAllPages(); wxTextFile file( aPath ); @@ -1034,26 +1019,26 @@ bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath ) file.Create(); } - std::vector plotPanels = m_workbook->GetSortedPlotPanels(); + file.AddLine( wxString::Format( "%llu", m_workbook->GetPageCount() ) ); - file.AddLine( wxString::Format( "%llu", plotPanels.size() ) ); - - for( const SIM_PANEL_BASE*& plotPanel : plotPanels ) + for( size_t i = 0; i < m_workbook->GetPageCount(); i++ ) { - file.AddLine( wxString::Format( "%d", plotPanel->GetType() ) ); - file.AddLine( m_workbook->GetSimCommand( plotPanel ) ); + const SIM_PANEL_BASE* basePanel = dynamic_cast( m_workbook->GetPage( i ) ); - const SIM_PLOT_PANEL* panel = dynamic_cast( plotPanel ); + file.AddLine( wxString::Format( "%d", basePanel->GetType() ) ); + file.AddLine( m_workbook->GetSimCommand( basePanel ) ); - if( !panel ) + const SIM_PLOT_PANEL* plotPanel = dynamic_cast( basePanel ); + + if( !plotPanel ) { file.AddLine( wxString::Format( "%llu", 0ull ) ); } else { - file.AddLine( wxString::Format( "%llu", panel->GetTraces().size() ) ); + file.AddLine( wxString::Format( "%llu", plotPanel->GetTraces().size() ) ); - for( const auto& trace : panel->GetTraces() ) + for( const auto& trace : plotPanel->GetTraces() ) { file.AddLine( wxString::Format( "%d", trace.second->GetType() ) ); file.AddLine( trace.second->GetName() ); @@ -1293,9 +1278,9 @@ void SIM_PLOT_FRAME::menuWhiteBackground( wxCommandEvent& event ) SIM_PLOT_COLORS::FillDefaultColorList( GetPlotBgOpt() ); // Now send changes to all SIM_PLOT_PANEL - for( size_t page = 0; page < m_plotNotebook->GetPageCount(); page++ ) + for( size_t page = 0; page < m_workbook->GetPageCount(); page++ ) { - wxWindow* curPage = m_plotNotebook->GetPage( page ); + wxWindow* curPage = m_workbook->GetPage( page ); // ensure it is truly a plot panel and not the (zero plots) placeholder // which is only SIM_PLOT_PANEL_BASE @@ -1314,9 +1299,6 @@ void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event ) if( idx == wxNOT_FOUND ) return; - SIM_PANEL_BASE* plotPanel = dynamic_cast( m_plotNotebook->GetPage( idx ) ); - - m_workbook->RemovePlotPanel( plotPanel ); wxCommandEvent dummy; onCursorUpdate( dummy ); } @@ -1324,7 +1306,6 @@ void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event ) void SIM_PLOT_FRAME::onPlotClosed( wxAuiNotebookEvent& event ) { - updateWorkbook(); updateFrame(); } @@ -1335,14 +1316,12 @@ void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event ) wxCommandEvent dummy; onCursorUpdate( dummy ); - updateWorkbook(); updateFrame(); } void SIM_PLOT_FRAME::onPlotDragged( wxAuiNotebookEvent& event ) { - updateWorkbook(); updateFrame(); } @@ -1400,14 +1379,14 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) return; } - if( m_workbook->HasPlotPanel( plotPanelWindow ) ) + if( m_workbook->GetPageIndex( plotPanelWindow ) != wxNOT_FOUND ) m_settingsDlg->SetSimCommand( m_workbook->GetSimCommand( plotPanelWindow ) ); if( m_settingsDlg->ShowModal() == wxID_OK ) { wxString oldCommand; - if( m_workbook->HasPlotPanel( plotPanelWindow ) ) + if( m_workbook->GetPageIndex( plotPanelWindow ) != wxNOT_FOUND ) oldCommand = m_workbook->GetSimCommand( plotPanelWindow ); else oldCommand = wxString(); @@ -1681,10 +1660,7 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent ) for( auto& trace : traceInfo ) { if( !updatePlot( trace.m_name, trace.m_type, trace.m_param, plotPanel ) ) - { - removePlot( trace.m_name, false ); - m_workbook->RemoveTrace( plotPanel, trace.m_name ); - } + removePlot( trace.m_name ); } updateSignalList(); diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index fc665f07f9..2f8797ecdc 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -149,11 +149,6 @@ private: */ void updateTitle(); - /** - * Update the workbook to match the changes in the frame. - */ - void updateWorkbook(); - /** * Update the frame to match the changes to the workbook. Should be always called after the * workbook was modified. @@ -170,7 +165,7 @@ private: */ SIM_PANEL_BASE* currentPlotWindow() const { - return dynamic_cast( m_plotNotebook->GetCurrentPage() ); + return dynamic_cast( m_workbook->GetCurrentPage() ); } /** @@ -186,9 +181,8 @@ private: * Remove a plot with a specific title. * * @param aPlotName is the full plot title (e.g. I(Net-C1-Pad1)). - * @param aErase decides if plot should be removed from corresponding TRACE_MAP (see m_plots). */ - void removePlot( const wxString& aPlotName, bool aErase = true ); + void removePlot( const wxString& aPlotName ); /** * Reload the current schematic for the netlist exporter. @@ -204,7 +198,7 @@ private: * @return True if a plot was successfully added/updated. */ bool updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam, - SIM_PLOT_PANEL* aPanel ); + SIM_PLOT_PANEL* aPlotPanel ); /** * Update the list of currently plotted signals. @@ -315,9 +309,6 @@ private: std::shared_ptr m_simulator; SIM_THREAD_REPORTER* m_reporter; - ///< Stores the data that can be preserved across simulator sessions - std::unique_ptr m_workbook; - ///< List of currently displayed tuners std::list m_tuners; diff --git a/eeschema/sim/sim_plot_frame_base.cpp b/eeschema/sim/sim_plot_frame_base.cpp index e0b60acc98..9e18f4855e 100644 --- a/eeschema/sim/sim_plot_frame_base.cpp +++ b/eeschema/sim/sim_plot_frame_base.cpp @@ -142,11 +142,11 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const m_sizerPlot = new wxBoxSizer( wxHORIZONTAL ); - m_plotNotebook = new wxAuiNotebook( m_plotPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_CLOSE_ON_ALL_TABS|wxAUI_NB_MIDDLE_CLICK_CLOSE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT|wxAUI_NB_TOP ); - m_plotNotebook->SetMinSize( wxSize( 200,-1 ) ); + m_workbook = new SIM_WORKBOOK( m_plotPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_CLOSE_ON_ALL_TABS|wxAUI_NB_MIDDLE_CLICK_CLOSE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT|wxAUI_NB_TOP ); + m_workbook->SetMinSize( wxSize( 200,-1 ) ); - m_sizerPlot->Add( m_plotNotebook, 1, wxEXPAND, 5 ); + m_sizerPlot->Add( m_workbook, 1, wxEXPAND, 5 ); m_plotPanel->SetSizer( m_sizerPlot ); @@ -290,10 +290,10 @@ SIM_PLOT_FRAME_BASE::SIM_PLOT_FRAME_BASE( wxWindow* parent, wxWindowID id, const this->Connect( m_showDotted->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowDottedUpdate ) ); m_viewMenu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME_BASE::menuWhiteBackground ), this, m_showWhiteBackground->GetId()); this->Connect( m_showWhiteBackground->GetId(), wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowWhiteBackgroundUpdate ) ); - m_plotNotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotDragged ), 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_plotNotebook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClosed ), NULL, this ); + m_workbook->Connect( wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotDragged ), NULL, this ); + m_workbook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this ); + m_workbook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClose ), NULL, this ); + m_workbook->Connect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClosed ), NULL, this ); m_signals->Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), NULL, this ); m_signals->Connect( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, wxListEventHandler( SIM_PLOT_FRAME_BASE::onSignalRClick ), NULL, this ); } @@ -305,10 +305,10 @@ SIM_PLOT_FRAME_BASE::~SIM_PLOT_FRAME_BASE() this->Disconnect( ID_MENU_SHOW_LEGEND, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowLegendUpdate ) ); this->Disconnect( ID_MENU_DOTTED, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowDottedUpdate ) ); this->Disconnect( ID_MENU_WHITE_BG, wxEVT_UPDATE_UI, wxUpdateUIEventHandler( SIM_PLOT_FRAME_BASE::menuShowWhiteBackgroundUpdate ) ); - m_plotNotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotDragged ), 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_plotNotebook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClosed ), NULL, this ); + m_workbook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotDragged ), NULL, this ); + m_workbook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotChanged ), NULL, this ); + m_workbook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClose ), NULL, this ); + m_workbook->Disconnect( wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED, wxAuiNotebookEventHandler( SIM_PLOT_FRAME_BASE::onPlotClosed ), NULL, this ); m_signals->Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( SIM_PLOT_FRAME_BASE::onSignalDblClick ), NULL, this ); m_signals->Disconnect( wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, wxListEventHandler( 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 c4ea75699b..524fc21c83 100644 --- a/eeschema/sim/sim_plot_frame_base.fbp +++ b/eeschema/sim/sim_plot_frame_base.fbp @@ -76,7 +76,7 @@ - + File m_fileMenu protected @@ -191,7 +191,7 @@ menuExit - + Simulation m_simulationMenu protected @@ -286,7 +286,7 @@ - + View m_viewMenu protected @@ -469,11 +469,11 @@ - + 5 wxEXPAND 1 - + 1 1 1 @@ -530,8 +530,8 @@ wxBORDER_NONE - - + + 1 1 1 @@ -582,16 +582,16 @@ wxTAB_TRAVERSAL - + -1,-1 m_sizer11 wxVERTICAL protected - + 5 wxEXPAND 1 - + 1 1 1 @@ -648,8 +648,8 @@ - - + + 1 1 1 @@ -744,7 +744,7 @@ 0 200,-1 1 - m_plotNotebook + m_workbook 1 @@ -755,7 +755,7 @@ 1 wxAUI_NB_CLOSE_ON_ALL_TABS|wxAUI_NB_MIDDLE_CLICK_CLOSE|wxAUI_NB_TAB_MOVE|wxAUI_NB_TAB_SPLIT|wxAUI_NB_TOP - + SIM_WORKBOOK; sim_workbook.h; Not forward_declare -1 0 @@ -772,8 +772,8 @@ - - + + 1 1 1 @@ -901,8 +901,8 @@ - - + + 1 1 1 @@ -953,16 +953,16 @@ wxTAB_TRAVERSAL - + m_sideSizer wxVERTICAL protected - + 5 wxEXPAND 1 - + 1 1 1 @@ -1019,8 +1019,8 @@ - - + + 1 1 1 @@ -1204,8 +1204,8 @@ - - + + 1 1 1 diff --git a/eeschema/sim/sim_plot_frame_base.h b/eeschema/sim/sim_plot_frame_base.h index 3667952124..709acacc1c 100644 --- a/eeschema/sim/sim_plot_frame_base.h +++ b/eeschema/sim/sim_plot_frame_base.h @@ -10,6 +10,7 @@ #include #include #include +#include "sim_workbook.h" #include "kiway_player.h" #include #include @@ -72,7 +73,7 @@ class SIM_PLOT_FRAME_BASE : public KIWAY_PLAYER wxSplitterWindow* m_splitterPlotAndConsole; wxPanel* m_plotPanel; wxBoxSizer* m_sizerPlot; - wxAuiNotebook* m_plotNotebook; + SIM_WORKBOOK* m_workbook; wxPanel* m_panelConsole; wxBoxSizer* m_sizerConsole; wxTextCtrl* m_simConsole; diff --git a/eeschema/sim/sim_plot_panel.cpp b/eeschema/sim/sim_plot_panel.cpp index b7e3793807..b81448a960 100644 --- a/eeschema/sim/sim_plot_panel.cpp +++ b/eeschema/sim/sim_plot_panel.cpp @@ -386,9 +386,9 @@ void SIM_PLOT_PANEL::prepareDCAxes() { wxRegEx simCmd( "^.dc[[:space:]]+([[:alnum:]]+\\M).*", wxRE_ADVANCED | wxRE_ICASE ); - if( simCmd.Matches( GetSimCommand() ) ) + if( simCmd.Matches( getSimCommand() ) ) { - switch( static_cast( simCmd.GetMatch( GetSimCommand().Lower(), 1 ).GetChar( 0 ) ) ) + switch( static_cast( simCmd.GetMatch( getSimCommand().Lower(), 1 ).GetChar( 0 ) ) ) { case 'v': m_axis_x = @@ -441,7 +441,7 @@ void SIM_PLOT_PANEL::UpdateTraceStyle( TRACE* trace ) } -bool SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints, const double* aX, +bool SIM_PLOT_PANEL::addTrace( const wxString& aName, int aPoints, const double* aX, const double* aY, SIM_PLOT_TYPE aType, const wxString& aParam ) { TRACE* trace = NULL; @@ -526,7 +526,7 @@ bool SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints, const double* } -bool SIM_PLOT_PANEL::DeleteTrace( const wxString& aName ) +bool SIM_PLOT_PANEL::deleteTrace( const wxString& aName ) { auto it = m_traces.find( aName ); @@ -548,11 +548,11 @@ bool SIM_PLOT_PANEL::DeleteTrace( const wxString& aName ) } -void SIM_PLOT_PANEL::DeleteAllTraces() +void SIM_PLOT_PANEL::deleteAllTraces() { for( auto& t : m_traces ) { - DeleteTrace( t.first ); + deleteTrace( t.first ); } m_traces.clear(); diff --git a/eeschema/sim/sim_plot_panel.h b/eeschema/sim/sim_plot_panel.h index 50bec3f079..a8d950f0a1 100644 --- a/eeschema/sim/sim_plot_panel.h +++ b/eeschema/sim/sim_plot_panel.h @@ -175,6 +175,8 @@ private: class SIM_PLOT_PANEL : public SIM_PANEL_BASE { + friend class SIM_WORKBOOK; + public: SIM_PLOT_PANEL( wxString aCommand, wxWindow* parent, SIM_PLOT_FRAME* aMainFrame, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, @@ -203,13 +205,6 @@ public: return m_axis_y2 ? m_axis_y2->GetName() : ""; } - bool AddTrace( const wxString& aName, int aPoints, const double* aX, const double* aY, - SIM_PLOT_TYPE aType, const wxString& aParam ); - - bool DeleteTrace( const wxString& aName ); - - void DeleteAllTraces(); - bool TraceShown( const wxString& aName ) const { return m_traces.count( aName ) > 0; @@ -293,6 +288,14 @@ public: return m_plotWin; } +protected: + bool addTrace( const wxString& aName, int aPoints, const double* aX, const double* aY, + SIM_PLOT_TYPE aType, const wxString& aParam ); + + bool deleteTrace( const wxString& aName ); + + void deleteAllTraces(); + private: ///< @brief Construct the plot axes for DC simulation plot. void prepareDCAxes(); diff --git a/eeschema/sim/sim_workbook.cpp b/eeschema/sim/sim_workbook.cpp index 79c6424893..a5241349dc 100644 --- a/eeschema/sim/sim_workbook.cpp +++ b/eeschema/sim/sim_workbook.cpp @@ -25,61 +25,53 @@ #include -SIM_WORKBOOK::SIM_WORKBOOK() : - m_flagModified( false ) +SIM_WORKBOOK::SIM_WORKBOOK() = default; + + +SIM_WORKBOOK::SIM_WORKBOOK( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos, const wxSize& + aSize, long aStyle ) : wxAuiNotebook( aParent, aId, aPos, aSize, aStyle ) { } -void SIM_WORKBOOK::Clear() +bool SIM_WORKBOOK::AddPage( wxWindow* page, const wxString& caption, bool select, const wxBitmap& bitmap ) { - m_plots.clear(); + m_modified = true; + return wxAuiNotebook::AddPage( page, caption, select, bitmap ); } -void SIM_WORKBOOK::AddPlotPanel( SIM_PANEL_BASE* aPlotPanel ) +bool SIM_WORKBOOK::AddPage( wxWindow* page, const wxString& text, bool select, int imageId ) { - wxASSERT( m_plots.count( aPlotPanel ) == 0 ); - m_plots[aPlotPanel] = PLOT_INFO(); - - m_flagModified = true; + m_modified = true; + return wxAuiNotebook::AddPage( page, text, select, imageId ); } -void SIM_WORKBOOK::RemovePlotPanel( SIM_PANEL_BASE* aPlotPanel ) +bool SIM_WORKBOOK::DeleteAllPages() { - wxASSERT( m_plots.count( aPlotPanel ) == 1 ); - m_plots.erase( aPlotPanel ); - - m_flagModified = true; + m_modified = true; + return wxAuiNotebook::DeleteAllPages(); } -std::vector SIM_WORKBOOK::GetSortedPlotPanels() const +bool SIM_WORKBOOK::DeletePage( size_t page ) { - std::vector plotPanels; - - for( const auto& plot : m_plots ) - plotPanels.push_back( plot.first ); - - std::sort( plotPanels.begin(), plotPanels.end(), - [&]( const SIM_PANEL_BASE*& a, const SIM_PANEL_BASE*& b ) - { - return m_plots.at( a ).pos < m_plots.at( b ).pos; - }); - - return plotPanels; + m_modified = true; + return wxAuiNotebook::DeletePage( page ); } -void SIM_WORKBOOK::AddTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName ) +void SIM_WORKBOOK::AddTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName, int aPoints, const + double* aX, const double* aY, SIM_PLOT_TYPE aType, const wxString& aParam ) { - m_flagModified = true; + aPlotPanel->addTrace( aName, aPoints, aX, aY, aType, aParam ); + m_modified = true; } -void SIM_WORKBOOK::RemoveTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName ) +void SIM_WORKBOOK::DeleteTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName ) { - m_flagModified = true; + aPlotPanel->deleteTrace( aName ); + m_modified = true; } - diff --git a/eeschema/sim/sim_workbook.h b/eeschema/sim/sim_workbook.h index e48984f4a9..866b320d19 100644 --- a/eeschema/sim/sim_workbook.h +++ b/eeschema/sim/sim_workbook.h @@ -22,63 +22,52 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#ifndef __SIM_WORKBOOK__ +#define __SIM_WORKBOOK__ + #include "dialog_sim_settings.h" #include #include -class SIM_WORKBOOK +class SIM_WORKBOOK : public wxAuiNotebook { public: - - struct PLOT_INFO - { - ///< The current position of the plot in the notebook - unsigned int pos; - }; - SIM_WORKBOOK(); + SIM_WORKBOOK( wxWindow* aParent, wxWindowID aId=wxID_ANY, const wxPoint& + aPos=wxDefaultPosition, const wxSize& aSize=wxDefaultSize, long + aStyle=wxAUI_NB_DEFAULT_STYLE ); - void Clear(); + // Methods from wxAuiNotebook + + bool AddPage( wxWindow* aPage, const wxString& aCaption, bool aSelect=false, const wxBitmap& aBitmap=wxNullBitmap ); + bool AddPage( wxWindow* aPage, const wxString& aText, bool aSelect, int aImageId ) override; - void AddPlotPanel( SIM_PANEL_BASE* aPlotPanel ); - void RemovePlotPanel( SIM_PANEL_BASE* aPlotPanel ); + bool DeleteAllPages() override; + bool DeletePage( size_t aPage ) override; - std::vector GetSortedPlotPanels() const; - - bool HasPlotPanel( SIM_PANEL_BASE* aPlotPanel ) const - { - return m_plots.count( aPlotPanel ) == 1; - } - - void AddTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName ); - void RemoveTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName ); - - void SetPlotPanelPosition( const SIM_PANEL_BASE* aPlotPanel, unsigned int pos ) - { - if( pos != m_plots.at( aPlotPanel ).pos ) - m_flagModified = true; - - m_plots.at( aPlotPanel ).pos = pos; - } + // Custom methods + void AddTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName, int aPoints, const double* + aX, const double* aY, SIM_PLOT_TYPE aType, const wxString& aParam ); + void DeleteTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName ); + void SetSimCommand( SIM_PANEL_BASE* aPlotPanel, const wxString& aSimCommand ) { - aPlotPanel->SetSimCommand( aSimCommand ); + aPlotPanel->setSimCommand( aSimCommand ); } const wxString& GetSimCommand( const SIM_PANEL_BASE* aPlotPanel ) { - return aPlotPanel->GetSimCommand(); + return aPlotPanel->getSimCommand(); } - void ClrModified() { m_flagModified = false; } - bool IsModified() const { return m_flagModified; } + void ClrModified() { m_modified = false; } + bool IsModified() const { return m_modified; } private: ///< Dirty bit, indicates something in the workbook has changed - bool m_flagModified; - - ///< Map of plot panels and associated data - std::map m_plots; + bool m_modified; }; + +#endif // __SIM_WORKBOOK__