From d43381d70c58ce317644e0f368aeca4ac378efad Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Fri, 20 Nov 2015 11:43:56 -0500 Subject: [PATCH] [Bugfix] Fixed Initialization Positioning Bug Positioning Behavior of RocketComponent defaulted to returning NaN or zero during unordered initialization. This prevented proper loading of Rocksim files. --- .../importt/PositionDependentHandler.java | 5 +++-- .../rocketcomponent/RocketComponent.java | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/core/src/net/sf/openrocket/file/rocksim/importt/PositionDependentHandler.java b/core/src/net/sf/openrocket/file/rocksim/importt/PositionDependentHandler.java index 2cf4a6130..aea6bff32 100644 --- a/core/src/net/sf/openrocket/file/rocksim/importt/PositionDependentHandler.java +++ b/core/src/net/sf/openrocket/file/rocksim/importt/PositionDependentHandler.java @@ -9,6 +9,7 @@ import net.sf.openrocket.aerodynamics.WarningSet; import net.sf.openrocket.file.DocumentLoadingContext; import net.sf.openrocket.file.rocksim.RocksimCommonConstants; import net.sf.openrocket.file.rocksim.RocksimLocationMode; +import net.sf.openrocket.rocketcomponent.RadiusRingComponent; import net.sf.openrocket.rocketcomponent.RocketComponent; import org.xml.sax.SAXException; @@ -83,10 +84,10 @@ public abstract class PositionDependentHandler extend */ public static void setLocation(RocketComponent component, RocketComponent.Position position, double location) { if (position.equals(RocketComponent.Position.BOTTOM)) { - component.setPositionValue(-1d * location); + component.setAxialOffset(-1d * location); } else { - component.setPositionValue(location); + component.setAxialOffset(location); } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index 0bda63489..657e1e085 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -914,12 +914,14 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab * @return double position of the component relative to the parent, with respect to position */ public double asPositionValue(Position thePosition) { + double relativeLength; if (null == this.parent) { - return Double.NaN; + relativeLength = 0; + }else{ + relativeLength = this.parent.length; } double thisX = this.position.x; - double relativeLength = this.parent.length; double result = Double.NaN; switch (thePosition) { @@ -1032,8 +1034,19 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab } if (null == this.parent) { // if this is the root of a hierarchy, constrain the position to zero. + if( this instanceof Rocket ){ + this.offset =0; + this.position = Coordinate.ZERO; + return; + } + // debug vv + else if( this instanceof RingComponent ){ + log.error("Attempting to set offset of a parent-less class :"+this.getName()); + } + this.offset = newOffset; - this.position= Coordinate.ZERO; + // best-effort approximation. this should be corrected later on in the initialization process. + this.position= new Coordinate( newOffset, 0, 0); return; }