From 3571ebad68df47bfbe351e8d4ab31835b3213b1e Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Sun, 5 Mar 2023 09:20:18 -0700 Subject: [PATCH] When creating a new sim branch, copy one data point and the separation event to the new branch so we can plot it if it has an immediate exception --- .../BasicEventSimulationEngine.java | 3 ++- .../simulation/FlightDataBranch.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java index 2e8212936..91c76e596 100644 --- a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java +++ b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java @@ -491,7 +491,8 @@ public class BasicEventSimulationEngine implements SimulationEngine { SimulationStatus boosterStatus = new SimulationStatus(currentStatus); // Prepare the new simulation branch - boosterStatus.setFlightData(new FlightDataBranch(boosterStage.getName(), FlightDataType.TYPE_TIME)); + boosterStatus.setFlightData(new FlightDataBranch(boosterStage.getName(), currentStatus.getFlightData())); + boosterStatus.getFlightData().addEvent(event); // Mark the current status as having dropped the current stage and all stages below it currentStatus.getConfiguration().clearStagesBelow( stageNumber); diff --git a/core/src/net/sf/openrocket/simulation/FlightDataBranch.java b/core/src/net/sf/openrocket/simulation/FlightDataBranch.java index c7f71f7fc..77bc60f56 100644 --- a/core/src/net/sf/openrocket/simulation/FlightDataBranch.java +++ b/core/src/net/sf/openrocket/simulation/FlightDataBranch.java @@ -75,6 +75,26 @@ public class FlightDataBranch implements Monitorable { maxValues.put(t, Double.NaN); } } + + /** + * Make a flight data branch with one data point copied from its parent. Intended for use + * when creating a new branch upon stage separation, so the data at separation is present + * in both branches (and if the new branch has an immediate exception, it can be plotted) + */ + public FlightDataBranch(String branchName, FlightDataBranch parent) { + this.branchName = branchName; + + // need to have at least one type to set up values + values.put(FlightDataType.TYPE_TIME, new ArrayList()); + minValues.put(FlightDataType.TYPE_TIME, Double.NaN); + maxValues.put(FlightDataType.TYPE_TIME, Double.NaN); + + // copy all values into new FlightDataBranch + this.addPoint(); + for (FlightDataType t : parent.getTypes()) { + this.setValue(t, parent.getLast(t)); + } + } /** * Makes an 'empty' flight data branch which has no data but all built in data types are defined.