diff --git a/eeschema/sim/sim_panel_base.cpp b/eeschema/sim/sim_panel_base.cpp index d98b485097..22c129ad9e 100644 --- a/eeschema/sim/sim_panel_base.cpp +++ b/eeschema/sim/sim_panel_base.cpp @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include "confirm.h" #include "sim_panel_base.h" #include "sim_plot_frame.h" @@ -73,6 +74,15 @@ 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 3712b846f0..4e04596542 100644 --- a/eeschema/sim/sim_panel_base.h +++ b/eeschema/sim/sim_panel_base.h @@ -46,8 +46,12 @@ public: SIM_TYPE GetType() const; -protected: - const wxString m_simCommand; + void SetSimCommand( const wxString& aSimCommand ); + + const wxString& GetSimCommand() const { return m_simCommand; } + +private: + wxString m_simCommand; }; diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 28c696b1d9..16b014a149 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -461,7 +461,7 @@ void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand ) SIM_PANEL_BASE* plotPanel = currentPlotWindow(); if( plotPanel && m_workbook->HasPlotPanel( plotPanel ) ) - m_exporter->SetSimCommand( m_workbook->GetSimCommand( plotPanel ) ); + m_exporter->SetSimCommand( plotPanel->GetSimCommand() ); } else { @@ -948,9 +948,8 @@ bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath ) } wxString simCommand = file.GetNextLine(); - SIM_PANEL_BASE* plotPanel = NewPlotPanel( simCommand ); - m_workbook->SetSimCommand( plotPanel, simCommand ); - StartSimulation( m_workbook->GetSimCommand( plotPanel ) ); + NewPlotPanel( simCommand ); + StartSimulation( simCommand ); // Perform simulation, so plots can be added with values do @@ -1028,12 +1027,11 @@ bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath ) for( const SIM_PANEL_BASE*& plotPanel : plotPanels ) { - SIM_WORKBOOK::PLOT_INFO plot = m_workbook->GetPlot( plotPanel ); - file.AddLine( wxString::Format( "%d", plotPanel->GetType() ) ); - file.AddLine( plot.m_simCommand ); + file.AddLine( plotPanel->GetSimCommand() ); const SIM_PLOT_PANEL* panel = dynamic_cast( plotPanel ); + if( !panel ) file.AddLine( wxString::Format( "%llu", 0ull ) ); else @@ -1089,16 +1087,8 @@ void SIM_PLOT_FRAME::menuNewPlot( wxCommandEvent& aEvent ) if( SIM_PANEL_BASE::IsPlottable( type ) ) { - SIM_PLOT_PANEL* prevPlot = CurrentPlot(); - SIM_PLOT_PANEL* newPlot = - dynamic_cast( NewPlotPanel( m_exporter->GetUsedSimCommand() ) ); - - // If the previous plot had the same type, copy the simulation command - if( prevPlot ) - { - m_workbook->SetSimCommand( newPlot, m_workbook->GetSimCommand( prevPlot ) ); - updateFrame(); - } + NewPlotPanel( m_exporter->GetUsedSimCommand() ); + updateFrame(); } } @@ -1404,14 +1394,14 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) } if( m_workbook->HasPlotPanel( plotPanelWindow ) ) - m_settingsDlg->SetSimCommand( m_workbook->GetSimCommand( plotPanelWindow ) ); + m_settingsDlg->SetSimCommand( plotPanelWindow->GetSimCommand() ); if( m_settingsDlg->ShowModal() == wxID_OK ) { wxString oldCommand; if( m_workbook->HasPlotPanel( plotPanelWindow ) ) - oldCommand = m_workbook->GetSimCommand( plotPanelWindow ); + oldCommand = plotPanelWindow->GetSimCommand(); else oldCommand = wxString(); @@ -1428,8 +1418,12 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) { plotPanelWindow = NewPlotPanel( newCommand ); } + else + { + // Update simulation command in the current plot + plotPanelWindow->SetSimCommand( newCommand ); + } - m_workbook->SetSimCommand( plotPanelWindow, newCommand ); m_simulator->Init(); updateFrame(); } diff --git a/eeschema/sim/sim_plot_panel.cpp b/eeschema/sim/sim_plot_panel.cpp index 0b3df11207..b7e3793807 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( m_simCommand ) ) + if( simCmd.Matches( GetSimCommand() ) ) { - switch( static_cast( simCmd.GetMatch( m_simCommand.Lower(), 1 ).GetChar( 0 ) ) ) + switch( static_cast( simCmd.GetMatch( GetSimCommand().Lower(), 1 ).GetChar( 0 ) ) ) { case 'v': m_axis_x = diff --git a/eeschema/sim/sim_workbook.h b/eeschema/sim/sim_workbook.h index dc4b2f2d09..fc971ef209 100644 --- a/eeschema/sim/sim_workbook.h +++ b/eeschema/sim/sim_workbook.h @@ -33,10 +33,6 @@ public: struct PLOT_INFO { - ///< Spice directive used to execute the simulation - ///< TODO: use SIM_PANEL_BASE::m_simCommand instead - wxString m_simCommand; - ///< The current position of the plot in the notebook unsigned int pos; }; @@ -66,24 +62,6 @@ public: m_plots.at( aPlotPanel ).pos = pos; } - void SetSimCommand( const SIM_PANEL_BASE* aPlotPanel, const wxString& aSimCommand ) - { - if( m_plots.at( aPlotPanel ).m_simCommand != aSimCommand ) - m_flagModified = true; - - m_plots.at( aPlotPanel ).m_simCommand = aSimCommand; - } - - const wxString& GetSimCommand( const SIM_PANEL_BASE* aPlotPanel ) const - { - return m_plots.at( aPlotPanel ).m_simCommand; - } - - PLOT_INFO GetPlot( const SIM_PANEL_BASE* aPlotPanel ) const - { - return m_plots.at( aPlotPanel ); - } - void ClrModified() { m_flagModified = false; } bool IsModified() const { return m_flagModified; }