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