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
18 package org.orekit.files.ccsds.ndm.odm.opm;
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.CommonMetadata;
25 import org.orekit.files.ccsds.ndm.odm.KeplerianElements;
26 import org.orekit.files.ccsds.section.Header;
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.time.AbsoluteDate;
32 import org.orekit.time.TimeStamped;
33 import org.orekit.utils.IERSConventions;
34 import org.orekit.utils.TimeStampedPVCoordinates;
35
36 /** This class gathers the informations present in the Orbital Parameter Message (OPM).
37 * @author sports
38 * @since 6.1
39 */
40 public class Opm extends NdmConstituent<Header, Segment<CommonMetadata, OpmData>> implements TimeStamped {
41
42 /** Root element for XML files. */
43 public static final String ROOT = "opm";
44
45 /** Key for format version. */
46 public static final String FORMAT_VERSION_KEY = "CCSDS_OPM_VERS";
47
48 /** Gravitational coefficient to use for building Cartesian/Keplerian orbits. */
49 private final double mu;
50
51 /** Simple constructor.
52 * @param header file header
53 * @param segments file segments
54 * @param conventions IERS conventions
55 * @param dataContext used for creating frames, time scales, etc.
56 * @param mu gravitational coefficient to use for building Cartesian/Keplerian orbits
57 */
58 public Opm(final Header header, final List<Segment<CommonMetadata, OpmData>> segments,
59 final IERSConventions conventions, final DataContext dataContext,
60 final double mu) {
61 super(header, segments, conventions, dataContext);
62 this.mu = mu;
63 }
64
65 /** Get the file metadata.
66 * @return file metadata
67 */
68 public CommonMetadata getMetadata() {
69 return getSegments().get(0).getMetadata();
70 }
71
72 /** Get the file data.
73 * @return file data
74 */
75 public OpmData getData() {
76 return getSegments().get(0).getData();
77 }
78
79 /** {@inheritDoc} */
80 @Override
81 public AbsoluteDate getDate() {
82 return getData().getStateVectorBlock().getEpoch();
83 }
84
85 /** Get the number of maneuvers present in the OPM.
86 * @return the number of maneuvers
87 */
88 public int getNbManeuvers() {
89 return getData().getNbManeuvers();
90 }
91
92 /** Get a list of all maneuvers.
93 * @return unmodifiable list of all maneuvers.
94 */
95 public List<Maneuver> getManeuvers() {
96 return getData().getManeuvers();
97 }
98
99 /** Get a maneuver.
100 * @param index maneuver index, counting from 0
101 * @return maneuver
102 */
103 public Maneuver getManeuver(final int index) {
104 return getData().getManeuver(index);
105 }
106
107 /** check whether the OPM contains at least one maneuver.
108 * @return true if OPM contains at least one maneuver false otherwise
109 */
110 public boolean hasManeuvers() {
111 return getData().hasManeuvers();
112 }
113
114 /** Get the position/velocity coordinates contained in the OPM.
115 * @return the position/velocity coordinates contained in the OPM
116 */
117 public TimeStampedPVCoordinates getPVCoordinates() {
118 return getData().getStateVectorBlock().toTimeStampedPVCoordinates();
119 }
120
121 /** Generate a Cartesian orbit.
122 * @return generated orbit
123 */
124 public CartesianOrbit generateCartesianOrbit() {
125 return new CartesianOrbit(getPVCoordinates(), getMetadata().getFrame(),
126 getData().getStateVectorBlock().getEpoch(),
127 mu);
128 }
129
130 /** Generate a keplerian orbit.
131 * @return generated orbit
132 */
133 public KeplerianOrbit generateKeplerianOrbit() {
134 final CommonMetadata metadata = getMetadata();
135 final OpmData data = getData();
136 final KeplerianElements keplerianElements = data.getKeplerianElementsBlock();
137 if (keplerianElements != null) {
138 return keplerianElements.generateKeplerianOrbit(metadata.getFrame());
139 } else {
140 return new KeplerianOrbit(getPVCoordinates(), metadata.getFrame(),
141 data.getStateVectorBlock().getEpoch(),
142 mu);
143 }
144 }
145
146 /** Generate spacecraft state from the {@link CartesianOrbit} generated by generateCartesianOrbit.
147 * @return the spacecraft state of the OPM
148 */
149 public SpacecraftState generateSpacecraftState() {
150 return new SpacecraftState(generateCartesianOrbit(), getData().getMass());
151 }
152
153 }
154