AemMetadataKey.java

  1. /* Copyright 2002-2025 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.aem;

  18. import org.orekit.files.ccsds.ndm.adm.AdmMetadataKey;
  19. import org.orekit.files.ccsds.ndm.adm.AttitudeType;
  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. /** Keys for {@link AemMetadata AEM container} entries.
  24.  * <p>
  25.  * Additional container are also listed in {@link AdmMetadataKey}.
  26.  * </p>
  27.  * @author Bryan Cazabonne
  28.  * @since 11.0
  29.  */
  30. public enum AemMetadataKey {

  31.     /** First reference frame. */
  32.     REF_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),

  33.     /** Second reference frame. */
  34.     REF_FRAME_B((token, context, container) -> {
  35.         if (token.getType() == TokenType.ENTRY) {
  36.             container.checkNotNull(container.getEndpoints().getFrameA(), REF_FRAME_A.name());
  37.             final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
  38.             return token.processAsFrame(container.getEndpoints()::setFrameB, context,
  39.                                         aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
  40.         }
  41.         return true;
  42.     }),

  43.     /** Rotation direction entry. */
  44.     ATTITUDE_DIR((token, context, container) -> {
  45.         if (token.getType() == TokenType.ENTRY) {
  46.             container.getEndpoints().setA2b(token.getContentAsUppercaseCharacter() == 'A');
  47.         }
  48.         return true;
  49.     }),

  50.     /** Start time entry. */
  51.     START_TIME((token, context, container) -> token.processAsDate(container::setStartTime, context)),

  52.     /** Stop time entry. */
  53.     STOP_TIME((token, context, container) -> token.processAsDate(container::setStopTime, context)),

  54.     /** Useable start time entry. */
  55.     USEABLE_START_TIME((token, context, container) -> token.processAsDate(container::setUseableStartTime, context)),

  56.     /** Useable stop time entry. */
  57.     USEABLE_STOP_TIME((token, context, container) -> token.processAsDate(container::setUseableStopTime, context)),

  58.     /** Format of the data line entry. */
  59.     ATTITUDE_TYPE((token, context, container) -> {
  60.         if (token.getType() == TokenType.ENTRY) {
  61.             try {
  62.                 container.setAttitudeType(AttitudeType.parseType(token.getRawContent()));
  63.                 return true;
  64.             } catch (IllegalArgumentException iae) {
  65.                 return false;
  66.             }
  67.         }
  68.         return true;
  69.     }),

  70.     /** Placement of the scalar component in quaternion entry. */
  71.     QUATERNION_TYPE((token, context, container) -> {
  72.         if (token.getType() == TokenType.ENTRY) {
  73.             container.setIsFirst("FIRST".equals(token.getContentAsUppercaseString()));
  74.         }
  75.         return true;
  76.     }),

  77.     /** Rotation order entry for Euler angles. */
  78.     EULER_ROT_SEQ((token, context, container) -> token.processAsRotationOrder(container::setEulerRotSeq)),

  79.     /** Reference frame for Euler rates. (only for ADM V1) */
  80.     RATE_FRAME((token, context, container) -> {
  81.         if (token.getType() == TokenType.ENTRY) {
  82.             final String content = token.getContentAsUppercaseString();
  83.             final char   suffix  = content.charAt(content.length() - 1);
  84.             container.setRateFrameIsA(suffix == 'A');
  85.         }
  86.         return true;
  87.     }),

  88.     /** Reference frame for angular velocities.
  89.      * @since 12.0
  90.      */
  91.     ANGVEL_FRAME((token, context, container) -> token.processAsFrame(container::setAngvelFrame, context, true, true, true)),

  92.     /** Interpolation method in ephemeris. */
  93.     INTERPOLATION_METHOD((token, context, container) -> token.processAsUppercaseString(container::setInterpolationMethod)),

  94.     /** Interpolation degree in ephemeris. */
  95.     INTERPOLATION_DEGREE((token, context, container) -> token.processAsInteger(container::setInterpolationDegree));

  96.     /** Processing method. */
  97.     private final transient TokenProcessor processor;

  98.     /** Simple constructor.
  99.      * @param processor processing method
  100.      */
  101.     AemMetadataKey(final TokenProcessor processor) {
  102.         this.processor = processor;
  103.     }

  104.     /** Process an token.
  105.      * @param token token to process
  106.      * @param context context binding
  107.      * @param container container to fill
  108.      * @return true of token was accepted
  109.      */
  110.     public boolean process(final ParseToken token, final ContextBinding context, final AemMetadata container) {
  111.         return processor.process(token, context, container);
  112.     }

  113.     /** Interface for processing one token. */
  114.     interface TokenProcessor {
  115.         /** Process one token.
  116.          * @param token token to process
  117.          * @param context context binding
  118.          * @param container container to fill
  119.          * @return true of token was accepted
  120.          */
  121.         boolean process(ParseToken token, ContextBinding context, AemMetadata container);
  122.     }

  123. }