import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.material.Material;
+import net.sf.openrocket.material.Material.Type;
+import net.sf.openrocket.preset.ExternalComponentPreset;
+import net.sf.openrocket.preset.RocketComponentPreset;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Prefs;
/**
* Class of components with well-defined physical appearance and which have an effect on
- * aerodynamic simulation. They have material defined for them, and the mass of the component
+ * aerodynamic simulation. They have material defined for them, and the mass of the component
* is calculated using the component's volume.
- *
+ *
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
//// Polished
POLISHED("ExternalComponent.Polished", 2e-6);
+ private static final Translator trans = Application.getTranslator();
private final String name;
private final double roughnessSize;
@Override
public String toString() {
- final Translator trans = Application.getTranslator();
return trans.get(name) + " (" + UnitGroup.UNITS_ROUGHNESS.toStringUnit(roughnessSize) + ")";
}
}
if (material.equals(mat))
return;
material = mat;
+ clearPreset();
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
}
}
-
+ @Override
+ protected void loadFromPreset(RocketComponentPreset preset) {
+ super.loadFromPreset(preset);
+
+ ExternalComponentPreset p = (ExternalComponentPreset) preset;
+ String materialName = p.getMaterialName();
+ double mass = p.getMass();
+
+ double volume = getComponentVolume();
+ double density;
+ if (volume > 0.00001) {
+ density = mass / volume;
+ } else {
+ density = 1000;
+ }
+
+ Material mat = Material.newMaterial(Type.BULK, materialName, density, true);
+ setMaterial(mat);
+ }
+
+
@Override
protected List<RocketComponent> copyFrom(RocketComponent c) {
ExternalComponent src = (ExternalComponent) c;
return super.copyFrom(c);
}
- /**
- * Accept a visitor to this ExternalComponent in the component hierarchy.
- *
- * @param theVisitor the visitor that will be called back with a reference to this ExternalComponent
- */
- @Override
- public void accept (final ComponentVisitor theVisitor) {
- theVisitor.visit(this);
- }
-
}