File indexing completed on 2024-04-14 03:47:59
0001 //SPDX-FileCopyrightText: 2009 Henry de Valence <hdevalence@gmail.com> 0002 //SPDX-FileCopyrightText: 2009 David Roberts <dvdr18@gmail.com> 0003 //SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com> 0004 // SPDX-License-Identifier: LGPL-2.1-or-later 0005 // 0006 #include "Planet.h" 0007 0008 #include "PlanetFactory.h" 0009 #include "MarbleDebug.h" 0010 #include "MarbleGlobal.h" 0011 #include "MarbleColors.h" 0012 0013 #include "src/lib/astro/solarsystem.h" 0014 0015 #include <QDateTime> 0016 #include <QString> 0017 0018 namespace Marble 0019 { 0020 0021 class PlanetPrivate 0022 { 0023 public: 0024 qreal M_0, M_1; // for calculating mean anomaly 0025 qreal C_1, C_2, C_3, C_4, C_5, C_6; // for calculating equation of center 0026 qreal Pi; // ecliptic longitude of the perihelion 0027 qreal epsilon; // obliquity of the ecliptic plane 0028 qreal theta_0, theta_1; // for calculating sidereal time 0029 qreal radius; //in metres 0030 qreal twilightZone; 0031 QString name, id; //localized and nonlocalized names 0032 bool atmosphere; 0033 QColor atmosphereColor; 0034 PlanetPrivate() : 0035 M_0(0.0), M_1(0.0), 0036 C_1(0.0), C_2(0.0), C_3(0.0), C_4(0.0), C_5(0.0), C_6(0.0), 0037 Pi(0.0), epsilon(0.0), 0038 theta_0(0.0), theta_1(0.0), 0039 radius(10000000.0), 0040 twilightZone(0), 0041 name(), id(), 0042 atmosphere(false) 0043 { 0044 // nothing to do 0045 } 0046 }; 0047 0048 0049 //Constructor 0050 Planet::Planet() 0051 : d( new PlanetPrivate ) 0052 { 0053 // nothing to do 0054 } 0055 0056 Planet::Planet( const QString& id ) 0057 : d( new PlanetPrivate ) 0058 { 0059 *this = PlanetFactory::construct( id ); 0060 } 0061 0062 //Copy Constructor 0063 Planet::Planet( const Planet& other ) 0064 : d( new PlanetPrivate ) 0065 { 0066 // PlanetPrivate does not have pointer members, so we can just 0067 // use its (compiler generated) assignment operator. 0068 *d = *other.d; 0069 } 0070 0071 //Destructor 0072 Planet::~Planet() 0073 { 0074 delete d; 0075 } 0076 0077 0078 /* Getter functions */ 0079 // for calculating mean anomaly 0080 qreal Planet::M_0() const 0081 { 0082 return d->M_0; 0083 } 0084 qreal Planet::M_1() const 0085 { 0086 return d->M_1; 0087 } 0088 0089 // for calculating equation of center 0090 qreal Planet::C_1() const 0091 { 0092 return d->C_1; 0093 } 0094 qreal Planet::C_2() const 0095 { 0096 return d->C_2; 0097 } 0098 qreal Planet::C_3() const 0099 { 0100 return d->C_3; 0101 } 0102 qreal Planet::C_4() const 0103 { 0104 return d->C_4; 0105 } 0106 qreal Planet::C_5() const 0107 { 0108 return d->C_5; 0109 } 0110 qreal Planet::C_6() const 0111 { 0112 return d->C_6; 0113 } 0114 0115 // ecliptic longitude of the perihelion 0116 qreal Planet::Pi() const 0117 { 0118 return d->Pi; 0119 } 0120 0121 // obliquity of the ecliptic plane 0122 qreal Planet::epsilon() const 0123 { 0124 return d->epsilon; 0125 } 0126 0127 // for calculating sidereal time 0128 qreal Planet::theta_0() const 0129 { 0130 return d->theta_0; 0131 } 0132 qreal Planet::theta_1() const 0133 { 0134 return d->theta_1; 0135 } 0136 0137 // the radius of the planet, in metres 0138 qreal Planet::radius() const 0139 { 0140 return d->radius; 0141 } 0142 0143 qreal Planet::twilightZone() const 0144 { 0145 return d->twilightZone; 0146 } 0147 0148 0149 QString Planet::name() const 0150 { 0151 return d->name; 0152 } 0153 0154 QString Planet::id() const 0155 { 0156 return d->id; 0157 } 0158 0159 void Planet::sunPosition(qreal &lon, qreal &lat, const QDateTime &dateTime) const 0160 { 0161 SolarSystem sys; 0162 sys.setCurrentMJD( 0163 dateTime.date().year(), dateTime.date().month(), dateTime.date().day(), 0164 dateTime.time().hour(), dateTime.time().minute(), 0165 (double)dateTime.time().second()); 0166 const QString pname = d->id.at(0).toUpper() + d->id.right(d->id.size() - 1); 0167 QByteArray name = pname.toLatin1(); 0168 sys.setCentralBody( name.data() ); 0169 0170 double ra = 0.0; 0171 double decl = 0.0; 0172 sys.getSun(ra, decl); 0173 0174 double _lon = 0.0; 0175 double _lat = 0.0; 0176 sys.getPlanetographic(ra, decl, _lon, _lat); 0177 0178 lon = _lon * DEG2RAD; 0179 lat = _lat * DEG2RAD; 0180 } 0181 0182 /* Setter functions */ 0183 void Planet::setM_0( qreal M_0 ) 0184 { 0185 d->M_0 = M_0; 0186 } 0187 void Planet::setM_1( qreal M_1 ) 0188 { 0189 d->M_1 = M_1; 0190 } 0191 0192 void Planet::setC_1( qreal C_1 ) 0193 { 0194 d->C_1 = C_1; 0195 } 0196 void Planet::setC_2( qreal C_2 ) 0197 { 0198 d->C_2 = C_2; 0199 } 0200 void Planet::setC_3( qreal C_3 ) 0201 { 0202 d->C_3 = C_3; 0203 } 0204 void Planet::setC_4( qreal C_4 ) 0205 { 0206 d->C_4 = C_4; 0207 } 0208 void Planet::setC_5( qreal C_5 ) 0209 { 0210 d->C_5 = C_5; 0211 } 0212 void Planet::setC_6( qreal C_6 ) 0213 { 0214 d->C_6 = C_6; 0215 } 0216 0217 void Planet::setPi( qreal Pi ) 0218 { 0219 d->Pi = Pi; 0220 } 0221 0222 void Planet::setEpsilon( qreal epsilon ) 0223 { 0224 d->epsilon = epsilon; 0225 } 0226 0227 void Planet::setTheta_0( qreal theta_0 ) 0228 { 0229 d->theta_0 = theta_0; 0230 } 0231 void Planet::setTheta_1( qreal theta_1 ) 0232 { 0233 d->theta_1 = theta_1; 0234 } 0235 0236 void Planet::setRadius( qreal radius ) 0237 { 0238 d->radius = radius; 0239 } 0240 0241 void Planet::setTwilightZone(qreal twilightZone) 0242 { 0243 d->twilightZone = twilightZone; 0244 } 0245 0246 void Planet::setName( const QString& name ) 0247 { 0248 d->name = name; 0249 } 0250 0251 void Planet::setId( const QString& id ) 0252 { 0253 d->id = id; 0254 } 0255 0256 0257 QString Planet::name( const QString& id ) 0258 { 0259 return PlanetFactory::localizedName( id ); 0260 } 0261 0262 QStringList Planet::planetList() 0263 { 0264 return PlanetFactory::planetList(); 0265 } 0266 0267 Planet& Planet::operator=(const Planet& rhs) 0268 { 0269 // PlanetPrivate does not have pointer members, so we can just 0270 // use its (compiler generated) assignment operator. 0271 *d = *rhs.d; 0272 return *this; 0273 } 0274 0275 bool Planet::hasAtmosphere() const 0276 { 0277 return d->atmosphere; 0278 } 0279 0280 void Planet::setHasAtmosphere(bool enabled) 0281 { 0282 d->atmosphere = enabled; 0283 } 0284 0285 QColor Planet::atmosphereColor() const 0286 { 0287 return d->atmosphereColor; 0288 } 0289 0290 void Planet::setAtmosphereColor(const QColor &color) 0291 { 0292 d->atmosphereColor = color; 0293 } 0294 0295 } //namespace Marble 0296