File indexing completed on 2024-03-24 03:47:03

0001 /*
0002     SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "horizonitem.h"
0007 
0008 #include "horizoncomponent.h"
0009 #include "labelsitem.h"
0010 #include "Options.h"
0011 #include "rootnode.h"
0012 #include "skynodes/horizonnode.h"
0013 #include "skynodes/labelnode.h"
0014 
0015 HorizonItem::HorizonItem(HorizonComponent *hComp, RootNode *rootNode)
0016     : SkyItem(LabelsItem::label_t::HORIZON_LABEL, rootNode), m_horizonComp(hComp)
0017 {
0018     appendChildNode(new HorizonNode());
0019 
0020     double az = -0.01;
0021     static QString name[8];
0022     name[0] = i18nc("Northeast", "NE");
0023     name[1] = i18nc("East", "E");
0024     name[2] = i18nc("Southeast", "SE");
0025     name[3] = i18nc("South", "S");
0026     name[4] = i18nc("Southwest", "SW");
0027     name[5] = i18nc("West", "W");
0028     name[6] = i18nc("Northwest", "NW");
0029     name[7] = i18nc("North", "N");
0030 
0031     for (int i = 0; i < 8; i++)
0032     {
0033         SkyPoint *c = new SkyPoint;
0034 
0035         az += 45.0;
0036         c->setAz(az);
0037         c->setAlt(0.0);
0038         LabelNode *compass = rootNode->labelsItem()->addLabel(name[i], labelType());
0039 
0040         m_compassLabels.insert(c, compass);
0041     }
0042 }
0043 
0044 void HorizonItem::update()
0045 {
0046     if (!childCount())
0047     {
0048         appendChildNode(new HorizonNode());
0049     }
0050 
0051     //HorizonNode *hNode = static_cast<HorizonNode *>(n->skyNodeAtIndex(0));
0052     QSGNode *n     = firstChild();
0053     SkyNode *hNode = static_cast<SkyNode *>(n);
0054     if (m_horizonComp->selected())
0055     {
0056         QPointF cpoint;
0057         bool visible;
0058 
0059         const Projector *proj = SkyMapLite::Instance()->projector();
0060         KStarsData *data      = KStarsData::Instance();
0061 
0062         QMap<SkyPoint *, LabelNode *>::const_iterator i = m_compassLabels.cbegin();
0063 
0064         while (i != m_compassLabels.cend())
0065         {
0066             SkyPoint *c = i.key();
0067             if (!Options::useAltAz())
0068             {
0069                 c->HorizontalToEquatorial(data->lst(), data->geo()->lat());
0070             }
0071 
0072             LabelNode *compass = (*i);
0073             cpoint             = proj->toScreen(c, false, &visible);
0074             if (visible && proj->onScreen(cpoint))
0075             {
0076                 compass->setLabelPos(cpoint);
0077             }
0078             else
0079             {
0080                 compass->hide();
0081             }
0082             ++i;
0083         }
0084 
0085         hNode->update();
0086     }
0087     else
0088     {
0089         hNode->hide();
0090         rootNode()->labelsItem()->hideLabels(LabelsItem::label_t::HORIZON_LABEL);
0091     }
0092 }