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.ArrayList;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.orekit.files.ccsds.section.CommentsContainer;
24  import org.orekit.files.ccsds.section.Data;
25  
26  /**
27   * Container for Attitude Parameter Message data.
28   * @author Bryan Cazabonne
29   * @since 10.2
30   */
31  public class ApmData implements Data {
32  
33      /** General comments block. */
34      private final CommentsContainer commentsBlock;
35  
36      /** Quaternion block. */
37      private final ApmQuaternion quaternionBlock;
38  
39      /** Euler angles block. */
40      private final Euler eulerBlock;
41  
42      /** Spin-stabilized block. */
43      private final SpinStabilized spinStabilizedBlock;
44  
45      /** Spacecraft parameters block. */
46      private final SpacecraftParameters spacecraftParameters;
47  
48      /** Maneuvers. */
49      private final List<Maneuver> maneuvers;
50  
51      /** Simple constructor.
52       * @param commentsBlock general comments block
53       * @param quaternionBlock quaternion logical block
54       * @param eulerBlock Euler angles logicial block (may be null)
55       * @param spinStabilizedBlock spin-stabilized logical block (may be null)
56       * @param spacecraftParameters spacecraft parameters logical block (may be null)
57       */
58      public ApmData(final CommentsContainer commentsBlock,
59                     final ApmQuaternion quaternionBlock,
60                     final Euler eulerBlock,
61                     final SpinStabilized spinStabilizedBlock,
62                     final SpacecraftParameters spacecraftParameters) {
63          this.commentsBlock        = commentsBlock;
64          this.quaternionBlock      = quaternionBlock;
65          this.eulerBlock           = eulerBlock;
66          this.spinStabilizedBlock  = spinStabilizedBlock;
67          this.spacecraftParameters = spacecraftParameters;
68          this.maneuvers            = new ArrayList<>();
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public void validate(final double version) {
74          quaternionBlock.validate(version);
75          if (eulerBlock != null) {
76              eulerBlock.validate(version);
77          }
78          if (spinStabilizedBlock != null) {
79              spinStabilizedBlock.validate(version);
80          }
81          if (spacecraftParameters != null) {
82              spacecraftParameters.validate(version);
83          }
84          for (final Maneuver maneuver : maneuvers) {
85              maneuver.validate(version);
86          }
87      }
88  
89      /** Get the comments.
90       * @return comments
91       */
92      public List<String> getComments() {
93          return commentsBlock.getComments();
94      }
95  
96      /** Get the quaternion logical block.
97       * @return quaternion block
98       */
99      public ApmQuaternion getQuaternionBlock() {
100         return quaternionBlock;
101     }
102 
103     /** Get the Euler angles logical block.
104      * @return Euler angles block (may be null)
105      */
106     public Euler getEulerBlock() {
107         return eulerBlock;
108     }
109 
110     /** Get the spin-stabilized logical block.
111      * @return spin-stabilized block (may be null)
112      */
113     public SpinStabilized getSpinStabilizedBlock() {
114         return spinStabilizedBlock;
115     }
116 
117     /** Get the spacecraft parameters logical block.
118      * @return spacecraft parameters block (may be null)
119      */
120     public SpacecraftParameters getSpacecraftParametersBlock() {
121         return spacecraftParameters;
122     }
123 
124     /**
125      * Get the number of maneuvers present in the APM.
126      * @return the number of maneuvers
127      */
128     public int getNbManeuvers() {
129         return maneuvers.size();
130     }
131 
132     /**
133      * Get a list of all maneuvers.
134      * @return unmodifiable list of all maneuvers.
135      */
136     public List<Maneuver> getManeuvers() {
137         return Collections.unmodifiableList(maneuvers);
138     }
139 
140     /**
141      * Get a maneuver.
142      * @param index maneuver index, counting from 0
143      * @return maneuver
144      */
145     public Maneuver getManeuver(final int index) {
146         return maneuvers.get(index);
147     }
148 
149     /**
150      * Add a maneuver.
151      * @param maneuver maneuver to be set
152      */
153     public void addManeuver(final Maneuver maneuver) {
154         maneuvers.add(maneuver);
155     }
156 
157     /**
158      * Get boolean testing whether the APM contains at least one maneuver.
159      * @return true if APM contains at least one maneuver
160      *         false otherwise
161      */
162     public boolean hasManeuvers() {
163         return !maneuvers.isEmpty();
164     }
165 
166 }