Kstars

solarsystemsinglecomponent.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Thomas Kabelmann <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "solarsystemsinglecomponent.h"
8 #include "solarsystemcomposite.h"
9 #include "skycomponent.h"
10 #include <KLocalizedString>
11 
12 #include "dms.h"
13 #include "kstarsdata.h"
14 #include "skyobjects/starobject.h"
15 #include "skyobjects/ksplanetbase.h"
16 #include "skyobjects/ksplanet.h"
17 #ifdef KSTARS_LITE
18 #include "skymaplite.h"
19 #else
20 #include "skymap.h"
21 #endif
22 
23 #include "Options.h"
24 #include "skylabeler.h"
25 
26 #include "skypainter.h"
27 #include "projections/projector.h"
28 
30  bool (*visibleMethod)(), bool isMoon)
31  : SkyComponent(parent), visible(visibleMethod), m_isMoon(isMoon), m_Earth(parent->earth()), m_Planet(kspb)
32 {
33  m_Planet->loadData();
34  if (!m_Planet->name().isEmpty())
35  {
36  objectNames(m_Planet->type()).append(m_Planet->name());
37  objectLists(m_Planet->type()).append(QPair<QString, const SkyObject *>(m_Planet->name(), m_Planet));
38  }
39  if (!m_Planet->longname().isEmpty() && m_Planet->longname() != m_Planet->name())
40  {
41  objectNames(m_Planet->type()).append(m_Planet->longname());
42  objectLists(m_Planet->type()).append(QPair<QString, const SkyObject *>(m_Planet->longname(), m_Planet));
43  }
44 }
45 
46 SolarSystemSingleComponent::~SolarSystemSingleComponent()
47 {
48  removeFromNames(m_Planet);
49  removeFromLists(m_Planet);
50  delete m_Planet;
51 }
52 
54 {
55  return visible();
56 }
57 
59 {
60  Q_UNUSED(exact)
61  if (QString::compare(m_Planet->name(), name, Qt::CaseInsensitive) == 0 ||
62  QString::compare(m_Planet->longname(), name, Qt::CaseInsensitive) == 0 ||
63  QString::compare(m_Planet->name2(), name, Qt::CaseInsensitive) == 0)
64  return m_Planet;
65  return nullptr;
66 }
67 
69 {
70  double r = m_Planet->angularDistanceTo(p).Degrees();
71  if (r < maxrad)
72  {
73  maxrad = r;
74  return m_Planet;
75  }
76  return nullptr;
77 }
78 
80 {
81  KStarsData *data = KStarsData::Instance();
82  if (selected())
83  m_Planet->EquatorialToHorizontal(data->lst(), data->geo()->lat());
84 }
85 
87 {
88  if (!m_isMoon && selected())
89  {
90  KStarsData *data = KStarsData::Instance();
91  m_Planet->findPosition(num, data->geo()->lat(), data->lst(), m_Earth);
92  m_Planet->EquatorialToHorizontal(data->lst(), data->geo()->lat());
93  if (m_Planet->hasTrail())
94  m_Planet->updateTrail(data->lst(), data->geo()->lat());
95  }
96 }
97 
98 // NOTE: This seems like code duplication, and yes IT IS. But there may be some
99 // NOTE: changes to be made to it later on, and calling `updateSolarSystemBodies`
100 // NOTE: is ugly.
102 {
103  KStarsData *data = KStarsData::Instance();
104  m_Planet->findPosition(num, data->geo()->lat(), data->lst(), m_Earth);
105  m_Planet->EquatorialToHorizontal(data->lst(), data->geo()->lat());
106  if (m_Planet->hasTrail())
107  m_Planet->updateTrail(data->lst(), data->geo()->lat());
108 }
109 
111 {
112  if (!selected())
113  return;
114 
115  skyp->setPen(m_Planet->color());
116  skyp->setBrush(m_Planet->color());
117 
118  bool drawn = skyp->drawPlanet(m_Planet);
119  if (drawn && Options::showPlanetNames())
120  SkyLabeler::AddLabel(m_Planet, SkyLabeler::PLANET_LABEL);
121 }
122 
124 {
125  if (selected())
126  m_Planet->drawTrail(skyp);
127 }
CaseInsensitive
void update(KSNumbers *num) override
update Only convert Equatorial to Horizontal coordinates given current time.
static void AddLabel(SkyObject *obj, label_t type)
static version of addLabel() below.
Definition: skylabeler.h:135
void updateSolarSystemBodies(KSNumbers *num) override
updateSolarSystemBodies Update Equatorial & Horizontal coordinates.
QColor & color()
Definition: ksplanetbase.h:203
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
void findPosition(const KSNumbers *num, const CachingDms *lat=nullptr, const CachingDms *LST=nullptr, const KSPlanetBase *Earth=nullptr)
Find position, including correction for Figure-of-the-Earth.
CachingDms * lst()
Definition: kstarsdata.h:223
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
virtual QString name(void) const
Definition: skyobject.h:145
void EquatorialToHorizontal(const CachingDms *LST, const CachingDms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates,...
Definition: skypoint.cpp:77
int type(void) const
Definition: skyobject.h:188
SolarSystemSingleComponent(SolarSystemComposite *, KSPlanetBase *kspb, bool(*visibleMethod)(), bool isMoon=false)
Initialize visible method, minimum size and sizeScale.
void updateTrail(dms *LST, const dms *lat)
update Horizontal coords of the trail
Definition: trailobject.cpp:45
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
const CachingDms * lat() const
Definition: geolocation.h:70
void drawTrails(SkyPainter *skyp) override
Draw trails for objects.
bool isEmpty() const const
GeoLocation * geo()
Definition: kstarsdata.h:229
virtual void setBrush(const QBrush &brush)=0
Set the brush of the painter.
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
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.
const double & Degrees() const
Definition: dms.h:141
bool hasTrail() const
Definition: trailobject.h:36
SkyObject * findByName(const QString &name, bool exact=true) override
Search the children of this SkyComponent for a SkyObject whose name matches the argument name the nam...
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 updateMoons(KSNumbers *num) override
update Update Equatorial & Horizontal coordinates.
Information about an object in the sky.
Definition: skyobject.h:41
virtual bool drawPlanet(KSPlanetBase *planet)=0
Draw a planet.
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:06 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.