Eliminate option of saving a subset of simulation data. Choices are to save all or nothing
This commit is contained in:
parent
d67f7aa94d
commit
ffcbc7cf60
@ -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() {
|
||||
|
@ -97,7 +97,7 @@ public class OpenRocketSaver extends RocketSaver {
|
||||
if (!first)
|
||||
writeln("");
|
||||
first = false;
|
||||
saveSimulation(s, options.getSimulationTimeSkip());
|
||||
saveSimulation(s, options.getSaveSimulationData());
|
||||
}
|
||||
indent--;
|
||||
writeln("</simulations>");
|
||||
@ -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("<simulation status=\"" + enumToXMLName(simStatus) + "\">");
|
||||
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)) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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 ||
|
||||
@ -78,15 +78,11 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
||||
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);
|
||||
|
||||
|
@ -75,34 +75,6 @@ public class StorageOptionChooser extends JPanel {
|
||||
allButton.addActionListener(actionUpdater);
|
||||
this.add(allButton, "spanx, wrap rel");
|
||||
|
||||
//// Every
|
||||
someButton = new JRadioButton(trans.get("StorageOptChooser.rdbut.Every"));
|
||||
//// <html>Store plottable values approximately this far apart.<br>"
|
||||
//// 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"));
|
||||
//// <html>Store only the values shown in the summary table.<br>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user