ThrustCurveMotor now includes both common name and designation
If both are not available (which is the case when loading from a file rather than from thrustcurve.org) use motor code for designation, and simplified designation for common name
This commit is contained in:
parent
31f52cec18
commit
08f76683e9
Binary file not shown.
@ -74,6 +74,28 @@ public interface Motor {
|
|||||||
public Type getMotorType();
|
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.
|
* Return the designation of the motor.
|
||||||
*
|
*
|
||||||
|
@ -4,6 +4,8 @@ import java.io.Serializable;
|
|||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -33,7 +35,10 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
|
|||||||
private String digest = "";
|
private String digest = "";
|
||||||
|
|
||||||
private Manufacturer manufacturer = Manufacturer.getManufacturer("Unknown");
|
private Manufacturer manufacturer = Manufacturer.getManufacturer("Unknown");
|
||||||
|
private String code = "";
|
||||||
|
private String commonName = "";
|
||||||
private String designation = "";
|
private String designation = "";
|
||||||
|
|
||||||
private String description = "";
|
private String description = "";
|
||||||
private Motor.Type type = Motor.Type.UNKNOWN;
|
private Motor.Type type = Motor.Type.UNKNOWN;
|
||||||
private double[] delays = {};
|
private double[] delays = {};
|
||||||
@ -75,6 +80,16 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
|
|||||||
return this;
|
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) {
|
public Builder setDesignation(String d) {
|
||||||
motor.designation = d;
|
motor.designation = d;
|
||||||
return this;
|
return this;
|
||||||
@ -130,11 +145,29 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setAvailablity(boolean avail) {
|
public Builder setAvailability(boolean avail) {
|
||||||
motor.available = avail;
|
motor.available = avail;
|
||||||
return this;
|
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() {
|
public ThrustCurveMotor build() {
|
||||||
// Check argument validity
|
// Check argument validity
|
||||||
if ((motor.time.length != motor.thrust.length) || (motor.time.length != motor.cg.length)) {
|
if ((motor.time.length != motor.thrust.length) || (motor.time.length != motor.cg.length)) {
|
||||||
@ -202,6 +235,19 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
|
|||||||
motor.unitRotationalInertia = Inertia.filledCylinderRotational( motor.diameter / 2);
|
motor.unitRotationalInertia = Inertia.filledCylinderRotational( motor.diameter / 2);
|
||||||
motor.unitLongitudinalInertia = Inertia.filledCylinderLongitudinal( motor.diameter / 2, motor.length);
|
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();
|
motor.computeStatistics();
|
||||||
|
|
||||||
return motor;
|
return motor;
|
||||||
@ -441,6 +487,21 @@ public class ThrustCurveMotor implements Motor, Comparable<ThrustCurveMotor>, Se
|
|||||||
return this.unitLongitudinalInertia;
|
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
|
@Override
|
||||||
public String getDesignation() {
|
public String getDesignation() {
|
||||||
return designation;
|
return designation;
|
||||||
|
@ -134,13 +134,11 @@ public class SerializeThrustcurveMotors {
|
|||||||
builder.setLength(mi.getLength() / 1000.0);
|
builder.setLength(mi.getLength() / 1000.0);
|
||||||
builder.setMotorType(type);
|
builder.setMotorType(type);
|
||||||
|
|
||||||
if ("OOP".equals(mi.getAvailiability())) {
|
builder.setCommonName(mi.getCommon_name());
|
||||||
builder.setDesignation(mi.getDesignation());
|
builder.setDesignation(mi.getDesignation());
|
||||||
builder.setAvailablity(false);
|
|
||||||
} else if (mi.getDesignation().startsWith("Micro")) {
|
if ("OOP".equals(mi.getAvailability())) {
|
||||||
builder.setDesignation(mi.getDesignation());
|
builder.setAvailability(false);
|
||||||
} else {
|
|
||||||
builder.setDesignation(mi.getCommon_name());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allMotors.add(builder.build());
|
allMotors.add(builder.build());
|
||||||
|
@ -270,7 +270,7 @@ public class TCMotor implements Cloneable {
|
|||||||
this.updated_on = updated_on;
|
this.updated_on = updated_on;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAvailiability() {
|
public String getAvailability() {
|
||||||
return availability;
|
return availability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user