File indexing completed on 2024-04-14 03:48:00

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009 Henry de Valence <hdevalence@gmail.com>
0004 // SPDX-FileCopyrightText: 2009 David Roberts <dvdr18@gmail.com>
0005 // SPDX-FileCopyrightText: 2012 Mohammed Nafees <nafees.technocool@gmail.com>
0006 // SPDX-FileCopyrightText: 2014 Dennis Nienhüser <nienhueser@kde.org>
0007 
0008 #include "PlanetFactory.h"
0009 #include "Planet.h"
0010 #include "MarbleColors.h"
0011 #include "MarbleDebug.h"
0012 #include "MarbleGlobal.h"
0013 
0014 namespace Marble {
0015 
0016 QList<QString> PlanetFactory::planetList()
0017 {
0018     QStringList planets;
0019 
0020     planets << "mercury"
0021     << "venus"
0022     << "earth"
0023     << "mars"
0024     << "jupiter"
0025     << "saturn"
0026     << "uranus"
0027     << "neptune"
0028     << "pluto"
0029     << "sun"
0030     << "moon"
0031     << "sky";
0032 
0033     return planets;
0034 }
0035 
0036 Planet PlanetFactory::construct( const QString &id )
0037 {
0038     Planet planet;
0039     planet.setId( id );
0040 
0041     // constants taken from https://aa.quae.nl/en/reken/zonpositie.html
0042 
0043     if (id == QLatin1String("mercury")) {
0044         planet.setM_0( 174.7948*DEG2RAD );
0045         planet.setM_1( 4.09233445*DEG2RAD );
0046         planet.setC_1( 23.4400*DEG2RAD );
0047         planet.setC_2( 2.9818*DEG2RAD );
0048         planet.setC_3( 0.5255*DEG2RAD );
0049         planet.setC_4( 0.1058*DEG2RAD );
0050         planet.setC_5( 0.0241*DEG2RAD );
0051         planet.setC_6( 0.0055*DEG2RAD );
0052         planet.setPi( 111.5943*DEG2RAD );
0053         planet.setEpsilon( 0.02*DEG2RAD );
0054         planet.setTheta_0( 13.5964*DEG2RAD );
0055         planet.setTheta_1( 6.1385025*DEG2RAD );
0056         planet.setRadius( 2440000.0 );
0057         planet.setName(QStringLiteral("Mercury"));
0058         planet.setHasAtmosphere( false );
0059     } else if (id == QLatin1String("venus")) {
0060         planet.setM_0( 50.4161*DEG2RAD );
0061         planet.setM_1( 1.60213034*DEG2RAD );
0062         planet.setC_1( 0.7758*DEG2RAD );
0063         planet.setC_2( 0.0033*DEG2RAD );
0064         planet.setC_3( 0 );
0065         planet.setC_4( 0 );
0066         planet.setC_5( 0 );
0067         planet.setC_6( 0 );
0068         planet.setPi( 73.9519*DEG2RAD );
0069         planet.setEpsilon( 2.64*DEG2RAD );
0070         planet.setTheta_0( 215.2995*DEG2RAD );
0071         planet.setTheta_1( -1.4813688*DEG2RAD );
0072         planet.setRadius( 6051800.0 );
0073         planet.setTwilightZone(18*DEG2RAD);
0074         planet.setName(QStringLiteral("Venus"));
0075         planet.setHasAtmosphere( true );
0076         planet.setAtmosphereColor( Oxygen::sunYellow4 );
0077     } else if (id == QLatin1String("earth")) {
0078         planet.setM_0( 357.5291*DEG2RAD );
0079         planet.setM_1( 0.98560028*DEG2RAD );
0080         planet.setC_1( 1.9148*DEG2RAD );
0081         planet.setC_2( 0.0200*DEG2RAD );
0082         planet.setC_3( 0.0003*DEG2RAD );
0083         planet.setC_4( 0 );
0084         planet.setC_5( 0 );
0085         planet.setC_6( 0 );
0086         planet.setPi( 102.9372*DEG2RAD );
0087         planet.setEpsilon( 23.43686*DEG2RAD );
0088         planet.setTheta_0( 280.1600*DEG2RAD );
0089         planet.setTheta_1( 360.9856235*DEG2RAD );
0090         planet.setRadius( 6378137.0 );
0091         planet.setTwilightZone(18*DEG2RAD);
0092         planet.setName(QStringLiteral("Earth"));
0093         planet.setHasAtmosphere( true );
0094         planet.setAtmosphereColor( Qt::white );
0095     } else if (id == QLatin1String("mars")) {
0096         planet.setM_0( 19.3730*DEG2RAD );
0097         planet.setM_1( 0.52402068*DEG2RAD );
0098         planet.setC_1( 10.6912*DEG2RAD );
0099         planet.setC_2( 0.6228*DEG2RAD );
0100         planet.setC_3( 0.0503*DEG2RAD );
0101         planet.setC_4( 0.0046*DEG2RAD );
0102         planet.setC_5( 0.0005*DEG2RAD );
0103         planet.setC_6( 0 );
0104         planet.setPi( 70.9812*DEG2RAD );
0105         planet.setEpsilon( 25.19*DEG2RAD );
0106         planet.setTheta_0( 313.4803*DEG2RAD );
0107         planet.setTheta_1( 350.89198226*DEG2RAD );
0108         planet.setRadius( 3397000.0 );
0109         planet.setTwilightZone(9.0*DEG2RAD);
0110         planet.setName(QStringLiteral("Mars"));
0111         planet.setHasAtmosphere( true );
0112         planet.setAtmosphereColor( Oxygen::hotOrange2 );
0113     } else if (id == QLatin1String("jupiter")) {
0114         planet.setM_0( 20.0202*DEG2RAD );
0115         planet.setM_1( 0.08308529*DEG2RAD );
0116         planet.setC_1( 5.5549*DEG2RAD );
0117         planet.setC_2( 0.1683*DEG2RAD );
0118         planet.setC_3( 0.0071*DEG2RAD );
0119         planet.setC_4( 0.0003*DEG2RAD );
0120         planet.setC_5( 0 );
0121         planet.setC_6( 0 );
0122         planet.setPi( 237.2074*DEG2RAD );
0123         planet.setEpsilon( 3.12*DEG2RAD );
0124         planet.setTheta_0( 146.0727*DEG2RAD );
0125         planet.setTheta_1( 870.5366420*DEG2RAD );
0126         planet.setRadius( 71492000.0 );
0127         planet.setName(QStringLiteral("Jupiter"));
0128         planet.setHasAtmosphere( true );
0129         planet.setAtmosphereColor( Oxygen::sunYellow2 );
0130     } else if (id == QLatin1String("saturn")) {
0131         planet.setM_0( 317.0207*DEG2RAD );
0132         planet.setM_1( 0.03344414*DEG2RAD );
0133         planet.setC_1( 6.3585*DEG2RAD );
0134         planet.setC_2( 0.2204*DEG2RAD );
0135         planet.setC_3( 0.0106*DEG2RAD );
0136         planet.setC_4( 0.0006*DEG2RAD );
0137         planet.setC_5( 0 );
0138         planet.setC_6( 0 );
0139         planet.setPi( 99.4571*DEG2RAD );
0140         planet.setEpsilon( 26.74*DEG2RAD );
0141         planet.setTheta_0( 174.3479*DEG2RAD );
0142         planet.setTheta_1( 810.7939024*DEG2RAD );
0143         planet.setRadius( 60268000.0 );
0144         planet.setName(QStringLiteral("Saturn"));
0145         planet.setHasAtmosphere( true );
0146         planet.setAtmosphereColor( Oxygen::sunYellow2 );
0147     } else if (id == QLatin1String("uranus")) {
0148         planet.setM_0( 141.0498*DEG2RAD );
0149         planet.setM_1( 0.01172834*DEG2RAD );
0150         planet.setC_1( 5.3042*DEG2RAD );
0151         planet.setC_2( 0.1534*DEG2RAD );
0152         planet.setC_3( 0.0062*DEG2RAD );
0153         planet.setC_4( 0.0003*DEG2RAD );
0154         planet.setC_5( 0 );
0155         planet.setC_6( 0 );
0156         planet.setPi( 5.4639*DEG2RAD );
0157         planet.setEpsilon( 82.22*DEG2RAD );
0158         planet.setTheta_0( 17.9705*DEG2RAD );
0159         planet.setTheta_1( -501.1600928*DEG2RAD );
0160         planet.setRadius( 25559000.0 );
0161         planet.setName(QStringLiteral("Uranus"));
0162         planet.setHasAtmosphere( true );
0163         planet.setAtmosphereColor( Oxygen::seaBlue4 );
0164     } else if (id == QLatin1String("neptune")) {
0165         planet.setM_0( 256.2250*DEG2RAD );
0166         planet.setM_1( 0.00598103*DEG2RAD );
0167         planet.setC_1( 1.0302*DEG2RAD );
0168         planet.setC_2( 0.0058*DEG2RAD );
0169         planet.setC_3( 0 );
0170         planet.setC_4( 0 );
0171         planet.setC_5( 0 );
0172         planet.setC_6( 0 );
0173         planet.setPi( 182.1957*DEG2RAD );
0174         planet.setEpsilon( 27.84*DEG2RAD );
0175         planet.setTheta_0( 52.3996*DEG2RAD );
0176         planet.setTheta_1( 536.3128492*DEG2RAD );
0177         planet.setRadius( 24766000.0 );
0178         planet.setName(QStringLiteral("Neptune"));
0179         planet.setHasAtmosphere( true );
0180         planet.setAtmosphereColor( Oxygen::skyBlue2 );
0181     } else if (id == QLatin1String("pluto")) {
0182         // dwarf planets ... (everybody likes pluto)
0183         planet.setM_0( 14.882*DEG2RAD );
0184         planet.setM_1( 0.00396*DEG2RAD );
0185         planet.setC_1( 28.3150*DEG2RAD );
0186         planet.setC_2( 4.3408*DEG2RAD );
0187         planet.setC_3( 0.9214*DEG2RAD );
0188         planet.setC_4( 0.2235*DEG2RAD );
0189         planet.setC_5( 0.0627*DEG2RAD );
0190         planet.setC_6( 0.0174*DEG2RAD );
0191         planet.setPi( 4.5433*DEG2RAD );
0192         planet.setEpsilon( 57.46*DEG2RAD );
0193         planet.setTheta_0( 56.3183*DEG2RAD );
0194         planet.setTheta_1( -56.3623195*DEG2RAD );
0195         planet.setRadius( 1151000.0 );
0196         planet.setName(QStringLiteral("Pluto"));
0197         planet.setHasAtmosphere( false );
0198     } else if (id == QLatin1String("sun")) {
0199         mDebug() << "WARNING: Creating Planet instance" << id << "with invalid orbital elements";
0200         planet.setRadius( 695000000.0 );
0201         //FIXME: fill in with valid data
0202         planet.setName(QStringLiteral("Sun"));
0203         planet.setHasAtmosphere( true );
0204         planet.setAtmosphereColor( Qt::white );
0205     } else if (id == QLatin1String("moon")) {
0206         mDebug() << "WARNING: Creating Planet instance" << id << "with invalid orbital elements";
0207         planet.setRadius( 1738000.0 );
0208         //FIXME: fill in with valid data
0209         planet.setName(QStringLiteral("Moon"));
0210         planet.setHasAtmosphere( false );
0211     } else if (id == QLatin1String("sky")) {
0212         mDebug() << "WARNING: Creating Planet instance" << id << "with invalid orbital elements";
0213         planet.setRadius( 10000000.0 );
0214         planet.setName(QStringLiteral("Sky"));
0215         planet.setHasAtmosphere( false );
0216     } else {
0217         mDebug() << "WARNING: Creating Planet instance" << id << "with invalid orbital elements";
0218         planet.setRadius( 10000000.0 );
0219         planet.setName(QStringLiteral("Unknown"));
0220         planet.setHasAtmosphere( false );
0221     }
0222 
0223     return planet;
0224 }
0225 
0226 QString PlanetFactory::localizedName( const QString &id )
0227 {
0228     if (id == QLatin1String("mercury")) {
0229         return QObject::tr("Mercury", "the planet");
0230     } else if (id == QLatin1String("venus")) {
0231         return QObject::tr("Venus", "the planet");
0232     } else if (id == QLatin1String("earth")) {
0233         return QObject::tr("Earth", "the planet");
0234     } else if (id == QLatin1String("mars")) {
0235         return QObject::tr("Mars", "the planet");
0236     } else if (id == QLatin1String("jupiter")) {
0237         return QObject::tr("Jupiter", "the planet");
0238     } else if (id == QLatin1String("saturn")) {
0239         return QObject::tr("Saturn", "the planet");
0240     } else if (id == QLatin1String("uranus")) {
0241         return QObject::tr("Uranus", "the planet");
0242     } else if (id == QLatin1String("neptune")) {
0243         return QObject::tr("Neptune", "the planet");
0244     // dwarf planets ... (everybody likes pluto)
0245     } else if (id == QLatin1String("pluto")) {
0246         return QObject::tr("Pluto", "the planet");
0247     // sun, moon and sky
0248     } else if (id == QLatin1String("sun")) {
0249         return QObject::tr("Sun", "the earth's star");
0250     } else if (id == QLatin1String("moon")) {
0251         return QObject::tr("Moon", "the earth's moon");
0252     } else if (id == QLatin1String("sky")) {
0253         return QObject::tr("Sky");
0254     } else if ( id.isEmpty() ) {
0255         mDebug() << "Warning: empty id";
0256         return QObject::tr("Unknown Planet", "a planet without data");
0257     }
0258 
0259     return id;
0260 }
0261 
0262 }