File indexing completed on 2024-04-28 15:10:46
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "milkywayitem.h" 0007 0008 #include "linelist.h" 0009 #include "linelistindex.h" 0010 #include "milkyway.h" 0011 #include "Options.h" 0012 #include "../skynodes/skypolygonnode.h" 0013 #include "../skynodes/trixelnode.h" 0014 #include "../skynodes/nodes/linenode.h" 0015 0016 #include <QSGNode> 0017 0018 MilkyWayItem::MilkyWayItem(MilkyWay *mwComp, RootNode *rootNode) 0019 : SkyItem(LabelsItem::label_t::NO_LABEL, rootNode), m_filled(Options::fillMilkyWay()), m_MWComp(mwComp) 0020 { 0021 initialize(); 0022 } 0023 0024 void MilkyWayItem::initialize() 0025 { 0026 LineListHash *trixels = m_MWComp->polyIndex(); 0027 0028 while (QSGNode *n = firstChild()) 0029 { 0030 removeChildNode(n); 0031 delete n; 0032 } 0033 0034 auto i = trixels->cbegin(); 0035 QList<std::shared_ptr<LineList>> addedLines; 0036 0037 while (i != trixels->cend()) 0038 { 0039 std::shared_ptr<LineListList> linesList = *i; 0040 0041 if (linesList->size()) 0042 { 0043 TrixelNode *trixel = new TrixelNode(i.key()); 0044 0045 appendChildNode(trixel); 0046 0047 QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("MWColor"); 0048 0049 for (int c = 0; c < linesList->size(); ++c) 0050 { 0051 std::shared_ptr<LineList> list = linesList->at(c); 0052 0053 if (!addedLines.contains(list)) 0054 { 0055 if (m_filled) 0056 { 0057 SkyPolygonNode *poly = new SkyPolygonNode(list.get()); 0058 0059 schemeColor.setAlpha(0.7 * 255); 0060 poly->setColor(schemeColor); 0061 trixel->appendChildNode(poly); 0062 } 0063 else 0064 { 0065 LineNode *ln = new LineNode(list.get(), m_MWComp->skipList(list.get()), schemeColor, 3, Qt::SolidLine); 0066 0067 trixel->appendChildNode(ln); 0068 } 0069 addedLines.append(list); 0070 } 0071 } 0072 } 0073 ++i; 0074 } 0075 } 0076 0077 void MilkyWayItem::update() 0078 { 0079 if (m_MWComp->selected()) 0080 { 0081 show(); 0082 QSGNode *n = firstChild(); 0083 0084 DrawID drawID = SkyMesh::Instance()->drawID(); 0085 UpdateID updateID = KStarsData::Instance()->updateID(); 0086 0087 QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("MWColor"); 0088 0089 if (Options::fillMilkyWay() != m_filled) 0090 { 0091 m_filled = Options::fillMilkyWay(); 0092 initialize(); 0093 } 0094 0095 while (n != 0) 0096 { 0097 TrixelNode *trixel = static_cast<TrixelNode *>(n); 0098 trixel->show(); 0099 n = n->nextSibling(); 0100 0101 QSGNode *l = trixel->firstChild(); 0102 while (l != 0) 0103 { 0104 if (m_filled) 0105 { 0106 SkyPolygonNode *polygon = static_cast<SkyPolygonNode *>(l); 0107 LineList *lineList = polygon->lineList(); 0108 polygon->setColor(schemeColor); 0109 0110 if (lineList->drawID == drawID) 0111 { 0112 polygon->hide(); 0113 l = l->nextSibling(); 0114 continue; 0115 } 0116 0117 lineList->drawID = drawID; 0118 if (lineList->updateID != updateID) 0119 m_MWComp->JITupdate(lineList); 0120 0121 polygon->update(); 0122 } 0123 else 0124 { 0125 LineNode *lines = static_cast<LineNode *>(l); 0126 QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("MWColor"); 0127 lines->setColor(schemeColor); 0128 0129 LineList *lineList = lines->lineList(); 0130 if (lineList->drawID == drawID) 0131 { 0132 lines->hide(); 0133 l = l->nextSibling(); 0134 continue; 0135 } 0136 lineList->drawID = drawID; 0137 if (lineList->updateID != updateID) 0138 m_MWComp->JITupdate(lineList); 0139 0140 lines->updateGeometry(); 0141 } 0142 l = l->nextSibling(); 0143 } 0144 } 0145 } 0146 else 0147 { 0148 hide(); 0149 } 0150 }