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 "linesitem.h"
0007 
0008 #include "linelist.h"
0009 #include "linelistindex.h"
0010 #include "projections/projector.h"
0011 #include "../skynodes/nodes/linenode.h"
0012 #include "../skynodes/trixelnode.h"
0013 
0014 #include <QSGNode>
0015 
0016 LineIndexNode::LineIndexNode(const QString &color) : schemeColor(color)
0017 {
0018 }
0019 
0020 LinesItem::LinesItem(RootNode *rootNode) : SkyItem(LabelsItem::label_t::NO_LABEL, rootNode)
0021 {
0022 }
0023 
0024 void LinesItem::addLinesComponent(LineListIndex *linesComp, QString color, int width, Qt::PenStyle style)
0025 {
0026     LineIndexNode *node = new LineIndexNode(color);
0027     appendChildNode(node);
0028 
0029     m_lineIndexes.insert(node, linesComp);
0030     LineListHash *list = linesComp->lineIndex();
0031     //Sort by trixels
0032     QMap<Trixel, std::shared_ptr<LineListList>> trixels;
0033 
0034     auto s = list->cbegin();
0035 
0036     while (s != list->cend())
0037     {
0038         trixels.insert(s.key(), *s);
0039         s++;
0040     }
0041 
0042     auto i = trixels.cbegin();
0043     QList<std::shared_ptr<LineList>> addedLines;
0044 
0045     while (i != trixels.cend())
0046     {
0047         std::shared_ptr<LineListList> linesList = *i;
0048 
0049         if (linesList->size())
0050         {
0051             TrixelNode *trixel = new TrixelNode(i.key());
0052 
0053             node->appendChildNode(trixel);
0054 
0055             QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed(color);
0056 
0057             for (int c = 0; c < linesList->size(); ++c)
0058             {
0059                 std::shared_ptr<LineList> list = linesList->at(c);
0060 
0061                 if (!addedLines.contains(list))
0062                 {
0063                     trixel->appendChildNode(new LineNode(linesList->at(c).get(), 0, schemeColor, width, style));
0064                     addedLines.append(list);
0065                 }
0066             }
0067         }
0068         ++i;
0069     }
0070 }
0071 
0072 void LinesItem::update()
0073 {
0074     QMap<LineIndexNode *, LineListIndex *>::iterator i = m_lineIndexes.begin();
0075 
0076     UpdateID updateID = KStarsData::Instance()->updateID();
0077 
0078     while (i != m_lineIndexes.end())
0079     {
0080         LineIndexNode *node = i.key();
0081         QColor schemeColor  = KStarsData::Instance()->colorScheme()->colorNamed(node->getSchemeColor());
0082         if (i.value()->selected())
0083         {
0084             node->show();
0085 
0086             QSGNode *n = node->firstChild();
0087             while (n != 0)
0088             {
0089                 TrixelNode *trixel = static_cast<TrixelNode *>(n);
0090                 trixel->show();
0091 
0092                 QSGNode *l = trixel->firstChild();
0093                 while (l != 0)
0094                 {
0095                     LineNode *lines = static_cast<LineNode *>(l);
0096                     lines->setColor(schemeColor);
0097                     l = l->nextSibling();
0098 
0099                     LineList *lineList = lines->lineList();
0100                     if (lineList->updateID != updateID)
0101                         i.value()->JITupdate(lineList);
0102 
0103                     lines->updateGeometry();
0104                 }
0105                 n = n->nextSibling();
0106             }
0107         }
0108         else
0109         {
0110             node->hide();
0111         }
0112         ++i;
0113     }
0114 }