diff --git a/core/src/net/sf/openrocket/rocketcomponent/ExternalComponent.java b/core/src/net/sf/openrocket/rocketcomponent/ExternalComponent.java index 4377a8c31..99660a3d1 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/ExternalComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/ExternalComponent.java @@ -16,8 +16,13 @@ import net.sf.openrocket.unit.UnitGroup; * @author Sampo Niskanen */ -public abstract class ExternalComponent extends RocketComponent { - +public abstract class ExternalComponent extends RocketComponent implements OutsideComponent { + + private boolean axial = true; + private double position_angular_rad = 0; + private double position_radial_m = 0; + private double rotation_rad = 0; + public enum Finish { //// Rough ROUGH("ExternalComponent.Rough", 500e-6), @@ -29,36 +34,36 @@ public abstract class ExternalComponent extends RocketComponent { SMOOTH("ExternalComponent.Smoothpaint", 20e-6), //// Polished POLISHED("ExternalComponent.Polished", 2e-6); - + private static final Translator trans = Application.getTranslator(); private final String name; private final double roughnessSize; - + Finish(String name, double roughness) { this.name = name; this.roughnessSize = roughness; } - + public double getRoughnessSize() { return roughnessSize; } - + @Override public String toString() { return trans.get(name) + " (" + UnitGroup.UNITS_ROUGHNESS.toStringUnit(roughnessSize) + ")"; } } - - + + /** * The material of the component. */ protected Material material = null; - + protected Finish finish = Finish.NORMAL; - - - + + + /** * Constructor that sets the relative position of the component. */ @@ -66,13 +71,13 @@ public abstract class ExternalComponent extends RocketComponent { super(relativePosition); this.material = Application.getPreferences().getDefaultComponentMaterial(this.getClass(), Material.Type.BULK); } - + /** * Returns the volume of the component. This value is used in calculating the mass * of the object. */ public abstract double getComponentVolume(); - + /** * Calculates the mass of the component as the product of the volume and interior density. */ @@ -80,7 +85,7 @@ public abstract class ExternalComponent extends RocketComponent { public double getComponentMass() { return material.getDensity() * getComponentVolume(); } - + /** * ExternalComponent has aerodynamic effect, so return true. */ @@ -88,7 +93,7 @@ public abstract class ExternalComponent extends RocketComponent { public boolean isAerodynamic() { return true; } - + /** * ExternalComponent has effect on the mass, so return true. */ @@ -96,50 +101,91 @@ public abstract class ExternalComponent extends RocketComponent { public boolean isMassive() { return true; } - - + + public Material getMaterial() { return material; } - + public void setMaterial(Material mat) { if (mat.getType() != Material.Type.BULK) { throw new IllegalArgumentException("ExternalComponent requires a bulk material" + " type=" + mat.getType()); } - + if (material.equals(mat)) return; material = mat; clearPreset(); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } - + public Finish getFinish() { return finish; } - + public void setFinish(Finish finish) { if (this.finish == finish) return; this.finish = finish; fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE); } - - + + + @Override + public boolean isInline() { + return this.axial; + } + + @Override + public void setInline(final boolean inline) { + this.axial = inline; + } + + @Override + public double getAngularPosition() { + return this.position_angular_rad; + } + + @Override + public void setAngularPosition(final double phi) { + this.position_angular_rad = phi; + } + + @Override + public double getRadialPosition() { + return this.position_radial_m; + } + + @Override + public void setRadialPosition(final double radius) { + this.position_radial_m = radius; + } + + @Override + public double getRotation() { + return this.rotation_rad; + } + + @Override + public void setRotation(final double rotation) { + this.rotation_rad = rotation; + } + + @Override protected void loadFromPreset(ComponentPreset preset) { super.loadFromPreset(preset); - + // Surface finish is left unchanged - - if ( preset.has(ComponentPreset.MATERIAL ) ) { + + if (preset.has(ComponentPreset.MATERIAL)) { Material mat = preset.get(ComponentPreset.MATERIAL); - if ( mat != null ) { + if (mat != null) { material = mat; } /* - TODO - - else if (c.isMassOverridden()) { + TODO - + else if (c.isMassOverridden()) { double mass = c.getOverrideMass(); double volume = getComponentVolume(); double density; @@ -150,12 +196,12 @@ public abstract class ExternalComponent extends RocketComponent { } mat = Material.newMaterial(Type.BULK, mat.getName(), density, true); setMaterial(mat); - } - */ + } + */ } } - - + + @Override protected List copyFrom(RocketComponent c) { ExternalComponent src = (ExternalComponent) c; @@ -163,5 +209,5 @@ public abstract class ExternalComponent extends RocketComponent { this.material = src.material; return super.copyFrom(c); } - + } diff --git a/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java b/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java new file mode 100644 index 000000000..23da91663 --- /dev/null +++ b/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java @@ -0,0 +1,64 @@ +package net.sf.openrocket.rocketcomponent; + +public interface OutsideComponent { + + + /** + * Indicates whether this component is located inside or outside of the rest of the rocket. (Specifically, inside or outside its parent.) + * + * @return True This component is aligned with its parent + * False This component is offset from its parent -- like an external pod, or strap-on stage + */ + public boolean isInline(); + + /** + * Change whether this component is located inside or outside of the rest of the rocket. (Specifically, inside or outside its parent.) + * + * @param inline True indicates that this component axially aligned with its parent. False indicates an off-center component. + */ + public void setInline(final boolean inline); + + /** + * Get the position of this component in polar coordinates + * + * @return Angular position in radians. + */ + public double getAngularPosition(); + + /** + * Set the position of this component in polar coordinates + * + * @param phi Angular position in radians + */ + public void setAngularPosition(final double phi); + + /** + * Get the position of this component in polar coordinates + * + * @return Radial position in radians (m) + */ + public double getRadialPosition(); + + /** + * Get the position of this component in polar coordinates + * + * @param radius Radial distance in standard units. (m) + */ + public void setRadialPosition(final double radius); + + /** + * If component is not symmetric, this is the axial rotation angle (around it's own center). Defaults to 0. + * + * @return Rotation angle in radians. + */ + public double getRotation(); + + /** + * If component is not symmetric, this is the axial rotation angle (around it's own center). Defaults to 0. + * + * @param rotation Rotation angle in radians. + */ + public void setRotation(final double rotation); + + +} diff --git a/core/src/net/sf/openrocket/rocketcomponent/Stage.java b/core/src/net/sf/openrocket/rocketcomponent/Stage.java index a3885117b..0c04b870f 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Stage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Stage.java @@ -3,12 +3,16 @@ package net.sf.openrocket.rocketcomponent; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.startup.Application; -public class Stage extends ComponentAssembly implements FlightConfigurableComponent { +public class Stage extends ComponentAssembly implements FlightConfigurableComponent, OutsideComponent { static final Translator trans = Application.getTranslator(); private FlightConfigurationImpl separationConfigurations; + private boolean axial = true; + private double position_angular_rad = 0; + private double position_radial_m = 0; + private double rotation_rad = 0; public Stage() { this.separationConfigurations = new FlightConfigurationImpl(this, ComponentChangeEvent.EVENT_CHANGE, new StageSeparationConfiguration()); @@ -61,4 +65,44 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon return copy; } + @Override + public boolean isInline() { + return this.axial; + } + + @Override + public void setInline(final boolean inline) { + this.axial = inline; + } + + @Override + public double getAngularPosition() { + return this.position_angular_rad; + } + + @Override + public void setAngularPosition(final double phi) { + this.position_angular_rad = phi; + } + + @Override + public double getRadialPosition() { + return this.position_radial_m; + } + + @Override + public void setRadialPosition(final double radius) { + this.position_radial_m = radius; + } + + @Override + public double getRotation() { + return this.rotation_rad; + } + + @Override + public void setRotation(final double rotation) { + this.rotation_rad = rotation; + } + }