Changed default motor to fit default grains
[sw/motorsim] / src / com / billkuker / rocketry / motorsim / grain / CSlot.java
1 package com.billkuker.rocketry.motorsim.grain;\r
2 \r
3 import java.awt.Shape;\r
4 import java.awt.geom.Ellipse2D;\r
5 import java.awt.geom.Rectangle2D;\r
6 import java.beans.PropertyVetoException;\r
7 \r
8 import javax.measure.quantity.Length;\r
9 import javax.measure.unit.SI;\r
10 \r
11 import org.jscience.physics.amount.Amount;\r
12 \r
13 import com.billkuker.rocketry.motorsim.Validating;\r
14 import com.billkuker.rocketry.motorsim.grain.util.BurningShape;\r
15 import com.billkuker.rocketry.motorsim.grain.util.ExtrudedShapeGrain;\r
16 import com.billkuker.rocketry.motorsim.visual.Editor;\r
17 import com.billkuker.rocketry.motorsim.visual.GrainPanel;\r
18 \r
19 public class CSlot extends ExtrudedShapeGrain implements Validating {\r
20 \r
21         private Amount<Length> oD = Amount.valueOf(30, SI.MILLIMETER);\r
22         private Amount<Length> iD = Amount.valueOf(0, SI.MILLIMETER);\r
23         private Amount<Length> slotWidth = Amount.valueOf(5, SI.MILLIMETER);\r
24         private Amount<Length> slotDepth = Amount.valueOf(15, SI.MILLIMETER);\r
25         \r
26         public CSlot(){\r
27                 try {\r
28                         setLength(Amount.valueOf(70, SI.MILLIMETER));\r
29                 } catch (PropertyVetoException e) {\r
30                         e.printStackTrace();\r
31                 }\r
32                 generateGeometry();\r
33         }\r
34 \r
35         public Amount<Length> getOD() {\r
36                 return oD;\r
37         }\r
38 \r
39         public void setOD(Amount<Length> od) throws PropertyVetoException {\r
40                 this.oD = od;\r
41                 generateGeometry();\r
42         }\r
43         \r
44         public Amount<Length> getSlotWidth() {\r
45                 return slotWidth;\r
46         }\r
47 \r
48         public void setSlotWidth(Amount<Length> slotWidth) {\r
49                 this.slotWidth = slotWidth;\r
50                 generateGeometry();\r
51         }\r
52 \r
53         public Amount<Length> getSlotDepth() {\r
54                 return slotDepth;\r
55         }\r
56 \r
57         public void setSlotDepth(Amount<Length> slotDepth) {\r
58                 this.slotDepth = slotDepth;\r
59                 generateGeometry();\r
60         }\r
61 \r
62 \r
63 \r
64 \r
65         private void generateGeometry() {\r
66                 double odmm = oD.doubleValue(SI.MILLIMETER);\r
67                 double wmm = slotWidth.doubleValue(SI.MILLIMETER);\r
68                 double dmm = slotDepth.doubleValue(SI.MILLIMETER);\r
69                 xsection = new BurningShape();\r
70                 Shape outside = new Ellipse2D.Double(0, 0, odmm, odmm);\r
71                 xsection.add(outside);\r
72                 xsection.inhibit(outside);\r
73                 \r
74                 double ymm = odmm/2.0 - wmm/2.0; //The Y position of the slot\r
75                 double xmm = odmm - dmm;\r
76                 Rectangle2D.Double slot;\r
77                 slot = new Rectangle2D.Double(xmm, ymm, dmm, wmm);\r
78                 xsection.subtract(slot);\r
79                 \r
80                 double idmm = iD.doubleValue(SI.MILLIMETER);\r
81                 double idymm = odmm/2.0 - idmm/2.0;\r
82                 double idxmm = xmm - idmm/2.0;\r
83                 Ellipse2D.Double id = new Ellipse2D.Double(idxmm, idymm, idmm, idmm);\r
84                 xsection.subtract(id);\r
85                 \r
86                 webThickness = null;\r
87         }\r
88         \r
89         public Amount<Length> getID() {\r
90                 return iD;\r
91         }\r
92 \r
93         public void setID(Amount<Length> id) {\r
94                 iD = id;\r
95                 generateGeometry();\r
96         }\r
97 \r
98         public static void main(String args[]) throws Exception {\r
99                 CSlot e = new CSlot();\r
100                 new Editor(e).showAsWindow();\r
101                 new GrainPanel(e).showAsWindow();\r
102         }\r
103         \r
104         public void validate() throws ValidationException{\r
105                 if ( oD.equals(Amount.ZERO) )\r
106                         throw new ValidationException(this, "Invalid oD");\r
107                 if ( getLength().equals(Amount.ZERO) )\r
108                         throw new ValidationException(this, "Invalid Length");\r
109         }\r
110 \r
111 }\r