Added a few checks for SIM_PLOT_FRAME to improve robustness

This commit is contained in:
Maciej Suminski 2016-08-11 14:41:41 +02:00
parent 3999ff1973
commit b897af7eb9
3 changed files with 34 additions and 14 deletions

View File

@ -78,6 +78,13 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent )
{ {
SetKiway( this, aKiway ); SetKiway( this, aKiway );
m_schematicFrame = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
if( m_schematicFrame == NULL )
throw std::runtime_error( "There is no schematic window" );
updateNetlistExporter();
Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( SIM_PLOT_FRAME::onClose ), NULL, this ); Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( SIM_PLOT_FRAME::onClose ), NULL, this );
Connect( EVT_SIM_REPORT, wxCommandEventHandler( SIM_PLOT_FRAME::onSimReport ), NULL, this ); Connect( EVT_SIM_REPORT, wxCommandEventHandler( SIM_PLOT_FRAME::onSimReport ), NULL, this );
Connect( EVT_SIM_STARTED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimStarted ), NULL, this ); Connect( EVT_SIM_STARTED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimStarted ), NULL, this );
@ -115,6 +122,7 @@ void SIM_PLOT_FRAME::StartSimulation()
void SIM_PLOT_FRAME::StopSimulation() void SIM_PLOT_FRAME::StopSimulation()
{ {
if( m_simulator )
m_simulator->Stop(); m_simulator->Stop();
} }
@ -158,8 +166,11 @@ void SIM_PLOT_FRAME::updateNetlistExporter()
} }
void SIM_PLOT_FRAME::updatePlot( const wxString& aSpiceName, const wxString& aName, SIM_PLOT_PANEL* aPanel ) bool SIM_PLOT_FRAME::updatePlot( const wxString& aSpiceName, const wxString& aName, SIM_PLOT_PANEL* aPanel )
{ {
if( !m_simulator )
return false;
// First, handle the x axis // First, handle the x axis
wxString xAxisName; wxString xAxisName;
SIM_TYPE simType = m_exporter->GetSimType(); SIM_TYPE simType = m_exporter->GetSimType();
@ -168,7 +179,7 @@ void SIM_PLOT_FRAME::updatePlot( const wxString& aSpiceName, const wxString& aNa
{ {
// There is no plot to be shown // There is no plot to be shown
m_simulator->Command( wxString::Format( "print %s", aSpiceName ).ToStdString() ); m_simulator->Command( wxString::Format( "print %s", aSpiceName ).ToStdString() );
return; return false;
} }
switch( simType ) switch( simType )
@ -198,7 +209,7 @@ void SIM_PLOT_FRAME::updatePlot( const wxString& aSpiceName, const wxString& aNa
int size = data_x.size(); int size = data_x.size();
if( data_x.empty() ) if( data_x.empty() )
return; return false;
// Now, Y axis data // Now, Y axis data
switch( m_exporter->GetSimType() ) switch( m_exporter->GetSimType() )
@ -208,6 +219,10 @@ void SIM_PLOT_FRAME::updatePlot( const wxString& aSpiceName, const wxString& aNa
{ {
auto data_mag = m_simulator->GetMagPlot( (const char*) aSpiceName.c_str() ); auto data_mag = m_simulator->GetMagPlot( (const char*) aSpiceName.c_str() );
auto data_phase = m_simulator->GetPhasePlot( (const char*) aSpiceName.c_str() ); auto data_phase = m_simulator->GetPhasePlot( (const char*) aSpiceName.c_str() );
if( data_mag.empty() || data_phase.empty() )
return false;
aPanel->AddTrace( aSpiceName, aName + " (mag)", size, data_x.data(), data_mag.data(), 0 ); aPanel->AddTrace( aSpiceName, aName + " (mag)", size, data_x.data(), data_mag.data(), 0 );
aPanel->AddTrace( aSpiceName, aName + " (phase)", size, data_x.data(), data_phase.data(), 0 ); aPanel->AddTrace( aSpiceName, aName + " (phase)", size, data_x.data(), data_phase.data(), 0 );
} }
@ -218,13 +233,20 @@ void SIM_PLOT_FRAME::updatePlot( const wxString& aSpiceName, const wxString& aNa
case ST_TRANSIENT: case ST_TRANSIENT:
{ {
auto data_y = m_simulator->GetMagPlot( (const char*) aSpiceName.c_str() ); auto data_y = m_simulator->GetMagPlot( (const char*) aSpiceName.c_str() );
if( data_y.empty() )
return false;
aPanel->AddTrace( aSpiceName, aName, size, data_x.data(), data_y.data(), 0 ); aPanel->AddTrace( aSpiceName, aName, size, data_x.data(), data_y.data(), 0 );
} }
break; break;
default: default:
return; wxASSERT_MSG( false, "Unhandled plot type" );
return false;
} }
return true;
} }

View File

@ -31,12 +31,14 @@
#include "sim_plot_frame_base.h" #include "sim_plot_frame_base.h"
#include "sim_types.h" #include "sim_types.h"
#include "kiway_player.h"
#include <netlist_exporters/netlist_exporter_pspice.h> #include <kiway_player.h>
#include <dialogs/dialog_sim_settings.h> #include <dialogs/dialog_sim_settings.h>
#include <wx/event.h> #include <wx/event.h>
#include <memory>
class SCH_EDIT_FRAME;
class SPICE_SIMULATOR; class SPICE_SIMULATOR;
class NETLIST_EXPORTER_PSPICE_SIM; class NETLIST_EXPORTER_PSPICE_SIM;
class SIM_PLOT_PANEL; class SIM_PLOT_PANEL;
@ -49,11 +51,6 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ); SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
~SIM_PLOT_FRAME(); ~SIM_PLOT_FRAME();
void SetSchFrame( SCH_EDIT_FRAME* aSchFrame )
{
m_schematicFrame = aSchFrame;
}
void StartSimulation(); void StartSimulation();
void StopSimulation(); void StopSimulation();
@ -74,8 +71,10 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
* (for NGSPICE it is e.g. "V(1)"). * (for NGSPICE it is e.g. "V(1)").
* @param aName is the name used in the legend. * @param aName is the name used in the legend.
* @param aPanel is the panel that should receive the update. * @param aPanel is the panel that should receive the update.
* @return True if a plot was successfully added/updated.
*/
bool updatePlot( const wxString& aSpiceName, const wxString& aName, SIM_PLOT_PANEL* aPanel );
*/ */
void updatePlot( const wxString& aSpiceName, const wxString& aName, SIM_PLOT_PANEL* aPanel );
/** /**
* @brief Returns node number for a given net. * @brief Returns node number for a given net.

View File

@ -36,7 +36,6 @@ void SCH_EDIT_FRAME::OnSimulate( wxCommandEvent& event )
simFrame->Iconize( false ); simFrame->Iconize( false );
simFrame->Raise(); simFrame->Raise();
simFrame->SetSchFrame( this );
} }
// I apologize for the following lines, but this is more or less what wxWidgets // I apologize for the following lines, but this is more or less what wxWidgets