1 /*
2     SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3     SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 #ifndef PLANETMOONSNODE_H_
6 #define PLANETMOONSNODE_H_
7 #include "skynode.h"
8 #include "../labelsitem.h"
9 
10 class PlanetNode;
11 class PlanetMoons;
12 class RootNode;
13 class PointSourceNode;
14 class KSPlanetBase;
15 class QSGSimpleTextureNode;
16 
17 /** @class PlanetMoonsNode
18  *
19  * A SkyNode derived class used as a container for displaying a planet with its moons (if any). Unlike
20  * PlanetMoons derived from SkyComponent PlanetMoonsNode represents both planet and moons. Ths PlanetNode
21  * shouldn't be instantiated outside of this class (exception is AsteroidsItem). Although all SkyNodes
22  * are "movable" objects (they change transform matrix to move across the SkyMapLite) this class is
23  * just a container that provides z-order for moons and planets that change their positions on their own.
24  *
25  *@short A container for planets and moons that provides z-order.
26  *@author Artem Fedoskin
27  *@version 1.0
28  */
29 
30 class PlanetMoonsNode : public SkyNode
31 {
32   public:
33     /**
34          * @short Constructor
35          * @param planet pointer to planet object
36          * @param parentNode pointer to the RootNode. It is needed for PointSourceNodes that use textures,
37          * which are cached in RootNode.
38          */
39     PlanetMoonsNode(KSPlanetBase *planet, RootNode *parentNode);
40     ~PlanetMoonsNode();
41 
42     /**
43          * @short Add object of type PlanetMoons to this node
44          * @param planetMoons PlanetMoons component
45          */
addMoons(PlanetMoons * planetMoons)46     inline void addMoons(PlanetMoons *planetMoons) { pmoons = planetMoons; }
47 
48     /**
49          * If planet has any moons first updateMoons() is called then the planet is updated
50          */
51     virtual void update() override;
52 
53     /**
54          * @short Hides both planet and its moons
55          */
56     virtual void hide() override;
57 
58     /**
59          * Update position of moons if planet has them. To allow z-ordering we need to change the structure
60          * of node tree by removing all child nodes of this tree and adding them again so that moons that
61          * are behind the planet are before the m_planetNode in the hierarchy and all others are appended
62          * after m_planetNode.
63          */
64     void updateMoons();
65 
66   private:
67     RootNode *m_rootNode;
68     PlanetMoons *pmoons;
69     PlanetNode *m_planetNode;
70 
71     LabelsItem::label_t m_labelType;
72 
73     QList<PointSourceNode *> m_moonNodes;
74 };
75 
76 #endif
77