]> git.gag.com Git - debian/openrocket/commitdiff
Support for different size clusters in centering ring template.
authorrodinia814 <rodinia814@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 31 May 2012 03:06:22 +0000 (03:06 +0000)
committerrodinia814 <rodinia814@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 31 May 2012 03:06:22 +0000 (03:06 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@733 180e2498-e6e9-4542-8430-84ac67f01cd8

core/src/net/sf/openrocket/gui/print/PrintableCenteringRing.java
core/src/net/sf/openrocket/gui/print/visitor/CenteringRingStrategy.java

index 502e045ab49c0937d5add741f5e42f2e78f6fa38..00c4e89c0ee5ade21353b19952203fea963ebefa 100644 (file)
@@ -37,7 +37,8 @@ public class PrintableCenteringRing extends AbstractPrintable<CenteringRing> {
     private Set<CenteringRingStrategy.Dimension> innerCenterPoints = new HashSet<CenteringRingStrategy.Dimension>();
 
     /**
-     * Construct a simple, non-clustered, printable centering ring.
+     * Construct a simple, non-clustered, printable centering ring, or if the motor mount represents a clustered
+     * configuration then get the cluster points to create the centering ring.
      *
      * @param theRing       the component to print
      * @param theMotorMount the motor mount if clustered, else null
@@ -46,17 +47,24 @@ public class PrintableCenteringRing extends AbstractPrintable<CenteringRing> {
         super(false, theRing);
         if (theMotorMount == null || theMotorMount.getClusterConfiguration().equals(ClusterConfiguration.SINGLE)) {
             //Single motor.
-            innerCenterPoints.add(new CenteringRingStrategy.Dimension((float) PrintUnit.METERS.toPoints(target.getOuterRadius()),
-                    (float) PrintUnit.METERS.toPoints(target.getOuterRadius())));
+            final float v = (float) PrintUnit.METERS.toPoints(target.getOuterRadius());
+            innerCenterPoints.add(
+                    new CenteringRingStrategy.Dimension(v, v,
+                            (float) PrintUnit.METERS.toPoints((target.getInnerRadius()))));
         }
         else {
             List<Coordinate> coords = theMotorMount.getClusterPoints();
-            populateCenterPoints(coords);
+            List<Coordinate> points = new ArrayList<Coordinate>();
+            for (Coordinate coordinate : coords) {
+                points.add(coordinate.setX(theMotorMount.getOuterRadius()));
+            }
+            populateCenterPoints(points);
         }
     }
 
     /**
-     * Constructor for a clustered centering ring.
+     * Constructor for a clustered centering ring.  This version is for a "split cluster", where each motor mount tube
+     * is a distinct entity.
      *
      * @param theRing        the centering ring component
      * @param theMotorMounts a list of the motor mount tubes that are physically supported by the centering ring
@@ -66,10 +74,18 @@ public class PrintableCenteringRing extends AbstractPrintable<CenteringRing> {
         List<Coordinate> points = new ArrayList<Coordinate>();
         //Transform the radial positions of the tubes.
         for (InnerTube it : theMotorMounts) {
-            double y = it.getRadialShiftY();
-            double z = it.getRadialShiftZ();
-            Coordinate coordinate = new Coordinate(0, y, z);
-            points.add(coordinate);
+            if (it.getClusterCount() > 1) {
+                List<Coordinate> c = it.getClusterPoints();
+                for (Coordinate coordinate : c) {
+                    points.add(coordinate.setX(it.getOuterRadius()));
+                }
+            }
+            else {
+                double y = it.getRadialShiftY();
+                double z = it.getRadialShiftZ();
+                Coordinate coordinate = new Coordinate(it.getOuterRadius(), y, z);
+                points.add(coordinate);
+            }
         }
         populateCenterPoints(points);
     }
@@ -101,9 +117,10 @@ public class PrintableCenteringRing extends AbstractPrintable<CenteringRing> {
     private void populateCenterPoints(final List<Coordinate> theCoords) {
         float radius = (float) PrintUnit.METERS.toPoints(target.getOuterRadius());
         for (Coordinate coordinate : theCoords) {
-            innerCenterPoints.add(new CenteringRingStrategy.Dimension((float) PrintUnit.METERS.toPoints
-                    (coordinate.y) + radius,
-                    (float) PrintUnit.METERS.toPoints(coordinate.z) + radius));
+            innerCenterPoints.add(new CenteringRingStrategy.Dimension(
+                    (float) PrintUnit.METERS.toPoints(coordinate.y) + radius, //center point x
+                    (float) PrintUnit.METERS.toPoints(coordinate.z) + radius, //center point y
+                    (float) PrintUnit.METERS.toPoints(coordinate.x)));        //radius of motor mount
         }
     }
 
@@ -137,7 +154,7 @@ public class PrintableCenteringRing extends AbstractPrintable<CenteringRing> {
         g2.draw(outerCircle);
 
         for (CenteringRingStrategy.Dimension next : innerCenterPoints) {
-            drawInnerCircle(g2, next.getWidth(), next.getHeight());
+            drawInnerCircle(g2, next.getWidth(), next.getHeight(), next.getBreadth());
         }
         g2.setColor(original);
     }
@@ -149,8 +166,8 @@ public class PrintableCenteringRing extends AbstractPrintable<CenteringRing> {
      * @param theCenterX the center x in points
      * @param theCenterY the center y in points
      */
-    private void drawInnerCircle(final Graphics2D g2, final double theCenterX, final double theCenterY) {
-        double innerRadius = PrintUnit.METERS.toPoints(target.getInnerRadius());
+    private void drawInnerCircle(final Graphics2D g2, final double theCenterX, final double theCenterY,
+                                 final double innerRadius) {
         Shape innerCircle = new Ellipse2D.Double(theCenterX - innerRadius, theCenterY - innerRadius, innerRadius * 2, innerRadius * 2);
         g2.setColor(Color.white);
         g2.fill(innerCircle);
index a3315aedd5f53b5d72f1fa3ada7919c7640e5980..1df756997d30bd397ce6953746e2954189ad54c4 100644 (file)
@@ -107,10 +107,8 @@ public class CenteringRingStrategy {
             if (rocketComponents != rc) {
                 if (rocketComponents instanceof InnerTube) {
                     InnerTube it = (InnerTube) rocketComponents;
-                    if (it.isMotorMount()) {
-                        if (overlaps(rc, it)) {
-                            mounts.add(it);
-                        }
+                    if (overlaps(rc, it)) {
+                        mounts.add(it);
                     }
                 }
             }
@@ -213,6 +211,10 @@ public class CenteringRingStrategy {
          * Height, in points.
          */
         public float height;
+        /**
+         * Breadth, in points.
+         */
+        public float breadth = 0f;
 
         /**
          * Constructor.
@@ -225,6 +227,19 @@ public class CenteringRingStrategy {
             height = h;
         }
 
+        /**
+         * Constructor.
+         *
+         * @param w width
+         * @param h height
+         * @param b breadth; optionally used to represent radius
+         */
+        public Dimension(float w, float h, float b) {
+            width = w;
+            height = h;
+            breadth = b;
+        }
+
         /**
          * Get the width.
          *
@@ -242,5 +257,14 @@ public class CenteringRingStrategy {
         public float getHeight() {
             return height;
         }
+
+        /**
+         * Get the breadth.
+         *
+         * @return the breadth
+         */
+        public float getBreadth() {
+            return breadth;
+        }
     }
 }