Kstars

horizonitem.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "horizonitem.h"
7 
8 #include "horizoncomponent.h"
9 #include "labelsitem.h"
10 #include "Options.h"
11 #include "rootnode.h"
12 #include "skynodes/horizonnode.h"
13 #include "skynodes/labelnode.h"
14 
16  : SkyItem(LabelsItem::label_t::HORIZON_LABEL, rootNode), m_horizonComp(hComp)
17 {
19 
20  double az = -0.01;
21  static QString name[8];
22  name[0] = i18nc("Northeast", "NE");
23  name[1] = i18nc("East", "E");
24  name[2] = i18nc("Southeast", "SE");
25  name[3] = i18nc("South", "S");
26  name[4] = i18nc("Southwest", "SW");
27  name[5] = i18nc("West", "W");
28  name[6] = i18nc("Northwest", "NW");
29  name[7] = i18nc("North", "N");
30 
31  for (int i = 0; i < 8; i++)
32  {
33  SkyPoint *c = new SkyPoint;
34 
35  az += 45.0;
36  c->setAz(az);
37  c->setAlt(0.0);
38  LabelNode *compass = rootNode->labelsItem()->addLabel(name[i], labelType());
39 
40  m_compassLabels.insert(c, compass);
41  }
42 }
43 
45 {
46  if (!childCount())
47  {
49  }
50 
51  //HorizonNode *hNode = static_cast<HorizonNode *>(n->skyNodeAtIndex(0));
52  QSGNode *n = firstChild();
53  SkyNode *hNode = static_cast<SkyNode *>(n);
54  if (m_horizonComp->selected())
55  {
56  QPointF cpoint;
57  bool visible;
58 
59  const Projector *proj = SkyMapLite::Instance()->projector();
60  KStarsData *data = KStarsData::Instance();
61 
63 
64  while (i != m_compassLabels.cend())
65  {
66  SkyPoint *c = i.key();
67  if (!Options::useAltAz())
68  {
69  c->HorizontalToEquatorial(data->lst(), data->geo()->lat());
70  }
71 
72  LabelNode *compass = (*i);
73  cpoint = proj->toScreen(c, false, &visible);
74  if (visible && proj->onScreen(cpoint))
75  {
76  compass->setLabelPos(cpoint);
77  }
78  else
79  {
80  compass->hide();
81  }
82  ++i;
83  }
84 
85  hNode->update();
86  }
87  else
88  {
89  hNode->hide();
90  rootNode()->labelsItem()->hideLabels(LabelsItem::label_t::HORIZON_LABEL);
91  }
92 }
void setAlt(dms alt)
Sets Alt, the Altitude.
Definition: skypoint.h:194
A base class that is used for displaying SkyComponents on SkyMapLite.
Definition: skyitem.h:29
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
LabelsItem::label_t labelType()
Definition: skyitem.h:60
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
A SkyNode derived class used for displaying labels.
Definition: labelnode.h:26
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
CachingDms * lst()
Definition: kstarsdata.h:223
virtual void update()
Updates coordinate of the object on SkyMapLite.
Definition: skynode.h:48
int childCount() const const
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
QMap::const_iterator cbegin() const const
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
QMap::iterator insert(const Key &key, const T &value)
const Projector * projector() const
Get the current projector.
Definition: skymaplite.h:323
const CachingDms * lat() const
Definition: geolocation.h:70
HorizonItem(HorizonComponent *hComp, RootNode *rootNode)
Constructor.
Definition: horizonitem.cpp:15
virtual void update()
Call update() of HorizonNode and update/hide compass labels based on their visibility.
Definition: horizonitem.cpp:44
QMap::const_iterator cend() const const
GeoLocation * geo()
Definition: kstarsdata.h:229
void hideLabels(label_t labelType)
hides all labels of type labelType
Definition: labelsitem.cpp:190
const Key key(const T &value, const Key &defaultKey) const const
void setAz(dms az)
Sets Az, the Azimuth.
Definition: skypoint.h:230
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
void setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
Definition: labelnode.cpp:123
RootNode * rootNode()
Definition: skyitem.h:57
This node acts as a parent of nodes that comprise horizon and both filled and non-filled ground.
Definition: horizonnode.h:20
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
Provides virtual functions for update of coordinates and nodes hiding.
Definition: skynode.h:27
LabelNode * addLabel(SkyObject *skyObject, label_t labelType)
Create LabelNode with given skyObject and append it to LabelTypeNode that corresponds to type.
Definition: labelsitem.cpp:111
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition: skynode.cpp:21
bool selected() override
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 04:01:54 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.