Square grain
authorBill Kuker <bkuker@billkuker.com>
Tue, 14 Feb 2012 18:41:46 +0000 (18:41 +0000)
committerBill Kuker <bkuker@billkuker.com>
Tue, 14 Feb 2012 18:41:46 +0000 (18:41 +0000)
Thanks Louis Schreyer (info@aquarix.de)

gui/com/billkuker/rocketry/motorsim/visual/workbench/MotorEditor.java
src/com/billkuker/rocketry/motorsim/grain/Square.java [new file with mode: 0644]

index 9264cf209fcadcda0113524b08c2ac9c116b63c8..303e7aa33b8f818cfa5fd121d27cf6b49278e468 100644 (file)
@@ -58,6 +58,7 @@ import com.billkuker.rocketry.motorsim.grain.Moonburner;
 import com.billkuker.rocketry.motorsim.grain.MultiGrain;\r
 import com.billkuker.rocketry.motorsim.grain.MultiPort;\r
 import com.billkuker.rocketry.motorsim.grain.RodAndTubeGrain;\r
+import com.billkuker.rocketry.motorsim.grain.Square;\r
 import com.billkuker.rocketry.motorsim.grain.Star;\r
 import com.billkuker.rocketry.motorsim.visual.BurnPanel;\r
 import com.billkuker.rocketry.motorsim.visual.ClassChooser;\r
@@ -120,6 +121,7 @@ public class MotorEditor extends JPanel implements PropertyChangeListener, FuelR
                grainTypes.add(CSlot.class);\r
                grainTypes.add(EndBurner.class);\r
                grainTypes.add(MultiPort.class);\r
+               grainTypes.add(Square.class);\r
        }\r
        \r
        private List<Class<? extends Chamber>> chamberTypes = new Vector<Class<? extends Chamber>>();\r
diff --git a/src/com/billkuker/rocketry/motorsim/grain/Square.java b/src/com/billkuker/rocketry/motorsim/grain/Square.java
new file mode 100644 (file)
index 0000000..2fba8a1
--- /dev/null
@@ -0,0 +1,79 @@
+package com.billkuker.rocketry.motorsim.grain;\r
+\r
+import java.awt.Shape;\r
+import java.awt.geom.Ellipse2D;\r
+import java.awt.geom.Rectangle2D;\r
+import java.beans.PropertyVetoException;\r
+\r
+import javax.measure.quantity.Length;\r
+import javax.measure.unit.SI;\r
+\r
+import org.jscience.physics.amount.Amount;\r
+\r
+import com.billkuker.rocketry.motorsim.Validating;\r
+import com.billkuker.rocketry.motorsim.grain.util.BurningShape;\r
+import com.billkuker.rocketry.motorsim.grain.util.ExtrudedShapeGrain;\r
+\r
+public class Square extends ExtrudedShapeGrain implements Validating {\r
+       private Amount<Length> oD = Amount.valueOf(30, SI.MILLIMETER);\r
+       private Amount<Length> side = Amount.valueOf(10, SI.MILLIMETER);\r
+\r
+       \r
+       public Square(){\r
+               try {\r
+                       setLength(Amount.valueOf(70, SI.MILLIMETER));\r
+               } catch (PropertyVetoException e) {\r
+                       e.printStackTrace();\r
+               }\r
+               generateGeometry();\r
+       }\r
+       \r
+       private void generateGeometry(){\r
+               double odmm = oD.doubleValue(SI.MILLIMETER);\r
+               double sidemm = side.doubleValue(SI.MILLIMETER);\r
+               \r
+               xsection = new BurningShape();\r
+               Shape outside = new Ellipse2D.Double(-odmm/2.0, -odmm/2.0, odmm, odmm);\r
+               xsection.add(outside);\r
+               xsection.inhibit(outside);\r
+               webThickness = null;\r
+               \r
+               Rectangle2D r = new Rectangle2D.Double(-sidemm/2.0, -sidemm/2.0, sidemm, sidemm);\r
+               xsection.subtract(r);\r
+\r
+       }\r
+       \r
+       public Amount<Length> getOD() {\r
+               return oD;\r
+       }\r
+\r
+       public void setOD(Amount<Length> od) throws PropertyVetoException {\r
+               if (od.equals(this.oD))\r
+                       return;\r
+               this.oD = od;\r
+               generateGeometry();\r
+       }\r
+\r
+       public Amount<Length> getCoreSide() {\r
+               return side;\r
+       }\r
+\r
+       public void setCoreSide(Amount<Length> side) throws PropertyVetoException {\r
+               if (side.equals(this.side))\r
+                       return;\r
+               this.side = side;\r
+               generateGeometry();\r
+       }\r
+       \r
+\r
+       \r
+       @Override\r
+       public void validate() throws ValidationException{\r
+               if ( side.equals(Amount.ZERO) )\r
+                       throw new ValidationException(this, "Invalid side");\r
+               if ( oD.equals(Amount.ZERO) )\r
+                       throw new ValidationException(this, "Invalid oD");\r
+               if ( getLength().equals(Amount.ZERO) )\r
+                       throw new ValidationException(this, "Invalid Length");\r
+       }\r
+}\r