1d6e475cf16064803d19755b8024de380d04211e
[sw/motorsim] / src / com / billkuker / rocketry / motorsim / grain / EndBurner.java
1 package com.billkuker.rocketry.motorsim.grain;
2
3 import java.awt.geom.Rectangle2D;
4 import java.beans.PropertyChangeEvent;
5 import java.beans.PropertyChangeListener;
6
7 import javax.measure.quantity.Length;
8 import javax.measure.unit.SI;
9
10 import org.jscience.physics.amount.Amount;
11
12 import com.billkuker.rocketry.motorsim.Validating;
13 import com.billkuker.rocketry.motorsim.Validating.ValidationException;
14 import com.billkuker.rocketry.motorsim.grain.util.BurningShape;
15 import com.billkuker.rocketry.motorsim.grain.util.RotatedShapeGrain;
16
17 public class EndBurner extends RotatedShapeGrain implements Validating {
18
19         private Amount<Length> length = Amount.valueOf(70, SI.MILLIMETER);
20         private Amount<Length> oD = Amount.valueOf(30, SI.MILLIMETER);
21         private Amount<Length> puntDiameter = Amount.valueOf(10, SI.MILLIMETER);
22         private Amount<Length> puntDepth = Amount.valueOf(10, SI.MILLIMETER);
23         
24         private void generateGeometry(){
25                 double len = length.doubleValue(SI.MILLIMETER);
26                 double od = oD.doubleValue(SI.MILLIMETER);
27                 double pdi = puntDiameter.doubleValue(SI.MILLIMETER);
28                 double plen = puntDepth.doubleValue(SI.MILLIMETER);
29                 
30                 Rectangle2D.Double grain, punt, end;
31                 grain = new Rectangle2D.Double(0,0,od/2.0,len);
32                 punt = new Rectangle2D.Double(0,len-plen, pdi/2.0, plen);
33                 end = new Rectangle2D.Double(0,len,od,0);
34                 
35                 shape = new BurningShape();
36                 web = null;
37                 
38                 shape.add(grain);
39                 shape.inhibit(grain);
40                 shape.subtract(punt);
41                 shape.subtract(end);
42         }
43         
44         public EndBurner(){
45                 this.addPropertyChangeListener(new PropertyChangeListener(){
46                         @Override
47                         public void propertyChange(PropertyChangeEvent evt) {
48                                 generateGeometry();
49                         }});
50                 generateGeometry();
51         }
52         
53         @Override
54         public void validate() throws ValidationException {
55                 if ( oD.equals(Amount.ZERO) )
56                         throw new ValidationException(this, "Invalid oD");
57                 if ( getLength().equals(Amount.ZERO) )
58                         throw new ValidationException(this, "Invalid Length");
59                 if ( puntDiameter.isGreaterThan(oD) )
60                         throw new ValidationException(this, "puntDiameter > oD");
61                 if ( puntDepth.isGreaterThan(length) )
62                         throw new ValidationException(this, "puntDepth > length");
63         }
64
65         public Amount<Length> getLength() {
66                 return length;
67         }
68
69         public void setLength(Amount<Length> length) {
70                 this.length = length;
71         }
72
73         public Amount<Length> getOD() {
74                 return oD;
75         }
76
77         public void setOD(Amount<Length> oD) {
78                 this.oD = oD;
79         }
80
81         public Amount<Length> getPuntDiameter() {
82                 return puntDiameter;
83         }
84
85         public void setPuntDiameter(Amount<Length> puntDiameter) {
86                 this.puntDiameter = puntDiameter;
87         }
88
89         public Amount<Length> getPuntDepth() {
90                 return puntDepth;
91         }
92
93         public void setPuntDepth(Amount<Length> puntDepth) {
94                 this.puntDepth = puntDepth;
95         }
96
97 }