CommonMetadata.java

  1. /* Copyright 2002-2022 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;

  18. import org.orekit.bodies.CelestialBodyFactory;
  19. import org.orekit.errors.OrekitException;
  20. import org.orekit.errors.OrekitMessages;
  21. import org.orekit.files.ccsds.definitions.BodyFacade;
  22. import org.orekit.files.ccsds.definitions.CelestialBodyFrame;
  23. import org.orekit.files.ccsds.definitions.FrameFacade;
  24. import org.orekit.files.ccsds.definitions.ModifiedFrame;
  25. import org.orekit.files.ccsds.utils.ContextBinding;
  26. import org.orekit.frames.Frame;
  27. import org.orekit.time.AbsoluteDate;

  28. /** Common metadata for Orbit Parameter/Ephemeris/Mean Messages.
  29.  * @author Luc Maisonobe
  30.  * @since 11.0
  31.  */
  32. public class CommonMetadata extends OdmMetadata {

  33.     /** Object identifier of the object for which the orbit state is provided. */
  34.     private String objectID;

  35.     /** Origin of reference frame. */
  36.     private BodyFacade center;

  37.     /** Reference frame in which data are given: used for state vector
  38.      * and Keplerian elements data (and for the covariance reference frame if none is given). */
  39.     private FrameFacade referenceFrame;

  40.     /** Epoch of reference frame, if not intrinsic to the definition of the
  41.      * reference frame. */
  42.     private String frameEpochString;

  43.     /** Epoch of reference frame, if not intrinsic to the definition of the
  44.      * reference frame. */
  45.     private AbsoluteDate frameEpoch;

  46.     /** Simple constructor.
  47.      */
  48.     public CommonMetadata() {
  49.         super(null);
  50.     }

  51.     /** {@inheritDoc} */
  52.     @Override
  53.     public void validate(final double version) {
  54.         super.validate(version);
  55.         checkNotNull(getObjectName(), OdmMetadataKey.OBJECT_NAME);
  56.         checkNotNull(objectID,        CommonMetadataKey.OBJECT_ID);
  57.         checkNotNull(center,          CommonMetadataKey.CENTER_NAME);
  58.         checkNotNull(referenceFrame,  CommonMetadataKey.REF_FRAME);
  59.     }

  60.     /** Finalize the metadata.
  61.      * <p>
  62.      * ODM standard enforces {@code TIME_SYSTEM} to appear *after*
  63.      * {@code REF_FRAME_EPOCH}, despite it is needed to interpret it.
  64.      * We have to wait until parsing end to finalize this date.
  65.      * <p>
  66.      * @param context context binding
  67.      */
  68.     public void finalizeMetadata(final ContextBinding context) {
  69.         if (frameEpochString != null) {
  70.             frameEpoch = context.getTimeSystem().getConverter(context).parse(frameEpochString);
  71.         }
  72.     }

  73.     /** Get the spacecraft ID for which the orbit state is provided.
  74.      * @return the spacecraft ID
  75.      */
  76.     public String getObjectID() {
  77.         return objectID;
  78.     }

  79.     /** Set the spacecraft ID for which the orbit state is provided.
  80.      * @param objectID the spacecraft ID to be set
  81.      */
  82.     public void setObjectID(final String objectID) {
  83.         refuseFurtherComments();
  84.         this.objectID = objectID;
  85.     }

  86.     /** Get the launch year.
  87.      * @return launch year
  88.      */
  89.     public int getLaunchYear() {
  90.         return getLaunchYear(objectID);
  91.     }

  92.     /** Get the launch number.
  93.      * @return launch number
  94.      */
  95.     public int getLaunchNumber() {
  96.         return getLaunchNumber(objectID);
  97.     }

  98.     /** Get the piece of launch.
  99.      * @return piece of launch
  100.      */
  101.     public String getLaunchPiece() {
  102.         return getLaunchPiece(objectID);
  103.     }

  104.     /** Get the origin of reference frame.
  105.      * @return the origin of reference frame.
  106.      */
  107.     public BodyFacade getCenter() {
  108.         return center;
  109.     }

  110.     /** Set the origin of reference frame.
  111.      * @param center origin of reference frame to be set
  112.      */
  113.     public void setCenter(final BodyFacade center) {
  114.         refuseFurtherComments();
  115.         this.center = center;
  116.     }

  117.     /**
  118.      * Get the reference frame in which data are given: used for state vector and
  119.      * Keplerian elements data (and for the covariance reference frame if none is given).
  120.      *
  121.      * @return the reference frame
  122.      */
  123.     public Frame getFrame() {
  124.         if (center.getBody() == null) {
  125.             throw new OrekitException(OrekitMessages.NO_DATA_LOADED_FOR_CELESTIAL_BODY, center.getName());
  126.         }
  127.         if (referenceFrame.asFrame() == null) {
  128.             throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME, referenceFrame.getName());
  129.         }
  130.         // Just return frame if we don't need to shift the center based on CENTER_NAME
  131.         // MCI and ICRF are the only non-Earth centered frames specified in Annex A.
  132.         final boolean isMci  = referenceFrame.asCelestialBodyFrame() == CelestialBodyFrame.MCI;
  133.         final boolean isIcrf = referenceFrame.asCelestialBodyFrame() == CelestialBodyFrame.ICRF;
  134.         final boolean isSolarSystemBarycenter =
  135.                 CelestialBodyFactory.SOLAR_SYSTEM_BARYCENTER.equals(center.getBody().getName());
  136.         if (!(isMci || isIcrf) && CelestialBodyFactory.EARTH.equals(center.getBody().getName()) ||
  137.             isMci && CelestialBodyFactory.MARS.equals(center.getBody().getName()) ||
  138.             isIcrf && isSolarSystemBarycenter) {
  139.             return referenceFrame.asFrame();
  140.         }
  141.         // else, translate frame to specified center.
  142.         return new ModifiedFrame(referenceFrame.asFrame(), referenceFrame.asCelestialBodyFrame(),
  143.                                  center.getBody(), center.getName());
  144.     }

  145.     /**
  146.      * Get the value of {@code REF_FRAME} as an Orekit {@link Frame}. The {@code
  147.      * CENTER_NAME} key word has not been applied yet, so the returned frame may not
  148.      * correspond to the reference frame of the data in the file.
  149.      *
  150.      * @return The reference frame specified by the {@code REF_FRAME} keyword.
  151.      * @see #getFrame()
  152.      */
  153.     public FrameFacade getReferenceFrame() {
  154.         return referenceFrame;
  155.     }

  156.     /** Set the reference frame in which data are given: used for state vector
  157.      * and Keplerian elements data (and for the covariance reference frame if none is given).
  158.      * @param referenceFrame the reference frame to be set
  159.      */
  160.     public void setReferenceFrame(final FrameFacade referenceFrame) {
  161.         refuseFurtherComments();
  162.         this.referenceFrame = referenceFrame;
  163.     }

  164.     /** Set epoch of reference frame, if not intrinsic to the definition of the
  165.      * reference frame.
  166.      * @param frameEpochString the epoch of reference frame to be set
  167.      */
  168.     public void setFrameEpochString(final String frameEpochString) {
  169.         refuseFurtherComments();
  170.         this.frameEpochString = frameEpochString;
  171.     }

  172.     /** Get epoch of reference frame, if not intrinsic to the definition of the
  173.      * reference frame.
  174.      * @return epoch of reference frame
  175.      */
  176.     public AbsoluteDate getFrameEpoch() {
  177.         return frameEpoch;
  178.     }

  179.     /** Set epoch of reference frame, if not intrinsic to the definition of the
  180.      * reference frame.
  181.      * @param frameEpoch the epoch of reference frame to be set
  182.      */
  183.     public void setFrameEpoch(final AbsoluteDate frameEpoch) {
  184.         refuseFurtherComments();
  185.         this.frameEpoch = frameEpoch;
  186.     }

  187. }