Make panel sim command only accessible from outside through workbook object

This commit is contained in:
Mikolaj Wielgus 2021-06-29 17:59:07 +02:00 committed by Jon Evans
parent c11ee69499
commit cd0c8a5676
4 changed files with 30 additions and 15 deletions

View File

@ -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 ) :

View File

@ -27,6 +27,7 @@
#define __SIM_PLOT_PANEL_BASE_H
#include "sim_types.h"
#include "netlist_exporter_pspice_sim.h"
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
@ -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;
};

View File

@ -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<const SIM_PLOT_PANEL*>( 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();

View File

@ -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; }