import net.sf.openrocket.database.Databases;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
-import net.sf.openrocket.document.StorageOptions;
import net.sf.openrocket.document.Simulation.Status;
+import net.sf.openrocket.document.StorageOptions;
import net.sf.openrocket.file.RocketLoadException;
import net.sf.openrocket.file.RocketLoader;
import net.sf.openrocket.file.simplesax.ElementHandler;
import net.sf.openrocket.file.simplesax.PlainTextHandler;
import net.sf.openrocket.file.simplesax.SimpleSAX;
+import net.sf.openrocket.logging.LogHelper;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Motor;
+import net.sf.openrocket.motor.MotorDigest;
+import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.rocketcomponent.BodyComponent;
import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.Bulkhead;
import net.sf.openrocket.rocketcomponent.EllipticalFinSet;
import net.sf.openrocket.rocketcomponent.EngineBlock;
import net.sf.openrocket.rocketcomponent.ExternalComponent;
+import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
import net.sf.openrocket.rocketcomponent.FinSet;
+import net.sf.openrocket.rocketcomponent.FinSet.TabRelativePosition;
import net.sf.openrocket.rocketcomponent.FreeformFinSet;
import net.sf.openrocket.rocketcomponent.IllegalFinPointException;
import net.sf.openrocket.rocketcomponent.InnerTube;
import net.sf.openrocket.rocketcomponent.RingComponent;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
+import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
import net.sf.openrocket.rocketcomponent.ShockCord;
import net.sf.openrocket.rocketcomponent.Stage;
import net.sf.openrocket.rocketcomponent.Streamer;
import net.sf.openrocket.rocketcomponent.Transition;
import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
import net.sf.openrocket.rocketcomponent.TubeCoupler;
-import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
-import net.sf.openrocket.rocketcomponent.FinSet.TabRelativePosition;
-import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
import net.sf.openrocket.simulation.FlightData;
import net.sf.openrocket.simulation.FlightDataBranch;
import net.sf.openrocket.simulation.FlightDataType;
import net.sf.openrocket.simulation.FlightEvent;
-import net.sf.openrocket.simulation.GUISimulationConditions;
import net.sf.openrocket.simulation.FlightEvent.Type;
+import net.sf.openrocket.simulation.GUISimulationConditions;
+import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate;
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
-
public class OpenRocketLoader extends RocketLoader {
+ private static final LogHelper log = Application.getLogger();
+
@Override
public OpenRocketDocument loadFromStream(InputStream source) throws RocketLoadException,
IOException {
+ log.info("Loading .ork file");
+
InputSource xmlSource = new InputSource(source);
OpenRocketHandler handler = new OpenRocketHandler();
try {
SimpleSAX.readXML(xmlSource, handler, warnings);
} catch (SAXException e) {
+ log.warn("Malformed XML in input");
throw new RocketLoadException("Malformed XML in input.", e);
}
doc.getDefaultStorageOptions().setExplicitlySet(false);
doc.clearUndo();
+ log.info("Loading done");
return doc;
}
class DocumentConfig {
/* Remember to update OpenRocketSaver as well! */
- public static final String[] SUPPORTED_VERSIONS = { "0.9", "1.0", "1.1" };
+ public static final String[] SUPPORTED_VERSIONS = { "0.9", "1.0", "1.1", "1.2" };
//////// Component constructors
// BodyTube
setters.put("BodyTube:radius", new DoubleSetter(
- Reflection.findMethodStatic(BodyTube.class, "setRadius", double.class),
+ Reflection.findMethodStatic(BodyTube.class, "setOuterRadius", double.class),
"auto",
- Reflection.findMethodStatic(BodyTube.class, "setRadiusAutomatic", boolean.class)));
+ Reflection.findMethodStatic(BodyTube.class, "setOuterRadiusAutomatic", boolean.class)));
// Transition
setters.put("Transition:shape", new EnumSetter<Transition.Shape>(
// LaunchLug
setters.put("LaunchLug:radius", new DoubleSetter(
- Reflection.findMethodStatic(LaunchLug.class, "setRadius", double.class)));
+ Reflection.findMethodStatic(LaunchLug.class, "setOuterRadius", double.class)));
setters.put("LaunchLug:length", new DoubleSetter(
Reflection.findMethodStatic(LaunchLug.class, "setLength", double.class)));
setters.put("LaunchLug:thickness", new DoubleSetter(
Setter s = DocumentConfig.setters.get(setterKey);
if (s != null) {
// Setter found
- System.out.println("Calling with key " + setterKey);
s.set(component, content, attributes, warnings);
break;
}
private Motor.Type type = null;
private String manufacturer = null;
private String designation = null;
+ private String digest = null;
private double diameter = Double.NaN;
private double length = Double.NaN;
private double delay = Double.NaN;
warnings.add(Warning.fromString("No motor specified, ignoring."));
return null;
}
- Motor[] motors = Databases.findMotors(type, manufacturer, designation, diameter, length);
- if (motors.length == 0) {
+
+ List<ThrustCurveMotor> motors = Application.getMotorSetDatabase().findMotors(type, manufacturer,
+ designation, diameter, length);
+
+ // No motors
+ if (motors.size() == 0) {
String str = "No motor with designation '" + designation + "'";
if (manufacturer != null)
str += " for manufacturer '" + manufacturer + "'";
- warnings.add(Warning.fromString(str + " found."));
+ str += " found.";
+ warnings.add(str);
return null;
}
- if (motors.length > 1) {
+
+ // One motor
+ if (motors.size() == 1) {
+ ThrustCurveMotor m = motors.get(0);
+ if (digest != null && !MotorDigest.digestMotor(m).equals(digest)) {
+ String str = "Motor with designation '" + designation + "'";
+ if (manufacturer != null)
+ str += " for manufacturer '" + manufacturer + "'";
+ str += " has differing thrust curve than the original.";
+ warnings.add(str);
+ }
+ return m;
+ }
+
+ // Multiple motors, check digest for which one to use
+ if (digest != null) {
+
+ // Check for motor with correct digest
+ for (ThrustCurveMotor m : motors) {
+ if (MotorDigest.digestMotor(m).equals(digest)) {
+ return m;
+ }
+ }
+ String str = "Motor with designation '" + designation + "'";
+ if (manufacturer != null)
+ str += " for manufacturer '" + manufacturer + "'";
+ str += " has differing thrust curve than the original.";
+ warnings.add(str);
+
+ } else {
+
+ // No digest, check for preferred digest (OpenRocket <= 1.1.0)
+ // TODO: MEDIUM: This should only be done for document versions 1.1 and below
+ for (ThrustCurveMotor m : motors) {
+ if (PreferredMotorDigests.DIGESTS.contains(MotorDigest.digestMotor(m))) {
+ return m;
+ }
+ }
+
String str = "Multiple motors with designation '" + designation + "'";
if (manufacturer != null)
str += " for manufacturer '" + manufacturer + "'";
- warnings.add(Warning.fromString(str + " found, one chosen arbitrarily."));
+ str += " found, one chosen arbitrarily.";
+ warnings.add(str);
+
}
- return motors[0];
+ return motors.get(0);
}
-
/**
* Return the delay to use for the motor.
*/
// Motor type
type = null;
for (Motor.Type t : Motor.Type.values()) {
- if (t.name().toLowerCase().equals(content)) {
+ if (t.name().toLowerCase().equals(content.trim())) {
type = t;
break;
}
} else if (element.equals("manufacturer")) {
// Manufacturer
- manufacturer = content;
+ manufacturer = content.trim();
} else if (element.equals("designation")) {
// Designation
- designation = content;
+ designation = content.trim();
+
+ } else if (element.equals("digest")) {
+
+ // Digest
+ digest = content.trim();
} else if (element.equals("diameter")) {
// Diameter
diameter = Double.NaN;
try {
- diameter = Double.parseDouble(content);
+ diameter = Double.parseDouble(content.trim());
} catch (NumberFormatException e) {
// Ignore
}
// Length
length = Double.NaN;
try {
- length = Double.parseDouble(content);
+ length = Double.parseDouble(content.trim());
} catch (NumberFormatException ignore) {
}
delay = Motor.PLUGGED;
} else {
try {
- delay = Double.parseDouble(content);
+ delay = Double.parseDouble(content.trim());
} catch (NumberFormatException ignore) {
}
} catch (NumberFormatException ignore) {
}
+ // TODO: HIGH: Store and load launchRodVelocity
data = new FlightData(maxAltitude, maxVelocity, maxAcceleration, maxMach,
- timeToApogee, flightTime, groundHitVelocity);
+ timeToApogee, flightTime, groundHitVelocity, Double.NaN);
}
data.getWarningSet().addAll(warningSet);
setMethod = set;
}
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
setMethod.invoke(c, s);
setMethod = set;
}
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
try {
setMethod = set;
}
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
}
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
this.enabledMethod = enabledMethod;
}
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
setMethod = set;
}
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
this.type = type;
}
+ @Override
public void set(RocketComponent c, String name, HashMap<String, String> attributes,
WarningSet warnings) {
class PositionSetter implements Setter {
+ @Override
public void set(RocketComponent c, String value, HashMap<String, String> attributes,
WarningSet warnings) {
class ClusterConfigurationSetter implements Setter {
+ @Override
public void set(RocketComponent component, String value, HashMap<String, String> attributes,
WarningSet warnings) {