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  
18  package org.orekit.files.ccsds.ndm.adm.apm;
19  
20  import java.io.IOException;
21  
22  import org.hipparchus.geometry.euclidean.threed.Vector3D;
23  import org.orekit.files.ccsds.definitions.TimeConverter;
24  import org.orekit.files.ccsds.definitions.Units;
25  import org.orekit.files.ccsds.section.AbstractWriter;
26  import org.orekit.files.ccsds.utils.generation.Generator;
27  import org.orekit.utils.units.Unit;
28  
29  /** Writer for maneuver data.
30   * @author Luc Maisonobe
31   * @since 11.0
32   */
33  class ManeuverWriter extends AbstractWriter {
34  
35      /** Maneuver block. */
36      private final Maneuver maneuver;
37  
38      /** Converter for dates. */
39      private final TimeConverter timeConverter;
40  
41      /** Create a writer.
42       * @param xmlTag name of the XML tag surrounding the section
43       * @param kvnTag name of the KVN tag surrounding the section (may be null)
44       * @param maneuver maneuver data to write
45       * @param timeConverter converter for dates
46       */
47      ManeuverWriter(final String xmlTag, final String kvnTag,
48                     final Maneuver maneuver, final TimeConverter timeConverter) {
49          super(xmlTag, kvnTag);
50          this.maneuver      = maneuver;
51          this.timeConverter = timeConverter;
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      protected void writeContent(final Generator generator) throws IOException {
57  
58          generator.writeComments(maneuver.getComments());
59  
60          // time
61          generator.writeEntry(ManeuverKey.MAN_EPOCH_START.name(), timeConverter, maneuver.getEpochStart(), true);
62          generator.writeEntry(ManeuverKey.MAN_DURATION.name(),    maneuver.getDuration(), Unit.SECOND,     true);
63  
64          // frame
65          generator.writeEntry(ManeuverKey.MAN_REF_FRAME.name(), maneuver.getRefFrameString(), null, false);
66  
67          // torque
68          final Vector3D torque = maneuver.getTorque();
69          generator.writeEntry(ManeuverKey.MAN_TOR_1.name(), torque.getX(), Units.N_M, true);
70          generator.writeEntry(ManeuverKey.MAN_TOR_2.name(), torque.getY(), Units.N_M, true);
71          generator.writeEntry(ManeuverKey.MAN_TOR_3.name(), torque.getZ(), Units.N_M, true);
72  
73      }
74  
75  }