File indexing completed on 2024-07-14 07:17:24

0001 /*
0002     SPDX-FileCopyrightText: 2008 Akarsh Simha <akarshsimha@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include <QDebug>
0008 
0009 #include "starblock.h"
0010 #include "skyobjects/starobject.h"
0011 #include "starcomponent.h"
0012 #include "skyobjects/stardata.h"
0013 #include "skyobjects/deepstardata.h"
0014 
0015 #ifdef KSTARS_LITE
0016 #include "skymaplite.h"
0017 #include "kstarslite/skyitems/skynodes/pointsourcenode.h"
0018 
0019 StarNode::StarNode() : starNode(0)
0020 {
0021 }
0022 
0023 StarNode::~StarNode()
0024 {
0025     if (starNode)
0026     {
0027         SkyMapLite::Instance()->deleteSkyNode(starNode);
0028         qDebug() << Q_FUNC_INFO << "REAL NODE DESTRUCTOR";
0029     }
0030 }
0031 #endif
0032 
0033 StarBlock::StarBlock(int nstars)
0034     : faintMag(-5), brightMag(35), parent(nullptr), prev(nullptr), next(nullptr), drawID(0), nStars(0),
0035 #ifdef KSTARS_LITE
0036       stars(nstars, StarNode())
0037 #else
0038       stars(nstars, StarObject())
0039 #endif
0040 {
0041 }
0042 
0043 void StarBlock::reset()
0044 {
0045     if (parent)
0046         parent->releaseBlock(this);
0047 
0048     parent    = nullptr;
0049     faintMag  = -5.0;
0050     brightMag = 35.0;
0051     nStars    = 0;
0052 }
0053 
0054 #ifdef KSTARS_LITE
0055 StarNode *StarBlock::addStar(const StarData &data)
0056 {
0057     if (isFull())
0058         return 0;
0059     StarNode &node   = stars[nStars++];
0060     StarObject &star = node.star;
0061 
0062     star.init(&data);
0063     if (star.mag() > faintMag)
0064         faintMag = star.mag();
0065     if (star.mag() < brightMag)
0066         brightMag = star.mag();
0067     return &node;
0068 }
0069 
0070 StarNode *StarBlock::addStar(const DeepStarData &data)
0071 {
0072     if (isFull())
0073         return 0;
0074     StarNode &node   = stars[nStars++];
0075     StarObject &star = node.star;
0076 
0077     star.init(&data);
0078     if (star.mag() > faintMag)
0079         faintMag = star.mag();
0080     if (star.mag() < brightMag)
0081         brightMag = star.mag();
0082     return &node;
0083 }
0084 #else
0085 StarObject *StarBlock::addStar(const StarData &data)
0086 {
0087     if (isFull())
0088         return nullptr;
0089     StarObject &star = stars[nStars++];
0090 
0091     star.init(&data);
0092     if (star.mag() > faintMag)
0093         faintMag = star.mag();
0094     if (star.mag() < brightMag)
0095         brightMag = star.mag();
0096     return &star;
0097 }
0098 
0099 StarObject *StarBlock::addStar(const DeepStarData &data)
0100 {
0101     if (isFull())
0102         return nullptr;
0103     StarObject &star = stars[nStars++];
0104 
0105     star.init(&data);
0106     if (star.mag() > faintMag)
0107         faintMag = star.mag();
0108     if (star.mag() < brightMag)
0109         brightMag = star.mag();
0110     return &star;
0111 }
0112 #endif