1 /*
2     SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3     SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #include "asteroidsitem.h"
7 
8 #include "Options.h"
9 #include "projections/projector.h"
10 #include "ksasteroid.h"
11 
12 #include "skynodes/planetnode.h"
13 #include "skynodes/pointsourcenode.h"
14 #include "kstarslite/skyitems/rootnode.h"
15 
16 #include "labelsitem.h"
17 
AsteroidsItem(const QList<SkyObject * > & asteroidsList,RootNode * rootNode)18 AsteroidsItem::AsteroidsItem(const QList<SkyObject *> &asteroidsList, RootNode *rootNode)
19     : SkyItem(LabelsItem::label_t::ASTEROID_LABEL, rootNode), m_asteroidsList(asteroidsList)
20 {
21     recreateList();
22 }
23 
recreateList()24 void AsteroidsItem::recreateList()
25 {
26     //Delete all child nodes
27     while (QSGNode *n = firstChild())
28     {
29         removeChildNode(n);
30         delete n;
31     }
32 
33     foreach (SkyObject *asteroid, m_asteroidsList)
34     {
35         KSAsteroid *ast = static_cast<KSAsteroid *>(asteroid);
36         if (ast->image().isNull() == false)
37         {
38             appendChildNode(new PlanetNode(ast, rootNode(), labelType()));
39         }
40         else
41         {
42             appendChildNode(new PointSourceNode(ast, rootNode(), labelType()));
43         }
44     }
45 }
46 
update()47 void AsteroidsItem::update()
48 {
49     QSGNode *n = firstChild();
50     while (n != 0)
51     {
52         SkyNode *pNode = static_cast<SkyNode *>(n);
53         n              = n->nextSibling();
54 
55         bool hideLabels =
56             !Options::showAsteroidNames() || (SkyMapLite::Instance()->isSlewing() && Options::hideLabels());
57 
58         double lgmin         = log10(MINZOOM);
59         double lgmax         = log10(MAXZOOM);
60         double lgz           = log10(Options::zoomFactor());
61         double labelMagLimit = 2.5 + Options::asteroidLabelDensity() / 5.0;
62         labelMagLimit += (15.0 - labelMagLimit) * (lgz - lgmin) / (lgmax - lgmin);
63         if (labelMagLimit > 10.0)
64             labelMagLimit = 10.0;
65         //printf("labelMagLim = %.1f\n", labelMagLimit );
66 
67         KSAsteroid *ast = static_cast<KSAsteroid *>(pNode->skyObject());
68 
69         bool drawLabel = false;
70 
71         if (ast->mag() > Options::magLimitAsteroid() || std::isnan(ast->mag()) != 0)
72         {
73             pNode->hide();
74             continue;
75         }
76         if (!(hideLabels || ast->mag() >= labelMagLimit))
77         {
78             drawLabel = true;
79         }
80         pNode->update(drawLabel);
81     }
82 }
83