[#1315] Update auto length in MassObject
This commit is contained in:
parent
2b8515a321
commit
bc69df1483
@ -13,7 +13,7 @@ public class MassObjectSaver extends InternalComponentSaver {
|
|||||||
|
|
||||||
MassObject mass = (MassObject) c;
|
MassObject mass = (MassObject) c;
|
||||||
|
|
||||||
elements.add("<packedlength>" + mass.getLength() + "</packedlength>");
|
elements.add("<packedlength>" + mass.getLengthNoAuto() + "</packedlength>");
|
||||||
if (mass.isRadiusAutomatic()) {
|
if (mass.isRadiusAutomatic()) {
|
||||||
elements.add("<packedradius>auto " + mass.getRadiusNoAuto() + "</packedradius>");
|
elements.add("<packedradius>auto " + mass.getRadiusNoAuto() + "</packedradius>");
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,6 +12,7 @@ import net.sf.openrocket.file.rocksim.RocksimLocationMode;
|
|||||||
import net.sf.openrocket.file.rocksim.importt.BaseHandler;
|
import net.sf.openrocket.file.rocksim.importt.BaseHandler;
|
||||||
import net.sf.openrocket.rocketcomponent.ExternalComponent;
|
import net.sf.openrocket.rocketcomponent.ExternalComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.FinSet;
|
import net.sf.openrocket.rocketcomponent.FinSet;
|
||||||
|
import net.sf.openrocket.rocketcomponent.MassObject;
|
||||||
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
|
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
|
||||||
import net.sf.openrocket.rocketcomponent.RingComponent;
|
import net.sf.openrocket.rocketcomponent.RingComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
@ -83,7 +84,7 @@ public abstract class BasePartDTO {
|
|||||||
setKnownCG(ec.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
|
setKnownCG(ec.getOverrideCGX() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
|
||||||
setKnownMass(ec.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS);
|
setKnownMass(ec.getMass() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS);
|
||||||
|
|
||||||
if (! (ec instanceof FinSet)) {
|
if (!(ec instanceof FinSet || ec instanceof MassObject)) {
|
||||||
setLen(ec.getLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
|
setLen(ec.getLength() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
|
||||||
}
|
}
|
||||||
setUseKnownCG(ec.isCGOverridden() || ec.isMassOverridden() ? 1 : 0);
|
setUseKnownCG(ec.isCGOverridden() || ec.isMassOverridden() ? 1 : 0);
|
||||||
@ -146,6 +147,10 @@ public abstract class BasePartDTO {
|
|||||||
setRadialAngle(rc.getRadialDirection());
|
setRadialAngle(rc.getRadialDirection());
|
||||||
setRadialLoc(rc.getRadialPosition() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
|
setRadialLoc(rc.getRadialPosition() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ec instanceof MassObject) {
|
||||||
|
setLen(((MassObject)ec).getLengthNoAuto() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getKnownMass() {
|
public Double getKnownMass() {
|
||||||
|
@ -50,7 +50,21 @@ public abstract class MassObject extends InternalComponent {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getLength() {
|
||||||
|
if (this.autoRadius) {
|
||||||
|
// Calculate the parachute volume using the non auto radius and the non auto length, and transform that back
|
||||||
|
// to the auto radius situation to get the auto radius length (the volume in both situations is the same).
|
||||||
|
double parachuteVolume = Math.pow(this.radius, 2) * this.length; // Math.PI left out, not needed
|
||||||
|
return parachuteVolume / Math.pow(getRadius(), 2);
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLengthNoAuto() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
public void setLength(double length) {
|
public void setLength(double length) {
|
||||||
for (RocketComponent listener : configListeners) {
|
for (RocketComponent listener : configListeners) {
|
||||||
if (listener instanceof MassObject) {
|
if (listener instanceof MassObject) {
|
||||||
@ -59,10 +73,17 @@ public abstract class MassObject extends InternalComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
length = Math.max(length, 0);
|
length = Math.max(length, 0);
|
||||||
if (MathUtil.equals(this.length, length)) {
|
if (this.autoRadius) {
|
||||||
return;
|
// Calculate the parachute volume using the auto radius and the new "auto" length, and transform that back
|
||||||
|
// to the non auto radius situation to set this.length (the volume in both situations is the same).
|
||||||
|
double parachuteVolume = Math.pow(getRadius(), 2) * length; // Math.PI left out, not needed
|
||||||
|
this.length = parachuteVolume / Math.pow(this.radius, 2);
|
||||||
|
} else {
|
||||||
|
if (MathUtil.equals(this.length, length)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.length = length;
|
||||||
}
|
}
|
||||||
this.length = length;
|
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +135,8 @@ public abstract class MassObject extends InternalComponent {
|
|||||||
|
|
||||||
public void setRadiusAutomatic(boolean auto) {
|
public void setRadiusAutomatic(boolean auto) {
|
||||||
for (RocketComponent listener : configListeners) {
|
for (RocketComponent listener : configListeners) {
|
||||||
if (listener instanceof Parachute) {
|
if (listener instanceof MassObject) {
|
||||||
((Parachute) listener).setRadiusAutomatic(auto);
|
((MassObject) listener).setRadiusAutomatic(auto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +145,10 @@ public abstract class MassObject extends InternalComponent {
|
|||||||
|
|
||||||
autoRadius = auto;
|
autoRadius = auto;
|
||||||
|
|
||||||
|
// Set the length
|
||||||
|
double parachuteVolume = (Math.PI * Math.pow(getRadius(), 2) * length);
|
||||||
|
length = parachuteVolume / (Math.PI * Math.pow(getRadius(), 2));
|
||||||
|
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,6 @@ public class Parachute extends RecoveryDevice {
|
|||||||
private int lineCount;
|
private int lineCount;
|
||||||
private final double DEFAULT_LINE_LENGTH = 0.3;
|
private final double DEFAULT_LINE_LENGTH = 0.3;
|
||||||
private double lineLength;
|
private double lineLength;
|
||||||
private final double InitialPackedLength = this.length;
|
|
||||||
private final double InitialPackedRadius = this.radius;
|
|
||||||
|
|
||||||
public Parachute() {
|
public Parachute() {
|
||||||
this.diameter = DEFAULT_DIAMETER;
|
this.diameter = DEFAULT_DIAMETER;
|
||||||
@ -213,23 +211,15 @@ public class Parachute extends RecoveryDevice {
|
|||||||
|
|
||||||
// // Set preset parachute packed length
|
// // Set preset parachute packed length
|
||||||
if ((preset.has(ComponentPreset.PACKED_LENGTH)) && preset.get(ComponentPreset.PACKED_LENGTH) > 0) {
|
if ((preset.has(ComponentPreset.PACKED_LENGTH)) && preset.get(ComponentPreset.PACKED_LENGTH) > 0) {
|
||||||
this.PackedLength = preset.get(ComponentPreset.PACKED_LENGTH);
|
length = preset.get(ComponentPreset.PACKED_LENGTH);
|
||||||
length = PackedLength;
|
|
||||||
} else {
|
|
||||||
length = InitialPackedLength;
|
|
||||||
}
|
}
|
||||||
// // Set preset parachute packed diameter
|
// // Set preset parachute packed diameter
|
||||||
if ((preset.has(ComponentPreset.PACKED_DIAMETER)) && preset.get(ComponentPreset.PACKED_DIAMETER) > 0) {
|
if ((preset.has(ComponentPreset.PACKED_DIAMETER)) && preset.get(ComponentPreset.PACKED_DIAMETER) > 0) {
|
||||||
this.PackedDiameter = preset.get(ComponentPreset.PACKED_DIAMETER);
|
radius = preset.get(ComponentPreset.PACKED_DIAMETER) / 2;
|
||||||
radius = PackedDiameter / 2;
|
|
||||||
} else {
|
|
||||||
radius = InitialPackedRadius;
|
|
||||||
}
|
}
|
||||||
// // Size parachute packed diameter within parent inner diameter
|
// // 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);
|
|
||||||
setRadiusAutomatic(true);
|
setRadiusAutomatic(true);
|
||||||
length = parachuteVolume / (Math.PI * Math.pow(getRadius(), 2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SUBSTITUTE / ACTIVATE Override Mass Preset
|
// SUBSTITUTE / ACTIVATE Override Mass Preset
|
||||||
|
@ -19,9 +19,6 @@ import net.sf.openrocket.util.MathUtil;
|
|||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
public abstract class RecoveryDevice extends MassObject implements FlightConfigurableComponent {
|
public abstract class RecoveryDevice extends MassObject implements FlightConfigurableComponent {
|
||||||
////
|
|
||||||
protected double PackedDiameter;
|
|
||||||
protected double PackedLength;
|
|
||||||
////
|
////
|
||||||
protected double DragCoefficient;
|
protected double DragCoefficient;
|
||||||
protected double cd = Parachute.DEFAULT_CD;
|
protected double cd = Parachute.DEFAULT_CD;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user