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 java.util.Locale;
20 import java.util.function.Function;
21
22 import org.orekit.annotation.DefaultDataContext;
23 import org.orekit.bodies.CelestialBodies;
24 import org.orekit.bodies.CelestialBody;
25 import org.orekit.bodies.CelestialBodyFactory;
26 import org.orekit.data.DataContext;
27 import org.orekit.frames.FactoryManagedFrame;
28 import org.orekit.frames.Frame;
29 import org.orekit.frames.Predefined;
30
31
32
33
34
35 public enum CenterName {
36
37 SOLAR_SYSTEM_BARYCENTER(CelestialBodies::getSolarSystemBarycenter),
38
39
40 SUN(CelestialBodies::getSun),
41
42
43 MERCURY(CelestialBodies::getMercury),
44
45
46 VENUS(CelestialBodies::getVenus),
47
48
49 EARTH_MOON(CelestialBodies::getEarthMoonBarycenter),
50
51
52 EARTH(CelestialBodies::getEarth),
53
54
55 MOON(CelestialBodies::getMoon),
56
57
58 MARS(CelestialBodies::getMars),
59
60
61 JUPITER(CelestialBodies::getJupiter),
62
63
64 SATURN(CelestialBodies::getSaturn),
65
66
67 URANUS(CelestialBodies::getUranus),
68
69
70 NEPTUNE(CelestialBodies::getNeptune),
71
72
73 PLUTO(CelestialBodies::getPluto);
74
75
76 private static final String INERTIAL_FRAME_SUFFIX = "/inertial";
77
78
79 private static final String ROTATING_FRAME_SUFFIX = "/rotating";
80
81
82
83
84
85 private static final Locale STANDARDIZED_LOCALE = Locale.US;
86
87
88
89
90
91 private final transient Function<CelestialBodies, CelestialBody> celestialBodyGetter;
92
93
94
95
96 CenterName(final Function<CelestialBodies, CelestialBody> celestialBodyGetter) {
97 this.celestialBodyGetter = celestialBodyGetter;
98 }
99
100
101
102
103
104
105
106
107
108 @DefaultDataContext
109 public CelestialBody getCelestialBody() {
110 return getCelestialBody(DataContext.getDefault().getCelestialBodies());
111 }
112
113
114
115
116
117
118
119
120 public CelestialBody getCelestialBody(final CelestialBodies celestialBodies) {
121 return celestialBodyGetter.apply(celestialBodies);
122 }
123
124
125
126
127
128
129
130 public static String guessCenter(final Frame frame) {
131 final String name = frame.getName();
132 if (name.endsWith(INERTIAL_FRAME_SUFFIX) || name.endsWith(ROTATING_FRAME_SUFFIX)) {
133 return name.substring(0, name.length() - 9).toUpperCase(STANDARDIZED_LOCALE);
134 } else if (frame instanceof ModifiedFrame) {
135 return ((ModifiedFrame) frame).getCenterName();
136 } else if (frame.getName().equals(Predefined.ICRF.getName())) {
137 return CelestialBodyFactory.SOLAR_SYSTEM_BARYCENTER.toUpperCase(STANDARDIZED_LOCALE);
138 } else if (frame.getDepth() == 0 || frame instanceof FactoryManagedFrame) {
139 return "EARTH";
140 } else {
141 return "UNKNOWN";
142 }
143 }
144
145
146
147
148
149
150
151
152 public static CenterName map(final Frame frame) {
153 try {
154 return CenterName.valueOf(guessCenter(frame));
155 } catch (IllegalArgumentException iae) {
156
157 return null;
158 }
159 }
160
161 }