From 297ab11fe2ad936bbb0d8876526ae134fd96e60f Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Thu, 23 Feb 2023 14:23:31 -0700 Subject: [PATCH 1/3] Don't bail on importing sim data when there is no tag; we can still have summary data --- .../file/openrocket/importt/FlightDataHandler.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/FlightDataHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/FlightDataHandler.java index 6d90c7050..99d819327 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/FlightDataHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/FlightDataHandler.java @@ -92,12 +92,6 @@ class FlightDataHandler extends AbstractElementHandler { public void endHandler(String element, HashMap attributes, String content, WarningSet warnings) { - // If no tag in XML, then there is no sim data - if (dataHandler == null) { - data = null; - return; - } - if (branches.size() > 0) { data = new FlightData(branches.toArray(new FlightDataBranch[0])); } else { @@ -158,4 +152,4 @@ class FlightDataHandler extends AbstractElementHandler { } -} \ No newline at end of file +} From f0621e5790a33a85a0083e10a5d556a2428af8fe Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Thu, 23 Feb 2023 15:15:54 -0700 Subject: [PATCH 2/3] Change simulation file loader so it always marks a simulation as LOADED if it has data, and NOT_SIMULATED if it doesn't. This is more reliable than the status attributed, as that gets saved as notsimulated when only summary data is saved. Also clean up logic in Simulation constructor a bit, --- .../sf/openrocket/document/Simulation.java | 40 +++++-------------- .../importt/SingleSimulationHandler.java | 20 +++++----- 2 files changed, 21 insertions(+), 39 deletions(-) diff --git a/core/src/net/sf/openrocket/document/Simulation.java b/core/src/net/sf/openrocket/document/Simulation.java index a695a1165..75f6cf0b2 100644 --- a/core/src/net/sf/openrocket/document/Simulation.java +++ b/core/src/net/sf/openrocket/document/Simulation.java @@ -146,40 +146,22 @@ public class Simulation implements ChangeSource, Cloneable { if (options == null) throw new IllegalArgumentException("options cannot be null"); - this.document = document; this.rocket = rocket; - - if (status == Status.UPTODATE) { - this.status = Status.LOADED; - } else if (data == null) { - this.status = Status.NOT_SIMULATED; - } else { - this.status = status; - } - this.name = name; - + this.status = status; + this.simulatedConditions = options.clone(); + this.simulatedData = data; + this.document = document; + addChangeListener(this.document); + this.options = options; - + this.options.addChangeListener(new ConditionListener()); + final FlightConfiguration config = rocket.getSelectedConfiguration(); this.setFlightConfigurationId(config.getFlightConfigurationID()); - - options.addChangeListener(new ConditionListener()); - addChangeListener(document); - - if (extensions != null) { - this.simulationExtensions.addAll(extensions); - } - - - if (data != null && this.status != Status.NOT_SIMULATED) { - simulatedData = data; - if (this.status == Status.LOADED) { - simulatedConditions = options.clone(); - simulatedConfigurationID = config.getModID(); - } - } - + this.simulatedConfigurationID = config.getModID(); + + this.simulationExtensions.addAll(extensions); } public FlightConfiguration getActiveConfiguration() { diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/SingleSimulationHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/SingleSimulationHandler.java index 6483e09bc..629d3be25 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/SingleSimulationHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/SingleSimulationHandler.java @@ -109,13 +109,6 @@ class SingleSimulationHandler extends AbstractElementHandler { public void endHandler(String element, HashMap attributes, String content, WarningSet warnings) { - String s = attributes.get("status"); - Simulation.Status status = (Status) DocumentConfig.findEnum(s, Simulation.Status.class); - if (status == null) { - warnings.add("Simulation status unknown, assuming outdated."); - status = Simulation.Status.OUTDATED; - } - SimulationOptions options; FlightConfigurationId idToSet= FlightConfigurationId.ERROR_FCID; if (conditionHandler != null) { @@ -126,16 +119,23 @@ class SingleSimulationHandler extends AbstractElementHandler { options = new SimulationOptions(); } - if (name == null) + if (name == null) name = "Simulation"; + // If the simulation was saved with flight data (which may just be a summary) + // mark it as loaded from the file else as not simulated. We're ignoring the + // simulation status attribute, since (1) it really isn't relevant now, and (2) + // sim summaries are getting marked as not simulated when they're saved FlightData data; if (dataHandler == null) data = null; else data = dataHandler.getFlightData(); - if (data == null) { + Simulation.Status status; + if (data != null) { + status = Status.LOADED; + } else { status = Status.NOT_SIMULATED; } @@ -153,4 +153,4 @@ class SingleSimulationHandler extends AbstractElementHandler { return extension; } -} \ No newline at end of file +} From 9a078f0e689c3400a79c1fead2db93abf0a1d879 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Thu, 23 Feb 2023 15:37:05 -0700 Subject: [PATCH 3/3] Mark simulations loaded from .ork file with blue sphere (same as data from external sources -- do we actually have a way to load data from external sources?) and appropriate tooltip --- core/resources/l10n/messages.properties | 1 + swing/src/net/sf/openrocket/gui/main/SimulationPanel.java | 2 ++ swing/src/net/sf/openrocket/gui/util/Icons.java | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 5a590191d..137fdf3ea 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -551,6 +551,7 @@ simpanel.col.Timetoapogee = Time to apogee simpanel.col.Flighttime = Flight time simpanel.col.Groundhitvelocity = Ground hit velocity simpanel.ttip.uptodate = Up to date +simpanel.ttip.loaded = Loaded from file simpanel.ttip.outdated = Out of date
Click Run simulations to simulate. simpanel.ttip.external = Imported data simpanel.ttip.notSimulated = Not simulated yet
Click Run simulations to simulate. diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index b7fd17732..3c8f45839 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -710,6 +710,8 @@ public class SimulationPanel extends JPanel { tip += trans.get("simpanel.ttip.noData")+"
"; break; case LOADED: + tip += trans.get("simpanel.ttip.loaded") + "
"; + break; case UPTODATE: tip += trans.get("simpanel.ttip.uptodate") + "
"; break; diff --git a/swing/src/net/sf/openrocket/gui/util/Icons.java b/swing/src/net/sf/openrocket/gui/util/Icons.java index 0ebd96ab0..bbbe1b052 100644 --- a/swing/src/net/sf/openrocket/gui/util/Icons.java +++ b/swing/src/net/sf/openrocket/gui/util/Icons.java @@ -33,7 +33,7 @@ public class Icons { map.put(Simulation.Status.NOT_SIMULATED, loadImageIcon("pix/spheres/gray-16x16.png", "Not simulated")); map.put(Simulation.Status.CANT_RUN, loadImageIcon("pix/spheres/yellow-16x16.png", "Can't run, no motors assigned.")); map.put(Simulation.Status.UPTODATE, loadImageIcon("pix/spheres/green-16x16.png", "Up to date")); - map.put(Simulation.Status.LOADED, loadImageIcon("pix/spheres/green-16x16.png", "Up to date")); + map.put(Simulation.Status.LOADED, loadImageIcon("pix/spheres/blue-16x16.png", "Loaded from File")); map.put(Simulation.Status.OUTDATED, loadImageIcon("pix/spheres/red-16x16.png", "Out-of-date")); map.put(Simulation.Status.EXTERNAL, loadImageIcon("pix/spheres/blue-16x16.png", "Imported data")); SIMULATION_STATUS_ICON_MAP = Collections.unmodifiableMap(map);