1   /* Copyright 2002-2016 CS Systèmes d'Information
2    * Licensed to CS Systèmes d'Information (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;
18  
19  import org.orekit.bodies.CelestialBodyFactory;
20  import org.orekit.errors.OrekitException;
21  import org.orekit.errors.OrekitMessages;
22  import org.orekit.frames.Frame;
23  import org.orekit.frames.FramesFactory;
24  import org.orekit.frames.HelmertTransformation;
25  import org.orekit.frames.LOFType;
26  import org.orekit.utils.IERSConventions;
27  
28  /** Frames used in CCSDS Orbit Data Messages.
29   * @author Steven Ports
30   * @since 6.1
31   */
32  public enum CCSDSFrame {
33  
34      /** Earth Mean Equator and Equinox of J2000. */
35      EME2000(null) {
36  
37          /** {@inheritDoc} */
38          @Override
39          public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
40              throws OrekitException {
41              return FramesFactory.getEME2000();
42          }
43  
44      },
45  
46      /** Geocentric Celestial Reference Frame. */
47      GCRF(null) {
48  
49          /** {@inheritDoc} */
50          @Override
51          public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
52              throws OrekitException {
53              return FramesFactory.getGCRF();
54          }
55  
56      },
57  
58      /** Greenwich Rotating Coordinates. */
59      GRC(null) {
60  
61          /** {@inheritDoc} */
62          @Override
63          public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
64              throws OrekitException {
65              if (conventions == null) {
66                  throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
67              }
68              return FramesFactory.getITRFEquinox(conventions, simpleEOP);
69          }
70  
71      },
72  
73      /** International Celestial Reference Frame. */
74      ICRF(null) {
75  
76          /** {@inheritDoc} */
77          @Override
78          public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
79              throws OrekitException {
80              return FramesFactory.getICRF();
81          }
82  
83      },
84  
85      /** International Celestial Reference Frame 2000. */
86      ITRF2000(null) {
87  
88          /** {@inheritDoc} */
89          @Override
90          public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
91              throws OrekitException {
92              if (conventions == null) {
93                  throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
94              }
95              final Frame itrf2008 = FramesFactory.getITRF(conventions, simpleEOP);
96              final HelmertTransformation.Predefined predefinedHT =
97                      HelmertTransformation.Predefined.ITRF_2008_TO_ITRF_2000;
98              return predefinedHT.createTransformedITRF(itrf2008, toString());
99          }
100 
101     },
102 
103     /** International Celestial Reference Frame 1993. */
104     ITRF93(null) {
105 
106         /** {@inheritDoc} */
107         @Override
108         public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
109             throws OrekitException {
110             if (conventions == null) {
111                 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
112             }
113             final Frame itrf2008 = FramesFactory.getITRF(conventions, simpleEOP);
114             final HelmertTransformation.Predefined predefinedHT =
115                     HelmertTransformation.Predefined.ITRF_2008_TO_ITRF_93;
116             return predefinedHT.createTransformedITRF(itrf2008, toString());
117         }
118 
119     },
120 
121     /** International Celestial Reference Frame 1997. */
122     ITRF97(null) {
123 
124         /** {@inheritDoc} */
125         @Override
126         public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
127             throws OrekitException {
128             if (conventions == null) {
129                 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
130             }
131             final Frame itrf2008 = FramesFactory.getITRF(conventions, simpleEOP);
132             final HelmertTransformation.Predefined predefinedHT =
133                     HelmertTransformation.Predefined.ITRF_2008_TO_ITRF_97;
134             return predefinedHT.createTransformedITRF(itrf2008, toString());
135         }
136 
137     },
138 
139     /** Mars Centered Inertial. */
140     MCI(null) {
141 
142         /** {@inheritDoc} */
143         @Override
144         public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
145             throws OrekitException {
146             return CelestialBodyFactory.getMars().getInertiallyOrientedFrame();
147         }
148 
149     },
150 
151     /** True of Date, Rotating. */
152     TDR(null) {
153 
154         /** {@inheritDoc} */
155         @Override
156         public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
157             throws OrekitException {
158             if (conventions == null) {
159                 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
160             }
161             return FramesFactory.getGTOD(conventions, simpleEOP);
162         }
163 
164     },
165 
166     /**
167      * True Equator Mean Equinox.
168      * TEME may be used only for OMMs based on NORAD
169      * Two Line Element sets, and in no other circumstances.
170      */
171     TEME(null) {
172 
173         /** {@inheritDoc} */
174         @Override
175         public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
176             throws OrekitException {
177             return FramesFactory.getTEME();
178         }
179 
180     },
181 
182     /** True of Date. */
183     TOD(null) {
184 
185         /** {@inheritDoc} */
186         @Override
187         public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
188             throws OrekitException {
189             if (conventions == null) {
190                 throw new OrekitException(OrekitMessages.CCSDS_UNKNOWN_CONVENTIONS);
191             }
192             return FramesFactory.getTOD(conventions, simpleEOP);
193         }
194 
195     },
196 
197     /** Radial, Transverse (along-track) and Normal. */
198     RTN(LOFType.QSW),
199 
200     /** Another name for Radial, Transverse (along-track) and Normal. */
201     RSW(LOFType.QSW),
202 
203     /** TNW : x-axis along the velocity vector, W along the orbital angular momentum vector and
204     N completes the right handed system. */
205     TNW(LOFType.TNW);
206 
207     /** Type of Local Orbital Frame (may be null). */
208     private final LOFType lofType;
209 
210     /** Simple constructor.
211      * @param lofType type of Local Orbital Frame (null if frame is not a Local Orbital Frame)
212      */
213     CCSDSFrame(final LOFType lofType) {
214         this.lofType = lofType;
215     }
216 
217     /** Check if the frame is a Local Orbital frame.
218      * @return true if the frame is a Local Orbital Frame
219      */
220     public boolean isLof() {
221         return lofType != null;
222     }
223 
224     /** Get the type of Local Orbital frame.
225      * <p>
226      * If the frame is not a Local Orbital frame (i.e. if this method returns null),
227      * then the {@link #getFrame(IERSConventions, boolean) getFrame} method must be used to
228      * retrieve the absolute frame.
229      * </p>
230      * @return type of Local Orbital Frame, or null if the frame is not a local orbital frame
231      * @see #isLof()
232      */
233     public LOFType getLofType() {
234         return lofType;
235     }
236 
237     /**
238      * Get the frame corresponding to the CCSDS constant.
239      * @param conventions IERS conventions to use
240      * @param simpleEOP if true, tidal effects are ignored when interpolating EOP
241      * @return frame corresponding to the CCSDS constant
242      * @exception OrekitException if the frame cannot be retrieved or if it
243      * is a Local Orbital Frame
244      * @see #isLof()
245      */
246     public Frame getFrame(final IERSConventions conventions, final boolean simpleEOP)
247         throws OrekitException {
248         throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME, toString());
249     }
250 
251 }