Kstars

equatoritem.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
3  SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "equatoritem.h"
7 
8 #include "projections/projector.h"
9 #include "../rootnode.h"
10 #include "../labelsitem.h"
11 #include "../skynodes/labelnode.h"
12 #include "../skynodes/trixelnode.h"
13 #include "../skynodes/nodes/linenode.h"
14 
15 #include <QSGNode>
16 
17 EquatorItem::EquatorItem(Equator *equatorComp, RootNode *rootNode)
18  : SkyItem(LabelsItem::label_t::EQUATOR_LABEL, rootNode), m_equatorComp(equatorComp)
19 {
20  LineListHash *trixels = equatorComp->lineIndex();
21 
22  auto i = trixels->cbegin();
23 
24  while (i != trixels->cend())
25  {
26  std::shared_ptr<LineListList> linesList = *i;
28 
29  if (linesList->size())
30  {
31  QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("EqColor");
32 
33  for (int c = 0; c < linesList->size(); ++c)
34  {
35  std::shared_ptr<LineList> lines = linesList->at(c);
36 
37  if (!addedLines.contains(lines))
38  {
39  LineNode *ln = new LineNode(linesList->at(c).get(), 0, schemeColor, 1, Qt::SolidLine);
40 
41  appendChildNode(ln);
42  addedLines.append(lines);
43  }
44  }
45  }
46  ++i;
47  }
48 
49  //Add compass labels
50  for (int ra = 0; ra < 23; ra += 2)
51  {
52  SkyPoint *o = new SkyPoint(ra, 0.0);
53 
54  QString label;
55  label.setNum(o->ra().hour());
56 
57  LabelNode *compass = rootNode->labelsItem()->addLabel(label, labelType());
58  m_compassLabels.insert(o, compass);
59  }
60 }
61 
63 {
64  if (m_equatorComp->selected())
65  {
66  show();
67  QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("EqColor");
68 
69  UpdateID updateID = KStarsData::Instance()->updateID();
70 
71  QSGNode *l = firstChild();
72  while (l != 0)
73  {
74  LineNode *lines = static_cast<LineNode *>(l);
75  lines->setColor(schemeColor);
76  l = l->nextSibling();
77 
78  LineList *lineList = lines->lineList();
79  if (lineList->updateID != updateID)
80  m_equatorComp->JITupdate(lineList);
81 
82  lines->updateGeometry();
83  }
84 
85  const Projector *proj = SkyMapLite::Instance()->projector();
86  KStarsData *data = KStarsData::Instance();
87 
88  QMap<SkyPoint *, LabelNode *>::iterator i = m_compassLabels.begin();
89 
90  while (i != m_compassLabels.end())
91  {
92  SkyPoint *c = i.key();
93  c->EquatorialToHorizontal(data->lst(), data->geo()->lat());
94 
95  LabelNode *compass = (*i);
96 
97  bool visible;
98  QPointF cpoint = proj->toScreen(c, false, &visible);
99  if (visible && proj->checkVisibility(c))
100  {
101  compass->setLabelPos(cpoint);
102  }
103  else
104  {
105  compass->hide();
106  }
107  ++i;
108  }
109  }
110  else
111  {
112  hide();
113  }
114 }
void append(const T &value)
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
void updateGeometry()
Update lines based on the visibility of line segments in m_lineList.
Definition: linenode.cpp:65
QMap::iterator begin()
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
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
bool contains(const T &value) const const
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
EquatorItem(Equator *equatorComp, RootNode *rootNode)
Constructor.
Definition: equatoritem.cpp:17
QHash::const_iterator cend() const const
void JITupdate(LineList *lineList) override
@ short override JITupdate so we don't perform the precession correction, only rotation.
virtual void show() override
makes this node visible
Definition: skyitem.cpp:23
QMap::iterator insert(const Key &key, const T &value)
QMap::iterator end()
QString & setNum(short n, int base)
const Projector * projector() const
Get the current projector.
Definition: skymaplite.h:323
const CachingDms * lat() const
Definition: geolocation.h:70
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
GeoLocation * geo()
Definition: kstarsdata.h:229
bool selected() override
Definition: equator.cpp:47
SkyOpacityNode derived class that draws lines from LineList.
Definition: linenode.h:27
virtual void hide() override
hides this item and corresponding labels
Definition: skyitem.cpp:37
virtual void update()
updates positions of lines and compass labels
Definition: equatoritem.cpp:62
const Key key(const T &value, const Key &defaultKey) const const
const CachingDms & ra() const
Definition: skypoint.h:263
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
int hour() const
Definition: dms.h:147
QHash::const_iterator cbegin() const const
SolidLine
QSGNode * nextSibling() const const
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:86
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 checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
Definition: projector.cpp:183
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 8 2022 04:13:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.