1 /* Copyright 2002-2021 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.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 import org.orekit.utils.units.Unit;
24
25 /** Keys for {@link ApmQuaternion APM quaternion} entries.
26 * @author Bryan Cazabonne
27 * @since 10.2
28 */
29 public enum ApmQuaternionKey {
30
31 /** Quaternion wrapping element in XML files. */
32 quaternion((token, context, container) -> true),
33
34 /** Quaternion wrapping element in XML files. */
35 quaternionRate((token, context, container) -> true),
36
37 /** Epoch entry. */
38 EPOCH((token, context, container) -> token.processAsDate(container::setEpoch, context)),
39
40 /** First reference frame entry. */
41 Q_FRAME_A((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameA, context, true, true, true)),
42
43 /** Second reference frame entry. */
44 Q_FRAME_B((token, context, container) -> token.processAsFrame(container.getEndpoints()::setFrameB, context, true, true, true)),
45
46 /** Rotation direction entry. */
47 Q_DIR((token, context, container) -> {
48 if (token.getType() == TokenType.ENTRY) {
49 container.getEndpoints().setA2b(token.getContentAsUppercaseCharacter() == 'A');
50 }
51 return true;
52 }),
53
54 /** Scalar part of the quaternion entry. */
55 QC((token, context, container) -> token.processAsIndexedDouble(0, Unit.ONE, context.getParsedUnitsBehavior(),
56 container::setQ)),
57
58 /** First component of the vector part of the quaternion entry. */
59 Q1((token, context, container) -> token.processAsIndexedDouble(1, Unit.ONE, context.getParsedUnitsBehavior(),
60 container::setQ)),
61
62 /** Second component of the vector part of the quaternion entry. */
63 Q2((token, context, container) -> token.processAsIndexedDouble(2, Unit.ONE, context.getParsedUnitsBehavior(),
64 container::setQ)),
65
66 /** Third component of the vector part of the quaternion entry. */
67 Q3((token, context, container) -> token.processAsIndexedDouble(3, Unit.ONE, context.getParsedUnitsBehavior(),
68 container::setQ)),
69
70 /** Scalar part of the quaternion derivative entry. */
71 QC_DOT((token, context, container) -> token.processAsIndexedDouble(0, Units.ONE_PER_S, context.getParsedUnitsBehavior(),
72 container::setQDot)),
73
74 /** First component of the vector part of the quaternion derivative entry. */
75 Q1_DOT((token, context, container) -> token.processAsIndexedDouble(1, Units.ONE_PER_S, context.getParsedUnitsBehavior(),
76 container::setQDot)),
77
78 /** Second component of the vector part of the quaternion derivative entry. */
79 Q2_DOT((token, context, container) -> token.processAsIndexedDouble(2, Units.ONE_PER_S, context.getParsedUnitsBehavior(),
80 container::setQDot)),
81
82 /** Third component of the vector part of the quaternion derivative entry. */
83 Q3_DOT((token, context, container) -> token.processAsIndexedDouble(3, Units.ONE_PER_S, context.getParsedUnitsBehavior(),
84 container::setQDot));
85
86 /** Processing method. */
87 private final TokenProcessor processor;
88
89 /** Simple constructor.
90 * @param processor processing method
91 */
92 ApmQuaternionKey(final TokenProcessor processor) {
93 this.processor = processor;
94 }
95
96 /** Process one token.
97 * @param token token to process
98 * @param context context binding
99 * @param container container to fill
100 * @return true of token was accepted
101 */
102 public boolean process(final ParseToken token, final ContextBinding context, final ApmQuaternion container) {
103 return processor.process(token, context, container);
104 }
105
106 /** Interface for processing one token. */
107 interface TokenProcessor {
108 /** Process one token.
109 * @param token token to process
110 * @param context context binding
111 * @param container container to fill
112 * @return true of token was accepted
113 */
114 boolean process(ParseToken token, ContextBinding context, ApmQuaternion container);
115 }
116
117 }