Kstars

milkywayitem.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "milkywayitem.h"
7
8#include "linelist.h"
9#include "linelistindex.h"
10#include "milkyway.h"
11#include "Options.h"
12#include "../skynodes/skypolygonnode.h"
13#include "../skynodes/trixelnode.h"
14#include "../skynodes/nodes/linenode.h"
15
16#include <QSGNode>
17
18MilkyWayItem::MilkyWayItem(MilkyWay *mwComp, RootNode *rootNode)
19 : SkyItem(LabelsItem::label_t::NO_LABEL, rootNode), m_filled(Options::fillMilkyWay()), m_MWComp(mwComp)
20{
21 initialize();
22}
23
24void MilkyWayItem::initialize()
25{
26 LineListHash *trixels = m_MWComp->polyIndex();
27
28 while (QSGNode *n = firstChild())
29 {
31 delete n;
32 }
33
34 auto i = trixels->cbegin();
36
37 while (i != trixels->cend())
38 {
39 std::shared_ptr<LineListList> linesList = *i;
40
41 if (linesList->size())
42 {
43 TrixelNode *trixel = new TrixelNode(i.key());
44
45 appendChildNode(trixel);
46
47 QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("MWColor");
48
49 for (int c = 0; c < linesList->size(); ++c)
50 {
51 std::shared_ptr<LineList> list = linesList->at(c);
52
53 if (!addedLines.contains(list))
54 {
55 if (m_filled)
56 {
57 SkyPolygonNode *poly = new SkyPolygonNode(list.get());
58
59 schemeColor.setAlpha(0.7 * 255);
60 poly->setColor(schemeColor);
61 trixel->appendChildNode(poly);
62 }
63 else
64 {
65 LineNode *ln = new LineNode(list.get(), m_MWComp->skipList(list.get()), schemeColor, 3, Qt::SolidLine);
66
67 trixel->appendChildNode(ln);
68 }
69 addedLines.append(list);
70 }
71 }
72 }
73 ++i;
74 }
75}
76
77void MilkyWayItem::update()
78{
79 if (m_MWComp->selected())
80 {
81 show();
82 QSGNode *n = firstChild();
83
84 DrawID drawID = SkyMesh::Instance()->drawID();
85 UpdateID updateID = KStarsData::Instance()->updateID();
86
87 QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("MWColor");
88
89 if (Options::fillMilkyWay() != m_filled)
90 {
91 m_filled = Options::fillMilkyWay();
92 initialize();
93 }
94
95 while (n != 0)
96 {
97 TrixelNode *trixel = static_cast<TrixelNode *>(n);
98 trixel->show();
99 n = n->nextSibling();
100
101 QSGNode *l = trixel->firstChild();
102 while (l != 0)
103 {
104 if (m_filled)
105 {
106 SkyPolygonNode *polygon = static_cast<SkyPolygonNode *>(l);
107 LineList *lineList = polygon->lineList();
108 polygon->setColor(schemeColor);
109
110 if (lineList->drawID == drawID)
111 {
112 polygon->hide();
113 l = l->nextSibling();
114 continue;
115 }
116
117 lineList->drawID = drawID;
118 if (lineList->updateID != updateID)
119 m_MWComp->JITupdate(lineList);
120
121 polygon->update();
122 }
123 else
124 {
125 LineNode *lines = static_cast<LineNode *>(l);
126 QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("MWColor");
127 lines->setColor(schemeColor);
128
129 LineList *lineList = lines->lineList();
130 if (lineList->drawID == drawID)
131 {
132 lines->hide();
133 l = l->nextSibling();
134 continue;
135 }
136 lineList->drawID = drawID;
137 if (lineList->updateID != updateID)
138 m_MWComp->JITupdate(lineList);
139
140 lines->updateGeometry();
141 }
142 l = l->nextSibling();
143 }
144 }
145 }
146 else
147 {
148 hide();
149 }
150}
This class is in charge of labels in SkyMapLite.
Definition labelsitem.h:53
virtual void JITupdate(LineList *lineList)
this is called from within the draw routines when the updateID of the lineList is stale.
A simple data container used by LineListIndex.
Definition linelist.h:25
DrawID drawID
A global drawID (in SkyMesh) is updated at the start of each draw cycle.
Definition linelist.h:44
SkyOpacityNode derived class that draws lines from LineList.
Definition linenode.h:28
void updateGeometry()
Update lines based on the visibility of line segments in m_lineList.
Definition linenode.cpp:65
Class that handles drawing of MilkyWay (both filled and non-filled)
Definition milkyway.h:25
SkipHashList * skipList(LineList *lineList) override
Returns a boolean indicating whether to skip the i-th line segment in the SkipList skipList.
Definition milkyway.cpp:43
bool selected() override
Definition milkyway.cpp:48
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
This is an interface for implementing SkyItems that represent SkyComponent derived objects on the Sky...
Definition skyitem.h:30
virtual void hide() override
hides this item and corresponding labels
Definition skyitem.cpp:37
virtual void show() override
makes this node visible
Definition skyitem.cpp:23
static SkyMesh * Instance()
returns the default instance of SkyMesh or null if it has not yet been created.
Definition skymesh.cpp:39
virtual void hide()
hides this node
A SkyNode derived class that represents polygon (either filled or non-filled) One of the applications...
void update(bool forceClip=true)
Update position and visibility of this polygon.
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
Convenience class that represents trixel in SkyMapLite.
Definition trixelnode.h:21
virtual void show() override
makes this node visible
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void initialize(StandardShortcut id)
void setAlpha(int alpha)
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
QSGNode * nextSibling() const const
void removeChildNode(QSGNode *node)
SolidLine
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.