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 "asteroidsitem.h"
0007 
0008 #include "Options.h"
0009 #include "projections/projector.h"
0010 #include "ksasteroid.h"
0011 
0012 #include "skynodes/planetnode.h"
0013 #include "skynodes/pointsourcenode.h"
0014 #include "kstarslite/skyitems/rootnode.h"
0015 
0016 #include "labelsitem.h"
0017 
0018 AsteroidsItem::AsteroidsItem(const QList<SkyObject *> &asteroidsList, RootNode *rootNode)
0019     : SkyItem(LabelsItem::label_t::ASTEROID_LABEL, rootNode), m_asteroidsList(asteroidsList)
0020 {
0021     recreateList();
0022 }
0023 
0024 void AsteroidsItem::recreateList()
0025 {
0026     //Delete all child nodes
0027     while (QSGNode *n = firstChild())
0028     {
0029         removeChildNode(n);
0030         delete n;
0031     }
0032 
0033     foreach (SkyObject *asteroid, m_asteroidsList)
0034     {
0035         KSAsteroid *ast = static_cast<KSAsteroid *>(asteroid);
0036         if (ast->image().isNull() == false)
0037         {
0038             appendChildNode(new PlanetNode(ast, rootNode(), labelType()));
0039         }
0040         else
0041         {
0042             appendChildNode(new PointSourceNode(ast, rootNode(), labelType()));
0043         }
0044     }
0045 }
0046 
0047 void AsteroidsItem::update()
0048 {
0049     QSGNode *n = firstChild();
0050     while (n != 0)
0051     {
0052         SkyNode *pNode = static_cast<SkyNode *>(n);
0053         n              = n->nextSibling();
0054 
0055         bool hideLabels =
0056             !Options::showAsteroidNames() || (SkyMapLite::Instance()->isSlewing() && Options::hideLabels());
0057 
0058         double lgmin         = log10(MINZOOM);
0059         double lgmax         = log10(MAXZOOM);
0060         double lgz           = log10(Options::zoomFactor());
0061         double labelMagLimit = 2.5 + Options::asteroidLabelDensity() / 5.0;
0062         labelMagLimit += (15.0 - labelMagLimit) * (lgz - lgmin) / (lgmax - lgmin);
0063         if (labelMagLimit > 10.0)
0064             labelMagLimit = 10.0;
0065         //printf("labelMagLim = %.1f\n", labelMagLimit );
0066 
0067         KSAsteroid *ast = static_cast<KSAsteroid *>(pNode->skyObject());
0068 
0069         bool drawLabel = false;
0070 
0071         if (ast->mag() > Options::magLimitAsteroid() || std::isnan(ast->mag()) != 0)
0072         {
0073             pNode->hide();
0074             continue;
0075         }
0076         if (!(hideLabels || ast->mag() >= labelMagLimit))
0077         {
0078             drawLabel = true;
0079         }
0080         pNode->update(drawLabel);
0081     }
0082 }