1   /* Contributed in the public domain.
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.definitions;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.orekit.bodies.CelestialBody;
21  import org.orekit.frames.FieldTransform;
22  import org.orekit.frames.Frame;
23  import org.orekit.frames.Transform;
24  import org.orekit.frames.TransformProvider;
25  import org.orekit.time.AbsoluteDate;
26  import org.orekit.time.FieldAbsoluteDate;
27  
28  /**
29   * A reference frame created from the {@code REF_FRAME} and {@code CENTER_NAME} is a CCSDS
30   * OPM, OMM, or OEM file.
31   *
32   * @author Evan Ward
33   */
34  public class ModifiedFrame extends Frame {
35  
36      /** Reference frame used to create this frame. */
37      private final CelestialBodyFrame refFrame;
38  
39      /** Value of the CENTER_NAME keyword in the ODM file used to create this frame. */
40      private final String centerName;
41  
42      /**
43       * Create a CCSDS reference frame by changing the origin of an existing frame.
44       *
45       * @param frame      the existing frame that specifies the orientation.
46       * @param refFrame   the reference frame used to create this frame.
47       * @param body       the new origin.
48       * @param centerName the value of the {@code CENTER_NAME} key word used to create
49       *                   {@code body}.
50       */
51      public ModifiedFrame(final Frame frame,
52                           final CelestialBodyFrame refFrame,
53                           final CelestialBody body,
54                           final String centerName) {
55          super(frame, new OriginTransformProvider(body, frame),
56                body.getName() + "/" + frame.getName(), frame.isPseudoInertial());
57          this.refFrame   = refFrame;
58          this.centerName = centerName;
59      }
60  
61      /**
62       * Get the CCSDS reference frame.
63       *
64       * @return the reference frame used to create this frame.
65       */
66      public CelestialBodyFrame getRefFrame() {
67          return refFrame;
68      }
69  
70      /**
71       * Get the CCSDS center name.
72       *
73       * @return the value of the {@code CENTER_NAME} key word used to specify the origin of
74       * this frame.
75       */
76      public String getCenterName() {
77          return centerName;
78      }
79  
80      /** Transform provider for {@link ModifiedFrame}. */
81      private static class OriginTransformProvider implements TransformProvider {
82  
83          /** The new origin. */
84          private final CelestialBody body;
85  
86          /** The original frame, specifying the orientation. */
87          private final Frame frame;
88  
89          /**
90           * Create a transform provider to change the origin of an existing frame.
91           *
92           * @param frame the existing frame that specifies the orientation.
93           * @param body  the new origin.
94           */
95          OriginTransformProvider(final CelestialBody body, final Frame frame) {
96              this.body = body;
97              this.frame = frame;
98          }
99  
100         @Override
101         public Transform getTransform(final AbsoluteDate date) {
102             return new Transform(date, body.getPVCoordinates(date, frame).negate());
103         }
104 
105         @Override
106         public <T extends CalculusFieldElement<T>> FieldTransform<T> getTransform(
107                 final FieldAbsoluteDate<T> date) {
108             return new FieldTransform<>(
109                     date,
110                     body.getPVCoordinates(date, frame).negate());
111         }
112 
113     }
114 
115 }