updates for 0.9.3
[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                                         innerRadius = Math.max(innerRadius, ((InnerTube)sibling).getOuterRadius());
32                                 }
33                                 innerRadius = Math.min(innerRadius, getOuterRadius());
34                         }
35                 }
36                 
37                 return super.getInnerRadius();
38         }
39
40         
41         @Override
42         public void setOuterRadiusAutomatic(boolean auto) {
43                 super.setOuterRadiusAutomatic(auto);
44         }
45         
46         @Override
47         public void setInnerRadiusAutomatic(boolean auto) {
48                 super.setInnerRadiusAutomatic(auto);
49         }
50         
51         @Override
52         public String getComponentName() {
53                 return "Centering ring";
54         }
55
56         @Override
57         public boolean isCompatible(Class<? extends RocketComponent> type) {
58                 return false;
59         }
60
61 }