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  
18  package org.orekit.files.ccsds.ndm.odm.omm;
19  
20  import java.util.List;
21  
22  import org.orekit.data.DataContext;
23  import org.orekit.files.ccsds.ndm.NdmConstituent;
24  import org.orekit.files.ccsds.ndm.odm.OdmCommonMetadata;
25  import org.orekit.files.ccsds.ndm.odm.KeplerianElements;
26  import org.orekit.files.ccsds.ndm.odm.OdmHeader;
27  import org.orekit.files.ccsds.section.Segment;
28  import org.orekit.orbits.CartesianOrbit;
29  import org.orekit.orbits.KeplerianOrbit;
30  import org.orekit.propagation.SpacecraftState;
31  import org.orekit.propagation.analytical.tle.TLE;
32  import org.orekit.time.AbsoluteDate;
33  import org.orekit.time.TimeStamped;
34  import org.orekit.utils.IERSConventions;
35  
36  /**
37   * This class gathers the informations present in the Orbital Mean-Elements Message (OMM).
38   * @author sports
39   * @since 6.1
40   */
41  public class Omm extends NdmConstituent<OdmHeader, Segment<OmmMetadata, OmmData>> implements TimeStamped {
42  
43      /** Root element for XML files. */
44      public static final String ROOT = "omm";
45  
46      /** Key for format version. */
47      public static final String FORMAT_VERSION_KEY = "CCSDS_OMM_VERS";
48  
49      /** Simple constructor.
50       * @param header file header
51       * @param segments file segments
52       * @param conventions IERS conventions
53       * @param dataContext used for creating frames, time scales, etc.
54       */
55      public Omm(final OdmHeader header, final List<Segment<OmmMetadata, OmmData>> segments,
56                 final IERSConventions conventions, final DataContext dataContext) {
57          super(header, segments, conventions, dataContext);
58      }
59  
60      /** Get the file metadata.
61       * @return file metadata
62       */
63      public OmmMetadata getMetadata() {
64          return getSegments().get(0).getMetadata();
65      }
66  
67      /** Get the file data.
68       * @return file data
69       */
70      public OmmData getData() {
71          return getSegments().get(0).getData();
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public AbsoluteDate getDate() {
77          return getData().getKeplerianElementsBlock().getEpoch();
78      }
79  
80      /** Generate a keplerian orbit.
81       * @return generated orbit
82       */
83      public KeplerianOrbit generateKeplerianOrbit() {
84          return getData().getKeplerianElementsBlock().generateKeplerianOrbit(getMetadata().getFrame());
85      }
86  
87      /** Generate spacecraft state from the {@link CartesianOrbit} generated by generateCartesianOrbit.
88       *  Raises an exception if OPM doesn't contain spacecraft mass information.
89       * @return the spacecraft state of the OPM
90       */
91      public SpacecraftState generateSpacecraftState() {
92          return new SpacecraftState(generateKeplerianOrbit()).withMass(getData().getMass());
93      }
94  
95      /** Generate TLE from OMM file. Launch Year, Launch Day and Launch Piece are not present in the
96       * OMM file, they have to be set manually by the user with the AdditionalData static class.
97       * @return the tle
98       */
99      public TLE generateTLE() {
100         final OdmCommonMetadata metadata = getMetadata();
101         final KeplerianElements kep = getData().getKeplerianElementsBlock();
102         final OmmTle               tle = getData().getTLEBlock();
103         return new TLE(tle.getNoradID(), tle.getClassificationType(),
104                        metadata.getLaunchYear(), metadata.getLaunchNumber(), metadata.getLaunchPiece(),
105                        tle.getEphemerisType(), tle.getElementSetNumber(), kep.getEpoch(),
106                        kep.getMeanMotion(), tle.getMeanMotionDot() / 2, tle.getMeanMotionDotDot() / 6,
107                        kep.getE(), kep.getI(), kep.getPa(), kep.getRaan(),
108                        kep.getAnomaly(), tle.getRevAtEpoch(),
109                        tle.getBStar(), getDataContext().getTimeScales().getUTC());
110     }
111 
112 }