Added OutsideComponent.java; Implemented in ExternalComponent and Stage
OutsideComponent.java is an interface which describes components place outside the rocket (i.e. wing-tip pods, or strap-on boosters stages. The interface is minimal, consisting merely of a couple getters and setters for the external position, rotation, and a flag to turn this on and off.
This commit is contained in:
parent
7b6367b30b
commit
58d9e8f682
@ -16,8 +16,13 @@ import net.sf.openrocket.unit.UnitGroup;
|
||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||
*/
|
||||
|
||||
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<RocketComponent> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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 <code> True </code> This component is aligned with its parent
|
||||
* <code> False </code> 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);
|
||||
|
||||
|
||||
}
|
@ -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<StageSeparationConfiguration> 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<StageSeparationConfiguration>(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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user