Kstars

crosshairnode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5#include "crosshairnode.h"
6#include "Options.h"
7#include "ksutils.h"
8#include "nodes/ellipsenode.h"
9#include "labelnode.h"
10#include "../labelsitem.h"
11
12#include <QSGFlatColorMaterial>
13
14CrosshairNode::CrosshairNode(INDI::BaseDevice *baseDevice, RootNode *rootNode)
15 : el1(new EllipseNode), el2(new EllipseNode), lines(new QSGGeometryNode), bd(baseDevice)
16{
17 addChildNode(el1);
18 addChildNode(el2);
19
21
22 lines->setGeometry(linesGeo);
23 //lines->setFlag(QSGNode::OwnsGeometry);
24
25 material = new QSGFlatColorMaterial;
26
27 lines->setMaterial(material);
28 //lines->setFlag(QSGNode::OwnsMaterial);
29
30 linesGeo->setDrawingMode(GL_LINES);
31 linesGeo->allocate(8);
32
33 addChildNode(lines);
34 labelsItem = rootNode->labelsItem();
35 label = labelsItem->addLabel(bd->getDeviceName(), LabelsItem::TELESCOPE_SYMBOL);
36}
37
38CrosshairNode::~CrosshairNode()
39{
40 labelsItem->deleteLabel(label);
41 removeChildNode(lines);
42 removeChildNode(el1);
43 removeChildNode(el2);
44 delete lines->geometry();
45 delete material;
46 delete lines;
47 delete el1;
48 delete el2;
49}
50
51void CrosshairNode::setColor(QColor color)
52{
53 if (material->color() != color)
54 {
55 material->setColor(color);
57 }
58 el1->setColor(color);
59 el2->setColor(color);
60}
61
62void CrosshairNode::update()
63{
64 SkyPoint indi_sp;
65 KStarsData *m_KStarsData = KStarsData::Instance();
66
67 //psky.setPen( QPen( QColor( m_KStarsData->colorScheme()->colorNamed("TargetColor" ) ) ) );
68 float pxperdegree = Options::zoomFactor() / 57.3;
69
70 auto coordNP = bd->getNumber("EQUATORIAL_EOD_COORD");
71
72 if (!coordNP)
73 {
74 coordNP = bd->getNumber("HORIZONTAL_COORD");
75 if (!coordNP)
76 {
77 hide();
78 }
79 else
80 {
81 auto np = coordNP->findWidgetByName("AZ");
82
83 if (!np)
84 hide();
85
86 indi_sp.setAz(np->getValue());
87
88 np = coordNP->findWidgetByName("ALT");
89 if (!np)
90 hide();
91
92 indi_sp.setAlt(np->getValue());
93 indi_sp.HorizontalToEquatorial(m_KStarsData->lst(), m_KStarsData->geo()->lat());
94 }
95 }
96 else
97 {
98 autonp = coordNP->findWidgetByName("RA");
99
100 if (!np )
101 hide();
102
103 indi_sp.setRA(np->value);
104
105 np = coordNP->findWidgetByName("DEC");
106 if (!np)
107 hide();
108
109 indi_sp.setDec(np->getValue());
110 }
111
112 if (Options::useAltAz())
113 indi_sp.EquatorialToHorizontal(m_KStarsData->lst(), m_KStarsData->geo()->lat());
114
115 if (std::isnan(indi_sp.ra().Degrees()) || std::isnan(indi_sp.dec().Degrees()))
116 hide();
117
118 QPointF P = SkyMapLite::Instance()->projector()->toScreen(&indi_sp);
119 float s1 = 0.5 * pxperdegree;
120 float s2 = pxperdegree;
121 float s3 = 2.0 * pxperdegree;
122
123 float x0 = P.x();
124 float y0 = P.y();
125 float x1 = x0 - 0.5 * s1;
126 float y1 = y0 - 0.5 * s1;
127 //float x2 = x0 - 0.5*s2; float y2 = y0 - 0.5*s2;
128 float x3 = x0 - 0.5 * s3;
129 float y3 = y0 - 0.5 * s3;
130
131 //Draw radial lines
132
134
135 vertex[0].set(x1, y0);
136 vertex[1].set(x3, y0);
137 vertex[2].set(x0 + s2, y0);
138 vertex[3].set(x0 + 0.5 * s1, y0);
139 vertex[4].set(x0, y1);
140 vertex[5].set(x0, y3);
141 vertex[6].set(x0, y0 + 0.5 * s1);
142 vertex[7].set(x0, y0 + s2);
143
145
146 //material
147 //Draw circles at 0.5 & 1 degrees*/
148 el1->updateGeometry(x0, y0, s1, s1, false);
149 el2->updateGeometry(x0, y0, s2, s2, false);
150
151 label->setLabelPos(QPointF(x0 + s2 + 2., y0));
152}
153
154void CrosshairNode::hide()
155{
157 label->hide();
158}
QSGTransformNode derived node used to draw ellipses.
Definition ellipsenode.h:23
void updateGeometry(float x, float y, int width, int height, bool filled)
Redraw ellipse with the given width, height and positions (x,y)
const CachingDms * lat() const
Definition geolocation.h:70
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
CachingDms * lst()
Definition kstarsdata.h:224
GeoLocation * geo()
Definition kstarsdata.h:230
void setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
void deleteLabel(LabelNode *label)
deletes particular label
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
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
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 & dec() const
Definition skypoint.h:269
void setDec(dms d)
Sets Dec, the current Declination.
Definition skypoint.h:169
void setRA(dms &r)
Sets RA, the current Right Ascension.
Definition skypoint.h:144
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
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
const double & Degrees() const
Definition dms.h:141
QString label(StandardShortcut id)
qreal x() const const
qreal y() const const
QSGGeometry * geometry()
const QColor & color() const const
void setColor(const QColor &color)
void set(float x, float y)
void allocate(int vertexCount, int indexCount)
const AttributeSet & defaultAttributes_Point2D()
void setDrawingMode(unsigned int mode)
Point2D * vertexDataAsPoint2D()
void markDirty(DirtyState bits)
void removeChildNode(QSGNode *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:59:52 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.