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.opm;
18  
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.orekit.files.ccsds.ndm.odm.CartesianCovariance;
23  import org.orekit.files.ccsds.ndm.odm.KeplerianElements;
24  import org.orekit.files.ccsds.ndm.odm.KeplerianElementsKey;
25  import org.orekit.files.ccsds.ndm.odm.SpacecraftParameters;
26  import org.orekit.files.ccsds.ndm.odm.StateVector;
27  import org.orekit.files.ccsds.ndm.odm.UserDefined;
28  import org.orekit.files.ccsds.section.Data;
29  
30  /**
31   * Container for Orbit Parameter Message data.
32   * @author Luc Maisonobe
33   * @since 11.0
34   */
35  public class OpmData implements Data {
36  
37      /** State vector block. */
38      private final  StateVector stateVectorBlock;
39  
40      /** Keplerian elements block. */
41      private final KeplerianElements keplerianElementsBlock;
42  
43      /** Spacecraft parameters block. */
44      private final SpacecraftParameters spacecraftParametersBlock;
45  
46      /** Covariance matrix logical block being read. */
47      private final CartesianCovariance covarianceBlock;
48  
49      /** Maneuvers. */
50      private final List<Maneuver> maneuverBlocks;
51  
52      /** User defined parameters. */
53      private final UserDefined userDefinedBlock;
54  
55      /** Mass. */
56      private final double mass;
57  
58      /** Simple constructor.
59       * @param stateVectorBlock state vector logical block
60       * @param keplerianElementsBlock Keplerian elements logical block (may be null)
61       * @param spacecraftParametersBlock spacecraft parameters logical block (may be null)
62       * @param covarianceBlock covariance matrix logical block (may be null)
63       * @param maneuverBlocks maneuvers block list
64       * @param userDefinedBlock user-defined logical block
65       * @param mass mass (always defined, even if there is no {@code spacecraftParameters} block
66       */
67      public OpmData(final StateVector stateVectorBlock,
68                     final KeplerianElements keplerianElementsBlock,
69                     final SpacecraftParameters spacecraftParametersBlock,
70                     final CartesianCovariance covarianceBlock,
71                     final List<Maneuver> maneuverBlocks,
72                     final UserDefined userDefinedBlock,
73                     final double mass) {
74          this.stateVectorBlock          = stateVectorBlock;
75          this.keplerianElementsBlock    = keplerianElementsBlock;
76          this.spacecraftParametersBlock = spacecraftParametersBlock;
77          this.covarianceBlock           = covarianceBlock;
78          this.maneuverBlocks            = maneuverBlocks;
79          this.userDefinedBlock          = userDefinedBlock;
80          this.mass                      = mass;
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      public void validate(final double version) {
86          stateVectorBlock.validate(version);
87          if (keplerianElementsBlock != null) {
88              keplerianElementsBlock.validate(version);
89              // in OPM, only semi-major axis is allowed, not mean motion
90              keplerianElementsBlock.checkNotNaN(keplerianElementsBlock.getA(),
91                                                 KeplerianElementsKey.SEMI_MAJOR_AXIS.name());
92          }
93          if (spacecraftParametersBlock != null) {
94              spacecraftParametersBlock.validate(version);
95          }
96          if (covarianceBlock != null) {
97              covarianceBlock.setEpoch(stateVectorBlock.getEpoch());
98              covarianceBlock.validate(version);
99          }
100         for (final Maneuver maneuver : maneuverBlocks) {
101             maneuver.validate(version);
102         }
103         if (userDefinedBlock != null) {
104             userDefinedBlock.validate(version);
105         }
106     }
107 
108     /** Get the state vector logical block.
109      * @return state vector block
110      */
111     public StateVector getStateVectorBlock() {
112         return stateVectorBlock;
113     }
114 
115     /** Get the Keplerian elements logical block.
116      * @return Keplerian elements block (may be null)
117      */
118     public KeplerianElements getKeplerianElementsBlock() {
119         return keplerianElementsBlock;
120     }
121 
122     /** Get the spacecraft parameters logical block.
123      * @return spacecraft parameters block (may be null)
124      */
125     public SpacecraftParameters getSpacecraftParametersBlock() {
126         return spacecraftParametersBlock;
127     }
128 
129     /** Get the covariance matrix logical block.
130      * @return covariance matrix block (may be null)
131      */
132     public CartesianCovariance getCovarianceBlock() {
133         return covarianceBlock;
134     }
135 
136     /** Get the mass.
137      * @return mass
138      */
139     public double getMass() {
140         return mass;
141     }
142 
143     /**
144      * Get the number of maneuvers present in the APM.
145      * @return the number of maneuvers
146      */
147     public int getNbManeuvers() {
148         return maneuverBlocks.size();
149     }
150 
151     /**
152      * Get a list of all maneuvers.
153      * @return unmodifiable list of all maneuvers.
154      */
155     public List<Maneuver> getManeuvers() {
156         return Collections.unmodifiableList(maneuverBlocks);
157     }
158 
159     /**
160      * Get a maneuver.
161      * @param index maneuver index, counting from 0
162      * @return maneuver
163      */
164     public Maneuver getManeuver(final int index) {
165         return maneuverBlocks.get(index);
166     }
167 
168     /**
169      * Get boolean testing whether the APM contains at least one maneuver.
170      * @return true if APM contains at least one maneuver
171      *         false otherwise
172      */
173     public boolean hasManeuvers() {
174         return !maneuverBlocks.isEmpty();
175     }
176 
177     /** Get the user defined parameters logical block.
178      * @return user defined parameters block (may be null)
179      */
180     public UserDefined getUserDefinedBlock() {
181         return userDefinedBlock;
182     }
183 
184 }