File indexing completed on 2024-09-01 10:10:53
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #pragma once 0007 0008 #include "skymaplite.h" 0009 0010 #include <QSGTransformNode> 0011 0012 class Projector; 0013 class SkyOpacityNode; 0014 0015 /** 0016 * @class SkyNode 0017 * @short Provides virtual functions for update of coordinates and nodes hiding 0018 * 0019 * A QSGTransformNode derived class that has to be subclassed by node containers like PlanetNode and 0020 * PointSourceNode. SkyObject * that is passed as parameter to constructor is used in subclasses 0021 * to calculate new coordinates in update(). Subclasses have to implement hide() so that each of 0022 * their child nodes can be hidden. 0023 * 0024 * @author Artem Fedoskin 0025 * @version 1.0 0026 */ 0027 class SkyNode : public QSGTransformNode 0028 { 0029 public: 0030 /** 0031 * @brief Constructor 0032 * @param skyObject that is represented on the SkyMapLIte 0033 */ 0034 explicit SkyNode(SkyObject *skyObject); 0035 SkyNode(); 0036 0037 virtual ~SkyNode() {} 0038 0039 inline const Projector *projector() { return SkyMapLite::Instance()->projector(); } 0040 0041 /** 0042 * @short short function to access SkyMapLite 0043 * @return pointer to instance of SkyMapLite class 0044 */ 0045 inline SkyMapLite *map() const { return SkyMapLite::Instance(); } 0046 0047 /** Updates coordinate of the object on SkyMapLite */ 0048 virtual void update() {} 0049 0050 /** 0051 * @short sets m_drawLabel to true if it is needed to be drawn and calls update() 0052 * @param drawLabel true of label has to be drawn 0053 */ 0054 void update(bool drawLabel); 0055 0056 void addChildNode(QSGNode *node); 0057 0058 /** 0059 * @short hides all child nodes (sets opacity of m_opacity to 0) 0060 */ 0061 virtual void hide(); 0062 0063 /** 0064 * @short shows all child nodes (sets opacity of m_opacity to 1) 0065 */ 0066 virtual void show(); 0067 0068 inline int hideCount() { return m_hideCount; } 0069 0070 /** 0071 * @short changes the position of SkyNode on SkyMapLite. Has to be overridden by the classes 0072 * that support moving 0073 * @param pos new position 0074 */ 0075 virtual void changePos(QPointF pos) { Q_UNUSED(pos); } 0076 0077 /** 0078 * @return true if object is visible (m_opacity->opacity() != 0) else returns false 0079 */ 0080 bool visible(); 0081 0082 /** 0083 * @short returns SkyObject associated with this SkyNode 0084 * @return pointer to the object of type SkyObject 0085 */ 0086 SkyObject *skyObject() const { return m_skyObject; } 0087 0088 SkyOpacityNode *m_opacity { nullptr }; 0089 0090 protected: 0091 SkyObject *m_skyObject { nullptr }; 0092 bool m_drawLabel { false }; 0093 int m_hideCount { 0 }; 0094 };