create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / gui / rocketfigure / TransitionShapes.java
1 package net.sf.openrocket.gui.rocketfigure;
2
3 import net.sf.openrocket.rocketcomponent.Transition;
4 import net.sf.openrocket.util.Coordinate;
5 import net.sf.openrocket.util.Transformation;
6
7 import java.awt.*;
8 import java.awt.geom.Ellipse2D;
9 import java.awt.geom.Path2D;
10 import java.awt.geom.Rectangle2D;
11
12
13 public class TransitionShapes extends RocketComponentShapes {
14
15         // TODO: LOW: Uses only first component of cluster (not currently clusterable).
16
17     public static Shape[] getShapesSide(net.sf.openrocket.rocketcomponent.RocketComponent component,
18                                         Transformation transformation) {
19         return getShapesSide(component, transformation, S);
20     }
21
22     public static Shape[] getShapesSide(net.sf.openrocket.rocketcomponent.RocketComponent component,
23                                         Transformation transformation, final double scaleFactor) {
24                 net.sf.openrocket.rocketcomponent.Transition transition = (net.sf.openrocket.rocketcomponent.Transition)component;
25
26                 Shape[] mainShapes;
27                 
28                 // Simpler shape for conical transition, others use the method from SymmetricComponent
29                 if (transition.getType() == Transition.Shape.CONICAL) {
30                         double length = transition.getLength();
31                         double r1 = transition.getForeRadius();
32                         double r2 = transition.getAftRadius();
33                         Coordinate start = transformation.transform(transition.
34                                         toAbsolute(Coordinate.NUL)[0]);
35                         
36                         Path2D.Float path = new Path2D.Float();
37                         path.moveTo(start.x* scaleFactor, r1* scaleFactor);
38                         path.lineTo((start.x+length)* scaleFactor, r2* scaleFactor);
39                         path.lineTo((start.x+length)* scaleFactor, -r2* scaleFactor);
40                         path.lineTo(start.x* scaleFactor, -r1* scaleFactor);
41                         path.closePath();
42                         
43                         mainShapes = new Shape[] { path };
44                 } else {
45                         mainShapes = SymmetricComponentShapes.getShapesSide(component, transformation, scaleFactor);
46                 }
47                 
48                 Rectangle2D.Double shoulder1=null, shoulder2=null;
49                 int arrayLength = mainShapes.length;
50                 
51                 if (transition.getForeShoulderLength() > 0.0005) {
52                         Coordinate start = transformation.transform(transition.
53                                         toAbsolute(Coordinate.NUL)[0]);
54                         double r = transition.getForeShoulderRadius();
55                         double l = transition.getForeShoulderLength();
56                         shoulder1 = new Rectangle2D.Double((start.x-l)* scaleFactor, -r* scaleFactor, l* scaleFactor, 2*r* scaleFactor);
57                         arrayLength++;
58                 }
59                 if (transition.getAftShoulderLength() > 0.0005) {
60                         Coordinate start = transformation.transform(transition.
61                                         toAbsolute(new Coordinate(transition.getLength()))[0]);
62                         double r = transition.getAftShoulderRadius();
63                         double l = transition.getAftShoulderLength();
64                         shoulder2 = new Rectangle2D.Double(start.x* scaleFactor, -r* scaleFactor, l* scaleFactor, 2*r* scaleFactor);
65                         arrayLength++;
66                 }
67                 if (shoulder1==null && shoulder2==null)
68                         return mainShapes;
69                 
70                 Shape[] shapes = new Shape[arrayLength];
71                 int i;
72                 
73                 for (i=0; i < mainShapes.length; i++) {
74                         shapes[i] = mainShapes[i];
75                 }
76                 if (shoulder1 != null) {
77                         shapes[i] = shoulder1;
78                         i++;
79                 }
80                 if (shoulder2 != null) {
81                         shapes[i] = shoulder2;
82                 }
83                 return shapes;
84         }
85         
86
87         public static Shape[] getShapesBack(net.sf.openrocket.rocketcomponent.RocketComponent component, 
88                         Transformation transformation) {
89                 net.sf.openrocket.rocketcomponent.Transition transition = (net.sf.openrocket.rocketcomponent.Transition)component;
90                 
91                 double r1 = transition.getForeRadius();
92                 double r2 = transition.getAftRadius();
93                 
94                 Shape[] s = new Shape[2];
95                 s[0] = new Ellipse2D.Double(-r1*S,-r1*S,2*r1*S,2*r1*S);
96                 s[1] = new Ellipse2D.Double(-r2*S,-r2*S,2*r2*S,2*r2*S);
97                 return s;
98         }
99         
100         
101 }