ApmQuaternionKey.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.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 ApmQuaternion APM quaternion} entries.
  24.  * @author Bryan Cazabonne
  25.  * @since 10.2
  26.  */
  27. public enum ApmQuaternionKey {

  28.     /** Quaternion wrapping element in XML files. */
  29.     quaternion((token, context, container) -> true),

  30.     /** Quaternion wrapping element in XML files. */
  31.     quaternionRate((token, context, container) -> true),

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

  34.     /** First reference frame entry. */
  35.     Q_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),

  36.     /** Second reference frame entry. */
  37.     Q_FRAME_B((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameB, context, true, true, true)),

  38.     /** Rotation direction entry. */
  39.     Q_DIR((token, context, container) -> {
  40.         if (token.getType() == TokenType.ENTRY) {
  41.             container.getEndpoints().setA2b(token.getContentAsUppercaseCharacter() == 'A');
  42.         }
  43.         return true;
  44.     }),

  45.     /** Scalar part of the quaternion entry. */
  46.     QC((token, context, container) -> token.processAsIndexedDouble(0, Unit.ONE, context.getParsedUnitsBehavior(),
  47.                                                                    container::setQ)),

  48.     /** First component of the vector part of the quaternion entry. */
  49.     Q1((token, context, container) -> token.processAsIndexedDouble(1, Unit.ONE, context.getParsedUnitsBehavior(),
  50.                                                                    container::setQ)),

  51.     /** Second component of the vector part of the quaternion entry. */
  52.     Q2((token, context, container) -> token.processAsIndexedDouble(2, Unit.ONE, context.getParsedUnitsBehavior(),
  53.                                                                    container::setQ)),

  54.     /** Third component of the vector part of the quaternion entry. */
  55.     Q3((token, context, container) -> token.processAsIndexedDouble(3, Unit.ONE, context.getParsedUnitsBehavior(),
  56.                                                                    container::setQ)),

  57.     /** Scalar part of the quaternion derivative entry. */
  58.     QC_DOT((token, context, container) -> token.processAsIndexedDouble(0, Units.ONE_PER_S, context.getParsedUnitsBehavior(),
  59.                                                                        container::setQDot)),

  60.     /** First component of the vector part of the quaternion derivative entry. */
  61.     Q1_DOT((token, context, container) -> token.processAsIndexedDouble(1, Units.ONE_PER_S, context.getParsedUnitsBehavior(),
  62.                                                                        container::setQDot)),

  63.     /** Second component of the vector part of the quaternion derivative entry. */
  64.     Q2_DOT((token, context, container) -> token.processAsIndexedDouble(2, Units.ONE_PER_S, context.getParsedUnitsBehavior(),
  65.                                                                        container::setQDot)),

  66.     /** Third component of the vector part of the quaternion derivative entry. */
  67.     Q3_DOT((token, context, container) -> token.processAsIndexedDouble(3, Units.ONE_PER_S, context.getParsedUnitsBehavior(),
  68.                                                                        container::setQDot));

  69.     /** Processing method. */
  70.     private final TokenProcessor processor;

  71.     /** Simple constructor.
  72.      * @param processor processing method
  73.      */
  74.     ApmQuaternionKey(final TokenProcessor processor) {
  75.         this.processor = processor;
  76.     }

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

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

  96. }