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