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

Akarsh Simha akarshsimha at gmail.com
Wed Aug 13 17:37:57 CEST 2008


SVN commit 846503 by asimha:

+ Improving efficiency of the find dialog by reducing the number of
  calls to selectedObject()

+ Adding (buggy) support for searching by HD Catalog numbers. The
  search is troublesome with dynamic stars, but nevertheless, should
  be manageable till we figure out how to fix that.

+ Showing HD catalog number in the popup menu

Searching for HD Catalog numbers does not produce any results in the
Find Dialog list because including HD numbers in the list will make it
very slow.

CCMAIL: kstars-devel at kde.org



 M  +16 -5     finddialog.cpp  
 M  +1 -1      kspopupmenu.cpp  
 M  +3 -3      kstarsactions.cpp  
 M  +1 -0      skycomponents/skymapcomposite.h  
 M  +48 -8     skycomponents/starcomponent.cpp  
 M  +14 -0     skycomponents/starcomponent.h  
 M  +9 -4      starobject.cpp  
 M  +9 -2      starobject.h  


--- trunk/KDE/kdeedu/kstars/kstars/finddialog.cpp #846502:846503
@@ -231,7 +231,19 @@
         QString ObjName = i.data().toString();
         obj = p->data()->skyComposite()->findByName( ObjName );
     }
-
+    if( !obj ) {
+        QString stext = ui->SearchBox->text();
+        if( stext.startsWith( "HD" ) ) {
+            stext.remove( "HD" );
+            bool ok;
+            int HD = stext.toInt( &ok );
+            // Looks like the user is looking for a HD star
+            if( ok ) {
+                KStars *p = (KStars*)parent();
+                obj = p->data()->skyComposite()->getStarComponent()->findByHDIndex( HD );
+            }
+        }
+    }
     return obj;
 }
 
@@ -274,13 +286,12 @@
 
 void FindDialog::slotOk() {
     //If no valid object selected, show a sorry-box.  Otherwise, emit accept()
+    SkyObject *selObj;
     if(!listFiltered) {
         filterList();
     }
-    if(!selectedObject()) {
-        filterList();
-    }
-    if ( selectedObject() == 0 ) {
+    selObj = selectedObject();
+    if ( selObj == 0 ) {
         QString message = i18n( "No object named %1 found.", ui->SearchBox->text() );
         KMessageBox::sorry( 0, message, i18n( "Bad object name" ) );
     } else {
--- trunk/KDE/kdeedu/kstars/kstars/kspopupmenu.cpp #846502:846503
@@ -76,7 +76,7 @@
 void KSPopupMenu::createStarMenu( StarObject *star ) {
     //Add name, rise/set time, center/track, and detail-window items
     initPopupMenu( star, star->translatedLongName(), i18n( "Spectral type: %1" , star->sptype()),
-                   i18n( "star" ) );
+                   ( (!star->getHDIndex()) ? "" : QString( "HD%1" ).arg( QString::number( star->getHDIndex() ) ) ) );
 
     //If the star is named, add custom items to popup menu based on object's ImageList and InfoList
     if ( star->name() != "star" ) {
--- trunk/KDE/kdeedu/kstars/kstars/kstarsactions.cpp #846502:846503
@@ -474,9 +474,9 @@
     }
 
     if ( !findDialog ) kWarning() << i18n( "KStars::slotFind() - Not enough memory for dialog" ) ;
-
-    if ( findDialog->exec() == QDialog::Accepted && findDialog->selectedObject() ) {
-        map()->setClickedObject( findDialog->selectedObject() );
+    SkyObject *targetObject;
+    if ( findDialog->exec() == QDialog::Accepted && ( targetObject = findDialog->selectedObject() ) ) {
+        map()->setClickedObject( targetObject );
         map()->setClickedPoint( map()->clickedObject() );
         map()->slotCenter();
     }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.h #846502:846503
@@ -22,6 +22,7 @@
 
 #include "skycomposite.h"
 #include "ksnumbers.h"
+#include "starcomponent.h"
 
 class SkyMesh;
 class SkyLabeler;
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #846502:846503
@@ -90,8 +90,11 @@
         }
     }
 
+    if( deepStars ) {
+        if( hdidxReader.openFile( "Henry-Draper.idx" ) )
+            kDebug() << "Could not open HD Index file. Search by HD numbers for deep stars will not work." << endl;
+    }
 }
-
 StarComponent::~StarComponent() {
     deepStarReader.closeFile();
 }
@@ -571,6 +574,7 @@
                 plainStarTemplate.EquatorialToHorizontal( data()->lst(), data()->geo()->lat() );
                 if( !SB->addStar( &plainStarTemplate ) )
                     kDebug() << "CODE ERROR: More unnamed static stars in trixel " << trixel << " than we allocated space for!" << endl;
+                star = SB->star( SB->getStarCount() - 1 );
             }
             ++nstars;
             
