Kstars

planetmoonsnode.cpp
1#include <QSGSimpleTextureNode>
2
3#include "planetnode.h"
4#include "pointsourcenode.h"
5#include "planetmoonsnode.h"
6#include "planetmoons.h"
7#include "ksplanetbase.h"
8#include "skylabeler.h"
9
10#include "../rootnode.h"
11#include "../labelsitem.h"
12
13#include "Options.h"
14
16 : SkyNode(planet), m_rootNode(parentNode), pmoons(0), m_planetNode(new PlanetNode(planet, parentNode)),
17 m_labelType(LabelsItem::label_t::NO_LABEL)
18//For now we consider labels only in case of Jupiter
19{
20 appendChildNode(m_planetNode);
21}
22
23PlanetMoonsNode::~PlanetMoonsNode()
24{
25 if (m_labelType != LabelsItem::label_t::NO_LABEL)
26 {
27 m_rootNode->labelsItem()->deleteLabels(m_labelType);
28 }
29}
30
32{
34 m_planetNode->update();
35}
36
38{
39 m_planetNode->hide();
40
41 foreach (PointSourceNode *moon, m_moonNodes)
42 {
43 moon->hide();
44 }
45}
46
47//TODO updateMoons and destructor
49{
50 //In order to get the z-order right for the moons and the planet,
51 //we need to first append the planet (both m_point and m_planetPic) then append all nodes for moons
52 //that are nearer than the planet and then prepend nodes for moons that are further than the planet
53 if (pmoons)
54 {
55 int nmoons = pmoons->nMoons();
56 if (m_labelType == LabelsItem::label_t::NO_LABEL)
57 {
58 m_labelType = LabelsItem::label_t::JUPITER_MOON_LABEL;
59 }
60
61 if (!m_moonNodes.length()) //Initialize PointSourceNodes used for drawing moons
62 {
63 for (int i = 0; i < nmoons; ++i)
64 {
65 m_moonNodes.append(new PointSourceNode(pmoons->moon(i), m_rootNode, m_labelType));
66 }
67 }
68
69 removeAllChildNodes(); // Clear all child nodes so that we can render moons according to z-order
70
71 // We need to reappend node that draws the planet
72 appendChildNode(m_planetNode);
73
74 bool drawLabel = true;
75
76 if (!(Options::showPlanetNames() && Options::zoomFactor() > 50. * MINZOOM))
77 {
78 drawLabel = false;
79 }
80
81 for (int i = 0; i < nmoons; ++i)
82 {
83 if (pmoons->z(i) < 0.0) //Moon is nearer than the planet
84 {
85 appendChildNode(m_moonNodes[i]);
86 m_moonNodes[i]->SkyNode::update(drawLabel);
87 }
88 else
89 {
90 //Draw Moons that are further than the planet
91 //skyp->drawPointSource( pmoons->moon(i), pmoons->moon(i)->mag() );
92 prependChildNode(m_moonNodes[i]);
93 m_moonNodes[i]->SkyNode::update(drawLabel);
94 }
95 }
96
97 /* //Draw Moon name labels if at high zoom
98 return;
99 for ( int i=0; i<nmoons; ++i ) {
100
101 if (planet ==KSPlanetBase::SATURN)
102 SkyLabeler::AddLabel( pmoons->moon(i), SkyLabeler::SATURN_MOON_LABEL );
103 else
104
105 SkyLabeler::AddLabel( pmoons->moon(i), SkyLabeler::JUPITER_MOON_LABEL );
106 }*/
107 }
108}
A subclass of TrailObject that provides additional information needed for most solar system objects.
This class is in charge of labels in SkyMapLite.
Definition labelsitem.h:53
void deleteLabels(label_t labelType)
deletes all labels of type labelType
void updateMoons()
Update position of moons if planet has them.
PlanetMoonsNode(KSPlanetBase *planet, RootNode *parentNode)
Constructor.
virtual void hide() override
Hides both planet and its moons.
virtual void update() override
If planet has any moons first updateMoons() is called then the planet is updated.
int nMoons() const
TrailObject * moon(int id)
Definition planetmoons.h:45
double z(int i) const
A SkyNode derived class used as a container for holding two other nodes: PointNode and QSGSimpleTextu...
Definition planetnode.h:30
virtual void update() override
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
A SkyNode derived class used for displaying PointNode with coordinates provided by SkyObject.
virtual void hide() override
hides this node and its label.
A QSGClipNode derived class used as a container for holding pointers to nodes and for clipping.
Definition rootnode.h:60
Provides virtual functions for update of coordinates and nodes hiding.
Definition skynode.h:28
void append(QList< T > &&value)
qsizetype length() const const
void appendChildNode(QSGNode *node)
void prependChildNode(QSGNode *node)
void removeAllChildNodes()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.