1 /* Copyright 2002-2026 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
18 package org.orekit.files.ccsds.ndm.odm;
19
20 import java.util.Optional;
21
22 import org.orekit.annotation.Nullable;
23 import org.orekit.files.ccsds.definitions.BodyFacade;
24 import org.orekit.files.ccsds.definitions.CcsdsFrameMapper;
25 import org.orekit.files.ccsds.definitions.FrameFacade;
26 import org.orekit.files.ccsds.utils.ContextBinding;
27 import org.orekit.frames.Frame;
28 import org.orekit.time.AbsoluteDate;
29
30 /** Common metadata for Orbit Parameter/Ephemeris/Mean Messages.
31 * @author Luc Maisonobe
32 * @since 11.0
33 */
34 public class OdmCommonMetadata extends OdmMetadata {
35
36 /** Object identifier of the object for which the orbit state is provided. */
37 private String objectID;
38
39 /** Origin of reference frame. */
40 private BodyFacade center;
41
42 /** Reference frame in which data are given: used for state vector
43 * and Keplerian elements data (and for the covariance reference frame if none is given). */
44 private FrameFacade referenceFrame;
45
46 /** Epoch of reference frame, if not intrinsic to the definition of the
47 * reference frame. */
48 @Nullable
49 private String frameEpochString;
50
51 /** Epoch of reference frame, if not intrinsic to the definition of the
52 * reference frame. */
53 @Nullable
54 private AbsoluteDate frameEpoch;
55
56 /**
57 * Complete constructor.
58 *
59 * @param frameMapper for creating an Orekit {@link Frame}.
60 * @since 13.1.5
61 */
62 public OdmCommonMetadata(final CcsdsFrameMapper frameMapper) {
63 super(null, frameMapper);
64 }
65
66 /** {@inheritDoc} */
67 @Override
68 public void validate(final double version) {
69 super.validate(version);
70 checkNotNull(getObjectName(), OdmMetadataKey.OBJECT_NAME.name());
71 checkNotNull(objectID, CommonMetadataKey.OBJECT_ID.name());
72 checkNotNull(center, CommonMetadataKey.CENTER_NAME.name());
73 checkNotNull(referenceFrame, CommonMetadataKey.REF_FRAME.name());
74 }
75
76 /** Finalize the metadata.
77 * <p>
78 * ODM standard enforces {@code TIME_SYSTEM} to appear *after*
79 * {@code REF_FRAME_EPOCH}, despite it is needed to interpret it.
80 * We have to wait until parsing end to finalize this date.
81 * </p>
82 * @param context context binding
83 */
84 public void finalizeMetadata(final ContextBinding context) {
85 if (frameEpochString != null) {
86 frameEpoch = context.getTimeSystem().getConverter(context).parse(frameEpochString);
87 }
88 }
89
90 /** Get the spacecraft ID for which the orbit state is provided.
91 * @return the spacecraft ID
92 */
93 public String getObjectID() {
94 return objectID;
95 }
96
97 /** Set the spacecraft ID for which the orbit state is provided.
98 * @param objectID the spacecraft ID to be set
99 */
100 public void setObjectID(final String objectID) {
101 refuseFurtherComments();
102 this.objectID = objectID;
103 }
104
105 /** Get the launch year.
106 * @return launch year
107 */
108 public int getLaunchYear() {
109 return getLaunchYear(objectID);
110 }
111
112 /** Get the launch number.
113 * @return launch number
114 */
115 public int getLaunchNumber() {
116 return getLaunchNumber(objectID);
117 }
118
119 /** Get the piece of launch.
120 * @return piece of launch
121 */
122 public String getLaunchPiece() {
123 return getLaunchPiece(objectID);
124 }
125
126 /** Get the origin of reference frame.
127 * @return the origin of reference frame.
128 */
129 public BodyFacade getCenter() {
130 return center;
131 }
132
133 /** Set the origin of reference frame.
134 * @param center origin of reference frame to be set
135 */
136 public void setCenter(final BodyFacade center) {
137 refuseFurtherComments();
138 this.center = center;
139 }
140
141 /**
142 * Get the reference frame in which data are given: used for state vector and
143 * Keplerian elements data (and for the covariance reference frame if none is given).
144 *
145 * @return the reference frame
146 * @see #getFrameMapper()
147 */
148 public Frame getFrame() {
149 return getFrameMapper().buildCcsdsFrame(center, referenceFrame, frameEpoch);
150 }
151
152 /**
153 * Get the value of {@code REF_FRAME} as an Orekit {@link Frame}. The {@code
154 * CENTER_NAME} key word has not been applied yet, so the returned frame may not
155 * correspond to the reference frame of the data in the file.
156 *
157 * @return The reference frame specified by the {@code REF_FRAME} keyword.
158 * @see #getFrame()
159 */
160 public FrameFacade getReferenceFrame() {
161 return referenceFrame;
162 }
163
164 /** Set the reference frame in which data are given: used for state vector
165 * and Keplerian elements data (and for the covariance reference frame if none is given).
166 * @param referenceFrame the reference frame to be set
167 */
168 public void setReferenceFrame(final FrameFacade referenceFrame) {
169 refuseFurtherComments();
170 this.referenceFrame = referenceFrame;
171 }
172
173 /** Set epoch of reference frame, if not intrinsic to the definition of the
174 * reference frame.
175 * @param frameEpochString the epoch of reference frame to be set
176 */
177 public void setFrameEpochString(final String frameEpochString) {
178 refuseFurtherComments();
179 this.frameEpochString = frameEpochString;
180 }
181
182 /** Get epoch of reference frame, if not intrinsic to the definition of the
183 * reference frame.
184 * @return epoch of reference frame
185 */
186 public Optional<AbsoluteDate> getFrameEpoch() {
187 return Optional.ofNullable(frameEpoch);
188 }
189
190 /** Set epoch of reference frame, if not intrinsic to the definition of the
191 * reference frame.
192 * @param frameEpoch the epoch of reference frame to be set
193 */
194 public void setFrameEpoch(final AbsoluteDate frameEpoch) {
195 refuseFurtherComments();
196 this.frameEpoch = frameEpoch;
197 }
198
199 }