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