1 package net.sf.openrocket.rocketcomponent;
3 import net.sf.openrocket.material.Material;
4 import net.sf.openrocket.unit.UnitGroup;
5 import net.sf.openrocket.util.Prefs;
8 * Class of components with well-defined physical appearance and which have an effect on
9 * aerodynamic simulation. They have material defined for them, and the mass of the component
10 * is calculated using the component's volume.
12 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
15 public abstract class ExternalComponent extends RocketComponent {
18 ROUGH("Rough", 500e-6),
19 UNFINISHED("Unfinished", 150e-6),
20 NORMAL("Regular paint", 60e-6),
21 SMOOTH("Smooth paint", 20e-6),
22 POLISHED("Polished", 2e-6);
24 private final String name;
25 private final double roughnessSize;
27 Finish(String name, double roughness) {
29 this.roughnessSize = roughness;
32 public double getRoughnessSize() {
37 public String toString() {
38 return name + " (" + UnitGroup.UNITS_ROUGHNESS.toStringUnit(roughnessSize) + ")";
44 * The material of the component.
46 protected Material material=null;
48 protected Finish finish = Finish.NORMAL;
53 * Constructor that sets the relative position of the component.
55 public ExternalComponent(RocketComponent.Position relativePosition) {
56 super(relativePosition);
57 this.material = Prefs.getDefaultComponentMaterial(this.getClass(), Material.Type.BULK);
61 * Returns the volume of the component. This value is used in calculating the mass
64 public abstract double getComponentVolume();
67 * Calculates the mass of the component as the product of the volume and interior density.
70 public double getComponentMass() {
71 return material.getDensity() * getComponentVolume();
75 * ExternalComponent has aerodynamic effect, so return true.
78 public boolean isAerodynamic() {
83 * ExternalComponent has effect on the mass, so return true.
86 public boolean isMassive() {
91 public Material getMaterial() {
95 public void setMaterial(Material mat) {
96 if (mat.getType() != Material.Type.BULK) {
97 throw new IllegalArgumentException("ExternalComponent requires a bulk material" +
98 " type="+mat.getType());
101 if (material.equals(mat))
104 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
107 public Finish getFinish() {
111 public void setFinish(Finish finish) {
112 if (this.finish == finish)
114 this.finish = finish;
115 fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);