From 843c2e6d227df2e29ef9657db00faed42979cd0b Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Tue, 9 Jan 2024 17:36:44 -0700 Subject: [PATCH] Only show error checkbox if there are errors --- .../sf/openrocket/document/Simulation.java | 16 +++++++++++++- .../gui/plot/SimulationPlotDialog.java | 22 ++++++++++--------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/core/src/net/sf/openrocket/document/Simulation.java b/core/src/net/sf/openrocket/document/Simulation.java index 0eacf4795..da87ff5a8 100644 --- a/core/src/net/sf/openrocket/document/Simulation.java +++ b/core/src/net/sf/openrocket/document/Simulation.java @@ -19,6 +19,7 @@ import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.simulation.BasicEventSimulationEngine; import net.sf.openrocket.simulation.DefaultSimulationOptionFactory; import net.sf.openrocket.simulation.FlightData; +import net.sf.openrocket.simulation.FlightEvent; import net.sf.openrocket.simulation.RK4SimulationStepper; import net.sf.openrocket.simulation.SimulationConditions; import net.sf.openrocket.simulation.SimulationEngine; @@ -349,7 +350,20 @@ public class Simulation implements ChangeSource, Cloneable { } /** - * Returns true is the status indicates that the simulation data is up-to-date. + * Determines whether the simulation has errors + */ + public boolean hasErrors() { + FlightData data = getSimulatedData(); + for (int branchNo = 0; branchNo < data.getBranchCount(); branchNo++) { + if (data.getBranch(branchNo).getFirstEvent(FlightEvent.Type.SIM_ABORT) != null) { + return true; + } + } + return false; + } + + /** + * Returns true if the status indicates that the simulation data is up-to-date. * @param status status of the simulation to check for if its data is up-to-date */ public static boolean isStatusUpToDate(Status status) { diff --git a/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java b/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java index 52ca5f144..9914c3901 100644 --- a/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java +++ b/swing/src/net/sf/openrocket/gui/plot/SimulationPlotDialog.java @@ -98,17 +98,19 @@ public class SimulationPlotDialog extends JDialog { }); panel.add(checkData, "split, left"); - //// Show errors + //// Show errors if any //// ALWAYS show errors initially; make user turn it off for themselves - final JCheckBox checkErrors = new JCheckBox(trans.get("PlotDialog.CheckBox.ShowErrors")); - checkErrors.setSelected(true); - checkErrors.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - myPlot.setShowErrors(checkErrors.isSelected()); - } - }); - panel.add(checkErrors, "split, left"); + if (simulation.hasErrors()) { + final JCheckBox checkErrors = new JCheckBox(trans.get("PlotDialog.CheckBox.ShowErrors")); + checkErrors.setSelected(true); + checkErrors.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + myPlot.setShowErrors(checkErrors.isSelected()); + } + }); + panel.add(checkErrors, "split, left"); + } //// Add series selection box ArrayList stages = new ArrayList();