Kstars

asteroidsitem.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
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 
19  : SkyItem(LabelsItem::label_t::ASTEROID_LABEL, rootNode), m_asteroidsList(asteroidsList)
20 {
21  recreateList();
22 }
23 
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  {
39  }
40  else
41  {
43  }
44  }
45 }
46 
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 }
A base class that is used for displaying SkyComponents on SkyMapLite.
Definition: skyitem.h:29
bool isSlewing() const
Definition: skymaplite.cpp:804
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
LabelsItem::label_t labelType()
Definition: skyitem.h:60
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
A subclass of KSPlanetBase that implements asteroids.
Definition: ksasteroid.h:41
virtual void update()
Updates coordinate of the object on SkyMapLite.
Definition: skynode.h:48
float mag() const
Definition: skyobject.h:206
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
A container for PointNode and QSGSimpleTextureNode used for displaying some solar system objects.
Definition: planetnode.h:29
const QImage & image() const
Definition: ksplanetbase.h:127
bool isNull() const const
A SkyNode derived class that represents stars and objects that are drawn as stars.
AsteroidsItem(const QList< SkyObject * > &asteroidsList, RootNode *rootNode=nullptr)
Constructor.
virtual void update() override
Determines the visibility of the object and its label and hides/updates them accordingly.
SkyObject * skyObject() const
returns SkyObject associated with this SkyNode
Definition: skynode.h:86
RootNode * rootNode()
Definition: skyitem.h:57
Provides virtual functions for update of coordinates and nodes hiding.
Definition: skynode.h:27
QSGNode * nextSibling() const const
void recreateList()
recreates the node tree (deletes old nodes and appends new ones based on SkyObjects in m_asteroidsLis...
Information about an object in the sky.
Definition: skyobject.h:41
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition: skynode.cpp:21
void removeChildNode(QSGNode *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Aug 13 2022 04:01:50 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.