Kstars

crosshairnode.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
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 
14 CrosshairNode::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 
38 CrosshairNode::~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 
51 void CrosshairNode::setColor(QColor color)
52 {
53  if (material->color() != color)
54  {
55  material->setColor(color);
56  lines->markDirty(QSGNode::DirtyMaterial);
57  }
58  el1->setColor(color);
59  el2->setColor(color);
60 }
61 
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 
133  QSGGeometry::Point2D *vertex = lines->geometry()->vertexDataAsPoint2D();
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 
144  lines->markDirty(QSGNode::DirtyGeometry);
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 
154 void CrosshairNode::hide()
155 {
156  SkyNode::hide();
157  label->hide();
158 }
void setAlt(dms alt)
Sets Alt, the Altitude.
Definition: skypoint.h:194
void setDrawingMode(unsigned int mode)
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
void set(float x, float y)
CachingDms * lst()
Definition: kstarsdata.h:223
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
const QSGGeometry::AttributeSet & defaultAttributes_Point2D()
const Projector * projector() const
Get the current projector.
Definition: skymaplite.h:323
const CachingDms & dec() const
Definition: skypoint.h:269
const CachingDms * lat() const
Definition: geolocation.h:70
GeoLocation * geo()
Definition: kstarsdata.h:229
QString label(StandardShortcut id)
void setAz(dms az)
Sets Az, the Azimuth.
Definition: skypoint.h:230
qreal x() const const
qreal y() const const
const CachingDms & ra() const
Definition: skypoint.h:263
QSGTransformNode derived node used to draw ellipses.
Definition: ellipsenode.h:22
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
void setDec(dms d)
Sets Dec, the current Declination.
Definition: skypoint.h:169
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 setRA(dms &r)
Sets RA, the current Right Ascension.
Definition: skypoint.h:144
void allocate(int vertexCount, int indexCount)
void update(bool drawLabel)
sets m_drawLabel to true if it is needed to be drawn and calls update()
Definition: skynode.cpp:33
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition: skynode.cpp:21
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:50 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.