Updates for 0.9.5
[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                                         /*
24                                          * Only InnerTubes are considered when determining the automatic
25                                          * inner radius (for now).
26                                          */
27                                         if (!(sibling instanceof InnerTube))  // Excludes itself
28                                                 continue;
29                                         
30                                         double pos1 = this.toRelative(Coordinate.NUL, sibling)[0].x;
31                                         double pos2 = this.toRelative(new Coordinate(getLength()), sibling)[0].x;
32                                         if (pos2 < 0 || pos1 > sibling.getLength())
33                                                 continue;
34                                         
35                                         innerRadius = Math.max(innerRadius, ((InnerTube)sibling).getOuterRadius());
36                                 }
37                                 innerRadius = Math.min(innerRadius, getOuterRadius());
38                         }
39                 }
40                 
41                 return super.getInnerRadius();
42         }
43
44         
45         @Override
46         public void setOuterRadiusAutomatic(boolean auto) {
47                 super.setOuterRadiusAutomatic(auto);
48         }
49         
50         @Override
51         public void setInnerRadiusAutomatic(boolean auto) {
52                 super.setInnerRadiusAutomatic(auto);
53         }
54         
55         @Override
56         public String getComponentName() {
57                 return "Centering ring";
58         }
59
60         @Override
61         public boolean isCompatible(Class<? extends RocketComponent> type) {
62                 return false;
63         }
64
65 }