Merge pull request #2097 from JoePfeiffer/2078-typo
Fix error in sim loading, add unit test, refine loading a bit.
This commit is contained in:
commit
5e9cbe2706
@ -61,7 +61,7 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
||||
}
|
||||
|
||||
// If we saved data for a simulation before, we'll use that as our default option this time
|
||||
boolean saveData = false;
|
||||
// Also, updaet all the sims' modIDs to agree with flight config
|
||||
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 ||
|
||||
@ -79,8 +79,6 @@ public class OpenRocketLoader extends AbstractRocketLoader {
|
||||
continue;
|
||||
|
||||
doc.getDefaultStorageOptions().setSaveSimulationData(true);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
doc.getDefaultStorageOptions().setExplicitlySet(false);
|
||||
|
@ -109,6 +109,13 @@ class SingleSimulationHandler extends AbstractElementHandler {
|
||||
public void endHandler(String element, HashMap<String, String> 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) {
|
||||
@ -123,20 +130,19 @@ class SingleSimulationHandler extends AbstractElementHandler {
|
||||
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
|
||||
// mark it as loaded from the file else as not simulated. If outdated data was saved,
|
||||
// it'll be marked as outdated (creating a new status for "loaded but outdated" seems
|
||||
// excessive, and the fact that it's outdated is the more important)
|
||||
FlightData data;
|
||||
if (dataHandler == null)
|
||||
data = null;
|
||||
else
|
||||
data = dataHandler.getFlightData();
|
||||
|
||||
Simulation.Status status;
|
||||
if (data != null) {
|
||||
status = Status.LOADED;
|
||||
} else {
|
||||
if (data == null) {
|
||||
status = Status.NOT_SIMULATED;
|
||||
} else if (status != Status.OUTDATED) {
|
||||
status = Status.LOADED;
|
||||
}
|
||||
|
||||
Simulation simulation = new Simulation(doc, doc.getRocket(), status, name,
|
||||
|
@ -22,6 +22,7 @@ import net.sf.openrocket.database.motor.MotorDatabase;
|
||||
import net.sf.openrocket.database.motor.ThrustCurveMotorSetDatabase;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.OpenRocketDocumentFactory;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.document.StorageOptions;
|
||||
import net.sf.openrocket.file.GeneralRocketLoader;
|
||||
import net.sf.openrocket.file.RocketLoadException;
|
||||
@ -264,7 +265,64 @@ public class OpenRocketSaverTest {
|
||||
|
||||
// TODO: fix estimateFileSize so that it's a lot more accurate
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test sim status with/without sim data in file.
|
||||
*/
|
||||
@Test
|
||||
public void TestSimStatus() {
|
||||
Rocket rocket = TestRockets.makeEstesAlphaIII();
|
||||
OpenRocketDocument rocketDoc = OpenRocketDocumentFactory.createDocumentFromRocket(rocket);
|
||||
|
||||
// Hook up some simulations.
|
||||
// First sim will not have options set
|
||||
Simulation sim1 = new Simulation(rocket);
|
||||
rocketDoc.addSimulation(sim1);
|
||||
|
||||
// Second sim has options, but hasn't been simulated
|
||||
Simulation sim2 = new Simulation(rocket);
|
||||
sim2.getOptions().setISAAtmosphere(true);
|
||||
sim2.getOptions().setTimeStep(0.05);
|
||||
sim2.setFlightConfigurationId(TestRockets.TEST_FCID_0);
|
||||
rocketDoc.addSimulation(sim2);
|
||||
|
||||
// Third sim has been executed
|
||||
Simulation sim3 = new Simulation(rocket);
|
||||
sim3.getOptions().setISAAtmosphere(true);
|
||||
sim3.getOptions().setTimeStep(0.05);
|
||||
sim3.setFlightConfigurationId(TestRockets.TEST_FCID_0);
|
||||
try {
|
||||
sim3.simulate();
|
||||
} catch (Exception e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
rocketDoc.addSimulation(sim3);
|
||||
|
||||
// Fourth sim has been executed, then configuration changed
|
||||
Simulation sim4 = new Simulation(rocket);
|
||||
sim4.getOptions().setISAAtmosphere(true);
|
||||
sim4.getOptions().setTimeStep(0.05);
|
||||
sim4.setFlightConfigurationId(TestRockets.TEST_FCID_0);
|
||||
try {
|
||||
sim4.simulate();
|
||||
} catch (Exception e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
sim4.getOptions().setTimeStep(0.1);
|
||||
rocketDoc.addSimulation(sim4);
|
||||
|
||||
// save, then load document
|
||||
StorageOptions options = new StorageOptions();
|
||||
options.setSaveSimulationData(true);
|
||||
|
||||
File file = saveRocket(rocketDoc, options);
|
||||
OpenRocketDocument rocketDocLoaded = loadRocket(file.getPath());
|
||||
|
||||
assertEquals(Simulation.Status.CANT_RUN, rocketDocLoaded.getSimulations().get(0).getStatus());
|
||||
assertEquals(Simulation.Status.NOT_SIMULATED, rocketDocLoaded.getSimulations().get(1).getStatus());
|
||||
assertEquals(Simulation.Status.LOADED, rocketDocLoaded.getSimulations().get(2).getStatus());
|
||||
assertEquals(Simulation.Status.OUTDATED, rocketDocLoaded.getSimulations().get(3).getStatus());
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Tests for File Version 1.7 //
|
||||
@ -276,7 +334,8 @@ public class OpenRocketSaverTest {
|
||||
assertEquals(108, getCalculatedFileVersion(rocketDoc));
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
/*
|
||||
* Utility Functions
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user