From ffcbc7cf60d6bf186b0ed23ce3e7345f3f814ea8 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Wed, 22 Feb 2023 09:48:21 -0700 Subject: [PATCH] Eliminate option of saving a subset of simulation data. Choices are to save all or nothing --- .../openrocket/document/StorageOptions.java | 13 ++-- .../file/openrocket/OpenRocketSaver.java | 66 ++++--------------- .../openrocket/importt/OpenRocketLoader.java | 18 ++--- .../gui/main/StorageOptionChooser.java | 58 ++-------------- .../sf/openrocket/utils/RockSimConverter.java | 2 +- 5 files changed, 31 insertions(+), 126 deletions(-) diff --git a/core/src/net/sf/openrocket/document/StorageOptions.java b/core/src/net/sf/openrocket/document/StorageOptions.java index 4618aa5d2..f1b56f2f7 100644 --- a/core/src/net/sf/openrocket/document/StorageOptions.java +++ b/core/src/net/sf/openrocket/document/StorageOptions.java @@ -9,12 +9,9 @@ public class StorageOptions implements Cloneable { ROCKSIM } - public static final double SIMULATION_DATA_NONE = Double.POSITIVE_INFINITY; - public static final double SIMULATION_DATA_ALL = 0; - private FileType fileType = FileType.OPENROCKET; - private double simulationTimeSkip = SIMULATION_DATA_NONE; + private boolean saveSimulationData = false; private boolean explicitlySet = false; @@ -26,12 +23,12 @@ public class StorageOptions implements Cloneable { this.fileType = fileType; } - public double getSimulationTimeSkip() { - return simulationTimeSkip; + public boolean getSaveSimulationData() { + return saveSimulationData; } - public void setSimulationTimeSkip(double simulationTimeSkip) { - this.simulationTimeSkip = simulationTimeSkip; + public void setSaveSimulationData(boolean s) { + saveSimulationData = s; } public boolean isExplicitlySet() { diff --git a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java index a330a497d..3e9c82389 100644 --- a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java @@ -97,7 +97,7 @@ public class OpenRocketSaver extends RocketSaver { if (!first) writeln(""); first = false; - saveSimulation(s, options.getSimulationTimeSkip()); + saveSimulation(s, options.getSaveSimulationData()); } indent--; writeln(""); @@ -173,13 +173,12 @@ public class OpenRocketSaver extends RocketSaver { // Size per flight data point int pointCount = 0; - double timeSkip = options.getSimulationTimeSkip(); - if (timeSkip != StorageOptions.SIMULATION_DATA_NONE) { + if (options.getSaveSimulationData()) { for (Simulation s : doc.getSimulations()) { FlightData data = s.getSimulatedData(); if (data != null) { for (int i = 0; i < data.getBranchCount(); i++) { - pointCount += countFlightDataBranchPoints(data.getBranch(i), timeSkip); + pointCount += countFlightDataBranchPoints(data.getBranch(i)); } } } @@ -317,11 +316,11 @@ public class OpenRocketSaver extends RocketSaver { } - private void saveSimulation(Simulation simulation, double timeSkip) throws IOException { + private void saveSimulation(Simulation simulation, boolean saveSimulationData) throws IOException { SimulationOptions cond = simulation.getOptions(); Simulation.Status simStatus; - simStatus = timeSkip != StorageOptions.SIMULATION_DATA_NONE ? simulation.getStatus() : Simulation.Status.NOT_SIMULATED; + simStatus = saveSimulationData ? simulation.getStatus() : Simulation.Status.NOT_SIMULATED; writeln(""); indent++; @@ -408,13 +407,11 @@ public class OpenRocketSaver extends RocketSaver { } // Check whether to store data - if (simulation.getStatus() == Simulation.Status.EXTERNAL) // Always store external data - timeSkip = 0; - - if (timeSkip != StorageOptions.SIMULATION_DATA_NONE) { + if ((simulation.getStatus() == Simulation.Status.EXTERNAL) || // Always store external data + saveSimulationData) { for (int i = 0; i < data.getBranchCount(); i++) { FlightDataBranch branch = data.getBranch(i); - saveFlightDataBranch(branch, timeSkip); + saveFlightDataBranch(branch); } } @@ -474,9 +471,8 @@ public class OpenRocketSaver extends RocketSaver { } } - private void saveFlightDataBranch(FlightDataBranch branch, double timeSkip) + private void saveFlightDataBranch(FlightDataBranch branch) throws IOException { - double previousTime = -100000; if (branch == null) return; @@ -540,25 +536,8 @@ public class OpenRocketSaver extends RocketSaver { // Write the data int length = branch.getLength(); - if (length > 0) { - writeDataPointString(data, 0, sb); - previousTime = timeData.get(0); - } - - for (int i = 1; i < length - 1; i++) { - if (timeData != null) { - if (Math.abs(timeData.get(i) - previousTime - timeSkip) < Math.abs(timeData.get(i + 1) - previousTime - timeSkip)) { - writeDataPointString(data, i, sb); - previousTime = timeData.get(i); - } - } else { - // If time data is not available, write all points - writeDataPointString(data, i, sb); - } - } - - if (length > 1) { - writeDataPointString(data, length - 1, sb); + for (int i = 0; i < length; i++) { + writeDataPointString(data, i, sb); } indent--; @@ -566,11 +545,9 @@ public class OpenRocketSaver extends RocketSaver { } /* TODO: LOW: This is largely duplicated from above! */ - private int countFlightDataBranchPoints(FlightDataBranch branch, double timeSkip) { + private int countFlightDataBranchPoints(FlightDataBranch branch) { int count = 0; - double previousTime = -100000; - if (branch == null) return 0; @@ -586,23 +563,8 @@ public class OpenRocketSaver extends RocketSaver { return branch.getLength(); } - // Write the data - int length = branch.getLength(); - if (length > 0) { - count++; - previousTime = timeData.get(0); - } - - for (int i = 1; i < length - 1; i++) { - if (Math.abs(timeData.get(i) - previousTime - timeSkip) < Math.abs(timeData.get(i + 1) - previousTime - timeSkip)) { - count++; - previousTime = timeData.get(i); - } - } - - if (length > 1) { - count++; - } + // Count the data + count += branch.getLength(); return count; } diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java index e0bf4717b..d1a8e82c8 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java @@ -60,8 +60,8 @@ public class OpenRocketLoader extends AbstractRocketLoader { config.applyPreloadedStageActiveness(); } - // Deduce suitable time skip - double timeSkip = StorageOptions.SIMULATION_DATA_NONE; + // If we saved data for a simulation before, we'll use that as our default option this time + boolean saveData = false; for (Simulation s : doc.getSimulations()) { s.syncModID(); // The config's modID can be out of sync with the simulation's after the whole loading process if (s.getStatus() == Simulation.Status.EXTERNAL || @@ -77,16 +77,12 @@ public class OpenRocketLoader extends AbstractRocketLoader { List list = branch.get(FlightDataType.TYPE_TIME); if (list == null) continue; - - double previousTime = Double.NaN; - for (double time : list) { - if (time - previousTime < timeSkip) - timeSkip = time - previousTime; - previousTime = time; - } + + doc.getDefaultStorageOptions().setSaveSimulationData(true); + break; + } - timeSkip = Math.rint(timeSkip * 100) / 100; - doc.getDefaultStorageOptions().setSimulationTimeSkip(timeSkip); + doc.getDefaultStorageOptions().setExplicitlySet(false); doc.getDefaultStorageOptions().setFileType(FileType.OPENROCKET); diff --git a/swing/src/net/sf/openrocket/gui/main/StorageOptionChooser.java b/swing/src/net/sf/openrocket/gui/main/StorageOptionChooser.java index 5bc056c71..c8a2552e5 100644 --- a/swing/src/net/sf/openrocket/gui/main/StorageOptionChooser.java +++ b/swing/src/net/sf/openrocket/gui/main/StorageOptionChooser.java @@ -74,35 +74,7 @@ public class StorageOptionChooser extends JPanel { buttonGroup.add(allButton); allButton.addActionListener(actionUpdater); this.add(allButton, "spanx, wrap rel"); - - //// Every - someButton = new JRadioButton(trans.get("StorageOptChooser.rdbut.Every")); - //// Store plottable values approximately this far apart.
" - //// Larger values result in smaller files. - tip = trans.get("StorageOptChooser.lbl.longB1") + - trans.get("StorageOptChooser.lbl.longB2"); - someButton.setToolTipText(tip); - buttonGroup.add(someButton); - someButton.addActionListener(actionUpdater); - this.add(someButton, ""); - - timeSpinner = new JSpinner(new SpinnerNumberModel(0.0, 0.0, 5.0, 0.1)); - timeSpinner.setToolTipText(tip); - timeSpinner.addChangeListener(new ChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - if (artificialEvent) - return; - someButton.setSelected(true); - } - }); - this.add(timeSpinner, "wmin 55lp"); - - //// seconds - JLabel label = new JLabel(trans.get("StorageOptChooser.lbl.seconds")); - label.setToolTipText(tip); - this.add(label, "wrap rel"); - + //// Only primary figures noneButton = new JRadioButton(trans.get("StorageOptChooser.rdbut.Onlyprimfig")); //// Store only the values shown in the summary table.
@@ -129,42 +101,20 @@ public class StorageOptionChooser extends JPanel { public void loadOptions(StorageOptions opts) { - double t; // Data storage radio button - t = opts.getSimulationTimeSkip(); - if (t == StorageOptions.SIMULATION_DATA_ALL) { + if (opts.getSaveSimulationData()) { allButton.setSelected(true); - t = DEFAULT_SAVE_TIME_SKIP; - } else if (t == StorageOptions.SIMULATION_DATA_NONE) { - noneButton.setSelected(true); - t = DEFAULT_SAVE_TIME_SKIP; } else { - someButton.setSelected(true); + noneButton.setSelected(true); } - // Time skip spinner - artificialEvent = true; - timeSpinner.setValue(t); - artificialEvent = false; - updateInfoLabel(); } public void storeOptions(StorageOptions opts) { - double t; - - if (allButton.isSelected()) { - t = StorageOptions.SIMULATION_DATA_ALL; - } else if (noneButton.isSelected()) { - t = StorageOptions.SIMULATION_DATA_NONE; - } else { - t = (Double)timeSpinner.getValue(); - } - - opts.setSimulationTimeSkip(t); - + opts.setSaveSimulationData(allButton.isSelected()); opts.setExplicitlySet(true); } diff --git a/swing/src/net/sf/openrocket/utils/RockSimConverter.java b/swing/src/net/sf/openrocket/utils/RockSimConverter.java index 1f1b35d3f..f1ebf1464 100644 --- a/swing/src/net/sf/openrocket/utils/RockSimConverter.java +++ b/swing/src/net/sf/openrocket/utils/RockSimConverter.java @@ -55,7 +55,7 @@ public class RockSimConverter { try { StorageOptions opts = new StorageOptions(); opts.setFileType(StorageOptions.FileType.OPENROCKET); - opts.setSimulationTimeSkip(StorageOptions.SIMULATION_DATA_NONE); + opts.setSaveSimulationData(false); opts.setExplicitlySet(true); GeneralRocketLoader loader = new GeneralRocketLoader(input);