File indexing completed on 2024-04-28 03:44:26

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 "skynode.h"
0009 #include "../labelsitem.h"
0010 
0011 class LabelNode;
0012 class PlanetItemNode;
0013 class PointNode;
0014 class RootNode;
0015 class SkyMapLite;
0016 
0017 /**
0018  * @class PointSourceNode
0019  *
0020  * A SkyNode derived class used for displaying PointNode with coordinates provided by SkyObject.
0021  *
0022  * @short A SkyNode derived class that represents stars and objects that are drawn as stars
0023  * @author Artem Fedoskin
0024  * @version 1.0
0025  */
0026 class PointSourceNode : public SkyNode
0027 {
0028   public:
0029     /**
0030      * @short Constructor
0031      * @param skyObject pointer to SkyObject that has to be displayed on SkyMapLite
0032      * @param parentNode pointer to the top parent node, which holds texture cache
0033      * @param labelType label type of PointNode
0034      * @param spType spectral class of PointNode
0035      * @param size initial size of PointNode
0036      * @param trixel trixelID, with which this node is indexed
0037      */
0038     PointSourceNode(SkyObject *skyObject, RootNode *parentNode,
0039                     LabelsItem::label_t labelType = LabelsItem::label_t::STAR_LABEL,
0040                     char spType = 'A', float size = 1, short trixel = -1);
0041     virtual ~PointSourceNode();
0042 
0043     /** @short Get the width of a star of magnitude mag */
0044     float starWidth(float mag) const;
0045 
0046     /**
0047      * @short updatePoint initializes PointNode if not done that yet. Makes it visible and updates
0048      * its size.
0049      * By using this function we can save some memory because m_point is created only when this
0050      * PointSourceNode becomes visible.
0051      */
0052     void updatePoint();
0053 
0054     /**
0055      * @short changePos changes the position m_point
0056      * @param pos new position
0057      */
0058     virtual void changePos(QPointF pos) override;
0059 
0060     /**
0061      * @short updatePos updates position of this node and its label. Initializes label if needed
0062      * The reason behind this function is that in StarItem we are already checking the visibility of star
0063      * to decide whether we need to create this node or no. So to avoid calculating the same thing twice
0064      * we set position of object directly. Also through this function StarItem sets the visibility of label
0065      * @param pos position of this node on SkyMapLite
0066      * @param drawLabel true if label has to be drawn
0067      */
0068     void updatePos(QPointF pos, bool drawLabel);
0069 
0070     /** @short update updates coordinates of this node based on the visibility of its SkyObject */
0071     virtual void update() override;
0072 
0073     /**
0074      * @short hides this node and its label. m_point is hided without explicitly doing this because
0075      * it is a child node of m_opacity inherited from SkyNode
0076      */
0077     virtual void hide() override;
0078 
0079   private:
0080     PointNode *m_point { nullptr };
0081     RootNode *m_rootNode { nullptr };
0082     LabelNode *m_label { nullptr };
0083     char m_spType { 0 };
0084     float m_size { 0 };
0085     LabelsItem::label_t m_labelType { LabelsItem::NO_LABEL };
0086     /**
0087      * Trixel to which this object belongs. Used only in stars. By default -1 for
0088      * all other objects that are not indexed by SkyMesh
0089      */
0090     short m_trixel { 0 };
0091     QPointF pos;
0092 };