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

Akarsh Simha akarshsimha at gmail.com
Sat Jul 12 22:57:46 CEST 2008


SVN commit 831513 by asimha:

+ Adding copy constructors to KSPlanetBase, KSAsteroid, KSComet and
  TrailObject in order to facilitate the use of Comets and Asteroids
  in the Calculator, esp. in the Conjunctions Tool.

+ Allowing the first object in a conjunction prediction to be an
  asteroid or a comet.

CCMAIL: kstars-devel at kde.org



 M  +24 -0     ksasteroid.cpp  
 M  +22 -1     ksasteroid.h  
 M  +25 -1     kscomet.cpp  
 M  +27 -0     kscomet.h  
 M  +7 -0      ksplanetbase.cpp  
 M  +6 -0      ksplanetbase.h  
 M  +2 -11     tools/conjunctions.cpp  
 M  +5 -0      trailobject.cpp  
 M  +6 -0      trailobject.h  


--- trunk/KDE/kdeedu/kstars/kstars/ksasteroid.cpp #831512:831513
@@ -41,6 +41,30 @@
     P = 365.2568984 * pow(a, 1.5); //period in days
 }
 
+KSAsteroid::KSAsteroid( KSAsteroid &o ) 
+    : KSPlanetBase( (KSPlanetBase &) o ) {
+    setType( 10 );
+    o.getOrbitalElements( &JD, &a, &e, &i, &w, &N, &M );
+    this->H = o.getAbsoluteMagnitude();
+    this->G = o.getSlopeParameter();
+    P = 365.2568984 * pow(a, 1.5); //period in days
+}
+
+bool KSAsteroid::getOrbitalElements( long double *_JD, double *_a, double *_e, dms *_i,
+                                     dms *_w, dms *_N, dms *_M ) {
+    if( !_JD || !_a || !_e || !_i || !_w || !_N || !_M )
+        return false;
+    *_JD = JD;
+    *_a = a;
+    *_e = e;
+    *_i = i;
+    *_w = w;
+    *_N = N;
+    *_M = M;
+    return true;
+}
+
+
 bool KSAsteroid::findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth ) {
     //Precess the longitude of the Ascending Node to the desired epoch:
     dms n = dms( double( N.Degrees() - 3.82394E-5 * ( num->julianDay() - J2000 )) ).reduce();
--- trunk/KDE/kdeedu/kstars/kstars/ksasteroid.h #831512:831513
@@ -77,11 +77,17 @@
     	*@p N the longitude of the orbit's ascending node
     	*@p M the mean anomaly for the Julian Day
     	*@p H absolute magnitude
-      *@p G slope parameter
+        *@p G slope parameter
     	*/
     KSAsteroid( KStarsData *kd, const QString &s, const QString &image_file,
                 long double JD, double a, double e, dms i, dms w, dms N, dms M, double H, double G );
 
+    /**
+     *@short Copy constructor
+     *@param o  Object to make copy of
+     */
+    KSAsteroid( KSAsteroid &o );
+
     /**Destructor (empty)*/
     virtual ~KSAsteroid() {}
 
@@ -90,6 +96,21 @@
     	*/
     virtual bool loadData();
 
+    /**
+     *@note Used by the copy constructor
+     *@short  Obtain values of orbital elements
+     *@p JD the Julian Day for the orbital elements
+     *@p a the semi-major axis of the asteroid's orbit (AU)
+     *@p e the eccentricity of the asteroid's orbit
+     *@p i the inclination angle of the asteroid's orbit
+     *@p w the argument of the orbit's perihelion
+     *@p N the longitude of the orbit's ascending node
+     *@p M the mean anomaly for the Julian Day
+     */
+    bool getOrbitalElements( long double *_JD, double *_a, double *_e, 
+                             dms *_i, dms *_w, dms *_N, dms *_M );
+
+
     /**This lets other classes like KSPlanetBase access H and G values
 	*Used by KSPlanetBase::FindMagnitude
 	*/
--- trunk/KDE/kdeedu/kstars/kstars/kscomet.cpp #831512:831513
@@ -27,7 +27,6 @@
 KSComet::KSComet( KStarsData *_kd, const QString &_s, const QString &imfile,
                   long double _JD, double _q, double _e, dms _i, dms _w, dms _Node, double Tp )
         : KSPlanetBase(_kd, _s, imfile), kd(_kd), JD(_JD), q(_q), e(_e), i(_i), w(_w), N(_Node) {
-
     setType( 9 ); //Comet
 
     //Find the Julian Day of Perihelion from Tp
@@ -53,8 +52,33 @@
         setLongName( name() );
         setName( name().mid( name().indexOf("/") + 1 ) );
     }
+
 }
 
