Merge pull request #26 from openrocket/unstable

Unstable update Feb 19
This commit is contained in:
ChrisMickelson 2018-02-19 23:12:01 -06:00 committed by GitHub
commit 1c287b90be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 48 additions and 31 deletions

View File

@ -145,7 +145,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
public void setStageNumber(final int newStageNumber) {
this.stageNumber = newStageNumber;
}
@Override
protected StringBuilder toDebugDetail() {
StringBuilder buf = super.toDebugDetail();
@ -197,7 +197,7 @@ public class AxialStage extends ComponentAssembly implements FlightConfigurableC
if( 1 == getInstanceCount()){
buffer.append(String.format("%-40s| %5.3f; %24s; %24s;", indent+this.getName()+" (# "+this.getStageNumber()+")",
this.getLength(), this.getPosition(), this.getComponentLocations()[0]));
buffer.append(String.format("len: %6.4f )(offset: %4.1f via: %s )\n", this.getLength(), this.getAxialOffset(), this.axialMethod.name ));
buffer.append(String.format("len: %6.4f )(offset: %4.1f via: %s )\n", this.getLength(), this.getAxialOffset(), this.axialMethod.name() ));
}else{
buffer.append(String.format("%-40s|(len: %6.4f )(offset: %4.1f via: %s)\n", (indent+this.getName()+"(# "+this.getStageNumber()+")"), this.getLength(), this.getAxialOffset(), this.axialMethod.name() ));
for (int instanceNumber = 0; instanceNumber < this.getInstanceCount(); instanceNumber++) {

View File

@ -8,6 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.rocketcomponent.position.AxialPositionable;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.Coordinate;
@ -21,7 +22,7 @@ import net.sf.openrocket.util.Coordinate;
*
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
*/
public abstract class ComponentAssembly extends RocketComponent {
public abstract class ComponentAssembly extends RocketComponent implements AxialPositionable {
private static final Logger log = LoggerFactory.getLogger(ComponentAssembly.class);
/**
@ -131,17 +132,18 @@ public abstract class ComponentAssembly extends RocketComponent {
super.setAxialOffset(this.axialMethod, _pos);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
}
public void setRelativePositionMethod(final AxialMethod _newPosition) {
@Override
public void setAxialMethod( final AxialMethod newMethod ) {
if (null == this.parent) {
throw new NullPointerException(" a Stage requires a parent before any positioning! ");
}
if ((this instanceof ParallelStage ) || ( this instanceof PodSet )){
if (AxialMethod.AFTER == _newPosition) {
if (AxialMethod.AFTER == newMethod) {
log.warn("Stages (or Pods) cannot be relative to other stages via AFTER! Ignoring.");
super.setAxialMethod(AxialMethod.TOP);
} else {
super.setAxialMethod(_newPosition);
super.setAxialMethod(newMethod);
}
}else if( this.getClass().equals( AxialStage.class)){
// Centerline stages must be set via AFTER-- regardless of what was requested:

View File

@ -22,7 +22,7 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo
protected double angleSeparation = Math.PI;
protected double angleOffset_rad = 0;
protected RadiusMethod radiusMethod = RadiusMethod.SURFACE;
protected RadiusMethod radiusMethod = RadiusMethod.RELATIVE;
protected double radiusOffset_m = 0;
public ParallelStage() {

View File

@ -25,7 +25,7 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
// angle to the first pod
protected double angleOffset_rad = 0;
protected RadiusMethod radiusMethod = RadiusMethod.SURFACE;
protected RadiusMethod radiusMethod = RadiusMethod.RELATIVE;
protected double radiusOffset_m = 0;
public PodSet() {
@ -155,7 +155,7 @@ public class PodSet extends ComponentAssembly implements RingInstanceable {
if (this.isAfter()){
// remember the implicit (this instanceof Stage)
throw new BugException("found a Stage on centerline, but not positioned as AFTER. Please fix this! " + this.getName() + " is " + this.getAxialMethod().name );
throw new BugException("found a pod positioned via: AFTER, but is not on the centerline?!: " + this.getName() + " is " + this.getAxialMethod().name() );
} else {
returnValue = super.asPositionValue(this.axialMethod);
}

View File

@ -967,7 +967,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
}else if( AxialMethod.BOTTOM == asMethod) {
result = this.position.x + ( this.length - parentLength);
}else {
throw new BugException("Unknown position type: " + asMethod.name);
throw new BugException("Unknown position type: " + asMethod.name() );
}
return result;
@ -2176,7 +2176,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
StackTraceElement[] stackTrace = (new Exception()).getStackTrace();
buf.append(" >> Dumping Detailed Information from: " + stackTrace[1].getMethodName() + "\n");
buf.append(" current Component: " + this.getName() + " ofClass: " + this.getClass().getSimpleName() + "\n");
buf.append(" offset: " + this.axialOffset + " via: " + this.axialMethod.name + " => " + this.getAxialOffset() + "\n");
buf.append(" offset: " + this.axialOffset + " via: " + this.axialMethod.name() + " => " + this.getAxialOffset() + "\n");
buf.append(" thisCenterX: " + this.position.x + "\n");
buf.append(" this length: " + this.length + "\n");
return buf;

View File

@ -46,15 +46,20 @@ public enum AngleMethod implements DistanceMethod {
};
public static final AngleMethod[] choices(){
return new AngleMethod[]{ AngleMethod.RELATIVE, AngleMethod.FIXED };
return new AngleMethod[]{ AngleMethod.RELATIVE };
}
public final String name;
public final String description;
private AngleMethod( final String _name ) {
this.name= _name;
private AngleMethod( final String descr ) {
this.description= descr;
}
@Override
public String toString() {
return description;
}
@Override
public boolean clampToZero() { return true; }

View File

@ -35,13 +35,18 @@ public enum AxialMethod implements DistanceMethod {
public static final AxialMethod[] axialOffsetMethods = { TOP, MIDDLE, BOTTOM };
public final String name;
public final String description;
private AxialMethod( final String _name ) {
this.name=_name;
private AxialMethod( final String newDescription ) {
this.description=newDescription;
}
@Override
public boolean clampToZero() { return true; }
@Override
public String toString() {
return description;
}
}

View File

@ -55,15 +55,20 @@ public enum RadiusMethod implements DistanceMethod {
};
public static final RadiusMethod[] choices(){
return new RadiusMethod[]{ RadiusMethod.FREE, RadiusMethod.RELATIVE, RadiusMethod.SURFACE };
return new RadiusMethod[]{ RadiusMethod.FREE, RadiusMethod.RELATIVE };
}
public final String name;
public final String description;
// =============
private RadiusMethod( final String _name ) {
this.name = _name;
private RadiusMethod( final String descr ) {
this.description = descr;
}
@Override
public String toString() {
return description;
}
@Override

View File

@ -173,7 +173,7 @@ public class ParallelStageTest extends BaseTestCase {
// without making the rocket 'external' and the Stage should be restricted to AFTER positioning.
sustainer.setRelativePositionMethod(AxialMethod.ABSOLUTE);
sustainer.setAxialMethod(AxialMethod.ABSOLUTE);
assertThat("Setting a centerline stage to anything other than AFTER is ignored.", sustainer.isAfter(), equalTo(true));
assertThat("Setting a centerline stage to anything other than AFTER is ignored.", sustainer.getAxialMethod(), equalTo(AxialMethod.AFTER));
@ -613,7 +613,7 @@ public class ParallelStageTest extends BaseTestCase {
boosterA.setAxialOffset(AxialMethod.TOP, targetOffset);
boosterB.setRelativePositionMethod(AxialMethod.TOP);
boosterB.setAxialMethod(AxialMethod.TOP);
boosterB.setAxialOffset(targetOffset);
String treeDump = rocket.toDebugTree();

View File

@ -64,12 +64,12 @@ public class ComponentAssemblyConfig extends RocketComponentConfig {
motherPanel.add(radiusUnitSelector, "growx 1, wrap");
// autoRadOffsModel.addEnableComponent(radiusUnitSelector, false);
// set location angle around the primary stage
JLabel angleMethodLabel = new JLabel(trans.get("RocketComponent.Position.Method.Angle.Label"));
motherPanel.add( angleMethodLabel, "align left");
EnumModel<AngleMethod> angleMethodModel = new EnumModel<AngleMethod>( boosters, "AngleMethod", AngleMethod.choices() );
final JComboBox<AngleMethod> angleMethodCombo = new JComboBox<AngleMethod>( angleMethodModel );
motherPanel.add( angleMethodCombo, "align left, wrap");
// // set location angle around the primary stage
// JLabel angleMethodLabel = new JLabel(trans.get("RocketComponent.Position.Method.Angle.Label"));
// motherPanel.add( angleMethodLabel, "align left");
// EnumModel<AngleMethod> angleMethodModel = new EnumModel<AngleMethod>( boosters, "AngleMethod", AngleMethod.choices() );
// final JComboBox<AngleMethod> angleMethodCombo = new JComboBox<AngleMethod>( angleMethodModel );
// motherPanel.add( angleMethodCombo, "align left, wrap");
JLabel angleLabel = new JLabel(trans.get("StageConfig.parallel.angle"));
motherPanel.add( angleLabel, "align left");