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.hipparchus.ode.events.Action;
  19. import org.orekit.propagation.SpacecraftState;
  20. import org.orekit.propagation.events.EventDetector;
  21. import org.orekit.time.AbsoluteDate;


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

  35.     /** Initialize event handler at the start of a propagation.
  36.      * <p>
  37.      * This method is called once at the start of the propagation. It
  38.      * may be used by the event handler to initialize some internal data
  39.      * if needed.
  40.      * </p>
  41.      * <p>
  42.      * The default implementation does nothing
  43.      * </p>
  44.      * @param initialState initial state
  45.      * @param target target date for the propagation
  46.      * @param detector event detector related to the event handler
  47.      *
  48.      */
  49.     default void init(SpacecraftState initialState, AbsoluteDate target, final T detector) {
  50.         // nothing by default
  51.     }

  52.     /**
  53.      * eventOccurred method mirrors the same interface method as in {@link EventDetector}
  54.      * and its subclasses, but with an additional parameter that allows the calling
  55.      * method to pass in an object from the detector which would have potential
  56.      * additional data to allow the implementing class to determine the correct
  57.      * return state.
  58.      *
  59.      * @param s SpaceCraft state to be used in the evaluation
  60.      * @param detector object with appropriate type that can be used in determining correct return state
  61.      * @param increasing with the event occurred in an "increasing" or "decreasing" slope direction
  62.      * @return the Action that the calling detector should pass back to the evaluation system
  63.      *
  64.      */
  65.     Action eventOccurred(SpacecraftState s, T detector, boolean increasing);

  66.     /** Reset the state prior to continue propagation.
  67.      * <p>This method is called after the step handler has returned and
  68.      * before the next step is started, but only when {@link
  69.      * #eventOccurred} has itself returned the {@link Action#RESET_STATE}
  70.      * indicator. It allows the user to reset the state for the next step,
  71.      * without perturbing the step handler of the finishing step. If the
  72.      * {@link #eventOccurred} never returns the {@link Action#RESET_STATE}
  73.      * indicator, this function will never be called, and it is safe to simply return null.</p>
  74.      * <p>
  75.      * The default implementation simply return its argument.
  76.      * </p>
  77.      * @param detector object with appropriate type that can be used in determining correct return state
  78.      * @param oldState old state
  79.      * @return new state
  80.      */
  81.     default SpacecraftState resetState(T detector, SpacecraftState oldState) {
  82.         return oldState;
  83.     }

  84. }