1   /* Copyright 2022-2025 Luc Maisonobe
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.adm.acm;
19  
20  import java.util.List;
21  
22  import org.hipparchus.geometry.euclidean.threed.RotationOrder;
23  import org.orekit.time.AbsoluteDate;
24  import org.orekit.time.TimeStamped;
25  import org.orekit.utils.AngularDerivativesFilter;
26  import org.orekit.utils.TimeStampedAngularCoordinates;
27  import org.orekit.utils.units.Unit;
28  
29  /** Attitude state entry.
30   * @author Luc Maisonobe
31   * @since 12.0
32   */
33  public class AttitudeState implements TimeStamped {
34  
35      /** Type of the elements. */
36      private final AttitudeElementsType attitudeType;
37  
38      /** Type of the elements rates. */
39      private final RateElementsType rateType;
40  
41      /** Entry date. */
42      private final AbsoluteDate date;
43  
44      /** Attitude elements. */
45      private final double[] elements;
46  
47      /** Simple constructor.
48       * @param attitudeType type of the elements
49       * @param rateType type of the elements rates
50       * (internally changed to {@link RateElementsType#NONE} if null)
51       * @param date entry date
52       * @param fields trajectory elements
53       * @param first index of first field to consider
54       */
55      public AttitudeState(final AttitudeElementsType attitudeType, final RateElementsType rateType,
56                           final AbsoluteDate date, final String[] fields, final int first) {
57  
58          this.attitudeType = attitudeType;
59          this.rateType     = rateType == null ? RateElementsType.NONE : rateType;
60  
61          final List<Unit> attUnits  = this.attitudeType.getUnits();
62          final List<Unit> rateUnits = this.rateType.getUnits();
63  
64          this.date         = date;
65          this.elements     = new double[attUnits.size() + rateUnits.size()];
66          for (int i = 0; i < attUnits.size(); ++i) {
67              elements[i] = attUnits.get(i).toSI(Double.parseDouble(fields[first + i]));
68          }
69          for (int i = 0; i < rateUnits.size(); ++i) {
70              elements[attUnits.size() + i] = rateUnits.get(i).toSI(Double.parseDouble(fields[attUnits.size() + first + i]));
71          }
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public AbsoluteDate getDate() {
77          return date;
78      }
79  
80      /** Get attitude elements.
81       * @return attitude elements
82       */
83      public double[] getElements() {
84          return elements.clone();
85      }
86  
87      /** Get the type of the elements.
88       * @return type of the elements
89       */
90      public AttitudeElementsType getAttitudeType() {
91          return attitudeType;
92      }
93  
94      /** Get the type of the elements rates.
95       * @return type of the elements rates
96       */
97      public RateElementsType getRateElementsType() {
98          return rateType;
99      }
100 
101     /** Get which derivatives of position are available in this state.
102      * @return a value indicating if the file contains rotation rate and/or acceleration
103       */
104     public AngularDerivativesFilter getAvailableDerivatives() {
105         return rateType == RateElementsType.NONE ?
106                AngularDerivativesFilter.USE_R :
107                AngularDerivativesFilter.USE_RR;
108     }
109 
110     /** Convert to angular coordinates.
111      * @param order rotation order for Euler angles
112      * @return angular coordinates
113      */
114     public TimeStampedAngularCoordinates toAngular(final RotationOrder order) {
115         return rateType.toAngular(getDate(), order,
116                                   attitudeType.toRotation(order, elements),
117                                   attitudeType.getUnits().size(), elements);
118     }
119 
120 }