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
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
--- /dev/null
+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