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.SimulationConditions;
import net.sf.openrocket.simulation.FlightEvent.Type;
+import net.sf.openrocket.simulation.SimulationOptions;
+import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate;
+import net.sf.openrocket.util.GeodeticComputationStrategy;
import net.sf.openrocket.util.LineStyle;
import net.sf.openrocket.util.Reflection;
*
* @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);
}
-
+
OpenRocketDocument doc = handler.getDocument();
doc.getDefaultConfiguration().setAllStages();
// Deduce suitable time skip
double timeSkip = StorageOptions.SIMULATION_DATA_NONE;
- for (Simulation s: doc.getSimulations()) {
+ for (Simulation s : doc.getSimulations()) {
if (s.getStatus() == Simulation.Status.EXTERNAL ||
s.getStatus() == Simulation.Status.NOT_SIMULATED)
continue;
FlightDataBranch branch = s.getSimulatedData().getBranch(0);
if (branch == null)
continue;
- List<Double> list = branch.get(FlightDataBranch.TYPE_TIME);
+ List<Double> list = branch.get(FlightDataType.TYPE_TIME);
if (list == null)
continue;
double previousTime = Double.NaN;
- for (double time: list) {
+ for (double time : list) {
if (time - previousTime < timeSkip)
- timeSkip = time-previousTime;
+ timeSkip = time - previousTime;
previousTime = time;
}
}
// Round value
- timeSkip = Math.rint(timeSkip*100)/100;
-
+ timeSkip = Math.rint(timeSkip * 100) / 100;
+
doc.getDefaultStorageOptions().setSimulationTimeSkip(timeSkip);
doc.getDefaultStorageOptions().setCompressionEnabled(false); // Set by caller if compressed
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", "1.3" };
+
//////// Component constructors
static final HashMap<String, Constructor<? extends RocketComponent>> constructors = new HashMap<String, Constructor<? extends RocketComponent>>();
constructors.put("ellipticalfinset", EllipticalFinSet.class.getConstructor(new Class<?>[0]));
constructors.put("freeformfinset", FreeformFinSet.class.getConstructor(new Class<?>[0]));
constructors.put("launchlug", LaunchLug.class.getConstructor(new Class<?>[0]));
-
+
// Internal components
constructors.put("engineblock", EngineBlock.class.getConstructor(new Class<?>[0]));
constructors.put("innertube", InnerTube.class.getConstructor(new Class<?>[0]));
"Error in constructing the 'constructors' HashMap.");
}
}
-
+
//////// Parameter setters
/*
static {
// RocketComponent
setters.put("RocketComponent:name", new StringSetter(
- Reflection.findMethodStatic(RocketComponent.class, "setName", String.class)));
+ Reflection.findMethod(RocketComponent.class, "setName", String.class)));
setters.put("RocketComponent:color", new ColorSetter(
- Reflection.findMethodStatic(RocketComponent.class, "setColor", Color.class)));
+ Reflection.findMethod(RocketComponent.class, "setColor", Color.class)));
setters.put("RocketComponent:linestyle", new EnumSetter<LineStyle>(
- Reflection.findMethodStatic(RocketComponent.class, "setLineStyle", LineStyle.class),
+ Reflection.findMethod(RocketComponent.class, "setLineStyle", LineStyle.class),
LineStyle.class));
setters.put("RocketComponent:position", new PositionSetter());
setters.put("RocketComponent:overridemass", new OverrideSetter(
- Reflection.findMethodStatic(RocketComponent.class, "setOverrideMass", double.class),
- Reflection.findMethodStatic(RocketComponent.class, "setMassOverridden", boolean.class)));
+ Reflection.findMethod(RocketComponent.class, "setOverrideMass", double.class),
+ Reflection.findMethod(RocketComponent.class, "setMassOverridden", boolean.class)));
setters.put("RocketComponent:overridecg", new OverrideSetter(
- Reflection.findMethodStatic(RocketComponent.class, "setOverrideCGX", double.class),
- Reflection.findMethodStatic(RocketComponent.class, "setCGOverridden", boolean.class)));
+ Reflection.findMethod(RocketComponent.class, "setOverrideCGX", double.class),
+ Reflection.findMethod(RocketComponent.class, "setCGOverridden", boolean.class)));
setters.put("RocketComponent:overridesubcomponents", new BooleanSetter(
- Reflection.findMethodStatic(RocketComponent.class, "setOverrideSubcomponents", boolean.class)));
+ Reflection.findMethod(RocketComponent.class, "setOverrideSubcomponents", boolean.class)));
setters.put("RocketComponent:comment", new StringSetter(
- Reflection.findMethodStatic(RocketComponent.class, "setComment", String.class)));
+ Reflection.findMethod(RocketComponent.class, "setComment", String.class)));
// ExternalComponent
setters.put("ExternalComponent:finish", new EnumSetter<Finish>(
- Reflection.findMethodStatic(ExternalComponent.class, "setFinish", Finish.class),
+ Reflection.findMethod(ExternalComponent.class, "setFinish", Finish.class),
Finish.class));
setters.put("ExternalComponent:material", new MaterialSetter(
- Reflection.findMethodStatic(ExternalComponent.class, "setMaterial", Material.class),
+ Reflection.findMethod(ExternalComponent.class, "setMaterial", Material.class),
Material.Type.BULK));
-
+
// BodyComponent
setters.put("BodyComponent:length", new DoubleSetter(
- Reflection.findMethodStatic(BodyComponent.class, "setLength", double.class)));
+ Reflection.findMethod(BodyComponent.class, "setLength", double.class)));
// SymmetricComponent
setters.put("SymmetricComponent:thickness", new DoubleSetter(
- Reflection.findMethodStatic(SymmetricComponent.class,"setThickness", double.class),
- "filled",
- Reflection.findMethodStatic(SymmetricComponent.class,"setFilled", boolean.class)));
+ Reflection.findMethod(SymmetricComponent.class, "setThickness", double.class),
+ "filled",
+ Reflection.findMethod(SymmetricComponent.class, "setFilled", boolean.class)));
// BodyTube
setters.put("BodyTube:radius", new DoubleSetter(
- Reflection.findMethodStatic(BodyTube.class, "setRadius", double.class),
+ Reflection.findMethod(BodyTube.class, "setOuterRadius", double.class),
"auto",
- Reflection.findMethodStatic(BodyTube.class,"setRadiusAutomatic", boolean.class)));
-
+ Reflection.findMethod(BodyTube.class, "setOuterRadiusAutomatic", boolean.class)));
+
// Transition
setters.put("Transition:shape", new EnumSetter<Transition.Shape>(
- Reflection.findMethodStatic(Transition.class, "setType", Transition.Shape.class),
+ Reflection.findMethod(Transition.class, "setType", Transition.Shape.class),
Transition.Shape.class));
setters.put("Transition:shapeclipped", new BooleanSetter(
- Reflection.findMethodStatic(Transition.class, "setClipped", boolean.class)));
+ Reflection.findMethod(Transition.class, "setClipped", boolean.class)));
setters.put("Transition:shapeparameter", new DoubleSetter(
- Reflection.findMethodStatic(Transition.class, "setShapeParameter", double.class)));
-
+ Reflection.findMethod(Transition.class, "setShapeParameter", double.class)));
+
setters.put("Transition:foreradius", new DoubleSetter(
- Reflection.findMethodStatic(Transition.class, "setForeRadius", double.class),
+ Reflection.findMethod(Transition.class, "setForeRadius", double.class),
"auto",
- Reflection.findMethodStatic(Transition.class, "setForeRadiusAutomatic", boolean.class)));
+ Reflection.findMethod(Transition.class, "setForeRadiusAutomatic", boolean.class)));
setters.put("Transition:aftradius", new DoubleSetter(
- Reflection.findMethodStatic(Transition.class, "setAftRadius", double.class),
+ Reflection.findMethod(Transition.class, "setAftRadius", double.class),
"auto",
- Reflection.findMethodStatic(Transition.class, "setAftRadiusAutomatic", boolean.class)));
-
+ Reflection.findMethod(Transition.class, "setAftRadiusAutomatic", boolean.class)));
+
setters.put("Transition:foreshoulderradius", new DoubleSetter(
- Reflection.findMethodStatic(Transition.class, "setForeShoulderRadius", double.class)));
+ Reflection.findMethod(Transition.class, "setForeShoulderRadius", double.class)));
setters.put("Transition:foreshoulderlength", new DoubleSetter(
- Reflection.findMethodStatic(Transition.class, "setForeShoulderLength", double.class)));
+ Reflection.findMethod(Transition.class, "setForeShoulderLength", double.class)));
setters.put("Transition:foreshoulderthickness", new DoubleSetter(
- Reflection.findMethodStatic(Transition.class, "setForeShoulderThickness", double.class)));
+ Reflection.findMethod(Transition.class, "setForeShoulderThickness", double.class)));
setters.put("Transition:foreshouldercapped", new BooleanSetter(
- Reflection.findMethodStatic(Transition.class, "setForeShoulderCapped", boolean.class)));
+ Reflection.findMethod(Transition.class, "setForeShoulderCapped", boolean.class)));
setters.put("Transition:aftshoulderradius", new DoubleSetter(
- Reflection.findMethodStatic(Transition.class, "setAftShoulderRadius", double.class)));
+ Reflection.findMethod(Transition.class, "setAftShoulderRadius", double.class)));
setters.put("Transition:aftshoulderlength", new DoubleSetter(
- Reflection.findMethodStatic(Transition.class, "setAftShoulderLength", double.class)));
+ Reflection.findMethod(Transition.class, "setAftShoulderLength", double.class)));
setters.put("Transition:aftshoulderthickness", new DoubleSetter(
- Reflection.findMethodStatic(Transition.class, "setAftShoulderThickness", double.class)));
+ Reflection.findMethod(Transition.class, "setAftShoulderThickness", double.class)));
setters.put("Transition:aftshouldercapped", new BooleanSetter(
- Reflection.findMethodStatic(Transition.class, "setAftShoulderCapped", boolean.class)));
+ Reflection.findMethod(Transition.class, "setAftShoulderCapped", boolean.class)));
// NoseCone - disable disallowed elements
setters.put("NoseCone:foreradius", null);
// FinSet
setters.put("FinSet:fincount", new IntSetter(
- Reflection.findMethodStatic(FinSet.class, "setFinCount", int.class)));
+ Reflection.findMethod(FinSet.class, "setFinCount", int.class)));
setters.put("FinSet:rotation", new DoubleSetter(
- Reflection.findMethodStatic(FinSet.class, "setBaseRotation", double.class), Math.PI/180.0));
+ Reflection.findMethod(FinSet.class, "setBaseRotation", double.class), Math.PI / 180.0));
setters.put("FinSet:thickness", new DoubleSetter(
- Reflection.findMethodStatic(FinSet.class, "setThickness", double.class)));
+ Reflection.findMethod(FinSet.class, "setThickness", double.class)));
setters.put("FinSet:crosssection", new EnumSetter<FinSet.CrossSection>(
- Reflection.findMethodStatic(FinSet.class, "setCrossSection", FinSet.CrossSection.class),
+ Reflection.findMethod(FinSet.class, "setCrossSection", FinSet.CrossSection.class),
FinSet.CrossSection.class));
setters.put("FinSet:cant", new DoubleSetter(
- Reflection.findMethodStatic(FinSet.class, "setCantAngle", double.class), Math.PI/180.0));
+ Reflection.findMethod(FinSet.class, "setCantAngle", double.class), Math.PI / 180.0));
setters.put("FinSet:tabheight", new DoubleSetter(
- Reflection.findMethodStatic(FinSet.class, "setTabHeight", double.class)));
+ Reflection.findMethod(FinSet.class, "setTabHeight", double.class)));
setters.put("FinSet:tablength", new DoubleSetter(
- Reflection.findMethodStatic(FinSet.class, "setTabLength", double.class)));
+ Reflection.findMethod(FinSet.class, "setTabLength", double.class)));
setters.put("FinSet:tabposition", new FinTabPositionSetter());
// TrapezoidFinSet
setters.put("TrapezoidFinSet:rootchord", new DoubleSetter(
- Reflection.findMethodStatic(TrapezoidFinSet.class, "setRootChord", double.class)));
+ Reflection.findMethod(TrapezoidFinSet.class, "setRootChord", double.class)));
setters.put("TrapezoidFinSet:tipchord", new DoubleSetter(
- Reflection.findMethodStatic(TrapezoidFinSet.class, "setTipChord", double.class)));
+ Reflection.findMethod(TrapezoidFinSet.class, "setTipChord", double.class)));
setters.put("TrapezoidFinSet:sweeplength", new DoubleSetter(
- Reflection.findMethodStatic(TrapezoidFinSet.class, "setSweep", double.class)));
+ Reflection.findMethod(TrapezoidFinSet.class, "setSweep", double.class)));
setters.put("TrapezoidFinSet:height", new DoubleSetter(
- Reflection.findMethodStatic(TrapezoidFinSet.class, "setHeight", double.class)));
-
+ Reflection.findMethod(TrapezoidFinSet.class, "setHeight", double.class)));
+
// EllipticalFinSet
setters.put("EllipticalFinSet:rootchord", new DoubleSetter(
- Reflection.findMethodStatic(EllipticalFinSet.class, "setLength", double.class)));
+ Reflection.findMethod(EllipticalFinSet.class, "setLength", double.class)));
setters.put("EllipticalFinSet:height", new DoubleSetter(
- Reflection.findMethodStatic(EllipticalFinSet.class, "setHeight", double.class)));
+ Reflection.findMethod(EllipticalFinSet.class, "setHeight", double.class)));
// FreeformFinSet points handled as a special handler
// LaunchLug
setters.put("LaunchLug:radius", new DoubleSetter(
- Reflection.findMethodStatic(LaunchLug.class, "setRadius", double.class)));
+ Reflection.findMethod(LaunchLug.class, "setOuterRadius", double.class)));
setters.put("LaunchLug:length", new DoubleSetter(
- Reflection.findMethodStatic(LaunchLug.class, "setLength", double.class)));
+ Reflection.findMethod(LaunchLug.class, "setLength", double.class)));
setters.put("LaunchLug:thickness", new DoubleSetter(
- Reflection.findMethodStatic(LaunchLug.class, "setThickness", double.class)));
+ Reflection.findMethod(LaunchLug.class, "setThickness", double.class)));
setters.put("LaunchLug:radialdirection", new DoubleSetter(
- Reflection.findMethodStatic(LaunchLug.class, "setRadialDirection", double.class),
- Math.PI/180.0));
+ Reflection.findMethod(LaunchLug.class, "setRadialDirection", double.class),
+ Math.PI / 180.0));
// InternalComponent - nothing
// StructuralComponent
setters.put("StructuralComponent:material", new MaterialSetter(
- Reflection.findMethodStatic(StructuralComponent.class, "setMaterial", Material.class),
+ Reflection.findMethod(StructuralComponent.class, "setMaterial", Material.class),
Material.Type.BULK));
// RingComponent
setters.put("RingComponent:length", new DoubleSetter(
- Reflection.findMethodStatic(RingComponent.class, "setLength", double.class)));
+ Reflection.findMethod(RingComponent.class, "setLength", double.class)));
setters.put("RingComponent:radialposition", new DoubleSetter(
- Reflection.findMethodStatic(RingComponent.class, "setRadialPosition", double.class)));
+ Reflection.findMethod(RingComponent.class, "setRadialPosition", double.class)));
setters.put("RingComponent:radialdirection", new DoubleSetter(
- Reflection.findMethodStatic(RingComponent.class, "setRadialDirection", double.class),
+ Reflection.findMethod(RingComponent.class, "setRadialDirection", double.class),
Math.PI / 180.0));
// ThicknessRingComponent - radius on separate components due to differing automatics
setters.put("ThicknessRingComponent:thickness", new DoubleSetter(
- Reflection.findMethodStatic(ThicknessRingComponent.class, "setThickness", double.class)));
-
+ Reflection.findMethod(ThicknessRingComponent.class, "setThickness", double.class)));
+
// EngineBlock
setters.put("EngineBlock:outerradius", new DoubleSetter(
- Reflection.findMethodStatic(EngineBlock.class, "setOuterRadius", double.class),
+ Reflection.findMethod(EngineBlock.class, "setOuterRadius", double.class),
"auto",
- Reflection.findMethodStatic(EngineBlock.class, "setOuterRadiusAutomatic", boolean.class)));
-
+ Reflection.findMethod(EngineBlock.class, "setOuterRadiusAutomatic", boolean.class)));
+
// TubeCoupler
setters.put("TubeCoupler:outerradius", new DoubleSetter(
- Reflection.findMethodStatic(TubeCoupler.class, "setOuterRadius", double.class),
+ Reflection.findMethod(TubeCoupler.class, "setOuterRadius", double.class),
"auto",
- Reflection.findMethodStatic(TubeCoupler.class, "setOuterRadiusAutomatic", boolean.class)));
+ Reflection.findMethod(TubeCoupler.class, "setOuterRadiusAutomatic", boolean.class)));
// InnerTube
setters.put("InnerTube:outerradius", new DoubleSetter(
- Reflection.findMethodStatic(InnerTube.class, "setOuterRadius", double.class)));
+ Reflection.findMethod(InnerTube.class, "setOuterRadius", double.class)));
setters.put("InnerTube:clusterconfiguration", new ClusterConfigurationSetter());
setters.put("InnerTube:clusterscale", new DoubleSetter(
- Reflection.findMethodStatic(InnerTube.class, "setClusterScale", double.class)));
+ Reflection.findMethod(InnerTube.class, "setClusterScale", double.class)));
setters.put("InnerTube:clusterrotation", new DoubleSetter(
- Reflection.findMethodStatic(InnerTube.class, "setClusterRotation", double.class),
+ Reflection.findMethod(InnerTube.class, "setClusterRotation", double.class),
Math.PI / 180.0));
// RadiusRingComponent
// Bulkhead
setters.put("RadiusRingComponent:innerradius", new DoubleSetter(
- Reflection.findMethodStatic(RadiusRingComponent.class, "setInnerRadius", double.class)));
+ Reflection.findMethod(RadiusRingComponent.class, "setInnerRadius", double.class)));
setters.put("Bulkhead:outerradius", new DoubleSetter(
- Reflection.findMethodStatic(Bulkhead.class, "setOuterRadius", double.class),
+ Reflection.findMethod(Bulkhead.class, "setOuterRadius", double.class),
"auto",
- Reflection.findMethodStatic(Bulkhead.class, "setOuterRadiusAutomatic", boolean.class)));
+ Reflection.findMethod(Bulkhead.class, "setOuterRadiusAutomatic", boolean.class)));
// CenteringRing
setters.put("CenteringRing:innerradius", new DoubleSetter(
- Reflection.findMethodStatic(CenteringRing.class, "setInnerRadius", double.class),
+ Reflection.findMethod(CenteringRing.class, "setInnerRadius", double.class),
"auto",
- Reflection.findMethodStatic(CenteringRing.class, "setInnerRadiusAutomatic", boolean.class)));
+ Reflection.findMethod(CenteringRing.class, "setInnerRadiusAutomatic", boolean.class)));
setters.put("CenteringRing:outerradius", new DoubleSetter(
- Reflection.findMethodStatic(CenteringRing.class, "setOuterRadius", double.class),
+ Reflection.findMethod(CenteringRing.class, "setOuterRadius", double.class),
"auto",
- Reflection.findMethodStatic(CenteringRing.class, "setOuterRadiusAutomatic", boolean.class)));
-
+ Reflection.findMethod(CenteringRing.class, "setOuterRadiusAutomatic", boolean.class)));
+
// MassObject
setters.put("MassObject:packedlength", new DoubleSetter(
- Reflection.findMethodStatic(MassObject.class, "setLength", double.class)));
+ Reflection.findMethod(MassObject.class, "setLength", double.class)));
setters.put("MassObject:packedradius", new DoubleSetter(
- Reflection.findMethodStatic(MassObject.class, "setRadius", double.class)));
+ Reflection.findMethod(MassObject.class, "setRadius", double.class)));
setters.put("MassObject:radialposition", new DoubleSetter(
- Reflection.findMethodStatic(MassObject.class, "setRadialPosition", double.class)));
+ Reflection.findMethod(MassObject.class, "setRadialPosition", double.class)));
setters.put("MassObject:radialdirection", new DoubleSetter(
- Reflection.findMethodStatic(MassObject.class, "setRadialDirection", double.class),
+ Reflection.findMethod(MassObject.class, "setRadialDirection", double.class),
Math.PI / 180.0));
// MassComponent
setters.put("MassComponent:mass", new DoubleSetter(
- Reflection.findMethodStatic(MassComponent.class, "setComponentMass", double.class)));
+ Reflection.findMethod(MassComponent.class, "setComponentMass", double.class)));
// ShockCord
setters.put("ShockCord:cordlength", new DoubleSetter(
- Reflection.findMethodStatic(ShockCord.class, "setCordLength", double.class)));
+ Reflection.findMethod(ShockCord.class, "setCordLength", double.class)));
setters.put("ShockCord:material", new MaterialSetter(
- Reflection.findMethodStatic(ShockCord.class, "setMaterial", Material.class),
+ Reflection.findMethod(ShockCord.class, "setMaterial", Material.class),
Material.Type.LINE));
// RecoveryDevice
setters.put("RecoveryDevice:cd", new DoubleSetter(
- Reflection.findMethodStatic(RecoveryDevice.class, "setCD", double.class),
+ Reflection.findMethod(RecoveryDevice.class, "setCD", double.class),
"auto",
- Reflection.findMethodStatic(RecoveryDevice.class, "setCDAutomatic", boolean.class)));
+ Reflection.findMethod(RecoveryDevice.class, "setCDAutomatic", boolean.class)));
setters.put("RecoveryDevice:deployevent", new EnumSetter<RecoveryDevice.DeployEvent>(
- Reflection.findMethodStatic(RecoveryDevice.class, "setDeployEvent", RecoveryDevice.DeployEvent.class),
+ Reflection.findMethod(RecoveryDevice.class, "setDeployEvent", RecoveryDevice.DeployEvent.class),
RecoveryDevice.DeployEvent.class));
setters.put("RecoveryDevice:deployaltitude", new DoubleSetter(
- Reflection.findMethodStatic(RecoveryDevice.class, "setDeployAltitude", double.class)));
+ Reflection.findMethod(RecoveryDevice.class, "setDeployAltitude", double.class)));
setters.put("RecoveryDevice:deploydelay", new DoubleSetter(
- Reflection.findMethodStatic(RecoveryDevice.class, "setDeployDelay", double.class)));
+ Reflection.findMethod(RecoveryDevice.class, "setDeployDelay", double.class)));
setters.put("RecoveryDevice:material", new MaterialSetter(
- Reflection.findMethodStatic(RecoveryDevice.class, "setMaterial", Material.class),
+ Reflection.findMethod(RecoveryDevice.class, "setMaterial", Material.class),
Material.Type.SURFACE));
// Parachute
setters.put("Parachute:diameter", new DoubleSetter(
- Reflection.findMethodStatic(Parachute.class, "setDiameter", double.class)));
+ Reflection.findMethod(Parachute.class, "setDiameter", double.class)));
setters.put("Parachute:linecount", new IntSetter(
- Reflection.findMethodStatic(Parachute.class, "setLineCount", int.class)));
+ Reflection.findMethod(Parachute.class, "setLineCount", int.class)));
setters.put("Parachute:linelength", new DoubleSetter(
- Reflection.findMethodStatic(Parachute.class, "setLineLength", double.class)));
+ Reflection.findMethod(Parachute.class, "setLineLength", double.class)));
setters.put("Parachute:linematerial", new MaterialSetter(
- Reflection.findMethodStatic(Parachute.class, "setLineMaterial", Material.class),
+ Reflection.findMethod(Parachute.class, "setLineMaterial", Material.class),
Material.Type.LINE));
-
+
// Streamer
setters.put("Streamer:striplength", new DoubleSetter(
- Reflection.findMethodStatic(Streamer.class, "setStripLength", double.class)));
+ Reflection.findMethod(Streamer.class, "setStripLength", double.class)));
setters.put("Streamer:stripwidth", new DoubleSetter(
- Reflection.findMethodStatic(Streamer.class, "setStripWidth", double.class)));
+ Reflection.findMethod(Streamer.class, "setStripWidth", double.class)));
// Rocket
// <motorconfiguration> handled by separate handler
setters.put("Rocket:referencetype", new EnumSetter<ReferenceType>(
- Reflection.findMethodStatic(Rocket.class, "setReferenceType", ReferenceType.class),
+ Reflection.findMethod(Rocket.class, "setReferenceType", ReferenceType.class),
ReferenceType.class));
setters.put("Rocket:customreference", new DoubleSetter(
- Reflection.findMethodStatic(Rocket.class, "setCustomReferenceLength", double.class)));
+ Reflection.findMethod(Rocket.class, "setCustomReferenceLength", double.class)));
setters.put("Rocket:designer", new StringSetter(
- Reflection.findMethodStatic(Rocket.class, "setDesigner", String.class)));
+ Reflection.findMethod(Rocket.class, "setDesigner", String.class)));
setters.put("Rocket:revision", new StringSetter(
- Reflection.findMethodStatic(Rocket.class, "setRevision", String.class)));
+ Reflection.findMethod(Rocket.class, "setRevision", String.class)));
}
* @param enumClass the class of the enum.
* @return the found enum value, or <code>null</code>.
*/
- public static <T extends Enum<T>> Enum<T> findEnum(String name,
+ public static <T extends Enum<T>> Enum<T> findEnum(String name,
Class<? extends Enum<T>> enumClass) {
if (name == null)
return null;
name = name.trim();
- for (Enum<T> e: enumClass.getEnumConstants()) {
+ for (Enum<T> e : enumClass.getEnumConstants()) {
if (e.name().toLowerCase().replace("_", "").equals(name)) {
return e;
}
*/
class OpenRocketHandler extends ElementHandler {
private OpenRocketContentHandler handler = null;
-
+
/**
* Return the OpenRocketDocument read from the file, or <code>null</code> if a document
* has not been read yet.
public OpenRocketDocument getDocument() {
return handler.getDocument();
}
-
+
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
// Check for unknown elements
if (!element.equals("openrocket")) {
warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
return null;
}
-
+
// Check for first call
if (handler != null) {
warnings.add(Warning.fromString("Multiple document elements found, ignoring later "
+ "ones."));
return null;
}
-
+
// Check version number
String version = null;
String creator = attributes.remove("creator");
str += ", attempting to read file anyway.";
warnings.add(str);
}
-
+
handler = new OpenRocketContentHandler();
return handler;
}
-
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException {
super.closeElement(element, attributes, content, warnings);
}
-
+
}
class OpenRocketContentHandler extends ElementHandler {
private final OpenRocketDocument doc;
private final Rocket rocket;
-
+
private boolean rocketDefined = false;
private boolean simulationsDefined = false;
-
+
public OpenRocketContentHandler() {
this.rocket = new Rocket();
this.doc = new OpenRocketDocument(rocket);
}
-
-
+
+
public OpenRocketDocument getDocument() {
if (!rocketDefined)
return null;
return doc;
}
-
+
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
if (element.equals("rocket")) {
if (rocketDefined) {
warnings.add(Warning
simulationsDefined = true;
return new SimulationsHandler(doc);
}
-
+
warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
-
+
return null;
}
}
*/
class ComponentHandler extends ElementHandler {
private final RocketComponent parent;
-
+
public ComponentHandler(RocketComponent parent) {
this.parent = parent;
}
-
+
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
// Attempt to construct new component
Constructor<? extends RocketComponent> constructor = DocumentConfig.constructors
.get(element);
warnings.add(Warning.fromString("Unknown element " + element + ", ignoring."));
return null;
}
-
+
RocketComponent c;
try {
c = constructor.newInstance();
} catch (IllegalAccessException e) {
throw new BugException("Error constructing component.", e);
} catch (InvocationTargetException e) {
- throw Reflection.handleInvocationTargetException(e);
+ throw Reflection.handleWrappedException(e);
}
-
+
parent.addChild(c);
-
+
return new ComponentParameterHandler(c);
}
}
*/
class ComponentParameterHandler extends ElementHandler {
private final RocketComponent component;
-
+
public ComponentParameterHandler(RocketComponent c) {
this.component = c;
}
-
+
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
warnings.add(Warning.fromString("Illegal component defined as motor mount."));
return null;
}
- return new MotorMountHandler((MotorMount)component);
+ return new MotorMountHandler((MotorMount) component);
}
if (element.equals("finpoints")) {
if (!(component instanceof FreeformFinSet)) {
warnings.add(Warning.fromString("Illegal component defined for fin points."));
return null;
}
- return new FinSetPointHandler((FreeformFinSet)component);
+ return new FinSetPointHandler((FreeformFinSet) component);
}
if (element.equals("motorconfiguration")) {
if (!(component instanceof Rocket)) {
warnings.add(Warning.fromString("Illegal component defined for motor configuration."));
return null;
}
- return new MotorConfigurationHandler((Rocket)component);
+ return new MotorConfigurationHandler((Rocket) component);
}
-
+
return PlainTextHandler.INSTANCE;
}
-
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) {
-
+
if (element.equals("subcomponents") || element.equals("motormount") ||
element.equals("finpoints") || element.equals("motorconfiguration")) {
return;
}
// Search for the correct setter class
-
+
Class<?> c;
for (c = component.getClass(); c != null; c = c.getSuperclass()) {
String setterKey = c.getSimpleName() + ":" + element;
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;
}
return PlainTextHandler.INSTANCE;
}
-
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException {
-
+
String strx = attributes.remove("x");
String stry = attributes.remove("y");
if (strx == null || stry == null) {
try {
double x = Double.parseDouble(strx);
double y = Double.parseDouble(stry);
- coordinates.add(new Coordinate(x,y));
+ coordinates.add(new Coordinate(x, y));
} catch (NumberFormatException e) {
warnings.add(Warning.fromString("Illegal fin points specification, ignoring."));
return;
this.mount = mount;
mount.setMotorMount(true);
}
-
+
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
if (element.equals("motor")) {
motorHandler = new MotorHandler();
return motorHandler;
return PlainTextHandler.INSTANCE;
}
- warnings.add(Warning.fromString("Unknown element '"+element+"' encountered, ignoring."));
+ warnings.add(Warning.fromString("Unknown element '" + element + "' encountered, ignoring."));
return null;
}
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException {
-
+
if (element.equals("motor")) {
String id = attributes.get("configid");
if (id == null || id.equals("")) {
warnings.add(Warning.fromString("Illegal motor specification, ignoring."));
return;
}
-
+
Motor motor = motorHandler.getMotor(warnings);
mount.setMotor(id, motor);
mount.setMotorDelay(id, motorHandler.getDelay(warnings));
return;
}
-
- if (element.equals("ignitionevent")) {
+
+ if (element.equals("ignitionevent")) {
MotorMount.IgnitionEvent event = null;
for (MotorMount.IgnitionEvent e : MotorMount.IgnitionEvent.values()) {
if (e.name().toLowerCase().replaceAll("_", "").equals(content)) {
}
}
if (event == null) {
- warnings.add(Warning.fromString("Unknown ignition event type '"+content+"', ignoring."));
+ warnings.add(Warning.fromString("Unknown ignition event type '" + content + "', ignoring."));
return;
}
mount.setIgnitionEvent(event);
return;
}
-
+
if (element.equals("ignitiondelay")) {
double d;
try {
public MotorConfigurationHandler(Rocket rocket) {
this.rocket = rocket;
}
-
+
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
if (inNameElement || !element.equals("name")) {
warnings.add(Warning.FILE_INVALID_PARAMETER);
return null;
return PlainTextHandler.INSTANCE;
}
-
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) {
name = content;
}
-
+
@Override
public void endHandler(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException {
-
+
String configid = attributes.remove("configid");
if (configid == null || configid.equals("")) {
warnings.add(Warning.FILE_INVALID_PARAMETER);
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) {
- String str = "No motor with designation '"+designation+"'";
+
+ 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) {
- String str = "Multiple motors with designation '"+designation+"'";
+
+ // 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.
*/
return delay;
}
-
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException {
// Motor type
type = null;
- for (Motor.Type t: Motor.Type.values()) {
- if (t.name().toLowerCase().equals(content)) {
+ for (Motor.Type t : Motor.Type.values()) {
+ if (t.name().toLowerCase().equals(content.trim())) {
type = t;
break;
}
}
if (type == null) {
- warnings.add(Warning.fromString("Unknown motor type '"+content+"', ignoring."));
+ warnings.add(Warning.fromString("Unknown motor type '" + content + "', ignoring."));
}
} 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
}
}
} else if (element.equals("length")) {
-
+
// Length
length = Double.NaN;
try {
- length = Double.parseDouble(content);
- } catch (NumberFormatException ignore) { }
+ length = Double.parseDouble(content.trim());
+ } catch (NumberFormatException ignore) {
+ }
if (Double.isNaN(length)) {
warnings.add(Warning.fromString("Illegal motor diameter specified, ignoring."));
delay = Motor.PLUGGED;
} else {
try {
- delay = Double.parseDouble(content);
- } catch (NumberFormatException ignore) { }
+ delay = Double.parseDouble(content.trim());
+ } catch (NumberFormatException ignore) {
+ }
if (Double.isNaN(delay)) {
warnings.add(Warning.fromString("Illegal motor delay specified, ignoring."));
}
}
-
+
} else {
super.closeElement(element, attributes, content, warnings);
}
public SimulationsHandler(OpenRocketDocument doc) {
this.doc = doc;
}
-
+
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
if (!element.equals("simulation")) {
- warnings.add("Unknown element '"+element+"', ignoring.");
+ warnings.add("Unknown element '" + element + "', ignoring.");
return null;
}
handler = new SingleSimulationHandler(doc);
return handler;
}
-
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException {
super.closeElement(element, attributes, content, warnings);
}
-
+
}
class SingleSimulationHandler extends ElementHandler {
-
+
private final OpenRocketDocument doc;
private String name;
}
-
+
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
- if (element.equals("name") || element.equals("simulator") ||
+ if (element.equals("name") || element.equals("simulator") ||
element.equals("calculator") || element.equals("listener")) {
return PlainTextHandler.INSTANCE;
} else if (element.equals("conditions")) {
dataHandler = new FlightDataHandler();
return dataHandler;
} else {
- warnings.add("Unknown element '"+element+"', ignoring.");
+ warnings.add("Unknown element '" + element + "', ignoring.");
return null;
}
}
} else if (element.equals("listener") && content.trim().length() > 0) {
listeners.add(content.trim());
}
-
+
}
-
+
@Override
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) {
status = Simulation.Status.OUTDATED;
}
- SimulationConditions conditions;
+ SimulationOptions conditions;
if (conditionHandler != null) {
conditions = conditionHandler.getConditions();
} else {
warnings.add("Simulation conditions not defined, using defaults.");
- conditions = new SimulationConditions(doc.getRocket());
+ conditions = new SimulationOptions(doc.getRocket());
}
if (name == null)
data = null;
else
data = dataHandler.getFlightData();
-
+
Simulation simulation = new Simulation(doc.getRocket(), status, name,
conditions, listeners, data);
class SimulationConditionsHandler extends ElementHandler {
- private SimulationConditions conditions;
+ private SimulationOptions conditions;
private AtmosphereHandler atmosphereHandler;
public SimulationConditionsHandler(Rocket rocket) {
- conditions = new SimulationConditions(rocket);
+ conditions = new SimulationOptions(rocket);
+ // Set up default loading settings (which may differ from the new defaults)
+ conditions.setGeodeticComputation(GeodeticComputationStrategy.FLAT);
}
- public SimulationConditions getConditions() {
+ public SimulationOptions getConditions() {
return conditions;
}
return atmosphereHandler;
}
return PlainTextHandler.INSTANCE;
- }
-
+ }
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) {
double d = Double.NaN;
try {
d = Double.parseDouble(content);
- } catch (NumberFormatException ignore) { }
+ } catch (NumberFormatException ignore) {
+ }
if (element.equals("configid")) {
if (Double.isNaN(d)) {
warnings.add("Illegal launch rod angle defined, ignoring.");
} else {
- conditions.setLaunchRodAngle(d*Math.PI/180);
+ conditions.setLaunchRodAngle(d * Math.PI / 180);
}
} else if (element.equals("launchroddirection")) {
if (Double.isNaN(d)) {
warnings.add("Illegal launch rod direction defined, ignoring.");
} else {
- conditions.setLaunchRodDirection(d*Math.PI/180);
+ conditions.setLaunchRodDirection(d * Math.PI / 180);
}
} else if (element.equals("windaverage")) {
if (Double.isNaN(d)) {
} else {
conditions.setLaunchLatitude(d);
}
+ } else if (element.equals("launchlongitude")) {
+ if (Double.isNaN(d)) {
+ warnings.add("Illegal launch longitude.");
+ } else {
+ conditions.setLaunchLongitude(d);
+ }
+ } else if (element.equals("geodeticmethod")) {
+ GeodeticComputationStrategy gcs =
+ (GeodeticComputationStrategy) DocumentConfig.findEnum(content, GeodeticComputationStrategy.class);
+ if (gcs != null) {
+ conditions.setGeodeticComputation(gcs);
+ } else {
+ warnings.add("Unknown geodetic computation method '" + content + "'");
+ }
} else if (element.equals("atmosphere")) {
atmosphereHandler.storeSettings(conditions, warnings);
} else if (element.equals("timestep")) {
WarningSet warnings) {
return PlainTextHandler.INSTANCE;
}
-
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) throws SAXException {
-
+
double d = Double.NaN;
try {
d = Double.parseDouble(content);
- } catch (NumberFormatException ignore) { }
+ } catch (NumberFormatException ignore) {
+ }
if (element.equals("basetemperature")) {
if (Double.isNaN(d)) {
super.closeElement(element, attributes, content, warnings);
}
}
-
- public void storeSettings(SimulationConditions cond, WarningSet warnings) {
+
+ public void storeSettings(SimulationOptions cond, WarningSet warnings) {
if (!Double.isNaN(pressure)) {
cond.setLaunchPressure(pressure);
}
if ("isa".equals(model)) {
cond.setISAAtmosphere(true);
- } else if ("extendedisa".equals(model)){
+ } else if ("extendedisa".equals(model)) {
cond.setISAAtmosphere(false);
} else {
cond.setISAAtmosphere(true);
private FlightDataBranchHandler dataHandler;
private WarningSet warningSet = new WarningSet();
private List<FlightDataBranch> branches = new ArrayList<FlightDataBranch>();
-
+
private FlightData data;
public FlightData getFlightData() {
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
if (element.equals("warning")) {
return PlainTextHandler.INSTANCE;
}
if (element.equals("databranch")) {
- if (attributes.get("name") == null || attributes.get("types")==null) {
+ if (attributes.get("name") == null || attributes.get("types") == null) {
warnings.add("Illegal flight data definition, ignoring.");
return null;
}
- dataHandler = new FlightDataBranchHandler(attributes.get("name"),
+ dataHandler = new FlightDataBranchHandler(attributes.get("name"),
attributes.get("types"));
return dataHandler;
}
- warnings.add("Unknown element '"+element+"' encountered, ignoring.");
+ warnings.add("Unknown element '" + element + "' encountered, ignoring.");
return null;
}
-
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
warningSet.add(Warning.fromString(content));
}
}
-
-
+
+
@Override
public void endHandler(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) {
-
+
if (branches.size() > 0) {
data = new FlightData(branches.toArray(new FlightDataBranch[0]));
} else {
double flightTime = Double.NaN;
double groundHitVelocity = Double.NaN;
- try {
+ try {
maxAltitude = DocumentConfig.stringToDouble(attributes.get("maxaltitude"));
- } catch (NumberFormatException ignore) { }
- try {
+ } catch (NumberFormatException ignore) {
+ }
+ try {
maxVelocity = DocumentConfig.stringToDouble(attributes.get("maxvelocity"));
- } catch (NumberFormatException ignore) { }
- try {
+ } catch (NumberFormatException ignore) {
+ }
+ try {
maxAcceleration = DocumentConfig.stringToDouble(attributes.get("maxacceleration"));
- } catch (NumberFormatException ignore) { }
- try {
+ } catch (NumberFormatException ignore) {
+ }
+ try {
maxMach = DocumentConfig.stringToDouble(attributes.get("maxmach"));
- } catch (NumberFormatException ignore) { }
- try {
+ } catch (NumberFormatException ignore) {
+ }
+ try {
timeToApogee = DocumentConfig.stringToDouble(attributes.get("timetoapogee"));
- } catch (NumberFormatException ignore) { }
- try {
+ } catch (NumberFormatException ignore) {
+ }
+ try {
flightTime = DocumentConfig.stringToDouble(attributes.get("flighttime"));
- } catch (NumberFormatException ignore) { }
- try {
- groundHitVelocity =
- DocumentConfig.stringToDouble(attributes.get("groundhitvelocity"));
- } catch (NumberFormatException ignore) { }
+ } catch (NumberFormatException ignore) {
+ }
+ try {
+ groundHitVelocity =
+ DocumentConfig.stringToDouble(attributes.get("groundhitvelocity"));
+ } 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);
+ data.immute();
}
-
+
}
class FlightDataBranchHandler extends ElementHandler {
- private final FlightDataBranch.Type[] types;
+ private final FlightDataType[] types;
private final FlightDataBranch branch;
public FlightDataBranchHandler(String name, String typeList) {
String[] split = typeList.split(",");
- types = new FlightDataBranch.Type[split.length];
- for (int i=0; i < split.length; i++) {
- types[i] = FlightDataBranch.getType(split[i], UnitGroup.UNITS_NONE);
+ types = new FlightDataType[split.length];
+ for (int i = 0; i < split.length; i++) {
+ types[i] = FlightDataType.getType(split[i], UnitGroup.UNITS_NONE);
}
// TODO: LOW: May throw an IllegalArgumentException
branch = new FlightDataBranch(name, types);
}
-
+
public FlightDataBranch getBranch() {
branch.immute();
return branch;
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
if (element.equals("datapoint"))
return PlainTextHandler.INSTANCE;
if (element.equals("event"))
return PlainTextHandler.INSTANCE;
- warnings.add("Unknown element '"+element+"' encountered, ignoring.");
+ warnings.add("Unknown element '" + element + "' encountered, ignoring.");
return null;
}
-
+
@Override
public void closeElement(String element, HashMap<String, String> attributes,
String content, WarningSet warnings) {
warnings.add("Illegal event specification, ignoring.");
return;
}
-
- branch.addEvent(time, new FlightEvent(type, time));
+
+ branch.addEvent(new FlightEvent(type, time));
return;
}
if (!element.equals("datapoint")) {
- warnings.add("Unknown element '"+element+"' encountered, ignoring.");
+ warnings.add("Unknown element '" + element + "' encountered, ignoring.");
return;
}
-
- // element == "datapoint"
+ // element == "datapoint"
+
// Check line format
String[] split = content.split(",");
if (split.length != types.length) {
// Parse the doubles
double[] values = new double[split.length];
- for (int i=0; i < values.length; i++) {
+ for (int i = 0; i < values.length; i++) {
try {
values[i] = DocumentConfig.stringToDouble(split[i]);
} catch (NumberFormatException e) {
// Add point to branch
branch.addPoint();
- for (int i=0; i < types.length; i++) {
+ for (int i = 0; i < types.length; i++) {
branch.setValue(types[i], values[i]);
}
}
-
///////////////// Setters implementation
//// StringSetter - sets the value to the contained String
class StringSetter implements Setter {
private final Reflection.Method setMethod;
-
+
public StringSetter(Reflection.Method set) {
setMethod = set;
}
-
+
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
setMethod.invoke(c, s);
//// IntSetter - set an integer value
class IntSetter implements Setter {
private final Reflection.Method setMethod;
-
+
public IntSetter(Reflection.Method set) {
setMethod = set;
}
-
+
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
try {
//// BooleanSetter - set a boolean value
class BooleanSetter implements Setter {
private final Reflection.Method setMethod;
-
+
public BooleanSetter(Reflection.Method set) {
setMethod = set;
}
-
+
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
private final String specialString;
private final Reflection.Method specialMethod;
private final double multiplier;
-
+
/**
* Set only the double value.
* @param set set method for the double value.
this.specialMethod = null;
this.multiplier = 1.0;
}
-
+
/**
* Multiply with the given multiplier and set the double value.
* @param set set method for the double value.
this.specialMethod = null;
this.multiplier = mul;
}
-
+
/**
* Set the double value, or if the value equals the special string, use the
* special setter and set it to true.
this.specialMethod = specialMethod;
this.multiplier = 1.0;
}
-
-
+
+
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
s = s.trim();
-
+
// Check for special case
if (specialMethod != null && s.equalsIgnoreCase(specialString)) {
specialMethod.invoke(c, true);
return;
}
-
+
// Normal case
try {
double d = Double.parseDouble(s);
class OverrideSetter implements Setter {
private final Reflection.Method setMethod;
private final Reflection.Method enabledMethod;
-
+
public OverrideSetter(Reflection.Method set, Reflection.Method enabledMethod) {
this.setMethod = set;
this.enabledMethod = enabledMethod;
}
-
+
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
try {
double d = Double.parseDouble(s);
setMethod.invoke(c, d);
class EnumSetter<T extends Enum<T>> implements Setter {
private final Reflection.Method setter;
private final Class<T> enumClass;
-
+
public EnumSetter(Reflection.Method set, Class<T> enumClass) {
this.setter = set;
this.enumClass = enumClass;
}
-
+
@Override
public void set(RocketComponent c, String name, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
Enum<?> setEnum = DocumentConfig.findEnum(name, enumClass);
if (setEnum == null) {
warnings.add(Warning.FILE_INVALID_PARAMETER);
return;
}
-
+
setter.invoke(c, setEnum);
}
}
//// ColorSetter - sets a Color value
class ColorSetter implements Setter {
private final Reflection.Method setMethod;
-
+
public ColorSetter(Reflection.Method set) {
setMethod = set;
}
-
+
+ @Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
-
+
String red = attributes.get("red");
String green = attributes.get("green");
String blue = attributes.get("blue");
-
+
if (red == null || green == null || blue == null) {
warnings.add(Warning.FILE_INVALID_PARAMETER);
return;
warnings.add(Warning.FILE_INVALID_PARAMETER);
return;
}
-
+
Color color = new Color(r, g, b);
setMethod.invoke(c, color);
class MaterialSetter implements Setter {
private final Reflection.Method setMethod;
private final Material.Type type;
-
+
public MaterialSetter(Reflection.Method set, Material.Type type) {
this.setMethod = set;
this.type = type;
}
-
+
+ @Override
public void set(RocketComponent c, String name, HashMap<String, String> attributes,
WarningSet warnings) {
warnings.add(Warning.fromString("Illegal material specification, ignoring."));
return;
}
-
+
// Parse thickness
-// double thickness = 0;
-// str = attributes.remove("thickness");
-// try {
-// if (str != null)
-// thickness = Double.parseDouble(str);
-// } catch (NumberFormatException e){
-// warnings.add(Warning.fromString("Illegal material specification, ignoring."));
-// return;
-// }
-
+ // double thickness = 0;
+ // str = attributes.remove("thickness");
+ // try {
+ // if (str != null)
+ // thickness = Double.parseDouble(str);
+ // } catch (NumberFormatException e){
+ // warnings.add(Warning.fromString("Illegal material specification, ignoring."));
+ // return;
+ // }
+
// Check type if specified
str = attributes.remove("type");
- if (str != null && !type.name().toLowerCase().equals(str)) {
+ if (str != null && !type.name().toLowerCase().equals(str)) {
warnings.add(Warning.fromString("Illegal material type specified, ignoring."));
return;
}
-
+
mat = Databases.findMaterial(type, name, density, false);
setMethod.invoke(c, mat);
class PositionSetter implements Setter {
-
+
+ @Override
public void set(RocketComponent c, String value, HashMap<String, String> attributes,
WarningSet warnings) {
- RocketComponent.Position type = (Position) DocumentConfig.findEnum(attributes.get("type"),
+ RocketComponent.Position type = (Position) DocumentConfig.findEnum(attributes.get("type"),
RocketComponent.Position.class);
if (type == null) {
warnings.add(Warning.FILE_INVALID_PARAMETER);
}
if (c instanceof FinSet) {
- ((FinSet)c).setRelativePosition(type);
+ ((FinSet) c).setRelativePosition(type);
c.setPositionValue(pos);
} else if (c instanceof LaunchLug) {
- ((LaunchLug)c).setRelativePosition(type);
+ ((LaunchLug) c).setRelativePosition(type);
c.setPositionValue(pos);
} else if (c instanceof InternalComponent) {
- ((InternalComponent)c).setRelativePosition(type);
+ ((InternalComponent) c).setRelativePosition(type);
c.setPositionValue(pos);
} else {
warnings.add(Warning.FILE_INVALID_PARAMETER);
class FinTabPositionSetter extends DoubleSetter {
-
+
public FinTabPositionSetter() {
- super(Reflection.findMethodStatic(FinSet.class, "setTabShift", double.class));
+ super(Reflection.findMethod(FinSet.class, "setTabShift", double.class));
}
-
+
@Override
public void set(RocketComponent c, String s, HashMap<String, String> attributes,
WarningSet warnings) {
if (!(c instanceof FinSet)) {
throw new IllegalStateException("FinTabPositionSetter called for component " + c);
}
-
+
String relative = attributes.get("relativeto");
- FinSet.TabRelativePosition position =
- (TabRelativePosition) DocumentConfig.findEnum(relative,
- FinSet.TabRelativePosition.class);
+ FinSet.TabRelativePosition position =
+ (TabRelativePosition) DocumentConfig.findEnum(relative,
+ FinSet.TabRelativePosition.class);
if (position != null) {
- ((FinSet)c).setTabRelativePosition(position);
+ ((FinSet) c).setTabRelativePosition(position);
} else {
if (relative == null) {
super.set(c, s, attributes, warnings);
}
-
+
}
class ClusterConfigurationSetter implements Setter {
-
+
+ @Override
public void set(RocketComponent component, String value, HashMap<String, String> attributes,
WarningSet warnings) {
}
ClusterConfiguration config = null;
- for (ClusterConfiguration c: ClusterConfiguration.CONFIGURATIONS) {
+ for (ClusterConfiguration c : ClusterConfiguration.CONFIGURATIONS) {
if (c.getXMLName().equals(value)) {
config = c;
break;
return;
}
- ((Clusterable)component).setClusterConfiguration(config);
+ ((Clusterable) component).setClusterConfiguration(config);
}
}
-
-