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 
23 PlanetMoonsNode::~PlanetMoonsNode()
24 {
25  if (m_labelType != LabelsItem::label_t::NO_LABEL)
26  {
27  m_rootNode->labelsItem()->deleteLabels(m_labelType);
28  }
29 }
30 
32 {
33  updateMoons();
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 }
void append(const T &value)
A container for nodes that holds collection of textures for stars and provides clipping.
Definition: rootnode.h:59
void updateMoons()
Update position of moons if planet has them.
int length() const const
void deleteLabels(label_t labelType)
deletes all labels of type labelType
Definition: labelsitem.cpp:214
void appendChildNode(QSGNode *node)
void removeAllChildNodes()
Handles labels in SkyMapLite.
Definition: labelsitem.h:52
virtual void update() override
If planet has any moons first updateMoons() is called then the planet is updated.
A container for PointNode and QSGSimpleTextureNode used for displaying some solar system objects.
Definition: planetnode.h:29
TrailObject * moon(int id)
Definition: planetmoons.h:45
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
Definition: planetnode.cpp:138
A SkyNode derived class that represents stars and objects that are drawn as stars.
virtual void hide() override
Hides both planet and its moons.
double z(int i) const
Definition: planetmoons.h:104
PlanetMoonsNode(KSPlanetBase *planet, RootNode *parentNode)
Constructor.
int nMoons() const
Definition: planetmoons.h:107
Provides virtual functions for update of coordinates and nodes hiding.
Definition: skynode.h:27
virtual void hide() override
hides this node and its label.
void prependChildNode(QSGNode *node)
virtual void update() override
Definition: planetnode.cpp:51
Provides necessary information about objects in the solar system.
Definition: ksplanetbase.h:49
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:00:02 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.