Kstars

deepskynode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "deepskynode.h"
7
8#include "deepskyobject.h"
9#include "dsosymbolnode.h"
10#include "labelnode.h"
11#include "Options.h"
12#include "skyobject.h"
13#include "trixelnode.h"
14#include "nodes/pointnode.h"
15#include "../rootnode.h"
16#include "../labelsitem.h"
17
18#include <QSGSimpleTextureNode>
19#include <QQuickWindow>
20
21
22DeepSkyNode::DeepSkyNode(DeepSkyObject *skyObject, DSOSymbolNode *symbol, LabelsItem::label_t labelType, short trixel)
23 : m_trixel(trixel), m_labelType(labelType), m_dso(skyObject), m_symbol(symbol)
24{
25 m_symbol->hide();
26}
27
29{
30 if (m_label)
31 SkyMapLite::rootNode()->labelsItem()->deleteLabel(m_label);
32}
33
35{
36 QSizeF size = m_objImg->rect().size();
37 QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1);
38 //FIXME: this is probably incorrect (inherited from drawDeepSkyImage())
39 m.rotate(m_angle, 0, 0, 1);
40 m.translate(-0.5 * size.width(), -0.5 * size.height());
41
42 setMatrix(m);
44}
45
47{
48 if (m_symbol->getColor() != color)
49 {
50 delete m_symbol;
51 m_symbol = new DSOSymbolNode(m_dso, color);
52 symbolTrixel->appendChildNode(m_symbol);
53 }
54
55 //m_label->setColor
56}
57
58void DeepSkyNode::update(bool drawImage, bool drawLabel, QPointF pos)
59{
60 if (pos.x() == -1 && pos.y() == -1)
61 {
62 const Projector *proj = projector();
63 if (!proj->checkVisibility(m_dso))
64 {
65 hide();
66 return;
67 }
68
69 bool visible = false;
70 pos = proj->toScreen(m_dso, true, &visible);
71 if (!visible || !proj->onScreen(pos))
72 {
73 hide();
74 return;
75 }
76 }
77 show();
78
79 // if size is 0.0 set it to 1.0, this are normally stars (type 0 and 1)
80 // if we use size 0.0 the star wouldn't be drawn
81 float majorAxis = m_dso->a();
82 if (majorAxis == 0.0)
83 {
84 majorAxis = 1.0;
85 }
86
87 float size = majorAxis * dms::PI * Options::zoomFactor() / 10800.0;
88
89 double zoom = Options::zoomFactor();
90 double w = m_dso->a() * dms::PI * zoom / 10800.0;
91 double h = m_dso->e() * w;
92
93 m_angle = projector()->findPA(m_dso, pos.x(), pos.y());
94
95 if (drawImage && Options::zoomFactor() > 5. * MINZOOM)
96 {
97 if (!(m_dso->image().isNull()))
98 {
99 if (!m_objImg)
100 {
101 m_objImg = new QSGSimpleTextureNode;
102 m_objImg->setTexture(SkyMapLite::Instance()->window()->createTextureFromImage(
103 m_dso->image(), QQuickWindow::TextureCanUseAtlas));
104 m_objImg->setOwnsTexture(true);
105 m_opacity->appendChildNode(m_objImg);
106 }
107
108 m_objImg->setRect(0, 0, w, h);
109 changePos(pos);
110 }
111 }
112 else
113 {
114 hide();
115 }
116
117 //Draw symbol
118 m_symbol->update(size, pos, m_angle);
119
120 // Draw label
121 if (drawLabel)
122 {
123 if (!m_label)
124 {
125 if (m_trixel != -1)
126 {
127 m_label = SkyMapLite::rootNode()->labelsItem()->addLabel(m_dso, m_labelType, m_trixel);
128 }
129 else
130 {
131 m_label = SkyMapLite::rootNode()->labelsItem()->addLabel(m_dso, m_labelType);
132 }
133 }
134 m_label->setLabelPos(pos);
135 }
136 else if (m_label)
137 {
138 m_label->hide();
139 }
140}
141
143{
145 if (m_label)
146 m_label->hide();
147 m_symbol->hide();
148}
A SkyNode derived class used for Deep Sky symbols in SkyMapLite.
void update(float size, const QPointF &pos, float positionangle)
Update size and position of the symbol.
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
virtual ~DeepSkyNode()
Destructor.
void setColor(QColor color, TrixelNode *symbolTrixel)
sets color of DSO symbol and label To not increase the code for symbols we just recreate the symbol p...
virtual void changePos(QPointF pos) override
changePos changes the position of this node and rotate it according to m_angle
DeepSkyNode(DeepSkyObject *skyObject, DSOSymbolNode *symbol, LabelsItem::label_t labelType, short trixel=-1)
Constructor.
void setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
label_t
The label_t enum.
Definition labelsitem.h:62
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
virtual void show()
shows all child nodes (sets opacity of m_opacity to 1)
Definition skynode.cpp:27
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition skynode.cpp:21
virtual void update()
Updates coordinate of the object on SkyMapLite.
Definition skynode.h:48
bool visible()
Definition skynode.cpp:44
Convenience class that represents trixel in SkyMapLite.
Definition trixelnode.h:21
static constexpr double PI
PI is a const static member; it's public so that it can be used anywhere, as long as dms....
Definition dms.h:385
qreal x() const const
qreal y() const const
QSizeF size() const const
void appendChildNode(QSGNode *node)
void markDirty(DirtyState bits)
QRectF rect() const const
void setOwnsTexture(bool owns)
void setRect(const QRectF &r)
void setTexture(QSGTexture *texture)
void setMatrix(const QMatrix4x4 &matrix)
qreal height() const const
qreal width() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:48:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.