File indexing completed on 2024-04-21 03:44:41
0001 /* 0002 SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "ksplanetbase.h" 0010 0011 #include <QHash> 0012 #include <QString> 0013 #include <QVector> 0014 0015 class KSNumbers; 0016 0017 /** 0018 * @class KSPlanet 0019 * A subclass of KSPlanetBase for seven of the major planets in the solar system 0020 * (Earth and Pluto have their own specialized classes derived from KSPlanetBase). 0021 * @note The Sun is subclassed from KSPlanet. 0022 * 0023 * KSPlanet contains internal classes to manage the computations of a planet's position. 0024 * The position is computed as a series of sinusoidal sums, similar to a Fourier 0025 * transform. See "Astronomical Algorithms" by Jean Meeus or the file README.planetmath 0026 * for details. 0027 * @short Provides necessary information about objects in the solar system. 0028 * 0029 * @author Jason Harris 0030 * @version 1.0 0031 */ 0032 class KSPlanet : public KSPlanetBase 0033 { 0034 public: 0035 /** 0036 * Constructor. 0037 * @param s Name of planet 0038 * @param image_file filename of the planet's image 0039 * @param c the color for the planet 0040 * @param pSize physical diameter of the planet, in km 0041 */ 0042 explicit KSPlanet(const QString &s = "unnamed", const QString &image_file = QString(), const QColor &c = Qt::white, 0043 double pSize = 0); 0044 0045 /** 0046 * Simplified constructor 0047 * @param n identifier of the planet to be created 0048 * @see PLANET enum 0049 */ 0050 explicit KSPlanet(int n); 0051 0052 KSPlanet *clone() const override; 0053 SkyObject::UID getUID() const override; 0054 0055 ~KSPlanet() override = default; 0056 0057 /** 0058 * @short return the untranslated name 0059 * This is a dirty way to solve a lot of localization-related trouble for the KDE 4.2 release 0060 * TODO: Change the whole architecture for names later 0061 */ 0062 QString untranslatedName() const; 0063 0064 /** @short Preload the data used by findPosition. */ 0065 bool loadData() override; 0066 0067 /** 0068 * Calculate the ecliptic longitude and latitude of the planet for 0069 * the given date (expressed in Julian Millenia since J2000). A reference 0070 * to the ecliptic coordinates is returned as the second object. 0071 * @param jm Julian Millenia (=jd/1000) 0072 * @param ret The ecliptic coordinates are returned by reference through this argument. 0073 */ 0074 virtual void calcEcliptic(double jm, EclipticPosition &ret) const; 0075 0076 protected: 0077 /** 0078 * Calculate the geocentric RA, Dec coordinates of the Planet. 0079 * @note reimplemented from KSPlanetBase 0080 * @param num pointer to object with time-dependent values for the desired date 0081 * @param Earth pointer to the planet Earth (needed to calculate geocentric coords) 0082 * @return true if position was successfully calculated. 0083 */ 0084 bool findGeocentricPosition(const KSNumbers *num, const KSPlanetBase *Earth = nullptr) override; 0085 0086 /** 0087 * @class OrbitData 0088 * This class contains doubles A,B,C which represent a single term in a planet's 0089 * positional expansion sums (each sum-term is A*COS(B+C*T)). 0090 * 0091 * @author Mark Hollomon 0092 * @version 1.0 0093 */ 0094 class OrbitData 0095 { 0096 public: 0097 /** Default constructor */ 0098 OrbitData() : A(0.), B(0.), C(0.) {} 0099 /** 0100 * Constructor 0101 * @param a the A value 0102 * @param b the B value 0103 * @param c the C value 0104 */ 0105 OrbitData(double a, double b, double c) : A(a), B(b), C(c) {} 0106 0107 double A, B, C; 0108 }; 0109 0110 typedef QVector<OrbitData> OBArray[6]; 0111 0112 /** 0113 * OrbitDataColl contains three groups of six QVectors. Each QVector is a 0114 * list of OrbitData objects, representing a single sum used in computing 0115 * the planet's position. A set of six of these vectors comprises the large 0116 * "meta-sum" which yields the planet's Longitude, Latitude, or Distance value. 0117 * 0118 * @author Mark Hollomon 0119 * @version 1.0 0120 */ 0121 class OrbitDataColl 0122 { 0123 public: 0124 /** Constructor */ 0125 OrbitDataColl() = default; 0126 0127 OBArray Lon; 0128 OBArray Lat; 0129 OBArray Dst; 0130 }; 0131 0132 /** 0133 * OrbitDataManager places the OrbitDataColl objects for all planets in a QDict 0134 * indexed by the planets' names. It also loads the positional data of each planet from disk. 0135 * 0136 * @author Mark Hollomon 0137 * @version 1.0 0138 */ 0139 class OrbitDataManager 0140 { 0141 public: 0142 /** Constructor */ 0143 OrbitDataManager(); 0144 0145 /** 0146 * Load orbital data for a planet from disk. 0147 * The data is stored on disk in a series of files named 0148 * "name.[LBR][0...5].vsop", where "L"=Longitude data, "B"=Latitude data, 0149 * and R=Radius data. 0150 * @param n the name of the planet whose data is to be loaded from disk. 0151 * @param odc reference to the OrbitDataColl containing the planet's orbital data. 0152 * @return true if data successfully loaded 0153 */ 0154 bool loadData(OrbitDataColl &odc, const QString &n); 0155 0156 private: 0157 /** 0158 * Read a single orbital data file from disk into an OrbitData vector. 0159 * The data files are named "name.[LBR][0...5].vsop", where 0160 * "L"=Longitude data, "B"=Latitude data, and R=Radius data. 0161 * @param fname the filename to be read. 0162 * @param vector pointer to the OrbitData vector to be filled with these data. 0163 */ 0164 bool readOrbitData(const QString &fname, QVector<KSPlanet::OrbitData> *vector); 0165 0166 QHash<QString, OrbitDataColl> hash; 0167 }; 0168 0169 private: 0170 void findMagnitude(const KSNumbers *) override; 0171 0172 protected: 0173 bool data_loaded { false }; 0174 static OrbitDataManager odm; 0175 };