refactored file package
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / CenteringRing.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import net.sf.openrocket.util.Coordinate;
4
5
6 public class CenteringRing extends RadiusRingComponent {
7
8         public CenteringRing() {
9                 setOuterRadiusAutomatic(true);
10                 setInnerRadiusAutomatic(true);
11                 setLength(0.002);
12         }
13         
14         
15         @Override
16         public double getInnerRadius() {
17                 // Implement sibling inner radius automation
18                 if (isInnerRadiusAutomatic()) {
19                         innerRadius = 0;
20                         // Component can be parentless if disattached from rocket
21                         if (this.getParent() != null) {
22                                 for (RocketComponent sibling: this.getParent().getChildren()) {
23                                         if (!(sibling instanceof RadialParent))  // Excludes itself
24                                                 continue;
25                                         
26                                         double pos1 = this.toRelative(Coordinate.NUL, sibling)[0].x;
27                                         double pos2 = this.toRelative(new Coordinate(getLength()), sibling)[0].x;
28                                         if (pos2 < 0 || pos1 > sibling.getLength())
29                                                 continue;
30                                         
31                                         // TODO: CRITICAL: ClassCastException below:
32                                         innerRadius = Math.max(innerRadius, ((InnerTube)sibling).getOuterRadius());
33                                 }
34                                 innerRadius = Math.min(innerRadius, getOuterRadius());
35                         }
36                 }
37                 
38                 return super.getInnerRadius();
39         }
40
41         
42         @Override
43         public void setOuterRadiusAutomatic(boolean auto) {
44                 super.setOuterRadiusAutomatic(auto);
45         }
46         
47         @Override
48         public void setInnerRadiusAutomatic(boolean auto) {
49                 super.setInnerRadiusAutomatic(auto);
50         }
51         
52         @Override
53         public String getComponentName() {
54                 return "Centering ring";
55         }
56
57         @Override
58         public boolean isCompatible(Class<? extends RocketComponent> type) {
59                 return false;
60         }
61
62 }