1   /* Copyright 2002-2021 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.orekit.files.ccsds.definitions.Units;
23  import org.orekit.files.ccsds.section.AbstractWriter;
24  import org.orekit.files.ccsds.utils.generation.Generator;
25  
26  /** Writer for spacecraft parameters data.
27   * @author Luc Maisonobe
28   * @since 11.0
29   */
30  class SpacecraftParametersWriter extends AbstractWriter {
31  
32      /** Spacecraft parameters block. */
33      private final SpacecraftParameters spacecraftParameters;
34  
35      /** Create a writer.
36       * @param xmlTag name of the XML tag surrounding the section
37       * @param kvnTag name of the KVN tag surrounding the section (may be null)
38       * @param spacecraftParameters spacecraft parameters data to write
39       */
40      SpacecraftParametersWriter(final String xmlTag, final String kvnTag,
41                                 final SpacecraftParameters spacecraftParameters) {
42          super(xmlTag, kvnTag);
43          this.spacecraftParameters = spacecraftParameters;
44      }
45  
46      /** {@inheritDoc} */
47      @Override
48      protected void writeContent(final Generator generator) throws IOException {
49  
50          generator.writeComments(spacecraftParameters.getComments());
51  
52          // frame
53          if (spacecraftParameters.getInertiaReferenceFrame() != null) {
54              generator.writeEntry(SpacecraftParametersKey.INERTIA_REF_FRAME.name(),
55                                   spacecraftParameters.getInertiaReferenceFrame().getName(),
56                                   null, false);
57          }
58  
59          // inertia matrix
60          generator.writeEntry(SpacecraftParametersKey.I11.name(), spacecraftParameters.getI11(), Units.KG_M2, true);
61          generator.writeEntry(SpacecraftParametersKey.I22.name(), spacecraftParameters.getI22(), Units.KG_M2, true);
62          generator.writeEntry(SpacecraftParametersKey.I33.name(), spacecraftParameters.getI33(), Units.KG_M2, true);
63          generator.writeEntry(SpacecraftParametersKey.I12.name(), spacecraftParameters.getI12(), Units.KG_M2, true);
64          generator.writeEntry(SpacecraftParametersKey.I13.name(), spacecraftParameters.getI13(), Units.KG_M2, true);
65          generator.writeEntry(SpacecraftParametersKey.I23.name(), spacecraftParameters.getI23(), Units.KG_M2, true);
66  
67      }
68  
69  }