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
|
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 FileType fileType = FileType.OPENROCKET;
|
||||||
|
|
||||||
private double simulationTimeSkip = SIMULATION_DATA_NONE;
|
private boolean saveSimulationData = false;
|
||||||
|
|
||||||
private boolean explicitlySet = false;
|
private boolean explicitlySet = false;
|
||||||
|
|
||||||
@ -26,12 +23,12 @@ public class StorageOptions implements Cloneable {
|
|||||||
this.fileType = fileType;
|
this.fileType = fileType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getSimulationTimeSkip() {
|
public boolean getSaveSimulationData() {
|
||||||
return simulationTimeSkip;
|
return saveSimulationData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSimulationTimeSkip(double simulationTimeSkip) {
|
public void setSaveSimulationData(boolean s) {
|
||||||
this.simulationTimeSkip = simulationTimeSkip;
|
saveSimulationData = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExplicitlySet() {
|
public boolean isExplicitlySet() {
|
||||||
|
@ -97,7 +97,7 @@ public class OpenRocketSaver extends RocketSaver {
|
|||||||
if (!first)
|
if (!first)
|
||||||
writeln("");
|
writeln("");
|
||||||
first = false;
|
first = false;
|
||||||
saveSimulation(s, options.getSimulationTimeSkip());
|
saveSimulation(s, options.getSaveSimulationData());
|
||||||
}
|
}
|
||||||
indent--;
|
indent--;
|
||||||
writeln("</simulations>");
|
writeln("</simulations>");
|
||||||
@ -173,13 +173,12 @@ public class OpenRocketSaver extends RocketSaver {
|
|||||||
|
|
||||||
// Size per flight data point
|
// Size per flight data point
|
||||||
int pointCount = 0;
|
int pointCount = 0;
|
||||||
double timeSkip = options.getSimulationTimeSkip();
|
if (options.getSaveSimulationData()) {
|
||||||
if (timeSkip != StorageOptions.SIMULATION_DATA_NONE) {
|
|
||||||
for (Simulation s : doc.getSimulations()) {
|
for (Simulation s : doc.getSimulations()) {
|
||||||
FlightData data = s.getSimulatedData();
|
FlightData data = s.getSimulatedData();
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
for (int i = 0; i < data.getBranchCount(); i++) {
|
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();
|
SimulationOptions cond = simulation.getOptions();
|
||||||
|
|
||||||
Simulation.Status simStatus;
|
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) + "\">");
|
writeln("<simulation status=\"" + enumToXMLName(simStatus) + "\">");
|
||||||
indent++;
|
indent++;
|
||||||
@ -408,13 +407,11 @@ public class OpenRocketSaver extends RocketSaver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check whether to store data
|
// Check whether to store data
|
||||||
if (simulation.getStatus() == Simulation.Status.EXTERNAL) // Always store external data
|
if ((simulation.getStatus() == Simulation.Status.EXTERNAL) || // Always store external data
|
||||||
timeSkip = 0;
|
saveSimulationData) {
|
||||||
|
|
||||||
if (timeSkip != StorageOptions.SIMULATION_DATA_NONE) {
|
|
||||||
for (int i = 0; i < data.getBranchCount(); i++) {
|
for (int i = 0; i < data.getBranchCount(); i++) {
|
||||||
FlightDataBranch branch = data.getBranch(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 {
|
throws IOException {
|
||||||
double previousTime = -100000;
|
|
||||||
|
|
||||||
if (branch == null)
|
if (branch == null)
|
||||||
return;
|
return;
|
||||||
@ -540,25 +536,8 @@ public class OpenRocketSaver extends RocketSaver {
|
|||||||
|
|
||||||
// Write the data
|
// Write the data
|
||||||
int length = branch.getLength();
|
int length = branch.getLength();
|
||||||
if (length > 0) {
|
for (int i = 0; i < length; i++) {
|
||||||
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);
|
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--;
|
indent--;
|
||||||
@ -566,11 +545,9 @@ public class OpenRocketSaver extends RocketSaver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: LOW: This is largely duplicated from above! */
|
/* TODO: LOW: This is largely duplicated from above! */
|
||||||
private int countFlightDataBranchPoints(FlightDataBranch branch, double timeSkip) {
|
private int countFlightDataBranchPoints(FlightDataBranch branch) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
double previousTime = -100000;
|
|
||||||
|
|
||||||
if (branch == null)
|
if (branch == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -586,23 +563,8 @@ public class OpenRocketSaver extends RocketSaver {
|
|||||||
return branch.getLength();
|
return branch.getLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the data
|
// Count the data
|
||||||
int length = branch.getLength();
|
count += 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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,8 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
|||||||
config.applyPreloadedStageActiveness();
|
config.applyPreloadedStageActiveness();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deduce suitable time skip
|
// If we saved data for a simulation before, we'll use that as our default option this time
|
||||||
double timeSkip = StorageOptions.SIMULATION_DATA_NONE;
|
boolean saveData = false;
|
||||||
for (Simulation s : doc.getSimulations()) {
|
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
|
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 ||
|
if (s.getStatus() == Simulation.Status.EXTERNAL ||
|
||||||
@ -78,15 +78,11 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
|||||||
if (list == null)
|
if (list == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
double previousTime = Double.NaN;
|
doc.getDefaultStorageOptions().setSaveSimulationData(true);
|
||||||
for (double time : list) {
|
break;
|
||||||
if (time - previousTime < timeSkip)
|
|
||||||
timeSkip = time - previousTime;
|
|
||||||
previousTime = time;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
timeSkip = Math.rint(timeSkip * 100) / 100;
|
|
||||||
doc.getDefaultStorageOptions().setSimulationTimeSkip(timeSkip);
|
|
||||||
doc.getDefaultStorageOptions().setExplicitlySet(false);
|
doc.getDefaultStorageOptions().setExplicitlySet(false);
|
||||||
doc.getDefaultStorageOptions().setFileType(FileType.OPENROCKET);
|
doc.getDefaultStorageOptions().setFileType(FileType.OPENROCKET);
|
||||||
|
|
||||||
|
@ -75,34 +75,6 @@ public class StorageOptionChooser extends JPanel {
|
|||||||
allButton.addActionListener(actionUpdater);
|
allButton.addActionListener(actionUpdater);
|
||||||
this.add(allButton, "spanx, wrap rel");
|
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
|
//// Only primary figures
|
||||||
noneButton = new JRadioButton(trans.get("StorageOptChooser.rdbut.Onlyprimfig"));
|
noneButton = new JRadioButton(trans.get("StorageOptChooser.rdbut.Onlyprimfig"));
|
||||||
//// <html>Store only the values shown in the summary table.<br>
|
//// <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) {
|
public void loadOptions(StorageOptions opts) {
|
||||||
double t;
|
|
||||||
|
|
||||||
// Data storage radio button
|
// Data storage radio button
|
||||||
t = opts.getSimulationTimeSkip();
|
if (opts.getSaveSimulationData()) {
|
||||||
if (t == StorageOptions.SIMULATION_DATA_ALL) {
|
|
||||||
allButton.setSelected(true);
|
allButton.setSelected(true);
|
||||||
t = DEFAULT_SAVE_TIME_SKIP;
|
|
||||||
} else if (t == StorageOptions.SIMULATION_DATA_NONE) {
|
|
||||||
noneButton.setSelected(true);
|
|
||||||
t = DEFAULT_SAVE_TIME_SKIP;
|
|
||||||
} else {
|
} else {
|
||||||
someButton.setSelected(true);
|
noneButton.setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Time skip spinner
|
|
||||||
artificialEvent = true;
|
|
||||||
timeSpinner.setValue(t);
|
|
||||||
artificialEvent = false;
|
|
||||||
|
|
||||||
updateInfoLabel();
|
updateInfoLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void storeOptions(StorageOptions opts) {
|
public void storeOptions(StorageOptions opts) {
|
||||||
double t;
|
opts.setSaveSimulationData(allButton.isSelected());
|
||||||
|
|
||||||
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.setExplicitlySet(true);
|
opts.setExplicitlySet(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class RockSimConverter {
|
|||||||
try {
|
try {
|
||||||
StorageOptions opts = new StorageOptions();
|
StorageOptions opts = new StorageOptions();
|
||||||
opts.setFileType(StorageOptions.FileType.OPENROCKET);
|
opts.setFileType(StorageOptions.FileType.OPENROCKET);
|
||||||
opts.setSimulationTimeSkip(StorageOptions.SIMULATION_DATA_NONE);
|
opts.setSaveSimulationData(false);
|
||||||
opts.setExplicitlySet(true);
|
opts.setExplicitlySet(true);
|
||||||
|
|
||||||
GeneralRocketLoader loader = new GeneralRocketLoader(input);
|
GeneralRocketLoader loader = new GeneralRocketLoader(input);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user