diff --git a/eeschema/sim/sim_panel_base.cpp b/eeschema/sim/sim_panel_base.cpp index 22c129ad9e..9e51e8f776 100644 --- a/eeschema/sim/sim_panel_base.cpp +++ b/eeschema/sim/sim_panel_base.cpp @@ -74,15 +74,6 @@ SIM_TYPE SIM_PANEL_BASE::GetType() const } -void SIM_PANEL_BASE::SetSimCommand( const wxString& aSimCommand ) -{ - wxCHECK_RET( GetType() == NETLIST_EXPORTER_PSPICE_SIM::CommandToSimType( aSimCommand ), - "Cannot change the type of simulation of the existing plot panel" ); - - m_simCommand = aSimCommand; -} - - SIM_NOPLOT_PANEL::SIM_NOPLOT_PANEL( wxString aCommand, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : diff --git a/eeschema/sim/sim_panel_base.h b/eeschema/sim/sim_panel_base.h index 4e04596542..494d3b1fa3 100644 --- a/eeschema/sim/sim_panel_base.h +++ b/eeschema/sim/sim_panel_base.h @@ -27,6 +27,7 @@ #define __SIM_PLOT_PANEL_BASE_H #include "sim_types.h" +#include "netlist_exporter_pspice_sim.h" #include #include #include @@ -34,6 +35,8 @@ class SIM_PANEL_BASE : public wxWindow { + friend class SIM_WORKBOOK; + public: SIM_PANEL_BASE(); SIM_PANEL_BASE( wxString aCommand ); @@ -46,10 +49,21 @@ public: SIM_TYPE GetType() const; - void SetSimCommand( const wxString& aSimCommand ); +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. const wxString& GetSimCommand() const { return m_simCommand; } + 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" ); + + m_simCommand = aSimCommand; + } + private: wxString m_simCommand; }; diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index b62bb3faab..f6442dbd79 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -472,7 +472,7 @@ void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand ) SIM_PANEL_BASE* plotPanel = currentPlotWindow(); if( plotPanel && m_workbook->HasPlotPanel( plotPanel ) ) - m_exporter->SetSimCommand( plotPanel->GetSimCommand() ); + m_exporter->SetSimCommand( m_workbook->GetSimCommand( plotPanel ) ); } else { @@ -1041,7 +1041,7 @@ bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath ) for( const SIM_PANEL_BASE*& plotPanel : plotPanels ) { file.AddLine( wxString::Format( "%d", plotPanel->GetType() ) ); - file.AddLine( plotPanel->GetSimCommand() ); + file.AddLine( m_workbook->GetSimCommand( plotPanel ) ); const SIM_PLOT_PANEL* panel = dynamic_cast( plotPanel ); @@ -1401,14 +1401,14 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) } if( m_workbook->HasPlotPanel( plotPanelWindow ) ) - m_settingsDlg->SetSimCommand( plotPanelWindow->GetSimCommand() ); + m_settingsDlg->SetSimCommand( m_workbook->GetSimCommand( plotPanelWindow ) ); if( m_settingsDlg->ShowModal() == wxID_OK ) { wxString oldCommand; if( m_workbook->HasPlotPanel( plotPanelWindow ) ) - oldCommand = plotPanelWindow->GetSimCommand(); + oldCommand = m_workbook->GetSimCommand( plotPanelWindow ); else oldCommand = wxString(); @@ -1428,7 +1428,7 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) else { // Update simulation command in the current plot - plotPanelWindow->SetSimCommand( newCommand ); + m_workbook->SetSimCommand( plotPanelWindow, newCommand ); } m_simulator->Init(); diff --git a/eeschema/sim/sim_workbook.h b/eeschema/sim/sim_workbook.h index fc971ef209..e48984f4a9 100644 --- a/eeschema/sim/sim_workbook.h +++ b/eeschema/sim/sim_workbook.h @@ -62,6 +62,16 @@ public: m_plots.at( aPlotPanel ).pos = pos; } + void SetSimCommand( SIM_PANEL_BASE* aPlotPanel, const wxString& aSimCommand ) + { + aPlotPanel->SetSimCommand( aSimCommand ); + } + + const wxString& GetSimCommand( const SIM_PANEL_BASE* aPlotPanel ) + { + return aPlotPanel->GetSimCommand(); + } + void ClrModified() { m_flagModified = false; } bool IsModified() const { return m_flagModified; }