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;
}
}
+ /**
+ * 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.
*
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();
/**
* Convenience class to model a dimension.
*/
- class Dimension {
+ public static class Dimension {
/**
* Width, in points.
*/
* Height, in points.
*/
public float height;
+ /**
+ * Breadth, in points.
+ */
+ public float breadth = 0f;
/**
* Constructor.
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.
*
public float getHeight() {
return height;
}
+
+ /**
+ * Get the breadth.
+ *
+ * @return the breadth
+ */
+ public float getBreadth() {
+ return breadth;
+ }
}
}