]> git.gag.com Git - debian/openrocket/blob - src/net/sf/openrocket/rocketcomponent/BodyComponent.java
DGP - 1st printing
[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          * Get the outer radius of the component at cylindrical coordinate (x,theta).
28          * 
29          * Note that the return value may be negative for a slanted object.
30          * 
31          * @param x  Distance in x direction
32          * @param theta  Angle about the x-axis
33          * @return  Distance to the outer edge of the object
34          */
35         public abstract double getRadius(double x, double theta);
36
37         
38         /**
39          * Get the inner radius of the component at cylindrical coordinate (x,theta).
40          * 
41          * Note that the return value may be negative for a slanted object.
42          * 
43          * @param x  Distance in x direction
44          * @param theta  Angle about the x-axis
45          * @return  Distance to the inner edge of the object
46          */
47         public abstract double getInnerRadius(double x, double theta);
48
49         
50
51         /**
52          * Sets the length of the body component.
53          */
54         public void setLength(double length) {
55                 if (this.length == length)
56                         return;
57                 this.length = Math.max(length,0);
58                 fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
59         }
60         
61         
62         /**
63          * Check whether the given type can be added to this component.  BodyComponents allow any
64          * InternalComponents or ExternalComponents, excluding BodyComponents, to be added.
65          * 
66          * @param type  The RocketComponent class type to add.
67          * @return      Whether such a component can be added.
68          */
69         @Override
70         public boolean isCompatible(Class<? extends RocketComponent> type) {
71                 if (InternalComponent.class.isAssignableFrom(type))
72                         return true;
73                 if (ExternalComponent.class.isAssignableFrom(type) &&
74                         !BodyComponent.class.isAssignableFrom(type))
75                         return true;
76                 return false;
77         }
78     
79     /**
80      * Accept a visitor to this BodyComponent in the component hierarchy.
81      * 
82      * @param theVisitor  the visitor that will be called back with a reference to this BodyComponent
83      */
84     @Override 
85     public void accept (final ComponentVisitor theVisitor) {
86         theVisitor.visit(this);
87     }
88     
89     
90 }