[refactor] Pods and ParallelStages are now attached to BodyTubes *only*

This commit is contained in:
Daniel_M_Williams 2018-01-07 14:19:02 -05:00
parent 20eff575f4
commit 23d7397fa6
13 changed files with 436 additions and 521 deletions

View File

@ -38,7 +38,7 @@ public enum IgnitionEvent {
AxialStage targetStage = (AxialStage)targetComponent.getStage(); AxialStage targetStage = (AxialStage)targetComponent.getStage();
AxialStage eventStage = (AxialStage)testEvent.getSource().getStage(); AxialStage eventStage = (AxialStage)testEvent.getSource().getStage();
AxialStage eventParentStage = eventStage.getPreviousStage(); AxialStage eventParentStage = eventStage.getUpperStage();
return ( targetStage.equals(eventParentStage)); return ( targetStage.equals(eventParentStage));
} }
}, },
@ -50,7 +50,7 @@ public enum IgnitionEvent {
AxialStage targetStage = (AxialStage)targetComponent.getStage(); AxialStage targetStage = (AxialStage)targetComponent.getStage();
AxialStage eventStage = (AxialStage)testEvent.getSource().getStage(); AxialStage eventStage = (AxialStage)testEvent.getSource().getStage();
AxialStage eventParentStage = eventStage.getPreviousStage(); AxialStage eventParentStage = eventStage.getUpperStage();
return ( targetStage.equals(eventParentStage)); return ( targetStage.equals(eventParentStage));
} }
}, },

View File

@ -82,12 +82,6 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
*/ */
@Override @Override
public boolean isCompatible(Class<? extends RocketComponent> type) { public boolean isCompatible(Class<? extends RocketComponent> type) {
if (ParallelStage.class.isAssignableFrom(type)) {
return true;
} else if (PodSet.class.isAssignableFrom(type)) {
return true;
}
return BodyComponent.class.isAssignableFrom(type); return BodyComponent.class.isAssignableFrom(type);
} }
@ -180,16 +174,16 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
* returns null if this is the first stage * returns null if this is the first stage
* @return the previous stage in the rocket * @return the previous stage in the rocket
*/ */
public AxialStage getPreviousStage() { public AxialStage getUpperStage() {
if( this instanceof ParallelStage ){ if( null == this.parent ) {
return (AxialStage) this.parent; return null;
} }else if(Rocket.class.isAssignableFrom(this.parent.getClass()) ){
AxialStage thisStage = this.getStage(); // necessary in case of pods or other assemblies final int thisIndex = getStageNumber();
if( thisStage.parent instanceof Rocket ){
final int thisIndex = parent.getChildPosition( thisStage );
if( 0 < thisIndex ){ if( 0 < thisIndex ){
return (AxialStage)thisStage.parent.getChild(thisIndex-1); return (AxialStage)parent.getChild(thisIndex-1);
} }
}else {
return this.parent.getStage();
} }
return null; return null;
} }

View File

