From df675f5366d8090773690dd85b5cc6ec770c4663 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Sun, 13 Nov 2022 15:57:33 -0700 Subject: [PATCH] Provide user with warning when a simulation branch contains no data Also, add a method to WarningSet making it easy to add a "discriminator" to warnings, informing the user what in a design or simulation is causing the warning. --- core/resources/l10n/messages.properties | 1 + core/src/net/sf/openrocket/aerodynamics/Warning.java | 3 ++- .../net/sf/openrocket/aerodynamics/WarningSet.java | 12 +++++++++++- .../simulation/BasicEventSimulationEngine.java | 6 ++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index c5929d0bb..7409e4c38 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1835,6 +1835,7 @@ Warning.ZERO_LENGTH_BODY = Zero length bodies may not result in accurate simulat Warning.ZERO_RADIUS_BODY = Zero length bodies may not result in accurate simulations. Warning.TUBE_SEPARATION = Space between tube fins may not result in accurate simulations. Warning.TUBE_OVERLAP = Overlapping tube fins may not result in accurate simulations. +Warning.EMPTY_BRANCH = Simulation branch contains no data Warning.SEPARATION_ORDER = Stages separated in an unreasonable order ! Scale dialog diff --git a/core/src/net/sf/openrocket/aerodynamics/Warning.java b/core/src/net/sf/openrocket/aerodynamics/Warning.java index 803073948..ae7c94e35 100644 --- a/core/src/net/sf/openrocket/aerodynamics/Warning.java +++ b/core/src/net/sf/openrocket/aerodynamics/Warning.java @@ -18,7 +18,6 @@ public abstract class Warning { return new Warning.Other(text); } - /** * Return true if the other warning should replace * this warning. The method should return true if the other @@ -398,4 +397,6 @@ public abstract class Warning { public static final Warning TUBE_OVERLAP = new Other(trans.get("Warning.TUBE_OVERLAP")); public static final Warning SEPARATION_ORDER = new Other(trans.get("Warning.SEPARATION_ORDER")); + + public static final Warning EMPTY_BRANCH = new Other(trans.get("Warning.EMPTY_BRANCH")); } diff --git a/core/src/net/sf/openrocket/aerodynamics/WarningSet.java b/core/src/net/sf/openrocket/aerodynamics/WarningSet.java index 4873976f3..6f709e83b 100644 --- a/core/src/net/sf/openrocket/aerodynamics/WarningSet.java +++ b/core/src/net/sf/openrocket/aerodynamics/WarningSet.java @@ -67,7 +67,17 @@ public class WarningSet extends AbstractSet implements Cloneable, Monit mutable.check(); return add(Warning.fromString(s)); } - + + /** + * Add a Warning of the specified type with the specified discriminator to the + * set. + * @param w the warning + * @param d the extra discriminator + * + */ + public boolean add (Warning w, String d) { + return this.add(w.toString() + ": " + d); + } @Override public Iterator iterator() { diff --git a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java index 339c0704b..d3d61b829 100644 --- a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java +++ b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java @@ -97,6 +97,12 @@ public class BasicEventSimulationEngine implements SimulationEngine { dataBranch.getBranchName(), currentStatus.getSimulationTime(), dataBranch.getLast(FlightDataType.TYPE_TIME))); + + + // Did the branch generate any data? + if (dataBranch.getLength() == 0) { + flightData.getWarningSet().add(Warning.EMPTY_BRANCH, dataBranch.getBranchName()); + } }while( ! toSimulate.isEmpty()); SimulationListenerHelper.fireEndSimulation(currentStatus, null);