create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / rocketcomponent / Parachute.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.material.Material;
5 import net.sf.openrocket.preset.ComponentPreset;
6 import net.sf.openrocket.preset.ComponentPreset.Type;
7 import net.sf.openrocket.startup.Application;
8 import net.sf.openrocket.util.MathUtil;
9
10 public class Parachute extends RecoveryDevice {
11         private static final Translator trans = Application.getTranslator();
12         
13         public static final double DEFAULT_CD = 0.8;
14         
15         private double diameter;
16         
17         private Material lineMaterial;
18         private int lineCount = 6;
19         private double lineLength = 0.3;
20         
21         
22         public Parachute() {
23                 this.diameter = 0.3;
24                 this.lineMaterial = Application.getPreferences().getDefaultComponentMaterial(Parachute.class, Material.Type.LINE);
25                 this.lineLength = 0.3;
26         }
27         
28         
29         public double getDiameter() {
30                 return diameter;
31         }
32         
33         public void setDiameter(double d) {
34                 if (MathUtil.equals(this.diameter, d))
35                         return;
36                 this.diameter = d;
37                 clearPreset();
38                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
39         }
40         
41         
42         public final Material getLineMaterial() {
43                 return lineMaterial;
44         }
45         
46         public final void setLineMaterial(Material mat) {
47                 if (mat.getType() != Material.Type.LINE) {
48                         throw new IllegalArgumentException("Attempted to set non-line material " + mat);
49                 }
50                 if (mat.equals(lineMaterial))
51                         return;
52                 this.lineMaterial = mat;
53                 if (getLineCount() != 0)
54                         fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
55                 else
56                         fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
57         }
58         
59         
60         public final int getLineCount() {
61                 return lineCount;
62         }
63         
64         public final void setLineCount(int n) {
65                 if (this.lineCount == n)
66                         return;
67                 this.lineCount = n;
68                 clearPreset();
69                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
70         }
71         
72         public final double getLineLength() {
73                 return lineLength;
74         }
75         
76         public final void setLineLength(double length) {
77                 if (MathUtil.equals(this.lineLength, length))
78                         return;
79                 this.lineLength = length;
80                 if (getLineCount() != 0)
81                         fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
82                 else
83                         fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
84         }
85         
86         
87         @Override
88         public double getComponentCD(double mach) {
89                 return DEFAULT_CD; // TODO: HIGH:  Better parachute CD estimate?
90         }
91         
92         @Override
93         public double getArea() {
94                 return Math.PI * MathUtil.pow2(diameter / 2);
95         }
96         
97         public void setArea(double area) {
98                 if (MathUtil.equals(getArea(), area))
99                         return;
100                 diameter = MathUtil.safeSqrt(area / Math.PI) * 2;
101                 clearPreset();
102                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
103         }
104         
105         @Override
106         public double getComponentMass() {
107                 return super.getComponentMass() +
108                                 getLineCount() * getLineLength() * getLineMaterial().getDensity();
109         }
110         
111         @Override
112         public String getComponentName() {
113                 //// Parachute
114                 return trans.get("Parachute.Parachute");
115         }
116         
117         @Override
118         public boolean allowsChildren() {
119                 return false;
120         }
121         
122         @Override
123         public boolean isCompatible(Class<? extends RocketComponent> type) {
124                 return false;
125         }
126
127
128         @Override
129         protected void loadFromPreset(ComponentPreset preset) {
130                 if( preset.has( ComponentPreset.DIAMETER )) {
131                         this.diameter = preset.get( ComponentPreset.DIAMETER );
132                 }
133                 if( preset.has( ComponentPreset.LINE_COUNT )) {
134                         this.lineCount = preset.get( ComponentPreset.LINE_COUNT );
135                 }
136                 if( preset.has( ComponentPreset.LINE_LENGTH )) {
137                         this.lineLength = preset.get( ComponentPreset.LINE_LENGTH );
138                 }
139                 if( preset.has( ComponentPreset.LINE_MATERIAL )) {
140                         this.lineMaterial = preset.get( ComponentPreset.LINE_MATERIAL );
141                 }
142                 super.loadFromPreset(preset);
143         }
144
145
146         @Override
147         public Type getPresetType() {
148                 return ComponentPreset.Type.PARACHUTE;
149         }
150         
151 }