[Kstars-devel] KDE/kdeedu/kstars/kstars

Médéric Boquien mboquien at free.fr
Fri Aug 7 00:42:37 CEST 2009


SVN commit 1008121 by mboquien:

Refactor the classes handling the moons of the planets. They had a lot of code duplication and adding moons to other planets would have been cumbersome.
Here is what it does:
* it removes JupiterMoonsComponent and the SaturnMoonsComponent classes and replaces them with a PlanetMoonsComponent class,
* it factors the sharable code of JupiterMoons and SaturnMoons into a new base class PlanetMoons. Only the code specific to the calculation of the location of the satellites is left into the subclasses.

Thanks to Alexey Khudyakov for reviewing the patch!

CCMAIL: kstars-devel at kde.org


 M  +2 -2      CMakeLists.txt  
 D             skycomponents/jupitermoonscomponent.cpp  
 D             skycomponents/jupitermoonscomponent.h  
 A             skycomponents/planetmoonscomponent.cpp   [License: GPL (v2+)]
 A             skycomponents/planetmoonscomponent.h   [License: GPL (v2+)]
 D             skycomponents/saturnmoonscomponent.cpp  
 D             skycomponents/saturnmoonscomponent.h  
 M  +3 -4      skycomponents/solarsystemcomposite.cpp  
 M  +3 -2      skycomponents/solarsystemcomposite.h  
 M  +10 -33    skyobjects/jupitermoons.cpp  
 M  +4 -58     skyobjects/jupitermoons.h  
 M  +1 -1      skyobjects/ksplanetbase.h  
 A             skyobjects/planetmoons.cpp   [License: GPL (v2+)]
 A             skyobjects/planetmoons.h   [License: GPL (v2+)]
 M  +10 -30    skyobjects/saturnmoons.cpp  
 M  +6 -57     skyobjects/saturnmoons.h  


--- trunk/KDE/kdeedu/kstars/kstars/CMakeLists.txt #1008120:1008121
@@ -188,8 +188,7 @@
    skycomponents/solarsystemlistcomponent.cpp 
    skycomponents/asteroidscomponent.cpp 
    skycomponents/cometscomponent.cpp 
-   skycomponents/jupitermoonscomponent.cpp 
-   skycomponents/saturnmoonscomponent.cpp 
+   skycomponents/planetmoonscomponent.cpp 
    skycomponents/solarsystemcomposite.cpp 
    skycomponents/satellitecomposite.cpp
    skycomponents/satellitecomponent.cpp
@@ -253,6 +252,7 @@
   skyobjects/deepskyobject.cpp
   skyobjects/jupitermoons.cpp
   skyobjects/saturnmoons.cpp
+  skyobjects/planetmoons.cpp
   skyobjects/ksasteroid.cpp
   skyobjects/kscomet.cpp
   skyobjects/ksmoon.cpp
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/solarsystemcomposite.cpp #1008120:1008121
@@ -33,8 +33,7 @@
 #include "skyobjects/kssun.h"
 #include "skyobjects/ksmoon.h"
 #include "skyobjects/kspluto.h"
-#include "jupitermoonscomponent.h"
-#include "saturnmoonscomponent.h"
+#include "planetmoonscomponent.h"
 
 // FIXME: is KStarsData needed here
 SolarSystemComposite::SolarSystemComposite(SkyComponent *parent, KStarsData * )
@@ -52,11 +51,11 @@
     addComponent( new SolarSystemSingleComponent( this, new KSPlanet( KSPlanetBase::MARS ), Options::showMars, 4 ) );
     SolarSystemSingleComponent *jup = new SolarSystemSingleComponent( this, new KSPlanet( KSPlanetBase::JUPITER ), Options::showJupiter, 4 );
     addComponent( jup );
-    m_JupiterMoons = new JupiterMoonsComponent( this, jup, &Options::showJupiter);
+    m_JupiterMoons = new PlanetMoonsComponent( this, jup, KSPlanetBase::JUPITER, &Options::showJupiter);
     addComponent( m_JupiterMoons );
     SolarSystemSingleComponent *sat = new SolarSystemSingleComponent( this, new KSPlanet( KSPlanetBase::SATURN ), Options::showSaturn, 4 );
     addComponent( sat );
