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{
60 if (QString::compare(m_Planet->name(), name, Qt::CaseInsensitive) == 0 ||
61 QString::compare(m_Planet->longname(), name, Qt::CaseInsensitive) == 0 ||
62 QString::compare(m_Planet->name2(), name, Qt::CaseInsensitive) == 0)
63 return m_Planet;
64 else if (!exact && m_Planet->name().contains(name, Qt::CaseInsensitive))
65 return m_Planet;
66 return nullptr;
67}
68
70{
71 double r = m_Planet->angularDistanceTo(p).Degrees();
72 if (r < maxrad)
73 {
74 maxrad = r;
75 return m_Planet;
76 }
77 return nullptr;
78}
79
81{
82 KStarsData *data = KStarsData::Instance();
83 if (selected())
84 m_Planet->EquatorialToHorizontal(data->lst(), data->geo()->lat());
85}
86
88{
89 if (!m_isMoon && selected())
90 {
91 KStarsData *data = KStarsData::Instance();
92 m_Planet->findPosition(num, data->geo()->lat(), data->lst(), m_Earth);
93 m_Planet->EquatorialToHorizontal(data->lst(), data->geo()->lat());
94 if (m_Planet->hasTrail())
95 m_Planet->updateTrail(data->lst(), data->geo()->lat());
96 }
97}
98
99// NOTE: This seems like code duplication, and yes IT IS. But there may be some
100// NOTE: changes to be made to it later on, and calling `updateSolarSystemBodies`
101// NOTE: is ugly.
103{
104 KStarsData *data = KStarsData::Instance();
105 m_Planet->findPosition(num, data->geo()->lat(), data->lst(), m_Earth);
106 m_Planet->EquatorialToHorizontal(data->lst(), data->geo()->lat());
107 if (m_Planet->hasTrail())
108 m_Planet->updateTrail(data->lst(), data->geo()->lat());
109}
110
112{
113 if (!selected())
114 return;
115
116 skyp->setPen(m_Planet->color());
117 skyp->setBrush(m_Planet->color());
118
119 bool drawn = skyp->drawPlanet(m_Planet);
120 if (drawn && Options::showPlanetNames())
121 SkyLabeler::AddLabel(m_Planet, SkyLabeler::PLANET_LABEL);
122}
123
125{
126 if (selected())
127 m_Planet->drawTrail(skyp);
128}
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
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
virtual bool drawPlanet(KSPlanetBase *planet)=0
Draw a planet.
virtual void setBrush(const QBrush &brush)=0
Set the brush of the painter.
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
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)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.