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  
19  import org.orekit.files.ccsds.ndm.adm.AdmMetadataKey;
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  
25  
26  /** Keys for {@link AemMetadata AEM container} entries.
27   * <p>
28   * Additional container are also listed in {@link AdmMetadataKey}.
29   * </p>
30   * @author Bryan Cazabonne
31   * @since 11.0
32   */
33  public enum AemMetadataKey {
34  
35      /** First reference frame. */
36      REF_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),
37  
38      /** Second reference frame. */
39      REF_FRAME_B((token, context, container) -> {
40          if (token.getType() == TokenType.ENTRY) {
41              container.checkNotNull(container.getEndpoints().getFrameA(), REF_FRAME_A.name());
42              final boolean aIsSpaceraftBody = container.getEndpoints().getFrameA().asSpacecraftBodyFrame() != null;
43              return token.processAsFrame(container.getEndpoints()::setFrameB, context,
44                                          aIsSpaceraftBody, aIsSpaceraftBody, !aIsSpaceraftBody);
45          }
46          return true;
47      }),
48  
49      /** Rotation direction entry. */
50      ATTITUDE_DIR((token, context, container) -> {
51          if (token.getType() == TokenType.ENTRY) {
52              container.getEndpoints().setA2b(token.getContentAsUppercaseCharacter() == 'A');
53          }
54          return true;
55      }),
56  
57      /** Start time entry. */
58      START_TIME((token, context, container) -> token.processAsDate(container::setStartTime, context)),
59  
60      /** Stop time entry. */
61      STOP_TIME((token, context, container) -> token.processAsDate(container::setStopTime, context)),
62  
63      /** Useable start time entry. */
64      USEABLE_START_TIME((token, context, container) -> token.processAsDate(container::setUseableStartTime, context)),
65  
66      /** Useable stop time entry. */
67      USEABLE_STOP_TIME((token, context, container) -> token.processAsDate(container::setUseableStopTime, context)),
68  
69      /** Format of the data line entry. */
70      ATTITUDE_TYPE((token, context, container) -> {
71          if (token.getType() == TokenType.ENTRY) {
72              try {
73                  container.setAttitudeType(AttitudeType.parseType(token.getRawContent()));
74                  return true;
75              } catch (IllegalArgumentException iae) {
76                  return false;
77              }
78          }
79          return true;
80      }),
81  
82      /** Placement of the scalar component in quaternion entry. */
83      QUATERNION_TYPE((token, context, container) -> {
84          if (token.getType() == TokenType.ENTRY) {
85              container.setIsFirst("FIRST".equals(token.getContentAsUppercaseString()));
86          }
87          return true;
88      }),
89  
90      /** Rotation order entry for Euler angles. */
91      EULER_ROT_SEQ((token, context, container) -> token.processAsRotationOrder(container::setEulerRotSeq)),
92  
93      /** Reference frame for Euler rates. (only for ADM V1) */
94      RATE_FRAME((token, context, container) -> {
95          if (token.getType() == TokenType.ENTRY) {
96              final String content = token.getContentAsUppercaseString();
97              final char   suffix  = content.charAt(content.length() - 1);
98              container.setRateFrameIsA(suffix == 'A');
99          }
100         return true;
101     }),
102 
103     /** Reference frame for angular velocities.
104      * @since 12.0
105      */
106     ANGVEL_FRAME((token, context, container) -> token.processAsFrame(container::setAngvelFrame, context, true, true, true)),
107 
108     /** Interpolation method in ephemeris. */
109     INTERPOLATION_METHOD((token, context, container) -> token.processAsUppercaseString(container::setInterpolationMethod)),
110 
111     /** Interpolation degree in ephemeris. */
112     INTERPOLATION_DEGREE((token, context, container) -> token.processAsInteger(container::setInterpolationDegree));
113 
114     /** Processing method. */
115     private final transient TokenProcessor processor;
116 
117     /** Simple constructor.
118      * @param processor processing method
119      */
120     AemMetadataKey(final TokenProcessor processor) {
121         this.processor = processor;
122     }
123 
124     /** Process an token.
125      * @param token token to process
126      * @param context context binding
127      * @param container container to fill
128      * @return true of token was accepted
129      */
130     public boolean process(final ParseToken token, final ContextBinding context, final AemMetadata container) {
131         return processor.process(token, context, container);
132     }
133 
134     /** Interface for processing one token. */
135     interface TokenProcessor {
136         /** Process one token.
137          * @param token token to process
138          * @param context context binding
139          * @param container container to fill
140          * @return true of token was accepted
141          */
142         boolean process(ParseToken token, ContextBinding context, AemMetadata container);
143     }
144 
145 }