[Kstars-devel] Name Resolver test patch

Akarsh Simha akarshsimha at gmail.com
Thu May 19 12:01:15 UTC 2016


Hello

The latest commits to master include a namespace called NameResolver,
which contains methods to resolve a deep-sky object identifier using
CDS Sesame (online resolver service). This namespace is added to the
make list, so it gets built and linked, but it is not used in KStars
at the moment -- so nothing should have been changed as far as the
name resolver feature is concerned.

However, the attached patch (which is definitely not ready to be
checked into master) will let one test the name resolver by calling it
from the Find Dialog. To test the resolver feature, after building,
switch to Equatorial Coordinates and pause the simulation clock. Then
fire up the Find Dialog, type in the name of an object unknown to
KStars but known to Simbad/NED, and just hit enter even though no
search results show up. Watch the console for messages.

The difficult tasks ahead are to make sure that we cleanly store the
object in KStars runtime memory, as well as commit it to the object
database, so that there will be no bugs from a newly introduced
object, ensuring that the object can be used in Alt vs. Time /
Observation Planner / Ekos etc. seamlessly. Also UI improvements will
be warranted.

Please let me know if I need to fix anything in the existing code, and
also if it conflicts with the goals of other concurrent projects
(KStars Lite and Windows)

Regards
Akarsh
-------------- next part --------------
diff --git a/kstars/dialogs/finddialog.cpp b/kstars/dialogs/finddialog.cpp
index 6cd0cfa..35083aa 100644
--- a/kstars/dialogs/finddialog.cpp
+++ b/kstars/dialogs/finddialog.cpp
@@ -23,6 +23,7 @@
 #include "skyobjects/skyobject.h"
 #include "skycomponents/starcomponent.h"
 #include "skycomponents/skymapcomposite.h"
+#include "tools/nameresolver.h"
 
 #include <KMessageBox>
 
