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.preset.ComponentPreset;
8 import net.sf.openrocket.startup.Application;
9 import net.sf.openrocket.unit.UnitGroup;
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 static final Translator trans = Application.getTranslator();
34 private final String name;
35 private final double roughnessSize;
37 Finish(String name, double roughness) {
39 this.roughnessSize = roughness;
42 public double getRoughnessSize() {
47 public String toString() {
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 = Application.getPreferences().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))
115 fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
118 public Finish getFinish() {
122 public void setFinish(Finish finish) {
123 if (this.finish == finish)
125 this.finish = finish;
126 fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE);
131 protected void loadFromPreset(ComponentPreset preset) {
132 super.loadFromPreset(preset);
134 // Surface finish is left unchanged
136 if ( preset.has(ComponentPreset.MATERIAL ) ) {
137 Material mat = preset.get(ComponentPreset.MATERIAL);
142 else if (c.isMassOverridden()) {
143 double mass = c.getOverrideMass();
144 double volume = getComponentVolume();
146 if (volume > 0.00001) {
147 density = mass / volume;
151 mat = Material.newMaterial(Type.BULK, mat.getName(), density, true);
160 protected List<RocketComponent> copyFrom(RocketComponent c) {
161 ExternalComponent src = (ExternalComponent) c;
162 this.finish = src.finish;
163 this.material = src.material;
164 return super.copyFrom(c);