moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / ksplanetbase.h
blobc4402973f8bfae9d68cfd3116c40e9557288061b
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 ***************************************************************************/
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 ***************************************************************************/
19 #ifndef KSPLANETBASE_H
20 #define KSPLANETBASE_H
22 #include <qstring.h>
23 #include <qptrlist.h>
24 #include <qimage.h>
26 #include <kdebug.h>
28 #include "skyobject.h"
29 #include "dms.h"
31 #define MAXTRAIL 400 //maximum number of points in a planet trail
33 class QPoint;
34 class KSNumbers;
35 class KSPopupMenu;
37 /**@class EclipticPosition
38 *@short The ecliptic position of a planet (Longitude, Latitude, and distance from Sun).
39 *@author Mark Hollomon
40 *@version 1.0
42 class EclipticPosition {
43 public:
44 dms longitude;
45 dms latitude;
46 double radius;
48 /**Constructor. */
49 EclipticPosition(dms plong = 0.0, dms plat = 0.0, double prad = 0.0) :
50 longitude(plong), latitude(plat), radius(prad) {};
52 /**Assignment operator. Copy all values from the target object. */
53 EclipticPosition &operator=(EclipticPosition &r) {
54 this->longitude = r.longitude;
55 this->latitude = r.latitude;
56 this->radius = r.radius;
57 return *this;
61 /**@class KSPlanetBase
62 *A subclass of SkyObject that provides additional information
63 *needed for solar system objects. This is a base class for KSPlanet,
64 * KSPluto, KSSun and KSMoon.
65 *@short Provides necessary information about objects in the solar system.
66 *@author Mark Hollomon
67 *@version 1.0
70 class KStarsData;
71 class KSPlanetBase : public SkyObject {
72 public:
74 /**Constructor. Calls SkyObject constructor with type=2 (planet),
75 *coordinates=0.0, mag=0.0, primary name s, and all other QStrings empty.
76 *@param s Name of planet
77 *@param im the planet's image
78 *@param pSize the planet's physical size, in km
80 KSPlanetBase( KStarsData *kd, QString s = i18n("unnamed"), QString image_file="", double pSize=0 );
82 /**
83 *Destructor (empty)
85 virtual ~KSPlanetBase() {}
87 /**@return pointer to Ecliptic Longitude coordinate
89 const dms* ecLong( void ) const { return &ep.longitude; };
91 /**
92 *@return pointer to Ecliptic Latitude coordinate
94 const dms* ecLat( void ) const { return &ep.latitude; };
96 /**@short Set Ecliptic Geocentric Longitude according to argument.
97 *@param elong Ecliptic Longitude
99 void setEcLong( dms elong ) { ep.longitude = elong; }
101 /**@short Set Ecliptic Geocentric Longitude according to argument.
102 *Differs from above function only in argument type.
103 *@param elong Ecliptic Longitude
105 void setEcLong( double elong ) { ep.longitude.setD( elong ); }
107 /**@short Set Ecliptic Geocentric Latitude according to argument.
108 *@param elat Ecliptic Latitude
110 void setEcLat( dms elat ) { ep.latitude = elat; }
112 /**@short Set Ecliptic Geocentric Latitude according to argument.
113 *Differs from above function only in argument type.
114 *@param elat Ecliptic Latitude
116 void setEcLat( double elat ) { ep.latitude.setD( elat ); }
118 /**@return pointer to Ecliptic Heliocentric Longitude coordinate
120 const dms* helEcLong( void ) const { return &helEcPos.longitude; };
123 *@return pointer to Ecliptic Heliocentric Latitude coordinate
125 const dms* helEcLat( void ) const { return &helEcPos.latitude; };
127 /**@short Set Ecliptic Heliocentric Longitude according to argument.
128 *@param elong Ecliptic Longitude
130 void setHelEcLong( dms elong ) { helEcPos.longitude = elong; }
132 /**@short Set Ecliptic Heliocentric Longitude according to argument.
133 *Differs from above function only in argument type.
134 *@param elong Ecliptic Longitude
136 void setHelEcLong( double elong ) { helEcPos.longitude.setD( elong ); }
138 /**@short Set Ecliptic Heliocentric Latitude according to argument.
139 *@param elat Ecliptic Latitude
141 void setHelEcLat( dms elat ) { helEcPos.latitude = elat; }
143 /**@short Set Ecliptic Heliocentric Latitude according to argument.
144 *Differs from above function only in argument type.
145 *@param elat Ecliptic Latitude
147 void setHelEcLat( double elat ) { helEcPos.latitude.setD( elat ); }
149 /**@short Load the planet's orbital data from disk.
150 *@return true if data successfully loaded
152 virtual bool loadData() = 0;
154 /**@short Convert Ecliptic logitude/latitude to Right Ascension/Declination.
155 *@param Obliquity current Obliquity of the Ecliptic (angle from Equator)
157 void EclipticToEquatorial( const dms *Obliquity );
159 /**@short Convert Right Ascension/Declination to Ecliptic logitude/latitude.
160 *@param Obliquity current Obliquity of the Ecliptic (angle from Equator)
162 void EquatorialToEcliptic( const dms *Obliquity );
164 /**@return pointer to image of planet
166 QImage* image( void ) { return &Image; };
168 /**@return pointer to unrotated image of planet
170 QImage* image0( void ) { return &Image0; };
172 /**@return distance from Sun, in Astronomical Units (1 AU is Earth-Sun distance)
174 double rsun( void ) const { return ep.radius; };
176 /**@short Set the solar distance in AU.
177 *@param r the new solar distance in AU
179 void setRsun( double r ) { ep.radius = r; };
181 /**@return distance from Earth, in Astronomical Units (1 AU is Earth-Sun distance)
183 double rearth() const { return Rearth; }
185 /**@short Set the distance from Earth, in AU.
186 *@param r the new earth-distance in AU
188 void setRearth( double r ) { Rearth = r; }
190 /**@short compute and set the distance from Earth, in AU.
191 *@param Earth pointer to the Earth from which to calculate the distance.
193 void setRearth( const KSPlanetBase *Earth );
195 /**Update position of the planet (reimplemented from SkyPoint)
196 *@param num current KSNumbers object
197 *@param includePlanets this function does nothing if includePlanets=false
198 *@param lat pointer to the geographic latitude; if NULL< we skip localizeCoords()
199 *@param LST pointer to the local sidereal time; if NULL< we skip localizeCoords()
201 virtual void updateCoords( KSNumbers *num, bool includePlanets=true, const dms *lat=0, const dms *LST=0 );
204 *@short Find position, including correction for Figure-of-the-Earth.
205 *@param num KSNumbers pointer for the target date/time
206 *@param lat pointer to the geographic latitude; if NULL, we skip localizeCoords()
207 *@param LST pointer to the local sidereal time; if NULL, we skip localizeCoords()
208 *@param Earth pointer to the Earth (not used for the Moon)
210 void findPosition( const KSNumbers *num, const dms *lat=0, const dms *LST=0, const KSPlanetBase *Earth = 0 );
212 /**@return the Planet's position angle.
214 virtual double pa() const { return PositionAngle; }
216 /**@short Set the Planet's position angle.
217 *@param p the new position angle
219 void setPA( double p ) { PositionAngle = p; }
221 /**@return the Planet's angular size, in arcminutes
223 double angSize() const { return AngularSize; }
225 /**@short set the planet's angular size, in km.
226 *@p size the planet's size, in km
228 void setAngularSize( double size ) { AngularSize = size; }
230 /**@return the Planet's physical size, in km
232 double physicalSize() const { return PhysicalSize; }
234 /**@short set the planet's physical size, in km.
235 *@p size the planet's size, in km
237 void setPhysicalSize( double size ) { PhysicalSize = size; }
239 /**@return true if the KSPlanet is one of the eight major planets
241 bool isMajorPlanet() const;
243 /**@return whether the planet has a trail
245 bool hasTrail() const { return ( Trail.count() > 0 ); }
247 /**@return a reference to the planet's trail
249 QPtrList<SkyPoint>* trail() { return &Trail; }
251 /**@short adds a point to the planet's trail
252 *@param sp a pointer to the SkyPoint to add (will be AutoDeleted)
254 void addToTrail() { Trail.append( new SkyPoint( ra(), dec() ) ); }
256 /**@short removes the oldest point from the trail
258 void clipTrail() { Trail.removeFirst(); }
260 /**@short clear the Trail
262 void clearTrail() { Trail.clear(); }
264 /**@short update Horizontal coords of the trail
266 void updateTrail( dms *LST, const dms *lat );
268 /**@short rotate Planet image
269 *@param imageAngle the new angle of rotation for the image
271 void rotateImage( double imageAngle );
273 /**@short scale and rotate Planet image
274 *@param scale the scaling factor
275 *@param imageAngle the new angle of rotation for the image
277 void scaleRotateImage( int scale, double imageAngle );
279 /**Show Solar System object popup menu. Overloaded from virtual
280 *SkyObject::showPopupMenu()
281 *@param pmenu pointer to the KSPopupMenu object
282 *@param pos QPojnt holding the x,y coordinates for the menu
284 virtual void showPopupMenu( KSPopupMenu *pmenu, QPoint pos ) { pmenu->createPlanetMenu( this ); pmenu->popup( pos ); }
286 protected:
287 virtual bool loadData(QString n) {
288 kdDebug() << "didn't reimplement for " << n << endl; return false;
291 /**@short find the object's current geocentric equatorial coordinates (RA and Dec)
292 *This function is pure virtual; it must be overloaded by subclasses.
293 *This function is private; it is called by the public function findPosition()
294 *which also includes the figure-of-the-earth correction, localizeCoords().
295 *@param num pointer to current KSNumbers object
296 *@param Earth pointer to planet Earth (needed to calculate geocentric coords)
297 *@return true if position was successfully calculated.
299 virtual bool findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth=NULL ) = 0;
301 /**Determine the position angle of the planet for a given date
302 *(used internally by findPosition() )
304 void findPA( const KSNumbers *num );
306 // Geocentric ecliptic position, but distance to the Sun
307 EclipticPosition ep;
309 // Heliocentric ecliptic position referred to the equinox of the epoch
310 // as obtained from VSOP.
311 EclipticPosition helEcPos;
312 QPtrList<SkyPoint> Trail;
313 double Rearth;
315 private:
316 /**@short correct the position for the fact that the location is not at the center of the Earth,
317 *but a position on its surface. This causes a small parallactic shift in a solar system
318 *body's apparent position. The effect is most significant for the Moon.
319 *This function is private, and should only be called from the public findPosition() function.
320 *@param num pointer to a ksnumbers object for the target date/time
321 *@param lat pointer to the geographic latitude of the location.
322 *@param LST pointer to the local sidereal time.
324 void localizeCoords( const KSNumbers *num, const dms *lat, const dms *LST );
326 /* Computes the visual magnitude for the major planets.
327 * @param num pointer to a ksnumbers object. Needed for the saturn rings contribution to
328 * saturn magnitude.
329 * @param Earth pointer to an Earth object. Needed to know the distance between the Earth and the
330 * Sun.
332 void findMagnitude(const KSNumbers *num);
334 QImage Image0, Image;
335 double PositionAngle, ImageAngle, AngularSize, PhysicalSize;
336 KStarsData *data;
339 #endif