1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.files.ccsds.definitions;
18
19 import org.orekit.bodies.CelestialBody;
20 import org.orekit.bodies.CelestialBodyFactory;
21 import org.orekit.errors.OrekitException;
22 import org.orekit.errors.OrekitMessages;
23 import org.orekit.frames.Frame;
24 import org.orekit.time.AbsoluteDate;
25
26
27
28
29
30
31
32 public class OrekitCcsdsFrameMapper implements CcsdsFrameMapper {
33
34
35 private static final String NO_REFERENCE_FRAME = "No reference frame";
36
37 @Override
38 public Frame buildCcsdsFrame(final FrameFacade orientation,
39 final AbsoluteDate frameEpoch) {
40 if (orientation == null) {
41 throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME, NO_REFERENCE_FRAME);
42 }
43 final Frame frame = orientation.asFrame();
44 if (frame == null) {
45 throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME, orientation.getName());
46 }
47 return frame;
48 }
49
50 @Override
51 public Frame buildCcsdsFrame(final BodyFacade center,
52 final FrameFacade orientation,
53 final AbsoluteDate frameEpoch) {
54 if (center == null) {
55 throw new OrekitException(OrekitMessages.NO_DATA_LOADED_FOR_CELESTIAL_BODY, "No Orbit center name");
56 }
57 final CelestialBody body = center.getBody();
58 if (body == null) {
59 throw new OrekitException(OrekitMessages.NO_DATA_LOADED_FOR_CELESTIAL_BODY, center.getName());
60 }
61 if (orientation == null) {
62 throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME, NO_REFERENCE_FRAME);
63 }
64 final Frame frame = orientation.asFrame();
65 if (frame == null) {
66 throw new OrekitException(OrekitMessages.CCSDS_INVALID_FRAME, orientation.getName());
67 }
68
69
70 final CelestialBodyFrame celestialBodyFrame =
71 orientation.asCelestialBodyFrame();
72 final boolean isMci = celestialBodyFrame == CelestialBodyFrame.MCI;
73 final boolean isIcrf = celestialBodyFrame == CelestialBodyFrame.ICRF;
74 final String centerName = body.getName();
75 final boolean isCenterEarth = CelestialBodyFactory.EARTH.equals(centerName);
76 final boolean isCenterMars = CelestialBodyFactory.MARS.equals(centerName);
77 final boolean isCenterSsb = CelestialBodyFactory
78 .SOLAR_SYSTEM_BARYCENTER.equals(centerName);
79 if (isIcrf && isCenterSsb) {
80
81 return frame;
82 }
83 if (isIcrf && isCenterEarth) {
84
85
86
87 Frame f = frame;
88 while (f.getDepth() != 0) {
89 f = f.getParent();
90 }
91 return f;
92 }
93 if (!isMci && isCenterEarth || isMci && isCenterMars) {
94
95
96
97
98 return frame;
99 }
100
101 return new ModifiedFrame(frame, celestialBodyFrame,
102 body, center.getName());
103 }
104
105 @Override
106 public int hashCode() {
107 return this.getClass().hashCode();
108 }
109
110 @Override
111 public boolean equals(final Object obj) {
112 return this == obj || this.getClass() == OrekitCcsdsFrameMapper.class &&
113 obj.getClass() == OrekitCcsdsFrameMapper.class;
114 }
115
116 }