1 package net.sf.openrocket.gui.print;
3 import net.sf.openrocket.gui.rocketfigure.TransitionShapes;
4 import net.sf.openrocket.rocketcomponent.NoseCone;
5 import net.sf.openrocket.util.Transformation;
7 import java.awt.Graphics2D;
8 import java.awt.Rectangle;
11 public class PrintableNoseCone extends AbstractPrintable<NoseCone> {
14 * If the component to be drawn is a nose cone, save a reference to it.
16 private NoseCone target;
19 * Construct a printable nose cone.
21 * @param noseCone the component to print
23 public PrintableNoseCone(NoseCone noseCone) {
24 super(false, noseCone);
28 protected void init(NoseCone component) {
31 double radius = target.getForeRadius();
32 if (radius < target.getAftRadius()) {
33 radius = target.getAftRadius();
35 setSize((int) PrintUnit.METERS.toPoints(2 * radius) + 4,
36 (int) PrintUnit.METERS.toPoints(target.getLength() + target.getAftShoulderLength()) + 4);
40 * Draw a nose cone. Presumes that the graphics context has already had the x/y position translated based on
41 * where it should be drawn.
43 * @param g2 the graphics context
46 protected void draw(Graphics2D g2) {
47 Shape[] shapes = TransitionShapes.getShapesSide(target, Transformation.rotate_x(0d), PrintUnit.METERS.toPoints(1));
49 if (shapes != null && shapes.length > 0) {
50 Rectangle r = shapes[0].getBounds();
51 g2.translate(r.getHeight() / 2, 0);
52 g2.rotate(Math.PI / 2);
53 for (Shape shape : shapes) {
56 g2.rotate(-Math.PI / 2);