@@ -593,9 +597,13 @@
                     if ( list->append( trixel, star, pm ) ) break;
                 }
             }
+
+            if( star->getHDIndex() != 0 )
+                m_HDHash.insert( star->getHDIndex(), star );
         }
 
     }
+
     dataReader.closeFile();
     nameReader.closeFile();
     kDebug() << "Loaded " << nstars << " stars in " << t.elapsed() << " ms" << endl;
@@ -608,20 +616,52 @@
     return m_genName.value( name );
 }
 
-// Overrides ListComponent::findByName() to include genetive name also in the search
+// Overrides ListComponent::findByName() to include genetive name and HD index also in the search
 SkyObject* StarComponent::findByName( const QString &name ) {
-    foreach ( SkyObject *o, objectList() )
-    if ( QString::compare( o->name(), name, Qt::CaseInsensitive ) == 0 || 
-        QString::compare( o->longname(), name, Qt::CaseInsensitive ) == 0 || 
-         QString::compare( o->name2(), name, Qt::CaseInsensitive ) == 0 || 
-         QString::compare( ((StarObject *)o)->gname(false), name, Qt::CaseInsensitive ) == 0)
+    SkyObject *o;
+    foreach ( o, objectList() )
+        if ( QString::compare( o->name(), name, Qt::CaseInsensitive ) == 0 || 
+             QString::compare( o->longname(), name, Qt::CaseInsensitive ) == 0 || 
+             QString::compare( o->name2(), name, Qt::CaseInsensitive ) == 0 || 
+             QString::compare( ((StarObject *)o)->gname(false), name, Qt::CaseInsensitive ) == 0)
+            return o;
+
+    return 0;
+}
+
+SkyObject *StarComponent::findByHDIndex( int HDnum ) {
+    FILE *hdidxFile;
+    SkyObject *o;
+    // First check the hash to see if we have a corresponding StarObject already
+    if( o = m_HDHash.value( HDnum, NULL ) )
         return o;
 
-    //No object found
+    if( !deepStars )
+        return 0;
+
+    hdidxFile = hdidxReader.getFileHandle();
+    if( hdidxFile ) {
+        qint32 offset;
+        fseek( hdidxFile, 4 * (HDnum - 1), SEEK_SET );
+        fread( &offset, 4, 1, hdidxFile );
+        if( offset > 0 ) {
+            FILE *deepStarFile;
+            starData stardata;
+            deepStarFile = deepStarReader.getFileHandle();
+            if( !fseek( deepStarFile, offset, SEEK_SET ) && fread( &stardata, sizeof( starData ), 1, deepStarFile ) ) {
+                m_starObject.init( &stardata );
+                m_starObject.EquatorialToHorizontal( data()->lst(), data()->geo()->lat() );
+                return &m_starObject;
+            }
+        }
+    }
+
     return 0;
+
 }
 
 
+
 // This uses the main star index for looking up nearby stars but then
 // filters out objects with the generic name "star".  We could easily
 // build an index for just the named stars which would make this go
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.h #846502:846503
@@ -126,6 +126,16 @@
     SkyObject* findByName( const QString &name );
 
     /**
+     *@short Find stars by HD catalog index
+     *@param HDnum HD Catalog Number of the star to find
+     *@return If the star is a static star, a pointer to the star will be returned
+     *        If it is a dynamic star, a fake copy will be created that survives till
+     *        the next findByHDIndex() call. If no match was found, returns NULL.
+     */
+
+    SkyObject* findByHDIndex( int HDnum );
+
+    /**
      *@short Prints some useful debug info about memory allocation for stars
      */
     void printDebugInfo();
@@ -174,6 +184,9 @@
     quint16        MSpT;             // Maximum number of stars in any given trixel
     bool           deepStars;        // Indicates whether deepstars are loaded
 
+    BinFileHelper  hdidxReader;
+    StarObject     m_starObject;
+
     KStarsSplash*  m_reloadSplash;
     KStarsSplash*  m_reindexSplash;
 