-    m_SaturnMoons = new SaturnMoonsComponent( this, sat, &Options::showSaturn);
+    m_SaturnMoons = new PlanetMoonsComponent( this, sat, KSPlanetBase::SATURN, &Options::showSaturn);
     addComponent( m_SaturnMoons );
     addComponent( new SolarSystemSingleComponent( this, new KSPlanet( KSPlanetBase::URANUS ), Options::showUranus, 4 ) );
     addComponent( new SolarSystemSingleComponent( this, new KSPlanet( KSPlanetBase::NEPTUNE ), Options::showNeptune, 4 ) );
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/solarsystemcomposite.h #1008120:1008121
@@ -19,6 +19,7 @@
 #define SOLARSYSTEMCOMPOSITE_H
 
 #include "skycomposite.h"
+#include "planetmoonscomponent.h"
 
 class KSPlanet;
 class KSSun;
@@ -70,8 +71,8 @@
     KSPlanet *m_Earth;
     KSSun *m_Sun;
     KSMoon *m_Moon;
-    JupiterMoonsComponent *m_JupiterMoons;
-    SaturnMoonsComponent *m_SaturnMoons;
+    PlanetMoonsComponent *m_JupiterMoons;
+    PlanetMoonsComponent *m_SaturnMoons;
     AsteroidsComponent *m_AsteroidsComponent;
     CometsComponent *m_CometsComponent;
     SkyLabeler* m_skyLabeler;
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/jupitermoons.cpp #1008120:1008121
@@ -17,8 +17,6 @@
 
 #include "jupitermoons.h"
 
-#include <kdebug.h>
-
 #include "ksnumbers.h"
 #include "ksplanet.h"
 #include "kssun.h"
@@ -32,36 +30,15 @@
     Moon.append( new TrailObject( SkyObject::MOON, 0.0, 0.0, 4.6, i18nc( "Jupiter's moon Ganymede", "Ganymede" ) ) );
     Moon.append( new TrailObject( SkyObject::MOON, 0.0, 0.0, 5.7, i18nc( "Jupiter's moon Callisto", "Callisto" ) ) );
 
-    for ( uint i=0; i<4; ++i ) {
-        XJ[i] = 0.0;
-        YJ[i] = 0.0;
-        ZJ[i] = 0.0;
-    }
+    XP = QVector<double>(4, 0.0);
+    YP = QVector<double>(4, 0.0);
+    ZP = QVector<double>(4, 0.0);
+    InFront = QVector<bool>(4, false);
 }
 
 JupiterMoons::~JupiterMoons(){
-    qDeleteAll( Moon );
 }
 
