[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.
This commit is contained in:
parent
ec5a3119c5
commit
d43381d70c
@ -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<C extends RocketComponent> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 <code>position</code>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user