EulerKey.java

  1. /* Copyright 2002-2024 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.utils.ContextBinding;
  20. import org.orekit.files.ccsds.utils.lexical.ParseToken;
  21. import org.orekit.files.ccsds.utils.lexical.TokenType;
  22. import org.orekit.utils.units.Unit;

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

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

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

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

  35.     /** First reference frame entry (only for ADM V1). */
  36.     EULER_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),

  37.     /** First reference frame entry.
  38.      * @since 12.0
  39.      */
  40.     REF_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),

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

  51.     /** Second reference frame entry.
  52.      * @since 12.0
  53.      */
  54.     REF_FRAME_B((token, context, container) -> {
  55.         if (token.getType() == TokenType.ENTRY) {
  56.             container.checkNotNull(container.getEndpoints().getFrameA(), EULER_FRAME_A.name());
  57.             final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
  58.             return token.processAsFrame(container.getEndpoints()::setFrameB, context,
  59.                                         aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
  60.         }
  61.         return true;
  62.     }),

  63.     /** Rotation direction entry (ADM V1 only). */
  64.     EULER_DIR((token, context, container) -> {
  65.         if (token.getType() == TokenType.ENTRY) {
  66.             container.getEndpoints().setA2b(token.getContentAsUppercaseCharacter() == 'A');
  67.         }
  68.         return true;
  69.     }),

  70.     /** Rotation sequence entry. */
  71.     EULER_ROT_SEQ((token, context, container) -> token.processAsRotationOrder(container::setEulerRotSeq)),

  72.     /** Reference frame for rate entry (ADM V1 only). */
  73.     RATE_FRAME((token, context, container) -> {
  74.         if (token.getType() == TokenType.ENTRY) {
  75.             final String content = token.getContentAsUppercaseString();
  76.             final char   suffix  = content.charAt(content.length() - 1);
  77.             container.setRateFrameIsA(suffix == 'A');
  78.         }
  79.         return true;
  80.     }),

  81.     /** X body rotation angle entry (ADM V1 only). */
  82.     X_ANGLE((token, context, container) -> token.processAsLabeledDouble('X', Unit.DEGREE, context.getParsedUnitsBehavior(),
  83.                                                                         container::setLabeledRotationAngle)),

  84.     /** Y body rotation angle entry (ADM V1 only). */
  85.     Y_ANGLE((token, context, container) -> token.processAsLabeledDouble('Y', Unit.DEGREE, context.getParsedUnitsBehavior(),
  86.                                                                         container::setLabeledRotationAngle)),

  87.     /** Z body rotation angle entry (ADM V1 only). */
  88.     Z_ANGLE((token, context, container) -> token.processAsLabeledDouble('Z', Unit.DEGREE, context.getParsedUnitsBehavior(),
  89.                                                                         container::setLabeledRotationAngle)),

  90.     /** X body rotation rate entry (ADM V1 only). */
  91.     X_RATE((token, context, container) -> token.processAsLabeledDouble('X', Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  92.                                                                        container::setLabeledRotationRate)),

  93.     /** Y body rotation rate entry (ADM V1 only). */
  94.     Y_RATE((token, context, container) -> token.processAsLabeledDouble('Y', Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  95.                                                                        container::setLabeledRotationRate)),

  96.     /** Z body rotation rate entry (ADM V1 only). */
  97.     Z_RATE((token, context, container) -> token.processAsLabeledDouble('Z', Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  98.                                                                        container::setLabeledRotationRate)),

  99.     /** First body rotation angle entry.
  100.      * @since 12.0
  101.      */
  102.     ANGLE_1((token, context, container) -> token.processAsIndexedDouble(0, Unit.DEGREE, context.getParsedUnitsBehavior(),
  103.                                                                         container::setIndexedRotationAngle)),

  104.     /** Second body rotation angle entry.
  105.      * @since 12.0
  106.      */
  107.     ANGLE_2((token, context, container) -> token.processAsIndexedDouble(1, Unit.DEGREE, context.getParsedUnitsBehavior(),
  108.                                                                         container::setIndexedRotationAngle)),

  109.     /** Third body rotation angle entry.
  110.      * @since 12.0
  111.      */
  112.     ANGLE_3((token, context, container) -> token.processAsIndexedDouble(2, Unit.DEGREE, context.getParsedUnitsBehavior(),
  113.                                                                         container::setIndexedRotationAngle)),

  114.     /** First body rotation rate entry.
  115.      * @since 12.0
  116.      */
  117.     ANGLE_1_DOT((token, context, container) -> token.processAsIndexedDouble(0, Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  118.                                                                             container::setIndexedRotationRate)),

  119.     /** Second body rotation rate entry.
  120.      * @since 12.0
  121.      */
  122.     ANGLE_2_DOT((token, context, container) -> token.processAsIndexedDouble(1, Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  123.                                                                             container::setIndexedRotationRate)),

  124.     /** Third body rotation rate entry.
  125.      * @since 12.0
  126.      */
  127.     ANGLE_3_DOT((token, context, container) -> token.processAsIndexedDouble(2, Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  128.                                                                             container::setIndexedRotationRate));

  129.     /** Processing method. */
  130.     private final transient TokenProcessor processor;

  131.     /** Simple constructor.
  132.      * @param processor processing method
  133.      */
  134.     EulerKey(final TokenProcessor processor) {
  135.         this.processor = processor;
  136.     }

  137.     /** Process one token.
  138.      * @param token token to process
  139.      * @param context context binding
  140.      * @param container container to fill
  141.      * @return true of token was accepted
  142.      */
  143.     public boolean process(final ParseToken token, final ContextBinding context, final Euler container) {
  144.         return processor.process(token, context, container);
  145.     }

  146.     /** Interface for processing one token. */
  147.     interface TokenProcessor {
  148.         /** Process one token.
  149.          * @param token token to process
  150.          * @param context context binding
  151.          * @param container container to fill
  152.          * @return true of token was accepted
  153.          */
  154.         boolean process(ParseToken token, ContextBinding context, Euler container);
  155.     }

  156. }