@ -351,6 +351,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
*/ */
@Override @Override
public boolean isCompatible(Class<? extends RocketComponent> type) { public boolean isCompatible(Class<? extends RocketComponent> type) {
if (ParallelStage.class.isAssignableFrom(type))
return true;
if (PodSet.class.isAssignableFrom(type))
return true;
if (InternalComponent.class.isAssignableFrom(type)) if (InternalComponent.class.isAssignableFrom(type))
return true; return true;
if (ExternalComponent.class.isAssignableFrom(type) && if (ExternalComponent.class.isAssignableFrom(type) &&

View File

@ -38,7 +38,7 @@ public abstract class ComponentAssembly extends RocketComponent {
@Override @Override
public double getAxialOffset() { public double getAxialOffset() {
return super.asPositionValue(this.relativePosition); return asPositionValue(this.relativePosition);
} }
/** /**

View File

@ -183,6 +183,7 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
return this.autoRadialPosition; return this.autoRadialPosition;
} }
@Override
public void setAutoRadialOffset( final boolean enabled ){ public void setAutoRadialOffset( final boolean enabled ){
this.autoRadialPosition = enabled; this.autoRadialPosition = enabled;
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
@ -207,11 +208,11 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
super.update(); super.update();
if( this.autoRadialPosition){ if( this.autoRadialPosition){
ComponentAssembly parentAssembly = (ComponentAssembly)this.parent; if( null == this.parent ){
if( null == parentAssembly ){
this.radialPosition_m = this.getOuterRadius(); this.radialPosition_m = this.getOuterRadius();
}else{ }else if( BodyTube.class.isAssignableFrom(this.parent.getClass())) {
this.radialPosition_m = this.getOuterRadius() + parentAssembly.getOuterRadius(); BodyTube parentBody = (BodyTube)this.parent;
this.radialPosition_m = this.getOuterRadius() + parentBody.getOuterRadius();
} }
} }
} }

View File

@ -227,11 +227,11 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
super.update(); super.update();
if( this.autoRadialPosition){ if( this.autoRadialPosition){
ComponentAssembly parentAssembly = (ComponentAssembly)this.parent; if( null == this.parent ){
if( null == parentAssembly ){
this.radialPosition_m = this.getOuterRadius(); this.radialPosition_m = this.getOuterRadius();
}else{ }else if( BodyTube.class.isAssignableFrom(this.parent.getClass())) {
this.radialPosition_m = this.getOuterRadius() + parentAssembly.getOuterRadius(); BodyTube parentBody = (BodyTube)this.parent;
this.radialPosition_m = this.getOuterRadius() + parentBody.getOuterRadius();
} }
} }
} }

View File

@ -11,6 +11,7 @@ import java.util.NoSuchElementException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import junit.framework.Assert;
import net.sf.openrocket.appearance.Appearance; import net.sf.openrocket.appearance.Appearance;
import net.sf.openrocket.appearance.Decal; import net.sf.openrocket.appearance.Decal;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
@ -110,7 +111,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
protected double length = 0; protected double length = 0;
/** /**
* Positioning of this component relative to the parent component. * How this component is axially positioned, possibly in relative to the parent component.
*/ */
protected Position relativePosition = Position.AFTER; protected Position relativePosition = Position.AFTER;
@ -992,32 +993,29 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
* @return double position of the component relative to the parent, with respect to <code>position</code> * @return double position of the component relative to the parent, with respect to <code>position</code>
*/ */
public double asPositionValue(Position thePosition) { public double asPositionValue(Position thePosition) {
double relativeLength; double parentLength;
if (null == this.parent) { if (null == this.parent) {
relativeLength = 0; parentLength = 0;
}else{ }else{
relativeLength = this.parent.length; parentLength = this.parent.length;
} }
double thisX = this.position.x;
double result = Double.NaN; double result = Double.NaN;
switch (thePosition) { switch (thePosition) {
case AFTER: case AFTER:
result = thisX - relativeLength; result = this.position.x - parentLength;
break; break;
case ABSOLUTE: case ABSOLUTE:
Coordinate[] insts = this.getLocations(); result = this.getComponentLocations()[0].x;
result = insts[0].x;
break; break;
case TOP: case TOP:
result = thisX; result = this.position.x;
break; break;
case MIDDLE: case MIDDLE:
result = thisX + (-relativeLength + this.getLength()) / 2; result = this.position.x + ( this.length - parentLength) / 2;
break; break;
case BOTTOM: case BOTTOM:
result = thisX + (-relativeLength + this.getLength()); result = this.position.x + ( this.length - parentLength);
break; break;
default: default:
throw new BugException("Unknown position type: " + thePosition); throw new BugException("Unknown position type: " + thePosition);
@ -1096,6 +1094,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
}else{ }else{
this.relativePosition = positionMethod; this.relativePosition = positionMethod;
} }
if (null == this.parent) { if (null == this.parent) {
// if this is the root of a hierarchy, constrain the position to zero. // if this is the root of a hierarchy, constrain the position to zero.
if( this instanceof Rocket ){ if( this instanceof Rocket ){
@ -1113,9 +1112,10 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
final double EPSILON = 0.000001; final double EPSILON = 0.000001;
double newAxialPosition = Double.NaN; double newAxialPosition = Double.NaN;
final double refLength = this.parent.getLength(); final double refLength = this.parent.getLength();
switch (this.relativePosition) { switch (this.relativePosition) {
case ABSOLUTE: case ABSOLUTE:
newAxialPosition = newOffset - this.parent.position.x; newAxialPosition = newOffset - this.parent.getComponentLocations()[0].x;
break; break;
case AFTER: case AFTER:
// no-op // no-op
@ -1129,6 +1129,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
break; break;
case BOTTOM: case BOTTOM:
newAxialPosition = (refLength - this.length) + newOffset; newAxialPosition = (refLength - this.length) + newOffset;
//System.err.println(String.format("____( %.6g - %.6g) + %.6g = %.6g", refLength, this.length, newOffset, newAxialPosition ));
break; break;
default: default:
throw new BugException("Unknown position type: " + this.relativePosition); throw new BugException("Unknown position type: " + this.relativePosition);

View File

@ -935,13 +935,12 @@ public class TestRockets {
coreBody.setMotorMount(true); coreBody.setMotorMount(true);
coreStage.addChild( coreBody); coreStage.addChild( coreBody);
{ {
MotorConfiguration motorConfig = new MotorConfiguration(coreBody, selFCID); MotorConfiguration coreMotorConfig = new MotorConfiguration(coreBody, selFCID);
Motor mtr = TestRockets.generateMotor_M1350_75mm(); Motor mtr = TestRockets.generateMotor_M1350_75mm();
motorConfig.setMotor( mtr); coreMotorConfig.setMotor( mtr);
coreBody.setMotorMount( true); coreBody.setMotorMount( true);
FlightConfigurationId motorConfigId = selFCID; FlightConfigurationId motorConfigId = selFCID;
coreBody.setMotorConfig( motorConfig, motorConfigId); coreBody.setMotorConfig( coreMotorConfig, motorConfigId);
}
TrapezoidFinSet coreFins = new TrapezoidFinSet(); TrapezoidFinSet coreFins = new TrapezoidFinSet();
coreFins.setName("Core Fins"); coreFins.setName("Core Fins");
@ -962,7 +961,7 @@ public class TestRockets {
// ====== ====== ====== ====== // ====== ====== ====== ======
ParallelStage boosterStage = new ParallelStage(); ParallelStage boosterStage = new ParallelStage();
boosterStage.setName("Booster Stage"); boosterStage.setName("Booster Stage");
coreStage.addChild( boosterStage); coreBody.addChild( boosterStage);
boosterStage.setRelativePositionMethod(Position.BOTTOM); boosterStage.setRelativePositionMethod(Position.BOTTOM);
boosterStage.setAxialOffset(0.0); boosterStage.setAxialOffset(0.0);
boosterStage.setInstanceCount(2); boosterStage.setInstanceCount(2);
@ -997,14 +996,15 @@ public class TestRockets {
boosterMotorTubes.setClusterScale(1.0); boosterMotorTubes.setClusterScale(1.0);
boosterBody.addChild( boosterMotorTubes); boosterBody.addChild( boosterMotorTubes);
FlightConfigurationId motorConfigId = selFCID; MotorConfiguration boosterMotorConfig = new MotorConfiguration( boosterMotorTubes, selFCID);
MotorConfiguration motorConfig = new MotorConfiguration( boosterMotorTubes, selFCID); Motor boosterMotor = TestRockets.generateMotor_G77_29mm();
Motor mtr = TestRockets.generateMotor_G77_29mm(); boosterMotorConfig.setMotor( boosterMotor );
motorConfig.setMotor(mtr); boosterMotorTubes.setMotorConfig( boosterMotorConfig, motorConfigId);
boosterMotorTubes.setMotorConfig( motorConfig, motorConfigId);
boosterMotorTubes.setMotorOverhang(0.01234); boosterMotorTubes.setMotorOverhang(0.01234);
} }
} }
}
} }
rocket.enableEvents(); rocket.enableEvents();

View File

@ -180,7 +180,7 @@ public class BarrowmanCalculatorTest {
Rocket rocket = TestRockets.makeFalcon9Heavy(); Rocket rocket = TestRockets.makeFalcon9Heavy();
AerodynamicCalculator calc = new BarrowmanCalculator(); AerodynamicCalculator calc = new BarrowmanCalculator();
ParallelStage booster = (ParallelStage)rocket.getChild(1).getChild(1); ParallelStage booster = (ParallelStage)rocket.getChild(1).getChild(0).getChild(1);
NoseCone nose = (NoseCone)booster.getChild(0); NoseCone nose = (NoseCone)booster.getChild(0);
BodyTube body = (BodyTube)booster.getChild(1); BodyTube body = (BodyTube)booster.getChild(1);

View File

@ -205,7 +205,7 @@ public class MassCalculatorTest extends BaseTestCase {
// ====== Booster Set Stage ====== // ====== Booster Set Stage ======
// ====== ====== ====== // ====== ====== ======
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(1); ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(0).getChild(1);
{ {
expMass = 0.0222459863653; expMass = 0.0222459863653;
// think of the casts as an assert that ( child instanceof NoseCone) == true // think of the casts as an assert that ( child instanceof NoseCone) == true
@ -288,7 +288,7 @@ public class MassCalculatorTest extends BaseTestCase {
// ====== Booster Set Stage ====== // ====== Booster Set Stage ======
// ====== ====== ====== // ====== ====== ======
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(1); ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(0).getChild(1);
{ {
expCMx = 0.055710581052; expCMx = 0.055710581052;
// think of the casts as an assert that ( child instanceof NoseCone) == true // think of the casts as an assert that ( child instanceof NoseCone) == true
@ -406,7 +406,7 @@ public class MassCalculatorTest extends BaseTestCase {
// ====== Booster Set Stage ====== // ====== Booster Set Stage ======
// ====== ====== ====== // ====== ====== ======
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
{ {
cc= boosters.getChild(0); cc= boosters.getChild(0);
expInertia = 1.82665797857e-5; expInertia = 1.82665797857e-5;
@ -535,7 +535,7 @@ public class MassCalculatorTest extends BaseTestCase {
FlightConfiguration config = rocket.getEmptyConfiguration(); FlightConfiguration config = rocket.getEmptyConfiguration();
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
config.setOnlyStage( boosters.getStageNumber() ); config.setOnlyStage( boosters.getStageNumber() );
final RigidBody actualData = MassCalculator.calculateStructure( config ); final RigidBody actualData = MassCalculator.calculateStructure( config );
@ -606,7 +606,7 @@ public class MassCalculatorTest extends BaseTestCase {
RigidBody actualPropellant = MassCalculator.calculateMotor( config ); RigidBody actualPropellant = MassCalculator.calculateMotor( config );
final Coordinate actCM= actualPropellant.getCM(); final Coordinate actCM= actualPropellant.getCM();
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
final MotorMount mnt = (MotorMount)boosters.getChild(1).getChild(0); final MotorMount mnt = (MotorMount)boosters.getChild(1).getChild(0);
final Motor boosterMotor = mnt.getMotorConfig( config.getFlightConfigurationID()).getMotor(); final Motor boosterMotor = mnt.getMotorConfig( config.getFlightConfigurationID()).getMotor();
@ -690,7 +690,7 @@ public class MassCalculatorTest extends BaseTestCase {
rocket.setSelectedConfiguration( config.getId() ); rocket.setSelectedConfiguration( config.getId() );
config.setOnlyStage( TestRockets.FALCON_9H_BOOSTER_STAGE_NUMBER ); config.setOnlyStage( TestRockets.FALCON_9H_BOOSTER_STAGE_NUMBER );
final ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); final ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
final double overrideMass = 0.5; final double overrideMass = 0.5;
boosters.setOverrideSubcomponents(true); boosters.setOverrideSubcomponents(true);
boosters.setMassOverridden(true); boosters.setMassOverridden(true);
@ -730,7 +730,7 @@ public class MassCalculatorTest extends BaseTestCase {
FlightConfiguration config = rocket.getEmptyConfiguration(); FlightConfiguration config = rocket.getEmptyConfiguration();
rocket.setSelectedConfiguration( config.getId() ); rocket.setSelectedConfiguration( config.getId() );
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
config.setOnlyStage( boosters.getStageNumber() ); config.setOnlyStage( boosters.getStageNumber() );
NoseCone nose = (NoseCone)boosters.getChild(0); NoseCone nose = (NoseCone)boosters.getChild(0);
@ -777,7 +777,7 @@ public class MassCalculatorTest extends BaseTestCase {
rocket.setSelectedConfiguration( config.getId() ); rocket.setSelectedConfiguration( config.getId() );
config.setOnlyStage( TestRockets.FALCON_9H_BOOSTER_STAGE_NUMBER ); config.setOnlyStage( TestRockets.FALCON_9H_BOOSTER_STAGE_NUMBER );
ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(1); ParallelStage boosters = (ParallelStage) rocket.getChild(1).getChild(0).getChild(1);
NoseCone nose = (NoseCone)boosters.getChild(0); NoseCone nose = (NoseCone)boosters.getChild(0);
nose.setCGOverridden(true); nose.setCGOverridden(true);