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

KDE's Doxygen guidelines are available online.