Kstars

milkywayitem.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
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 
18 MilkyWayItem::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 
24 void MilkyWayItem::initialize()
25 {
26  LineListHash *trixels = m_MWComp->polyIndex();
27 
28  while (QSGNode *n = firstChild())
29  {
30  removeChildNode(n);
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 
77 void 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 }
void append(const T &value)
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
A base class that is used for displaying SkyComponents on SkyMapLite.
Definition: skyitem.h:29
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
void updateGeometry()
Update lines based on the visibility of line segments in m_lineList.
Definition: linenode.cpp:65
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
DrawID drawID
A global drawID (in SkyMesh) is updated at the start of each draw cycle.
Definition: linelist.h:44
Class that handles drawing of MilkyWay (both filled and non-filled)
Definition: milkyway.h:24
bool contains(const T &value) const const
QHash::const_iterator cend() const const
void initialize(StandardShortcut id)
virtual void show() override
makes this node visible
Definition: trixelnode.cpp:40
DrawID drawID() const
Definition: skymesh.h:264
ColorScheme * colorScheme()
Definition: kstarsdata.h:171
const T & at(int i) const const
void setAlpha(int alpha)
Convenience class that represents trixel in SkyMapLite.
Definition: trixelnode.h:20
SkyOpacityNode derived class that draws lines from LineList.
Definition: linenode.h:27
A SkyNode derived class that represents polygon (either filled or non-filled) One of the applications...
static SkyMesh * Instance()
returns the default instance of SkyMesh or null if it has not yet been created.
Definition: skymesh.cpp:39
QFlags< Option > Options
QHash::const_iterator cbegin() const const
SolidLine
void update(bool forceClip=true)
Update position and visibility of this polygon.
QSGNode * nextSibling() const const
virtual void hide()
hides this node
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:86
MESSAGECORE_EXPORT KMime::Content * firstChild(const KMime::Content *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:04:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.