Kstars

asteroidsitem.cpp
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
19 : SkyItem(LabelsItem::label_t::ASTEROID_LABEL, rootNode), m_asteroidsList(asteroidsList)
20{
22}
23
25{
26 //Delete all child nodes
27 while (QSGNode *n = firstChild())
28 {
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}
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.
void recreateList()
recreates the node tree (deletes old nodes and appends new ones based on SkyObjects in m_asteroidsLis...
A subclass of KSPlanetBase that implements asteroids.
Definition ksasteroid.h:42
const QImage & image() const
This class is in charge of labels in SkyMapLite.
Definition labelsitem.h:53
A SkyNode derived class used as a container for holding two other nodes: PointNode and QSGSimpleTextu...
Definition planetnode.h:30
A SkyNode derived class used for displaying PointNode with coordinates provided by SkyObject.
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
This is an interface for implementing SkyItems that represent SkyComponent derived objects on the Sky...
Definition skyitem.h:30
RootNode * rootNode()
Definition skyitem.h:57
LabelsItem::label_t labelType()
Definition skyitem.h:60
bool isSlewing() const
Provides virtual functions for update of coordinates and nodes hiding.
Definition skynode.h:28
SkyObject * skyObject() const
returns SkyObject associated with this SkyNode
Definition skynode.h:86
virtual void hide()
hides all child nodes (sets opacity of m_opacity to 0)
Definition skynode.cpp:21
virtual void update()
Updates coordinate of the object on SkyMapLite.
Definition skynode.h:48
Provides all necessary information about an object in the sky: its coordinates, name(s),...
Definition skyobject.h:42
float mag() const
Definition skyobject.h:207
bool isNull() const const
void appendChildNode(QSGNode *node)
QSGNode * firstChild() const const
QSGNode * nextSibling() const const
void removeChildNode(QSGNode *node)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.