Merge pull request #1371 from hcraigmiller/Cd-Code-Correction
Improve parachute preset code/gui
This commit is contained in:
commit
6b5982c6aa
@ -9,24 +9,33 @@ import net.sf.openrocket.util.MathUtil;
|
||||
|
||||
public class Parachute extends RecoveryDevice {
|
||||
private static final Translator trans = Application.getTranslator();
|
||||
|
||||
public static double DEFAULT_CD = 0.8;
|
||||
|
||||
private final double DEFAULT_DIAMETER = 0.3;
|
||||
private double diameter;
|
||||
public static double DEFAULT_CD = 0.8;
|
||||
private final Material DEFAULT_LINE_MATERIAL;
|
||||
private Material lineMaterial;
|
||||
private final int DEFAULT_LINE_COUNT = 6;
|
||||
private int lineCount;
|
||||
private final double DEFAULT_LINE_LENGTH = 0.3;
|
||||
private double lineLength;
|
||||
private final double InitialPackedLength = this.length;
|
||||
private final double InitialPackedRadius = this.radius;
|
||||
|
||||
private Material lineMaterial;
|
||||
private int lineCount = 6;
|
||||
private double lineLength = 0.3;
|
||||
|
||||
public Parachute() {
|
||||
this.diameter = 0.3;
|
||||
this.diameter = DEFAULT_DIAMETER;
|
||||
lineCount = DEFAULT_LINE_COUNT;
|
||||
lineLength = DEFAULT_LINE_LENGTH;
|
||||
this.lineMaterial = Application.getPreferences().getDefaultComponentMaterial(Parachute.class, Material.Type.LINE);
|
||||
DEFAULT_LINE_MATERIAL = lineMaterial;
|
||||
super.displayOrder_side = 11; // Order for displaying the component in the 2D side view
|
||||
super.displayOrder_back = 9; // Order for displaying the component in the 2D back view
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentName() {
|
||||
//// Parachute
|
||||
return trans.get("Parachute.Parachute");
|
||||
}
|
||||
|
||||
public double getDiameter() {
|
||||
return diameter;
|
||||
@ -38,7 +47,6 @@ public class Parachute extends RecoveryDevice {
|
||||
((Parachute) listener).setDiameter(d);
|
||||
}
|
||||
}
|
||||
|
||||
if (MathUtil.equals(this.diameter, d))
|
||||
return;
|
||||
this.diameter = d;
|
||||
@ -46,30 +54,28 @@ public class Parachute extends RecoveryDevice {
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
}
|
||||
|
||||
|
||||
public final Material getLineMaterial() {
|
||||
return lineMaterial;
|
||||
@Override
|
||||
public double getArea() {
|
||||
return Math.PI * MathUtil.pow2(diameter / 2);
|
||||
}
|
||||
|
||||
public final void setLineMaterial(Material mat) {
|
||||
public void setArea(double area) {
|
||||
for (RocketComponent listener : configListeners) {
|
||||
if (listener instanceof Parachute) {
|
||||
((Parachute) listener).setLineMaterial(mat);
|
||||
((Parachute) listener).setArea(area);
|
||||
}
|
||||
}
|
||||
|
||||
if (mat.getType() != Material.Type.LINE) {
|
||||
throw new IllegalArgumentException("Attempted to set non-line material " + mat);
|
||||
}
|
||||
if (mat.equals(lineMaterial))
|
||||
if (MathUtil.equals(getArea(), area))
|
||||
return;
|
||||
this.lineMaterial = mat;
|
||||
if (getLineCount() != 0)
|
||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||
else
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
diameter = MathUtil.safeSqrt(area / Math.PI) * 2;
|
||||
clearPreset();
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getComponentCD(double mach) {
|
||||
return cd; // TODO: HIGH: Better parachute CD estimate?
|
||||
}
|
||||
|
||||
public final int getLineCount() {
|
||||
return lineCount;
|
||||
@ -81,7 +87,6 @@ public class Parachute extends RecoveryDevice {
|
||||
((Parachute) listener).setLineCount(n);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.lineCount == n)
|
||||
return;
|
||||
this.lineCount = n;
|
||||
@ -99,39 +104,39 @@ public class Parachute extends RecoveryDevice {
|
||||
((Parachute) listener).setLineLength(length);
|
||||
}
|
||||
}
|
||||
|
||||
if (MathUtil.equals(this.lineLength, length))
|
||||
return;
|
||||
this.lineLength = length;
|
||||
if (getLineCount() != 0)
|
||||
if (getLineCount() != 0) {
|
||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||
else
|
||||
clearPreset();
|
||||
} else {
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getComponentCD(double mach) {
|
||||
return DEFAULT_CD; // TODO: HIGH: Better parachute CD estimate?
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return Math.PI * MathUtil.pow2(diameter / 2);
|
||||
public final Material getLineMaterial() {
|
||||
return lineMaterial;
|
||||
}
|
||||
|
||||
public void setArea(double area) {
|
||||
public final void setLineMaterial(Material mat) {
|
||||
for (RocketComponent listener : configListeners) {
|
||||
if (listener instanceof Parachute) {
|
||||
((Parachute) listener).setArea(area);
|
||||
((Parachute) listener).setLineMaterial(mat);
|
||||
}
|
||||
}
|
||||
|
||||
if (MathUtil.equals(getArea(), area))
|
||||
if (mat.getType() != Material.Type.LINE) {
|
||||
throw new IllegalArgumentException("Attempted to set non-line material " + mat);
|
||||
}
|
||||
if (mat.equals(lineMaterial))
|
||||
return;
|
||||
diameter = MathUtil.safeSqrt(area / Math.PI) * 2;
|
||||
this.lineMaterial = mat;
|
||||
if (getLineCount() != 0) {
|
||||
clearPreset();
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||
}
|
||||
else
|
||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -140,12 +145,6 @@ public class Parachute extends RecoveryDevice {
|
||||
getLineCount() * getLineLength() * getLineMaterial().getDensity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentName() {
|
||||
//// Parachute
|
||||
return trans.get("Parachute.Parachute");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsChildren() {
|
||||
return false;
|
||||
@ -156,11 +155,11 @@ public class Parachute extends RecoveryDevice {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void loadFromPreset(ComponentPreset preset) {
|
||||
|
||||
// BEGIN Substitute parachute description for component name
|
||||
// SUBSTITUTE preset parachute values for existing component values
|
||||
// // Set preset parachute description
|
||||
if (preset.has(ComponentPreset.DESCRIPTION)) {
|
||||
String temporaryName = preset.get(ComponentPreset.DESCRIPTION);
|
||||
int size = temporaryName.length();
|
||||
@ -172,89 +171,76 @@ public class Parachute extends RecoveryDevice {
|
||||
} else {
|
||||
this.name = getComponentName();
|
||||
}
|
||||
// END Substitute parachute description for component name
|
||||
|
||||
if (preset.has(ComponentPreset.DIAMETER)) {
|
||||
// // Set preset parachute diameter
|
||||
if ((preset.has(ComponentPreset.DIAMETER)) && preset.get(ComponentPreset.DIAMETER) > 0) {
|
||||
this.diameter = preset.get(ComponentPreset.DIAMETER);
|
||||
} else {
|
||||
this.diameter = DEFAULT_DIAMETER;
|
||||
}
|
||||
|
||||
// BEGIN Implement parachute cd
|
||||
if (preset.has(ComponentPreset.PARACHUTE_CD)) {
|
||||
if (preset.get(ComponentPreset.PARACHUTE_CD) > 0) {
|
||||
// // Set preset parachute drag coefficient
|
||||
if ((preset.has(ComponentPreset.PARACHUTE_CD)) && preset.get(ComponentPreset.PARACHUTE_CD) > 0){
|
||||
cdAutomatic = false;
|
||||
cd = preset.get(ComponentPreset.PARACHUTE_CD);
|
||||
}
|
||||
else {
|
||||
cdAutomatic = true;
|
||||
cd = Parachute.DEFAULT_CD;
|
||||
}
|
||||
} else {
|
||||
cdAutomatic = true;
|
||||
cd = Parachute.DEFAULT_CD;
|
||||
}
|
||||
// END Implement parachute cd
|
||||
// // Set preset parachute line count
|
||||
if ((preset.has(ComponentPreset.LINE_COUNT)) && preset.get(ComponentPreset.LINE_COUNT) > 0) {
|
||||
this.lineCount = preset.get(ComponentPreset.LINE_COUNT);
|
||||
} else {
|
||||
this.lineCount = DEFAULT_LINE_COUNT;
|
||||
}
|
||||
// // Set preset parachute line length
|
||||
if ((preset.has(ComponentPreset.LINE_LENGTH)) && preset.get(ComponentPreset.LINE_LENGTH) > 0) {
|
||||
this.lineLength = preset.get(ComponentPreset.LINE_LENGTH);
|
||||
} else {
|
||||
this.lineLength = DEFAULT_LINE_LENGTH;
|
||||
}
|
||||
// // Set preset parachute line material
|
||||
// NEED a better way to set preset if field is empty ----
|
||||
if ((preset.has(ComponentPreset.LINE_MATERIAL))) {
|
||||
String lineMaterialEmpty = preset.get(ComponentPreset.LINE_MATERIAL).toString();
|
||||
int count = lineMaterialEmpty.length();
|
||||
if (count > 12 ) {
|
||||
this.lineMaterial = preset.get(ComponentPreset.LINE_MATERIAL);
|
||||
} else {
|
||||
this.lineMaterial = DEFAULT_LINE_MATERIAL;
|
||||
}
|
||||
} else {
|
||||
this.lineMaterial = DEFAULT_LINE_MATERIAL;
|
||||
}
|
||||
|
||||
// BEGIN Implement parachute length, diameter, and volume
|
||||
//// BEGIN Implement parachute packed length
|
||||
if (preset.has(ComponentPreset.PACKED_LENGTH)) {
|
||||
// // Set preset parachute packed length
|
||||
if ((preset.has(ComponentPreset.PACKED_LENGTH)) && preset.get(ComponentPreset.PACKED_LENGTH) > 0) {
|
||||
this.PackedLength = preset.get(ComponentPreset.PACKED_LENGTH);
|
||||
if (PackedLength > 0) {
|
||||
length = PackedLength;
|
||||
}
|
||||
else {
|
||||
length = InitialPackedLength;
|
||||
}
|
||||
} else {
|
||||
length = InitialPackedLength;
|
||||
}
|
||||
//// END Implement parachute packed length
|
||||
//// BEGIN Implement parachute packed diameter
|
||||
if (preset.has(ComponentPreset.PACKED_DIAMETER)) {
|
||||
// // Set preset parachute packed diameter
|
||||
if ((preset.has(ComponentPreset.PACKED_DIAMETER)) && preset.get(ComponentPreset.PACKED_DIAMETER) > 0) {
|
||||
this.PackedDiameter = preset.get(ComponentPreset.PACKED_DIAMETER);
|
||||
if (PackedDiameter > 0) {
|
||||
radius = PackedDiameter / 2;
|
||||
}
|
||||
if (PackedDiameter <= 0) {
|
||||
radius = InitialPackedRadius;
|
||||
}
|
||||
} else {
|
||||
radius = InitialPackedRadius;
|
||||
}
|
||||
//// END Implement parachute packed diameter
|
||||
//// BEGIN Size parachute packed diameter within parent inner diameter
|
||||
// // Size parachute packed diameter within parent inner diameter
|
||||
if (length > 0 && radius > 0) {
|
||||
double parachuteVolume = (Math.PI * Math.pow(radius, 2) * length);
|
||||
setRadiusAutomatic(true);
|
||||
length = parachuteVolume / (Math.PI * Math.pow(getRadius(), 2));
|
||||
|
||||
}
|
||||
//// END Size parachute packed diameter within parent inner diameter
|
||||
// END Implement parachute length, diameter, and volume
|
||||
|
||||
// BEGIN Activate Override Mass Preset
|
||||
if (preset.has(ComponentPreset.MASS)) {
|
||||
// SUBSTITUTE / ACTIVATE Override Mass Preset
|
||||
if ((preset.has(ComponentPreset.MASS))&& (preset.get(ComponentPreset.MASS)) > 0){
|
||||
this.overrideMass = (preset.get(ComponentPreset.MASS));
|
||||
if (overrideMass > 0) {
|
||||
massOverridden = true;
|
||||
} else {
|
||||
this.overrideMass = 0;
|
||||
massOverridden = false;
|
||||
}
|
||||
} else {
|
||||
this.overrideMass = 0;
|
||||
massOverridden = false;
|
||||
}
|
||||
// END Activate Override Mass Preset
|
||||
|
||||
if (preset.has(ComponentPreset.LINE_COUNT)) {
|
||||
this.lineCount = preset.get(ComponentPreset.LINE_COUNT);
|
||||
}
|
||||
if (preset.has(ComponentPreset.LINE_LENGTH)) {
|
||||
this.lineLength = preset.get(ComponentPreset.LINE_LENGTH);
|
||||
}
|
||||
if (preset.has(ComponentPreset.LINE_MATERIAL)) {
|
||||
this.lineMaterial = preset.get(ComponentPreset.LINE_MATERIAL);
|
||||
}
|
||||
super.loadFromPreset(preset);
|
||||
}
|
||||
|
||||
|
@ -20,19 +20,22 @@ import net.sf.openrocket.util.MathUtil;
|
||||
*/
|
||||
public abstract class RecoveryDevice extends MassObject implements FlightConfigurableComponent {
|
||||
////
|
||||
protected double DragCoefficient;
|
||||
protected double PackedDiameter;
|
||||
protected double PackedLength;
|
||||
////
|
||||
protected double DragCoefficient;
|
||||
protected double cd = Parachute.DEFAULT_CD;
|
||||
protected boolean cdAutomatic = true;
|
||||
|
||||
////
|
||||
private final Material.Surface defaultMaterial;
|
||||
private Material.Surface material;
|
||||
|
||||
private FlightConfigurableParameterSet<DeploymentConfiguration> deploymentConfigurations;
|
||||
|
||||
public RecoveryDevice() {
|
||||
this.deploymentConfigurations = new FlightConfigurableParameterSet<DeploymentConfiguration>( new DeploymentConfiguration());
|
||||
this.deploymentConfigurations =
|
||||
new FlightConfigurableParameterSet<DeploymentConfiguration>( new DeploymentConfiguration());
|
||||
defaultMaterial = (Material.Surface) Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE);
|
||||
setMaterial(Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE));
|
||||
}
|
||||
|
||||
@ -40,8 +43,6 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
||||
|
||||
public abstract double getComponentCD(double mach);
|
||||
|
||||
|
||||
|
||||
public double getCD() {
|
||||
return getCD(0);
|
||||
}
|
||||
@ -63,6 +64,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
||||
return;
|
||||
this.cd = cd;
|
||||
this.cdAutomatic = false;
|
||||
clearPreset();
|
||||
fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
|
||||
}
|
||||
|
||||
@ -128,9 +130,19 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
||||
|
||||
@Override
|
||||
protected void loadFromPreset(ComponentPreset preset) {
|
||||
// // Set preset parachute line material
|
||||
// NEED a better way to set preset if field is empty ----
|
||||
if (preset.has(ComponentPreset.MATERIAL)) {
|
||||
String surfaceMaterialEmpty = preset.get(ComponentPreset.MATERIAL).toString();
|
||||
int count = surfaceMaterialEmpty.length();
|
||||
if (count > 12 ) {
|
||||
Material m = preset.get(ComponentPreset.MATERIAL);
|
||||
this.material = (Material.Surface) m;
|
||||
} else {
|
||||
this.material = defaultMaterial;
|
||||
}
|
||||
} else {
|
||||
this.material = defaultMaterial;
|
||||
}
|
||||
super.loadFromPreset(preset);
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user