Kstars

horizoncomponent.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 "horizoncomponent.h"
8
9#include "dms.h"
10#include "kstarsdata.h"
11#include "Options.h"
12#include "skylabeler.h"
13#ifdef KSTARS_LITE
14#include "skymaplite.h"
15#else
16#include "skymap.h"
17#endif
18#include "skypainter.h"
19#include "projections/projector.h"
20
21#include <QPointF>
22
23#define NCIRCLE 360 //number of points used to define equator, ecliptic and horizon
24
26{
27 KStarsData *data = KStarsData::Instance();
28 emitProgressText(i18n("Creating horizon"));
29
30 //Define Horizon
31 for (unsigned int i = 0; i < NCIRCLE; ++i)
32 {
33 std::shared_ptr<SkyPoint> o(new SkyPoint());
34
35 o->setAz(i * 360. / NCIRCLE);
36 o->setAlt(0.0);
37
38 o->HorizontalToEquatorial(data->lst(), data->geo()->lat());
39 pointList().append(o);
40 }
41}
42
44{
45 return Options::showHorizon() || Options::showGround();
46}
47
49{
50 if (!selected())
51 return;
52
53 KStarsData *data = KStarsData::Instance();
54
55 for (auto &p : pointList())
56 {
57 p->HorizontalToEquatorial(data->lst(), data->geo()->lat());
58 }
59}
60
61//Only half of the Horizon circle is ever valid, the invalid half is "behind" the observer.
62//To select the valid half, we start with the azimuth of the central focus point.
63//The valid horizon points have azimuth between this az +- 90
64//This is true for Equatorial or Horizontal coordinates
66{
67 if (!selected())
68 return;
69
70 KStarsData *data = KStarsData::Instance();
71
72 skyp->setPen(QPen(QColor(data->colorScheme()->colorNamed("HorzColor")), 2, Qt::SolidLine));
73
74 if (Options::showGround())
75 skyp->setBrush(QColor(data->colorScheme()->colorNamed("HorzColor")));
76 else
77 skyp->setBrush(Qt::NoBrush);
78
79 SkyPoint labelPoint;
80 bool drawLabel;
81 skyp->drawHorizon(Options::showGround(), &labelPoint, &drawLabel);
82
83 if (drawLabel)
84 {
85 SkyPoint labelPoint2;
86 labelPoint2.setAlt(0.0);
87 labelPoint2.setAz(labelPoint.az().Degrees() + 1.0);
88 labelPoint2.HorizontalToEquatorial(data->lst(), data->geo()->lat());
89 }
90
91 drawCompassLabels();
92}
93
94void HorizonComponent::drawCompassLabels()
95{
96#ifndef KSTARS_LITE
97 SkyPoint c;
98 QPointF cpoint;
99 bool visible;
100
101 const Projector *proj = SkyMap::Instance()->projector();
102 KStarsData *data = KStarsData::Instance();
103
104 SkyLabeler *skyLabeler = SkyLabeler::Instance();
105 // Set proper color for labels
106 QColor color(data->colorScheme()->colorNamed("CompassColor"));
107 skyLabeler->setPen(QPen(QBrush(color), 1, Qt::SolidLine));
108
109 double az = -0.01;
110 static QString name[8];
111 name[0] = i18nc("Northeast", "NE");
112 name[1] = i18nc("East", "E");
113 name[2] = i18nc("Southeast", "SE");
114 name[3] = i18nc("South", "S");
115 name[4] = i18nc("Southwest", "SW");
116 name[5] = i18nc("West", "W");
117 name[6] = i18nc("Northwest", "NW");
118 name[7] = i18nc("North", "N");
119
120 for (const auto &item : name)
121 {
122 az += 45.0;
123 c.setAz(az);
124 c.setAlt(0.0);
125 if (!Options::useAltAz())
126 {
127 c.HorizontalToEquatorial(data->lst(), data->geo()->lat());
128 }
129
130 cpoint = proj->toScreen(&c, false, &visible);
131 if (visible && proj->onScreen(cpoint))
132 {
133 skyLabeler->drawGuideLabel(cpoint, item, 0.0);
134 }
135 }
136#endif
137}
QColor colorNamed(const QString &name) const
Retrieve a color by name.
const CachingDms * lat() const
Definition geolocation.h:70
bool selected() override
void update(KSNumbers *) override
Update the sky position(s) of this component.
HorizonComponent(SkyComposite *parent)
Constructor.
void draw(SkyPainter *skyp) override
Draw the Horizon on the Sky map.
There are several time-dependent values used in position calculations, that are not specific to an ob...
Definition ksnumbers.h:43
KStarsData is the backbone of KStars.
Definition kstarsdata.h:74
CachingDms * lst()
Definition kstarsdata.h:226
ColorScheme * colorScheme()
Definition kstarsdata.h:174
GeoLocation * geo()
Definition kstarsdata.h:232
An abstract parent class, to be inherited by SkyComponents that store a QList of SkyPoints.
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
QPointF toScreen(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=nullptr) const
This is exactly the same as toScreenVec but it returns a QPointF.
Definition projector.cpp:93
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition projector.cpp:98
virtual void emitProgressText(const QString &message)
Emit signal about progress.
SkyComposite is a kind of container class for SkyComponent objects.
The purpose of this class is to prevent labels from overlapping.
Definition skylabeler.h:99
bool drawGuideLabel(QPointF &o, const QString &text, double angle)
Tries to draw the text at the position and angle specified.
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
const Projector * projector() const
Get the current projector.
Definition skymap.h:300
Draws things on the sky, without regard to backend.
Definition skypainter.h:40
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
void setAlt(dms alt)
Sets Alt, the Altitude.
Definition skypoint.h:194
void HorizontalToEquatorial(const dms *LST, const dms *lat)
Determine the (RA, Dec) coordinates of the SkyPoint from its (Altitude, Azimuth) coordinates,...
Definition skypoint.cpp:143
void setAz(dms az)
Sets Az, the Azimuth.
Definition skypoint.h:230
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void append(QList< T > &&value)
SolidLine
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:57:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.