File indexing completed on 2024-07-21 09:22:25

0001 /*
0002     SPDX-FileCopyrightText: 2001 Thomas Kabelmann <tk78@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 //#define PROFILE_UPDATECOORDS
0010 
0011 #include "skyobject.h"
0012 
0013 #include <QString>
0014 
0015 struct DeepStarData;
0016 class KSNumbers;
0017 class KSPopupMenu;
0018 struct StarData;
0019 
0020 /**
0021  * @class StarObject
0022  *
0023  * This is a subclass of SkyObject.  It adds the Spectral type, and flags
0024  * for variability and multiplicity.
0025  * For stars, the primary name (n) is the latin name (e.g., "Betelgeuse").  The
0026  * secondary name (n2) is the genetive name (e.g., "alpha Orionis").
0027  * @short subclass of SkyObject specialized for stars.
0028  *
0029  * @author Thomas Kabelmann
0030  * @version 1.0
0031  */
0032 class StarObject : public SkyObject
0033 {
0034   public:
0035     /**
0036      * @short returns the reindex interval (in centuries!) for the given
0037      * magnitude of proper motion (in milliarcsec/year).  ASSUMING a
0038      * 25 arc-minute margin for proper motion.
0039      */
0040     static double reindexInterval(double pm);
0041 
0042     /**
0043      * Constructor.  Sets sky coordinates, magnitude, latin name, genetive name, and spectral type.
0044      *
0045      * @param r Right Ascension
0046      * @param d Declination
0047      * @param m magnitude
0048      * @param n common name
0049      * @param n2 genetive name
0050      * @param sptype Spectral Type
0051      * @param pmra Proper motion in RA direction [mas/yr]
0052      * @param pmdec Proper motion in Dec direction [mas/yr]
0053      * @param par Parallax angle [mas]
0054      * @param mult Multiplicity flag (false=dingle star; true=multiple star)
0055      * @param var Variability flag (true if star is a known periodic variable)
0056      * @param hd Henry Draper Number
0057      */
0058     explicit StarObject(dms r = dms(0.0), dms d = dms(0.0), float m = 0.0, const QString &n = QString(),
0059                         const QString &n2 = QString(), const QString &sptype = "--", double pmra = 0.0,
0060                         double pmdec = 0.0, double par = 0.0, bool mult = false, bool var = false, int hd = 0);
0061     /**
0062      * Constructor.  Sets sky coordinates, magnitude, latin name, genetive name, and
0063      * spectral type.  Differs from above function only in data type of RA and Dec.
0064      *
0065      * @param r Right Ascension
0066      * @param d Declination
0067      * @param m magnitude
0068      * @param n common name
0069      * @param n2 genetive name
0070      * @param sptype Spectral Type
0071      * @param pmra Proper motion in RA direction [mas/yr]
0072      * @param pmdec Proper motion in Dec direction [mas/yr]
0073      * @param par Parallax angle [mas]
0074      * @param mult Multiplicity flag (false=dingle star; true=multiple star)
0075      * @param var Variability flag (true if star is a known periodic variable)
0076      * @param hd Henry Draper Number
0077      */
0078     StarObject(double r, double d, float m = 0.0, const QString &n = QString(), const QString &n2 = QString(),
0079                const QString &sptype = "--", double pmra = 0.0, double pmdec = 0.0, double par = 0.0, bool mult = false,
0080                bool var = false, int hd = 0);
0081 
0082     StarObject *clone() const override;
0083     UID getUID() const override;
0084 
0085     /** Copy constructor */
0086     StarObject(const StarObject &o);
0087 
0088     /** Destructor. (Empty) */
0089     ~StarObject() override = default;
0090 
0091     /**
0092      * @short  Initializes a StarObject to given data
0093      *
0094      * This is almost like the StarObject constructor itself, but it avoids
0095      * setting up name, gname etc for unnamed stars. If called instead of the
0096      * constructor, this method will be much faster for unnamed stars
0097      *
0098      * @param  stardata  Pointer to starData object containing required data (except name and gname)
0099      * @return Nothing
0100      */
0101     void init(const StarData *stardata);
0102 
0103     /**
0104      * @short  Initializes a StarObject to given data
0105      *
0106      * @param  stardata  Pointer to deepStarData object containing the available data
0107      * @return Nothing
0108      */
0109     void init(const DeepStarData *stardata);
0110 
0111     /**
0112      * @short  Sets the name, genetive name, and long name
0113      *
0114      * @param  name  Common name
0115      * @param  name2 Genetive name
0116      */
0117     void setNames(const QString &name, const QString &name2);
0118 
0119     /** @return true if the star has a name ("star" doesn't count) */
0120     inline bool hasName() const { return (!Name.isEmpty() && Name != starString); }
0121 
0122     /** @return true if the star has a latin name ("star" or HD... doesn't count) */
0123     inline bool hasLatinName() const
0124     {
0125         return (!Name.isEmpty() && Name != starString && Name != gname(false) && Name != gname(true) &&
0126                 !Name.startsWith("HD "));
0127     }
0128 
0129     /** If star is unnamed return "star" otherwise return the name */
0130     inline QString name(void) const override { return hasName() ? Name : starString; }
0131 
0132     /** If star is unnamed return "star" otherwise return the longname */
0133     inline QString longname(void) const override { return hasLongName() ? LongName : starString; }
0134 
0135     /**
0136      * Returns entire spectral type string
0137      * @return Spectral Type string
0138      */
0139     QString sptype(void) const;
0140 
0141     /** Returns just the first character of the spectral type string. */
0142     char spchar() const;
0143 
0144     /**
0145      * Returns the genetive name of the star.
0146      * @return genetive name of the star
0147      */
0148     QString gname(bool useGreekChars = true) const;
0149 
0150     /**
0151      * Returns the greek letter portion of the star's genetive name.
0152      * Returns empty string if star has no genetive name defined.
0153      * @return greek letter portion of genetive name
0154      */
0155     QString greekLetter(bool useGreekChars = true) const;
0156 
0157     /** @return the genitive form of the star's constellation. */
0158     QString constell(void) const;
0159 
0160     /**
0161      * Determine the current coordinates (RA, Dec) from the catalog
0162      * coordinates (RA0, Dec0), accounting for both precession and nutation.
0163      *
0164      * @param num pointer to KSNumbers object containing current values of
0165      * time-dependent variables.
0166      * @param includePlanets does nothing in this implementation (see KSPlanetBase::updateCoords()).
0167      * @param lat does nothing in this implementation (see KSPlanetBase::updateCoords()).
0168      * @param LST does nothing in this implementation (see KSPlanetBase::updateCoords()).
0169      * @param forceRecompute defines whether the data should be recomputed forcefully.
0170      */
0171     void updateCoords(const KSNumbers *num, bool includePlanets = true, const CachingDms *lat = nullptr,
0172                       const CachingDms *LST = nullptr, bool forceRecompute = false) override;
0173 
0174     /**
0175      * @short Fills ra and dec with the coordinates of the star with the proper
0176      * motion correction but without precision and its friends.  It is used
0177      * in StarComponent to re-index all the stars.
0178      * @note In the Hipparcos catalog, from which most of the proper
0179      * motion data in KStars is obtained, the RA correction already
0180      * has the cos(delta) factor incorporated into it. See
0181      * https://heasarc.gsfc.nasa.gov/W3Browse/all/hipparcos.html
0182      *
0183      * @return true if we changed the coordinates, false otherwise
0184      * NOTE: ra and dec both in degrees.
0185      */
0186     bool getIndexCoords(const KSNumbers *num, CachingDms &ra, CachingDms &dec);
0187     bool getIndexCoords(const KSNumbers *num, double *ra, double *dec);
0188 
0189     /** @short added for JIT updates from both StarComponent and ConstellationLines */
0190     void JITupdate();
0191 
0192     /** @short returns the magnitude of the proper motion correction in milliarcsec/year */
0193     inline double pmMagnitude() const
0194     {
0195         return sqrt(pmRA() * pmRA() + pmDec() * pmDec());
0196     }
0197 
0198     /**
0199      * @short returns the square of the magnitude of the proper motion correction in (milliarcsec/year)^2
0200      * @note In the Hipparcos catalog, from which most of the proper
0201      * motion data in KStars is obtained, the RA correction already
0202      * has the cos(delta) factor incorporated into it. See
0203      * https://heasarc.gsfc.nasa.gov/W3Browse/all/hipparcos.html
0204      * @note This method is faster when the square root need not be taken
0205      */
0206     inline double pmMagnitudeSquared() const
0207     {
0208         return (pmRA() * pmRA() + pmDec() * pmDec());
0209     }
0210 
0211     /**
0212      * @short Set the Ra and Dec components of the star's proper motion, in milliarcsec/year.
0213      * Note that the RA component should already have been multiplied by cos(dec).
0214      * @param pmra the new RA proper motion
0215      * @param pmdec the new Dec proper motion
0216      */
0217     inline void setProperMotion(double pmra, double pmdec)
0218     {
0219         PM_RA  = pmra;
0220         PM_Dec = pmdec;
0221     }
0222 
0223     /** @return the RA component of the star's proper motion, in mas/yr (multiplied by cos(dec)) */
0224     inline double pmRA() const { return PM_RA; }
0225 
0226     /** @return the Dec component of the star's proper motion, in mas/yr */
0227     inline double pmDec() const { return PM_Dec; }
0228 
0229     /** @short set the star's parallax angle, in milliarcsec */
0230     inline void setParallax(double plx) { Parallax = plx; }
0231 
0232     /** @return the star's parallax angle, in milliarcsec */
0233     inline double parallax() const { return Parallax; }
0234 
0235     /** @return the star's distance from the Sun in parsecs, as computed from the parallax. */
0236     inline double distance() const { return 1000. / parallax(); }
0237 
0238     /**
0239      * @short set the star's multiplicity flag (i.e., is it a binary or multiple star?)
0240      * @param m true if binary/multiple star system
0241      */
0242     inline void setMultiple(bool m) { Multiplicity = m; }
0243 
0244     /** @return whether the star is a binary or multiple starobject */
0245     inline bool isMultiple() const { return Multiplicity; }
0246 
0247     /** @return the star's HD index */
0248     inline int getHDIndex() const { return HD; }
0249 
0250     /**
0251      * @short set the star's variability flag
0252      *
0253      * @param v true if star is variable
0254      */
0255     inline void setVariable(bool v) { Variability = v; }
0256 
0257     /** @return whether the star is a binary or multiple starobject */
0258     inline bool isVariable() const { return Variability; }
0259 
0260     /** @short returns the name, the magnitude or both. */
0261     QString nameLabel(bool drawName, bool drawMag) const;
0262 
0263     QString labelString() const override;
0264 
0265     /**
0266      * @return the pixel distance for offseting the star's name label
0267      * This takes the zoom level and the star's brightness into account.
0268      */
0269     double labelOffset() const override;
0270 
0271     /** @return the Visual magnitude of the star */
0272     inline float getVMag() const { return V; }
0273 
0274     /** @return the blue magnitude of the star */
0275     inline float getBMag() const { return B; }
0276 
0277     /**
0278      * @return the B - V color index of the star, or a nonsense number
0279      * larger than 30 if it's not well defined
0280      */
0281     inline float getBVIndex() const { return ((B < 30.0 && V < 30.0) ? B - V : 99.9); }
0282 
0283     void initPopupMenu(KSPopupMenu *pmenu) override;
0284 
0285     quint64 updateID { 0 };
0286     quint64 updateNumID { 0 };
0287 
0288 #ifdef PROFILE_UPDATECOORDS
0289     static double updateCoordsCpuTime;
0290     static unsigned int starsUpdated;
0291 #endif
0292 
0293   protected:
0294     // DEBUG EDIT. For testing proper motion, uncomment this, and related blocks
0295     // See starobject.cpp for further info.
0296     //    static QVector<SkyPoint *> Trail;
0297     //    bool testStar;
0298     // END DEBUG
0299 
0300   private:
0301     double PM_RA { 0 };
0302     double PM_Dec { 0 };
0303     double Parallax { 0 };
0304     bool Multiplicity { false };
0305     bool Variability { false };
0306     char SpType[2];
0307     int HD { 0 };
0308     // B and V magnitudes, separately. NOTE 1) This is kept separate from mag for a reason.
0309     // See init( const DeepStarData *); 2) This applies only to deep stars at the moment
0310     float B { 0 };
0311     float V { 0 };
0312 };