summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/ksplanetbase.h
blob: 7178708725b18defe30071ad78cbc5f95d4b9d9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341

/***************************************************************************
                          ksplanetbase.h  -  K Desktop Planetarium
                             -------------------
    begin                : Sun Jan 29 2002
    copyright            : (C) 2002 by Mark Hollomon
    email                : mhh@mindspring.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KSPLANETBASE_H
#define KSPLANETBASE_H

#include <tqstring.h>
#include <tqptrlist.h>
#include <tqimage.h>

#include <kdebug.h>

#include "skyobject.h"
#include "dms.h"

#define MAXTRAIL 400  //maximum number of points in a planet trail

class TQPoint;
class KSNumbers;
class KSPopupMenu;

/**@class EclipticPosition
	*@short The ecliptic position of a planet (Longitude, Latitude, and distance from Sun).
	*@author Mark Hollomon
	*@version 1.0
	*/
class EclipticPosition {
	public:
		dms longitude;
		dms latitude;
		double radius;

		/**Constructor. */
		EclipticPosition(dms plong = 0.0, dms plat = 0.0, double prad = 0.0) :
			longitude(plong), latitude(plat), radius(prad) {}

		/**Assignment operator. Copy all values from the target object. */
		EclipticPosition &operator=(EclipticPosition &r) {
			this->longitude = r.longitude;
			this->latitude = r.latitude;
			this->radius = r.radius;
			return *this;
		}
};

/**@class KSPlanetBase
	*A subclass of SkyObject that provides additional information
	*needed for solar system objects. This is a base class for KSPlanet,
	* KSPluto, KSSun and KSMoon.
	*@short Provides necessary information about objects in the solar system.
	*@author Mark Hollomon
	*@version 1.0
	*/

class KStarsData;
class KSPlanetBase : public SkyObject {
public:

/**Constructor.  Calls SkyObject constructor with type=2 (planet),
	*coordinates=0.0, mag=0.0, primary name s, and all other TQStrings empty.
	@param kd Some kind of data
	*@param s Name of planet
	*@param image_file filename of the planet's image
	*@param pSize the planet's physical size, in km
	*
	*@todo Figure out what @p kd does.
	*/
	KSPlanetBase( KStarsData *kd, TQString s = i18n("unnamed"), TQString image_file="", double pSize=0 );

/**
	*Destructor (empty)
	*/
	virtual ~KSPlanetBase() {}

/**@return pointer to Ecliptic Longitude coordinate
	*/
	const dms* ecLong( void ) const { return &ep.longitude; }

/**
	*@return pointer to Ecliptic Latitude coordinate
	*/
	const dms* ecLat( void ) const { return &ep.latitude; }

/**@short Set Ecliptic Geocentric Longitude according to argument.
	*@param elong Ecliptic Longitude
	*/
	void setEcLong( dms elong ) { ep.longitude = elong; }

/**@short Set Ecliptic Geocentric Longitude according to argument.
	*Differs from above function only in argument type.
	*@param elong Ecliptic Longitude
	*/
	void setEcLong( double elong ) { ep.longitude.setD( elong ); }

/**@short Set Ecliptic Geocentric Latitude according to argument.
	*@param elat Ecliptic Latitude
	*/
	void setEcLat( dms elat ) { ep.latitude = elat; }

/**@short Set Ecliptic Geocentric Latitude according to argument.
	*Differs from above function only in argument type.
	*@param elat Ecliptic Latitude
	*/
	void setEcLat( double elat ) { ep.latitude.setD( elat ); }
	
