1   /* Copyright 2022-2025 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  
19  import org.orekit.files.ccsds.definitions.Units;
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  
24  /** Keys for {@link AngularVelocity APM angular velocity} entries.
25   * @author Luc Maisonobe
26   * @since 12.0
27   */
28  public enum AngularVelocityKey {
29  
30      /** Comment entry. */
31      COMMENT((token, context, container) ->
32              token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),
33  
34      /** First reference frame entry. */
35      REF_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),
36  
37      /** Second reference frame entry. */
38      REF_FRAME_B((token, context, container) -> {
39          if (token.getType() == TokenType.ENTRY) {
40              container.checkNotNull(container.getEndpoints().getFrameA(), REF_FRAME_A.name());
41              final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
42              return token.processAsFrame(container.getEndpoints()::setFrameB, context,
43                                          aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
44          }
45          return true;
46      }),
47  
48      /** Frame in which angular velocity is defined. */
49      ANGVEL_FRAME((token, context, container) -> token.processAsFrame(container::setFrame, context, true, true, true)),
50  
51      /** Angular velocity around X axis. */
52      ANGVEL_X((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
53                                                                    container::setAngVelX)),
54  
55      /** Angular velocity around Y axis. */
56      ANGVEL_Y((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
57                                                                    container::setAngVelY)),
58  
59      /** Angular velocity around Z axis. */
60      ANGVEL_Z((token, context, container) -> token.processAsDouble(Units.DEG_PER_S, context.getParsedUnitsBehavior(),
61                                                                    container::setAngVelZ));
62  
63      /** Processing method. */
64      private final transient TokenProcessor processor;
65  
66      /** Simple constructor.
67       * @param processor processing method
68       */
69      AngularVelocityKey(final TokenProcessor processor) {
70          this.processor = processor;
71      }
72  
73      /** Process one token.
74       * @param token token to process
75       * @param context context binding
76       * @param container container to fill
77       * @return true of token was accepted
78       */
79      public boolean process(final ParseToken token, final ContextBinding context, final AngularVelocity container) {
80          return processor.process(token, context, container);
81      }
82  
83      /** Interface for processing one token. */
84      interface TokenProcessor {
85          /** Process one token.
86           * @param token token to process
87           * @param context context binding
88           * @param container container to fill
89           * @return true of token was accepted
90           */
91          boolean process(ParseToken token, ContextBinding context, AngularVelocity container);
92      }
93  
94  }