Added a few checks for SIM_PLOT_FRAME to improve robustness
This commit is contained in:
parent
3999ff1973
commit
b897af7eb9
|
@ -78,6 +78,13 @@ SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent )
|
|||
{
|
||||
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( EVT_SIM_REPORT, wxCommandEventHandler( SIM_PLOT_FRAME::onSimReport ), NULL, this );
|
||||
Connect( EVT_SIM_STARTED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimStarted ), NULL, this );
|
||||
|
@ -115,7 +122,8 @@ void SIM_PLOT_FRAME::StartSimulation()
|
|||
|
||||
void SIM_PLOT_FRAME::StopSimulation()
|
||||
{
|
||||
m_simulator->Stop();
|
||||
if( m_simulator )
|
||||
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
|
||||
wxString xAxisName;
|
||||
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
|
||||
m_simulator->Command( wxString::Format( "print %s", aSpiceName ).ToStdString() );
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
switch( simType )
|
||||
|
@ -198,7 +209,7 @@ void SIM_PLOT_FRAME::updatePlot( const wxString& aSpiceName, const wxString& aNa
|
|||
int size = data_x.size();
|
||||
|
||||
if( data_x.empty() )
|
||||
return;
|
||||
return false;
|
||||
|
||||
// Now, Y axis data
|
||||
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_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 + " (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:
|
||||
{
|
||||
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 );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
wxASSERT_MSG( false, "Unhandled plot type" );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,12 +31,14 @@
|
|||
|
||||
#include "sim_plot_frame_base.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 <wx/event.h>
|
||||
#include <memory>
|
||||
|
||||
class SCH_EDIT_FRAME;
|
||||
class SPICE_SIMULATOR;
|
||||
class NETLIST_EXPORTER_PSPICE_SIM;
|
||||
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();
|
||||
|
||||
void SetSchFrame( SCH_EDIT_FRAME* aSchFrame )
|
||||
{
|
||||
m_schematicFrame = aSchFrame;
|
||||
}
|
||||
|
||||
void StartSimulation();
|
||||
void StopSimulation();
|
||||
|
||||
|
@ -74,8 +71,10 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
|
|||
* (for NGSPICE it is e.g. "V(1)").
|
||||
* @param aName is the name used in the legend.
|
||||
* @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.
|
||||
|
|
|
@ -36,7 +36,6 @@ void SCH_EDIT_FRAME::OnSimulate( wxCommandEvent& event )
|
|||
simFrame->Iconize( false );
|
||||
|
||||
simFrame->Raise();
|
||||
simFrame->SetSchFrame( this );
|
||||
}
|
||||
|
||||
// I apologize for the following lines, but this is more or less what wxWidgets
|
||||
|
|
Loading…
Reference in New Issue