Kstars

planetmoonscomponent.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Vipul Kumar Singh Médéric Boquien <vipulkrsingh@gmail.com, mboquien@free.fr>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "planetmoonscomponent.h"
8
9#include "kstarsdata.h"
10#include "Options.h"
11#include "skylabeler.h"
12#include "skypainter.h"
13#include "kssun.h"
14#include "solarsystemcomposite.h"
15#include "solarsystemsinglecomponent.h"
16#include "projections/projector.h"
17#include "skyobjects/jupitermoons.h"
18
20 KSPlanetBase::Planets &_planet)
21 : SkyComponent(p), planet(_planet), m_Planet(planetComponent)
22{
23 /*
24 if (planet == KSPlanetBase::JUPITER)
25 pmoons = new JupiterMoons();
26 else
27 pmoons = new SaturnMoons();
28 */
29 Q_ASSERT(planet == KSPlanetBase::JUPITER);
30 // delete pmoons;
31 // pmoons = new JupiterMoons();
32 // int nmoons = pmoons->nMoons();
33
34 // for (int i = 0; i < nmoons; ++i)
35 // {
36 // objectNames(SkyObject::MOON).append( pmoons->name(i) );
37 // objectLists(SkyObject::MOON).append( QPair<QString, const SkyObject*>(pmoons->name(i),pmoons->moon(i)) );
38 // }
39}
40
42{
43 return m_Planet->selected();
44}
45
46#ifndef KSTARS_LITE
48{
49 KStarsData *data = KStarsData::Instance();
50 if (selected())
51 pmoons->EquatorialToHorizontal(data->lst(), data->geo()->lat());
52}
53#endif
54
55void PlanetMoonsComponent::updateMoons(KSNumbers *num)
56{
57 //FIXME: evil cast
58 if (selected())
59 pmoons->findPosition(num, m_Planet->planet(), dynamic_cast<KSSun *>(parent()->findByName(i18n("Sun"))));
60}
61
63{
64 Q_UNUSED(exact)
65 int nmoons = pmoons->nMoons();
66
67 for (int i = 0; i < nmoons; ++i)
68 {
69 TrailObject *moon = pmoons->moon(i);
70 if (QString::compare(moon->name(), name, Qt::CaseInsensitive) == 0 ||
71 QString::compare(moon->longname(), name, Qt::CaseInsensitive) == 0 ||
72 QString::compare(moon->name2(), name, Qt::CaseInsensitive) == 0)
73 return moon;
74 }
75
76 return nullptr;
77}
78
79#ifdef KSTARS_LITE
81{
82 return m_Planet->planet();
83}
84#endif
85
87{
88 SkyObject *oBest = nullptr;
89 int nmoons = pmoons->nMoons();
90
91 if (Options::zoomFactor() < 3000)
92 return nullptr;
93
94 for (int i = 0; i < nmoons; ++i)
95 {
96 SkyObject *moon = pmoons->moon(i);
97 double r = moon->angularDistanceTo(p).Degrees();
98 if (r < maxrad)
99 {
100 maxrad = r;
101 oBest = moon;
102 }
103 }
104 return oBest;
105}
106
108{
109 if (!(planet == KSPlanetBase::JUPITER && Options::showJupiter()))
110 return;
111
112 //In order to get the z-order right for the moons and the planet,
113 //we need to first draw the moons that are further away than the planet,
114 //then re-draw the planet, then draw the moons nearer than the planet.
115 QList<TrailObject *> frontMoons;
116 int nmoons = pmoons->nMoons();
117
118 for (int i = 0; i < nmoons; ++i)
119 {
120 if (pmoons->z(i) < 0.0) //Moon is nearer than the planet
121 {
122 frontMoons.append(pmoons->moon(i));
123 }
124 else
125 {
126 //Draw Moons that are further than the planet
127 skyp->drawPointSource(pmoons->moon(i), pmoons->moon(i)->mag());
128 }
129 }
130
131 //Now redraw the planet
132 m_Planet->draw(skyp);
133
134 //Now draw the remaining moons, as stored in frontMoons
135 foreach (TrailObject *moon, frontMoons)
136 {
137 skyp->drawPointSource(moon, moon->mag());
138 }
139
140 //Draw Moon name labels if at high zoom
141 if (!(Options::showPlanetNames() && Options::zoomFactor() > 50. * MINZOOM))
142 return;
143 for (int i = 0; i < nmoons; ++i)
144 {
145 /*
146 if (planet ==KSPlanetBase::SATURN)
147 SkyLabeler::AddLabel( pmoons->moon(i), SkyLabeler::SATURN_MOON_LABEL );
148 else
149 */
150 SkyLabeler::AddLabel(pmoons->moon(i), SkyLabeler::JUPITER_MOON_LABEL);
151 }
152}
153
155{
156 if (!selected())
157 return;
158 int nmoons = pmoons->nMoons();
159 for (int i = 0; i < nmoons; ++i)
160 pmoons->moon(i)->drawTrail(skyp);
161}
const CachingDms * lat() const
Definition geolocation.h:70
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
A subclass of TrailObject that provides additional information needed for most solar system objects.
Child class of KSPlanetBase; encapsulates information about the Sun.
Definition kssun.h:24
KStarsData is the backbone of KStars.
Definition kstarsdata.h:74
CachingDms * lst()
Definition kstarsdata.h:226
GeoLocation * geo()
Definition kstarsdata.h:232
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
PlanetMoonsComponent(SkyComposite *parent, SolarSystemSingleComponent *pla, KSPlanetBase::Planets &planet)
Constructor.
void update(KSNumbers *num) override
Update the sky position(s) of this component.
SkyObject * findByName(const QString &name, bool exact=true) override
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
void drawTrails(SkyPainter *skyp) override
Draw trails for objects.
KSPlanetBase * getPlanet() const
Return pointer to stored planet object.
SkyComponent represents an object on the sky map.
SkyComposite * parent()
SkyComposite is a kind of container class for SkyComponent objects.
static void AddLabel(SkyObject *obj, label_t type)
static version of addLabel() below.
Definition skylabeler.h:135
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
virtual QString name(void) const
Definition skyobject.h:146
virtual QString longname(void) const
Definition skyobject.h:165
QString name2(void) const
Definition skyobject.h:157
float mag() const
Definition skyobject.h:207
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
virtual bool drawPointSource(const SkyPoint *loc, float mag, char sp='A')=0
Draw a point source (e.g., a star).
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=nullptr) const
Computes the angular distance between two SkyObjects.
Definition skypoint.cpp:899
This class encapsulates some methods which are shared between all single-object solar system componen...
KSPlanetBase * planet()
Return pointer to stored planet object.
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
provides a SkyObject with an attachable Trail
Definition trailobject.h:22
QString i18n(const char *text, const TYPE &arg...)
void append(QList< T > &&value)
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.