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.odm.opm;
19  
20  import java.io.IOException;
21  
22  import org.orekit.files.ccsds.definitions.Units;
23  import org.orekit.files.ccsds.ndm.odm.KeplerianElements;
24  import org.orekit.files.ccsds.ndm.odm.KeplerianElementsKey;
25  import org.orekit.files.ccsds.section.AbstractWriter;
26  import org.orekit.files.ccsds.utils.generation.Generator;
27  import org.orekit.orbits.PositionAngleType;
28  import org.orekit.utils.units.Unit;
29  
30  /** Writer for Keplerian elements data in OPM files.
31   * @author Luc Maisonobe
32   * @since 11.0
33   */
34  class OsculationgKeplerianElementsWriter extends AbstractWriter {
35  
36      /** Keplerian elements block. */
37      private final KeplerianElements keplerianElements;
38  
39      /** Create a writer.
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 keplerianElements Keplerian elements to write
43       */
44      OsculationgKeplerianElementsWriter(final String xmlTag, final String kvnTag,
45                                         final KeplerianElements keplerianElements) {
46          super(xmlTag, kvnTag);
47          this.keplerianElements = keplerianElements;
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      protected void writeContent(final Generator generator) throws IOException {
53  
54          // Keplerian elements block
55          generator.writeComments(keplerianElements.getComments());
56          generator.writeEntry(KeplerianElementsKey.SEMI_MAJOR_AXIS.name(),   keplerianElements.getA(), Unit.KILOMETRE, true);
57          generator.writeEntry(KeplerianElementsKey.ECCENTRICITY.name(),      keplerianElements.getE(), Unit.ONE,       true);
58          generator.writeEntry(KeplerianElementsKey.INCLINATION.name(),       keplerianElements.getI(), Unit.DEGREE,    true);
59          generator.writeEntry(KeplerianElementsKey.RA_OF_ASC_NODE.name(),    keplerianElements.getRaan(), Unit.DEGREE, true);
60          generator.writeEntry(KeplerianElementsKey.ARG_OF_PERICENTER.name(), keplerianElements.getPa(), Unit.DEGREE,   true);
61          generator.writeEntry(keplerianElements.getAnomalyType() == PositionAngleType.TRUE ?
62                                                                     KeplerianElementsKey.TRUE_ANOMALY.name() : KeplerianElementsKey.MEAN_ANOMALY.name(),
63                                                                     keplerianElements.getAnomaly(),
64                                                                     Unit.DEGREE,
65                                                                     true);
66          generator.writeEntry(KeplerianElementsKey.GM.name(), keplerianElements.getMu(), Units.KM3_PER_S2, true);
67  
68      }
69  
70  }