1 package net.sf.openrocket.rocketcomponent;
5 import net.sf.openrocket.l10n.Translator;
6 import net.sf.openrocket.material.Material;
7 import net.sf.openrocket.material.Material.Type;
8 import net.sf.openrocket.startup.Application;
9 import net.sf.openrocket.unit.UnitGroup;
10 import net.sf.openrocket.util.Prefs;
13 * Class of components with well-defined physical appearance and which have an effect on
14 * aerodynamic simulation. They have material defined for them, and the mass of the component
15 * is calculated using the component's volume.
17 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
20 public abstract class ExternalComponent extends RocketComponent {
24 ROUGH("ExternalComponent.Rough", 500e-6),
26 UNFINISHED("ExternalComponent.Unfinished", 150e-6),
28 NORMAL("ExternalComponent.Regularpaint", 60e-6),
30 SMOOTH("ExternalComponent.Smoothpaint", 20e-6),
32 POLISHED("ExternalComponent.Polished", 2e-6);
34 private static final Translator trans = Application.getTranslator();
35 private final String name;
36 private final double roughnessSize;
38 Finish(String name, double roughness) {
40 this.roughnessSize = roughness;
43 public double getRoughnessSize() {
48 public String toString() {
49 return trans.get(name) + " (" + UnitGroup.UNITS_ROUGHNESS.toStringUnit(roughnessSize) + ")";
55 * The material of the component.
57 protected Material material = null;
59 protected Finish finish = Finish.NORMAL;
64 * Constructor that sets the relative position of the component.
66 public ExternalComponent(RocketComponent.Position relativePosition) {
67 super(relativePosition);
68 this.material = Prefs.getDefaultComponentMaterial(this.getClass(), Material.Type.BULK);
72 * Returns the volume of the component. This value is used in calculating the mass
75 public abstract double getComponentVolume();
78 * Calculates the mass of the component as the product of the volume and interior density.
81 public double getComponentMass() {
82 return material.getDensity() * getComponentVolume();
86 * ExternalComponent has aerodynamic effect, so return true.
89 public boolean isAerodynamic() {
94 * ExternalComponent has effect on the mass, so return true.
97 public boolean isMassive() {
102 public Material getMaterial() {
106 public void setMaterial(Material mat) {
107 if (mat.getType() != Material.Type.BULK) {
108 throw new IllegalArgumentException("ExternalComponent requires a bulk material" +
109 " type=" + mat.getType());
112 if (material.equals(mat))
116 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
120 public Finish getFinish() {
124 public void setFinish(Finish finish) {
125 if (this.finish == finish)
127 this.finish = finish;
128 fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
133 protected void loadFromPreset(RocketComponent preset) {
134 super.loadFromPreset(preset);
136 // Surface finish is left unchanged
138 ExternalComponent c = (ExternalComponent) preset;
140 Material mat = c.getMaterial();
141 if (c.isMassOverridden()) {
142 double mass = c.getOverrideMass();
143 double volume = getComponentVolume();
145 if (volume > 0.00001) {
146 density = mass / volume;
150 mat = Material.newMaterial(Type.BULK, mat.getName(), density, true);
158 protected List<RocketComponent> copyFrom(RocketComponent c) {
159 ExternalComponent src = (ExternalComponent) c;
160 this.finish = src.finish;
161 this.material = src.material;
162 return super.copyFrom(c);