From: Bill Kuker Date: Wed, 15 Apr 2009 20:00:43 +0000 (+0000) Subject: Added DEFAULT_GRAIN to grain types. When possible these should all be the same grain. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=cc777874078cf599e580a5fd2ead9d82b79a769f;p=sw%2Fmotorsim Added DEFAULT_GRAIN to grain types. When possible these should all be the same grain. --- diff --git a/src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java b/src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java index f0d94f6..78d5fbf 100644 --- a/src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java +++ b/src/com/billkuker/rocketry/motorsim/grain/CoredCylindricalGrain.java @@ -21,9 +21,24 @@ public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Va private Amount oD, iD; private boolean outerSurfaceInhibited = true, innerSurfaceInhibited = false; + + public static CoredCylindricalGrain DEFAULT_GRAIN = new CoredCylindricalGrain(){ + { + try{ + setOD(Amount.valueOf(30, SI.MILLIMETER)); + setID(Amount.valueOf(10, SI.MILLIMETER)); + setLength(Amount.valueOf(70, SI.MILLIMETER)); + setInnerSurfaceInhibited(false); + setOuterSurfaceInhibited(true); + setForeEndInhibited(false); + setAftEndInhibited(false); + } catch ( Exception e ){ + throw new Error(e); + } + } + }; public CoredCylindricalGrain() { - oD = Amount.valueOf(30, SI.MILLIMETER); iD = Amount.valueOf(10, SI.MILLIMETER); } @@ -249,11 +264,9 @@ public class CoredCylindricalGrain extends ExtrudedGrain implements MotorPart.Va } public static void main(String args[]) throws Exception { - CoredCylindricalGrain e = new CoredCylindricalGrain(); + CoredCylindricalGrain e = DEFAULT_GRAIN; new Editor(e).show(); new GrainPanel(e).show(); } - - } diff --git a/src/com/billkuker/rocketry/motorsim/grain/ExtrudedShapeGrain.java b/src/com/billkuker/rocketry/motorsim/grain/ExtrudedShapeGrain.java index ef00d4a..0378dcb 100644 --- a/src/com/billkuker/rocketry/motorsim/grain/ExtrudedShapeGrain.java +++ b/src/com/billkuker/rocketry/motorsim/grain/ExtrudedShapeGrain.java @@ -19,6 +19,21 @@ import com.billkuker.rocketry.motorsim.visual.Editor; import com.billkuker.rocketry.motorsim.visual.GrainPanel; public class ExtrudedShapeGrain extends MotorPart implements Grain { + + public static ExtrudedShapeGrain DEFAULT_GRAIN = new ExtrudedShapeGrain(){ + { + try{ + Shape outside = new Ellipse2D.Double(0, 0, 30, 30); + xsection.add(outside); + xsection.inhibit(outside); + xsection.subtract(new Ellipse2D.Double(10,10, 10, 10)); + setLength(Amount.valueOf(70, SI.MILLIMETER)); + setEndSurfaceInhibited(false); + } catch ( Exception e ){ + throw new Error(e); + } + } + }; BurningShape xsection = new BurningShape(); @@ -30,33 +45,6 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain { Amount webThickness; - { - /* - * Similar test grain Shape outside = new Ellipse2D.Double(50,50,30,30); - * plus.add(outside); minus.add(new Ellipse2D.Double(50,60,10,10)); - * inhibited.add(outside); length = Amount.valueOf(70, SI.MILLIMETER); / - */ - - /* Big c-slot */ - Shape outside = new Ellipse2D.Double(0, 0, 30, 30); - xsection.add(outside); - xsection.inhibit(outside); - //xsection.subtract(new Rectangle2D.Double(13, 13, 4, 30)); - xsection.subtract(new Ellipse2D.Double(10,10, 10, 10)); - length = Amount.valueOf(100, SI.MILLIMETER); - /**/ - - /* - * Plus sign Shape outside = new Ellipse2D.Double(0,0,200,200); - * plus.add(outside); inhibited.add(outside); minus.add(new - * Rectangle2D.Double(90,40,20,120)); minus.add(new - * Rectangle2D.Double(40,90,120,20)); - */ - - findWebThickness(); - - } - @Override public Amount surfaceArea(Amount regression) { Amount zero = Amount.valueOf(0, Area.UNIT); @@ -105,10 +93,8 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain { @Override public Amount webThickness() { - return webThickness; - } - - private void findWebThickness() { + if ( webThickness != null ) + return webThickness; java.awt.geom.Area a = getCrossSection(Amount.valueOf(0, SI.MILLIMETER)); Rectangle r = a.getBounds(); double max = r.getWidth() < r.getHeight() ? r.getHeight() : r @@ -133,6 +119,7 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain { webThickness = Amount.valueOf(guess, SI.MILLIMETER); if (webThickness.isGreaterThan(length.divide(2))) webThickness = length.divide(2); + return webThickness; } @Override @@ -157,13 +144,6 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain { } return res; } - - public static void main(String args[]) throws Exception { - ExtrudedShapeGrain e = new ExtrudedShapeGrain(); - new Editor(e).show(); - new GrainPanel(e).show(); - } - public Amount getLength() { return length; @@ -187,4 +167,11 @@ public class ExtrudedShapeGrain extends MotorPart implements Grain { firePropertyChange("endSurfaceInhibited", old, endSurfaceInhibited); } + + public static void main(String args[]) throws Exception { + ExtrudedShapeGrain e = DEFAULT_GRAIN; + new Editor(e).show(); + new GrainPanel(e).show(); + } + } diff --git a/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java b/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java index bf35bb8..e9228ba 100644 --- a/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java +++ b/src/com/billkuker/rocketry/motorsim/grain/RodAndTubeGrain.java @@ -14,27 +14,33 @@ import com.billkuker.rocketry.motorsim.visual.GrainPanel; public class RodAndTubeGrain extends CompoundGrain { CoredCylindricalGrain rod, tube; + public static RodAndTubeGrain DEFAULT_GRAIN = new RodAndTubeGrain(){ + { + try{ + setOd(Amount.valueOf(30, SI.MILLIMETER)); + setTubeID(Amount.valueOf(20, SI.MILLIMETER)); + setRodDiameter(Amount.valueOf(10, SI.MILLIMETER)); + setForeEndInhibited(true); + setAftEndInhibited(true); + } catch ( Exception e ){ + throw new Error(e); + } + } + }; + public RodAndTubeGrain() { try{ rod = new CoredCylindricalGrain(); - rod.setInnerSurfaceInhibited(true); rod.setID(Amount.valueOf(0, SI.MILLIMETER)); - rod.setOD(Amount.valueOf(10, SI.MILLIMETER)); + rod.setInnerSurfaceInhibited(true); rod.setOuterSurfaceInhibited(false); - rod.setForeEndInhibited(true); - rod.setAftEndInhibited(true); tube = new CoredCylindricalGrain(); tube.setInnerSurfaceInhibited(false); - tube.setID(Amount.valueOf(20, SI.MILLIMETER)); - tube.setOD(Amount.valueOf(30, SI.MILLIMETER)); - tube.setForeEndInhibited(true); - tube.setAftEndInhibited(true); } catch ( PropertyVetoException v ){ v.printStackTrace(); //I know these values are OK } - add(rod); add(tube); } @@ -94,7 +100,7 @@ public class RodAndTubeGrain extends CompoundGrain { public static void main(String args[]) throws Exception { - Grain g = new RodAndTubeGrain(); + Grain g = DEFAULT_GRAIN; new Editor(g).show(); new GrainPanel(g).show(); } diff --git a/src/com/billkuker/rocketry/motorsim/grain/RotatedShapeGrain.java b/src/com/billkuker/rocketry/motorsim/grain/RotatedShapeGrain.java index 45187f6..30b78f2 100644 --- a/src/com/billkuker/rocketry/motorsim/grain/RotatedShapeGrain.java +++ b/src/com/billkuker/rocketry/motorsim/grain/RotatedShapeGrain.java @@ -23,6 +23,21 @@ public class RotatedShapeGrain implements Grain { private static Logger log = Logger.getLogger(RotatedShapeGrain.class); + public static RotatedShapeGrain DEFAULT_GRAIN = new RotatedShapeGrain(){ + { + try{ + Shape outside = new Rectangle2D.Double(0,0,15,70); + shape.add( outside ); + shape.inhibit( outside ); + shape.subtract( new Rectangle2D.Double(0,0,5,70)); + shape.subtract(new Rectangle2D.Double(0, -10, 15, 10)); + shape.subtract(new Rectangle2D.Double(0, 70, 15, 10)); + } catch ( Exception e ){ + throw new Error(e); + } + } + }; + public enum Quality { High() {{ @@ -50,15 +65,6 @@ public class RotatedShapeGrain implements Grain { Amount web = null; - { - Shape outside = new Rectangle2D.Double(0,0,15,100); - shape.add( outside ); - shape.inhibit( outside ); - shape.subtract( new Rectangle2D.Double(0,0,5,100)); - shape.subtract(new Rectangle2D.Double(0, -10, 15, 10)); - shape.subtract(new Rectangle2D.Double(0, 100, 15, 10)); - } - @Override public Area getCrossSection(Amount regression) { Area ret = new Area(); @@ -147,14 +153,7 @@ public class RotatedShapeGrain implements Grain { return web; } - - public static void main(String args[]) throws Exception { - RotatedShapeGrain e = new RotatedShapeGrain(); - new Editor(e).show(); - new GrainPanel(e).show(); - } - private Shape square(java.awt.geom.Area a) { PathIterator i = a.getPathIterator(new AffineTransform(), quality.squareFlatteningError); GeneralPath cur = new GeneralPath(); @@ -249,5 +248,12 @@ public class RotatedShapeGrain implements Grain { return len; } + + public static void main(String args[]) throws Exception { + RotatedShapeGrain e = DEFAULT_GRAIN; + new Editor(e).show(); + new GrainPanel(e).show(); + } + }