Kstars

solarsystemsinglecomponent.cpp
1/*
2 SPDX-FileCopyrightText: 2005 Thomas Kabelmann <thomas.kabelmann@gmx.de>
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
46SolarSystemSingleComponent::~SolarSystemSingleComponent()
47{
48 removeFromNames(m_Planet);
49 removeFromLists(m_Planet);
50 delete m_Planet;
51}
52
54{
55 return visible();
56}
57
59{
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}
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.
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.
QColor & color()
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
CachingDms * lst()
Definition kstarsdata.h:224
GeoLocation * geo()
Definition kstarsdata.h:230
SkyComponent represents an object on the sky map.
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:145
virtual QString longname(void) const
Definition skyobject.h:164
QString name2(void) const
Definition skyobject.h:156
int type(void) const
Definition skyobject.h:188
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
The sky coordinates of a point in the sky.
Definition skypoint.h:45
dms angularDistanceTo(const SkyPoint *sp, double *const positionAngle=nullptr) const
Computes the angular distance between two SkyObjects.
Definition skypoint.cpp:899
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
The solar system composite manages all planets, asteroids and comets.
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...
SkyObject * objectNearest(SkyPoint *p, double &maxrad) override
Find the SkyObject nearest the given SkyPoint.
SolarSystemSingleComponent(SolarSystemComposite *, KSPlanetBase *kspb, bool(*visibleMethod)(), bool isMoon=false)
Initialize visible method, minimum size and sizeScale.
void updateMoons(KSNumbers *num) override
update Update Equatorial & Horizontal coordinates.
void updateSolarSystemBodies(KSNumbers *num) override
updateSolarSystemBodies Update Equatorial & Horizontal coordinates.
void drawTrails(SkyPainter *skyp) override
Draw trails for objects.
void draw(SkyPainter *skyp) override
Draw the object on the SkyMap skyp a pointer to the SkyPainter to use.
void update(KSNumbers *num) override
update Only convert Equatorial to Horizontal coordinates given current time.
bool hasTrail() const
Definition trailobject.h:36
void updateTrail(dms *LST, const dms *lat)
update Horizontal coords of the trail
const double & Degrees() const
Definition dms.h:141
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 Tue Mar 26 2024 11:19:04 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.