Kstars

equatoritem.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
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
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;
27 QList<std::shared_ptr<LineList>> addedLines;
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
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}
QColor colorNamed(const QString &name) const
Retrieve a color by name.
EquatorItem(Equator *equatorComp, RootNode *rootNode)
Constructor.
virtual void update()
updates positions of lines and compass labels
Represents the equator on the sky map.
Definition equator.h:20
bool selected() override
Definition equator.cpp:47
const CachingDms * lat() const
Definition geolocation.h:70
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
A SkyNode derived class used for displaying labels.
Definition labelnode.h:27
void setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
This class is in charge of labels in SkyMapLite.
Definition labelsitem.h:53
A simple data container used by LineListIndex.
Definition linelist.h:25
SkyOpacityNode derived class that draws lines from LineList.
Definition linenode.h:28
void updateGeometry()
Update lines based on the visibility of line segments in m_lineList.
Definition linenode.cpp:65
void JITupdate(LineList *lineList) override
@ short override JITupdate so we don't perform the precession correction, only rotation.
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 checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
This is an interface for implementing SkyItems that represent SkyComponent derived objects on the Sky...
Definition skyitem.h:30
virtual void hide() override
hides this item and corresponding labels
Definition skyitem.cpp:37
virtual void show() override
makes this node visible
Definition skyitem.cpp:23
const Projector * projector() const
Get the current projector.
Definition skymaplite.h:323
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition skynode.cpp:21
The sky coordinates of a point in the sky.
Definition skypoint.h:45
const CachingDms & ra() const
Definition skypoint.h:263
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
int hour() const
Definition dms.h:147
const_iterator cbegin() const const
const_iterator cend() const const
iterator begin()
iterator end()
QSGNode * firstChild() const const
QSGNode * nextSibling() const const
QString & setNum(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.