1 | |
2 | /*************************************************************************** |
3 | ksplanetbase.h - K Desktop Planetarium |
4 | ------------------- |
5 | begin : Sun Jan 29 2002 |
6 | copyright : (C) 2002 by Mark Hollomon |
7 | email : mhh@mindspring.com |
8 | ***************************************************************************/ |
9 | |
10 | /*************************************************************************** |
11 | * * |
12 | * This program is free software; you can redistribute it and/or modify * |
13 | * it under the terms of the GNU General Public License as published by * |
14 | * the Free Software Foundation; either version 2 of the License, or * |
15 | * (at your option) any later version. * |
16 | * * |
17 | ***************************************************************************/ |
18 | |
19 | #ifndef KSPLANETBASE_H_ |
20 | #define KSPLANETBASE_H_ |
21 | |
22 | |
23 | #include <QList> |
24 | #include <QImage> |
25 | #include <QColor> |
26 | |
27 | #include <kdebug.h> |
28 | |
29 | #include "trailobject.h" |
30 | |
31 | class KSNumbers; |
32 | class ; |
33 | |
34 | /** |
35 | *@class EclipticPosition |
36 | *@short The ecliptic position of a planet (Longitude, Latitude, and distance from Sun). |
37 | *@author Mark Hollomon |
38 | *@version 1.0 |
39 | */ |
40 | class EclipticPosition { |
41 | public: |
42 | dms longitude; |
43 | dms latitude; |
44 | double radius; |
45 | |
46 | /**Constructor. */ |
47 | explicit EclipticPosition(dms plong = dms(), dms plat = dms(), double prad = 0.0) : |
48 | longitude(plong), latitude(plat), radius(prad) |
49 | {} |
50 | }; |
51 | |
52 | /** |
53 | *@class KSPlanetBase |
54 | *A subclass of TrailObject that provides additional information |
55 | *needed for most solar system objects. This is a base class for |
56 | *KSSun, KSMoon, KSPlanet, KSAsteroid, and KSComet. Those classes |
57 | *cover all solar system objects except planetary moons, which are |
58 | *derived directly from TrailObject |
59 | *@short Provides necessary information about objects in the solar system. |
60 | *@author Mark Hollomon |
61 | *@version 1.0 |
62 | */ |
63 | class KSPlanetBase : public TrailObject { |
64 | public: |
65 | /** |
66 | *Constructor. Calls SkyObject constructor with type=2 (planet), |
67 | *coordinates=0.0, mag=0.0, primary name s, and all other QStrings empty. |
68 | *@param s Name of planet |
69 | *@param image_file filename of the planet's image |
70 | *@param c color of the symbol to use for this planet |
71 | *@param pSize the planet's physical size, in km |
72 | */ |
73 | explicit KSPlanetBase( const QString &s = i18n("unnamed" ), |
74 | const QString &image_file=QString(), |
75 | const QColor &c=Qt::white, double pSize=0 ); |
76 | |
77 | /** Destructor (empty) */ |
78 | virtual ~KSPlanetBase() {} |
79 | |
80 | void init(const QString &s, const QString &image_file, const QColor &c, double pSize ); |
81 | |
82 | enum Planets { MERCURY=0, VENUS=1, MARS=2, JUPITER=3, SATURN=4, URANUS=5, NEPTUNE=6, PLUTO=7, SUN=8, MOON=9, UNKNOWN_PLANET }; |
83 | |
84 | static KSPlanetBase* createPlanet( int n ); |
85 | |
86 | static QVector<QColor> planetColor; |
87 | |
88 | virtual bool loadData() = 0; |
89 | |
90 | /** @return pointer to Ecliptic Longitude coordinate */ |
91 | const dms& ecLong() const { return ep.longitude; } |
92 | |
93 | /** @return pointer to Ecliptic Latitude coordinate */ |
94 | const dms& ecLat() const { return ep.latitude; } |
95 | |
96 | /**@short Set Ecliptic Geocentric Longitude according to argument. |
97 | * @param elong Ecliptic Longitude |
98 | */ |
99 | void setEcLong( dms elong ) { ep.longitude = elong; } |
100 | |
101 | /**@short Set Ecliptic Geocentric Latitude according to argument. |
102 | * @param elat Ecliptic Latitude |
103 | */ |
104 | void setEcLat( dms elat ) { ep.latitude = elat; } |
105 | |
106 | /**@return pointer to Ecliptic Heliocentric Longitude coordinate */ |
107 | const dms& helEcLong() const { return helEcPos.longitude; } |
108 | |
109 | /**@return pointer to Ecliptic Heliocentric Latitude coordinate */ |
110 | const dms& helEcLat() const { return helEcPos.latitude; } |
111 | |
112 | /**@short Convert Ecliptic logitude/latitude to Right Ascension/Declination. |
113 | * @param Obliquity current Obliquity of the Ecliptic (angle from Equator) |
114 | */ |
115 | void EclipticToEquatorial( const dms *Obliquity ); |
116 | |
117 | /**@short Convert Right Ascension/Declination to Ecliptic logitude/latitude. |
118 | * @param Obliquity current Obliquity of the Ecliptic (angle from Equator) |
119 | */ |
120 | void EquatorialToEcliptic( const dms *Obliquity ); |
121 | |
122 | /** @return pointer to this planet's texture */ |
123 | const QImage& image() const { return m_image; } |
124 | |
125 | /**@return distance from Sun, in Astronomical Units (1 AU is Earth-Sun distance) */ |
126 | double rsun() const { return ep.radius; } |
127 | |
128 | /**@short Set the solar distance in AU. |
129 | * @param r the new solar distance in AU |
130 | */ |
131 | void setRsun( double r ) { ep.radius = r; } |
132 | |
133 | /**@return distance from Earth, in Astronomical Units (1 AU is Earth-Sun distance) */ |
134 | double rearth() const { return Rearth; } |
135 | |
136 | /**@short Set the distance from Earth, in AU. |
137 | * @param r the new earth-distance in AU |
138 | */ |
139 | void setRearth( double r ) { Rearth = r; } |
140 | |
141 | /**@short compute and set the distance from Earth, in AU. |
142 | * @param Earth pointer to the Earth from which to calculate the distance. |
143 | */ |
144 | void setRearth( const KSPlanetBase *Earth ); |
145 | |
146 | /**Update position of the planet (reimplemented from SkyPoint) |
147 | * @param num current KSNumbers object |
148 | * @param includePlanets this function does nothing if includePlanets=false |
149 | * @param lat pointer to the geographic latitude; if NULL, we skip localizeCoords() |
150 | * @param LST pointer to the local sidereal time; if NULL, we skip localizeCoords() |
151 | */ |
152 | virtual void updateCoords( KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0, bool forceRecompute = false ); |
153 | |
154 | /**@short Find position, including correction for Figure-of-the-Earth. |
155 | * @param num KSNumbers pointer for the target date/time |
156 | * @param lat pointer to the geographic latitude; if NULL, we skip localizeCoords() |
157 | * @param LST pointer to the local sidereal time; if NULL, we skip localizeCoords() |
158 | * @param Earth pointer to the Earth (not used for the Moon) |
159 | */ |
160 | void findPosition( const KSNumbers *num, const dms *lat=0, const dms *LST=0, const KSPlanetBase *Earth = 0 ); |
161 | |
162 | /** @return the Planet's position angle. */ |
163 | virtual double pa() const { return PositionAngle; } |
164 | |
165 | /**@short Set the Planet's position angle. |
166 | * @param p the new position angle |
167 | */ |
168 | void setPA( double p ) { PositionAngle = p; } |
169 | |
170 | /** @return the Planet's angular size, in arcminutes */ |
171 | double angSize() const { return AngularSize; } |
172 | |
173 | /**@short set the planet's angular size, in km. |
174 | * @param size the planet's size, in km |
175 | */ |
176 | void setAngularSize( double size ) { AngularSize = size; } |
177 | |
178 | /** @return the Planet's physical size, in km */ |
179 | double physicalSize() const { return PhysicalSize; } |
180 | |
181 | /**@short set the planet's physical size, in km. |
182 | * @param size the planet's size, in km |
183 | */ |
184 | void setPhysicalSize( double size ) { PhysicalSize = size; } |
185 | |
186 | /** @return the phase angle of this planet */ |
187 | inline dms phase() { return dms( Phase ); } |
188 | |
189 | /** @return the color for the planet symbol */ |
190 | QColor& color() { return m_Color; } |
191 | |
192 | /** @short Set the color for the planet symbol */ |
193 | void setColor( const QColor &c ) { m_Color = c; } |
194 | |
195 | /** @return true if the KSPlanet is one of the eight major planets */ |
196 | bool isMajorPlanet() const; |
197 | |
198 | /** @return the pixel distance for offseting the object's name label */ |
199 | virtual double labelOffset() const; |
200 | |
201 | protected: |
202 | /** Big object. Planet, Moon, Sun. */ |
203 | static const UID UID_SOL_BIGOBJ; |
204 | /** Asteroids */ |
205 | static const UID UID_SOL_ASTEROID; |
206 | /** Comets */ |
207 | static const UID UID_SOL_COMET; |
208 | |
209 | /** Compute high 32-bits of UID. */ |
210 | inline UID solarsysUID(UID type) const { return (SkyObject::UID_SOLARSYS << 60) | (type << 56); } |
211 | |
212 | /**@short find the object's current geocentric equatorial coordinates (RA and Dec) |
213 | * This function is pure virtual; it must be overloaded by subclasses. |
214 | * This function is private; it is called by the public function findPosition() |
215 | * which also includes the figure-of-the-earth correction, localizeCoords(). |
216 | * @param num pointer to current KSNumbers object |
217 | * @param Earth pointer to planet Earth (needed to calculate geocentric coords) |
218 | * @return true if position was successfully calculated. |
219 | */ |
220 | virtual bool findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth=NULL ) = 0; |
221 | |
222 | /** |
223 | * @short Computes the visual magnitude for the major planets. |
224 | * @param num pointer to a ksnumbers object. Needed for the saturn rings contribution to |
225 | * saturn's magnitude. |
226 | */ |
227 | virtual void findMagnitude(const KSNumbers *num) = 0; |
228 | |
229 | /**Determine the position angle of the planet for a given date |
230 | * (used internally by findPosition() ) |
231 | */ |
232 | void findPA( const KSNumbers *num ); |
233 | |
234 | /** Determine the phase of the planet. */ |
235 | virtual void findPhase(); |
236 | |
237 | // Geocentric ecliptic position, but distance to the Sun |
238 | EclipticPosition ep; |
239 | |
240 | // Heliocentric ecliptic position referred to the equinox of the epoch |
241 | // as obtained from VSOP. |
242 | EclipticPosition helEcPos; |
243 | double Rearth; |
244 | double Phase; |
245 | QImage m_image; |
246 | |
247 | private: |
248 | /** |
249 | * @short correct the position for the fact that the location is not at the center of the Earth, |
250 | * but a position on its surface. This causes a small parallactic shift in a solar system |
251 | * body's apparent position. The effect is most significant for the Moon. |
252 | * This function is private, and should only be called from the public findPosition() function. |
253 | * @param num pointer to a ksnumbers object for the target date/time |
254 | * @param lat pointer to the geographic latitude of the location. |
255 | * @param LST pointer to the local sidereal time. |
256 | */ |
257 | void localizeCoords( const KSNumbers *num, const dms *lat, const dms *LST ); |
258 | |
259 | double PositionAngle, AngularSize, PhysicalSize; |
260 | QColor m_Color; |
261 | }; |
262 | |
263 | #endif |
264 | |