1 package net.sf.openrocket.rocketcomponent;
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.material.Material;
5 import net.sf.openrocket.startup.Application;
6 import net.sf.openrocket.unit.UnitGroup;
7 import net.sf.openrocket.util.Prefs;
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.
16 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
19 public abstract class ExternalComponent extends RocketComponent {
23 ROUGH("ExternalComponent.Rough", 500e-6),
25 UNFINISHED("ExternalComponent.Unfinished", 150e-6),
27 NORMAL("ExternalComponent.Regularpaint", 60e-6),
29 SMOOTH("ExternalComponent.Smoothpaint", 20e-6),
31 POLISHED("ExternalComponent.Polished", 2e-6);
33 private final String name;
34 private final double roughnessSize;
36 Finish(String name, double roughness) {
38 this.roughnessSize = roughness;
41 public double getRoughnessSize() {
46 public String toString() {
47 final Translator trans = Application.getTranslator();
48 return trans.get(name) + " (" + UnitGroup.UNITS_ROUGHNESS.toStringUnit(roughnessSize) + ")";
54 * The material of the component.
56 protected Material material = null;
58 protected Finish finish = Finish.NORMAL;
63 * Constructor that sets the relative position of the component.
65 public ExternalComponent(RocketComponent.Position relativePosition) {
66 super(relativePosition);
67 this.material = Prefs.getDefaultComponentMaterial(this.getClass(), Material.Type.BULK);
71 * Returns the volume of the component. This value is used in calculating the mass
74 public abstract double getComponentVolume();
77 * Calculates the mass of the component as the product of the volume and interior density.
80 public double getComponentMass() {
81 return material.getDensity() * getComponentVolume();
85 * ExternalComponent has aerodynamic effect, so return true.
88 public boolean isAerodynamic() {
93 * ExternalComponent has effect on the mass, so return true.
96 public boolean isMassive() {
101 public Material getMaterial() {
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());
111 if (material.equals(mat))
114 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
117 public Finish getFinish() {
121 public void setFinish(Finish finish) {
122 if (this.finish == finish)
124 this.finish = finish;
125 fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
130 protected List<RocketComponent> copyFrom(RocketComponent c) {
131 ExternalComponent src = (ExternalComponent) c;
132 this.finish = src.finish;
133 this.material = src.material;
134 return super.copyFrom(c);