Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / net / sf / openrocket / gui / print / PrintableTransition.java
index a70703daf9bf8ddfde945d30d12682b3182a8b44..41a9958a1ddc079de9cc5174b749e7478b4a2602 100644 (file)
@@ -1,5 +1,7 @@
 package net.sf.openrocket.gui.print;
 
+import net.sf.openrocket.rocketcomponent.Transition;
+
 import java.awt.BasicStroke;
 import java.awt.Graphics2D;
 import java.awt.geom.Arc2D;
@@ -8,8 +10,6 @@ import java.awt.geom.Line2D;
 import java.awt.geom.Path2D;
 import java.awt.geom.Point2D;
 
-import net.sf.openrocket.rocketcomponent.Transition;
-
 /**
  * This class allows for a Transition to be printable.  It does so by decorating an existing transition (which will not be
  * modified) and rendering it within a JPanel.  The JPanel is not actually visualized on a display, but instead renders
@@ -18,8 +18,8 @@ import net.sf.openrocket.rocketcomponent.Transition;
  * Note: Currently nose cones are only supported by drawing the 2D projection of the profile.  A more useful approach
  * may be to draw a myriahedral projection that can be cut out and bent to form the shape.
  */
-public class PrintableTransition extends AbstractPrintableTransition {
-       
+public class PrintableTransition extends AbstractPrintable<Transition> {
+
        /**
         * Dashed array value.
         */
@@ -31,38 +31,38 @@ public class PrintableTransition extends AbstractPrintableTransition {
                        BasicStroke.CAP_BUTT,
                        BasicStroke.JOIN_MITER,
                        10.0f, dash1, 0.0f);
-       
+
        /**
         * The layout is an outer arc, an inner arc, and two lines one either endpoints that connect the arcs.
         * Most of the math involves transposing geometric cartesian coordinates to the Java AWT coordinate system.
         */
        private Path2D gp;
-       
+
        /**
         * The glue tab.
         */
        private Path2D glueTab1;
-       
+
        /**
         * The alignment marks.
         */
        private Line2D tick1, tick2;
-       
+
        /**
         * The x coordinates for the two ticks drawn at theta degrees.
         */
        private int tick3X, tick4X;
-       
+
        /**
         * The angle, in degrees.
         */
        private float theta;
-       
+
        /**
         * The x,y coordinates for where the virtual circle center is located.
         */
        private int circleCenterX, circleCenterY;
-       
+
        /**
         * Constructor.
         *
@@ -71,13 +71,20 @@ public class PrintableTransition extends AbstractPrintableTransition {
        public PrintableTransition(Transition transition) {
                super(false, transition);
        }
-       
+
+    /**
+     * Compute the basic values of each arc of the transition/shroud.  This is adapted from
+     * <a href="http://www.rocketshoppe.com/info/Transitions.pdf">The Properties of
+     * Model Rocket Body Tube Transitions, by J.R. Brohm</a>
+     *
+     * @param component the component
+     */
        @Override
        protected void init(Transition component) {
-               
+
                double r1 = component.getAftRadius();
                double r2 = component.getForeRadius();
-               
+
                //Regardless of orientation, we have the convention of R1 as the smaller radius.  Flip if different.
                if (r1 > r2) {
                        r1 = r2;
@@ -87,19 +94,19 @@ public class PrintableTransition extends AbstractPrintableTransition {
                double v = r2 - r1;
                double tmp = Math.sqrt(v * v + len * len);
                double factor = tmp / v;
-               
+
                theta = (float) (360d * v / tmp);
-               
+
                int r1InPoints = (int) PrintUnit.METERS.toPoints(r1 * factor);
                int r2InPoints = (int) PrintUnit.METERS.toPoints(r2 * factor);
-               
-               int x = marginX;
+
+               int x = 0;
                int tabOffset = 35;
-               int y = tabOffset + marginY;
-               
+               int y = tabOffset;
+
                Arc2D.Double outerArc = new Arc2D.Double();
                Arc2D.Double innerArc = new Arc2D.Double();
-               
+
                //If the arcs are more than 3/4 of a circle, then assume the height (y) is the same as the radius of the bigger arc.
                if (theta >= 270) {
                        y += r2InPoints;
@@ -110,23 +117,23 @@ public class PrintableTransition extends AbstractPrintableTransition {
                        double thetaRads = Math.toRadians(theta - 180);
                        y += (int) ((Math.cos(thetaRads) * r2InPoints) * Math.tan(thetaRads));
                }
-               
+
                circleCenterY = y;
                circleCenterX = r2InPoints + x;
-               
+
                //Create the larger arc.
                outerArc.setArcByCenter(circleCenterX, circleCenterY, r2InPoints, 180, theta, Arc2D.OPEN);
-               
+
                //Create the smaller arc.
                innerArc.setArcByCenter(circleCenterX, circleCenterY, r1InPoints, 180, theta, Arc2D.OPEN);
-               
+
                //Create the line between the start of the larger arc and the start of the smaller arc.
                Path2D.Double line = new Path2D.Double();
                line.setWindingRule(Path2D.WIND_NON_ZERO);
                line.moveTo(x, y);
                final int width = r2InPoints - r1InPoints;
                line.lineTo(width + x, y);
-               
+
                //Create the line between the endpoint of the larger arc and the endpoint of the smaller arc.
                Path2D.Double closingLine = new Path2D.Double();
                closingLine.setWindingRule(Path2D.WIND_NON_ZERO);
@@ -134,21 +141,21 @@ public class PrintableTransition extends AbstractPrintableTransition {
                closingLine.moveTo(innerArcEndPoint.getX(), innerArcEndPoint.getY());
                Point2D outerArcEndPoint = outerArc.getEndPoint();
                closingLine.lineTo(outerArcEndPoint.getX(), outerArcEndPoint.getY());
-               
+
                //Add all shapes to the polygon path.
                gp = new Path2D.Float(GeneralPath.WIND_EVEN_ODD, 4);
                gp.append(line, false);
                gp.append(outerArc, false);
                gp.append(closingLine, false);
                gp.append(innerArc, false);
-               
+
                //Create the glue tab.
                glueTab1 = new Path2D.Float(GeneralPath.WIND_EVEN_ODD, 4);
                glueTab1.moveTo(x, y);
                glueTab1.lineTo(x + tabOffset, y - tabOffset);
                glueTab1.lineTo(width + x - tabOffset, y - tabOffset);
                glueTab1.lineTo(width + x, y);
-               
+
                //Create tick marks for alignment, 1/4 of the width in from either edge
                int fromEdge = width / 4;
                final int tickLength = 8;
@@ -156,13 +163,13 @@ public class PrintableTransition extends AbstractPrintableTransition {
                tick1 = new Line2D.Float(x + fromEdge, y, x + fromEdge, y + tickLength);
                //Upper right
                tick2 = new Line2D.Float(x + width - fromEdge, y, x + width - fromEdge, y + tickLength);
-               
+
                tick3X = r2InPoints - fromEdge;
                tick4X = r1InPoints + fromEdge;
-               
+
                setSize(gp.getBounds().width, gp.getBounds().height + tabOffset);
        }
-       
+
        /**
         * Draw alignment marks on an angle.
         *
@@ -179,7 +186,7 @@ public class PrintableTransition extends AbstractPrintableTransition {
                g2.rotate(Math.toRadians(theta));
                g2.translate(-x, -y);
        }
-       
+
        /**
         * Draw a transition.
         *
@@ -199,9 +206,9 @@ public class PrintableTransition extends AbstractPrintableTransition {
                                circleCenterY,
                                new Line2D.Float(-tick4X, 0, -tick4X, -8),
                                theta);
-               
+
                g2.setStroke(dashed);
                g2.draw(glueTab1);
        }
-       
+
 }