@@ -186,6 +199,7 @@
 
     QVector<HighPMStarList*> m_highPMStars;
     QHash<QString, SkyObject*> m_genName;
+    QHash<int, StarObject*> m_HDHash;
 
 
     /**
--- trunk/KDE/kdeedu/kstars/kstars/starobject.cpp #846502:846503
@@ -69,13 +69,14 @@
     Parallax = o.parallax();
     Multiplicity = o.isMultiple();
     Variability = o.isVariable();
+    HD = o.getHDIndex();
     updateID = updateNumID = 0;
 }
 
 StarObject::StarObject( dms r, dms d, float m,
                         const QString &n, const QString &n2,
                         const QString &sptype, double pmra, double pmdec,
-                        double par, bool mult, bool var )
+                        double par, bool mult, bool var, int hd )
         : SkyObject (SkyObject::STAR, r, d, m, n, n2, QString()),
           PM_RA(pmra), PM_Dec(pmdec),
           Parallax(par), Multiplicity(mult), Variability(var)
@@ -95,6 +96,8 @@
         setName( gname() );
     }
 
+    HD = hd;
+
     setLongName(lname);
     updateID = updateNumID = 0;
 }
@@ -102,7 +105,7 @@
 StarObject::StarObject( double r, double d, float m,
                         const QString &n, const QString &n2,
                         const QString &sptype, double pmra, double pmdec,
-                        double par, bool mult, bool var )
+                        double par, bool mult, bool var, int hd )
     : SkyObject (SkyObject::STAR, r, d, m, n, n2, QString()),
       PM_RA(pmra), PM_Dec(pmdec),
       Parallax(par), Multiplicity(mult), Variability(var)
@@ -121,7 +124,9 @@
         //If genetive name exists, but no primary name, set primary name = genetive name.
         setName( gname() );
     }
-    
+
+    HD = hd;    
+
     setLongName(lname);
     updateID = updateNumID = 0;
 }
@@ -146,7 +151,7 @@
     Multiplicity = stardata->flags & 0x02;
     Variability = stardata->flags & 0x04 ;
     updateID = updateNumID = 0;
-	
+    HD = stardata->HD;
 
     // DEBUG Edit. For testing proper motion. Uncomment all related blocks to test.
     // WARNING: You can debug only ONE STAR AT A TIME, because
--- trunk/KDE/kdeedu/kstars/kstars/starobject.h #846502:846503
@@ -67,10 +67,11 @@
         *@param par Parallax angle [mas]
         *@param mult Multiplicity flag (false=dingle star; true=multiple star)
         *@param var Variability flag (true if star is a known periodic variable)
+        *@param hd Henry Draper Number
         */
     explicit StarObject( dms r=dms(0.0), dms d=dms(0.0), float m=0.0, const QString &n=QString(),
                          const QString &n2=QString(), const QString &sptype="--", double pmra=0.0, double pmdec=0.0,
-                         double par=0.0, bool mult=false, bool var=false );
+                         double par=0.0, bool mult=false, bool var=false, int hd=0 );
     /**
         *Constructor.  Sets sky coordinates, magnitude, latin name, genetive name, and
         *spectral type.  Differs from above function only in data type of RA and Dec.
@@ -85,10 +86,11 @@
         *@param par Parallax angle [mas]
         *@param mult Multiplicity flag (false=dingle star; true=multiple star)
         *@param var Variability flag (true if star is a known periodic variable)
+        *@param hd Henry Draper Number
         */
     StarObject( double r, double d, float m=0.0, const QString &n=QString(),
                 const QString &n2=QString(), const QString &sptype="--", double pmra=0.0, double pmdec=0.0,
-                double par=0.0, bool mult=false, bool var=false );
+                double par=0.0, bool mult=false, bool var=false, int hd=0 );
 
     /**
      * Destructor. (Empty)
@@ -221,6 +223,10 @@
         */
     inline bool isMultiple() const { return Multiplicity; }
 
+    /**@return the star's HD index
+        */
+    inline int getHDIndex() { return HD; }
+
     /**@short set the star's variability flag
         *@param v true if star is variable
         */
@@ -326,6 +332,7 @@
 
     double PM_RA, PM_Dec, Parallax;  //, VRange, VPeriod;
     bool Multiplicity, Variability;
+    int HD;
 };
 
 #endif


More information about the Kstars-devel mailing list