EventHandler.java

  1. /* Copyright 2013 Applied Defense Solutions, Inc.
  2.  * Licensed to CS Communication & Systèmes (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.propagation.events.handlers;

  18. import org.orekit.propagation.SpacecraftState;
  19. import org.orekit.propagation.events.EventDetector;
  20. import org.orekit.time.AbsoluteDate;


  21. /**
  22.  * An interface defining how to override event handling behavior in the standard
  23.  * propagator eventing classes without requiring subclassing.  In cases where
  24.  * one wishes to use anonymous classes rather than explicit subclassing this
  25.  * allows for a more direct way to override the behavior.  Event classes have to
  26.  * specifically support this capability.
  27.  *
  28.  * @author Hank Grabowski
  29.  *
  30.  * @param <T> object type that the handler is called from
  31.  * @since 6.1
  32.  */
  33. public interface EventHandler<T extends EventDetector> {

  34.     /** Enumerate for actions to be performed when an event occurs. */
  35.     enum Action {

  36.         /** Stop indicator.
  37.          * <p>This value should be used as the return value of the {@link
  38.          * #eventOccurred eventOccurred} method when the propagation should be
  39.          * stopped after the event ending the current step.</p>
  40.          */
  41.         STOP,

  42.         /** Reset state indicator.
  43.          * <p>This value should be used as the return value of the {@link
  44.          * #eventOccurred eventOccurred} method when the propagation should
  45.          * go on after the event ending the current step, with a new state
  46.          * (which will be retrieved thanks to the {@link #resetState
  47.          * resetState} method).</p>
  48.          */
  49.         RESET_STATE,

  50.         /** Reset derivatives indicator.
  51.          * <p>This value should be used as the return value of the {@link
  52.          * #eventOccurred eventOccurred} method when the propagation should
  53.          * go on after the event ending the current step, with recomputed
  54.          * derivatives vector.</p>
  55.          */
  56.         RESET_DERIVATIVES,

  57.         /** Continue indicator.
  58.          * <p>This value should be used as the return value of the {@link
  59.          * #eventOccurred eventOccurred} method when the propagation should go
  60.          * on after the event ending the current step.</p>
  61.          */
  62.         CONTINUE;

  63.     }

  64.     /** Initialize event handler at the start of a propagation.
  65.      * <p>
  66.      * This method is called once at the start of the propagation. It
  67.      * may be used by the event handler to initialize some internal data
  68.      * if needed.
  69.      * </p>
  70.      * <p>
  71.      * The default implementation does nothing
  72.      * </p>
  73.      * @param initialState initial state
  74.      * @param target target date for the propagation
  75.      *
  76.      */
  77.     default void init(SpacecraftState initialState, AbsoluteDate target) {
  78.         // nothing by default
  79.     }

  80.     /**
  81.      * eventOccurred method mirrors the same interface method as in {@link EventDetector}
  82.      * and its subclasses, but with an additional parameter that allows the calling
  83.      * method to pass in an object from the detector which would have potential
  84.      * additional data to allow the implementing class to determine the correct
  85.      * return state.
  86.      *
  87.      * @param s SpaceCraft state to be used in the evaluation
  88.      * @param detector object with appropriate type that can be used in determining correct return state
  89.      * @param increasing with the event occurred in an "increasing" or "decreasing" slope direction
  90.      * @return the Action that the calling detector should pass back to the evaluation system
  91.      *
  92.      */
  93.     Action eventOccurred(SpacecraftState s, T detector, boolean increasing);

  94.     /** Reset the state prior to continue propagation.
  95.      * <p>This method is called after the step handler has returned and
  96.      * before the next step is started, but only when {@link
  97.      * #eventOccurred} has itself returned the {@link Action#RESET_STATE}
  98.      * indicator. It allows the user to reset the state for the next step,
  99.      * without perturbing the step handler of the finishing step. If the
  100.      * {@link #eventOccurred} never returns the {@link Action#RESET_STATE}
  101.      * indicator, this function will never be called, and it is safe to simply return null.</p>
  102.      * <p>
  103.      * The default implementation simply return its argument.
  104.      * </p>
  105.      * @param detector object with appropriate type that can be used in determining correct return state
  106.      * @param oldState old state
  107.      * @return new state
  108.      */
  109.     default SpacecraftState resetState(T detector, SpacecraftState oldState) {
  110.         return oldState;
  111.     }

  112. }