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  package org.orekit.files.ccsds.ndm;
18  
19  import org.orekit.annotation.DefaultDataContext;
20  import org.orekit.data.DataContext;
21  import org.orekit.files.ccsds.ndm.adm.aem.AemParser;
22  import org.orekit.files.ccsds.ndm.adm.apm.ApmParser;
23  import org.orekit.files.ccsds.ndm.odm.ocm.OcmParser;
24  import org.orekit.files.ccsds.ndm.odm.oem.OemParser;
25  import org.orekit.files.ccsds.ndm.odm.omm.OmmParser;
26  import org.orekit.files.ccsds.ndm.odm.opm.OpmParser;
27  import org.orekit.files.ccsds.ndm.tdm.IdentityConverter;
28  import org.orekit.files.ccsds.ndm.tdm.RangeUnits;
29  import org.orekit.files.ccsds.ndm.tdm.RangeUnitsConverter;
30  import org.orekit.files.ccsds.ndm.tdm.TdmParser;
31  import org.orekit.time.AbsoluteDate;
32  import org.orekit.utils.IERSConventions;
33  
34  /** Builder for all {@link NdmConstituent CCSDS Message} files parsers.
35   * <p>
36   * This builder can be used for building all CCSDS Messages parsers types.
37   * It is particularly useful in multi-threaded context as parsers cannot
38   * be shared between threads and thus several independent parsers must be
39   * built in this case.
40   * </p>
41   * @author Luc Maisonobe
42   * @since 11.0
43   */
44  public class ParserBuilder extends AbstractBuilder<ParserBuilder> {
45  
46      /** Indicator for simple or accurate EOP interpolation. */
47      private final  boolean simpleEOP;
48  
49      /** Gravitational coefficient. */
50      private final double mu;
51  
52      /** Default mass. */
53      private final double defaultMass;
54  
55      /** Default interpolation degree. */
56      private final int defaultInterpolationDegree;
57  
58      /** Behavior adopted for units that have been parsed from a CCSDS message. */
59      private final ParsedUnitsBehavior parsedUnitsBehavior;
60  
61      /**
62       * Simple constructor.
63       * <p>
64       * This constructor creates a builder with
65       * <ul>
66       *   <li>{@link #getConventions() IERS conventions} set to {@link IERSConventions#IERS_2010}</li>
67       *   <li>{@link #isSimpleEOP() simple EOP} set to {@code true}</li>
68       *   <li>{@link #getDataContext() data context} set to {@link DataContext#getDefault() default context}</li>
69       *   <li>{@link #getMissionReferenceDate() mission reference date} set to {@code null}</li>
70       *   <li>{@link #getMu() gravitational coefficient} set to {@code Double.NaN}</li>
71       *   <li>{@link #getDefaultMass() default mass} set to {@code Double.NaN}</li>
72       *   <li>{@link #getDefaultInterpolationDegree() default interpolation degree} set to {@code 1}</li>
73       *   <li>{@link #getParsedUnitsBehavior() parsed unit behavior} set to {@link ParsedUnitsBehavior#CONVERT_COMPATIBLE}</li>
74       *   <li>{@link #getRangeUnitsConverter() converter for range units} set to {@link IdentityConverter}</li>
75       * </ul>
76       */
77      @DefaultDataContext
78      public ParserBuilder() {
79          this(DataContext.getDefault());
80      }
81  
82      /**
83       * Simple constructor.
84       * <p>
85       * This constructor creates a builder with
86       * <ul>
87       *   <li>{@link #getConventions() IERS conventions} set to {@link IERSConventions#IERS_2010}</li>
88       *   <li>{@link #isSimpleEOP() simple EOP} set to {@code true}</li>
89       *   <li>{@link #getMissionReferenceDate() mission reference date} set to {@code null}</li>
90       *   <li>{@link #getMu() gravitational coefficient} set to {@code Double.NaN}</li>
91       *   <li>{@link #getDefaultMass() default mass} set to {@code Double.NaN}</li>
92       *   <li>{@link #getDefaultInterpolationDegree() default interpolation degree} set to {@code 1}</li>
93       *   <li>{@link #getParsedUnitsBehavior() parsed unit behavior} set to {@link ParsedUnitsBehavior#CONVERT_COMPATIBLE}</li>
94       *   <li>{@link #getRangeUnitsConverter() converter for range units} set to {@link IdentityConverter}</li>
95       * </ul>
96       * @param dataContext data context used to retrieve frames, time scales, etc.
97       */
98      public ParserBuilder(final DataContext dataContext) {
99          this(IERSConventions.IERS_2010, dataContext, null, new IdentityConverter(),
100              true, Double.NaN, Double.NaN, 1, ParsedUnitsBehavior.CONVERT_COMPATIBLE);
101     }
102 
103     /** Complete constructor.
104      * @param conventions IERS Conventions
105      * @param dataContext used to retrieve frames, time scales, etc.
106      * @param missionReferenceDate reference date for Mission Elapsed Time or Mission Relative Time time systems
107      * @param simpleEOP if true, tidal effects are ignored when interpolating EOP
108      * @param mu gravitational coefficient
109      * @param defaultMass default mass
110      * @param defaultInterpolationDegree default interpolation degree
111      * @param parsedUnitsBehavior behavior to adopt for handling parsed units
112      * @param rangeUnitsConverter converter for {@link RangeUnits#RU Range Units}
113      */
114     private ParserBuilder(final IERSConventions conventions, final DataContext dataContext,
115                           final AbsoluteDate missionReferenceDate,
116                           final RangeUnitsConverter rangeUnitsConverter,
117                           final boolean simpleEOP, final double mu, final double defaultMass,
118                           final int defaultInterpolationDegree,
119                           final ParsedUnitsBehavior parsedUnitsBehavior) {
120         super(conventions, dataContext, missionReferenceDate, rangeUnitsConverter);
121         this.simpleEOP                  = simpleEOP;
122         this.mu                         = mu;
123         this.defaultMass                = defaultMass;
124         this.defaultInterpolationDegree = defaultInterpolationDegree;
125         this.parsedUnitsBehavior        = parsedUnitsBehavior;
126     }
127 
128     /** {@inheritDoc} */
129     @Override
130     protected ParserBuilder create(final IERSConventions newConventions, final DataContext newDataContext,
131                                    final AbsoluteDate newMissionReferenceDate, final RangeUnitsConverter newRangeUnitsConverter) {
132         return new ParserBuilder(newConventions, newDataContext, newMissionReferenceDate, newRangeUnitsConverter,
133                                  simpleEOP, mu, defaultMass, defaultInterpolationDegree, parsedUnitsBehavior);
134     }
135 
136     /** Set up flag for ignoring tidal effects when interpolating EOP.
137      * @param newSimpleEOP true if tidal effects are ignored when interpolating EOP
138      * @return a new builder with updated configuration (the instance is not changed)
139      */
140     public ParserBuilder withSimpleEOP(final boolean newSimpleEOP) {
141         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
142                                  newSimpleEOP, getMu(), getDefaultMass(),
143                                  getDefaultInterpolationDegree(), getParsedUnitsBehavior());
144     }
145 
146     /** Check if tidal effects are ignored when interpolating EOP.
147      * @return true if tidal effects are ignored when interpolating EOP
148      */
149     public boolean isSimpleEOP() {
150         return simpleEOP;
151     }
152 
153     /** Set up the gravitational coefficient.
154      * @param newMu gravitational coefficient
155      * @return a new builder with updated configuration (the instance is not changed)
156      */
157     public ParserBuilder withMu(final double newMu) {
158         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
159                                  isSimpleEOP(), newMu, getDefaultMass(),
160                                  getDefaultInterpolationDegree(), getParsedUnitsBehavior());
161     }
162 
163     /** Get the gravitational coefficient.
164      * @return gravitational coefficient
165      */
166     public double getMu() {
167         return mu;
168     }
169 
170     /** Set up the default mass.
171      * <p>
172      * The default mass is used only by {@link OpmParser}.
173      * </p>
174      * @param newDefaultMass default mass
175      * @return a new builder with updated configuration (the instance is not changed)
176      */
177     public ParserBuilder withDefaultMass(final double newDefaultMass) {
178         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
179                                  isSimpleEOP(), getMu(), newDefaultMass,
180                                  getDefaultInterpolationDegree(), getParsedUnitsBehavior());
181     }
182 
183     /** Get the default mass.
184      * @return default mass
185      */
186     public double getDefaultMass() {
187         return defaultMass;
188     }
189 
190     /** Set up the default interpolation degree.
191      * <p>
192      * The default interpolation degree is used only by {@link AemParser}
193      * and {@link OemParser}.
194      * </p>
195      * @param newDefaultInterpolationDegree default interpolation degree
196      * @return a new builder with updated configuration (the instance is not changed)
197      */
198     public ParserBuilder withDefaultInterpolationDegree(final int newDefaultInterpolationDegree) {
199         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
200                                  isSimpleEOP(), getMu(), getDefaultMass(),
201                                  newDefaultInterpolationDegree, getParsedUnitsBehavior());
202     }
203 
204     /** Get the default interpolation degree.
205      * @return default interpolation degree
206      */
207     public int getDefaultInterpolationDegree() {
208         return defaultInterpolationDegree;
209     }
210 
211     /** Set up the behavior to adopt for handling parsed units.
212      * @param newParsedUnitsBehavior behavior to adopt for handling parsed units
213      * @return a new builder with updated configuration (the instance is not changed)
214      */
215     public ParserBuilder withParsedUnitsBehavior(final ParsedUnitsBehavior newParsedUnitsBehavior) {
216         return new ParserBuilder(getConventions(), getDataContext(), getMissionReferenceDate(), getRangeUnitsConverter(),
217                                  isSimpleEOP(), getMu(), getDefaultMass(),
218                                  getDefaultInterpolationDegree(), newParsedUnitsBehavior);
219     }
220 
221     /** Get the behavior to adopt for handling parsed units.
222      * @return behavior to adopt for handling parsed units
223      */
224     public ParsedUnitsBehavior getParsedUnitsBehavior() {
225         return parsedUnitsBehavior;
226     }
227 
228     /** Build a parser for {@link org.orekit.files.ccsds.ndm.Ndm Navigation Data Messages}.
229      * @return a new parser
230      */
231     public NdmParser buildNdmParser() {
232         return new NdmParser(this);
233     }
234 
235     /** Build a parser for {@link org.orekit.files.ccsds.ndm.odm.opm.Opm Orbit Parameters Messages}.
236      * @return a new parser
237      */
238     public OpmParser buildOpmParser() {
239         return new OpmParser(getConventions(), isSimpleEOP(), getDataContext(), getMissionReferenceDate(),
240                              getMu(), getDefaultMass(), getParsedUnitsBehavior());
241     }
242 
243     /** Build a parser for {@link org.orekit.files.ccsds.ndm.odm.omm.Omm Orbit Mean elements Messages}.
244      * @return a new parser
245      */
246     public OmmParser buildOmmParser() {
247         return new OmmParser(getConventions(), isSimpleEOP(), getDataContext(), getMissionReferenceDate(),
248                              getMu(), getDefaultMass(), getParsedUnitsBehavior());
249     }
250 
251     /** Build a parser for {@link org.orekit.files.ccsds.ndm.odm.oem.Oem Orbit Ephemeris Messages}.
252      * @return a new parser
253      */
254     public OemParser buildOemParser() {
255         return new OemParser(getConventions(), isSimpleEOP(), getDataContext(), getMissionReferenceDate(),
256                              getMu(), getDefaultInterpolationDegree(), getParsedUnitsBehavior());
257     }
258 
259     /** Build a parser for {@link org.orekit.files.ccsds.ndm.odm.ocm.Ocm Orbit Comprehensive Messages}.
260      * @return a new parser
261      */
262     public OcmParser buildOcmParser() {
263         return new OcmParser(getConventions(), isSimpleEOP(), getDataContext(), getMu(), getParsedUnitsBehavior());
264     }
265 
266     /** Build a parser for {@link org.orekit.files.ccsds.ndm.adm.apm.Apm Attitude Parameters Messages}.
267      * @return a new parser
268      */
269     public ApmParser buildApmParser() {
270         return new ApmParser(getConventions(), isSimpleEOP(), getDataContext(),
271                              getMissionReferenceDate(), getParsedUnitsBehavior());
272     }
273 
274     /** Build a parser for {@link org.orekit.files.ccsds.ndm.adm.aem.Aem Attitude Ephemeris Messages}.
275      * @return a new parser
276      */
277     public AemParser buildAemParser() {
278         return new AemParser(getConventions(), isSimpleEOP(), getDataContext(), getMissionReferenceDate(),
279                              getDefaultInterpolationDegree(), getParsedUnitsBehavior());
280     }
281 
282     /** Build a parser for {@link org.orekit.files.ccsds.ndm.tdm.Tdm Tracking Data Messages}.
283      * @return a new parser
284      */
285     public TdmParser buildTdmParser() {
286         return new TdmParser(getConventions(), isSimpleEOP(), getDataContext(),
287                              getParsedUnitsBehavior(), getRangeUnitsConverter());
288     }
289 
290 }