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