From 1a036904c0e11479fad6312ccbede319d767a388 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Thu, 26 Nov 2015 10:22:40 -0500 Subject: [PATCH] [bugfix] .ork files load motors correctly (again). --- .../openrocket/importt/MotorMountHandler.java | 30 ++++--------------- .../sf/openrocket/motor/MotorInstance.java | 7 ++++- .../rocketcomponent/RocketComponent.java | 4 --- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java index dc5cb869c..211c39216 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java @@ -12,6 +12,7 @@ import net.sf.openrocket.file.simplesax.ElementHandler; import net.sf.openrocket.file.simplesax.PlainTextHandler; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.MotorInstance; +import net.sf.openrocket.motor.MotorInstanceId; import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.MotorMount; @@ -64,7 +65,7 @@ class MotorMountHandler extends AbstractElementHandler { // System.err.println("closing MotorMount element: "+ element); if (element.equals("motor")) { - // yes, this is confirmed to be the FLIGHT config id, instead of the motor inastance id. + // yes, this is confirmed to be the FLIGHT config id, instead of the motor instance id. FlightConfigurationID fcid = new FlightConfigurationID(attributes.get("configid")); if (!fcid.isValid()) { warnings.add(Warning.fromString("Illegal motor specification, ignoring.")); @@ -72,35 +73,16 @@ class MotorMountHandler extends AbstractElementHandler { } Motor motor = motorHandler.getMotor(warnings); + MotorInstance motorInstance = motor.getNewInstance(); + RocketComponent rc = (RocketComponent)mount; + motorInstance.setID( new MotorInstanceId(rc.getID(), 1)); motorInstance.setEjectionDelay(motorHandler.getDelay(warnings)); mount.setMotorInstance(fcid, motorInstance); - + Rocket rkt = ((RocketComponent)mount).getRocket(); rkt.createFlightConfiguration(fcid); -// // vvvvvvv DEBUG vvvvvvv -// if( mount instanceof BodyTube ){ -// System.err.println(" processing <"+element+"> element with mount: "+((RocketComponent)mount).getName()+" with content: "+content); -// MotorInstance justSet = mount.getMotorInstance(fcid); -// String shortKey = fcid.key.substring(0,8); -// String motorKey = justSet.getMotorID().toString().substring(0,8); -// String contains; -// if( justSet.isEmpty()){ -// contains = "empty"; -// }else{ -// contains = justSet.getMotor().getDesignation(); -// } -// System.err.println(" set( key:"+ shortKey + " to Motor: "+motorKey+ " containing: "+contains); -// -// // exhaustive part... -// -// ((BodyTube)mount).printMotorDebug( fcid ); -// -// rkt.getConfigurationSet().printDebug(); -// } -// // ^^^^^^^ DEBUG ^^^^^^^^ - return; } diff --git a/core/src/net/sf/openrocket/motor/MotorInstance.java b/core/src/net/sf/openrocket/motor/MotorInstance.java index e6a8a9c36..c83d05c16 100644 --- a/core/src/net/sf/openrocket/motor/MotorInstance.java +++ b/core/src/net/sf/openrocket/motor/MotorInstance.java @@ -34,7 +34,12 @@ public class MotorInstance implements FlightConfigurableParameter private final List listeners = new ArrayList(); /** Immutable configuration with no motor and zero delay. */ - public static final MotorInstance EMPTY_INSTANCE = new MotorInstance(); + public static final MotorInstance EMPTY_INSTANCE = new MotorInstance(){ + @Override + public boolean equals( Object other ){ + return (this==other); + } + }; protected MotorInstance() { this.id = MotorInstanceId.EMPTY_ID; diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index e16259f16..832d83af6 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -1042,10 +1042,6 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab 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; // best-effort approximation. this should be corrected later on in the initialization process.