File indexing completed on 2024-07-14 07:17:24

0001 /*
0002     SPDX-FileCopyrightText: 2005 Thomas Kabelmann <thomas.kabelmann@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "solarsystemcomposite.h"
0008 
0009 #include "asteroidscomponent.h"
0010 #include "cometscomponent.h"
0011 #include "kstarsdata.h"
0012 #include "Options.h"
0013 #ifndef KSTARS_LITE
0014 #include "skymap.h"
0015 #endif
0016 #include "solarsystemsinglecomponent.h"
0017 #include "earthshadowcomponent.h"
0018 #include "skyobjects/ksmoon.h"
0019 #include "skyobjects/ksplanet.h"
0020 #include "skyobjects/kssun.h"
0021 #include "skyobjects/ksearthshadow.h"
0022 
0023 SolarSystemComposite::SolarSystemComposite(SkyComposite *parent) : SkyComposite(parent)
0024 {
0025     emitProgressText(i18n("Loading solar system"));
0026     m_Earth = new KSPlanet(i18n("Earth"), QString(), QColor("white"), 12756.28 /*diameter in km*/);
0027     m_Sun                           = new KSSun();
0028     SolarSystemSingleComponent *sun = new SolarSystemSingleComponent(this, m_Sun, Options::showSun);
0029     addComponent(sun, 2);
0030     m_Moon                           = new KSMoon();
0031     SolarSystemSingleComponent *moon = new SolarSystemSingleComponent(this, m_Moon, Options::showMoon, true);
0032     addComponent(moon, 3);
0033     m_EarthShadow = new KSEarthShadow(m_Moon, m_Sun, m_Earth);
0034     EarthShadowComponent * shadow = new EarthShadowComponent(this, m_EarthShadow);
0035     addComponent(shadow);
0036     SolarSystemSingleComponent *mercury =
0037         new SolarSystemSingleComponent(this, new KSPlanet(KSPlanetBase::MERCURY), Options::showMercury);
0038     addComponent(mercury, 4);
0039     SolarSystemSingleComponent *venus =
0040         new SolarSystemSingleComponent(this, new KSPlanet(KSPlanetBase::VENUS), Options::showVenus);
0041     addComponent(venus, 4);
0042     SolarSystemSingleComponent *mars =
0043         new SolarSystemSingleComponent(this, new KSPlanet(KSPlanetBase::MARS), Options::showMars);
0044     addComponent(mars, 4);
0045     SolarSystemSingleComponent *jup =
0046         new SolarSystemSingleComponent(this, new KSPlanet(KSPlanetBase::JUPITER), Options::showJupiter);
0047     addComponent(jup, 4);
0048     /*
0049     m_JupiterMoons = new PlanetMoonsComponent( this, jup, KSPlanetBase::JUPITER);
0050     addComponent( m_JupiterMoons, 5 );
0051     */
0052     SolarSystemSingleComponent *sat =
0053         new SolarSystemSingleComponent(this, new KSPlanet(KSPlanetBase::SATURN), Options::showSaturn);
0054     addComponent(sat, 4);
0055     SolarSystemSingleComponent *uranus =
0056         new SolarSystemSingleComponent(this, new KSPlanet(KSPlanetBase::URANUS), Options::showUranus);
0057     addComponent(uranus, 4);
0058     SolarSystemSingleComponent *nep =
0059         new SolarSystemSingleComponent(this, new KSPlanet(KSPlanetBase::NEPTUNE), Options::showNeptune);
0060     addComponent(nep, 4);
0061     //addComponent( new SolarSystemSingleComponent( this, new KSPluto(), Options::showPluto ) );
0062 
0063     m_planets.append(sun);
0064     m_planets.append(moon);
0065     m_planets.append(mercury);
0066     m_planets.append(venus);
0067     m_planets.append(mars);
0068     m_planets.append(sat);
0069     m_planets.append(jup);
0070     m_planets.append(uranus);
0071     m_planets.append(nep);
0072 
0073     /*m_planetObjects.append(sun->planet());
0074     m_planetObjects.append(moon->planet());
0075     m_planetObjects.append(mercury->planet());
0076     m_planetObjects.append(venus->planet());
0077     m_planetObjects.append(mars->planet());
0078     m_planetObjects.append(sat->planet());
0079     m_planetObjects.append(jup->planet());
0080     m_planetObjects.append(uranus->planet());
0081     m_planetObjects.append(nep->planet());
0082 
0083     foreach(PlanetMoonsComponent *pMoons, planetMoonsComponent()) {
0084         PlanetMoons *moons = pMoons->getMoons();
0085         for(int i = 0; i < moons->nMoons(); ++i) {
0086             SkyObject *moon = moons->moon(i);
0087             objectLists(SkyObject::MOON).append(QPair<QString, const SkyObject*>(moon->name(), moon));
0088         }
0089     }*/
0090 
0091     addComponent(m_AsteroidsComponent = new AsteroidsComponent(this), 7);
0092     addComponent(m_CometsComponent = new CometsComponent(this), 7);
0093 }
0094 
0095 SolarSystemComposite::~SolarSystemComposite()
0096 {
0097     delete (m_EarthShadow);
0098 }
0099 
0100 bool SolarSystemComposite::selected()
0101 {
0102 #ifndef KSTARS_LITE
0103     return Options::showSolarSystem() && !(Options::hideOnSlew() && Options::hidePlanets() && SkyMap::IsSlewing());
0104 #else
0105     return Options::showSolarSystem() && !(Options::hideOnSlew() && Options::hidePlanets());
0106 #endif
0107 }
0108 
0109 void SolarSystemComposite::update(KSNumbers *num)
0110 {
0111     //    if ( ! selected() ) return;
0112 
0113     KStarsData *data = KStarsData::Instance();
0114     m_Sun->EquatorialToHorizontal(data->lst(), data->geo()->lat());
0115     m_Moon->EquatorialToHorizontal(data->lst(), data->geo()->lat());
0116     //    m_JupiterMoons->update( num );
0117 
0118     foreach (SkyComponent *comp, components())
0119     {
0120         comp->update(num);
0121     }
0122 }
0123 
0124 void SolarSystemComposite::updateSolarSystemBodies(KSNumbers *num)
0125 {
0126     m_Earth->findPosition(num);
0127     foreach (SkyComponent *comp, components())
0128     {
0129         comp->updateSolarSystemBodies(num);
0130     }
0131 }
0132 
0133 void SolarSystemComposite::updateMoons(KSNumbers *num)
0134 {
0135     //    if ( ! selected() ) return;
0136     m_Earth->findPosition(num);
0137     foreach (SkyComponent *comp, components())
0138     {
0139         comp->updateMoons(num);
0140     }
0141     //    m_JupiterMoons->updateMoons( num );
0142 }
0143 
0144 void SolarSystemComposite::drawTrails(SkyPainter *skyp)
0145 {
0146     if (selected())
0147         foreach (SkyComponent *comp, components())
0148             comp->drawTrails(skyp);
0149 }
0150 
0151 const QList<SkyObject *> &SolarSystemComposite::asteroids() const
0152 {
0153     return m_AsteroidsComponent->objectList();
0154 }
0155 
0156 const QList<SkyObject *> &SolarSystemComposite::comets() const
0157 {
0158     return m_CometsComponent->objectList();
0159 }
0160 
0161 const QList<SkyObject *> &SolarSystemComposite::planetObjects() const
0162 {
0163     return m_planetObjects;
0164 }
0165 
0166 const QList<SkyObject *> &SolarSystemComposite::moons() const
0167 {
0168     return m_moons;
0169 }
0170 
0171 CometsComponent *SolarSystemComposite::cometsComponent()
0172 {
0173     return m_CometsComponent;
0174 }
0175 
0176 AsteroidsComponent *SolarSystemComposite::asteroidsComponent()
0177 {
0178     return m_AsteroidsComponent;
0179 }
0180 
0181 const QList<SolarSystemSingleComponent *> &SolarSystemComposite::planets() const
0182 {
0183     return m_planets;
0184 }
0185 
0186 /*
0187 QList<PlanetMoonsComponent *> SolarSystemComposite::planetMoonsComponent() const
0188 {
0189     return QList <PlanetMoonsComponent *>({m_JupiterMoons});
0190 }
0191 */