DGP - 1st printing
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / CenteringRing.java
index 515667a5d11c4a6c861fb65b2bf9ad7ad1320a18..1621042c6551c61c928b759383d2513e88c20e24 100644 (file)
@@ -17,18 +17,25 @@ public class CenteringRing extends RadiusRingComponent {
                // Implement sibling inner radius automation
                if (isInnerRadiusAutomatic()) {
                        innerRadius = 0;
-                       for (RocketComponent sibling: this.getParent().getChildren()) {
-                               if (!(sibling instanceof RadialParent))  // Excludes itself
-                                       continue;
-
-                               double pos1 = this.toRelative(Coordinate.NUL, sibling)[0].x;
-                               double pos2 = this.toRelative(new Coordinate(getLength()), sibling)[0].x;
-                               if (pos2 < 0 || pos1 > sibling.getLength())
-                                       continue;
-                               
-                               innerRadius = Math.max(innerRadius, ((InnerTube)sibling).getOuterRadius());
+                       // Component can be parentless if disattached from rocket
+                       if (this.getParent() != null) {
+                               for (RocketComponent sibling: this.getParent().getChildren()) {
+                                       /*
+                                        * Only InnerTubes are considered when determining the automatic
+                                        * inner radius (for now).
+                                        */
+                                       if (!(sibling instanceof InnerTube))  // Excludes itself
+                                               continue;
+                                       
+                                       double pos1 = this.toRelative(Coordinate.NUL, sibling)[0].x;
+                                       double pos2 = this.toRelative(new Coordinate(getLength()), sibling)[0].x;
+                                       if (pos2 < 0 || pos1 > sibling.getLength())
+                                               continue;
+                                       
+                                       innerRadius = Math.max(innerRadius, ((InnerTube)sibling).getOuterRadius());
+                               }
+                               innerRadius = Math.min(innerRadius, getOuterRadius());
                        }
-                       innerRadius = Math.min(innerRadius, getOuterRadius());
                }
                
                return super.getInnerRadius();
@@ -54,5 +61,15 @@ public class CenteringRing extends RadiusRingComponent {
        public boolean isCompatible(Class<? extends RocketComponent> type) {
                return false;
        }
+    
+    /**
+     * Accept a visitor to this CenteringRing in the component hierarchy.
+     * 
+     * @param theVisitor  the visitor that will be called back with a reference to this CenteringRing
+     */
+    @Override 
+    public void accept (final ComponentVisitor theVisitor) {
+        theVisitor.visit(this);
+    }
 
 }