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;
10 * Class of components with well-defined physical appearance and which have an effect on
11 * aerodynamic simulation. They have material defined for them, and the mass of the component
12 * is calculated using the component's volume.
14 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
17 public abstract class ExternalComponent extends RocketComponent {
20 ROUGH("Rough", 500e-6),
21 UNFINISHED("Unfinished", 150e-6),
22 NORMAL("Regular paint", 60e-6),
23 SMOOTH("Smooth paint", 20e-6),
24 POLISHED("Polished", 2e-6);
26 private final String name;
27 private final double roughnessSize;
29 Finish(String name, double roughness) {
31 this.roughnessSize = roughness;
34 public double getRoughnessSize() {
39 public String toString() {
40 return name + " (" + UnitGroup.UNITS_ROUGHNESS.toStringUnit(roughnessSize) + ")";
46 * The material of the component.
48 protected Material material = null;
50 protected Finish finish = Finish.NORMAL;
55 * Constructor that sets the relative position of the component.
57 public ExternalComponent(RocketComponent.Position relativePosition) {
58 super(relativePosition);
59 this.material = Prefs.getDefaultComponentMaterial(this.getClass(), Material.Type.BULK);
63 * Returns the volume of the component. This value is used in calculating the mass
66 public abstract double getComponentVolume();
69 * Calculates the mass of the component as the product of the volume and interior density.
72 public double getComponentMass() {
73 return material.getDensity() * getComponentVolume();
77 * ExternalComponent has aerodynamic effect, so return true.
80 public boolean isAerodynamic() {
85 * ExternalComponent has effect on the mass, so return true.
88 public boolean isMassive() {
93 public Material getMaterial() {
97 public void setMaterial(Material mat) {
98 if (mat.getType() != Material.Type.BULK) {
99 throw new IllegalArgumentException("ExternalComponent requires a bulk material" +
100 " type=" + mat.getType());
103 if (material.equals(mat))
106 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
109 public Finish getFinish() {
113 public void setFinish(Finish finish) {
114 if (this.finish == finish)
116 this.finish = finish;
117 fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
122 protected List<RocketComponent> copyFrom(RocketComponent c) {
123 ExternalComponent src = (ExternalComponent) c;
124 this.finish = src.finish;
125 this.material = src.material;
126 return super.copyFrom(c);