1 package net.sf.openrocket.rocketcomponent;
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.material.Material;
5 import net.sf.openrocket.simulation.FlightEvent;
6 import net.sf.openrocket.startup.Application;
7 import net.sf.openrocket.util.MathUtil;
8 import net.sf.openrocket.util.Pair;
12 * RecoveryDevice is a class representing devices that slow down descent.
13 * Recovery devices report that they have no aerodynamic effect, since they
14 * are within the rocket during ascent.
16 * A recovery device includes a surface material of which it is made of.
17 * The mass of the component is calculated based on the material and the
18 * area of the device from {@link #getArea()}. {@link #getComponentMass()}
19 * may be overridden if additional mass needs to be included.
21 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
23 public abstract class RecoveryDevice extends MassObject {
24 private static final Translator trans = Application.getTranslator();
26 public static enum DeployEvent {
27 //// Launch (plus NN seconds)
28 LAUNCH(trans.get("RecoveryDevice.DeployEvent.LAUNCH")) {
30 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
31 return e.getType() == FlightEvent.Type.LAUNCH;
34 //// First ejection charge of this stage
35 EJECTION(trans.get("RecoveryDevice.DeployEvent.EJECTION")) {
37 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
38 if (e.getType() != FlightEvent.Type.EJECTION_CHARGE)
40 RocketComponent charge = e.getSource();
41 return charge.getStageNumber() == source.getStageNumber();
45 APOGEE(trans.get("RecoveryDevice.DeployEvent.APOGEE")) {
47 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
48 return e.getType() == FlightEvent.Type.APOGEE;
51 //// Specific altitude during descent
52 ALTITUDE(trans.get("RecoveryDevice.DeployEvent.ALTITUDE")) {
53 @SuppressWarnings("unchecked")
55 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
56 if (e.getType() != FlightEvent.Type.ALTITUDE)
59 double alt = ((RecoveryDevice)source).getDeployAltitude();
60 Pair<Double,Double> altitude = (Pair<Double,Double>)e.getData();
62 return (altitude.getU() >= alt) && (altitude.getV() <= alt);
66 NEVER(trans.get("RecoveryDevice.DeployEvent.NEVER")) {
68 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
74 private final String description;
76 DeployEvent(String description) {
77 this.description = description;
80 public abstract boolean isActivationEvent(FlightEvent e, RocketComponent source);
83 public String toString() {
90 private DeployEvent deployEvent = DeployEvent.EJECTION;
91 private double deployAltitude = 200;
92 private double deployDelay = 0;
94 private double cd = Parachute.DEFAULT_CD;
95 private boolean cdAutomatic = true;
98 private Material.Surface material;
101 public RecoveryDevice() {
102 this(Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE));
105 public RecoveryDevice(Material material) {
107 setMaterial(material);
110 public RecoveryDevice(double length, double radius, Material material) {
111 super(length, radius);
112 setMaterial(material);
118 public abstract double getArea();
120 public abstract double getComponentCD(double mach);
124 public double getCD() {
128 public double getCD(double mach) {
130 cd = getComponentCD(mach);
134 public void setCD(double cd) {
135 if (MathUtil.equals(this.cd, cd) && !isCDAutomatic())
138 this.cdAutomatic = false;
139 fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
143 public boolean isCDAutomatic() {
147 public void setCDAutomatic(boolean auto) {
148 if (cdAutomatic == auto)
150 this.cdAutomatic = auto;
151 fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
156 public final Material getMaterial() {
160 public final void setMaterial(Material mat) {
161 if (!(mat instanceof Material.Surface)) {
162 throw new IllegalArgumentException("Attempted to set non-surface material "+mat);
164 if (mat.equals(material))
166 this.material = (Material.Surface)mat;
167 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
173 public DeployEvent getDeployEvent() {
177 public void setDeployEvent(DeployEvent deployEvent) {
178 if (this.deployEvent == deployEvent)
180 this.deployEvent = deployEvent;
181 fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
185 public double getDeployAltitude() {
186 return deployAltitude;
189 public void setDeployAltitude(double deployAltitude) {
190 if (MathUtil.equals(this.deployAltitude, deployAltitude))
192 this.deployAltitude = deployAltitude;
193 if (getDeployEvent() == DeployEvent.ALTITUDE)
194 fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
196 fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
200 public double getDeployDelay() {
204 public void setDeployDelay(double delay) {
205 delay = MathUtil.max(delay, 0);
206 if (MathUtil.equals(this.deployDelay, delay))
208 this.deployDelay = delay;
209 fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
215 public double getComponentMass() {
216 return getArea() * getMaterial().getDensity();