ParserBuilder.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;

  18. import org.orekit.annotation.DefaultDataContext;
  19. import org.orekit.data.DataContext;
  20. import org.orekit.files.ccsds.ndm.adm.aem.AemParser;
  21. import org.orekit.files.ccsds.ndm.adm.apm.ApmParser;
  22. import org.orekit.files.ccsds.ndm.odm.ocm.OcmParser;
  23. import org.orekit.files.ccsds.ndm.odm.oem.OemParser;
  24. import org.orekit.files.ccsds.ndm.odm.omm.OmmParser;
  25. import org.orekit.files.ccsds.ndm.odm.opm.OpmParser;
  26. import org.orekit.files.ccsds.ndm.tdm.IdentityConverter;
  27. import org.orekit.files.ccsds.ndm.tdm.RangeUnits;
  28. import org.orekit.files.ccsds.ndm.tdm.RangeUnitsConverter;
  29. import org.orekit.files.ccsds.ndm.tdm.TdmParser;
  30. import org.orekit.time.AbsoluteDate;
  31. import org.orekit.utils.IERSConventions;

  32. /** Builder for all {@link NdmConstituent CCSDS Message} files parsers.
  33.  * <p>
  34.  * This builder can be used for building all CCSDS Messages parsers types.
  35.  * It is particularly useful in multi-threaded context as parsers cannot
  36.  * be shared between threads and thus several independent parsers must be
  37.  * built in this case.
  38.  * </p>
  39.  * @author Luc Maisonobe
  40.  * @since 11.0
  41.  */
  42. public class ParserBuilder extends AbstractBuilder<ParserBuilder> {

  43.     /** Indicator for simple or accurate EOP interpolation. */
  44.     private final  boolean simpleEOP;

  45.     /** Gravitational coefficient. */
  46.     private final double mu;

  47.     /** Default mass. */
  48.     private final double defaultMass;

  49.     /** Default interpolation degree. */
  50.     private final int defaultInterpolationDegree;

  51.     /** Behavior adopted for units that have been parsed from a CCSDS message. */
  52.     private final ParsedUnitsBehavior parsedUnitsBehavior;

  53.     /**
  54.      * Simple constructor.
  55.      * <p>
  56.      * This constructor creates a builder with
  57.      * <ul>
  58.      *   <li>{@link #getConventions() IERS conventions} set to {@link IERSConventions#IERS_2010}</li>
  59.      *   <li>{@link #isSimpleEOP() simple EOP} set to {@code true}</li>
  60.      *   <li>{@link #getDataContext() data context} set to {@link DataContext#getDefault() default context}</li>
  61.      *   <li>{@link #getMissionReferenceDate() mission reference date} set to {@code null}</li>
  62.      *   <li>{@link #getMu() gravitational coefficient} set to {@code Double.NaN}</li>
  63.      *   <li>{@link #getDefaultMass() default mass} set to {@code Double.NaN}</li>
  64.      *   <li>{@link #getDefaultInterpolationDegree() default interpolation degree} set to {@code 1}</li>
  65.      *   <li>{@link #getParsedUnitsBehavior() parsed unit behavior} set to {@link ParsedUnitsBehavior#CONVERT_COMPATIBLE}</li>
  66.      *   <li>{@link #getRangeUnitsConverter() converter for range units} set to {@link IdentityConverter}</li>
  67.      * </ul>
  68.      */
  69.     @DefaultDataContext
  70.     public ParserBuilder() {
  71.         this(DataContext.getDefault());
  72.     }

  73.     /**
  74.      * Simple constructor.
  75.      * <p>
  76.      * This constructor creates a builder with
  77.      * <ul>
  78.      *   <li>{@link #getConventions() IERS conventions} set to {@link IERSConventions#IERS_2010}</li>
  79.      *   <li>{@link #isSimpleEOP() simple EOP} set to {@code true}</li>
  80.      *   <li>{@link #getMissionReferenceDate() mission reference date} set to {@code null}</li>
  81.      *   <li>{@link #getMu() gravitational coefficient} set to {@code Double.NaN}</li>
  82.      *   <li>{@link #getDefaultMass() default mass} set to {@code Double.NaN}</li>
  83.      *   <li>{@link #getDefaultInterpolationDegree() default interpolation degree} set to {@code 1}</li>
  84.      *   <li>{@link #getParsedUnitsBehavior() parsed unit behavior} set to {@link ParsedUnitsBehavior#CONVERT_COMPATIBLE}</li>
  85.      *   <li>{@link #getRangeUnitsConverter() converter for range units} set to {@link IdentityConverter}</li>
  86.      * </ul>
  87.      * @param dataContext data context used to retrieve frames, time scales, etc.
  88.      */
  89.     public ParserBuilder(final DataContext dataContext) {
  90.         this(IERSConventions.IERS_2010, dataContext, null, new IdentityConverter(),
  91.              true, Double.NaN, Double.NaN, 1, ParsedUnitsBehavior.CONVERT_COMPATIBLE);
  92.     }

  93.     /** Complete constructor.
  94.      * @param conventions IERS Conventions
  95.      * @param dataContext used to retrieve frames, time scales, etc.
  96.      * @param missionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
  97.      * @param simpleEOP if true, tidal effects are ignored when interpolating EOP
  98.      * @param mu gravitational coefficient
  99.      * @param defaultMass default mass
  100.      * @param defaultInterpolationDegree default interpolation degree
  101.      * @param parsedUnitsBehavior behavior to adopt for handling parsed units
  102.      * @param rangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
  103.      */
  104.     private ParserBuilder(final IERSConventions conventions, final DataContext dataContext,
  105.                           final AbsoluteDate missionReferenceDate,
  106.                           final RangeUnitsConverter rangeUnitsConverter,
  107.                           final boolean simpleEOP, final double mu, final double defaultMass,
  108.                           final int defaultInterpolationDegree,
  109.                           final ParsedUnitsBehavior parsedUnitsBehavior) {
  110.         super(conventions, dataContext, missionReferenceDate, rangeUnitsConverter);
  111.         this.simpleEOP                  = simpleEOP;
  112.         this.mu                         = mu;
  113.         this.defaultMass                = defaultMass;
  114.         this.defaultInterpolationDegree = defaultInterpolationDegree;
  115.         this.parsedUnitsBehavior        = parsedUnitsBehavior;
  116.     }

  117.     /** {@inheritDoc} */
  118.     @Override
  119.     protected ParserBuilder create(final IERSConventions newConventions, final DataContext newDataContext,
  120.                                    final AbsoluteDate newMissionReferenceDate, final RangeUnitsConverter newRangeUnitsConverter) {
  121.         return new ParserBuilder(newConventions, newDataContext, newMissionReferenceDate, newRangeUnitsConverter,
  122.                                  simpleEOP, mu, defaultMass, defaultInterpolationDegree, parsedUnitsBehavior);
  123.     }

  124.     /** Set up flag for ignoring tidal effects when interpolating EOP.
  125.      * @param newSimpleEOP true if tidal effects are ignored when interpolating EOP
  126.      * @return a new builder with updated configuration (the instance is not changed)
  127.      */
  128.     public ParserBuilder withSimpleEOP(final boolean newSimpleEOP) {
  129.         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
  130.                                  newSimpleEOP, getMu(), getDefaultMass(),
  131.                                  getDefaultInterpolationDegree(), getParsedUnitsBehavior());
  132.     }

  133.     /** Check if tidal effects are ignored when interpolating EOP.
  134.      * @return true if tidal effects are ignored when interpolating EOP
  135.      */
  136.     public boolean isSimpleEOP() {
  137.         return simpleEOP;
  138.     }

  139.     /** Set up the gravitational coefficient.
  140.      * @param newMu gravitational coefficient
  141.      * @return a new builder with updated configuration (the instance is not changed)
  142.      */
  143.     public ParserBuilder withMu(final double newMu) {
  144.         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
  145.                                  isSimpleEOP(), newMu, getDefaultMass(),
  146.                                  getDefaultInterpolationDegree(), getParsedUnitsBehavior());
  147.     }

  148.     /** Get the gravitational coefficient.
  149.      * @return gravitational coefficient
  150.      */
  151.     public double getMu() {
  152.         return mu;
  153.     }

  154.     /** Set up the default mass.
  155.      * <p>
  156.      * The default mass is used only by {@link OpmParser}.
  157.      * </p>
  158.      * @param newDefaultMass default mass
  159.      * @return a new builder with updated configuration (the instance is not changed)
  160.      */
  161.     public ParserBuilder withDefaultMass(final double newDefaultMass) {
  162.         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
  163.                                  isSimpleEOP(), getMu(), newDefaultMass,
  164.                                  getDefaultInterpolationDegree(), getParsedUnitsBehavior());
  165.     }

  166.     /** Get the default mass.
  167.      * @return default mass
  168.      */
  169.     public double getDefaultMass() {
  170.         return defaultMass;
  171.     }

  172.     /** Set up the default interpolation degree.
  173.      * <p>
  174.      * The default interpolation degree is used only by {@link AemParser}
  175.      * and {@link OemParser}.
  176.      * </p>
  177.      * @param newDefaultInterpolationDegree default interpolation degree
  178.      * @return a new builder with updated configuration (the instance is not changed)
  179.      */
  180.     public ParserBuilder withDefaultInterpolationDegree(final int newDefaultInterpolationDegree) {
  181.         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
  182.                                  isSimpleEOP(), getMu(), getDefaultMass(),
  183.                                  newDefaultInterpolationDegree, getParsedUnitsBehavior());
  184.     }

  185.     /** Get the default interpolation degree.
  186.      * @return default interpolation degree
  187.      */
  188.     public int getDefaultInterpolationDegree() {
  189.         return defaultInterpolationDegree;
  190.     }

  191.     /** Set up the behavior to adopt for handling parsed units.
  192.      * @param newParsedUnitsBehavior behavior to adopt for handling parsed units
  193.      * @return a new builder with updated configuration (the instance is not changed)
  194.      */
  195.     public ParserBuilder withParsedUnitsBehavior(final ParsedUnitsBehavior newParsedUnitsBehavior) {
  196.         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
  197.                                  isSimpleEOP(), getMu(), getDefaultMass(),
  198.                                  getDefaultInterpolationDegree(), newParsedUnitsBehavior);
  199.     }

  200.     /** Get the behavior to adopt for handling parsed units.
  201.      * @return behavior to adopt for handling parsed units
  202.      */
  203.     public ParsedUnitsBehavior getParsedUnitsBehavior() {
  204.         return parsedUnitsBehavior;
  205.     }

  206.     /** Build a parser for {@link org.orekit.files.ccsds.ndm.Ndm Navigation Data Messages}.
  207.      * @return a new parser
  208.      */
  209.     public NdmParser buildNdmParser() {
  210.         return new NdmParser(this);
  211.     }

  212.     /** Build a parser for {@link org.orekit.files.ccsds.ndm.odm.opm.Opm Orbit Parameters Messages}.
  213.      * @return a new parser
  214.      */
  215.     public OpmParser buildOpmParser() {
  216.         return new OpmParser(getConventions(), isSimpleEOP(), getDataContext(), getMissionReferenceDate(),
  217.                              getMu(), getDefaultMass(), getParsedUnitsBehavior());
  218.     }

  219.     /** Build a parser for {@link org.orekit.files.ccsds.ndm.odm.omm.Omm Orbit Mean elements Messages}.
  220.      * @return a new parser
  221.      */
  222.     public OmmParser buildOmmParser() {
  223.         return new OmmParser(getConventions(), isSimpleEOP(), getDataContext(), getMissionReferenceDate(),
  224.                              getMu(), getDefaultMass(), getParsedUnitsBehavior());
  225.     }

  226.     /** Build a parser for {@link org.orekit.files.ccsds.ndm.odm.oem.Oem Orbit Ephemeris Messages}.
  227.      * @return a new parser
  228.      */
  229.     public OemParser buildOemParser() {
  230.         return new OemParser(getConventions(), isSimpleEOP(), getDataContext(), getMissionReferenceDate(),
  231.                              getMu(), getDefaultInterpolationDegree(), getParsedUnitsBehavior());
  232.     }

  233.     /** Build a parser for {@link org.orekit.files.ccsds.ndm.odm.ocm.Ocm Orbit Comprehensive Messages}.
  234.      * @return a new parser
  235.      */
  236.     public OcmParser buildOcmParser() {
  237.         return new OcmParser(getConventions(), isSimpleEOP(), getDataContext(), getMu(), getParsedUnitsBehavior());
  238.     }

  239.     /** Build a parser for {@link org.orekit.files.ccsds.ndm.adm.apm.Apm Attitude Parameters Messages}.
  240.      * @return a new parser
  241.      */
  242.     public ApmParser buildApmParser() {
  243.         return new ApmParser(getConventions(), isSimpleEOP(), getDataContext(),
  244.                              getMissionReferenceDate(), getParsedUnitsBehavior());
  245.     }

  246.     /** Build a parser for {@link org.orekit.files.ccsds.ndm.adm.aem.Aem Attitude Ephemeris Messages}.
  247.      * @return a new parser
  248.      */
  249.     public AemParser buildAemParser() {
  250.         return new AemParser(getConventions(), isSimpleEOP(), getDataContext(), getMissionReferenceDate(),
  251.                              getDefaultInterpolationDegree(), getParsedUnitsBehavior());
  252.     }

  253.     /** Build a parser for {@link org.orekit.files.ccsds.ndm.tdm.Tdm Tracking Data Messages}.
  254.      * @return a new parser
  255.      */
  256.     public TdmParser buildTdmParser() {
  257.         return new TdmParser(getConventions(), isSimpleEOP(), getDataContext(),
  258.                              getParsedUnitsBehavior(), getRangeUnitsConverter());
  259.     }

  260. }