AemMetadataKey.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.aem;

  18. import org.orekit.files.ccsds.ndm.adm.AdmMetadataKey;
  19. import org.orekit.files.ccsds.ndm.adm.AdmParser;
  20. import org.orekit.files.ccsds.ndm.adm.AttitudeType;
  21. import org.orekit.files.ccsds.utils.ContextBinding;
  22. import org.orekit.files.ccsds.utils.lexical.ParseToken;
  23. import org.orekit.files.ccsds.utils.lexical.TokenType;


  24. /** Keys for {@link AemMetadata AEM container} entries.
  25.  * <p>
  26.  * Additional container are also listed in {@link AdmMetadataKey}.
  27.  * </p>
  28.  * @author Bryan Cazabonne
  29.  * @since 11.0
  30.  */
  31. public enum AemMetadataKey {

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

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

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

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

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

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

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

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

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

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

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

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

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

  93.     /** Processing method. */
  94.     private final TokenProcessor processor;

  95.     /** Simple constructor.
  96.      * @param processor processing method
  97.      */
  98.     AemMetadataKey(final TokenProcessor processor) {
  99.         this.processor = processor;
  100.     }

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

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

  120. }