Kstars

horizoncomponent.cpp
1 /*
2  SPDX-FileCopyrightText: 2005 Thomas Kabelmann <[email protected]>
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 
94 void 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 }
void append(const T &value)
void setAlt(dms alt)
Sets Alt, the Altitude.
Definition: skypoint.h:194
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
HorizonComponent(SkyComposite *parent)
Constructor.
CachingDms * lst()
Definition: kstarsdata.h:223
virtual void setPen(const QPen &pen)=0
Set the pen of the painter.
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
Definition: skylabeler.cpp:197
virtual void emitProgressText(const QString &message)
Emit signal about progress.
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
void update(KSNumbers *) override
Update the sky position(s) of this component.
QString i18n(const char *text, const TYPE &arg...)
Store several time-dependent astronomical quantities.
Definition: ksnumbers.h:42
const CachingDms * lat() const
Definition: geolocation.h:70
bool drawGuideLabel(QPointF &o, const QString &text, double angle)
Tries to draw the text at the position and angle specified.
Definition: skylabeler.cpp:112
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
GeoLocation * geo()
Definition: kstarsdata.h:229
virtual void setBrush(const QBrush &brush)=0
Set the brush of the painter.
Draws things on the sky, without regard to backend.
Definition: skypainter.h:37
void draw(SkyPainter *skyp) override
Draw the Horizon on the Sky map.
void setAz(dms az)
Sets Az, the Azimuth.
Definition: skypoint.h:230
const double & Degrees() const
Definition: dms.h:141
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
QString i18nc(const char *context, const char *text, const TYPE &arg...)
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
const Projector * projector() const
Get the current projector.
Definition: skymap.h:299
SolidLine
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:86
bool selected() override
const dms & az() const
Definition: skypoint.h:275
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:54 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.