diff --git a/core/resources/datafiles/thrustcurves/thrustcurves.ser b/core/resources/datafiles/thrustcurves/thrustcurves.ser index 57c3662a3..940a7da86 100644 Binary files a/core/resources/datafiles/thrustcurves/thrustcurves.ser and b/core/resources/datafiles/thrustcurves/thrustcurves.ser differ diff --git a/core/src/net/sf/openrocket/motor/Motor.java b/core/src/net/sf/openrocket/motor/Motor.java index ae9199251..61d4eb4f1 100644 --- a/core/src/net/sf/openrocket/motor/Motor.java +++ b/core/src/net/sf/openrocket/motor/Motor.java @@ -74,6 +74,28 @@ public interface Motor { public Type getMotorType(); + /** + * Return the motor code + * + * @return the code + */ + public String getCode(); + + /** + * Return the common name of the motor. + * + * @return the common name + */ + public String getCommonName(); + + /** + * Return the common name of the motor, including a delay. + * + * @param delay the delay of the motor. + * @return common name with delay. + */ + public String getCommonName(double delay); + /** * Return the designation of the motor. * diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java index 8d269344c..d5256d186 100644 --- a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java @@ -4,6 +4,8 @@ import java.io.Serializable; import java.text.Collator; import java.util.Arrays; import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,7 +35,10 @@ public class ThrustCurveMotor implements Motor, Comparable, Se private String digest = ""; private Manufacturer manufacturer = Manufacturer.getManufacturer("Unknown"); + private String code = ""; + private String commonName = ""; private String designation = ""; + private String description = ""; private Motor.Type type = Motor.Type.UNKNOWN; private double[] delays = {}; @@ -74,6 +79,16 @@ public class ThrustCurveMotor implements Motor, Comparable, Se motor.description = d; return this; } + + public Builder setCode(String c) { + motor.code = c; + return this; + } + + public Builder setCommonName(String n) { + motor.commonName = n; + return this; + } public Builder setDesignation(String d) { motor.designation = d; @@ -130,10 +145,28 @@ public class ThrustCurveMotor implements Motor, Comparable, Se return this; } - public Builder setAvailablity(boolean avail) { + public Builder setAvailability(boolean avail) { motor.available = avail; return this; } + + /** + * Simplify a motor designation, if possible. This attempts to reduce the designation + * into a simple letter + number notation for the impulse class and average thrust. + * + * @param str the designation to simplify + * @return the simplified designation, or the string itself if the format was not detected + */ + private static final Pattern SIMPLIFY_PATTERN = Pattern.compile("^[0-9]*[ -]*([A-Z][0-9]+).*"); + static String simplifyDesignation(String str) { + str = str.trim(); + Matcher m = SIMPLIFY_PATTERN.matcher(str); + if (m.matches()) { + return m.group(1); + } else { + return str.replaceAll("\\s", ""); + } + } public ThrustCurveMotor build() { // Check argument validity @@ -202,6 +235,19 @@ public class ThrustCurveMotor implements Motor, Comparable, Se motor.unitRotationalInertia = Inertia.filledCylinderRotational( motor.diameter / 2); motor.unitLongitudinalInertia = Inertia.filledCylinderLongitudinal( motor.diameter / 2, motor.length); + // If I don't have a motor designation (will be the case if I read the thrustcurve from a file) + // use the motor code + if (motor.designation.equals("")) { + motor.designation = motor.code; + } + + // If I don't have a motor common name (will be the case if I read the thrustcurve from a flle) + // apply the motor code simplification heuristics to generate a common name + if (motor.commonName.equals("")) { + motor.commonName = motor.designation; + } + + motor.computeStatistics(); return motor; @@ -440,6 +486,21 @@ public class ThrustCurveMotor implements Motor, Comparable, Se public double getUnitIzz(){ return this.unitLongitudinalInertia; } + + @Override + public String getCode() { + return code; + } + + @Override + public String getCommonName() { + return commonName; + } + + @Override + public String getCommonName(double delay) { + return commonName + "-" + getDelayString(delay); + } @Override public String getDesignation() { diff --git a/core/src/net/sf/openrocket/thrustcurve/SerializeThrustcurveMotors.java b/core/src/net/sf/openrocket/thrustcurve/SerializeThrustcurveMotors.java index 2299898dc..d900802bd 100644 --- a/core/src/net/sf/openrocket/thrustcurve/SerializeThrustcurveMotors.java +++ b/core/src/net/sf/openrocket/thrustcurve/SerializeThrustcurveMotors.java @@ -133,14 +133,12 @@ public class SerializeThrustcurveMotors { builder.setDiameter(mi.getDiameter() / 1000.0); builder.setLength(mi.getLength() / 1000.0); builder.setMotorType(type); + + builder.setCommonName(mi.getCommon_name()); + builder.setDesignation(mi.getDesignation()); - if ("OOP".equals(mi.getAvailiability())) { - builder.setDesignation(mi.getDesignation()); - builder.setAvailablity(false); - } else if (mi.getDesignation().startsWith("Micro")) { - builder.setDesignation(mi.getDesignation()); - } else { - builder.setDesignation(mi.getCommon_name()); + if ("OOP".equals(mi.getAvailability())) { + builder.setAvailability(false); } allMotors.add(builder.build()); diff --git a/core/src/net/sf/openrocket/thrustcurve/TCMotor.java b/core/src/net/sf/openrocket/thrustcurve/TCMotor.java index e9e645fca..9ce3bed90 100644 --- a/core/src/net/sf/openrocket/thrustcurve/TCMotor.java +++ b/core/src/net/sf/openrocket/thrustcurve/TCMotor.java @@ -270,7 +270,7 @@ public class TCMotor implements Cloneable { this.updated_on = updated_on; } - public String getAvailiability() { + public String getAvailability() { return availability; }