[refactor] Pods and ParallelStages are now attached to BodyTubes *only*
This commit is contained in:
parent
20eff575f4
commit
23d7397fa6
@ -38,7 +38,7 @@ public enum IgnitionEvent {
|
||||
|
||||
AxialStage targetStage = (AxialStage)targetComponent.getStage();
|
||||
AxialStage eventStage = (AxialStage)testEvent.getSource().getStage();
|
||||
AxialStage eventParentStage = eventStage.getPreviousStage();
|
||||
AxialStage eventParentStage = eventStage.getUpperStage();
|
||||
return ( targetStage.equals(eventParentStage));
|
||||
}
|
||||
},
|
||||
@ -50,7 +50,7 @@ public enum IgnitionEvent {
|
||||
|
||||
AxialStage targetStage = (AxialStage)targetComponent.getStage();
|
||||
AxialStage eventStage = (AxialStage)testEvent.getSource().getStage();
|
||||
AxialStage eventParentStage = eventStage.getPreviousStage();
|
||||
AxialStage eventParentStage = eventStage.getUpperStage();
|
||||
return ( targetStage.equals(eventParentStage));
|
||||
}
|
||||
},
|
||||
|
@ -82,12 +82,6 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@ -180,16 +174,16 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
|
||||
* returns null if this is the first stage
|
||||
* @return the previous stage in the rocket
|
||||
*/
|
||||
public AxialStage getPreviousStage() {
|
||||
if( this instanceof ParallelStage ){
|
||||
return (AxialStage) this.parent;
|
||||
}
|
||||
AxialStage thisStage = this.getStage(); // necessary in case of pods or other assemblies
|
||||
if( thisStage.parent instanceof Rocket ){
|
||||
final int thisIndex = parent.getChildPosition( thisStage );
|
||||
public AxialStage getUpperStage() {
|
||||
if( null == this.parent ) {
|
||||
return null;
|
||||
}else if(Rocket.class.isAssignableFrom(this.parent.getClass()) ){
|
||||
final int thisIndex = getStageNumber();
|
||||
if( 0 < thisIndex ){
|
||||
return (AxialStage)thisStage.parent.getChild(thisIndex-1);
|
||||
return (AxialStage)parent.getChild(thisIndex-1);
|
||||
}
|
||||
}else {
|
||||
return this.parent.getStage();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -351,6 +351,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
|
||||
*/
|
||||
@Override
|
||||
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))
|
||||
return true;
|
||||
if (ExternalComponent.class.isAssignableFrom(type) &&
|
||||
|
@ -38,7 +38,7 @@ public abstract class ComponentAssembly extends RocketComponent {
|
||||
|
||||
@Override
|
||||
public double getAxialOffset() {
|
||||
return super.asPositionValue(this.relativePosition);
|
||||
return asPositionValue(this.relativePosition);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,6 +183,7 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
|
||||
return this.autoRadialPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoRadialOffset( final boolean enabled ){
|
||||
this.autoRadialPosition = enabled;
|
||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||
@ -206,12 +207,12 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
|
||||
protected void update() {
|
||||
super.update();
|
||||
|
||||
if( this.autoRadialPosition ){
|
||||
ComponentAssembly parentAssembly = (ComponentAssembly)this.parent;
|
||||
if( null == parentAssembly ){
|
||||
if( this.autoRadialPosition){
|
||||
if( null == this.parent ){
|
||||
this.radialPosition_m = this.getOuterRadius();
|
||||
}else{
|
||||
this.radialPosition_m = this.getOuterRadius() + parentAssembly.getOuterRadius();
|
||||
}else if( BodyTube.class.isAssignableFrom(this.parent.getClass())) {
|
||||
BodyTube parentBody = (BodyTube)this.parent;
|
||||
this.radialPosition_m = this.getOuterRadius() + parentBody.getOuterRadius();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -227,11 +227,11 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
|
||||
super.update();
|
||||
|
||||
if( this.autoRadialPosition){
|
||||
ComponentAssembly parentAssembly = (ComponentAssembly)this.parent;
|
||||
if( null == parentAssembly ){
|
||||
if( null == this.parent ){
|
||||
this.radialPosition_m = this.getOuterRadius();
|
||||
}else{
|
||||
this.radialPosition_m = this.getOuterRadius() + parentAssembly.getOuterRadius();
|
||||
}else if( BodyTube.class.isAssignableFrom(this.parent.getClass())) {
|
||||
BodyTube parentBody = (BodyTube)this.parent;
|
||||
this.radialPosition_m = this.getOuterRadius() + parentBody.getOuterRadius();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import java.util.NoSuchElementException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import net.sf.openrocket.appearance.Appearance;
|
||||
import net.sf.openrocket.appearance.Decal;
|
||||
import net.sf.openrocket.motor.Motor;
|
||||
@ -110,7 +111,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
||||
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;
|
||||
|
||||
@ -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>
|
||||
*/
|
||||
public double asPositionValue(Position thePosition) {
|
||||
double relativeLength;
|
||||
double parentLength;
|
||||
if (null == this.parent) {
|
||||
relativeLength = 0;
|
||||
parentLength = 0;
|
||||
}else{
|
||||
relativeLength = this.parent.length;
|
||||
parentLength = this.parent.length;
|
||||
}
|
||||
|
||||
double thisX = this.position.x;
|
||||
double result = Double.NaN;
|
||||
|
||||
switch (thePosition) {
|
||||
case AFTER:
|
||||
result = thisX - relativeLength;
|
||||
result = this.position.x - parentLength;
|
||||
break;
|
||||
case ABSOLUTE:
|
||||
Coordinate[] insts = this.getLocations();
|
||||
result = insts[0].x;
|
||||
result = this.getComponentLocations()[0].x;
|
||||
break;
|
||||
case TOP:
|
||||
result = thisX;
|
||||
result = this.position.x;
|
||||
break;
|
||||
case MIDDLE:
|
||||
result = thisX + (-relativeLength + this.getLength()) / 2;
|
||||
result = this.position.x + ( this.length - parentLength) / 2;
|
||||
break;
|
||||
case BOTTOM:
|
||||
result = thisX + (-relativeLength + this.getLength());
|
||||
result = this.position.x + ( this.length - parentLength);
|
||||
break;
|
||||
default:
|
||||
throw new BugException("Unknown position type: " + thePosition);
|
||||
@ -1096,6 +1094,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
||||
}else{
|
||||
this.relativePosition = positionMethod;
|
||||
}
|
||||
|
||||
if (null == this.parent) {
|
||||
// if this is the root of a hierarchy, constrain the position to zero.
|
||||
if( this instanceof Rocket ){
|
||||
@ -1113,9 +1112,10 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
||||
final double EPSILON = 0.000001;
|
||||
double newAxialPosition = Double.NaN;
|
||||
final double refLength = this.parent.getLength();
|
||||
|
||||
switch (this.relativePosition) {
|
||||
case ABSOLUTE:
|
||||
newAxialPosition = newOffset - this.parent.position.x;
|
||||
newAxialPosition = newOffset - this.parent.getComponentLocations()[0].x;
|
||||
break;
|
||||
case AFTER:
|
||||
// no-op
|
||||
@ -1129,6 +1129,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
||||
break;
|
||||
case BOTTOM:
|
||||
newAxialPosition = (refLength - this.length) + newOffset;
|
||||
//System.err.println(String.format("____( %.6g - %.6g) + %.6g = %.6g", refLength, this.length, newOffset, newAxialPosition ));
|
||||
break;
|
||||
default:
|
||||
throw new BugException("Unknown position type: " + this.relativePosition);
|
||||
|
@ -935,13 +935,12 @@ public class TestRockets {
|
||||
coreBody.setMotorMount(true);
|
||||
coreStage.addChild( coreBody);
|
||||
{
|
||||
MotorConfiguration motorConfig = new MotorConfiguration(coreBody, selFCID);
|
||||
MotorConfiguration coreMotorConfig = new MotorConfiguration(coreBody, selFCID);
|
||||
Motor mtr = TestRockets.generateMotor_M1350_75mm();
|
||||
motorConfig.setMotor( mtr);
|
||||
coreMotorConfig.setMotor( mtr);
|
||||
coreBody.setMotorMount( true);
|
||||
FlightConfigurationId motorConfigId = selFCID;
|
||||
coreBody.setMotorConfig( motorConfig, motorConfigId);
|
||||
}
|
||||
coreBody.setMotorConfig( coreMotorConfig, motorConfigId);
|
||||
|
||||
TrapezoidFinSet coreFins = new TrapezoidFinSet();
|
||||
coreFins.setName("Core Fins");
|
||||
@ -962,7 +961,7 @@ public class TestRockets {
|
||||
// ====== ====== ====== ======
|
||||
ParallelStage boosterStage = new ParallelStage();
|
||||
boosterStage.setName("Booster Stage");
|
||||
coreStage.addChild( boosterStage);
|
||||
coreBody.addChild( boosterStage);
|
||||
boosterStage.setRelativePositionMethod(Position.BOTTOM);
|
||||
boosterStage.setAxialOffset(0.0);
|
||||
boosterStage.setInstanceCount(2);
|
||||
@ -997,14 +996,15 @@ public class TestRockets {
|
||||
boosterMotorTubes.setClusterScale(1.0);
|
||||
boosterBody.addChild( boosterMotorTubes);
|
||||
|
||||
FlightConfigurationId motorConfigId = selFCID;
|
||||
MotorConfiguration motorConfig = new MotorConfiguration( boosterMotorTubes, selFCID);
|
||||
Motor mtr = TestRockets.generateMotor_G77_29mm();
|
||||
motorConfig.setMotor(mtr);
|
||||
boosterMotorTubes.setMotorConfig( motorConfig, motorConfigId);
|
||||
MotorConfiguration boosterMotorConfig = new MotorConfiguration( boosterMotorTubes, selFCID);
|
||||
Motor boosterMotor = TestRockets.generateMotor_G77_29mm();
|
||||
boosterMotorConfig.setMotor( boosterMotor );
|
||||
boosterMotorTubes.setMotorConfig( boosterMotorConfig, motorConfigId);
|
||||
boosterMotorTubes.setMotorOverhang(0.01234);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
rocket.enableEvents();
|
||||
|
@ -180,7 +180,7 @@ public class BarrowmanCalculatorTest {
|
||||
Rocket rocket = TestRockets.makeFalcon9Heavy();
|
||||
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);
|
||||
BodyTube body = (BodyTube)booster.getChild(1);
|
||||
|
||||
|
@ -205,7 +205,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
|
||||
// ====== Booster Set Stage ======
|
||||
// ====== ====== ======
|
||||
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(1);
|
||||
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(0).getChild(1);
|
||||
{
|
||||
expMass = 0.0222459863653;
|
||||
// think of the casts as an assert that ( child instanceof NoseCone) == true
|
||||
@ -288,7 +288,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
|
||||
// ====== Booster Set Stage ======
|
||||
// ====== ====== ======
|
||||
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(1);
|
||||
ParallelStage boosters = (ParallelStage) rkt.getChild(1).getChild(0).getChild(1);
|
||||
{
|
||||
expCMx = 0.055710581052;
|
||||
// think of the casts as an assert that ( child instanceof NoseCone) == true
|
||||
@ -406,7 +406,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
|
||||
// ====== 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);
|
||||
expInertia = 1.82665797857e-5;
|
||||
@ -535,7 +535,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
|
||||
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() );
|
||||
|
||||
final RigidBody actualData = MassCalculator.calculateStructure( config );
|
||||
@ -606,7 +606,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
RigidBody actualPropellant = MassCalculator.calculateMotor( config );
|
||||
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 Motor boosterMotor = mnt.getMotorConfig( config.getFlightConfigurationID()).getMotor();
|
||||
|
||||
@ -690,7 +690,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
rocket.setSelectedConfiguration( config.getId() );
|
||||
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;
|
||||
boosters.setOverrideSubcomponents(true);
|
||||
boosters.setMassOverridden(true);
|
||||
@ -730,7 +730,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
FlightConfiguration config = rocket.getEmptyConfiguration();
|
||||
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() );
|
||||
|
||||
NoseCone nose = (NoseCone)boosters.getChild(0);
|
||||
@ -777,7 +777,7 @@ public class MassCalculatorTest extends BaseTestCase {
|
||||
rocket.setSelectedConfiguration( config.getId() );
|
||||
|
||||
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);
|
||||
nose.setCGOverridden(true);
|
||||
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user