+KSComet::KSComet( KSComet &o )
+    : KSPlanetBase( (KSPlanetBase &) o ) {
+    setType( 9 ); // Comet
+    kd = KStarsData::Instance();
+    o.getOrbitalElements( &JD, &q, &e, &i, &w, &N );
+    JDp = o.getPerihelionJD();
+    a = q/(1.0 - e);
+    P = 365.2568984 * pow(a, 1.5);
+    setLongName( o.name2() );
+}    
+
+bool KSComet::getOrbitalElements( long double *_JD, double *_q, double *_e, dms *_i,
+                                  dms *_w, dms *_N ) {
+    if( !_JD || !_q || !_e || !_i || !_w || !_N )
+        return false;
+    *_JD = JD;
+    *_q = q;
+    *_e = e;
+    *_i = i;
+    *_w = w;
+    *_N = N;
+    return true;
+}
+
 bool KSComet::findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth ) {
     double v(0.0), r(0.0);
 
--- trunk/KDE/kdeedu/kstars/kstars/kscomet.h #831512:831513
@@ -62,6 +62,12 @@
     KSComet( KStarsData *kd, const QString &s, const QString &image_file,
              long double JD, double q, double e, dms i, dms w, dms N, double Tp );
 
+    /**
+     *Copy Constructor
+     *@param o  Object to copy into this
+     */
+    KSComet( KSComet &o );
+
     /**Destructor (empty)*/
     virtual ~KSComet() {}
 
@@ -70,7 +76,28 @@
     	*/
     virtual bool loadData();
 
+    /**
+     *@short Loads the orbital elements into the given pointers
+     *
+     *@param _JD  Julian Day of Orbital Elements
+     *@param _q the perihelion distance of the comet's orbit (AU)
+     *@param _e the eccentricity of the comet's orbit
+     *@param _i the inclination angle of the comet's orbit
+     *@param _w the argument of the orbit's perihelion
+     *@param _N the longitude of the orbit's ascending node
+     *
+     *@return true on success, false if one or more pointers were NULL
+     */
+    bool getOrbitalElements( long double *_JD, double *_q, double *_e, dms *_i,
+                             dms *_w, dms *_N );
 
+    /**
+     *@short Returns the Julian Day of Perihelion passage
+     *@return Julian Day of Perihelion Passage
+     */
+    inline long double getPerihelionJD() { return JDp; }
+
+
 protected:
     /**Calculate the geocentric RA, Dec coordinates of the Comet.
     	*@note reimplemented from KSPlanetBase
--- trunk/KDE/kdeedu/kstars/kstars/ksplanetbase.cpp #831512:831513
@@ -39,6 +39,13 @@
     init( s, image_file, c, pSize );
 }
 
+KSPlanetBase::KSPlanetBase( KSPlanetBase &o ) 
+    : TrailObject( (TrailObject &) o ) {
+    init( o.name(), "", o.color(), o.physicalSize() );
+    Image = *o.image();
+    Image0 = *o.image0();
+}
+
 void KSPlanetBase::init( const QString &s, const QString &image_file, const QColor &c, double pSize ) {
     if (! image_file.isEmpty()) {
         QFile imFile;
--- trunk/KDE/kdeedu/kstars/kstars/ksplanetbase.h #831512:831513
@@ -86,6 +86,12 @@
                            const QString &image_file=QString(),
                            const QColor &c=Qt::white, double pSize=0 );
 
+    /**
+     *Copy Constructor. Creates a copy of the given KSPlanetBase object
+     *@param o  Object to be copied
+     */
+    KSPlanetBase( KSPlanetBase &o );
+
    /**
      *Destructor (empty)
      */
--- trunk/KDE/kdeedu/kstars/kstars/tools/conjunctions.cpp #831512:831513
@@ -136,24 +136,15 @@
                 Object1 = KSPlanetBase::createPlanet( pNames.key( fd.selectedObject()->name() ) ); // TODO: Fix i18n issues.
                 break;
             }
-                /*
             case 9: {
-                Object1 = (KSComet *) new KSComet();
-                *Object1 = *fd.selectedObject();
+                Object1 = (KSComet *) new KSComet( (KSComet &) *fd.selectedObject() );
                 break;
             }
             case 10: {
-                Object1 = (KSAsteroid *) new KSAsteroid();
-                *Object1 = *fd.selectedObject();
+                Object1 = (KSAsteroid *) new KSAsteroid( (KSAsteroid &) *fd.selectedObject() );
                 break;
             }
-                */
-            case 9:
-            case 10: {
-                KMessageBox::error( NULL, i18n( "This feature is not yet implemented for Comets and Asteroids" ) );
-                break;
             }
-            }
         }
         if( Object1 )
             Obj1FindButton->setText( Object1->name() );
--- trunk/KDE/kdeedu/kstars/kstars/trailobject.cpp #831512:831513
@@ -26,6 +26,11 @@
   : SkyObject( t, r, d, m, n )
 {}
 
+TrailObject::TrailObject( TrailObject &o ) 
+    : SkyObject( (SkyObject &) o )
+{}
+
+
 void TrailObject::updateTrail( dms *LST, const dms *lat ) {
     for ( int i=0; i < Trail.size(); ++i )
         Trail[i].EquatorialToHorizontal( LST, lat );
--- trunk/KDE/kdeedu/kstars/kstars/trailobject.h #831512:831513
@@ -42,6 +42,12 @@
     TrailObject( int t, double r, double d, float m=0.0, const QString &n=QString() );
 
     /**
+     *Copy constructor.
+     *@param o SkyObject from which to copy data
+     */
+    TrailObject( TrailObject &o );
+
+    /**
      *@return whether the planet has a trail
      */
     inline bool hasTrail() const { return ( Trail.count() > 0 ); }


More information about the Kstars-devel mailing list