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 ddbe59fea..67383b299 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java @@ -90,7 +90,7 @@ class MotorMountHandler extends AbstractElementHandler { return; } - MotorConfiguration inst = mount.getMotorInstance(fcid); + MotorConfiguration inst = mount.getMotorConfig(fcid); inst.setIgnitionDelay(ignitionConfigHandler.ignitionDelay); inst.setIgnitionEvent(ignitionConfigHandler.ignitionEvent); return; @@ -109,7 +109,7 @@ class MotorMountHandler extends AbstractElementHandler { return; } - mount.getDefaultMotorInstance().setIgnitionEvent(event); + mount.getDefaultMotorConfig().setIgnitionEvent(event); return; } @@ -123,7 +123,7 @@ class MotorMountHandler extends AbstractElementHandler { return; } - mount.getDefaultMotorInstance().setIgnitionDelay(d); + mount.getDefaultMotorConfig().setIgnitionDelay(d); return; } diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java index 3c79edf13..6be0ed885 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java @@ -179,7 +179,7 @@ public class RocketComponentSaver { List elements = new ArrayList(); - MotorConfiguration defaultInstance = mount.getDefaultMotorInstance(); + MotorConfiguration defaultInstance = mount.getDefaultMotorConfig(); elements.add(""); @@ -192,7 +192,7 @@ public class RocketComponentSaver { for( FlightConfigurationId fcid : rkt.getIds()){ - MotorConfiguration motorInstance = mount.getMotorInstance(fcid); + MotorConfiguration motorInstance = mount.getMotorConfig(fcid); // Nothing is stored if no motor loaded if( motorInstance.isEmpty()){ continue; diff --git a/core/src/net/sf/openrocket/formatting/MotorDescriptionSubstitutor.java b/core/src/net/sf/openrocket/formatting/MotorDescriptionSubstitutor.java index 09ee5559c..f02f82540 100644 --- a/core/src/net/sf/openrocket/formatting/MotorDescriptionSubstitutor.java +++ b/core/src/net/sf/openrocket/formatting/MotorDescriptionSubstitutor.java @@ -69,7 +69,7 @@ public class MotorDescriptionSubstitutor implements RocketSubstitutor { } else if (c instanceof MotorMount) { MotorMount mount = (MotorMount) c; - MotorConfiguration inst = mount.getMotorInstance(fcid); + MotorConfiguration inst = mount.getMotorConfig(fcid); Motor motor = inst.getMotor(); if (mount.isMotorMount() && motor != null) { diff --git a/core/src/net/sf/openrocket/motor/MotorConfiguration.java b/core/src/net/sf/openrocket/motor/MotorConfiguration.java index 9f0ca7c94..8793d372d 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfiguration.java +++ b/core/src/net/sf/openrocket/motor/MotorConfiguration.java @@ -2,6 +2,7 @@ package net.sf.openrocket.motor; import net.sf.openrocket.rocketcomponent.FlightConfigurableParameter; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; +import net.sf.openrocket.rocketcomponent.InnerTube; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.util.Coordinate; @@ -13,12 +14,13 @@ import net.sf.openrocket.util.Inertia; */ public class MotorConfiguration implements FlightConfigurableParameter { - public static final String EMPTY_DESCRIPTION = "Empty Configuration"; + public static final String EMPTY_DESCRIPTION = "Empty Configuration".intern(); protected final MotorMount mount; protected final FlightConfigurationId fcid; - protected final MotorInstanceId id; + protected final MotorConfigurationId id; + protected String name = ""; protected Motor motor = null; protected double ejectionDelay = 0.0; @@ -29,9 +31,16 @@ public class MotorConfiguration implements FlightConfigurableParameter */ -public final class MotorInstanceId { +public final class MotorConfigurationId { - private final String name ; private final UUID key; - private final static String ERROR_ID_TEXT = "MotorInstance Error Id"; - private final static UUID ERROR_KEY = new UUID( 6227, 5676); - public final static MotorInstanceId ERROR_ID = new MotorInstanceId(); + private final static String ERROR_ID_TEXT = "MotorInstance Error Id".intern(); + private final static UUID ERROR_KEY = new UUID( 62274413, 56768908); + public final static MotorConfigurationId ERROR_ID = new MotorConfigurationId(); - private MotorInstanceId( ) { - this.name = MotorInstanceId.ERROR_ID_TEXT; - this.key = MotorInstanceId.ERROR_KEY; + private MotorConfigurationId( ) { + this.key = MotorConfigurationId.ERROR_KEY; } /** @@ -32,18 +30,17 @@ public final class MotorInstanceId { * @param componentName the component ID, must not be null * @param number a positive motor number */ - public MotorInstanceId(final MotorMount _mount, final FlightConfigurationId _fcid ) { + public MotorConfigurationId(final MotorMount _mount, final FlightConfigurationId _fcid) { if (null == _mount ) { - throw new IllegalArgumentException("Provided MotorConfiguration was null"); + throw new NullPointerException("Provided MotorMount was null"); } if (null == _fcid ) { - throw new IllegalArgumentException("Provided MotorConfiguration was null"); + throw new NullPointerException("Provided FlightConfigurationId was null"); } // Use intern so comparison can be done using == instead of equals() - this.name = _mount.getID()+"-"+_fcid.toShortKey(); - final long upper = _mount.getID().hashCode() << 32; - final long lower = _fcid.key.getMostSignificantBits(); + final long upper = ((long)_mount.getID().hashCode()) << 32; + final long lower = _fcid.key.getLeastSignificantBits(); this.key = new UUID( upper, lower); } @@ -53,10 +50,10 @@ public final class MotorInstanceId { if (this == other) return true; - if (!(other instanceof MotorInstanceId)) + if (!(other instanceof MotorConfigurationId)) return false; - MotorInstanceId otherId = (MotorInstanceId) other; + MotorConfigurationId otherId = (MotorConfigurationId) other; return ( this.key.equals( otherId.key)); } @@ -67,10 +64,10 @@ public final class MotorInstanceId { @Override public String toString(){ - if( this.key == MotorInstanceId.ERROR_KEY){ - return MotorInstanceId.ERROR_ID_TEXT; + if( this.key == MotorConfigurationId.ERROR_KEY){ + return MotorConfigurationId.ERROR_ID_TEXT; }else{ - return name; + return key.toString(); } } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index e83abb52f..9293b93fb 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -363,12 +363,12 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial //////////////// Motor mount ///////////////// @Override - public MotorConfiguration getDefaultMotorInstance(){ + public MotorConfiguration getDefaultMotorConfig(){ return this.motors.getDefault(); } @Override - public MotorConfiguration getMotorInstance( final FlightConfigurationId fcid){ + public MotorConfiguration getMotorConfig( final FlightConfigurationId fcid){ return this.motors.get(fcid); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index a537c273c..0beb16675 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -3,6 +3,7 @@ package net.sf.openrocket.rocketcomponent; import java.util.ArrayDeque; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Queue; import java.util.Set; @@ -11,7 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import net.sf.openrocket.motor.MotorConfiguration; -import net.sf.openrocket.motor.MotorInstanceId; +import net.sf.openrocket.motor.MotorConfigurationId; import net.sf.openrocket.util.ArrayList; import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; @@ -28,8 +29,8 @@ import net.sf.openrocket.util.Monitorable; public class FlightConfiguration implements FlightConfigurableParameter, Monitorable { private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class); - public final static String DEFAULT_CONFIGURATION_NAME = "Default Configuration"; - public final static String NO_MOTORS_TEXT = "[No Motors Defined]"; + public final static String DEFAULT_CONFIGURATION_NAME = "Default Configuration".intern(); + public final static String NO_MOTORS_TEXT = "[No Motors Defined]".intern(); protected String configurationName=null; @@ -63,7 +64,7 @@ public class FlightConfiguration implements FlightConfigurableParameter stages = new HashMap(); - protected final HashMap motors = new HashMap(); + final protected HashMap motors = new HashMap(); private int boundsModID = -1; private ArrayList cachedBounds = new ArrayList(); @@ -306,7 +307,7 @@ public class FlightConfiguration implements FlightConfigurableParameter getMotorIDs() { + public Set getMotorIDs() { return motors.keySet(); } - public MotorConfiguration getMotorInstance(MotorInstanceId id) { + public MotorConfiguration getMotorInstance(MotorConfigurationId id) { return motors.get(id); } @@ -365,22 +366,35 @@ public class FlightConfiguration implements FlightConfigurableParameter getAllMotors() { + return this.motors.values(); + } + public Collection getActiveMotors() { - return motors.values(); + Collection activeMotors = new ArrayList(); + for( MotorConfiguration config : this.motors.values() ){ + if( isComponentActive( config.getMount() )){ + activeMotors.add( config ); + } + } + + return activeMotors; } protected void updateMotors() { this.motors.clear(); - for ( RocketComponent compMount : getActiveComponents() ){ - if (( compMount instanceof MotorMount )&&( ((MotorMount)compMount).isMotorMount())){ - MotorMount mount = (MotorMount)compMount; - MotorConfiguration sourceConfig = mount.getMotorInstance( fcid); - if( sourceConfig.isEmpty()){ + Iterator iter = rocket.iterator(false); + while( iter.hasNext() ){ + RocketComponent comp = iter.next(); + if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){ + MotorMount mount = (MotorMount)comp; + MotorConfiguration motorConfig = mount.getMotorConfig( fcid); + if( motorConfig.isEmpty()){ continue; } - this.motors.put( sourceConfig.getID(), sourceConfig); + this.motors.put( motorConfig.getID(), motorConfig); } } } @@ -394,12 +408,16 @@ public class FlightConfiguration implements FlightConfigurableParameter getStageList() { return this.stageMap.values(); } + + public AxialStage getStage( final int stageNumber ) { + return this.stageMap.get( stageNumber); + } /* * Returns the stage at the top of the central stack @@ -662,7 +666,7 @@ public class Rocket extends RocketComponent { MotorMount mount = (MotorMount) c; if (!mount.isMotorMount()) continue; - if (mount.getMotorInstance(fcid).getMotor() != null) { + if (mount.getMotorConfig(fcid).getMotor() != null) { return true; } } diff --git a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java index a9009411b..41c7b155d 100644 --- a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java +++ b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java @@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory; import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.motor.MotorConfiguration; -import net.sf.openrocket.motor.MotorInstanceId; +import net.sf.openrocket.motor.MotorConfigurationId; import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.DeploymentConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration; @@ -86,7 +86,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { } currentStatus = toSimulate.pop(); log.info(">>Starting simulation of branch: "+currentStatus.getFlightData().getBranchName()); - + FlightDataBranch dataBranch = simulateLoop(); flightData.addBranch(dataBranch); flightData.getWarningSet().addAll(currentStatus.getWarnings()); @@ -190,16 +190,15 @@ public class BasicEventSimulationEngine implements SimulationEngine { currentStatus.getConfiguration().getRocket())); } - - // Check for burnt out motors - for( MotorClusterState state : currentStatus.getMotors()){ - //state.update( currentStatus.getSimulationTime() ); - if ( state.isFinishedThrusting()){ - MotorInstanceId motorId = state.getID(); - addEvent(new FlightEvent(FlightEvent.Type.BURNOUT, currentStatus.getSimulationTime(), - (RocketComponent) state.getMount(), motorId)); - } - } +// //@Obsolete +// //@Redundant +// // Check for burnt out motors +// for( MotorClusterState state : currentStatus.getActiveMotors()){ +// if ( state.isSpent()){ +// addEvent(new FlightEvent(FlightEvent.Type.BURNOUT, currentStatus.getSimulationTime(), +// (RocketComponent) state.getMount(), state)); +// } +// } // Check for Tumbling // Conditions for transision are: @@ -274,16 +273,8 @@ public class BasicEventSimulationEngine implements SimulationEngine { } } -// // DEBUG: -// if(( event.getType() == FlightEvent.Type.BURNOUT)|| ( event.getType() == FlightEvent.Type.EJECTION_CHARGE)){ -// System.err.println("@simulationTime: "+currentStatus.getSimulationTime()); -// System.err.println(" Processing "+event.getType().name()+" @"+event.getTime()+" from: "+event.getSource().getName()); -// MotorClusterState eventState = (MotorClusterState) event.getData(); -// System.err.println(" and motor: "+eventState.getMotor().getDesignation()+" in:"+eventState.getMount().getName() -// +" @: "+eventState.getEjectionDelay()); -// } // Check for motor ignition events, add ignition events to queue - for (MotorClusterState state : currentStatus.getAllMotors() ){ + for (MotorClusterState state : currentStatus.getActiveMotors() ){ if( state.testForIgnition(event )){ final double simulationTime = currentStatus.getSimulationTime() ; MotorClusterState sourceState = (MotorClusterState) event.getData(); @@ -295,10 +286,8 @@ public class BasicEventSimulationEngine implements SimulationEngine { final RocketComponent mount = (RocketComponent)state.getMount(); // TODO: this event seems to get enqueue'd multiple times ... - System.err.println("@simulationTime: "+simulationTime); - System.err.println("Queueing motorIgnitionEvent: "+state.getMotor().getDesignation()+" in:"+state.getMount().getName() - +" @: "+ignitionTime); - System.err.println(" Because of "+event.getType().name()+" @"+event.getTime()+" from: "+event.getSource().getName()); + log.info("Queueing Ignition Event for: "+state.toDescription()+" @: "+ignitionTime); + //log.info(" Because of "+event.getType().name()+" @"+event.getTime()+" from: "+event.getSource().getName()); addEvent(new FlightEvent(FlightEvent.Type.IGNITION, ignitionTime, mount, state )); } @@ -342,9 +331,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { case IGNITION: { MotorClusterState motorState = (MotorClusterState) event.getData(); - System.err.println(" >> Igniting motor: "+motorState.getMotor().getDesignation() - +" @"+currentStatus.getSimulationTime() - +" ("+motorState.getMount().getName()); + log.info(" Igniting motor: "+motorState.toDescription()+" @"+currentStatus.getSimulationTime()); motorState.ignite( event.getTime()); // Ignite the motor @@ -353,19 +340,17 @@ public class BasicEventSimulationEngine implements SimulationEngine { // ... ignite ...uhh, again? // TBH, I'm not sure what this call is for. It seems to be mostly a bunch of event distribution. - MotorInstanceId motorId = motorState.getID(); + MotorConfigurationId motorId = motorState.getID(); MotorMount mount = (MotorMount) event.getSource(); if (!SimulationListenerHelper.fireMotorIgnition(currentStatus, motorId, mount, motorState)) { continue; } - // and queue up the burnout for this motor, as well. double duration = motorState.getMotor().getBurnTimeEstimate(); double burnout = currentStatus.getSimulationTime() + duration; addEvent(new FlightEvent(FlightEvent.Type.BURNOUT, burnout, event.getSource(), motorState )); - break; } @@ -390,13 +375,15 @@ public class BasicEventSimulationEngine implements SimulationEngine { } // Add ejection charge event - MotorClusterState state = (MotorClusterState) event.getData(); - AxialStage stage = state.getMount().getStage(); + MotorClusterState motorState = (MotorClusterState) event.getData(); + motorState.burnOut( event.getTime() ); + + AxialStage stage = motorState.getMount().getStage(); log.debug( " adding EJECTION_CHARGE event for stage "+stage.getStageNumber()+": "+stage.getName()); - log.debug( " .... for motor "+state.getMotor().getDesignation()); + log.debug( " .... for motor "+motorState.getMotor().getDesignation()); - double delay = state.getEjectionDelay(); - if ( state.hasEjectionCharge() ){ + double delay = motorState.getEjectionDelay(); + if ( motorState.hasEjectionCharge() ){ addEvent(new FlightEvent(FlightEvent.Type.EJECTION_CHARGE, currentStatus.getSimulationTime() + delay, stage, event.getData())); } @@ -405,6 +392,8 @@ public class BasicEventSimulationEngine implements SimulationEngine { } case EJECTION_CHARGE: { + MotorClusterState motorState = (MotorClusterState) event.getData(); + motorState.expend( event.getTime() ); currentStatus.getFlightData().addEvent(event); break; } @@ -414,17 +403,20 @@ public class BasicEventSimulationEngine implements SimulationEngine { currentStatus.getFlightData().addEvent(event); RocketComponent boosterStage = event.getSource(); - int stageNumber = boosterStage.getStageNumber(); + final int stageNumber = boosterStage.getStageNumber(); - // Prepare the booster status for simulation. + // Mark the status as having dropped the booster + currentStatus.getConfiguration().clearStage( stageNumber); + + // Prepare the simulation branch SimulationStatus boosterStatus = new SimulationStatus(currentStatus); boosterStatus.setFlightData(new FlightDataBranch(boosterStage.getName(), FlightDataType.TYPE_TIME)); // Mark the booster status as only having the booster. boosterStatus.getConfiguration().setOnlyStage(stageNumber); toSimulate.add(boosterStatus); - - // Mark the status as having dropped the booster - currentStatus.getConfiguration().clearStage( stageNumber); + log.info(String.format("==>> @ %g; from Branch: %s ---- Branching: %s ---- \n", + currentStatus.getSimulationTime(), + currentStatus.getFlightData().getBranchName(), boosterStatus.getFlightData().getBranchName())); break; } @@ -591,14 +583,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { SimulationConditions conds = currentStatus.getSimulationConditions().clone(); conds.getSimulationListenerList().add(OptimumCoastListener.INSTANCE); BasicEventSimulationEngine e = new BasicEventSimulationEngine(); -// log.error(" cloned simConditions: "+conds.toString() -// +" ... "+conds.getRocket().getName() -// +" ... "+conds.getFlightConfigurationID().toShortKey()); -// FlightConfigurationID dbid = conds.getFlightConfigurationID(); -// FlightConfiguration cloneConfig = conds.getRocket().getFlightConfiguration( dbid ); -// System.err.println(" configId: "+dbid.toShortKey()); -// System.err.println(" motors detail: "+cloneConfig.toMotorDetail()); - + FlightData d = e.simulate(conds); return d; } catch (Exception e) { diff --git a/core/src/net/sf/openrocket/simulation/MotorClusterState.java b/core/src/net/sf/openrocket/simulation/MotorClusterState.java index b96937f89..2a918999f 100644 --- a/core/src/net/sf/openrocket/simulation/MotorClusterState.java +++ b/core/src/net/sf/openrocket/simulation/MotorClusterState.java @@ -1,21 +1,15 @@ package net.sf.openrocket.simulation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import net.sf.openrocket.models.atmosphere.AtmosphericConditions; import net.sf.openrocket.motor.IgnitionEvent; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.MotorConfiguration; -import net.sf.openrocket.motor.MotorInstanceId; -import net.sf.openrocket.rocketcomponent.InnerTube; +import net.sf.openrocket.motor.MotorConfigurationId; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RocketComponent; public class MotorClusterState { - private static final Logger log = LoggerFactory.getLogger(MotorClusterState.class); - // for reference: set at initialization ONLY. final protected Motor motor; final protected MotorConfiguration config; @@ -26,35 +20,18 @@ public class MotorClusterState { protected double ignitionTime = Double.NaN; protected double cutoffTime = Double.NaN; protected double ejectionTime = Double.NaN; - protected ThrustState currentState = ThrustState.PREFLIGHT; + protected ThrustState currentState = ThrustState.ARMED; public MotorClusterState(final MotorConfiguration _config) { - log.debug(" Creating motor instance of " + _config.getDescription()); this.config = _config; - this.motor = _config.getMotor(); - MotorMount mount = this.config.getMount(); - if( mount instanceof InnerTube ){ - InnerTube inner = (InnerTube) mount; - this.motorCount = inner.getClusterConfiguration().getClusterCount(); - }else{ - this.motorCount =0; - } - thrustDuration = this.motor.getBurnTimeEstimate(); + this.motor = this.config.getMotor(); + this.motorCount = this.config.getMotorCount(); + this.thrustDuration = this.motor.getBurnTimeEstimate(); - this.resetToPreflight(); + this.reset(); } - - public void arm( final double _armTime ){ - if( ThrustState.PREFLIGHT == currentState ){ - log.info( "igniting motor: "+this.toString()+" at t="+_armTime); - //this.ignitionTime = _ignitionTime; - this.currentState = this.currentState.getNext(); - }else{ - throw new IllegalStateException("Attempted to arm a motor with status="+this.currentState.getName()); - } - } - + public double getIgnitionTime() { return ignitionTime; } @@ -65,31 +42,31 @@ public class MotorClusterState { public void ignite( final double _ignitionTime ){ if( ThrustState.ARMED == currentState ){ - log.info( "igniting motor: "+this.toString()+" at t="+_ignitionTime); this.ignitionTime = _ignitionTime; this.currentState = this.currentState.getNext(); - }else{ - throw new IllegalStateException("Attempted to ignite a motor state with status="+this.currentState.getName()); +// }else{ +// System.err.println("!! Attempted to ignite motor "+toDescription() +// +" with current status="+this.currentState.getName()+" ... Ignoring."); } } public void burnOut( final double _burnOutTime ){ if( ThrustState.THRUSTING == currentState ){ - log.info( "igniting motor: "+this.toString()+" at t="+_burnOutTime); this.ignitionTime = _burnOutTime; this.currentState = this.currentState.getNext(); - }else{ - throw new IllegalStateException("Attempted to stop thrust (burn-out) a motor state with status="+this.currentState.getName()); +// }else{ +// System.err.println("!! Attempted to turn off motor state "+toDescription()+" with current status=" +// +this.currentState.getName()+" ... Ignoring."); } } - public void fireEjectionCharge( final double _ejectionTime ){ + public void expend( final double _ejectionTime ){ if( ThrustState.DELAYING == currentState ){ - log.info( "igniting motor: "+this.toString()+" at t="+_ejectionTime); this.ejectionTime = _ejectionTime; this.currentState = this.currentState.getNext(); - }else{ - throw new IllegalStateException("Attempted to fire an ejection charge in motor state: "+this.currentState.getName()); +// }else{ +// System.err.println("!! Attempted to mark as spent motor state "+toDescription()+" with current status=" +// +this.currentState.getName()+" ... Ignoring."); } } @@ -104,7 +81,7 @@ public class MotorClusterState { return config.getEjectionDelay(); } - public MotorInstanceId getID() { + public MotorConfigurationId getID() { return config.getID(); } @@ -145,24 +122,20 @@ public class MotorClusterState { return ! isPlugged(); } - public boolean isFinishedThrusting(){ - return currentState.isAfter( ThrustState.THRUSTING ); + public boolean isSpent(){ + return currentState == ThrustState.SPENT; } /** * alias to 'resetToPreflight()' */ public void reset(){ - resetToPreflight(); - } - - public void resetToPreflight(){ // i.e. in the "future" ignitionTime = Double.POSITIVE_INFINITY; cutoffTime = Double.POSITIVE_INFINITY; ejectionTime = Double.POSITIVE_INFINITY; - currentState = ThrustState.PREFLIGHT; + currentState = ThrustState.ARMED; } public boolean testForIgnition( final FlightEvent _event ){ @@ -170,25 +143,17 @@ public class MotorClusterState { return getIgnitionEvent().isActivationEvent( _event, mount); } + public String toDescription(){ + return String.format("%32s / %4s - %s", + getMount().getName(), this.motor.getDesignation(), this.currentState.getName()); + } + + @Override public String toString(){ return this.motor.getDesignation(); } -// public void update( final double simulationTime ){ -// final double motorTime = this.getMotorTime( simulationTime ); -// log.debug("Attempt to update this motorClusterSimulation with: "); -// log.debug(" this.ignitionTime= "+this.ignitionTime); -// log.debug(" this.thrustDuration= "+this.thrustDuration); -// log.debug(" simTime = "+simulationTime); -// log.debug(" motorTime= "+motorTime ); -// -// log.debug( " time array = "+((ThrustCurveMotor)this.getMotor()).getTimePoints() ); -// -// switch( this.currentState ){ -// -// } - - + } \ No newline at end of file diff --git a/core/src/net/sf/openrocket/simulation/SimulationStatus.java b/core/src/net/sf/openrocket/simulation/SimulationStatus.java index 57ee12bee..bc0f49edc 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationStatus.java +++ b/core/src/net/sf/openrocket/simulation/SimulationStatus.java @@ -10,7 +10,7 @@ import java.util.Set; import net.sf.openrocket.aerodynamics.FlightConditions; import net.sf.openrocket.aerodynamics.WarningSet; import net.sf.openrocket.motor.MotorConfiguration; -import net.sf.openrocket.motor.MotorInstanceId; +import net.sf.openrocket.motor.MotorConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.rocketcomponent.RecoveryDevice; @@ -48,7 +48,8 @@ public class SimulationStatus implements Monitorable { private double effectiveLaunchRodLength; // Set of all motors - List motorStateList = new ArrayList(); + private List motorStateList = new ArrayList(); + /** Nanosecond time when the simulation was started. */ private long simulationStartWallTime = Long.MIN_VALUE; @@ -147,11 +148,7 @@ public class SimulationStatus implements Monitorable { this.launchRodCleared = false; this.apogeeReached = false; - for( MotorConfiguration motorConfig : this.configuration.getActiveMotors() ) { - MotorClusterState simMotor = new MotorClusterState( motorConfig); - simMotor.arm( this.time ); - this.motorStateList.add( simMotor); - } + this.populateMotors(); this.warnings = new WarningSet(); } @@ -189,7 +186,6 @@ public class SimulationStatus implements Monitorable { this.deployedRecoveryDevices.clear(); this.deployedRecoveryDevices.addAll(orig.deployedRecoveryDevices); - // FIXME - is this right? this.motorStateList.clear(); this.motorStateList.addAll(orig.motorStateList); @@ -215,13 +211,7 @@ public class SimulationStatus implements Monitorable { public double getSimulationTime() { return time; } - - public void armAllMotors(){ - for( MotorClusterState motor : this.motorStateList ){ - motor.resetToPreflight(); - } - } - + public void setConfiguration(FlightConfiguration configuration) { if (this.configuration != null) this.modIDadd += this.configuration.getModID(); @@ -233,21 +223,17 @@ public class SimulationStatus implements Monitorable { return motorStateList; } - public Collection getAllMotors() { - return motorStateList; + public Collection getActiveMotors() { + List activeList = new ArrayList(); + for( MotorClusterState state: this.motorStateList ){ + if(( ! state.isSpent()) && (this.configuration.isComponentActive( state.getMount()))){ + activeList.add( state ); + } + } + + return activeList; } -// public Collection getActiveMotors() { -// List activeList = new ArrayList(); -// for( MotorInstance inst : this.motorStateList ){ -// if( inst.isActive() ){ -// activeList.add( inst ); -// } -// } -// -// return activeList; -// } - public FlightConfiguration getConfiguration() { return configuration; } @@ -309,7 +295,7 @@ public class SimulationStatus implements Monitorable { } - public boolean moveBurntOutMotor( final MotorInstanceId motor) { + public boolean moveBurntOutMotor( final MotorConfigurationId motor) { // get motor from normal list // remove motor from 'normal' list // add to spent list @@ -460,12 +446,10 @@ public class SimulationStatus implements Monitorable { this.simulationConditions = simulationConditions; } - public SimulationConditions getSimulationConditions() { return simulationConditions; } - /** * Store extra data available for use by simulation listeners. The data can be retrieved * using {@link #getExtraData(String)}. @@ -506,7 +490,6 @@ public class SimulationStatus implements Monitorable { } } - @Override public int getModID() { return (modID + modIDadd + simulationConditions.getModID() + configuration.getModID() + @@ -514,5 +497,35 @@ public class SimulationStatus implements Monitorable { eventQueue.getModID() + warnings.getModID()); } + public String toEventDebug(){ + final StringBuilder buf = new StringBuilder(""); + for ( FlightEvent event : this.eventQueue){ + buf.append(" [t:"+event.getType()+" @"+ event.getTime()); + if( null != event.getSource()){ + buf.append(" src:"+event.getSource().getName()); + } + if( null != event.getData()){ + buf.append(" data:"+event.getData().getClass().getSimpleName()); + } + buf.append("]\n"); + } + return buf.toString(); + } + public String toMotorsDebug(){ + final StringBuilder buf = new StringBuilder("MotorState list:\n"); + for ( MotorClusterState state : this.motorStateList){ + buf.append(" ["+state.toDescription()+"]\n"); + } + return buf.toString(); + } + + private void populateMotors(){ + motorStateList.clear(); + for( MotorConfiguration motorConfig : this.configuration.getAllMotors() ) { + MotorClusterState simMotor = new MotorClusterState( motorConfig); + this.motorStateList.add( simMotor); + } + } + } diff --git a/core/src/net/sf/openrocket/simulation/ThrustState.java b/core/src/net/sf/openrocket/simulation/ThrustState.java index d269b2bb3..37a71d87d 100644 --- a/core/src/net/sf/openrocket/simulation/ThrustState.java +++ b/core/src/net/sf/openrocket/simulation/ThrustState.java @@ -2,7 +2,7 @@ package net.sf.openrocket.simulation; public enum ThrustState { - SPENT("Finished with sequence.", "Finished Producing thrust.", null) + SPENT("Spent", "Finished Producing thrust.", null) ,DELAYING("Delaying", " After Burnout, but before ejection", SPENT){ @Override public boolean needsSimulation(){ return true;} @@ -14,7 +14,6 @@ public enum ThrustState { public boolean needsSimulation(){ return true;} } ,ARMED("Armed", "Armed, but not yet lit.", THRUSTING) - ,PREFLIGHT("Pre-Launch", "Safed and inactive, prior to launch.", ARMED) ; private final static int SEQUENCE_NUMBER_END = 10; // arbitrary number diff --git a/core/src/net/sf/openrocket/simulation/extension/impl/ScriptingSimulationListener.java b/core/src/net/sf/openrocket/simulation/extension/impl/ScriptingSimulationListener.java index 8e6a4e7e3..ba916ca8a 100644 --- a/core/src/net/sf/openrocket/simulation/extension/impl/ScriptingSimulationListener.java +++ b/core/src/net/sf/openrocket/simulation/extension/impl/ScriptingSimulationListener.java @@ -13,7 +13,7 @@ import net.sf.openrocket.aerodynamics.AerodynamicForces; import net.sf.openrocket.aerodynamics.FlightConditions; import net.sf.openrocket.masscalc.MassData; import net.sf.openrocket.models.atmosphere.AtmosphericConditions; -import net.sf.openrocket.motor.MotorInstanceId; +import net.sf.openrocket.motor.MotorConfigurationId; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RecoveryDevice; import net.sf.openrocket.simulation.AccelerationData; @@ -105,7 +105,7 @@ public class ScriptingSimulationListener implements SimulationListener, Simulati } @Override - public boolean motorIgnition(SimulationStatus status, MotorInstanceId motorId, MotorMount mount, MotorClusterState instance) throws SimulationException { + public boolean motorIgnition(SimulationStatus status, MotorConfigurationId motorId, MotorMount mount, MotorClusterState instance) throws SimulationException { return invoke(Boolean.class, true, "motorIgnition", status, motorId, mount, instance); } diff --git a/core/src/net/sf/openrocket/simulation/listeners/AbstractSimulationListener.java b/core/src/net/sf/openrocket/simulation/listeners/AbstractSimulationListener.java index 09fc3d2b5..6529bc8e8 100644 --- a/core/src/net/sf/openrocket/simulation/listeners/AbstractSimulationListener.java +++ b/core/src/net/sf/openrocket/simulation/listeners/AbstractSimulationListener.java @@ -4,7 +4,7 @@ import net.sf.openrocket.aerodynamics.AerodynamicForces; import net.sf.openrocket.aerodynamics.FlightConditions; import net.sf.openrocket.masscalc.MassData; import net.sf.openrocket.models.atmosphere.AtmosphericConditions; -import net.sf.openrocket.motor.MotorInstanceId; +import net.sf.openrocket.motor.MotorConfigurationId; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RecoveryDevice; import net.sf.openrocket.simulation.AccelerationData; @@ -72,7 +72,7 @@ public class AbstractSimulationListener implements SimulationListener, Simulatio } @Override - public boolean motorIgnition(SimulationStatus status, MotorInstanceId motorId, MotorMount mount, MotorClusterState instance) throws SimulationException { + public boolean motorIgnition(SimulationStatus status, MotorConfigurationId motorId, MotorMount mount, MotorClusterState instance) throws SimulationException { return true; } diff --git a/core/src/net/sf/openrocket/simulation/listeners/SimulationEventListener.java b/core/src/net/sf/openrocket/simulation/listeners/SimulationEventListener.java index e90f6528b..218fed074 100644 --- a/core/src/net/sf/openrocket/simulation/listeners/SimulationEventListener.java +++ b/core/src/net/sf/openrocket/simulation/listeners/SimulationEventListener.java @@ -1,6 +1,6 @@ package net.sf.openrocket.simulation.listeners; -import net.sf.openrocket.motor.MotorInstanceId; +import net.sf.openrocket.motor.MotorConfigurationId; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RecoveryDevice; import net.sf.openrocket.simulation.FlightEvent; @@ -43,7 +43,7 @@ public interface SimulationEventListener { * @param instance the motor instance being ignited * @return true to ignite the motor, false to abort ignition */ - public boolean motorIgnition(SimulationStatus status, MotorInstanceId motorId, MotorMount mount, + public boolean motorIgnition(SimulationStatus status, MotorConfigurationId motorId, MotorMount mount, MotorClusterState instance) throws SimulationException; diff --git a/core/src/net/sf/openrocket/simulation/listeners/SimulationListenerHelper.java b/core/src/net/sf/openrocket/simulation/listeners/SimulationListenerHelper.java index 087329754..bfcc45e5e 100644 --- a/core/src/net/sf/openrocket/simulation/listeners/SimulationListenerHelper.java +++ b/core/src/net/sf/openrocket/simulation/listeners/SimulationListenerHelper.java @@ -9,7 +9,7 @@ import net.sf.openrocket.aerodynamics.FlightConditions; import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.masscalc.MassData; import net.sf.openrocket.models.atmosphere.AtmosphericConditions; -import net.sf.openrocket.motor.MotorInstanceId; +import net.sf.openrocket.motor.MotorConfigurationId; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.RecoveryDevice; import net.sf.openrocket.simulation.AccelerationData; @@ -167,7 +167,7 @@ public class SimulationListenerHelper { * * @return true to handle the event normally, false to skip event. */ - public static boolean fireMotorIgnition(SimulationStatus status, MotorInstanceId motorId, MotorMount mount, + public static boolean fireMotorIgnition(SimulationStatus status, MotorConfigurationId motorId, MotorMount mount, MotorClusterState instance) throws SimulationException { boolean result; int modID = status.getModID(); // Contains also motor instance diff --git a/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java b/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java index 458362f0a..c737c6923 100644 --- a/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java +++ b/core/test/net/sf/openrocket/masscalc/MassCalculatorTest.java @@ -9,6 +9,7 @@ import net.sf.openrocket.masscalc.MassCalculator.MassCalcType; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.rocketcomponent.BodyTube; import net.sf.openrocket.rocketcomponent.FlightConfiguration; +import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.InnerTube; import net.sf.openrocket.rocketcomponent.NoseCone; import net.sf.openrocket.rocketcomponent.ParallelStage; @@ -299,7 +300,8 @@ public class MassCalculatorTest extends BaseTestCase { Rocket rocket = TestRockets.makeEstesAlphaIII(); InnerTube mmt = (InnerTube) rocket.getChild(0).getChild(1).getChild(2); - Motor activeMotor = mmt.getMotorInstance( rocket.getSelectedConfiguration().getId()).getMotor(); + FlightConfigurationId fcid = rocket.getSelectedConfiguration().getId(); + Motor activeMotor = mmt.getMotorConfig( fcid ).getMotor(); String desig = activeMotor.getDesignation(); double expLaunchMass = 0.0164; // kg diff --git a/swing/src/net/sf/openrocket/gui/configdialog/MotorConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/MotorConfig.java index caa405d1c..a1f4192ca 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/MotorConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/MotorConfig.java @@ -69,7 +69,7 @@ public class MotorConfig extends JPanel { //// Ignition at: panel.add(new JLabel(trans.get("MotorCfg.lbl.Ignitionat") + " " + CommonStrings.dagger), ""); - MotorConfiguration motorInstance = mount.getDefaultMotorInstance(); + MotorConfiguration motorInstance = mount.getDefaultMotorConfig(); final EnumModel igEvModel = new EnumModel(motorInstance, "IgnitionEvent", IgnitionEvent.values()); final JComboBox eventBox = new JComboBox( igEvModel); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java index 5b3e0192c..d6a850aba 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java @@ -47,7 +47,7 @@ public class IgnitionSelectionDialog extends JDialog { public IgnitionSelectionDialog(Window parent, final FlightConfigurationId curFCID, MotorMount _mount) { super(parent, trans.get("edtmotorconfdlg.title.Selectignitionconf"), Dialog.ModalityType.APPLICATION_MODAL); curMount = _mount; - curMotorInstance = curMount.getMotorInstance(curFCID); + curMotorInstance = curMount.getMotorConfig(curFCID); startIgnitionEvent = curMotorInstance.getIgnitionEvent(); startIgnitionDelay = curMotorInstance.getIgnitionDelay(); JPanel panel = new JPanel(new MigLayout("fill")); @@ -106,7 +106,7 @@ public class IgnitionSelectionDialog extends JDialog { IgnitionEvent cie = curMotorInstance.getIgnitionEvent(); // update the default instance - final MotorConfiguration defaultMotorInstance = curMount.getDefaultMotorInstance(); + final MotorConfiguration defaultMotorInstance = curMount.getDefaultMotorConfig(); defaultMotorInstance.setIgnitionDelay( cid); defaultMotorInstance.setIgnitionEvent( cie); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java index 8b99ba191..449f69227 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java @@ -325,7 +325,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec } motorFilterPanel.setMotorMount(mountToEdit); - MotorConfiguration curMotorInstance = mountToEdit.getMotorInstance(_fcid); + MotorConfiguration curMotorInstance = mountToEdit.getMotorConfig(_fcid); selectedMotor = null; selectedMotorSet = null; selectedDelay = 0; diff --git a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java index c4dbdea91..5ddcec25a 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java @@ -425,7 +425,7 @@ public class PhotoPanel extends JPanel implements GLEventListener { continue; } - final Motor motor = mount.getMotorInstance(motorID).getMotor(); + final Motor motor = mount.getMotorConfig(motorID).getMotor(); final double length = motor.getLength(); Coordinate[] position = ((RocketComponent) mount) diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java index 07f61fcac..dd115452a 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -215,7 +215,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel Motor mtr = motorChooserDialog.getSelectedMotor(); double d = motorChooserDialog.getSelectedDelay(); if (mtr != null) { - MotorConfiguration curConfig = curMount.getMotorInstance(fcid); + MotorConfiguration curConfig = curMount.getMotorConfig(fcid); curConfig.setMotor(mtr); curConfig.setEjectionDelay(d); curConfig.setIgnitionEvent( IgnitionEvent.NEVER); @@ -261,7 +261,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel if ( (null == fcid )||( null == curMount )){ return; } - MotorConfiguration curInstance = curMount.getMotorInstance(fcid); + MotorConfiguration curInstance = curMount.getMotorConfig(fcid); curInstance.useDefaultIgnition(); @@ -277,7 +277,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel JLabel label = new JLabel(); label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS)); - MotorConfiguration curMotor = mount.getMotorInstance( configId); + MotorConfiguration curMotor = mount.getMotorConfig( configId); String motorString = getMotorSpecification( curMotor ); JLabel motorDescriptionLabel = new JLabel(motorString); @@ -309,8 +309,8 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel } private JLabel getIgnitionEventString(FlightConfigurationId id, MotorMount mount) { - MotorConfiguration defInstance = mount.getDefaultMotorInstance(); - MotorConfiguration curInstance = mount.getMotorInstance(id); + MotorConfiguration defInstance = mount.getDefaultMotorConfig(); + MotorConfiguration curInstance = mount.getMotorConfig(id); IgnitionEvent ignitionEvent = curInstance.getIgnitionEvent(); Double ignitionDelay = curInstance.getIgnitionDelay(); diff --git a/swing/src/net/sf/openrocket/gui/print/DesignReport.java b/swing/src/net/sf/openrocket/gui/print/DesignReport.java index 88a7dcce4..3428c0de5 100644 --- a/swing/src/net/sf/openrocket/gui/print/DesignReport.java +++ b/swing/src/net/sf/openrocket/gui/print/DesignReport.java @@ -356,8 +356,8 @@ public class DesignReport { MotorMount mount = (MotorMount) c; // TODO: refactor this... it's redundant with containing if, and could probably be simplified - if (mount.isMotorMount() && (mount.getMotorInstance(motorId) != null) &&(null != mount.getMotorInstance(motorId).getMotor())) { - Motor motor = mount.getMotorInstance(motorId).getMotor(); + if (mount.isMotorMount() && (mount.getMotorConfig(motorId) != null) &&(null != mount.getMotorConfig(motorId).getMotor())) { + Motor motor = mount.getMotorConfig(motorId).getMotor(); int motorCount = mount.getMotorCount();