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.omm;
19  
20  import java.util.Optional;
21  
22  import org.orekit.annotation.Nullable;
23  import org.orekit.errors.OrekitException;
24  import org.orekit.errors.OrekitMessages;
25  import org.orekit.files.ccsds.ndm.odm.CartesianCovariance;
26  import org.orekit.files.ccsds.ndm.odm.KeplerianElements;
27  import org.orekit.files.ccsds.ndm.odm.KeplerianElementsKey;
28  import org.orekit.files.ccsds.ndm.odm.SpacecraftParameters;
29  import org.orekit.files.ccsds.ndm.odm.UserDefined;
30  import org.orekit.files.ccsds.section.Data;
31  
32  /**
33   * Container for Orbit Mean-elements Message data.
34   * @author Luc Maisonobe
35   * @since 11.0
36   */
37  public class OmmData implements Data {
38  
39      /** Keplerian elements block. */
40      private final KeplerianElements keplerianElementsBlock;
41  
42      /** Spacecraft parameters block. */
43      @Nullable
44      private final SpacecraftParameters spacecraftParameters;
45  
46      /** TLE block. */
47      @Nullable
48      private final OmmTle tleBlock;
49  
50      /** Covariance matrix logical block being read. */
51      @Nullable
52      private final CartesianCovariance covarianceBlock;
53  
54      /** User defined parameters. */
55      @Nullable
56      private final UserDefined userDefinedBlock;
57  
58      /** Mass. */
59      private final double mass;
60  
61      /** Simple constructor.
62       * @param keplerianElementsBlock Keplerian elements logical block
63       * @param spacecraftParameters spacecraft parameters logical block (may be null)
64       * @param tleBlock TLE logical block (may be null)
65       * @param covarianceBlock covariance matrix logical block (may be null)
66       * @param userDefinedBlock user-defined logical block
67       * @param mass mass (always defined, even if there is no {@code spacecraftParameters} block
68       */
69      public OmmData(final KeplerianElements keplerianElementsBlock,
70                     final SpacecraftParameters spacecraftParameters,
71                     final OmmTle tleBlock,
72                     final CartesianCovariance covarianceBlock,
73                     final UserDefined userDefinedBlock,
74                     final double mass) {
75          this.keplerianElementsBlock = keplerianElementsBlock;
76          this.spacecraftParameters   = spacecraftParameters;
77          this.tleBlock               = tleBlock;
78          this.covarianceBlock        = covarianceBlock;
79          this.userDefinedBlock       = userDefinedBlock;
80          this.mass                   = mass;
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      public void validate(final double version) {
86          if (keplerianElementsBlock == null) {
87              throw new OrekitException(OrekitMessages.UNINITIALIZED_VALUE_FOR_KEY,
88                                        KeplerianElementsKey.EPOCH);
89          }
90          keplerianElementsBlock.validate(version);
91          if (spacecraftParameters != null) {
92              spacecraftParameters.validate(version);
93          }
94          if (tleBlock == null) {
95              // semi-major axis was not checked above, we do it now
96              keplerianElementsBlock.checkNotNaN(keplerianElementsBlock.getA().orElse(Double.NaN),
97                                                 KeplerianElementsKey.SEMI_MAJOR_AXIS.name());
98          } else {
99              // in OMM with TLE block, only mean motion is allowed, not semi-major axis
100             keplerianElementsBlock.checkNotNaN(keplerianElementsBlock.getMeanMotion().orElse(Double.NaN),
101                                                KeplerianElementsKey.MEAN_MOTION.name());
102             tleBlock.validate(version);
103         }
104         if (covarianceBlock != null) {
105             covarianceBlock.setEpoch(keplerianElementsBlock.getEpoch());
106             covarianceBlock.validate(version);
107         }
108         if (userDefinedBlock != null) {
109             userDefinedBlock.validate(version);
110         }
111     }
112 
113     /** Get the Keplerian elements logical block.
114      * @return Keplerian elements block
115      */
116     public KeplerianElements getKeplerianElementsBlock() {
117         return keplerianElementsBlock;
118     }
119 
120     /** Get the spacecraft parameters logical block.
121      * @return spacecraft parameters block
122      */
123     public Optional<SpacecraftParameters> getSpacecraftParametersBlock() {
124         return Optional.ofNullable(spacecraftParameters);
125     }
126 
127     /** Get the TLE logical block.
128      * @return TLE block
129      */
130     public Optional<OmmTle> getTLEBlock() {
131         return Optional.ofNullable(tleBlock);
132     }
133 
134     /** Get the covariance matrix logical block.
135      * @return covariance matrix block
136      */
137     public Optional<CartesianCovariance> getCovarianceBlock() {
138         return Optional.ofNullable(covarianceBlock);
139     }
140 
141     /** Get the user defined parameters logical block.
142      * @return user defined parameters block
143      */
144     public Optional<UserDefined> getUserDefinedBlock() {
145         return Optional.ofNullable(userDefinedBlock);
146     }
147 
148     /** Get the mass.
149      * @return mass
150      */
151     public double getMass() {
152         return mass;
153     }
154 
155 }