]> git.gag.com Git - debian/openrocket/blobdiff - core/src/net/sf/openrocket/gui/print/visitor/CenteringRingStrategy.java
create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / gui / print / visitor / CenteringRingStrategy.java
index 3cf17cae99b4ae8d099812319b472f0c82725939..1df756997d30bd397ce6953746e2954189ad54c4 100644 (file)
@@ -10,8 +10,10 @@ import net.sf.openrocket.gui.print.PrintUnit;
 import net.sf.openrocket.gui.print.PrintableCenteringRing;
 import net.sf.openrocket.logging.LogHelper;
 import net.sf.openrocket.rocketcomponent.CenteringRing;
+import net.sf.openrocket.rocketcomponent.InnerTube;
 import net.sf.openrocket.rocketcomponent.RocketComponent;
 import net.sf.openrocket.startup.Application;
+import net.sf.openrocket.util.ArrayList;
 
 import java.awt.image.BufferedImage;
 import java.util.List;
@@ -88,6 +90,56 @@ public class CenteringRingStrategy {
         }
     }
 
+    /**
+     * Find the inner tubes that are physically supported by the given centering ring.  Note that this only looks for
+     * motor mount tubes that are siblings to the centering ring.
+     *
+     * @param rc the centering ring, for which all motor mount tubes that run through it are located.
+     *
+     * @return the list of tubes found
+     */
+    private List<InnerTube> findMotorMount(CenteringRing rc) {
+        RocketComponent parent = rc.getParent();
+        List<RocketComponent> siblings = parent.getChildren();
+
+        List<InnerTube> mounts = new ArrayList<InnerTube>();
+        for (RocketComponent rocketComponents : siblings) {
+            if (rocketComponents != rc) {
+                if (rocketComponents instanceof InnerTube) {
+                    InnerTube it = (InnerTube) rocketComponents;
+                    if (overlaps(rc, it)) {
+                        mounts.add(it);
+                    }
+                }
+            }
+        }
+
+        return mounts;
+    }
+
+    /**
+     * Determine if the centering ring physically overlaps with the inner tube.
+     *
+     * @param one the centering ring
+     * @param two the inner body tube
+     *
+     * @return true if the two physically intersect, from which we infer that the centering ring supports the tube
+     */
+    private boolean overlaps(CenteringRing one, InnerTube two) {
+        final double crTopPosition = one.asPositionValue(RocketComponent.Position.ABSOLUTE, one.getParent());
+        final double mmTopPosition = two.asPositionValue(RocketComponent.Position.ABSOLUTE, two.getParent());
+        final double crBottomPosition = one.getLength() + crTopPosition;
+        final double mmBottomPosition = two.getLength() + mmTopPosition;
+
+        if (crTopPosition >= mmTopPosition && crTopPosition <= mmBottomPosition) {
+            return true;
+        }
+        if (crBottomPosition >= mmTopPosition && crBottomPosition <= mmBottomPosition) {
+            return true;
+        }
+        return false;
+    }
+
     /**
      * The core behavior of this visitor.
      *
@@ -97,7 +149,7 @@ public class CenteringRingStrategy {
     private void render(final CenteringRing component) {
         try {
             AbstractPrintable pfs;
-            pfs = new PrintableCenteringRing(component);
+            pfs = PrintableCenteringRing.create(component, findMotorMount(component));
 
             java.awt.Dimension size = pfs.getSize();
             final Dimension pageSize = getPageSize();
@@ -150,7 +202,7 @@ public class CenteringRingStrategy {
     /**
      * Convenience class to model a dimension.
      */
-    class Dimension {
+    public static class Dimension {
         /**
          * Width, in points.
          */
@@ -159,6 +211,10 @@ public class CenteringRingStrategy {
          * Height, in points.
          */
         public float height;
+        /**
+         * Breadth, in points.
+         */
+        public float breadth = 0f;
 
         /**
          * Constructor.
@@ -171,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.
          *
@@ -188,5 +257,14 @@ public class CenteringRingStrategy {
         public float getHeight() {
             return height;
         }
+
+        /**
+         * Get the breadth.
+         *
+         * @return the breadth
+         */
+        public float getBreadth() {
+            return breadth;
+        }
     }
 }