File indexing completed on 2025-01-05 03:58:41

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