1   /* Copyright 2002-2025 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      /** Format version.
36       * @since 12.0
37       */
38      private final double formatVersion;
39  
40      /** Maneuver block. */
41      private final Maneuver maneuver;
42  
43      /** Converter for dates. */
44      private final TimeConverter timeConverter;
45  
46      /** Create a writer.
47       * @param formatVersion format version
48       * @param xmlTag name of the XML tag surrounding the section
49       * @param kvnTag name of the KVN tag surrounding the section (may be null)
50       * @param maneuver maneuver data to write
51       * @param timeConverter converter for dates
52       */
53      ManeuverWriter(final double formatVersion, final String xmlTag, final String kvnTag,
54                     final Maneuver maneuver, final TimeConverter timeConverter) {
55          super(xmlTag, kvnTag);
56          this.formatVersion = formatVersion;
57          this.maneuver      = maneuver;
58          this.timeConverter = timeConverter;
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      protected void writeContent(final Generator generator) throws IOException {
64  
65          generator.writeComments(maneuver.getComments());
66  
67          // time
68          generator.writeEntry(ManeuverKey.MAN_EPOCH_START.name(), timeConverter, maneuver.getEpochStart(), true, true);
69          generator.writeEntry(ManeuverKey.MAN_DURATION.name(),    maneuver.getDuration(), Unit.SECOND,     true);
70  
71          // frame
72          generator.writeEntry(ManeuverKey.MAN_REF_FRAME.name(), maneuver.getFrame().getName(), null, false);
73  
74          // torque
75          final Vector3D torque = maneuver.getTorque();
76          if (formatVersion < 2.0) {
77              generator.writeEntry(ManeuverKey.MAN_TOR_1.name(), torque.getX(), Units.N_M, true);
78              generator.writeEntry(ManeuverKey.MAN_TOR_2.name(), torque.getY(), Units.N_M, true);
79              generator.writeEntry(ManeuverKey.MAN_TOR_3.name(), torque.getZ(), Units.N_M, true);
80          } else {
81              generator.writeEntry(ManeuverKey.MAN_TOR_X.name(),      torque.getX(),           Units.N_M,     true);
82              generator.writeEntry(ManeuverKey.MAN_TOR_Y.name(),      torque.getY(),           Units.N_M,     true);
83              generator.writeEntry(ManeuverKey.MAN_TOR_Z.name(),      torque.getZ(),           Units.N_M,     true);
84              generator.writeEntry(ManeuverKey.MAN_DELTA_MASS.name(), maneuver.getDeltaMass(), Unit.KILOGRAM, true);
85          }
86  
87      }
88  
89  }