1/***************************************************************************
2 ksplanet.h - K Desktop Planetarium
3 -------------------
4 begin : Sun Jul 22 2001
5 copyright : (C) 2001 by Jason Harris
6 email : jharris@30doradus.org
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef KSPLANET_H_
19#define KSPLANET_H_
20
21#include <QVector>
22#include <QHash>
23
24#include "ksplanetbase.h"
25#include "dms.h"
26
27/**@class KSPlanet
28 *A subclass of KSPlanetBase for seven of the major planets in the solar system
29 *(Earth and Pluto have their own specialized classes derived from KSPlanetBase).
30 *@note The Sun is subclassed from KSPlanet.
31 *
32 *KSPlanet contains internal classes to manage the computations of a planet's position.
33 *The position is computed as a series of sinusoidal sums, similar to a Fourier
34 *transform. See "Astronomical Algorithms" by Jean Meeus or the file README.planetmath
35 *for details.
36 *@short Provides necessary information about objects in the solar system.
37 *@author Jason Harris
38 *@version 1.0
39 */
40class KSPlanet : public KSPlanetBase {
41public:
42
43 /**
44 * Constructor.
45 * @param s Name of planet
46 * @param image_file filename of the planet's image
47 * @param c the color for the planet
48 * @param pSize physical diameter of the planet, in km
49 */
50 explicit KSPlanet( const QString &s="unnamed", const QString &image_file=QString(),
51 const QColor & c=Qt::white, double pSize=0 );
52
53 /**
54 * Simplified constructor
55 * @param n identifier of the planet to be created
56 * @see PLANET enum
57 */
58 explicit KSPlanet( int n );
59
60 virtual KSPlanet* clone() const;
61 virtual SkyObject::UID getUID() const;
62
63 /**
64 * Destructor (empty)
65 */
66 virtual ~KSPlanet() {}
67
68 /**@short return the untranslated name
69 *This is a dirty way to solve a lot of localization-related trouble for the KDE 4.2 release
70 *TODO: Change the whole architecture for names later
71 */
72 QString untranslatedName( void ) const;
73
74 /**@short Preload the data used by findPosition.
75 */
76 virtual bool loadData();
77
78 /**Calculate the ecliptic longitude and latitude of the planet for
79 *the given date (expressed in Julian Millenia since J2000). A reference
80 *to the ecliptic coordinates is returned as the second object.
81 *@param jm Julian Millenia (=jd/1000)
82 *@param ret The ecliptic coordinates are returned by reference through this argument.
83 */
84 virtual void calcEcliptic(double jm, EclipticPosition &ret) const;
85
86protected:
87
88 bool data_loaded;
89
90 /**Calculate the geocentric RA, Dec coordinates of the Planet.
91 *@note reimplemented from KSPlanetBase
92 *@param num pointer to object with time-dependent values for the desired date
93 *@param Earth pointer to the planet Earth (needed to calculate geocentric coords)
94 *@return true if position was successfully calculated.
95 */
96 virtual bool findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth=NULL );
97
98 /**@class OrbitData
99 *This class contains doubles A,B,C which represent a single term in a planet's
100 *positional expansion sums (each sum-term is A*COS(B+C*T)).
101 *@author Mark Hollomon
102 *@version 1.0
103 */
104 class OrbitData {
105 public:
106 /**
107 *Default constructor
108 */
109 OrbitData() : A(0.), B(0.), C(0.) {}
110 /**
111 *Constructor
112 *@param a the A value
113 *@param b the B value
114 *@param c the C value
115 */
116 OrbitData(double a, double b, double c) : A(a), B(b), C(c) {}
117
118 /**
119 *Assignment operator
120 */
121 OrbitData operator= ( const OrbitData o ) { return o; }
122
123 double A, B, C;
124 };
125
126 typedef QVector<OrbitData> OBArray[6];
127
128 /**OrbitDataColl contains three groups of six QVectors. Each QVector is a
129 *list of OrbitData objects, representing a single sum used in computing
130 *the planet's position. A set of six of these vectors comprises the large
131 *"meta-sum" which yields the planet's Longitude, Latitude, or Distance value.
132 *@author Mark Hollomon
133 *@version 1.0
134 */
135 class OrbitDataColl {
136 public:
137 /**Constructor*/
138 OrbitDataColl();
139
140 OBArray Lon;
141 OBArray Lat;
142 OBArray Dst;
143 };
144
145
146 /**OrbitDataManager places the OrbitDataColl objects for all planets in a QDict
147 *indexed by the planets' names. It also loads the positional data of each planet
148 *from disk.
149 *@author Mark Hollomon
150 *@version 1.0
151 */
152 class OrbitDataManager {
153 public:
154 /**Constructor*/
155 OrbitDataManager();
156
157 /**Load orbital data for a planet from disk.
158 *The data is stored on disk in a series of files named
159 *"name.[LBR][0...5].vsop", where "L"=Longitude data, "B"=Latitude data,
160 *and R=Radius data.
161 *@param n the name of the planet whose data is to be loaded from disk.
162 *@param odc reference to the OrbitDataColl containing the planet's orbital data.
163 *@return true if data successfully loaded
164 */
165 bool loadData( OrbitDataColl &odc, const QString &n);
166
167 private:
168 /**Read a single orbital data file from disk into an OrbitData vector.
169 *The data files are named "name.[LBR][0...5].vsop", where
170 *"L"=Longitude data, "B"=Latitude data, and R=Radius data.
171 *@param fname the filename to be read.
172 *@param vector pointer to the OrbitData vector to be filled with these data.
173 */
174 bool readOrbitData(const QString &fname, QVector<KSPlanet::OrbitData> *vector);
175
176 QHash<QString, OrbitDataColl> hash;
177 };
178
179 static OrbitDataManager odm;
180
181private:
182 virtual void findMagnitude(const KSNumbers*);
183};
184
185#endif
186