Persist per-motor configuration of ignition specification in ork file.
This commit is contained in:
parent
25f619aa19
commit
fb78952bc0
@ -1026,6 +1026,9 @@ class MotorMountHandler extends AbstractElementHandler {
|
||||
Motor motor = motorHandler.getMotor(warnings);
|
||||
mount.setMotor(id, motor);
|
||||
mount.setMotorDelay(id, motorHandler.getDelay(warnings));
|
||||
MotorConfiguration motorConfig = mount.getFlightConfiguration(id);
|
||||
motorConfig.setIgnitionEvent( motorHandler.getIgnitionEvent());
|
||||
motorConfig.setIgnitionDelay( motorHandler.getIgnitionDelay());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1148,6 +1151,9 @@ class MotorHandler extends AbstractElementHandler {
|
||||
private double length = Double.NaN;
|
||||
private double delay = Double.NaN;
|
||||
|
||||
private Double ignitionDelay = null;
|
||||
private MotorConfiguration.IgnitionEvent ignitionEvent = null;
|
||||
|
||||
public MotorHandler(DocumentLoadingContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
@ -1178,7 +1184,14 @@ class MotorHandler extends AbstractElementHandler {
|
||||
return delay;
|
||||
}
|
||||
|
||||
|
||||
public Double getIgnitionDelay() {
|
||||
return ignitionDelay;
|
||||
}
|
||||
|
||||
public MotorConfiguration.IgnitionEvent getIgnitionEvent() {
|
||||
return ignitionEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeElement(String element, HashMap<String, String> attributes,
|
||||
String content, WarningSet warnings) throws SAXException {
|
||||
@ -1260,6 +1273,24 @@ class MotorHandler extends AbstractElementHandler {
|
||||
|
||||
}
|
||||
|
||||
} else if ( element.equals("ignitionevent")) {
|
||||
|
||||
for (MotorConfiguration.IgnitionEvent e : MotorConfiguration.IgnitionEvent.values()) {
|
||||
if (e.name().toLowerCase(Locale.ENGLISH).replaceAll("_", "").equals(content)) {
|
||||
ignitionEvent = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ignitionEvent == null) {
|
||||
warnings.add(Warning.fromString("Unknown ignition event type '" + content + "', ignoring."));
|
||||
}
|
||||
|
||||
} else if ( element.equals("ignitiondelay")) {
|
||||
try {
|
||||
ignitionDelay = Double.parseDouble(content);
|
||||
} catch (NumberFormatException nfe) {
|
||||
warnings.add(Warning.fromString("Illegal ignition delay specified, ignoring."));
|
||||
}
|
||||
} else {
|
||||
super.closeElement(element, attributes, content, warnings);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import net.sf.openrocket.motor.Motor;
|
||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||
import net.sf.openrocket.preset.ComponentPreset;
|
||||
import net.sf.openrocket.rocketcomponent.ComponentAssembly;
|
||||
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
|
||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||
@ -127,8 +128,11 @@ public class RocketComponentSaver {
|
||||
elements.add("<motormount>");
|
||||
|
||||
for (String id : motorConfigIDs) {
|
||||
Motor motor = mount.getMotor(id);
|
||||
|
||||
MotorConfiguration motorConfig = mount.getFlightConfiguration(id);
|
||||
if ( motorConfig == null ) {
|
||||
continue;
|
||||
}
|
||||
Motor motor = motorConfig.getMotor();
|
||||
// Nothing is stored if no motor loaded
|
||||
if (motor == null)
|
||||
continue;
|
||||
@ -148,10 +152,17 @@ public class RocketComponentSaver {
|
||||
elements.add(" <length>" + motor.getLength() + "</length>");
|
||||
|
||||
// Motor delay
|
||||
if (mount.getMotorDelay(id) == Motor.PLUGGED) {
|
||||
if (motorConfig.getEjectionDelay() == Motor.PLUGGED) {
|
||||
elements.add(" <delay>none</delay>");
|
||||
} else {
|
||||
elements.add(" <delay>" + mount.getMotorDelay(id) + "</delay>");
|
||||
elements.add(" <delay>" + motorConfig.getEjectionDelay() + "</delay>");
|
||||
}
|
||||
|
||||
if ( motorConfig.getIgnitionEvent() != null ) {
|
||||
elements.add(" <ignitionevent>" + motorConfig.getIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + "</ignitionevent>");
|
||||
}
|
||||
if ( motorConfig.getIgnitionDelay() != null ) {
|
||||
elements.add(" <ignitiondelay>" + motorConfig.getIgnitionDelay() + "</ignitiondelay>");
|
||||
}
|
||||
|
||||
elements.add(" </motor>");
|
||||
|
Loading…
x
Reference in New Issue
Block a user