Avoid simulator crash if the simulation was not run, when using most of main menu commands, due to a null pointer not tested.

This commit is contained in:
jean-pierre charras 2016-08-12 15:36:43 +02:00
parent 8a8dc5fbbb
commit 6e5628ceaf
1 changed files with 27 additions and 6 deletions

View File

@ -338,6 +338,9 @@ void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName, bool aErase )
{
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
if( !plotPanel )
return;
if( aErase )
{
auto& traceMap = m_plots[plotPanel].m_traces;
@ -645,6 +648,9 @@ void SIM_PLOT_FRAME::menuOpenWorkbook( wxCommandEvent& event )
void SIM_PLOT_FRAME::menuSaveWorkbook( wxCommandEvent& event )
{
if( !CurrentPlot() )
return;
wxFileDialog saveDlg( this, wxT( "Save simulation workbook" ), "", "",
"Workbook file (*.wbk)|*.wbk", wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
@ -658,6 +664,9 @@ void SIM_PLOT_FRAME::menuSaveWorkbook( wxCommandEvent& event )
void SIM_PLOT_FRAME::menuSaveImage( wxCommandEvent& event )
{
if( !CurrentPlot() )
return;
wxFileDialog saveDlg( this, wxT( "Save plot as image" ), "", "",
"PNG file (*.png)|*.png", wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
@ -670,6 +679,9 @@ void SIM_PLOT_FRAME::menuSaveImage( wxCommandEvent& event )
void SIM_PLOT_FRAME::menuSaveCsv( wxCommandEvent& event )
{
if( !CurrentPlot() )
return;
const wxChar SEPARATOR = ';';
wxFileDialog saveDlg( this, wxT( "Save plot data" ), "", "",
@ -710,18 +722,21 @@ void SIM_PLOT_FRAME::menuSaveCsv( wxCommandEvent& event )
void SIM_PLOT_FRAME::menuZoomIn( wxCommandEvent& event )
{
if( CurrentPlot() )
CurrentPlot()->ZoomIn();
}
void SIM_PLOT_FRAME::menuZoomOut( wxCommandEvent& event )
{
if( CurrentPlot() )
CurrentPlot()->ZoomOut();
}
void SIM_PLOT_FRAME::menuZoomFit( wxCommandEvent& event )
{
if( CurrentPlot() )
CurrentPlot()->Fit();
}
@ -729,6 +744,8 @@ void SIM_PLOT_FRAME::menuZoomFit( wxCommandEvent& event )
void SIM_PLOT_FRAME::menuShowGrid( wxCommandEvent& event )
{
SIM_PLOT_PANEL* plot = CurrentPlot();
if( plot )
plot->ShowGrid( !plot->IsGridShown() );
}
@ -736,6 +753,8 @@ void SIM_PLOT_FRAME::menuShowGrid( wxCommandEvent& event )
void SIM_PLOT_FRAME::menuShowGridUpdate( wxUpdateUIEvent& event )
{
SIM_PLOT_PANEL* plot = CurrentPlot();
if( plot )
event.Check( plot ? plot->IsGridShown() : false );
}
@ -743,6 +762,8 @@ void SIM_PLOT_FRAME::menuShowGridUpdate( wxUpdateUIEvent& event )
void SIM_PLOT_FRAME::menuShowLegend( wxCommandEvent& event )
{
SIM_PLOT_PANEL* plot = CurrentPlot();
if( plot )
plot->ShowLegend( !plot->IsLegendShown() );
}