1 package net.sf.openrocket.rocketcomponent;
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;
10 public class CenteringRing extends RadiusRingComponent {
12 public CenteringRing() {
13 setOuterRadiusAutomatic(true);
14 setInnerRadiusAutomatic(true);
18 private static final Translator trans = Application.getTranslator();
22 public double getInnerRadius() {
23 // Implement sibling inner radius automation
24 if (isInnerRadiusAutomatic()) {
26 // Component can be parentless if disattached from rocket
27 if (this.getParent() != null) {
28 for (RocketComponent sibling : this.getParent().getChildren()) {
30 * Only InnerTubes are considered when determining the automatic
31 * inner radius (for now).
33 if (!(sibling instanceof InnerTube)) // Excludes itself
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())
41 innerRadius = Math.max(innerRadius, ((InnerTube) sibling).getOuterRadius());
43 innerRadius = Math.min(innerRadius, getOuterRadius());
47 return super.getInnerRadius();
52 public void setOuterRadiusAutomatic(boolean auto) {
53 super.setOuterRadiusAutomatic(auto);
57 public void setInnerRadiusAutomatic(boolean auto) {
58 super.setInnerRadiusAutomatic(auto);
62 public String getComponentName() {
63 return trans.get ("CenteringRing.CenteringRing");
67 public boolean allowsChildren() {
72 public boolean isCompatible(Class<? extends RocketComponent> type) {
77 public Type getPresetType() {
78 return ComponentPreset.Type.CENTERING_RING;