Marble

Planet.cpp
1// SPDX-FileCopyrightText: 2009 Henry de Valence <hdevalence@gmail.com>
2// SPDX-FileCopyrightText: 2009 David Roberts <dvdr18@gmail.com>
3// SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
4// SPDX-License-Identifier: LGPL-2.1-or-later
5//
6#include "Planet.h"
7
8#include "MarbleColors.h"
9#include "MarbleDebug.h"
10#include "MarbleGlobal.h"
11#include "PlanetFactory.h"
12
13#include "src/lib/astro/solarsystem.h"
14
15#include <QString>
16
17namespace Marble
18{
19
20class PlanetPrivate
21{
22public:
23 qreal M_0, M_1; // for calculating mean anomaly
24 qreal C_1, C_2, C_3, C_4, C_5, C_6; // for calculating equation of center
25 qreal Pi; // ecliptic longitude of the perihelion
26 qreal epsilon; // obliquity of the ecliptic plane
27 qreal theta_0, theta_1; // for calculating sidereal time
28 qreal radius; // in metres
29 qreal twilightZone;
30 QString name, id; // localized and nonlocalized names
31 bool atmosphere;
32 QColor atmosphereColor;
33 PlanetPrivate()
34 : M_0(0.0)
35 , M_1(0.0)
36 , C_1(0.0)
37 , C_2(0.0)
38 , C_3(0.0)
39 , C_4(0.0)
40 , C_5(0.0)
41 , C_6(0.0)
42 , Pi(0.0)
43 , epsilon(0.0)
44 , theta_0(0.0)
45 , theta_1(0.0)
46 , radius(10000000.0)
47 , twilightZone(0)
48 , name()
49 , id()
50 , atmosphere(false)
51 {
52 // nothing to do
53 }
54};
55
56// Constructor
57Planet::Planet()
58 : d(new PlanetPrivate)
59{
60 // nothing to do
61}
62
63Planet::Planet(const QString &id)
64 : d(new PlanetPrivate)
65{
66 *this = PlanetFactory::construct(id);
67}
68
69// Copy Constructor
70Planet::Planet(const Planet &other)
71 : d(new PlanetPrivate)
72{
73 // PlanetPrivate does not have pointer members, so we can just
74 // use its (compiler generated) assignment operator.
75 *d = *other.d;
76}
77
78// Destructor
79Planet::~Planet()
80{
81 delete d;
82}
83
84/* Getter functions */
85// for calculating mean anomaly
86qreal Planet::M_0() const
87{
88 return d->M_0;
89}
90qreal Planet::M_1() const
91{
92 return d->M_1;
93}
94
95// for calculating equation of center
96qreal Planet::C_1() const
97{
98 return d->C_1;
99}
100qreal Planet::C_2() const
101{
102 return d->C_2;
103}
104qreal Planet::C_3() const
105{
106 return d->C_3;
107}
108qreal Planet::C_4() const
109{
110 return d->C_4;
111}
112qreal Planet::C_5() const
113{
114 return d->C_5;
115}
116qreal Planet::C_6() const
117{
118 return d->C_6;
119}
120
121// ecliptic longitude of the perihelion
122qreal Planet::Pi() const
123{
124 return d->Pi;
125}
126
127// obliquity of the ecliptic plane
128qreal Planet::epsilon() const
129{
130 return d->epsilon;
131}
132
133// for calculating sidereal time
134qreal Planet::theta_0() const
135{
136 return d->theta_0;
137}
138qreal Planet::theta_1() const
139{
140 return d->theta_1;
141}
142
143// the radius of the planet, in metres
144qreal Planet::radius() const
145{
146 return d->radius;
147}
148
149qreal Planet::twilightZone() const
150{
151 return d->twilightZone;
152}
153
154QString Planet::name() const
155{
156 return d->name;
157}
158
159QString Planet::id() const
160{
161 return d->id;
162}
163
164void Planet::sunPosition(qreal &lon, qreal &lat, const QDateTime &dateTime) const
165{
166 SolarSystem sys;
167 sys.setCurrentMJD(dateTime.date().year(),
168 dateTime.date().month(),
169 dateTime.date().day(),
170 dateTime.time().hour(),
171 dateTime.time().minute(),
172 (double)dateTime.time().second());
173 const QString pname = d->id.at(0).toUpper() + d->id.right(d->id.size() - 1);
174 QByteArray name = pname.toLatin1();
175 sys.setCentralBody(name.data());
176
177 double ra = 0.0;
178 double decl = 0.0;
179 sys.getSun(ra, decl);
180
181 double _lon = 0.0;
182 double _lat = 0.0;
183 sys.getPlanetographic(ra, decl, _lon, _lat);
184
185 lon = _lon * DEG2RAD;
186 lat = _lat * DEG2RAD;
187}
188
189/* Setter functions */
190void Planet::setM_0(qreal M_0)
191{
192 d->M_0 = M_0;
193}
194void Planet::setM_1(qreal M_1)
195{
196 d->M_1 = M_1;
197}
198
199void Planet::setC_1(qreal C_1)
200{
201 d->C_1 = C_1;
202}
203void Planet::setC_2(qreal C_2)
204{
205 d->C_2 = C_2;
206}
207void Planet::setC_3(qreal C_3)
208{
209 d->C_3 = C_3;
210}
211void Planet::setC_4(qreal C_4)
212{
213 d->C_4 = C_4;
214}
215void Planet::setC_5(qreal C_5)
216{
217 d->C_5 = C_5;
218}
219void Planet::setC_6(qreal C_6)
220{
221 d->C_6 = C_6;
222}
223
224void Planet::setPi(qreal Pi)
225{
226 d->Pi = Pi;
227}
228
229void Planet::setEpsilon(qreal epsilon)
230{
231 d->epsilon = epsilon;
232}
233
234void Planet::setTheta_0(qreal theta_0)
235{
236 d->theta_0 = theta_0;
237}
238void Planet::setTheta_1(qreal theta_1)
239{
240 d->theta_1 = theta_1;
241}
242
243void Planet::setRadius(qreal radius)
244{
245 d->radius = radius;
246}
247
248void Planet::setTwilightZone(qreal twilightZone)
249{
250 d->twilightZone = twilightZone;
251}
252
253void Planet::setName(const QString &name)
254{
255 d->name = name;
256}
257
258void Planet::setId(const QString &id)
259{
260 d->id = id;
261}
262
263QString Planet::name(const QString &id)
264{
265 return PlanetFactory::localizedName(id);
266}
267
268QStringList Planet::planetList()
269{
270 return PlanetFactory::planetList();
271}
272
273Planet &Planet::operator=(const Planet &rhs)
274{
275 // PlanetPrivate does not have pointer members, so we can just
276 // use its (compiler generated) assignment operator.
277 *d = *rhs.d;
278 return *this;
279}
280
281bool Planet::hasAtmosphere() const
282{
283 return d->atmosphere;
284}
285
286void Planet::setHasAtmosphere(bool enabled)
287{
288 d->atmosphere = enabled;
289}
290
291QColor Planet::atmosphereColor() const
292{
293 return d->atmosphereColor;
294}
295
296void Planet::setAtmosphereColor(const QColor &color)
297{
298 d->atmosphereColor = color;
299}
300
301} // namespace Marble
QString name(GameStandardAction id)
Binds a QML item to a specific geodetic location in screen coordinates.
char32_t toUpper(char32_t ucs4)
int day() const const
int month() const const
int year() const const
QDate date() const const
QTime time() const const
const QChar at(qsizetype position) const const
QChar * data()
QByteArray toLatin1() const const
int hour() const const
int minute() const const
int second() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.