Kstars

pointsourcenode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6#include "skyobject.h"
7#include "Options.h"
8
9#include <QSGSimpleTextureNode>
10
11#include "pointsourcenode.h"
12#include "nodes/pointnode.h"
13
14#include "../rootnode.h"
15#include "../labelsitem.h"
16#include "labelnode.h"
17
19 char spType, float size, short trixel)
20 : SkyNode(skyObject), m_rootNode(parentNode), m_spType(spType), m_size(size),
21 m_labelType(labelType), m_trixel(trixel)
22{
23}
24
25float PointSourceNode::starWidth(float mag) const
26{
27 //adjust maglimit for ZoomLevel
28 const double maxSize = 10.0;
29
30 double lgmin = log10(MINZOOM);
31 // double lgmax = log10(MAXZOOM);
32 double lgz = log10(Options::zoomFactor());
33
34 float sizeFactor = maxSize + (lgz - lgmin);
35
36 float m_sizeMagLim = map()->sizeMagLim();
37
38 float size = (sizeFactor * (m_sizeMagLim - mag) / m_sizeMagLim) + 1.;
39 if (size <= 1.0)
40 size = 1.0;
41 if (size > maxSize)
42 size = maxSize;
43
44 return size;
45}
46
47PointSourceNode::~PointSourceNode()
48{
49 if (m_label &&
50 (m_labelType == LabelsItem::label_t::STAR_LABEL || m_labelType == LabelsItem::label_t::CATALOG_STAR_LABEL))
51 {
52 m_rootNode->labelsItem()->deleteLabel(m_label);
53 }
54}
55
57{
58 if (!m_point)
59 {
60 m_point = new PointNode(m_rootNode, m_spType, starWidth(m_size));
61 addChildNode(m_point);
62 }
63 show();
64 m_point->setSize(starWidth(m_skyObject->mag())); //Set points size base on the magnitude of object
65}
66
68{
69 QSizeF size = m_point->size();
70 QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1);
71 m.translate(-0.5 * size.width(), -0.5 * size.height());
72
73 setMatrix(m);
75}
76
78{
79 if (!projector()->checkVisibility(m_skyObject))
80 {
81 hide();
82 return;
83 }
84
85 bool visible = false;
86 pos = projector()->toScreen(m_skyObject, true, &visible);
87 if (visible &&
88 projector()->onScreen(
89 pos)) // FIXME: onScreen here should use canvas size rather than SkyMap size, especially while printing in portrait mode! (Inherited from SkyMap)
90 {
91 updatePos(pos, m_drawLabel);
92 }
93 else
94 {
95 hide();
96 }
97}
98
99void PointSourceNode::updatePos(QPointF pos, bool drawLabel)
100{
101 updatePoint();
102 changePos(pos);
103
104 m_drawLabel = drawLabel;
105
106 if (m_drawLabel && m_labelType != LabelsItem::label_t::NO_LABEL)
107 {
108 if (!m_label) //This way labels will be created only when they are needed
109 {
110 if (m_trixel != -1)
111 {
112 m_label = m_rootNode->labelsItem()->addLabel(m_skyObject, m_labelType, m_trixel);
113 }
114 else
115 {
116 m_label = m_rootNode->labelsItem()->addLabel(m_skyObject, m_labelType);
117 }
118 }
119 m_label->setLabelPos(pos);
120 }
121 else
122 {
123 if (m_label)
124 m_label->hide();
125 }
126}
127
129{
130 if (m_label)
131 m_label->hide();
133}
void setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
LabelNode * addLabel(SkyObject *skyObject, label_t labelType)
Create LabelNode with given skyObject and append it to LabelTypeNode that corresponds to type.
label_t
The label_t enum.
Definition labelsitem.h:62
void deleteLabel(LabelNode *label)
deletes particular label
SkyOpacityNode derived class that represents stars and planets using cached QSGTexture.
Definition pointnode.h:25
void setSize(float size)
setSize update size of PointNode with the given parameter
Definition pointnode.cpp:23
virtual void hide() override
hides this node and its label.
PointSourceNode(SkyObject *skyObject, RootNode *parentNode, LabelsItem::label_t labelType=LabelsItem::label_t::STAR_LABEL, char spType='A', float size=1, short trixel=-1)
Constructor.
virtual void update() override
update updates coordinates of this node based on the visibility of its SkyObject
void updatePoint()
updatePoint initializes PointNode if not done that yet.
void updatePos(QPointF pos, bool drawLabel)
updatePos updates position of this node and its label.
virtual void changePos(QPointF pos) override
changePos changes the position m_point
float starWidth(float mag) const
Get the width of a star of magnitude mag.
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
float sizeMagLim() const
Used in PointSourceNode.
Definition skymaplite.h:341
Provides virtual functions for update of coordinates and nodes hiding.
Definition skynode.h:28
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
bool visible()
Definition skynode.cpp:44
SkyMapLite * map() const
short function to access SkyMapLite
Definition skynode.h:45
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
float mag() const
Definition skyobject.h:206
void translate(const QVector3D &vector)
qreal x() const const
qreal y() const const
void markDirty(DirtyState bits)
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 Oct 11 2024 12:15:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.