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 "equatoritem.h" 0007 0008 #include "projections/projector.h" 0009 #include "../rootnode.h" 0010 #include "../labelsitem.h" 0011 #include "../skynodes/labelnode.h" 0012 #include "../skynodes/trixelnode.h" 0013 #include "../skynodes/nodes/linenode.h" 0014 0015 #include <QSGNode> 0016 0017 EquatorItem::EquatorItem(Equator *equatorComp, RootNode *rootNode) 0018 : SkyItem(LabelsItem::label_t::EQUATOR_LABEL, rootNode), m_equatorComp(equatorComp) 0019 { 0020 LineListHash *trixels = equatorComp->lineIndex(); 0021 0022 auto i = trixels->cbegin(); 0023 0024 while (i != trixels->cend()) 0025 { 0026 std::shared_ptr<LineListList> linesList = *i; 0027 QList<std::shared_ptr<LineList>> addedLines; 0028 0029 if (linesList->size()) 0030 { 0031 QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("EqColor"); 0032 0033 for (int c = 0; c < linesList->size(); ++c) 0034 { 0035 std::shared_ptr<LineList> lines = linesList->at(c); 0036 0037 if (!addedLines.contains(lines)) 0038 { 0039 LineNode *ln = new LineNode(linesList->at(c).get(), 0, schemeColor, 1, Qt::SolidLine); 0040 0041 appendChildNode(ln); 0042 addedLines.append(lines); 0043 } 0044 } 0045 } 0046 ++i; 0047 } 0048 0049 //Add compass labels 0050 for (int ra = 0; ra < 23; ra += 2) 0051 { 0052 SkyPoint *o = new SkyPoint(ra, 0.0); 0053 0054 QString label; 0055 label.setNum(o->ra().hour()); 0056 0057 LabelNode *compass = rootNode->labelsItem()->addLabel(label, labelType()); 0058 m_compassLabels.insert(o, compass); 0059 } 0060 } 0061 0062 void EquatorItem::update() 0063 { 0064 if (m_equatorComp->selected()) 0065 { 0066 show(); 0067 QColor schemeColor = KStarsData::Instance()->colorScheme()->colorNamed("EqColor"); 0068 0069 UpdateID updateID = KStarsData::Instance()->updateID(); 0070 0071 QSGNode *l = firstChild(); 0072 while (l != 0) 0073 { 0074 LineNode *lines = static_cast<LineNode *>(l); 0075 lines->setColor(schemeColor); 0076 l = l->nextSibling(); 0077 0078 LineList *lineList = lines->lineList(); 0079 if (lineList->updateID != updateID) 0080 m_equatorComp->JITupdate(lineList); 0081 0082 lines->updateGeometry(); 0083 } 0084 0085 const Projector *proj = SkyMapLite::Instance()->projector(); 0086 KStarsData *data = KStarsData::Instance(); 0087 0088 QMap<SkyPoint *, LabelNode *>::iterator i = m_compassLabels.begin(); 0089 0090 while (i != m_compassLabels.end()) 0091 { 0092 SkyPoint *c = i.key(); 0093 c->EquatorialToHorizontal(data->lst(), data->geo()->lat()); 0094 0095 LabelNode *compass = (*i); 0096 0097 bool visible; 0098 QPointF cpoint = proj->toScreen(c, false, &visible); 0099 if (visible && proj->checkVisibility(c)) 0100 { 0101 compass->setLabelPos(cpoint); 0102 } 0103 else 0104 { 0105 compass->hide(); 0106 } 0107 ++i; 0108 } 0109 } 0110 else 0111 { 0112 hide(); 0113 } 0114 }