Kstars

satellitenode.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
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);
46  QSGGeometry::Point2D *vertex = m_geometry->vertexDataAsPoint2D();
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 {
132  SkyNode::hide();
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 }
SkyOpacityNode derived class that represents stars and planets using cached QSGTexture.
Definition: pointnode.h:24
bool isVisible()
Definition: satellite.cpp:1294
void setDrawingMode(unsigned int mode)
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
void initPoint()
Initialize m_point (if not already) to draw satellite as a star.
void set(float x, float y)
CachingDms * lst()
Definition: kstarsdata.h:223
bool selected()
Definition: satellite.cpp:1299
void setGeometry(QSGGeometry *geometry)
SatelliteNode(Satellite *sat, RootNode *rootNode)
Constructor.
void setOpaqueMaterial(QSGMaterial *material)
bool onScreen(const QPointF &p) const
Check whether the projected point is on-screen.
Definition: projector.cpp:98
const QSGGeometry::AttributeSet & defaultAttributes_Point2D()
const Projector * projector() const
Get the current projector.
Definition: skymaplite.h:323
const CachingDms * lat() const
Definition: geolocation.h:70
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
GeoLocation * geo()
Definition: kstarsdata.h:229
bool visible()
Definition: skynode.cpp:44
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
void setMatrix(const QMatrix4x4 &matrix)
virtual void changePos(QPointF pos) override
changes the position of SkyNode on SkyMapLite.
void markDirty(QSGNode::DirtyState bits)
void setColor(const QColor &color)
qreal x() const const
qreal y() const const
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 setLabelPos(QPointF pos)
set the position of label with the given offset from SkyObject's position and makes the label visible...
Definition: labelnode.cpp:123
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
virtual void show()
shows all child nodes (sets opacity of m_opacity to 1)
Definition: skynode.cpp:27
void allocate(int vertexCount, int indexCount)
void initLines()
Initialize m_lines (if not already) to draw satellite with lines.
QSGGeometry::Point2D * vertexDataAsPoint2D()
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:86
virtual void update() override
Update position and visibility of satellite.
LabelNode * addLabel(SkyObject *skyObject, label_t labelType)
Create LabelNode with given skyObject and append it to LabelTypeNode that corresponds to type.
Definition: labelsitem.cpp:111
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition: skynode.cpp:21
void setFlag(QSGNode::Flag f, bool enabled)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.