ddb59d1b5731603c87c153bf666421acc12f6b6c
[debian/openrocket] / core / src / net / sf / openrocket / rocketcomponent / CenteringRing.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import net.sf.openrocket.preset.ComponentPreset;
4 import net.sf.openrocket.preset.ComponentPreset.Type;
5 import net.sf.openrocket.util.Coordinate;
6
7
8 public class CenteringRing extends RadiusRingComponent {
9
10         public CenteringRing() {
11                 setOuterRadiusAutomatic(true);
12                 setInnerRadiusAutomatic(true);
13                 setLength(0.002);
14         }
15
16
17         @Override
18         public double getInnerRadius() {
19                 // Implement sibling inner radius automation
20                 if (isInnerRadiusAutomatic()) {
21                         innerRadius = 0;
22                         // Component can be parentless if disattached from rocket
23                         if (this.getParent() != null) {
24                                 for (RocketComponent sibling : this.getParent().getChildren()) {
25                                         /*
26                                          * Only InnerTubes are considered when determining the automatic
27                                          * inner radius (for now).
28                                          */
29                                         if (!(sibling instanceof InnerTube)) // Excludes itself
30                                                 continue;
31
32                                         double pos1 = this.toRelative(Coordinate.NUL, sibling)[0].x;
33                                         double pos2 = this.toRelative(new Coordinate(getLength()), sibling)[0].x;
34                                         if (pos2 < 0 || pos1 > sibling.getLength())
35                                                 continue;
36
37                                         innerRadius = Math.max(innerRadius, ((InnerTube) sibling).getOuterRadius());
38                                 }
39                                 innerRadius = Math.min(innerRadius, getOuterRadius());
40                         }
41                 }
42
43                 return super.getInnerRadius();
44         }
45
46
47         @Override
48         public void setOuterRadiusAutomatic(boolean auto) {
49                 super.setOuterRadiusAutomatic(auto);
50         }
51
52         @Override
53         public void setInnerRadiusAutomatic(boolean auto) {
54                 super.setInnerRadiusAutomatic(auto);
55         }
56
57         @Override
58         public String getComponentName() {
59                 return "Centering ring";
60         }
61
62         @Override
63         public boolean allowsChildren() {
64                 return false;
65         }
66
67         @Override
68         public boolean isCompatible(Class<? extends RocketComponent> type) {
69                 return false;
70         }
71
72         @Override
73         public Type getPresetType() {
74                 return ComponentPreset.Type.CENTERING_RING;
75         }
76
77 }