	/**@return pointer to Ecliptic Heliocentric Longitude coordinate
	*/
	const dms* helEcLong( void ) const { return &helEcPos.longitude; }

/**
	*@return pointer to Ecliptic Heliocentric Latitude coordinate
	*/
	const dms* helEcLat( void ) const { return &helEcPos.latitude; }

/**@short Set Ecliptic Heliocentric Longitude according to argument.
	*@param elong Ecliptic Longitude
	*/
	void setHelEcLong( dms elong ) { helEcPos.longitude = elong; }

/**@short Set Ecliptic Heliocentric Longitude according to argument.
	*Differs from above function only in argument type.
	*@param elong Ecliptic Longitude
	*/
	void setHelEcLong( double elong ) { helEcPos.longitude.setD( elong ); }

/**@short Set Ecliptic Heliocentric Latitude according to argument.
	*@param elat Ecliptic Latitude
	*/
	void setHelEcLat( dms elat ) { helEcPos.latitude = elat; }

/**@short Set Ecliptic Heliocentric Latitude according to argument.
	*Differs from above function only in argument type.
	*@param elat Ecliptic Latitude
	*/
	void setHelEcLat( double elat ) { helEcPos.latitude.setD( elat ); }

/**@short Load the planet's orbital data from disk.
	*@return true if data successfully loaded
	*/
	virtual bool loadData() = 0;

/**@short Convert Ecliptic logitude/latitude to Right Ascension/Declination.
	*@param Obliquity current Obliquity of the Ecliptic (angle from Equator)
	*/
	void EclipticToEquatorial( const dms *Obliquity );

/**@short Convert Right Ascension/Declination to Ecliptic logitude/latitude.
	*@param Obliquity current Obliquity of the Ecliptic (angle from Equator)
	*/
	void EquatorialToEcliptic( const dms *Obliquity );

/**@return pointer to image of planet
	*/
	TQImage* image( void ) { return &Image; }

/**@return pointer to unrotated image of planet
	*/
	TQImage* image0( void ) { return &Image0; }

/**@return distance from Sun, in Astronomical Units (1 AU is Earth-Sun distance)
	*/
	double rsun( void ) const { return ep.radius; }

/**@short Set the solar distance in AU.
	*@param r the new solar distance in AU
	*/
	void setRsun( double r ) { ep.radius = r; }

/**@return distance from Earth, in Astronomical Units (1 AU is Earth-Sun distance)
	*/
	double rearth() const { return Rearth; }

/**@short Set the distance from Earth, in AU.
	*@param r the new earth-distance in AU
	*/
	void setRearth( double r ) { Rearth = r; }

/**@short compute and set the distance from Earth, in AU.
	*@param Earth pointer to the Earth from which to calculate the distance.
	*/
	void setRearth( const KSPlanetBase *Earth );

/**Update position of the planet (reimplemented from SkyPoint)
	*@param num current KSNumbers object
	*@param includePlanets this function does nothing if includePlanets=false
	*@param lat pointer to the geographic latitude; if NULL< we skip localizeCoords()
	*@param LST pointer to the local sidereal time; if NULL< we skip localizeCoords()
	*/
	virtual void updateCoords( KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0 );

/**
	*@short Find position, including correction for Figure-of-the-Earth.
	*@param num KSNumbers pointer for the target date/time
	*@param lat pointer to the geographic latitude; if NULL, we skip localizeCoords()
	*@param LST pointer to the local sidereal time; if NULL, we skip localizeCoords()
	*@param Earth pointer to the Earth (not used for the Moon)
	*/
	void findPosition( const KSNumbers *num, const dms *lat=0, const dms *LST=0, const KSPlanetBase *Earth = 0 );

/**@return the Planet's position angle.
	*/
		virtual double pa() const { return PositionAngle; }

/**@short Set the Planet's position angle.
	*@param p the new position angle
	*/
		void setPA( double p ) { PositionAngle = p; }

/**@return the Planet's angular size, in arcminutes
	*/
		double angSize() const { return AngularSize; }

/**@short set the planet's angular size, in km.
	*@p size the planet's size, in km
	*/
	void setAngularSize( double size ) { AngularSize = size; }

/**@return the Planet's physical size, in km
	*/
		double physicalSize() const { return PhysicalSize; }

/**@short set the planet's physical size, in km.
	*@p size the planet's size, in km
	*/
	void setPhysicalSize( double size ) { PhysicalSize = size; }

/**@return true if the KSPlanet is one of the eight major planets
 */
	bool isMajorPlanet() const;

/**@return whether the planet has a trail
 */
	bool hasTrail() const { return ( Trail.count() > 0 ); }

/**@return a reference to the planet's trail
	*/
		TQPtrList<SkyPoint>* trail() { return &Trail; }

/**@short adds a point to the planet's trail
	*/
		void addToTrail() { Trail.append( new SkyPoint( ra(), dec() ) ); }

/**@short removes the oldest point from the trail
	*/
		void clipTrail() { Trail.removeFirst(); }

/**@short clear the Trail
	*/
		void clearTrail() { Trail.clear(); }

/**@short updateQt::Horizontal coords of the trail
	*/
		void updateTrail( dms *LST, const dms *lat );

/**@short rotate Planet image
	*@param imageAngle the new angle of rotation for the image
	*/
	void rotateImage( double imageAngle );

/**@short scale and rotate Planet image
	*@param scale the scaling factor
	*@param imageAngle the new angle of rotation for the image
	*/
	void scaleRotateImage( int scale, double imageAngle );

/**Show Solar System object popup menu.  Overloaded from virtual 
	*SkyObject::showPopupMenu()
	*@param pmenu pointer to the KSPopupMenu object
	*@param pos TQPojnt holding the x,y coordinates for the menu
	*/
	virtual void showPopupMenu( KSPopupMenu *pmenu, TQPoint pos ) { pmenu->createPlanetMenu( this ); pmenu->popup( pos ); }

protected:
	virtual bool loadData(TQString n) {
		kdDebug() << "didn't reimplement for " << n << endl; return false;
	}

/**@short find the object's current geocentric equatorial coordinates (RA and Dec)
	*This function is pure virtual; it must be overloaded by subclasses.
	*This function is private; it is called by the public function findPosition()
	*which also includes the figure-of-the-earth correction, localizeCoords().
	*@param num pointer to current KSNumbers object
	*@param Earth pointer to planet Earth (needed to calculate geocentric coords)
	*@return true if position was successfully calculated.
	*/
	virtual bool findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth=NULL ) = 0;

/**Determine the position angle of the planet for a given date
	*(used internally by findPosition() )
	*/
	void findPA( const KSNumbers *num );

	// Geocentric ecliptic position, but distance to the Sun
	EclipticPosition ep;

	// Heliocentric ecliptic position referred to the equinox of the epoch 
	// as obtained from VSOP.
	EclipticPosition helEcPos;
	TQPtrList<SkyPoint> Trail;
	double  Rearth;

private:
/**@short correct the position for the fact that the location is not at the center of the Earth,
	*but a position on its surface.  This causes a small parallactic shift in a solar system
	*body's apparent position.  The effect is most significant for the Moon.
	*This function is private, and should only be called from the public findPosition() function.
	*@param num pointer to a ksnumbers object for the target date/time
	*@param lat pointer to the geographic latitude of the location.
	*@param LST pointer to the local sidereal time.
	*/
	void localizeCoords( const KSNumbers *num, const dms *lat, const dms *LST );

	/* Computes the visual magnitude for the major planets. 
	 * @param num pointer to a ksnumbers object. Needed for the saturn rings contribution to 
	 *        saturn magnitude.
	 * @param Earth pointer to an Earth object. Needed to know the distance between the Earth and the
	 *        Sun.
	 */
	void findMagnitude(const KSNumbers *num);

	TQImage Image0, Image;
	double PositionAngle, ImageAngle, AngularSize, PhysicalSize;
	KStarsData *data;
};

#endif