Opm.java

  1. /* Copyright 2002-2024 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. import java.util.List;

  19. import org.orekit.data.DataContext;
  20. import org.orekit.files.ccsds.ndm.NdmConstituent;
  21. import org.orekit.files.ccsds.ndm.odm.OdmCommonMetadata;
  22. import org.orekit.files.ccsds.ndm.odm.KeplerianElements;
  23. import org.orekit.files.ccsds.ndm.odm.OdmHeader;
  24. import org.orekit.files.ccsds.section.Segment;
  25. import org.orekit.orbits.CartesianOrbit;
  26. import org.orekit.orbits.KeplerianOrbit;
  27. import org.orekit.propagation.SpacecraftState;
  28. import org.orekit.time.AbsoluteDate;
  29. import org.orekit.time.TimeStamped;
  30. import org.orekit.utils.IERSConventions;
  31. import org.orekit.utils.TimeStampedPVCoordinates;

  32. /** This class gathers the informations present in the Orbital Parameter Message (OPM).
  33.  * @author sports
  34.  * @since 6.1
  35.  */
  36. public class Opm extends NdmConstituent<OdmHeader, Segment<OdmCommonMetadata, OpmData>> implements TimeStamped {

  37.     /** Root element for XML files. */
  38.     public static final String ROOT = "opm";

  39.     /** Key for format version. */
  40.     public static final String FORMAT_VERSION_KEY = "CCSDS_OPM_VERS";

  41.     /** Gravitational coefficient to use for building Cartesian/Keplerian orbits. */
  42.     private final double mu;

  43.     /** Simple constructor.
  44.      * @param header file header
  45.      * @param segments file segments
  46.      * @param conventions IERS conventions
  47.      * @param dataContext used for creating frames, time scales, etc.
  48.      * @param mu gravitational coefficient to use for building Cartesian/Keplerian orbits
  49.      */
  50.     public Opm(final OdmHeader header, final List<Segment<OdmCommonMetadata, OpmData>> segments,
  51.                final IERSConventions conventions, final DataContext dataContext,
  52.                final double mu) {
  53.         super(header, segments, conventions, dataContext);
  54.         this.mu = mu;
  55.     }

  56.     /** Get the file metadata.
  57.      * @return file metadata
  58.      */
  59.     public OdmCommonMetadata getMetadata() {
  60.         return getSegments().get(0).getMetadata();
  61.     }

  62.     /** Get the file data.
  63.      * @return file data
  64.      */
  65.     public OpmData getData() {
  66.         return getSegments().get(0).getData();
  67.     }

  68.     /** {@inheritDoc} */
  69.     @Override
  70.     public AbsoluteDate getDate() {
  71.         return getData().getStateVectorBlock().getEpoch();
  72.     }

  73.     /** Get the number of maneuvers present in the OPM.
  74.      * @return the number of maneuvers
  75.      */
  76.     public int getNbManeuvers() {
  77.         return getData().getNbManeuvers();
  78.     }

  79.     /** Get a list of all maneuvers.
  80.      * @return unmodifiable list of all maneuvers.
  81.      */
  82.     public List<Maneuver> getManeuvers() {
  83.         return getData().getManeuvers();
  84.     }

  85.     /** Get a maneuver.
  86.      * @param index maneuver index, counting from 0
  87.      * @return maneuver
  88.      */
  89.     public Maneuver getManeuver(final int index) {
  90.         return getData().getManeuver(index);
  91.     }

  92.     /** check whether the OPM contains at least one maneuver.
  93.      * @return true if OPM contains at least one maneuver false otherwise
  94.      */
  95.     public boolean hasManeuvers() {
  96.         return getData().hasManeuvers();
  97.     }

  98.     /** Get the position/velocity coordinates contained in the OPM.
  99.      * @return the position/velocity coordinates contained in the OPM
  100.      */
  101.     public TimeStampedPVCoordinates getPVCoordinates() {
  102.         return getData().getStateVectorBlock().toTimeStampedPVCoordinates();
  103.     }

  104.     /** Generate a Cartesian orbit.
  105.      * @return generated orbit
  106.      */
  107.     public CartesianOrbit generateCartesianOrbit() {
  108.         return new CartesianOrbit(getPVCoordinates(), getMetadata().getFrame(),
  109.                                   getData().getStateVectorBlock().getEpoch(),
  110.                                   mu);
  111.     }

  112.     /** Generate a keplerian orbit.
  113.      * @return generated orbit
  114.      */
  115.     public KeplerianOrbit generateKeplerianOrbit() {
  116.         final OdmCommonMetadata metadata = getMetadata();
  117.         final OpmData        data     = getData();
  118.         final KeplerianElements keplerianElements = data.getKeplerianElementsBlock();
  119.         if (keplerianElements != null) {
  120.             return keplerianElements.generateKeplerianOrbit(metadata.getFrame());
  121.         } else {
  122.             return new KeplerianOrbit(getPVCoordinates(), metadata.getFrame(),
  123.                                       data.getStateVectorBlock().getEpoch(),
  124.                                       mu);
  125.         }
  126.     }

  127.     /** Generate spacecraft state from the {@link CartesianOrbit} generated by generateCartesianOrbit.
  128.      * @return the spacecraft state of the OPM
  129.      */
  130.     public SpacecraftState generateSpacecraftState() {
  131.         return new SpacecraftState(generateCartesianOrbit(), getData().getMass());
  132.     }

  133. }