Initial commit
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / BodyComponent.java
1 package net.sf.openrocket.rocketcomponent;
2
3
4 /**
5  * Class to represent a body object.  The object can be described as a function of
6  * the cylindrical coordinates x and angle theta as  r = f(x,theta).  The component 
7  * need not be symmetrical in any way (e.g. square tube, slanted cone etc).
8  * 
9  * It defines the methods getRadius(x,theta) and getInnerRadius(x,theta), as well
10  * as get/setLength().
11  * 
12  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
13  */
14
15 public abstract class BodyComponent extends ExternalComponent {
16
17         /**
18          * Default constructor.  Sets the relative position to POSITION_RELATIVE_AFTER,
19          * i.e. body components come after one another.
20          */
21         public BodyComponent() {
22                 super(RocketComponent.Position.AFTER);
23         }
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
52         /**
53          * Sets the length of the body component.
54          */
55         public void setLength(double length) {
56                 if (this.length == length)
57                         return;
58                 this.length = Math.max(length,0);
59                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
60         }
61         
62         
63         /**
64          * Check whether the given type can be added to this component.  BodyComponents allow any
65          * InternalComponents or ExternalComponents, excluding BodyComponents, to be added.
66          * 
67          * @param type  The RocketComponent class type to add.
68          * @return      Whether such a component can be added.
69          */
70         @Override
71         public boolean isCompatible(Class<? extends RocketComponent> type) {
72                 if (InternalComponent.class.isAssignableFrom(type))
73                         return true;
74                 if (ExternalComponent.class.isAssignableFrom(type) &&
75                         !BodyComponent.class.isAssignableFrom(type))
76                         return true;
77                 return false;
78         }
79 }