File indexing completed on 2024-04-14 03:42:48

0001 /*
0002     SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "cometsitem.h"
0007 
0008 #include "Options.h"
0009 #include "projections/projector.h"
0010 #include "kscomet.h"
0011 
0012 #include "rootnode.h"
0013 #include "labelsitem.h"
0014 #include "skylabeler.h"
0015 
0016 #include "skynodes/pointsourcenode.h"
0017 
0018 CometsItem::CometsItem(const QList<SkyObject *> &cometsList, RootNode *rootNode)
0019     : SkyItem(LabelsItem::label_t::COMET_LABEL, rootNode), m_cometsList(cometsList)
0020 {
0021     recreateList();
0022 }
0023 
0024 void CometsItem::update()
0025 {
0026     if (Options::zoomFactor() < 10 * MINZOOM)
0027     {
0028         hide();
0029         return;
0030     }
0031 
0032     show();
0033 
0034     bool hideLabel = !Options::showCometNames() || (SkyMapLite::Instance()->isSlewing() && Options::hideLabels());
0035 
0036     if (hideLabel)
0037     {
0038         hideLabels();
0039     }
0040     double rsunLabelLimit = Options::maxRadCometName();
0041 
0042     /*//FIXME: Should these be config'able?
0043     skyp->setPen( QPen( QColor( "darkcyan" ) ) );
0044     skyp->setBrush( QBrush( QColor( "darkcyan" ) ) );*/
0045 
0046     //Traverse all children nodes
0047     QSGNode *n = firstChild();
0048     while (n != 0)
0049     {
0050         SkyNode *skyNode = static_cast<SkyNode *>(n);
0051         n                = n->nextSibling();
0052 
0053         //TODO: Might be better move it to PointSourceNode
0054         KSComet *com = static_cast<KSComet *>(skyNode->skyObject());
0055         double mag   = com->mag();
0056         if (std::isnan(mag) == 0)
0057         {
0058             bool drawLabel = false;
0059             if (!(hideLabel || com->rsun() >= rsunLabelLimit))
0060             {
0061                 drawLabel = true;
0062             }
0063             skyNode->update(drawLabel);
0064         }
0065         else
0066         {
0067             skyNode->hide();
0068         }
0069     }
0070 }
0071 
0072 void CometsItem::recreateList()
0073 {
0074     //Delete all child nodes
0075     while (QSGNode *n = firstChild())
0076     {
0077         removeChildNode(n);
0078         delete n;
0079     }
0080 
0081     foreach (SkyObject *comet, m_cometsList)
0082     {
0083         KSComet *com = static_cast<KSComet *>(comet);
0084         appendChildNode(new PointSourceNode(com, rootNode(), labelType()));
0085     }
0086 }