Marble

Planet.cpp
1 //SPDX-FileCopyrightText: 2009 Henry de Valence <[email protected]>
2 //SPDX-FileCopyrightText: 2009 David Roberts <[email protected]>
3 //SPDX-FileCopyrightText: 2012 Mohammed Nafees <[email protected]>
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 
18 namespace Marble
19 {
20 
21 class PlanetPrivate
22 {
23 public:
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
50 Planet::Planet()
51  : d( new PlanetPrivate )
52 {
53  // nothing to do
54 }
55 
56 Planet::Planet( const QString& id )
57  : d( new PlanetPrivate )
58 {
59  *this = PlanetFactory::construct( id );
60 }
61 
62 //Copy Constructor
63 Planet::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
72 Planet::~Planet()
73 {
74  delete d;
75 }
76 
77 
78  /* Getter functions */
79  // for calculating mean anomaly
80 qreal Planet::M_0() const
81 {
82  return d->M_0;
83 }
84 qreal Planet::M_1() const
85 {
86  return d->M_1;
87 }
88 
89  // for calculating equation of center
90 qreal Planet::C_1() const
91 {
92  return d->C_1;
93 }
94 qreal Planet::C_2() const
95 {
96  return d->C_2;
97 }
98 qreal Planet::C_3() const
99 {
100  return d->C_3;
101 }
102 qreal Planet::C_4() const
103 {
104  return d->C_4;
105 }
106 qreal Planet::C_5() const
107 {
108  return d->C_5;
109 }
110 qreal Planet::C_6() const
111 {
112  return d->C_6;
113 }
114 
115  // ecliptic longitude of the perihelion
116 qreal Planet::Pi() const
117 {
118  return d->Pi;
119 }
120 
121  // obliquity of the ecliptic plane
122 qreal Planet::epsilon() const
123 {
124  return d->epsilon;
125 }
126 
127  // for calculating sidereal time
128 qreal Planet::theta_0() const
129 {
130  return d->theta_0;
131 }
132 qreal Planet::theta_1() const
133 {
134  return d->theta_1;
135 }
136 
137  // the radius of the planet, in metres
138 qreal Planet::radius() const
139 {
140  return d->radius;
141 }
142 
143 qreal Planet::twilightZone() const
144 {
145  return d->twilightZone;
146 }
147 
148 
149 QString Planet::name() const
150 {
151  return d->name;
152 }
153 
154 QString Planet::id() const
155 {
156  return d->id;
157 }
158 
159 void 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 */
183 void Planet::setM_0( qreal M_0 )
184 {
185  d->M_0 = M_0;
186 }
187 void Planet::setM_1( qreal M_1 )
188 {
189  d->M_1 = M_1;
190 }
191 
192 void Planet::setC_1( qreal C_1 )
193 {
194  d->C_1 = C_1;
195 }
196 void Planet::setC_2( qreal C_2 )
197 {
198  d->C_2 = C_2;
199 }
200 void Planet::setC_3( qreal C_3 )
201 {
202  d->C_3 = C_3;
203 }
204 void Planet::setC_4( qreal C_4 )
205 {
206  d->C_4 = C_4;
207 }
208 void Planet::setC_5( qreal C_5 )
209 {
210  d->C_5 = C_5;
211 }
212 void Planet::setC_6( qreal C_6 )
213 {
214  d->C_6 = C_6;
215 }
216 
217 void Planet::setPi( qreal Pi )
218 {
219  d->Pi = Pi;
220 }
221 
222 void Planet::setEpsilon( qreal epsilon )
223 {
224  d->epsilon = epsilon;
225 }
226 
227 void Planet::setTheta_0( qreal theta_0 )
228 {
229  d->theta_0 = theta_0;
230 }
231 void Planet::setTheta_1( qreal theta_1 )
232 {
233  d->theta_1 = theta_1;
234 }
235 
236 void Planet::setRadius( qreal radius )
237 {
238  d->radius = radius;
239 }
240 
241 void Planet::setTwilightZone(qreal twilightZone)
242 {
243  d->twilightZone = twilightZone;
244 }
245 
246 void Planet::setName( const QString& name )
247 {
248  d->name = name;
249 }
250 
251 void Planet::setId( const QString& id )
252 {
253  d->id = id;
254 }
255 
256 
257 QString Planet::name( const QString& id )
258 {
259  return PlanetFactory::localizedName( id );
260 }
261 
262 QStringList Planet::planetList()
263 {
264  return PlanetFactory::planetList();
265 }
266 
267 Planet& 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 
275 bool Planet::hasAtmosphere() const
276 {
277  return d->atmosphere;
278 }
279 
280 void Planet::setHasAtmosphere(bool enabled)
281 {
282  d->atmosphere = enabled;
283 }
284 
285 QColor Planet::atmosphereColor() const
286 {
287  return d->atmosphereColor;
288 }
289 
290 void Planet::setAtmosphereColor(const QColor &color)
291 {
292  d->atmosphereColor = color;
293 }
294 
295 } //namespace Marble
296 
int month() const const
static QString localizedName(const QString &id)
Returns a localized name of the planet with the given ID.
QTime time() const const
int year() const const
QChar toUpper() const const
QByteArray toLatin1() const const
static Planet construct(const QString &id)
Creates the planet with the given ID, or one with default values if ID is not among planetList()
static QList< QString > planetList()
Provides a list of known planet IDs.
Binds a QML item to a specific geodetic location in screen coordinates.
int hour() const const
int second() const const
QString name(StandardShortcut id)
QDate date() const const
const QChar at(int position) const const
QChar * data()
int minute() const const
int day() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Oct 2 2023 03:52:09 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.