bug fixes and rocket optimization
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / BodyTube.java
index b84478e7dc7f6578bb72a2e08173615f38fd717a..7725bbae4b91de346429991251b8d9fc2accd04f 100644 (file)
@@ -4,18 +4,21 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 
+import net.sf.openrocket.l10n.Translator;
 import net.sf.openrocket.motor.Motor;
+import net.sf.openrocket.startup.Application;
 import net.sf.openrocket.util.Coordinate;
 import net.sf.openrocket.util.MathUtil;
 
 
 /**
  * Rocket body tube component.  Has only two parameters, a radius and length.
- * 
+ *
  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
  */
 
-public class BodyTube extends SymmetricComponent implements MotorMount {
+public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial {
+       private static final Translator trans = Application.getTranslator();
        
        private double radius = 0;
        private boolean autoRadius = false; // Radius chosen automatically based on parent component
@@ -61,8 +64,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
        
        /**
         * Return the outer radius of the body tube.
+        *
+        * @return  the outside radius of the tube
         */
-       public double getRadius() {
+       @Override
+       public double getOuterRadius() {
                if (autoRadius) {
                        // Return auto radius from front or rear
                        double r = -1;
@@ -88,8 +94,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
         * Set the outer radius of the body tube.  If the radius is less than the wall thickness,
         * the wall thickness is decreased accordingly of the value of the radius.
         * This method sets the automatic radius off.
+        *
+        * @param radius  the outside radius in standard units
         */
-       public void setRadius(double radius) {
+       @Override
+       public void setOuterRadius(double radius) {
                if ((this.radius == radius) && (autoRadius == false))
                        return;
                
@@ -106,14 +115,14 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
         * Returns whether the radius is selected automatically or not.
         * Returns false also in case automatic radius selection is not possible.
         */
-       public boolean isRadiusAutomatic() {
+       public boolean isOuterRadiusAutomatic() {
                return autoRadius;
        }
        
        /**
-        * Sets whether the radius is selected automatically or not.  
+        * Sets whether the radius is selected automatically or not.
         */
-       public void setRadiusAutomatic(boolean auto) {
+       public void setOuterRadiusAutomatic(boolean auto) {
                if (autoRadius == auto)
                        return;
                
@@ -124,29 +133,29 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
        
        @Override
        public double getAftRadius() {
-               return getRadius();
+               return getOuterRadius();
        }
        
        @Override
        public double getForeRadius() {
-               return getRadius();
+               return getOuterRadius();
        }
        
        @Override
        public boolean isAftRadiusAutomatic() {
-               return isRadiusAutomatic();
+               return isOuterRadiusAutomatic();
        }
        
        @Override
        public boolean isForeRadiusAutomatic() {
-               return isRadiusAutomatic();
+               return isOuterRadiusAutomatic();
        }
        
        
 
        @Override
        protected double getFrontAutoRadius() {
-               if (isRadiusAutomatic()) {
+               if (isOuterRadiusAutomatic()) {
                        // Search for previous SymmetricComponent
                        SymmetricComponent c = this.getPreviousSymmetricComponent();
                        if (c != null) {
@@ -155,12 +164,12 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
                                return -1;
                        }
                }
-               return getRadius();
+               return getOuterRadius();
        }
        
        @Override
        protected double getRearAutoRadius() {
-               if (isRadiusAutomatic()) {
+               if (isOuterRadiusAutomatic()) {
                        // Search for next SymmetricComponent
                        SymmetricComponent c = this.getNextSymmetricComponent();
                        if (c != null) {
@@ -169,21 +178,23 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
                                return -1;
                        }
                }
-               return getRadius();
+               return getOuterRadius();
        }
        
        
 
 
 
+       @Override
        public double getInnerRadius() {
                if (filled)
                        return 0;
-               return Math.max(getRadius() - thickness, 0);
+               return Math.max(getOuterRadius() - thickness, 0);
        }
        
+       @Override
        public void setInnerRadius(double r) {
-               setThickness(getRadius() - r);
+               setThickness(getOuterRadius() - r);
        }
        
        
@@ -194,7 +205,8 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
         */
        @Override
        public String getComponentName() {
-               return "Body tube";
+               //// Body tube
+               return trans.get("BodyTube.BodyTube");
        }
        
        
@@ -202,11 +214,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
        
        // From SymmetricComponent
        /**
-        * Returns the outer radius at the position x.  This returns the same value as getRadius().
+        * Returns the outer radius at the position x.  This returns the same value as getOuterRadius().
         */
        @Override
        public double getRadius(double x) {
-               return getRadius();
+               return getOuterRadius();
        }
        
        /**
@@ -217,7 +229,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
                if (filled)
                        return 0.0;
                else
-                       return Math.max(getRadius() - thickness, 0);
+                       return Math.max(getOuterRadius() - thickness, 0);
        }
        
        
@@ -234,7 +246,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
         */
        @Override
        public double getComponentVolume() {
-               double r = getRadius();
+               double r = getOuterRadius();
                if (filled)
                        return getFilledVolume(r, length);
                else
@@ -243,15 +255,15 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
        
        
        @Override
-       public double getLongitudalUnitInertia() {
+       public double getLongitudinalUnitInertia() {
                // 1/12 * (3 * (r1^2 + r2^2) + h^2)
-               return (3 * (MathUtil.pow2(getInnerRadius())) + MathUtil.pow2(getRadius()) + MathUtil.pow2(getLength())) / 12;
+               return (3 * (MathUtil.pow2(getInnerRadius())) + MathUtil.pow2(getOuterRadius()) + MathUtil.pow2(getLength())) / 12;
        }
        
        @Override
        public double getRotationalUnitInertia() {
                // 1/2 * (r1^2 + r2^2)
-               return (MathUtil.pow2(getInnerRadius()) + MathUtil.pow2(getRadius())) / 2;
+               return (MathUtil.pow2(getInnerRadius()) + MathUtil.pow2(getOuterRadius())) / 2;
        }
        
        
@@ -268,19 +280,37 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
        /**
         * Adds bounding coordinates to the given set.  The body tube will fit within the
         * convex hull of the points.
-        * 
+        *
         * Currently the points are simply a rectangular box around the body tube.
         */
        @Override
        public Collection<Coordinate> getComponentBounds() {
                Collection<Coordinate> bounds = new ArrayList<Coordinate>(8);
-               double r = getRadius();
+               double r = getOuterRadius();
                addBound(bounds, 0, r);
                addBound(bounds, length, r);
                return bounds;
        }
        
        
+
+       /**
+        * Check whether the given type can be added to this component.  BodyTubes allow any
+        * InternalComponents or ExternalComponents, excluding BodyComponents, to be added.
+        *
+        * @param type  The RocketComponent class type to add.
+        * @return      Whether such a component can be added.
+        */
+       @Override
+       public boolean isCompatible(Class<? extends RocketComponent> type) {
+               if (InternalComponent.class.isAssignableFrom(type))
+                       return true;
+               if (ExternalComponent.class.isAssignableFrom(type) &&
+                               !BodyComponent.class.isAssignableFrom(type))
+                       return true;
+               return false;
+       }
+       
        ////////////////  Motor mount  /////////////////
        
        @Override
@@ -408,7 +438,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount {
        /*
         * (non-Javadoc)
         * Copy the motor and ejection delay HashMaps.
-        * 
+        *
         * @see rocketcomponent.RocketComponent#copy()
         */
        @SuppressWarnings("unchecked")