-QString JupiterMoons::name( int id ) const { 
-    return Moon[id]->translatedName(); 
-}
-
-TrailObject* JupiterMoons::moonNamed( const QString &name ) const {
-    for ( uint i=0; i<4; ++i ) {
-        if ( Moon[i]->name() == name ) {
-            return Moon[i];
-            break;
-        }
-    }
-    return 0;
-}
-
-void JupiterMoons::EquatorialToHorizontal( const dms *LST, const dms *lat ) {
-    for ( uint i=0; i<4; ++i )
-        moon(i)->EquatorialToHorizontal( LST, lat );
-}
-
 void JupiterMoons::findPosition( const KSNumbers *num, const KSPlanet *Jupiter, const KSSun *Sun ) {
     double Xj, Yj, Zj, Rj;
     double sinJB, cosJB, sinJL, cosJL;
@@ -498,14 +475,14 @@
     pa = Jupiter->pa()*dms::PI/180.0;
 
     for ( int i=0; i<4; ++i ) {
-        XJ[i] = A6[i] * cos( D ) - C6[i] * sin( D );
-        YJ[i] = A6[i] * sin( D ) + C6[i] * cos( D );
-        ZJ[i] = B6[i];
+        XP[i] = A6[i] * cos( D ) - C6[i] * sin( D );
+        YP[i] = A6[i] * sin( D ) + C6[i] * cos( D );
+        ZP[i] = B6[i];
 
-        Moon[i]->setRA( Jupiter->ra()->Hours() - 0.011*( XJ[i] * cos( pa ) - YJ[i] * sin( pa ) )/15.0 );
-        Moon[i]->setDec( Jupiter->dec()->Degrees() - 0.011*( XJ[i] * sin( pa ) + YJ[i] * cos( pa ) ) );
+        Moon[i]->setRA( Jupiter->ra()->Hours() - 0.011*( XP[i] * cos( pa ) - YP[i] * sin( pa ) )/15.0 );
+        Moon[i]->setDec( Jupiter->dec()->Degrees() - 0.011*( XP[i] * sin( pa ) + YP[i] * cos( pa ) ) );
 
-        if ( ZJ[i] < 0.0 ) InFront[i] = true;
+        if ( ZP[i] < 0.0 ) InFront[i] = true;
         else InFront[i] = false;
 
         //Update Trails
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/jupitermoons.h #1008120:1008121
@@ -20,6 +20,7 @@
 
 #include <QString>
 #include <QVector>
+#include "planetmoons.h"
 
 class KSNumbers;
 class KSPlanet;
@@ -37,7 +38,7 @@
   *@author Jason Harris
   *@version 1.0
   */
-class JupiterMoons {
+class JupiterMoons: public PlanetMoons {
 public:
     /**
       *Constructor.  Assign the name of each moon,
@@ -48,7 +49,7 @@
     /**
       *Destructor.  Delete moon objects.
       */
-    ~JupiterMoons();
+    virtual ~JupiterMoons();
 
     /**
       *@short Find the positions of each Moon, relative to Jupiter.
@@ -70,62 +71,7 @@
       *@param jup pointer to the jupiter object
       *@param sunptr pointer to the Sun object
       */
-    void findPosition( const KSNumbers *num, const KSPlanet *jup, const KSSun *sunptr );
-
-    /**
-      *@return pointer to a moon given the ID number.
-      *@param id which moon?  0=Io, 1=Europa, 2=Ganymede, 3=Callisto
-      */
-    inline TrailObject* moon( int id ) { return Moon[id]; }
-
-    /**
-      *@return pointer to a moon, given its name:
-      *@param name the name of the moon (Io, Europa, Ganymede, Callisto)
-      */
-    TrailObject* moonNamed( const QString &name ) const;
-
-    /**
-      *@return true if the Moon is nearer to Earth than Jupiter.
-      *@param id which moon?  0=Io, 1=Europa, 2=Ganymede, 3=Callisto
-      */
-    inline bool inFront( int id ) const { return InFront[id]; }
-
-    /**
-      *@return the name of a moon.
-      *@param id which moon?  0=Io, 1=Europa, 2=Ganymede, 3=Callisto
-      */
-    QString name( int id ) const;
-
-    /**
-      *Convert the RA,Dec coordinates of each moon to Az,Alt
-      *@param LSTh pointer to the current local sidereal time
-      *@param lat pointer to the geographic latitude
-      */
-    void EquatorialToHorizontal( const dms *LSTh, const dms *lat );
-
-    /**
-      *@return the X-coordinate in the Jupiter-centered coord. system.
-      *@param i which moon? 0=Io, 1=Europa, 2=Ganymede, 3=Callisto.  
-      */
-    double x( int i ) const { return XJ[i]; }
-
-    /**
-      *@return the Y-coordinate in the Jupiter-centered coord. system.
-      *@param i which moon? 0=Io, 1=Europa, 2=Ganymede, 3=Callisto.  
-      */
-    double y( int i ) const { return YJ[i]; }
-
-    /**
-      *@return the Z-coordinate in the Jupiter-centered coord. system.
-      *@param i which moon? 0=Io, 1=Europa, 2=Ganymede, 3=Callisto.  
-      */
-    double z( int i ) const { return ZJ[i]; }
-
-private:
-    QVector<TrailObject*> Moon;
-    bool InFront[4];
-    //the rectangular position, relative to Jupiter.  X-axis is equator of Jupiter; usints are Jup. Radius
-    double XJ[4], YJ[4], ZJ[4];
+    virtual void findPosition( const KSNumbers *num, const KSPlanet *jup, const KSSun *sunptr );
 };
 
 #endif
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/ksplanetbase.h #1008120:1008121
@@ -82,7 +82,7 @@
 
     void init(const QString &s, const QString &image_file, const QColor &c, double pSize );
 
-    enum { MERCURY=0, VENUS=1, MARS=2, JUPITER=3, SATURN=4, URANUS=5, NEPTUNE=6, PLUTO=7, SUN=8, MOON=9, UNKNOWN_PLANET };
+    enum Planets { MERCURY=0, VENUS=1, MARS=2, JUPITER=3, SATURN=4, URANUS=5, NEPTUNE=6, PLUTO=7, SUN=8, MOON=9, UNKNOWN_PLANET };
 
     static KSPlanetBase* createPlanet( int n );
 
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/saturnmoons.cpp #1008120:1008121
@@ -36,35 +36,15 @@
     Moon.append( new TrailObject( SkyObject::MOON, 0.0, 0.0, 14.9, i18nc( "Saturn's moon Hyperion", "Hyperion" ) ) );
     Moon.append( new TrailObject( SkyObject::MOON, 0.0, 0.0, 11, i18nc( "Saturn's moon Iapetus", "Iapetus" ) ) );
 
-    for ( uint i=0; i<8; ++i ) {
-        XS[i] = 0.0;
-        YS[i] = 0.0;
-        ZS[i] = 0.0;
-    }
+    XP = QVector<double>(8, 0.0);
+    YP = QVector<double>(8, 0.0);
+    ZP = QVector<double>(8, 0.0);
+    InFront = QVector<bool>(8, false);
 }
 
 SaturnMoons::~SaturnMoons(){
-    qDeleteAll( Moon );
 }
 
-QString SaturnMoons::name( int id ) const {
-    return Moon[id]->translatedName();
-}
-
-TrailObject* SaturnMoons::moonNamed( const QString &name ) const {
-    for ( uint i=0; i<8; ++i ) {
-        if ( Moon[i]->name() == name ) {
-            return Moon[i];
-            break;
-        }
-    }
-    return 0;
-}
-
-void SaturnMoons::EquatorialToHorizontal( const dms *LST, const dms *lat ) {
-    for ( uint i=0; i<8; ++i )
-        moon(i)->EquatorialToHorizontal( LST, lat );
-}
 void SaturnMoons::HelperSubroutine(double e, double lambdadash, double p, double a,
                                    double omega, double i, double c1, double s1,
                                    double& r, double& lambda, double& gamma, double& w)
@@ -441,14 +421,14 @@
     double pa = Saturn->pa()*dms::PI/180.0;
 
     for ( int i=0; i<8; ++i ) {
-        XS[i] = A4[i+1] * cos( D ) - C4[i+1] * sin( D );
-        YS[i] = A4[i+1] * sin( D ) + C4[i+1] * cos( D );
-        ZS[i] = B4[i+1];
+        XP[i] = A4[i+1] * cos( D ) - C4[i+1] * sin( D );
+        YP[i] = A4[i+1] * sin( D ) + C4[i+1] * cos( D );
+        ZP[i] = B4[i+1];
 
-        Moon[i]->setRA( Saturn->ra()->Hours() - 0.011*( XS[i] * cos( pa ) - YS[i] * sin( pa ) )/15.0 );
-        Moon[i]->setDec( Saturn->dec()->Degrees() - 0.011*( XS[i] * sin( pa ) + YS[i] * cos( pa ) ) );
+        Moon[i]->setRA( Saturn->ra()->Hours() - 0.011*( XP[i] * cos( pa ) - YP[i] * sin( pa ) )/15.0 );
+        Moon[i]->setDec( Saturn->dec()->Degrees() - 0.011*( XP[i] * sin( pa ) + YP[i] * cos( pa ) ) );
 
-        if ( ZS[i] < 0.0 ) InFront[i] = true;
+        if ( ZP[i] < 0.0 ) InFront[i] = true;
         else InFront[i] = false;
 
         //Update Trails
--- trunk/KDE/kdeedu/kstars/kstars/skyobjects/saturnmoons.h #1008120:1008121
@@ -20,6 +20,7 @@
 
 #include <QString>
 #include <QVector>
+#include "planetmoons.h"
 
 class KSNumbers;
 class KSPlanet;
@@ -28,7 +29,7 @@
 class dms;
 
 /**
-  *@class SAturnMoons
+  *@class SaturnMoons
   *Implements the Eight largest moons of Saturn.
   *using Algorithms based on "Astronomical Algorithms"by Jean Meeus 
   *
@@ -37,7 +38,7 @@
   *@author Vipul Kumar Singh
   *@version 1.0
   */
-class SaturnMoons {
+class SaturnMoons : public PlanetMoons {
 public:
     /**
       *Constructor.  Assign the name of each moon,
@@ -48,7 +49,7 @@
     /**
       *Destructor.  Delete moon objects.
       */
-    ~SaturnMoons();
+    virtual ~SaturnMoons();
 
     /**
       *@short Find the positions of each Moon, relative to Saturn.
@@ -70,57 +71,10 @@
       *@param sat pointer to the Saturn object
       *@param sunptr pointer to the Sun object
       */
-    void findPosition( const KSNumbers *num, const KSPlanet *sat, const KSSun *sunptr );
+    virtual void findPosition( const KSNumbers *num, const KSPlanet *sat, const KSSun *sunptr );
 
-    /**
-      *@return pointer to a moon given the ID number.
-      *@param id which moon? 0=Mimas,1=Enceladus,2=Tethys,3=Dione,4=Rhea,5=Titan,6=Hyperion,7=Lapetus
-      */
-    inline TrailObject* moon( int id ) { return Moon[id]; }
+  private:
 
-    /**
-      *@return pointer to a moon, given its name:
-      *@param name the name of the moon (Mimas,Enceladus,Tethys,Dione,Rhea,Titan,Hyperion,Lapetus )
-      */
-    TrailObject* moonNamed( const QString &name ) const;
-
-    /**
-      *@return true if the Moon is nearer to Earth than Saturn.
-      *@param id which moon? 0=Mimas,1=Enceladus,2=Tethys,3=Dione,4=Rhea,5=Titan,6=Hyperion,7=Lapetus
-      */
-    inline bool inFront( int id ) const { return InFront[id]; }
-
-    /**
-      *@return the name of a moon.
-      *@param id which moon? 0=Mimas,1=Enceladus,2=Tethys,3=Dione,4=Rhea,5=Titan,6=Hyperion,7=Lapetus
-      */
-    QString name( int id ) const;
-
-    /**
-      *Convert the RA,Dec coordinates of each moon to Az,Alt
-      *@param LSTh pointer to the current local sidereal time
-      *@param lat pointer to the geographic latitude
-      */
-    void EquatorialToHorizontal( const dms *LSTh, const dms *lat );
-
-    /**
-      *@return the X-coordinate in the Saturn-centered coord. system.
-      *@param i which moon? 0=Mimas,1=Enceladus,2=Tethys,3=Dione,4=Rhea,5=Titan,6=Hyperion,7=Lapetus
-      */
-    double x( int i ) const { return XS[i]; }
-
-    /**
-      *@return the Y-coordinate in the Saturn-centered coord. system.
-      *@param i which moon? 0=Mimas,1=Enceladus,2=Tethys,3=Dione,4=Rhea,5=Titan,6=Hyperion,7=Lapetus
-      */
-    double y( int i ) const { return YS[i]; }
-
-    /**
-      *@return the Z-coordinate in the Saturn-centered coord. system.
-      *@param i which moon? 0=Mimas,1=Enceladus,2=Tethys,3=Dione,4=Rhea,5=Titan,6=Hyperion,7=Lapetus
-      */
-    double z( int i ) const { return ZS[i]; }
-
     /** the subroutine helps in saturn moon calculations
     */
     void HelperSubroutine( double e, double lambdadash, double p, double a, double omega, double i, double c1, double s1, double& r, double& lambda, double& gamma, double& w );
@@ -136,11 +90,6 @@
 	Value -= 360;
       return Value;
     }
-private:
-    QVector<TrailObject*> Moon;
-    bool InFront[8];
-    //the rectangular position, relative to Saturn.  X-axis is equator of Saturn; usints are Sat. Radius
-    double XS[8], YS[8], ZS[8];
 };
 
 #endif


More information about the Kstars-devel mailing list