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 {
|
public class Parachute extends RecoveryDevice {
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
private final double DEFAULT_DIAMETER = 0.3;
|
||||||
public static double DEFAULT_CD = 0.8;
|
|
||||||
|
|
||||||
private double diameter;
|
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 InitialPackedLength = this.length;
|
||||||
private final double InitialPackedRadius = this.radius;
|
private final double InitialPackedRadius = this.radius;
|
||||||
|
|
||||||
private Material lineMaterial;
|
|
||||||
private int lineCount = 6;
|
|
||||||
private double lineLength = 0.3;
|
|
||||||
|
|
||||||
public Parachute() {
|
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);
|
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_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
|
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() {
|
public double getDiameter() {
|
||||||
return diameter;
|
return diameter;
|
||||||
@ -38,7 +47,6 @@ public class Parachute extends RecoveryDevice {
|
|||||||
((Parachute) listener).setDiameter(d);
|
((Parachute) listener).setDiameter(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MathUtil.equals(this.diameter, d))
|
if (MathUtil.equals(this.diameter, d))
|
||||||
return;
|
return;
|
||||||
this.diameter = d;
|
this.diameter = d;
|
||||||
@ -46,30 +54,28 @@ public class Parachute extends RecoveryDevice {
|
|||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public final Material getLineMaterial() {
|
public double getArea() {
|
||||||
return lineMaterial;
|
return Math.PI * MathUtil.pow2(diameter / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setLineMaterial(Material mat) {
|
public void setArea(double area) {
|
||||||
for (RocketComponent listener : configListeners) {
|
for (RocketComponent listener : configListeners) {
|
||||||
if (listener instanceof Parachute) {
|
if (listener instanceof Parachute) {
|
||||||
((Parachute) listener).setLineMaterial(mat);
|
((Parachute) listener).setArea(area);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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;
|
return;
|
||||||
this.lineMaterial = mat;
|
diameter = MathUtil.safeSqrt(area / Math.PI) * 2;
|
||||||
if (getLineCount() != 0)
|
clearPreset();
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||||
else
|
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getComponentCD(double mach) {
|
||||||
|
return cd; // TODO: HIGH: Better parachute CD estimate?
|
||||||
|
}
|
||||||
|
|
||||||
public final int getLineCount() {
|
public final int getLineCount() {
|
||||||
return lineCount;
|
return lineCount;
|
||||||
@ -81,7 +87,6 @@ public class Parachute extends RecoveryDevice {
|
|||||||
((Parachute) listener).setLineCount(n);
|
((Parachute) listener).setLineCount(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lineCount == n)
|
if (this.lineCount == n)
|
||||||
return;
|
return;
|
||||||
this.lineCount = n;
|
this.lineCount = n;
|
||||||
@ -99,39 +104,39 @@ public class Parachute extends RecoveryDevice {
|
|||||||
((Parachute) listener).setLineLength(length);
|
((Parachute) listener).setLineLength(length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MathUtil.equals(this.lineLength, length))
|
if (MathUtil.equals(this.lineLength, length))
|
||||||
return;
|
return;
|
||||||
this.lineLength = length;
|
this.lineLength = length;
|
||||||
if (getLineCount() != 0)
|
if (getLineCount() != 0) {
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||||
else
|
clearPreset();
|
||||||
|
} else {
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getComponentCD(double mach) {
|
|
||||||
return DEFAULT_CD; // TODO: HIGH: Better parachute CD estimate?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public final Material getLineMaterial() {
|
||||||
public double getArea() {
|
return lineMaterial;
|
||||||
return Math.PI * MathUtil.pow2(diameter / 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArea(double area) {
|
public final void setLineMaterial(Material mat) {
|
||||||
for (RocketComponent listener : configListeners) {
|
for (RocketComponent listener : configListeners) {
|
||||||
if (listener instanceof Parachute) {
|
if (listener instanceof Parachute) {
|
||||||
((Parachute) listener).setArea(area);
|
((Parachute) listener).setLineMaterial(mat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mat.getType() != Material.Type.LINE) {
|
||||||
if (MathUtil.equals(getArea(), area))
|
throw new IllegalArgumentException("Attempted to set non-line material " + mat);
|
||||||
|
}
|
||||||
|
if (mat.equals(lineMaterial))
|
||||||
return;
|
return;
|
||||||
diameter = MathUtil.safeSqrt(area / Math.PI) * 2;
|
this.lineMaterial = mat;
|
||||||
|
if (getLineCount() != 0) {
|
||||||
clearPreset();
|
clearPreset();
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -140,12 +145,6 @@ public class Parachute extends RecoveryDevice {
|
|||||||
getLineCount() * getLineLength() * getLineMaterial().getDensity();
|
getLineCount() * getLineLength() * getLineMaterial().getDensity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getComponentName() {
|
|
||||||
//// Parachute
|
|
||||||
return trans.get("Parachute.Parachute");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allowsChildren() {
|
public boolean allowsChildren() {
|
||||||
return false;
|
return false;
|
||||||
@ -156,11 +155,11 @@ public class Parachute extends RecoveryDevice {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadFromPreset(ComponentPreset preset) {
|
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)) {
|
if (preset.has(ComponentPreset.DESCRIPTION)) {
|
||||||
String temporaryName = preset.get(ComponentPreset.DESCRIPTION);
|
String temporaryName = preset.get(ComponentPreset.DESCRIPTION);
|
||||||
int size = temporaryName.length();
|
int size = temporaryName.length();
|
||||||
@ -172,89 +171,76 @@ public class Parachute extends RecoveryDevice {
|
|||||||
} else {
|
} else {
|
||||||
this.name = getComponentName();
|
this.name = getComponentName();
|
||||||
}
|
}
|
||||||
// END Substitute parachute description for component name
|
// // Set preset parachute diameter
|
||||||
|
if ((preset.has(ComponentPreset.DIAMETER)) && preset.get(ComponentPreset.DIAMETER) > 0) {
|
||||||
if (preset.has(ComponentPreset.DIAMETER)) {
|
|
||||||
this.diameter = preset.get(ComponentPreset.DIAMETER);
|
this.diameter = preset.get(ComponentPreset.DIAMETER);
|
||||||
|
} else {
|
||||||
|
this.diameter = DEFAULT_DIAMETER;
|
||||||
}
|
}
|
||||||
|
// // Set preset parachute drag coefficient
|
||||||
// BEGIN Implement parachute cd
|
if ((preset.has(ComponentPreset.PARACHUTE_CD)) && preset.get(ComponentPreset.PARACHUTE_CD) > 0){
|
||||||
if (preset.has(ComponentPreset.PARACHUTE_CD)) {
|
|
||||||
if (preset.get(ComponentPreset.PARACHUTE_CD) > 0) {
|
|
||||||
cdAutomatic = false;
|
cdAutomatic = false;
|
||||||
cd = preset.get(ComponentPreset.PARACHUTE_CD);
|
cd = preset.get(ComponentPreset.PARACHUTE_CD);
|
||||||
}
|
|
||||||
else {
|
|
||||||
cdAutomatic = true;
|
|
||||||
cd = Parachute.DEFAULT_CD;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
cdAutomatic = true;
|
cdAutomatic = true;
|
||||||
cd = Parachute.DEFAULT_CD;
|
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
|
// // Set preset parachute packed length
|
||||||
//// BEGIN Implement parachute packed length
|
if ((preset.has(ComponentPreset.PACKED_LENGTH)) && preset.get(ComponentPreset.PACKED_LENGTH) > 0) {
|
||||||
if (preset.has(ComponentPreset.PACKED_LENGTH)) {
|
|
||||||
this.PackedLength = preset.get(ComponentPreset.PACKED_LENGTH);
|
this.PackedLength = preset.get(ComponentPreset.PACKED_LENGTH);
|
||||||
if (PackedLength > 0) {
|
|
||||||
length = PackedLength;
|
length = PackedLength;
|
||||||
}
|
|
||||||
else {
|
|
||||||
length = InitialPackedLength;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
length = InitialPackedLength;
|
length = InitialPackedLength;
|
||||||
}
|
}
|
||||||
//// END Implement parachute packed length
|
// // Set preset parachute packed diameter
|
||||||
//// BEGIN Implement parachute packed diameter
|
if ((preset.has(ComponentPreset.PACKED_DIAMETER)) && preset.get(ComponentPreset.PACKED_DIAMETER) > 0) {
|
||||||
if (preset.has(ComponentPreset.PACKED_DIAMETER)) {
|
|
||||||
this.PackedDiameter = preset.get(ComponentPreset.PACKED_DIAMETER);
|
this.PackedDiameter = preset.get(ComponentPreset.PACKED_DIAMETER);
|
||||||
if (PackedDiameter > 0) {
|
|
||||||
radius = PackedDiameter / 2;
|
radius = PackedDiameter / 2;
|
||||||
}
|
|
||||||
if (PackedDiameter <= 0) {
|
|
||||||
radius = InitialPackedRadius;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
radius = InitialPackedRadius;
|
radius = InitialPackedRadius;
|
||||||
}
|
}
|
||||||
//// END Implement parachute packed diameter
|
// // Size parachute packed diameter within parent inner diameter
|
||||||
//// BEGIN Size parachute packed diameter within parent inner diameter
|
|
||||||
if (length > 0 && radius > 0) {
|
if (length > 0 && radius > 0) {
|
||||||
double parachuteVolume = (Math.PI * Math.pow(radius, 2) * length);
|
double parachuteVolume = (Math.PI * Math.pow(radius, 2) * length);
|
||||||
setRadiusAutomatic(true);
|
setRadiusAutomatic(true);
|
||||||
length = parachuteVolume / (Math.PI * Math.pow(getRadius(), 2));
|
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
|
// SUBSTITUTE / ACTIVATE Override Mass Preset
|
||||||
if (preset.has(ComponentPreset.MASS)) {
|
if ((preset.has(ComponentPreset.MASS))&& (preset.get(ComponentPreset.MASS)) > 0){
|
||||||
this.overrideMass = (preset.get(ComponentPreset.MASS));
|
this.overrideMass = (preset.get(ComponentPreset.MASS));
|
||||||
if (overrideMass > 0) {
|
|
||||||
massOverridden = true;
|
massOverridden = true;
|
||||||
} else {
|
} else {
|
||||||
this.overrideMass = 0;
|
this.overrideMass = 0;
|
||||||
massOverridden = false;
|
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);
|
super.loadFromPreset(preset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,19 +20,22 @@ import net.sf.openrocket.util.MathUtil;
|
|||||||
*/
|
*/
|
||||||
public abstract class RecoveryDevice extends MassObject implements FlightConfigurableComponent {
|
public abstract class RecoveryDevice extends MassObject implements FlightConfigurableComponent {
|
||||||
////
|
////
|
||||||
protected double DragCoefficient;
|
|
||||||
protected double PackedDiameter;
|
protected double PackedDiameter;
|
||||||
protected double PackedLength;
|
protected double PackedLength;
|
||||||
////
|
////
|
||||||
|
protected double DragCoefficient;
|
||||||
protected double cd = Parachute.DEFAULT_CD;
|
protected double cd = Parachute.DEFAULT_CD;
|
||||||
protected boolean cdAutomatic = true;
|
protected boolean cdAutomatic = true;
|
||||||
|
////
|
||||||
|
private final Material.Surface defaultMaterial;
|
||||||
private Material.Surface material;
|
private Material.Surface material;
|
||||||
|
|
||||||
private FlightConfigurableParameterSet<DeploymentConfiguration> deploymentConfigurations;
|
private FlightConfigurableParameterSet<DeploymentConfiguration> deploymentConfigurations;
|
||||||
|
|
||||||
public RecoveryDevice() {
|
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));
|
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 abstract double getComponentCD(double mach);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public double getCD() {
|
public double getCD() {
|
||||||
return getCD(0);
|
return getCD(0);
|
||||||
}
|
}
|
||||||
@ -63,6 +64,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
|||||||
return;
|
return;
|
||||||
this.cd = cd;
|
this.cd = cd;
|
||||||
this.cdAutomatic = false;
|
this.cdAutomatic = false;
|
||||||
|
clearPreset();
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,9 +130,19 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadFromPreset(ComponentPreset preset) {
|
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)) {
|
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);
|
Material m = preset.get(ComponentPreset.MATERIAL);
|
||||||
this.material = (Material.Surface) m;
|
this.material = (Material.Surface) m;
|
||||||
|
} else {
|
||||||
|
this.material = defaultMaterial;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.material = defaultMaterial;
|
||||||
}
|
}
|
||||||
super.loadFromPreset(preset);
|
super.loadFromPreset(preset);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user