EulerKey.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.adm.apm;

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

  24. /** Keys for {@link ApmData APM Euler angles} entries.
  25.  * @author Bryan Cazabonne
  26.  * @since 10.2
  27.  */
  28. public enum EulerKey {

  29.     /** Rotation angles wrapping element in XML files. */
  30.     rotationAngles((token, context, container) -> true),

  31.     /** Rotation rates wrapping element in XML files. */
  32.     rotationRates((token, context, container) -> true),

  33.     /** Comment entry. */
  34.     COMMENT((token, context, container) ->
  35.             token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),

  36.     /** First reference frame entry. */
  37.     EULER_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),

  38.     /** Second reference frame entry. */
  39.     EULER_FRAME_B((token, context, container) -> {
  40.         if (token.getType() == TokenType.ENTRY) {
  41.             container.checkNotNull(container.getEndpoints().getFrameA(), EULER_FRAME_A);
  42.             final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
  43.             return token.processAsFrame(container.getEndpoints()::setFrameB, context,
  44.                                         aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
  45.         }
  46.         return true;
  47.     }),

  48.     /** Rotation direction entry. */
  49.     EULER_DIR((token, context, container) -> {
  50.         if (token.getType() == TokenType.ENTRY) {
  51.             container.getEndpoints().setA2b(token.getContentAsUppercaseCharacter() == 'A');
  52.         }
  53.         return true;
  54.     }),

  55.     /** Rotation sequence entry. */
  56.     EULER_ROT_SEQ((token, context, container) -> AdmParser.processRotationOrder(token, container::setEulerRotSeq)),

  57.     /** Reference frame for rate entry. */
  58.     RATE_FRAME((token, context, container) -> {
  59.         if (token.getType() == TokenType.ENTRY) {
  60.             final String content = token.getContentAsUppercaseString();
  61.             final char   suffix  = content.charAt(content.length() - 1);
  62.             container.setRateFrameIsA(suffix == 'A');
  63.         }
  64.         return true;
  65.     }),

  66.     /** X body rotation angle entry. */
  67.     X_ANGLE((token, context, container) -> token.processAsLabeledDouble('X', Unit.DEGREE, context.getParsedUnitsBehavior(),
  68.                                                                         container::setRotationAngle)),

  69.     /** Y body rotation angle entry. */
  70.     Y_ANGLE((token, context, container) -> token.processAsLabeledDouble('Y', Unit.DEGREE, context.getParsedUnitsBehavior(),
  71.                                                                         container::setRotationAngle)),

  72.     /** Z body rotation angle entry. */
  73.     Z_ANGLE((token, context, container) -> token.processAsLabeledDouble('Z', Unit.DEGREE, context.getParsedUnitsBehavior(),
  74.                                                                         container::setRotationAngle)),

  75.     /** X body rotation rate entry. */
  76.     X_RATE((token, context, container) -> token.processAsLabeledDouble('X', Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  77.                                                                        container::setRotationRate)),

  78.     /** Y body rotation rate entry. */
  79.     Y_RATE((token, context, container) -> token.processAsLabeledDouble('Y', Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  80.                                                                        container::setRotationRate)),

  81.     /** Z body rotation rate entry. */
  82.     Z_RATE((token, context, container) -> token.processAsLabeledDouble('Z', Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  83.                                                                        container::setRotationRate));

  84.     /** Processing method. */
  85.     private final TokenProcessor processor;

  86.     /** Simple constructor.
  87.      * @param processor processing method
  88.      */
  89.     EulerKey(final TokenProcessor processor) {
  90.         this.processor = processor;
  91.     }

  92.     /** Process one token.
  93.      * @param token token to process
  94.      * @param context context binding
  95.      * @param container container to fill
  96.      * @return true of token was accepted
  97.      */
  98.     public boolean process(final ParseToken token, final ContextBinding context, final Euler container) {
  99.         return processor.process(token, context, container);
  100.     }

  101.     /** Interface for processing one token. */
  102.     interface TokenProcessor {
  103.         /** Process one token.
  104.          * @param token token to process
  105.          * @param context context binding
  106.          * @param container container to fill
  107.          * @return true of token was accepted
  108.          */
  109.         boolean process(ParseToken token, ContextBinding context, Euler container);
  110.     }

  111. }