Kstars

planetmoonscomponent.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Vipul Kumar Singh Médéric Boquien <[email protected], [email protected]>
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 
55 void 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 }
void append(const T &value)
PlanetMoonsComponent(SkyComposite *parent, SolarSystemSingleComponent *pla, KSPlanetBase::Planets &planet)
Constructor.
CaseInsensitive
static void AddLabel(SkyObject *obj, label_t type)
static version of addLabel() below.
Definition: skylabeler.h:135
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
KSPlanetBase * planet()
Return pointer to stored planet object.
CachingDms * lst()
Definition: kstarsdata.h:223
KSPlanetBase * getPlanet() const
Return pointer to stored planet object.
virtual QString name(void) const
Definition: skyobject.h:145
SkyObject * findByName(const QString &name, bool exact=true) override
float mag() const
Definition: skyobject.h:206
SkyComposite * parent()
Definition: skycomponent.h:137
Provides necessary information about the Sun.
Definition: kssun.h:23
QString i18n(const char *text, const TYPE &arg...)
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
const CachingDms * lat() const
Definition: geolocation.h:70
void update(KSNumbers *num) override
Update the sky position(s) of this component.
provides a SkyObject with an attachable Trail
Definition: trailobject.h:21
GeoLocation * geo()
Definition: kstarsdata.h:229
virtual bool drawPointSource(const SkyPoint *loc, float mag, char sp='A')=0
Draw a point source (e.g., a star).
Draws things on the sky, without regard to backend.
Definition: skypainter.h:37
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=nullptr) const
Computes the angular distance between two SkyObjects.
Definition: skypoint.cpp:899
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.
const double & Degrees() const
Definition: dms.h:141
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
virtual QString longname(void) const
Definition: skyobject.h:164
QString name2(void) const
Definition: skyobject.h:156
int compare(const QString &other, Qt::CaseSensitivity cs) const const
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
Information about an object in the sky.
Definition: skyobject.h:41
Provides necessary information about objects in the solar system.
Definition: ksplanetbase.h:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:04:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.