ManeuverWriter.java

  1. /* Copyright 2002-2024 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. import java.io.IOException;

  19. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  20. import org.orekit.files.ccsds.definitions.TimeConverter;
  21. import org.orekit.files.ccsds.definitions.Units;
  22. import org.orekit.files.ccsds.section.AbstractWriter;
  23. import org.orekit.files.ccsds.utils.generation.Generator;
  24. import org.orekit.utils.units.Unit;

  25. /** Writer for maneuver data.
  26.  * @author Luc Maisonobe
  27.  * @since 11.0
  28.  */
  29. class ManeuverWriter extends AbstractWriter {

  30.     /** Format version.
  31.      * @since 12.0
  32.      */
  33.     private final double formatVersion;

  34.     /** Maneuver block. */
  35.     private final Maneuver maneuver;

  36.     /** Converter for dates. */
  37.     private final TimeConverter timeConverter;

  38.     /** Create a writer.
  39.      * @param formatVersion format version
  40.      * @param xmlTag name of the XML tag surrounding the section
  41.      * @param kvnTag name of the KVN tag surrounding the section (may be null)
  42.      * @param maneuver maneuver data to write
  43.      * @param timeConverter converter for dates
  44.      */
  45.     ManeuverWriter(final double formatVersion, final String xmlTag, final String kvnTag,
  46.                    final Maneuver maneuver, final TimeConverter timeConverter) {
  47.         super(xmlTag, kvnTag);
  48.         this.formatVersion = formatVersion;
  49.         this.maneuver      = maneuver;
  50.         this.timeConverter = timeConverter;
  51.     }

  52.     /** {@inheritDoc} */
  53.     @Override
  54.     protected void writeContent(final Generator generator) throws IOException {

  55.         generator.writeComments(maneuver.getComments());

  56.         // time
  57.         generator.writeEntry(ManeuverKey.MAN_EPOCH_START.name(), timeConverter, maneuver.getEpochStart(), true, true);
  58.         generator.writeEntry(ManeuverKey.MAN_DURATION.name(),    maneuver.getDuration(), Unit.SECOND,     true);

  59.         // frame
  60.         generator.writeEntry(ManeuverKey.MAN_REF_FRAME.name(), maneuver.getFrame().getName(), null, false);

  61.         // torque
  62.         final Vector3D torque = maneuver.getTorque();
  63.         if (formatVersion < 2.0) {
  64.             generator.writeEntry(ManeuverKey.MAN_TOR_1.name(), torque.getX(), Units.N_M, true);
  65.             generator.writeEntry(ManeuverKey.MAN_TOR_2.name(), torque.getY(), Units.N_M, true);
  66.             generator.writeEntry(ManeuverKey.MAN_TOR_3.name(), torque.getZ(), Units.N_M, true);
  67.         } else {
  68.             generator.writeEntry(ManeuverKey.MAN_TOR_X.name(),      torque.getX(),           Units.N_M,     true);
  69.             generator.writeEntry(ManeuverKey.MAN_TOR_Y.name(),      torque.getY(),           Units.N_M,     true);
  70.             generator.writeEntry(ManeuverKey.MAN_TOR_Z.name(),      torque.getZ(),           Units.N_M,     true);
  71.             generator.writeEntry(ManeuverKey.MAN_DELTA_MASS.name(), maneuver.getDeltaMass(), Unit.KILOGRAM, true);
  72.         }

  73.     }

  74. }