Merge pull request #2070 from JoePfeiffer/fix-2067

Properly load simulation data from saved simulations
This commit is contained in:
Joe Pfeiffer 2023-02-25 17:55:33 -07:00 committed by GitHub
commit 91038c32e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 47 deletions

View File

@ -555,6 +555,7 @@ simpanel.col.Timetoapogee = Time to apogee
simpanel.col.Flighttime = Flight time
simpanel.col.Groundhitvelocity = Ground hit velocity
simpanel.ttip.uptodate = <i>Up to date</i>
simpanel.ttip.loaded = <i>Loaded from file</i>
simpanel.ttip.outdated = <i><font color=\"red\">Out of date</font></i><br>Click <i><b>Run simulations</b></i> to simulate.
simpanel.ttip.external = <i>Imported data</i>
simpanel.ttip.notSimulated = <i>Not simulated yet</i><br>Click <i><b>Run simulations</b></i> to simulate.

View File

@ -146,40 +146,22 @@ public class Simulation implements ChangeSource, Cloneable {
if (options == null)
throw new IllegalArgumentException("options cannot be null");
this.document = document;
this.rocket = rocket;
if (status == Status.UPTODATE) {
this.status = Status.LOADED;
} else if (data == null) {
this.status = Status.NOT_SIMULATED;
} else {
this.status = status;
}
this.name = name;
this.status = status;
this.simulatedConditions = options.clone();
this.simulatedData = data;
this.document = document;
addChangeListener(this.document);
this.options = options;
this.options.addChangeListener(new ConditionListener());
final FlightConfiguration config = rocket.getSelectedConfiguration();
this.setFlightConfigurationId(config.getFlightConfigurationID());
options.addChangeListener(new ConditionListener());
addChangeListener(document);
if (extensions != null) {
this.simulationExtensions.addAll(extensions);
}
if (data != null && this.status != Status.NOT_SIMULATED) {
simulatedData = data;
if (this.status == Status.LOADED) {
simulatedConditions = options.clone();
simulatedConfigurationID = config.getModID();
}
}
this.simulatedConfigurationID = config.getModID();
this.simulationExtensions.addAll(extensions);
}
public FlightConfiguration getActiveConfiguration() {

View File

@ -92,12 +92,6 @@ class FlightDataHandler extends AbstractElementHandler {
public void endHandler(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) {
// If no <databranch> tag in XML, then there is no sim data
if (dataHandler == null) {
data = null;
return;
}
if (branches.size() > 0) {
data = new FlightData(branches.toArray(new FlightDataBranch[0]));
} else {
@ -158,4 +152,4 @@ class FlightDataHandler extends AbstractElementHandler {
}
}
}

View File

@ -109,13 +109,6 @@ 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) {
@ -126,16 +119,23 @@ class SingleSimulationHandler extends AbstractElementHandler {
options = new SimulationOptions();
}
if (name == null)
if (name == null)
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
FlightData data;
if (dataHandler == null)
data = null;
else
data = dataHandler.getFlightData();
if (data == null) {
Simulation.Status status;
if (data != null) {
status = Status.LOADED;
} else {
status = Status.NOT_SIMULATED;
}
@ -153,4 +153,4 @@ class SingleSimulationHandler extends AbstractElementHandler {
return extension;
}
}
}

View File

@ -710,6 +710,8 @@ public class SimulationPanel extends JPanel {
tip += trans.get("simpanel.ttip.noData")+"<br>";
break;
case LOADED:
tip += trans.get("simpanel.ttip.loaded") + "<br>";
break;
case UPTODATE:
tip += trans.get("simpanel.ttip.uptodate") + "<br>";
break;

View File

@ -33,7 +33,7 @@ public class Icons {
map.put(Simulation.Status.NOT_SIMULATED, loadImageIcon("pix/spheres/gray-16x16.png", "Not simulated"));
map.put(Simulation.Status.CANT_RUN, loadImageIcon("pix/spheres/yellow-16x16.png", "Can't run, no motors assigned."));
map.put(Simulation.Status.UPTODATE, loadImageIcon("pix/spheres/green-16x16.png", "Up to date"));
map.put(Simulation.Status.LOADED, loadImageIcon("pix/spheres/green-16x16.png", "Up to date"));
map.put(Simulation.Status.LOADED, loadImageIcon("pix/spheres/blue-16x16.png", "Loaded from File"));
map.put(Simulation.Status.OUTDATED, loadImageIcon("pix/spheres/red-16x16.png", "Out-of-date"));
map.put(Simulation.Status.EXTERNAL, loadImageIcon("pix/spheres/blue-16x16.png", "Imported data"));
SIMULATION_STATUS_ICON_MAP = Collections.unmodifiableMap(map);