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.odm;
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  import org.orekit.orbits.PositionAngleType;
24  import org.orekit.utils.units.Unit;
25  
26  
27  /** Keys for {@link KeplerianElements Keplerian elements} entries.
28   * @author Luc Maisonobe
29   * @since 11.0
30   */
31  public enum KeplerianElementsKey {
32  
33      /** Comment entry. */
34      COMMENT((token, context, container) ->
35              token.getType() == TokenType.ENTRY ? container.addComment(token.getContentAsNormalizedString()) : true),
36  
37      /** Epoch of Keplerian elements. */
38      EPOCH((token, context, container) -> token.processAsDate(container::setEpoch, context)),
39  
40      /** Orbit semi-major axis. */
41      SEMI_MAJOR_AXIS((token, context, container) -> token.processAsDouble(Unit.KILOMETRE, context.getParsedUnitsBehavior(), container::setA)),
42  
43      /** Mean motion. */
44      MEAN_MOTION((token, context, container) -> token.processAsDouble(Units.REV_PER_DAY, context.getParsedUnitsBehavior(), container::setMeanMotion)),
45  
46      /** Orbit eccentricity. */
47      ECCENTRICITY((token, context, container) -> token.processAsDouble(Unit.ONE, context.getParsedUnitsBehavior(), container::setE)),
48  
49      /** Orbit inclination. */
50      INCLINATION((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(), container::setI)),
51  
52      /** Orbit right ascension of ascending node. */
53      RA_OF_ASC_NODE((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(), container::setRaan)),
54  
55      /** Orbit argument of pericenter. */
56      ARG_OF_PERICENTER((token, context, container) -> token.processAsDouble(Unit.DEGREE, context.getParsedUnitsBehavior(), container::setPa)),
57  
58      /** Orbit true anomaly. */
59      TRUE_ANOMALY((token, context, container) -> {
60          if (token.getType() == TokenType.ENTRY) {
61              final double angle = context.
62                                   getParsedUnitsBehavior().
63                                   select(token.getUnits(), Unit.DEGREE).
64                                   toSI(token.getContentAsDouble());
65              container.setAnomaly(angle);
66              container.setAnomalyType(PositionAngleType.TRUE);
67          }
68          return true;
69      }),
70  
71      /** Orbit mean anomaly. */
72      MEAN_ANOMALY((token, context, container) -> {
73          if (token.getType() == TokenType.ENTRY) {
74              final double angle = context.
75                                   getParsedUnitsBehavior().
76                                   select(token.getUnits(), Unit.DEGREE).
77                                   toSI(token.getContentAsDouble());
78              container.setAnomaly(angle);
79              container.setAnomalyType(PositionAngleType.MEAN);
80          }
81          return true;
82      }),
83  
84      /** Gravitational coefficient. */
85      GM((token, context, container) -> token.processAsDouble(Units.KM3_PER_S2, context.getParsedUnitsBehavior(), container::setMu));
86  
87      /** Processing method. */
88      private final transient TokenProcessor processor;
89  
90      /** Simple constructor.
91       * @param processor processing method
92       */
93      KeplerianElementsKey(final TokenProcessor processor) {
94          this.processor = processor;
95      }
96  
97      /** Process one token.
98       * @param token token to process
99       * @param context context binding
100      * @param container container to fill
101      * @return true of token was accepted
102      */
103     public boolean process(final ParseToken token, final ContextBinding context, final KeplerianElements container) {
104         return processor.process(token, context, container);
105     }
106 
107     /** Interface for processing one token. */
108     interface TokenProcessor {
109         /** Process one token.
110          * @param token token to process
111          * @param context context binding
112          * @param container container to fill
113          * @return true of token was accepted
114          */
115         boolean process(ParseToken token, ContextBinding context, KeplerianElements container);
116     }
117 
118 }