diff --git a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java index 82cccd9ed..a7db4f200 100644 --- a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java +++ b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java @@ -259,7 +259,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { private boolean handleEvents() throws SimulationException { boolean ret = true; FlightEvent event; - + log.trace("HandleEvents: current branch = " + currentStatus.getFlightData().getBranchName()); for (event = nextEvent(); event != null; event = nextEvent()) { log.trace("Obtained event from queue: " + event.toString()); @@ -300,7 +300,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { // Ignore events for components that are no longer attached to the rocket if (event.getSource() != null && event.getSource().getParent() != null && !currentStatus.getConfiguration().isComponentActive(event.getSource())) { - log.trace("Ignoring event from unattached componenent"); + log.trace("Ignoring event from unattached component"); continue; } @@ -332,6 +332,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { // Check for recovery device deployment, add events to queue + // TODO: LOW: check if deprecated function getActiveComponents needs to be replaced for (RocketComponent c : currentStatus.getConfiguration().getActiveComponents()) { if (!(c instanceof RecoveryDevice)) continue; diff --git a/core/src/net/sf/openrocket/simulation/FlightData.java b/core/src/net/sf/openrocket/simulation/FlightData.java index e7f24f806..6cdb356e1 100644 --- a/core/src/net/sf/openrocket/simulation/FlightData.java +++ b/core/src/net/sf/openrocket/simulation/FlightData.java @@ -220,7 +220,7 @@ public class FlightData { timeToApogee = Double.NaN; - // Launch rod velocity + // Launch rod velocity + deployment velocity + ground hit velocity for (FlightEvent event : branch.getEvents()) { if (event.getType() == FlightEvent.Type.LAUNCHROD) { double t = event.getTime(); diff --git a/core/src/net/sf/openrocket/simulation/listeners/system/GroundHitListener.java b/core/src/net/sf/openrocket/simulation/listeners/system/GroundHitListener.java new file mode 100644 index 000000000..96d9ffd1b --- /dev/null +++ b/core/src/net/sf/openrocket/simulation/listeners/system/GroundHitListener.java @@ -0,0 +1,29 @@ +package net.sf.openrocket.simulation.listeners.system; + +import net.sf.openrocket.simulation.FlightEvent; +import net.sf.openrocket.simulation.SimulationStatus; +import net.sf.openrocket.simulation.listeners.AbstractSimulationListener; + + +/** + * A simulation listeners that ends the simulation when the ground is hit. + * + * @author Sibo Van Gool + */ +public class GroundHitListener extends AbstractSimulationListener { + + public static final GroundHitListener INSTANCE = new GroundHitListener(); + + @Override + public boolean handleFlightEvent(SimulationStatus status, FlightEvent event) { + if (event.getType() == FlightEvent.Type.GROUND_HIT) { + status.getEventQueue().add(new FlightEvent(FlightEvent.Type.SIMULATION_END, status.getSimulationTime())); + } + return true; + } + + @Override + public boolean isSystemListener() { + return true; + } +} diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 74b855abf..39445e35c 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -66,7 +66,7 @@ import net.sf.openrocket.simulation.FlightData; import net.sf.openrocket.simulation.customexpression.CustomExpression; import net.sf.openrocket.simulation.customexpression.CustomExpressionSimulationListener; import net.sf.openrocket.simulation.listeners.SimulationListener; -import net.sf.openrocket.simulation.listeners.system.ApogeeEndListener; +import net.sf.openrocket.simulation.listeners.system.GroundHitListener; import net.sf.openrocket.simulation.listeners.system.InterruptListener; import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.UnitGroup; @@ -770,7 +770,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change protected SimulationListener[] getExtraListeners() { return new SimulationListener[] { InterruptListener.INSTANCE, - ApogeeEndListener.INSTANCE, + GroundHitListener.INSTANCE, exprListener }; }