Changed motorIO from files to streams
[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         private Amount<Length> slotOffset = Amount.valueOf(0, SI.MILLIMETER);\r
26 \r
27         public CSlot(){\r
28                 try {\r
29                         setLength(Amount.valueOf(70, SI.MILLIMETER));\r
30                 } catch (PropertyVetoException e) {\r
31                         e.printStackTrace();\r
32                 }\r
33                 generateGeometry();\r
34         }\r
35 \r
36         public Amount<Length> getOD() {\r
37                 return oD;\r
38         }\r
39 \r
40         public void setOD(Amount<Length> od) throws PropertyVetoException {\r
41                 this.oD = od;\r
42                 generateGeometry();\r
43         }\r
44         \r
45         public Amount<Length> getSlotWidth() {\r
46                 return slotWidth;\r
47         }\r
48 \r
49         public void setSlotWidth(Amount<Length> slotWidth) {\r
50                 this.slotWidth = slotWidth;\r
51                 generateGeometry();\r
52         }\r
53 \r
54         public Amount<Length> getSlotDepth() {\r
55                 return slotDepth;\r
56         }\r
57 \r
58         public void setSlotDepth(Amount<Length> slotDepth) {\r
59                 this.slotDepth = slotDepth;\r
60                 generateGeometry();\r
61         }\r
62 \r
63         public Amount<Length> getSlotOffset() {\r
64                 return slotOffset;\r
65         }\r
66 \r
67         public void setSlotOffset(Amount<Length> slotOffset) {\r
68                 this.slotOffset = slotOffset;\r
69                 generateGeometry();\r
70         }\r
71 \r
72         private void generateGeometry() {\r
73                 double odmm = oD.doubleValue(SI.MILLIMETER);\r
74                 double wmm = slotWidth.doubleValue(SI.MILLIMETER);\r
75                 double dmm = slotDepth.doubleValue(SI.MILLIMETER);\r
76                 xsection = new BurningShape();\r
77                 Shape outside = new Ellipse2D.Double(0, 0, odmm, odmm);\r
78                 xsection.add(outside);\r
79                 xsection.inhibit(outside);\r
80                 \r
81                 double offmm = slotOffset.doubleValue(SI.MILLIMETER);\r
82                 \r
83                 double ymm = odmm/2.0 - wmm/2.0 - offmm; //The Y position of the slot\r
84                 double xmm = odmm - dmm; //X pos of slot\r
85                 Rectangle2D.Double slot;\r
86                 slot = new Rectangle2D.Double(xmm, ymm, dmm, wmm);\r
87                 xsection.subtract(slot);\r
88                 \r
89                 double idmm = iD.doubleValue(SI.MILLIMETER);\r
90                 double idymm = odmm/2.0 - idmm/2.0 - offmm; //y pos of id\r
91                 double idxmm = xmm - idmm/2.0; //x pos of id\r
92                 Ellipse2D.Double id = new Ellipse2D.Double(idxmm, idymm, idmm, idmm);\r
93                 xsection.subtract(id);\r
94                 \r
95                 webThickness = null;\r
96         }\r
97         \r
98         public Amount<Length> getID() {\r
99                 return iD;\r
100         }\r
101 \r
102         public void setID(Amount<Length> id) {\r
103                 iD = id;\r
104                 generateGeometry();\r
105         }\r
106 \r
107         public static void main(String args[]) throws Exception {\r
108                 CSlot e = new CSlot();\r
109                 new Editor(e).showAsWindow();\r
110                 new GrainPanel(e).showAsWindow();\r
111         }\r
112         \r
113         public void validate() throws ValidationException{\r
114                 if ( oD.equals(Amount.ZERO) )\r
115                         throw new ValidationException(this, "Invalid oD");\r
116                 if ( getLength().equals(Amount.ZERO) )\r
117                         throw new ValidationException(this, "Invalid Length");\r
118         }\r
119 \r
120 }\r