Kstars

satellitenode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "satellitenode.h"
7
8#include "ksutils.h"
9#include "labelnode.h"
10#include "linelist.h"
11#include "Options.h"
12#include "satellite.h"
13#include "nodes/pointnode.h"
14#include "nodes/polynode.h"
15#include "../rootnode.h"
16#include "../labelsitem.h"
17
18#include <QSGFlatColorMaterial>
19
21 : m_sat(sat), m_rootNode(rootNode)
22{
23}
24
26{
27 if (m_point)
28 {
29 delete m_point;
30 m_point = 0;
31 }
32 if (!m_lines)
33 {
34 m_lines = new QSGGeometryNode;
36 m_lines->setGeometry(m_geometry);
38 m_geometry->setDrawingMode(GL_LINES);
39
40 m_material = new QSGFlatColorMaterial;
41 m_lines->setOpaqueMaterial(m_material);
43 addChildNode(m_lines);
44
45 m_geometry->allocate(8);
47
48 vertex[0].set(-0.5, -0.5);
49 vertex[1].set(0.5, -0.5);
50 vertex[2].set(0.5, -0.5);
51 vertex[3].set(0.5, 0.5);
52 vertex[4].set(0.5, 0.5);
53 vertex[5].set(-0.5, 0.5);
54 vertex[6].set(-0.5, 0.5);
55 vertex[7].set(-0.5, -0.5);
56
59 }
60}
61
63{
64 if (m_lines)
65 {
66 delete m_lines;
67 m_lines = 0;
68 }
69 if (!m_point)
70 {
71 m_point = new PointNode(m_rootNode, 'B', 3.5);
72 addChildNode(m_point);
73 }
74}
75
77{
78 if (m_sat->selected())
79 {
80 KStarsData *data = KStarsData::Instance();
81 const Projector *m_proj = SkyMapLite::Instance()->projector();
82 QPointF pos;
83
84 bool visible = false;
85
86 m_sat->HorizontalToEquatorial(data->lst(), data->geo()->lat());
87
88 pos = m_proj->toScreen(m_sat, true, &visible);
89
90 if (!visible || !m_proj->onScreen(pos))
91 {
92 hide();
93 return;
94 }
95 show();
96
97 if (Options::drawSatellitesLikeStars())
98 {
99 initPoint();
100 }
101 else
102 {
103 QColor color;
104 initLines();
105 if (m_sat->isVisible())
106 color = data->colorScheme()->colorNamed("VisibleSatColor");
107 else
108 color = data->colorScheme()->colorNamed("SatColor");
109
110 m_material->setColor(color);
111 }
112
113 changePos(pos);
114
115 if (Options::showSatellitesLabels())
116 {
117 if (!m_label)
118 {
119 m_label = SkyMapLite::rootNode()->labelsItem()->addLabel(m_sat, LabelsItem::label_t::SATELLITE_LABEL);
120 }
121 m_label->setLabelPos(pos);
122 }
123 }
124 else
125 {
126 hide();
127 }
128}
129
131{
133 if (m_label)
134 m_label->hide();
135}
136
138{
139 //QSizeF size = m_point->size();
140 QMatrix4x4 m(1, 0, 0, pos.x(), 0, 1, 0, pos.y(), 0, 0, 1, 0, 0, 0, 0, 1);
141 //m.translate(-0.5*size.width(), -0.5*size.height());
142
143 setMatrix(m);
145}
QColor colorNamed(const QString &name) const
Retrieve a color by name.
const CachingDms * lat() const
Definition geolocation.h:70
KStarsData is the backbone of KStars.
Definition kstarsdata.h:72
CachingDms * lst()
Definition kstarsdata.h:224
ColorScheme * colorScheme()
Definition kstarsdata.h:172
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...
SkyOpacityNode derived class that represents stars and planets using cached QSGTexture.
Definition pointnode.h:25
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
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
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition projector.cpp:98
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
virtual void changePos(QPointF pos) override
changes the position of SkyNode on SkyMapLite.
void initLines()
Initialize m_lines (if not already) to draw satellite with lines.
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
SatelliteNode(Satellite *sat, RootNode *rootNode)
Constructor.
void initPoint()
Initialize m_point (if not already) to draw satellite as a star.
virtual void update() override
Update position and visibility of satellite.
Represents an artificial satellites.
Definition satellite.h:23
bool isVisible()
bool selected()
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
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
qreal x() const const
qreal y() const const
void setGeometry(QSGGeometry *geometry)
void setColor(const QColor &color)
void allocate(int vertexCount, int indexCount)
const AttributeSet & defaultAttributes_Point2D()
void setDrawingMode(unsigned int mode)
Point2D * vertexDataAsPoint2D()
void setOpaqueMaterial(QSGMaterial *material)
void markDirty(DirtyState bits)
void setFlag(Flag f, bool enabled)
void setMatrix(const QMatrix4x4 &matrix)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:49:22 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.