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.adm.apm;
18  
19  import java.util.Arrays;
20  
21  import org.hipparchus.geometry.euclidean.threed.Vector3D;
22  import org.orekit.files.ccsds.section.CommentsContainer;
23  import org.orekit.time.AbsoluteDate;
24  
25  /**
26   * Maneuver in an APM file.
27   * @author Bryan Cazabonne
28   * @since 10.2
29   */
30  public class Maneuver extends CommentsContainer {
31  
32      /** Epoch of start of maneuver . */
33      private AbsoluteDate epochStart;
34  
35      /** Coordinate system for the torque vector, for absolute frames. */
36      private String refFrameString;
37  
38      /** Duration (value is 0 for impulsive maneuver). */
39      private double duration;
40  
41      /** Torque vector (N.m). */
42      private double[] torque;
43  
44      /**
45       * Simple constructor.
46       */
47      public Maneuver() {
48          duration = Double.NaN;
49          torque   = new double[3];
50          Arrays.fill(torque, Double.NaN);
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public void validate(final double version) {
56          super.validate(version);
57          checkNotNull(epochStart,     ManeuverKey.MAN_EPOCH_START);
58          checkNotNaN(duration,        ManeuverKey.MAN_DURATION);
59          checkNotNull(refFrameString, ManeuverKey.MAN_REF_FRAME);
60          checkNotNaN(torque[0],       ManeuverKey.MAN_TOR_1);
61          checkNotNaN(torque[1],       ManeuverKey.MAN_TOR_2);
62          checkNotNaN(torque[2],       ManeuverKey.MAN_TOR_3);
63      }
64  
65      /**
66       * Get epoch start.
67       * @return epoch start
68       */
69      public AbsoluteDate getEpochStart() {
70          return epochStart;
71      }
72  
73      /**
74       * Set epoch start.
75       * @param epochStart epoch start
76       */
77      public void setEpochStart(final AbsoluteDate epochStart) {
78          refuseFurtherComments();
79          this.epochStart = epochStart;
80      }
81  
82      /**
83       * Get Coordinate system for the torque vector, for absolute frames.
84       * @return coordinate system for the torque vector, for absolute frames
85       */
86      public String getRefFrameString() {
87          return refFrameString;
88      }
89  
90      /**
91       * Set Coordinate system for the torque vector, for absolute frames.
92       * @param refFrameString coordinate system for the torque vector, for absolute frames
93       */
94      public void setRefFrameString(final String refFrameString) {
95          refuseFurtherComments();
96          this.refFrameString = refFrameString;
97      }
98  
99      /**
100      * Get duration (value is 0 for impulsive maneuver).
101      * @return duration (value is 0 for impulsive maneuver)
102      */
103     public double getDuration() {
104         return duration;
105     }
106 
107     /**
108      * Set duration (value is 0 for impulsive maneuver).
109      * @param duration duration (value is 0 for impulsive maneuver)
110      */
111     public void setDuration(final double duration) {
112         refuseFurtherComments();
113         this.duration = duration;
114     }
115 
116     /** Check if maneuver has been completed.
117      * @return true if maneuver has been completed
118      */
119     public boolean completed() {
120         return !(epochStart     == null ||
121                  refFrameString == null ||
122                  Double.isNaN(duration + torque[0] + torque[1] + torque[2]));
123     }
124 
125     /**
126      * Get the torque vector (N.m).
127      * @return torque vector
128      */
129     public Vector3D getTorque() {
130         return new Vector3D(torque);
131     }
132 
133     /**
134      * Set the torque vector (N.m).
135      * @param index vector component index (counting from 0)
136      * @param value component value
137      */
138     public void setTorque(final int index, final double value) {
139         refuseFurtherComments();
140         this.torque[index] = value;
141     }
142 
143 }