KeplerianElementsKey.java

  1. /* Copyright 2002-2022 CS GROUP
  2.  * Licensed to CS GROUP (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.files.ccsds.ndm.odm;

  18. import org.orekit.files.ccsds.definitions.Units;
  19. import org.orekit.files.ccsds.utils.ContextBinding;
  20. import org.orekit.files.ccsds.utils.lexical.ParseToken;
  21. import org.orekit.files.ccsds.utils.lexical.TokenType;
  22. import org.orekit.orbits.PositionAngle;
  23. import org.orekit.utils.units.Unit;


  24. /** Keys for {@link KeplerianElements Keplerian elements} entries.
  25.  * @author Luc Maisonobe
  26.  * @since 11.0
  27.  */
  28. public enum KeplerianElementsKey {

  29.     /** Comment entry. */
  30.     COMMENT((token, context, container) ->
  31.             token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),

  32.     /** Epoch of Keplerian elements. */
  33.     EPOCH((token, context, container) -> token.processAsDate(container::setEpoch, context)),

  34.     /** Orbit semi-major axis. */
  35.     SEMI_MAJOR_AXIS((token, context, container) -> token.processAsDouble(Unit.KILOMETRE, context.getParsedUnitsBehavior(), container::setA)),

  36.     /** Mean motion. */
  37.     MEAN_MOTION((token, context, container) -> token.processAsDouble(Units.REV_PER_DAY, context.getParsedUnitsBehavior(), container::setMeanMotion)),

  38.     /** Orbit eccentricity. */
  39.     ECCENTRICITY((token, context, container) -> token.processAsDouble(Unit.ONE, context.getParsedUnitsBehavior(), container::setE)),

  40.     /** Orbit inclination. */
  41.     INCLINATION((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(), container::setI)),

  42.     /** Orbit right ascension of ascending node. */
  43.     RA_OF_ASC_NODE((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(), container::setRaan)),

  44.     /** Orbit argument of pericenter. */
  45.     ARG_OF_PERICENTER((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(), container::setPa)),

  46.     /** Orbit true anomaly. */
  47.     TRUE_ANOMALY((token, context, container) -> {
  48.         if (token.getType() == TokenType.ENTRY) {
  49.             final double angle = context.
  50.                                  getParsedUnitsBehavior().
  51.                                  select(token.getUnits(), Unit.DEGREE).
  52.                                  toSI(token.getContentAsDouble());
  53.             container.setAnomaly(angle);
  54.             container.setAnomalyType(PositionAngle.TRUE);
  55.         }
  56.         return true;
  57.     }),

  58.     /** Orbit mean anomaly. */
  59.     MEAN_ANOMALY((token, context, container) -> {
  60.         if (token.getType() == TokenType.ENTRY) {
  61.             final double angle = context.
  62.                                  getParsedUnitsBehavior().
  63.                                  select(token.getUnits(), Unit.DEGREE).
  64.                                  toSI(token.getContentAsDouble());
  65.             container.setAnomaly(angle);
  66.             container.setAnomalyType(PositionAngle.MEAN);
  67.         }
  68.         return true;
  69.     }),

  70.     /** Gravitational coefficient. */
  71.     GM((token, context, container) -> token.processAsDouble(Units.KM3_PER_S2, context.getParsedUnitsBehavior(), container::setMu));

  72.     /** Processing method. */
  73.     private final TokenProcessor processor;

  74.     /** Simple constructor.
  75.      * @param processor processing method
  76.      */
  77.     KeplerianElementsKey(final TokenProcessor processor) {
  78.         this.processor = processor;
  79.     }

  80.     /** Process one token.
  81.      * @param token token to process
  82.      * @param context context binding
  83.      * @param container container to fill
  84.      * @return true of token was accepted
  85.      */
  86.     public boolean process(final ParseToken token, final ContextBinding context, final KeplerianElements container) {
  87.         return processor.process(token, context, container);
  88.     }

  89.     /** Interface for processing one token. */
  90.     interface TokenProcessor {
  91.         /** Process one token.
  92.          * @param token token to process
  93.          * @param context context binding
  94.          * @param container container to fill
  95.          * @return true of token was accepted
  96.          */
  97.         boolean process(ParseToken token, ContextBinding context, KeplerianElements container);
  98.     }

  99. }