prepare to upload
[debian/openrocket] / core / src / net / sf / openrocket / rocketcomponent / BodyComponent.java
1 package net.sf.openrocket.rocketcomponent;
2
3
4
5 /**
6  * Class to represent a body object.  The object can be described as a function of
7  * the cylindrical coordinates x and angle theta as  r = f(x,theta).  The component
8  * need not be symmetrical in any way (e.g. square tube, slanted cone etc).
9  *
10  * It defines the methods getRadius(x,theta) and getInnerRadius(x,theta), as well
11  * as get/setLength().
12  *
13  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
14  */
15
16 public abstract class BodyComponent extends ExternalComponent {
17         
18         /**
19          * Default constructor.  Sets the relative position to POSITION_RELATIVE_AFTER,
20          * i.e. body components come after one another.
21          */
22         public BodyComponent() {
23                 super(RocketComponent.Position.AFTER);
24         }
25         
26         
27         /**
28          * Get the outer radius of the component at cylindrical coordinate (x,theta).
29          *
30          * Note that the return value may be negative for a slanted object.
31          *
32          * @param x  Distance in x direction
33          * @param theta  Angle about the x-axis
34          * @return  Distance to the outer edge of the object
35          */
36         public abstract double getRadius(double x, double theta);
37         
38         
39         /**
40          * Get the inner radius of the component at cylindrical coordinate (x,theta).
41          *
42          * Note that the return value may be negative for a slanted object.
43          *
44          * @param x  Distance in x direction
45          * @param theta  Angle about the x-axis
46          * @return  Distance to the inner edge of the object
47          */
48         public abstract double getInnerRadius(double x, double theta);
49         
50         
51         @Override
52         protected void loadFromPreset(RocketComponent preset) {
53                 BodyComponent c = (BodyComponent) preset;
54                 this.setLength(c.getLength());
55                 
56                 super.loadFromPreset(preset);
57         }
58         
59         
60
61         /**
62          * Sets the length of the body component.
63          * <p>
64          * Note: This should be overridden by the subcomponents which need to call
65          * clearPreset().  (BodyTube allows changing length without resetting the preset.)
66          */
67         public void setLength(double length) {
68                 if (this.length == length)
69                         return;
70                 this.length = Math.max(length, 0);
71                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
72         }
73         
74         @Override
75         public boolean allowsChildren() {
76                 return true;
77         }
78         
79 }