1 package net.sf.openrocket.rocketcomponent;
3 import java.util.ArrayList;
4 import java.util.HashMap;
7 import net.sf.openrocket.util.Coordinate;
8 import net.sf.openrocket.util.MathUtil;
12 * This class defines an inner tube that can be used as a motor mount. The component
13 * may also be clustered.
15 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
17 public class InnerTube extends ThicknessRingComponent
18 implements Clusterable, RadialParent, MotorMount {
20 private ClusterConfiguration cluster = ClusterConfiguration.SINGLE;
21 private double clusterScale = 1.0;
22 private double clusterRotation = 0.0;
25 private boolean motorMount = false;
26 private HashMap<String, Double> ejectionDelays = new HashMap<String, Double>();
27 private HashMap<String, Motor> motors = new HashMap<String, Motor>();
28 private IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC;
29 private double ignitionDelay = 0;
30 private double overhang = 0;
38 this.setOuterRadius(0.019/2);
39 this.setInnerRadius(0.018/2);
40 this.setLength(0.070);
45 public double getInnerRadius(double x) {
46 return getInnerRadius();
51 public double getOuterRadius(double x) {
52 return getOuterRadius();
57 public String getComponentName() {
62 * Allow all InternalComponents to be added to this component.
65 public boolean isCompatible(Class<? extends RocketComponent> type) {
66 return InternalComponent.class.isAssignableFrom(type);
71 ///////////// Cluster methods //////////////
74 * Get the current cluster configuration.
75 * @return The current cluster configuration.
77 public ClusterConfiguration getClusterConfiguration() {
82 * Set the current cluster configuration.
83 * @param cluster The cluster configuration.
85 public void setClusterConfiguration(ClusterConfiguration cluster) {
86 this.cluster = cluster;
87 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
91 * Return the number of tubes in the cluster.
92 * @return Number of tubes in the current cluster.
95 public int getClusterCount() {
96 return cluster.getClusterCount();
100 * Get the cluster scaling. A value of 1.0 indicates that the tubes are packed
101 * touching each other, larger values separate the tubes and smaller values
102 * pack inside each other.
104 public double getClusterScale() {
109 * Set the cluster scaling.
110 * @see #getClusterScale()
112 public void setClusterScale(double scale) {
113 scale = Math.max(scale,0);
114 if (MathUtil.equals(clusterScale, scale))
116 clusterScale = scale;
117 fireComponentChangeEvent(new ComponentChangeEvent(this,ComponentChangeEvent.MASS_CHANGE));
123 * @return the clusterRotation
125 public double getClusterRotation() {
126 return clusterRotation;
131 * @param rotation the clusterRotation to set
133 public void setClusterRotation(double rotation) {
134 rotation = MathUtil.reduce180(rotation);
135 if (clusterRotation == rotation)
137 this.clusterRotation = rotation;
138 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
143 public double getClusterSeparation() {
144 return 2*getOuterRadius()*clusterScale;
148 public List<Coordinate> getClusterPoints() {
149 List<Coordinate> list = new ArrayList<Coordinate>(getClusterCount());
150 List<Double> points = cluster.getPoints(clusterRotation - getRadialDirection());
151 double separation = getClusterSeparation();
152 for (int i=0; i < points.size()/2; i++) {
153 list.add(new Coordinate(0,points.get(2*i)*separation,points.get(2*i+1)*separation));
160 public Coordinate[] shiftCoordinates(Coordinate[] array) {
161 array = super.shiftCoordinates(array);
163 int count = getClusterCount();
167 List<Coordinate> points = getClusterPoints();
168 assert(points.size() == count);
169 Coordinate[] newArray = new Coordinate[array.length * count];
170 for (int i=0; i < array.length; i++) {
171 for (int j=0; j < count; j++) {
172 newArray[i*count + j] = array[i].add(points.get(j));
182 //////////////// Motor mount /////////////////
185 public boolean isMotorMount() {
190 public void setMotorMount(boolean mount) {
191 if (motorMount == mount)
194 fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
198 public Motor getMotor(String id) {
199 return motors.get(id);
203 public void setMotor(String id, Motor motor) {
204 Motor current = motors.get(id);
205 if ((motor == null && current == null) ||
206 (motor != null && motor.equals(current)))
208 motors.put(id, motor);
209 fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
213 public double getMotorDelay(String id) {
214 Double delay = ejectionDelays.get(id);
216 return Motor.PLUGGED;
221 public void setMotorDelay(String id, double delay) {
222 ejectionDelays.put(id, delay);
223 fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
227 public int getMotorCount() {
228 return getClusterCount();
232 public double getMotorMountDiameter() {
233 return getInnerRadius()*2;
237 public IgnitionEvent getIgnitionEvent() {
238 return ignitionEvent;
242 public void setIgnitionEvent(IgnitionEvent event) {
243 if (ignitionEvent == event)
245 ignitionEvent = event;
246 fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
251 public double getIgnitionDelay() {
252 return ignitionDelay;
256 public void setIgnitionDelay(double delay) {
257 if (MathUtil.equals(delay, ignitionDelay))
259 ignitionDelay = delay;
260 fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
265 public double getMotorOverhang() {
270 public void setMotorOverhang(double overhang) {
271 if (MathUtil.equals(this.overhang, overhang))
273 this.overhang = overhang;
274 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);