AngularVelocityKey.java

  1. /* Copyright 2002-2024 Luc Maisonobe
  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. /** Keys for {@link AngularVelocity APM angular velocity} entries.
  23.  * @author Luc Maisonobe
  24.  * @since 12.0
  25.  */
  26. public enum AngularVelocityKey {

  27.     /** Comment entry. */
  28.     COMMENT((token, context, container) ->
  29.             token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),

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

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

  42.     /** Frame in which angular velocity is defined. */
  43.     ANGVEL_FRAME((token, context, container) -> token.processAsFrame(container::setFrame, context, true, true, true)),

  44.     /** Angular velocity around X axis. */
  45.     ANGVEL_X((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  46.                                                                   container::setAngVelX)),

  47.     /** Angular velocity around Y axis. */
  48.     ANGVEL_Y((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  49.                                                                   container::setAngVelY)),

  50.     /** Angular velocity around Z axis. */
  51.     ANGVEL_Z((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
  52.                                                                   container::setAngVelZ));

  53.     /** Processing method. */
  54.     private final transient TokenProcessor processor;

  55.     /** Simple constructor.
  56.      * @param processor processing method
  57.      */
  58.     AngularVelocityKey(final TokenProcessor processor) {
  59.         this.processor = processor;
  60.     }

  61.     /** Process one token.
  62.      * @param token token to process
  63.      * @param context context binding
  64.      * @param container container to fill
  65.      * @return true of token was accepted
  66.      */
  67.     public boolean process(final ParseToken token, final ContextBinding context, final AngularVelocity container) {
  68.         return processor.process(token, context, container);
  69.     }

  70.     /** Interface for processing one token. */
  71.     interface TokenProcessor {
  72.         /** Process one token.
  73.          * @param token token to process
  74.          * @param context context binding
  75.          * @param container container to fill
  76.          * @return true of token was accepted
  77.          */
  78.         boolean process(ParseToken token, ContextBinding context, AngularVelocity container);
  79.     }

  80. }