@@ -53,7 +54,8 @@ FindDialogUI::FindDialogUI( QWidget *parent ) : QFrame( parent ) {
 
 FindDialog::FindDialog( QWidget* parent ) :
     QDialog( parent ),
-    timer(0)
+    timer(0),
+    m_targetObject( 0 )
 {
     ui = new FindDialogUI( this );
 
@@ -105,6 +107,7 @@ void FindDialog::init() {
     filterByType();
     sortModel->sort( 0 );
     initSelection();
+    m_targetObject = 0;
 }
 
 void FindDialog::initSelection() {
@@ -317,6 +320,21 @@ void FindDialog::slotOk() {
         filterList();
     }
     selObj = selectedObject();
+    if( ! selObj ) {
+        // ==== FIXME: What follows is buggy testing code : please improve ====
+        // This code is expected to cause crashes / memory leaks
+        // because we don't commit the DSO data to the database, or
+        // any CatalogComponent.
+        CatalogEntryData cedata;
+        cedata = NameResolver::resolveName( processSearchText() );
+        DeepSkyObject *dso = new DeepSkyObject( cedata );
+        if( ! std::isnan( cedata.ra ) && ! std::isnan( cedata.dec ) ) {
+            qDebug() << dso->ra0().toHMSString() << ";" << dso->dec0().toDMSString();
+            selObj = dso;
+        }
+        // ==== END buggy testing code ====
+    }
+    m_targetObject = selObj;
     if ( selObj == 0 ) {
         QString message = i18n( "No object named %1 found.", ui->SearchBox->text() );
         KMessageBox::sorry( 0, message, i18n( "Bad object name" ) );
diff --git a/kstars/dialogs/finddialog.h b/kstars/dialogs/finddialog.h
index 1a3f488..fb38a2b 100644
--- a/kstars/dialogs/finddialog.h
+++ b/kstars/dialogs/finddialog.h
@@ -54,8 +54,12 @@ public:
     /** Destructor */
     virtual ~FindDialog();
 
-    /** @return the currently-selected item from the listbox of named objects */
-    SkyObject* selectedObject() const;
+    /**
+     * @return the target object (need not be the same as currently selected object!)
+     *
+     * @note Avoid using selectedObject()
+     */
+    inline SkyObject *targetObject() { return m_targetObject; }
 
 public slots:
     /**When Text is entered in the QLineEdit, filter the List of objects
@@ -90,6 +94,9 @@ protected:
      */
     void keyPressEvent( QKeyEvent *e );
 
+    /** @return the currently-selected item from the listbox of named objects */
+    SkyObject* selectedObject() const;
+
 private:
 
     /** @short Do some post processing on the search text to interpret what the user meant
@@ -108,6 +115,7 @@ private:
     QTimer* timer;
     bool listFiltered;
     QPushButton *okB;
+    SkyObject *m_targetObject;
 };
 
 #endif
diff --git a/kstars/ekos/scheduler.cpp b/kstars/ekos/scheduler.cpp
index ec087ae..3e957d3 100644
--- a/kstars/ekos/scheduler.cpp
+++ b/kstars/ekos/scheduler.cpp
@@ -258,7 +258,7 @@ void Scheduler::selectObject()
     QPointer<FindDialog> fd = new FindDialog( this );
     if ( fd->exec() == QDialog::Accepted )
     {
-        SkyObject *object = fd->selectedObject();
+        SkyObject *object = fd->targetObject();
         addObject(object);
     }
 
diff --git a/kstars/kstarsactions.cpp b/kstars/kstarsactions.cpp
index d47d20e..c30db0d 100644
--- a/kstars/kstarsactions.cpp
+++ b/kstars/kstarsactions.cpp
@@ -767,7 +767,7 @@ void KStars::slotFind() {
 
     if ( !m_FindDialog ) qWarning() << i18n( "KStars::slotFind() - Not enough memory for dialog" ) ;
     SkyObject *targetObject;
-    if ( m_FindDialog->exec() == QDialog::Accepted && ( targetObject = m_FindDialog->selectedObject() ) ) {
+    if ( m_FindDialog->exec() == QDialog::Accepted && ( targetObject = m_FindDialog->targetObject() ) ) {
         map()->setClickedObject( targetObject );
         map()->setClickedPoint( map()->clickedObject() );
         map()->slotCenter();
diff --git a/kstars/oal/execute.cpp b/kstars/oal/execute.cpp
index fbd1356..ea3058f 100644
--- a/kstars/oal/execute.cpp
+++ b/kstars/oal/execute.cpp
@@ -403,7 +403,7 @@ void Execute::slotShowTargets() {
 void Execute::slotAddObject() {
    QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
    if ( fd->exec() == QDialog::Accepted ) {
-       SkyObject *o = fd->selectedObject();
+       SkyObject *o = fd->targetObject();
        if( o != 0 ) {
            KStarsData::Instance()->observingList()->slotAddObject( o, true );
            init();
diff --git a/kstars/printing/pwizfovsh.cpp b/kstars/printing/pwizfovsh.cpp
index bae2a42..4b810ed 100644
--- a/kstars/printing/pwizfovsh.cpp
+++ b/kstars/printing/pwizfovsh.cpp
@@ -48,7 +48,7 @@ void PWizFovShUI::slotSelectFromList()
     QPointer<FindDialog> findDlg( new FindDialog( this ) );
     if(findDlg->exec() == QDialog::Accepted && findDlg)
     {
-        SkyObject *obj = findDlg->selectedObject();
+        SkyObject *obj = findDlg->targetObject();
         if(obj)
         {
             setBeginObject(obj);
diff --git a/kstars/printing/pwizobjectselection.cpp b/kstars/printing/pwizobjectselection.cpp
index b8a1439..dcf27bf 100644
--- a/kstars/printing/pwizobjectselection.cpp
+++ b/kstars/printing/pwizobjectselection.cpp
@@ -60,7 +60,7 @@ void PWizObjectSelectionUI::slotSelectFromList()
     QPointer<FindDialog> findDlg( new FindDialog( this ) );
     if(findDlg->exec() == QDialog::Accepted && findDlg)
     {
-        SkyObject *obj = findDlg->selectedObject();
+        SkyObject *obj = findDlg->targetObject();
         if(obj)
         {
             setSkyObject(obj);
diff --git a/kstars/skyobjects/deepskyobject.cpp b/kstars/skyobjects/deepskyobject.cpp
index cb9941a..cae5079 100644
--- a/kstars/skyobjects/deepskyobject.cpp
+++ b/kstars/skyobjects/deepskyobject.cpp
@@ -33,6 +33,7 @@
 #include "Options.h"
 #include "skymap.h"
 #include "texturemanager.h"
+#include "catalogentrydata.h"
 
 #include <QDebug>
 #include <KLocalizedString>
@@ -70,6 +71,27 @@ DeepSkyObject::DeepSkyObject( int t, dms r, dms d, float m,
     loadImage();
 }
 
+DeepSkyObject::DeepSkyObject( const CatalogEntryData &data )
+{
+    // FIXME: This assumes that CatalogEntryData coordinates have
+    // J2000.0 as epoch as opposed to the catalog's epoch!!! -- asimha
+    setType( data.type );
+    setRA0( data.ra/15.0 ); // NOTE: CatalogEntryData stores RA in degrees, whereas setRA0() wants it in hours.
+    setDec0( data.dec );
+    setLongName( data.long_name );
+    setName( data.catalog_name + ' ' + QString::number( data.ID ) );
+    MajorAxis = data.major_axis;
+    MinorAxis = data.minor_axis;
+    PositionAngle = data.position_angle;
+    PGC = 0;
+    UGC = 0;
+    setCatalog( data.catalog_name );
+    updateID = updateNumID = 0;
+    customCat = NULL; // <-- FIXME!
+    Flux = data.flux;
+    loadImage();
+}
+
 DeepSkyObject* DeepSkyObject::clone() const
 {
     Q_ASSERT( typeid( this ) == typeid( static_cast<const DeepSkyObject *>( this ) ) ); // Ensure we are not slicing a derived class
diff --git a/kstars/skyobjects/deepskyobject.h b/kstars/skyobjects/deepskyobject.h
index d4004d9..2e4d8f0 100644
--- a/kstars/skyobjects/deepskyobject.h
+++ b/kstars/skyobjects/deepskyobject.h
@@ -28,6 +28,7 @@ class QImage;
 class QString;
 class KSPopupMenu;
 class CatalogComponent;
+class CatalogEntryData;
 
 /**
   *@class DeepSkyObject
@@ -70,6 +71,8 @@ public:
      */
     DeepSkyObject(const DeepSkyObject &o );
 
+    DeepSkyObject( const CatalogEntryData &data );
+
     QString labelString() const;
 
     virtual DeepSkyObject* clone() const;
diff --git a/kstars/tools/altvstime.cpp b/kstars/tools/altvstime.cpp
index df98e3e..d017ec0 100644
--- a/kstars/tools/altvstime.cpp
+++ b/kstars/tools/altvstime.cpp
@@ -336,7 +336,7 @@ void AltVsTime::slotAddSource() {
 void AltVsTime::slotBrowseObject() {
     QPointer<FindDialog> fd = new FindDialog(this);
     if ( fd->exec() == QDialog::Accepted ) {
-        SkyObject *o = fd->selectedObject();
+        SkyObject *o = fd->targetObject();
         processObject( o );
     }
     delete fd;
diff --git a/kstars/tools/conjunctions.cpp b/kstars/tools/conjunctions.cpp
index 882b352..85efa94 100644
--- a/kstars/tools/conjunctions.cpp
+++ b/kstars/tools/conjunctions.cpp
@@ -164,9 +164,9 @@ void ConjunctionsTool::slotFindObject() {
     QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
     if ( fd->exec() == QDialog::Accepted ) {
         delete Object1;
-        if( !fd->selectedObject() )
+        if( !fd->targetObject() )
             return;
-        Object1 = fd->selectedObject()->clone();
+        Object1 = fd->targetObject()->clone();
         if( Object1 )
             Obj1FindButton->setText( Object1->name() );
     }
diff --git a/kstars/tools/modcalcaltaz.cpp b/kstars/tools/modcalcaltaz.cpp
index cdfeefd..7e38337 100644
--- a/kstars/tools/modcalcaltaz.cpp
+++ b/kstars/tools/modcalcaltaz.cpp
@@ -87,7 +87,7 @@ void modCalcAltAz::slotObject()
 {
     FindDialog fd(KStars::Instance());
     if ( fd.exec() == QDialog::Accepted ) {
-        SkyObject *o = fd.selectedObject();
+        SkyObject *o = fd.targetObject();
         RA->showInHours( o->ra() );
         Dec->showInDegrees( o->dec() );
         slotCompute();
diff --git a/kstars/tools/modcalcangdist.cpp b/kstars/tools/modcalcangdist.cpp
index 8dd46ab..497d9e1 100644
--- a/kstars/tools/modcalcangdist.cpp
+++ b/kstars/tools/modcalcangdist.cpp
@@ -96,7 +96,7 @@ void modCalcAngDist::slotValidatePositions(){
 void modCalcAngDist::slotObjectButton() {
     QPointer<FindDialog> fd = new FindDialog( this );
     if ( fd->exec() == QDialog::Accepted ) {
-        SkyObject *o = fd->selectedObject();
+        SkyObject *o = fd->targetObject();
         if ( sender()->objectName() == QString("FirstObjectButton") ) {
             FirstRA->showInHours( o->ra() );
             FirstDec->showInDegrees( o->dec() );
diff --git a/kstars/tools/modcalcapcoord.cpp b/kstars/tools/modcalcapcoord.cpp
index 8be76f9..dae3e0d 100644
--- a/kstars/tools/modcalcapcoord.cpp
+++ b/kstars/tools/modcalcapcoord.cpp
@@ -83,7 +83,7 @@ void modCalcApCoord::slotCompute(){
 void modCalcApCoord::slotObject() {
     QPointer<FindDialog> fd = new FindDialog( this );
     if ( fd->exec() == QDialog::Accepted ) {
-        SkyObject *o = fd->selectedObject();
+        SkyObject *o = fd->targetObject();
         RACat->showInHours( o->ra0() );
         DecCat->showInDegrees( o->dec0() );
         EpochCat->setValue( 2000.0 );
diff --git a/kstars/tools/modcalceclipticcoords.cpp b/kstars/tools/modcalceclipticcoords.cpp
index 8f1aa35..b28542a 100644
--- a/kstars/tools/modcalceclipticcoords.cpp
+++ b/kstars/tools/modcalceclipticcoords.cpp
@@ -65,7 +65,7 @@ void modCalcEclCoords::slotNow() {
 void modCalcEclCoords::slotObject() {
     FindDialog fd(KStars::Instance());
     if ( fd.exec() == QDialog::Accepted ) {
-        SkyObject *o = fd.selectedObject();
+        SkyObject *o = fd.targetObject();
         RA->showInHours( o->ra() );
         Dec->showInDegrees( o->dec() );
         slotCompute();
diff --git a/kstars/tools/modcalcgalcoord.cpp b/kstars/tools/modcalcgalcoord.cpp
index 8427957..2f5e37f 100644
--- a/kstars/tools/modcalcgalcoord.cpp
+++ b/kstars/tools/modcalcgalcoord.cpp
@@ -58,7 +58,7 @@ void modCalcGalCoord::slotObject()
 {
     QPointer<FindDialog> fd = new FindDialog( this );
     if ( fd->exec() == QDialog::Accepted ) {
-        SkyObject *o = fd->selectedObject();
+        SkyObject *o = fd->targetObject();
         RA->showInHours( o->ra() );
         Dec->showInDegrees( o->dec() );
         slotComputeCoords();
diff --git a/kstars/tools/modcalcvlsr.cpp b/kstars/tools/modcalcvlsr.cpp
index 18350a0..98e07a2 100644
--- a/kstars/tools/modcalcvlsr.cpp
+++ b/kstars/tools/modcalcvlsr.cpp
@@ -83,7 +83,7 @@ void modCalcVlsr::slotNow()
 void modCalcVlsr::slotFindObject() {
     QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
     if ( fd->exec() == QDialog::Accepted ) {
-        SkyObject *o = fd->selectedObject();
+        SkyObject *o = fd->targetObject();
         RA->showInHours( o->ra0() );
         Dec->showInDegrees( o->dec0() );
     }
diff --git a/kstars/tools/observinglist.cpp b/kstars/tools/observinglist.cpp
index 787a01c..4b97456 100644
--- a/kstars/tools/observinglist.cpp
+++ b/kstars/tools/observinglist.cpp
@@ -680,7 +680,7 @@ void ObservingList::slotAddToSession() {
 void ObservingList::slotFind() {
    QPointer<FindDialog> fd = new FindDialog( KStars::Instance() );
    if ( fd->exec() == QDialog::Accepted ) {
-       SkyObject *o = fd->selectedObject();
+       SkyObject *o = fd->targetObject();
        if( o != 0 ) {
            slotAddObject( o, sessionView );
        }
diff --git a/kstars/tools/scriptbuilder.cpp b/kstars/tools/scriptbuilder.cpp
index b8fad06..4ed6406 100644
--- a/kstars/tools/scriptbuilder.cpp
+++ b/kstars/tools/scriptbuilder.cpp
@@ -1527,13 +1527,13 @@ void ScriptBuilder::slotFindCity() {
 void ScriptBuilder::slotFindObject() {
     QPointer<FindDialog> fd = new FindDialog( ks );
 
-    if ( fd->exec() == QDialog::Accepted && fd->selectedObject() ) {
+    if ( fd->exec() == QDialog::Accepted && fd->targetObject() ) {
         setUnsavedChanges( true );
 
         if (sender() == argLookToward->FindButton)
-            argLookToward->FocusEdit->setEditText( fd->selectedObject()->name() );
+            argLookToward->FocusEdit->setEditText( fd->targetObject()->name() );
         else
-            argFindObject->NameEdit->setText(fd->selectedObject()->name());
+            argFindObject->NameEdit->setText(fd->targetObject()->name());
     }
     delete fd;
 }


More information about the Kstars-devel mailing list