I18 changes
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / ExternalComponent.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import java.util.List;
4
5 import net.sf.openrocket.l10n.Translator;
6 import net.sf.openrocket.material.Material;
7 import net.sf.openrocket.startup.Application;
8 import net.sf.openrocket.unit.UnitGroup;
9 import net.sf.openrocket.util.Prefs;
10
11 /**
12  * Class of components with well-defined physical appearance and which have an effect on
13  * aerodynamic simulation.  They have material defined for them, and the mass of the component 
14  * is calculated using the component's volume.
15  * 
16  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
17  */
18
19 public abstract class ExternalComponent extends RocketComponent {
20         
21         public enum Finish {
22                 //// Rough
23                 ROUGH("ExternalComponent.Rough", 500e-6),
24                 //// Unfinished
25                 UNFINISHED("ExternalComponent.Unfinished", 150e-6),
26                 //// Regular paint
27                 NORMAL("ExternalComponent.Regularpaint", 60e-6),
28                 //// Smooth paint
29                 SMOOTH("ExternalComponent.Smoothpaint", 20e-6),
30                 //// Polished
31                 POLISHED("ExternalComponent.Polished", 2e-6);
32                 
33                 private final String name;
34                 private final double roughnessSize;
35                 
36                 Finish(String name, double roughness) {
37                         this.name = name;
38                         this.roughnessSize = roughness;
39                 }
40                 
41                 public double getRoughnessSize() {
42                         return roughnessSize;
43                 }
44                 
45                 @Override
46                 public String toString() {
47                         final Translator trans = Application.getTranslator();
48                         return trans.get(name) + " (" + UnitGroup.UNITS_ROUGHNESS.toStringUnit(roughnessSize) + ")";
49                 }
50         }
51         
52         
53         /**
54          * The material of the component.
55          */
56         protected Material material = null;
57         
58         protected Finish finish = Finish.NORMAL;
59         
60         
61
62         /**
63          * Constructor that sets the relative position of the component.
64          */
65         public ExternalComponent(RocketComponent.Position relativePosition) {
66                 super(relativePosition);
67                 this.material = Prefs.getDefaultComponentMaterial(this.getClass(), Material.Type.BULK);
68         }
69         
70         /**
71          * Returns the volume of the component.  This value is used in calculating the mass
72          * of the object.
73          */
74         public abstract double getComponentVolume();
75         
76         /**
77          * Calculates the mass of the component as the product of the volume and interior density.
78          */
79         @Override
80         public double getComponentMass() {
81                 return material.getDensity() * getComponentVolume();
82         }
83         
84         /**
85          * ExternalComponent has aerodynamic effect, so return true.
86          */
87         @Override
88         public boolean isAerodynamic() {
89                 return true;
90         }
91         
92         /**
93          * ExternalComponent has effect on the mass, so return true.
94          */
95         @Override
96         public boolean isMassive() {
97                 return true;
98         }
99         
100         
101         public Material getMaterial() {
102                 return material;
103         }
104         
105         public void setMaterial(Material mat) {
106                 if (mat.getType() != Material.Type.BULK) {
107                         throw new IllegalArgumentException("ExternalComponent requires a bulk material" +
108                                         " type=" + mat.getType());
109                 }
110                 
111                 if (material.equals(mat))
112                         return;
113                 material = mat;
114                 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
115         }
116         
117         public Finish getFinish() {
118                 return finish;
119         }
120         
121         public void setFinish(Finish finish) {
122                 if (this.finish == finish)
123                         return;
124                 this.finish = finish;
125                 fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
126         }
127         
128         
129
130         @Override
131         protected List<RocketComponent> copyFrom(RocketComponent c) {
132                 ExternalComponent src = (ExternalComponent) c;
133                 this.finish = src.finish;
134                 this.material = src.material;
135                 return super.copyFrom(c);
136         }
137         
138     /**
139      * Accept a visitor to this ExternalComponent in the component hierarchy.
140      * 
141      * @param theVisitor  the visitor that will be called back with a reference to this ExternalComponent
142      */
143     @Override 
144     public void accept (final ComponentVisitor theVisitor) {
145         theVisitor.visit(this);
146     }
147     
148 }