File indexing completed on 2024-04-14 03:43:04

0001 /*
0002     SPDX-FileCopyrightText: 2008 Akarsh Simha Thomas Kabelmann <akarshsimha@gmail.com, thomas.kabelmann@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 /**
0010  * @class DeepStarComponent
0011  * Stores and manages unnamed stars, most of which are dynamically loaded into memory.
0012  *
0013  * @author Akarsh Simha
0014  * @note Much of the code here is copied from class StarComponent authored by Thomas Kabelmann
0015  * @version 0.1
0016  */
0017 
0018 #include "binfilehelper.h"
0019 #include "ksnumbers.h"
0020 #include "listcomponent.h"
0021 #include "starblockfactory.h"
0022 #include "skyobjects/deepstardata.h"
0023 #include "skyobjects/stardata.h"
0024 
0025 class SkyLabeler;
0026 class SkyMesh;
0027 class StarBlockFactory;
0028 class StarBlockList;
0029 class StarObject;
0030 
0031 class DeepStarComponent : public ListComponent
0032 {
0033 #ifdef KSTARS_LITE
0034     friend class DeepStarItem; //Needs access to staticStars and buch of other facilities
0035 #endif
0036 
0037   public:
0038     DeepStarComponent(SkyComposite *parent, QString fileName, float trigMag, bool staticstars = false);
0039 
0040     ~DeepStarComponent() override;
0041 
0042     //This function is empty; we need that so that the JiT update
0043     //is the only one being used.
0044     void update(KSNumbers *num) override;
0045 
0046     bool selected() override;
0047 
0048     void draw(SkyPainter *skyp) override;
0049 
0050     bool loadStaticStars();
0051 
0052     bool openDataFile();
0053 
0054     /**
0055      * @return true if this DeepStarComponent has static stars (that are not dynamically loaded)
0056      */
0057     inline bool hasStaticStars() const { return staticStars; }
0058 
0059     /**
0060      * @return return the estimated faint magnitude limit of this DeepStarComponent
0061      */
0062     float faintMagnitude() const { return m_FaintMagnitude; }
0063 
0064     /**
0065      * @param HDnum Henry-Draper catalog number of the desired star
0066      * @return A star matching the given Henry-Draper catalog number
0067      */
0068     StarObject *findByHDIndex(int HDnum);
0069 
0070     /**
0071      * @return Nearest star within maxrad of SkyPoint p, or nullptr if not found
0072      */
0073     SkyObject *objectNearest(SkyPoint *p, double &maxrad) override;
0074 
0075     inline bool fileOpen() const { return fileOpened; }
0076 
0077     inline BinFileHelper *getStarReader() { return &starReader; }
0078 
0079     bool verifySBLIntegrity();
0080 
0081     /**
0082      * @short Add to the given list, the stars from this component,
0083      * that lie within the specified circular aperture, and that are
0084      * brighter than the limiting magnitude specified.
0085      * @p center The center point of the aperture
0086      * @p radius The radius around the center point that defines the
0087      * aperture
0088      * @p maglim Optional parameter indicating the limiting magnitude.
0089      * If magnitude limit is numerically < -28, the limiting magnitude
0090      * is assumed to be the limiting magnitude of the catalog (i.e. no
0091      * magnitude limit)
0092      * @p list The list to operate on
0093      * @return false if the limiting magnitude is brighter than the
0094      * trigger magnitude of the DeepStarComponent
0095      */
0096     bool starsInAperture(QList<StarObject *> &list, const SkyPoint &center, float radius, float maglim = -29);
0097 
0098     // TODO: Find the right place for this method
0099     static void byteSwap(DeepStarData *stardata);
0100     static void byteSwap(StarData *stardata);
0101 
0102     static StarBlockFactory m_StarBlockFactory;
0103 
0104   private:
0105     SkyMesh *m_skyMesh { nullptr };
0106     KSNumbers m_reindexNum;
0107 
0108     float m_zoomMagLimit { 0 };
0109     /// Magnitude at which this catalog triggers
0110     float triggerMag { 0 };
0111     /// Limiting magnitude of the catalog currently loaded
0112     float m_FaintMagnitude { 0 };
0113     /// Indicates whether the file is opened or not
0114     bool fileOpened { false };
0115     unsigned long visibleStarCount { 0 };
0116     /// Maximum number of stars in any given trixel
0117     quint16 MSpT { 0 };
0118 
0119     // Time keeping variables
0120     long unsigned t_dynamicLoad { 0 };
0121     long unsigned t_drawUnnamed { 0 };
0122     long unsigned t_updateCache { 0 };
0123 
0124     QVector<std::shared_ptr<StarBlockList>> m_starBlockList;
0125     QHash<int, StarObject *> m_CatalogNumber;
0126 
0127     bool staticStars { false };
0128 
0129     // Stuff required for reading data
0130     DeepStarData deepstardata;
0131     StarData stardata;
0132     BinFileHelper starReader;
0133     QString dataFileName;
0134 };