File indexing completed on 2024-03-24 15:17: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 "skyitem.h"
0009 #include "skyopacitynode.h"
0010 #include "deepskycomponent.h"
0011 #include "skynodes/trixelnode.h"
0012 
0013 class DeepSkyComponent;
0014 class SkyMesh;
0015 class StarBlockFactory;
0016 class MeshIterator;
0017 
0018 /**
0019  * @short This class represents DSOs from particular catalog. To create a node, first create a DSOTrixelNode,
0020  * (if a node of this trixelID is not a child of m_trixels yet), append it to m_trixels and then append
0021  * DeepSkyNode to DSOTrixelNode
0022  */
0023 class DSOIndexNode : public SkyOpacityNode
0024 {
0025   public:
0026     DSOIndexNode(DeepSkyIndex *index, LabelsItem::label_t labelType, QString colorString);
0027 
0028     /** @short hides the catalog nodes and their labels */
0029     virtual void hide();
0030 
0031     /** @short shows the catalog nodes and their labels */
0032     virtual void show();
0033 
0034     DeepSkyIndex *m_index { nullptr };
0035     QSGNode *m_trixels { nullptr };
0036     /** @short m_labelType holds label type of this catalog */
0037     LabelsItem::label_t m_labelType;
0038     /** @short schemeColor holds the color, with which nodes of this catalog should be drawn */
0039     QString schemeColor;
0040 };
0041 
0042 /**
0043  * @short The DSOTrixelNode class represents trixel. Symbols should be appended to m_symbols, labels to
0044  * m_labels and DeepSkyNodes directly to DSOTrixelNode
0045  */
0046 class DSOTrixelNode : public TrixelNode
0047 {
0048   public:
0049     explicit DSOTrixelNode(Trixel trixelID);
0050 
0051     virtual void deleteAllChildNodes();
0052 
0053     TrixelNode *m_labels { nullptr };
0054     QSGNode *m_symbols { nullptr };
0055 };
0056 
0057 /**
0058  * @class DeepSkyItem
0059  *
0060  * @short Class that handles representation of Deep Sky Objects.
0061  *
0062  * @author Artem Fedoskin
0063  * @version 1.0
0064  */
0065 class DeepSkyItem : public SkyItem
0066 {
0067   public:
0068     /**
0069      * @short Constructor. Instantiates DSOIndexNodes for catalogs
0070      * @param dsoComp pointer to DeepSkyComponent that handles data
0071      * @param rootNode parent RootNode that instantiated this object
0072      */
0073     DeepSkyItem(DeepSkyComponent *dsoComp, RootNode *rootNode);
0074 
0075     /** @short Call update on all DSOIndexNodes (catalogs) */
0076     virtual void update();
0077 
0078     /**
0079      * @short update all nodes needed to represent DSO in the given DSOIndexNode
0080      * In this function we perform some tricks to reduce memory consumption:
0081      * 1. Each TrixelNode has hideCount() function that returns the number of updates, during which this TrixelNode
0082      * was hidden. Whenever TrixelNode becomes visible this counter is set to 0 and is not being incremented.
0083      * 2. Based on the zoom level we calculate the limit for hideCount. If hideCount() of particular TrixelNode is
0084      * larger than the limit, we delete all nodes of this TrixelNode.
0085      * 3. If DSOTrixelNode is visible, we iterate over its DeepSkyObjects and DeepSkyNodes. If hideCount of DeepSkyNode
0086      * is larger than the limit we delete it. If DeepSkyObject is visible but no DeepSkyNode to represent this object
0087      * is created, we instantiate a new one.
0088      * @param node - DSOIndexNode(catalog) that should be updated
0089      * @param drawObject - true if objects from this catalog should be drawn, false otherwise
0090      * @param region - MeshIterator that should be used to iterate over visible trixels
0091      * @param drawImage - true if images for objects should be drawn, false otherwise
0092      */
0093     void updateDeepSkyNode(DSOIndexNode *node, bool drawObject, MeshIterator *region, bool drawImage = false);
0094 
0095   private:
0096     DeepSkyComponent *m_dsoComp { nullptr };
0097     SkyMesh *m_skyMesh { nullptr };
0098 
0099     DSOIndexNode *m_Messier { nullptr };
0100     DSOIndexNode *m_NGC { nullptr };
0101     DSOIndexNode *m_IC { nullptr };
0102     DSOIndexNode *m_other { nullptr };
0103 };