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 (exact)
61 {
62 if (QString::compare(m_Planet->name(), name, Qt::CaseInsensitive) == 0 ||
63 QString::compare(m_Planet->longname(), name, Qt::CaseInsensitive) == 0 ||
64 QString::compare(m_Planet->name2(), name, Qt::CaseInsensitive) == 0)
65 return m_Planet;
66 }
67 else if (m_Planet->name().contains(name, Qt::CaseInsensitive))
68 return m_Planet;
69 return nullptr;
70}
71
73{
74 double r = m_Planet->angularDistanceTo(p).Degrees();
75 if (r < maxrad)
76 {
77 maxrad = r;
78 return m_Planet;
79 }
80 return nullptr;
81}
82
84{
85 KStarsData *data = KStarsData::Instance();
86 if (selected())
87 m_Planet->EquatorialToHorizontal(data->lst(), data->geo()->lat());
88}
89
91{
92 if (!m_isMoon && selected())
93 {
94 KStarsData *data = KStarsData::Instance();
95 m_Planet->findPosition(num, data->geo()->lat(), data->lst(), m_Earth);
96 m_Planet->EquatorialToHorizontal(data->lst(), data->geo()->lat());
97 if (m_Planet->hasTrail())
98 m_Planet->updateTrail(data->lst(), data->geo()->lat());
99 }
100}
101
102// NOTE: This seems like code duplication, and yes IT IS. But there may be some
103// NOTE: changes to be made to it later on, and calling `updateSolarSystemBodies`
104// NOTE: is ugly.
106{
107 KStarsData *data = KStarsData::Instance();
108 m_Planet->findPosition(num, data->geo()->lat(), data->lst(), m_Earth);
109 m_Planet->EquatorialToHorizontal(data->lst(), data->geo()->lat());
110 if (m_Planet->hasTrail())
111 m_Planet->updateTrail(data->lst(), data->geo()->lat());
112}
113
115{
116 if (!selected())
117 return;
118
119 skyp->setPen(m_Planet->color());
120 skyp->setBrush(m_Planet->color());
121
122 bool drawn = skyp->drawPlanet(m_Planet);
123 if (drawn && Options::showPlanetNames())
124 SkyLabeler::AddLabel(m_Planet, SkyLabeler::PLANET_LABEL);
125}
126
128{
129 if (selected())
130 m_Planet->drawTrail(skyp);
131}
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 Fri May 24 2024 11:49:23 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.