Kstars

fovsymbolnode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "fovsymbolnode.h"
8
9#include "nodes/rectnode.h"
10#include "nodes/ellipsenode.h"
11
12#include <QSGFlatColorMaterial>
13
14FOVSymbolNode::FOVSymbolNode(const QString &name, float a, float b, float xoffset, float yoffset, float rot,
15 FOVItem::Shape shape, const QString &color)
16 : m_symbol(nullptr)
17{
18 m_name = name;
19 m_sizeX = a;
20 m_sizeY = (b < 0.0) ? a : b;
21
22 m_offsetX = xoffset;
23 m_offsetY = yoffset;
24 m_rotation = rot;
25 m_color = color;
26 m_northPA = 0;
27 m_center.setRA(0);
28 m_center.setDec(0);
29
30 switch (shape)
31 {
32 case FOVItem::SQUARE:
33 m_symbol = new SquareFOV();
34 break;
35 case FOVItem::CIRCLE:
36 m_symbol = new CircleFOV();
37 break;
38 case FOVItem::CROSSHAIRS:
39 m_symbol = new CrosshairFOV();
40 break;
41 case FOVItem::BULLSEYE:
42 m_symbol = new BullsEyeFOV();
43 break;
44 case FOVItem::SOLIDCIRCLE:
45 m_symbol = new SolidCircleFOV();
46 break;
47 default:
48 break;
49 }
50
51 if (m_symbol)
52 addChildNode(m_symbol);
53}
54
55void FOVSymbolNode::update(float zoomFactor)
56{
57 show();
58 float pixelSizeX = m_sizeX * zoomFactor / 57.3 / 60.0;
59 float pixelSizeY = m_sizeY * zoomFactor / 57.3 / 60.0;
60
61 float offsetXPixelSize = m_offsetX * zoomFactor / 57.3 / 60.0;
62 float offsetYPixelSize = m_offsetY * zoomFactor / 57.3 / 60.0;
63 SkyMapLite *map = SkyMapLite::Instance();
64
66
67 if (m_center.ra().Degrees() > 0)
68 {
69 m_center.EquatorialToHorizontal(KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
70 QPointF skypoint_center = map->projector()->toScreen(&m_center);
71 newMatrix.translate(skypoint_center.toPoint().x(), skypoint_center.toPoint().y());
72 }
73 else
74 {
75 QPoint center(map->width() / 2, map->height() / 2);
76 newMatrix.translate(center.x(), center.y());
77 }
78
80 newMatrix.rotate(m_rotation + m_northPA, 0, 0, 1);
81
82 m_symbol->setMatrix(newMatrix);
83
84 m_symbol->updateSymbol(m_color, pixelSizeX, pixelSizeY);
85}
86
87FOVSymbolBase::FOVSymbolBase(FOVItem::Shape shape) : m_shape(shape) //Will be changed by the subclass
88{
89}
90
91SquareFOV::SquareFOV() : FOVSymbolBase(FOVItem::SQUARE)
92{
93 rect1 = new RectNode();
94 appendChildNode(rect1);
95
96 rect2 = new RectNode();
97 appendChildNode(rect2);
98
99 lines = new QSGGeometryNode;
100 appendChildNode(lines);
101
102 lines->setGeometry(new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 0));
103 lines->setOpaqueMaterial(new QSGFlatColorMaterial);
104 lines->setFlag(QSGNode::OwnsGeometry);
105 lines->setFlag(QSGNode::OwnsMaterial);
106 lines->geometry()->allocate(6);
107 lines->geometry()->setDrawingMode(GL_LINES);
108}
109
110void SquareFOV::updateSymbol(QColor color, float pixelSizeX, float pixelSizeY)
111{
112 QPoint center(0, 0);
113
114 /*if (m_imageDisplay)
115 {
116 //QTransform imageT;
117 //imageT.rotate(m_rotation+m_northPA);
118 //p.drawImage(targetRect, m_image.transformed(imageT));
119 p.drawImage(targetRect, m_image);
120 }*/
121
122 rect1->setRect(center.x() - pixelSizeX / 2, center.y() - pixelSizeY / 2, pixelSizeX, pixelSizeY);
123 rect1->setColor(color);
124
125 rect2->setRect(center.x(), center.y() - (3 * pixelSizeY / 5), pixelSizeX / 40, pixelSizeX / 10);
126 rect2->setColor(color);
127
128 QSGFlatColorMaterial *material = static_cast<QSGFlatColorMaterial *>(lines->opaqueMaterial());
129 if (material->color() != color)
130 {
131 material->setColor(color);
133 }
134
135 QSGGeometry::Point2D *vertex = lines->geometry()->vertexDataAsPoint2D();
136 vertex[0].set(center.x() - pixelSizeX / 30, center.y() - (3 * pixelSizeY / 5));
137 vertex[1].set(center.x() + pixelSizeX / 20, center.y() - (3 * pixelSizeY / 5));
138
139 vertex[2].set(center.x() - pixelSizeX / 30, center.y() - (3 * pixelSizeY / 5));
140 vertex[3].set(center.x() + pixelSizeX / 70, center.y() - (0.7 * pixelSizeY));
141
142 vertex[4].set(center.x() + pixelSizeX / 20, center.y() - (3 * pixelSizeY / 5));
143 vertex[5].set(center.x() + pixelSizeX / 70, center.y() - (0.7 * pixelSizeY));
144
146}
147
148CircleFOV::CircleFOV() : FOVSymbolBase(FOVItem::CIRCLE)
149{
150 el = new EllipseNode();
151 appendChildNode(el);
152}
153
154void CircleFOV::updateSymbol(QColor color, float pixelSizeX, float pixelSizeY)
155{
156 el->setColor(color);
157 el->updateGeometry(0, 0, pixelSizeX / 2, pixelSizeY / 2, false);
158}
159
160CrosshairFOV::CrosshairFOV() : FOVSymbolBase(FOVItem::CROSSHAIRS)
161{
162 lines = new QSGGeometryNode;
163 appendChildNode(lines);
164
165 lines->setGeometry(new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 0));
166 lines->setOpaqueMaterial(new QSGFlatColorMaterial);
167 lines->setFlag(QSGNode::OwnsGeometry);
168 lines->setFlag(QSGNode::OwnsMaterial);
169 lines->geometry()->allocate(8);
170 lines->geometry()->setDrawingMode(GL_LINES);
171
172 el1 = new EllipseNode;
173 appendChildNode(el1);
174
175 el2 = new EllipseNode;
176 appendChildNode(el2);
177}
178
179void CrosshairFOV::updateSymbol(QColor color, float pixelSizeX, float pixelSizeY)
180{
181 QPoint center(0, 0);
182
183 QSGGeometry::Point2D *vertex = lines->geometry()->vertexDataAsPoint2D();
184 vertex[0].set(center.x() + 0.5 * pixelSizeX, center.y());
185 vertex[1].set(center.x() + 1.5 * pixelSizeX, center.y());
186
187 vertex[2].set(center.x() - 0.5 * pixelSizeX, center.y());
188 vertex[3].set(center.x() - 1.5 * pixelSizeX, center.y());
189
190 vertex[4].set(center.x(), center.y() + 0.5 * pixelSizeY);
191 vertex[5].set(center.x(), center.y() + 1.5 * pixelSizeY);
192
193 vertex[6].set(center.x(), center.y() - 0.5 * pixelSizeY);
194 vertex[7].set(center.x(), center.y() - 1.5 * pixelSizeY);
195
197
198 //Draw circles at 0.5 & 1 degrees
199 el1->setColor(color);
200 el1->updateGeometry(center.x(), center.y(), 0.5 * pixelSizeX, 0.5 * pixelSizeY, false);
201
202 el2->setColor(color);
203 el1->updateGeometry(center.x(), center.y(), pixelSizeX, pixelSizeY, false);
204}
205
206BullsEyeFOV::BullsEyeFOV() : FOVSymbolBase(FOVItem::BULLSEYE)
207{
208 el1 = new EllipseNode;
209 appendChildNode(el1);
210
211 el2 = new EllipseNode;
212 appendChildNode(el2);
213
214 el3 = new EllipseNode;
215 appendChildNode(el3);
216}
217
218void BullsEyeFOV::updateSymbol(QColor color, float pixelSizeX, float pixelSizeY)
219{
220 el1->setColor(color);
221 el1->updateGeometry(0, 0, 0.5 * pixelSizeX, 0.5 * pixelSizeY, false);
222
223 el2->setColor(color);
224 el2->updateGeometry(0, 0, 2.0 * pixelSizeX, 2.0 * pixelSizeY, false);
225
226 el3->setColor(color);
227 el3->updateGeometry(0, 0, 4.0 * pixelSizeX, 4.0 * pixelSizeY, false);
228}
229
230SolidCircleFOV::SolidCircleFOV() : FOVSymbolBase(FOVItem::SOLIDCIRCLE)
231{
232 el = new EllipseNode;
233 appendChildNode(el);
234}
235
236void SolidCircleFOV::updateSymbol(QColor color, float pixelSizeX, float pixelSizeY)
237{
238 QColor colorAlpha = color;
239 colorAlpha.setAlpha(127);
240 el->setColor(colorAlpha);
241 el->updateGeometry(0, 0, pixelSizeX / 2, pixelSizeY / 2, false);
242}
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)
This class handles representation of FOV symbols in SkyMapLite.
Definition fovitem.h:18
Shape
FOV symbol types.
Definition fovitem.h:22
FOVSymbolBase is a virtual class that should be subclassed by every type of FOV symbol.
virtual void updateSymbol(QColor color, float pixelSizeX, float pixelSizeY)=0
updates geometry (position, size) of elements of this FOV symbol
FOVSymbolBase(FOVItem::Shape shape)
FOVSymbolNode(const QString &name, float a, float b, float xoffset, float yoffset, float rot, FOVItem::Shape shape=FOVItem::SQUARE, const QString &color="#FFFFFF")
Constructor.
QSGGeometryNode derived class that draws filled and non-filled rectangles.
Definition rectnode.h:22
void setRect(int x, int y, int w, int h)
setRect sets rectangle to display
Definition rectnode.cpp:25
void setColor(const QColor &color)
setColor sets the color of rectangle
Definition rectnode.cpp:35
This is the main item that displays all SkyItems.
Definition skymaplite.h:59
const Projector * projector() const
Get the current projector.
Definition skymaplite.h:323
virtual void show()
shows all child nodes (sets opacity of m_opacity to 1)
Definition skynode.cpp:27
virtual void update()
Updates coordinate of the object on SkyMapLite.
Definition skynode.h:48
SkyMapLite * map() const
short function to access SkyMapLite
Definition skynode.h:45
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
const QSGGeometry * geometry() const const
const QColor & color() const const
void setColor(const QColor &color)
const QSGGeometry::AttributeSet & defaultAttributes_Point2D()
QSGMaterial * opaqueMaterial() const const
void appendChildNode(QSGNode *node)
void markDirty(QSGNode::DirtyState bits)
void setMatrix(const QMatrix4x4 &matrix)
QTextStream & center(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:45:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.