summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-08-16 06:17:28 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-08-16 06:42:48 (GMT)
commit628cdbea1f34adb63c5bcce33faf261b459688cc (patch)
treeb922e9dda7e7e644c8f30f3bf9b619e27c16e156
parentd2f79ff590fab7cfa6653a8f4d3d735646c4191d (diff)
Add missing files and missing build list line to DSO Resolver branch
-rw-r--r--kstars/CMakeLists.txt1
-rw-r--r--kstars/tools/nameresolver.cpp187
-rw-r--r--kstars/tools/nameresolver.h91
3 files changed, 279 insertions, 0 deletions
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index cd854e6..6dc8cc2 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -196,6 +196,7 @@ set(libkstarstools_SRCS
tools/wutdialog.cpp
tools/flagmanager.cpp
tools/horizonmanager.cpp
+ tools/nameresolver.cpp
#FIXME Port to KF5
#tools/moonphasetool.cpp
diff --git a/kstars/tools/nameresolver.cpp b/kstars/tools/nameresolver.cpp
new file mode 100644
index 0000000..c98e284
--- /dev/null
+++ b/kstars/tools/nameresolver.cpp
@@ -0,0 +1,187 @@
+/***************************************************************************
+ nameresolver.cpp - K Desktop Planetarium
+ -------------------
+ begin : Sun 24 Aug 2014 02:28:09 CDT
+ copyright : (c) 2014 by Akarsh Simha
+ email : akarsh.simha@kdemail.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+
+/* Project Includes */
+#include "nameresolver.h"
+#include "../../datahandlers/catalogentrydata.h"
+
+/* KDE Includes */
+#include <kio/filecopyjob.h>
+
+/* Qt Includes */
+#include <QUrl>
+#include <QTemporaryFile>
+#include <QString>
+#include <QXmlStreamReader>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QNetworkAccessManager>
+#include <QDebug>
+#include <QEventLoop>
+
+class CatalogEntryData NameResolver::resolveName( const QString &name ) {
+ class CatalogEntryData data;
+
+ data.long_name = name;
+
+ if( !NameResolverInternals::sesameResolver( data, name ) ) {
+ qDebug() << "Error: sesameResolver failed. Could not resolve name on CDS Sesame!";
+ return data; // default data structure with no information
+ }
+ // More to be done here if the resolved name is SIMBAD
+ return data;
+
+}
+
+bool NameResolver::NameResolverInternals::sesameResolver( class CatalogEntryData &data, const QString &name ) {
+
+ QUrl resolverUrl = QUrl( QString( "http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame/-oxpFI/SNV?%1" ).arg( name ) );
+
+ qDebug() << "Attempting to resolve object " << name << "using CDS Sesame.";
+ QNetworkAccessManager manager;
+ QNetworkReply *response = manager.get( QNetworkRequest( resolverUrl ) );
+
+ // Wait synchronously
+ QEventLoop event;
+ QObject::connect( response, SIGNAL( finished() ), &event, SLOT( quit() ) );
+ event.exec();
+
+ if (response->error() != QNetworkReply::NoError) {
+ qWarning() << "Error trying to get XML response from CDS Sesame server: " << response->errorString();
+ return false;
+ }
+
+ QXmlStreamReader xml( response->readAll() );
+ if( xml.atEnd() ) {
+ // file is empty
+ qDebug() << "Empty result instead of expected XML from CDS Sesame! Maybe bad internet connection?";
+ return false;
+ }
+
+ while( !xml.atEnd() && !xml.hasError() ) {
+ QXmlStreamReader::TokenType token = xml.readNext();
+
+ if( xml.isStartDocument() )
+ continue;
+
+ if( token == QXmlStreamReader::StartElement ) {
+ qDebug() << "Parsing token with name " << xml.name();
+
+ if( xml.name() == "Resolver" ) {
+ // This is the section we want
+ char resolver;
+ QXmlStreamAttributes attributes = xml.attributes();
+ if( attributes.hasAttribute( "name" ) )
+ resolver = attributes.value("name").at( 0 ).toLatin1(); // Expected to be S (Simbad), V (VizieR), or N (NED)
+ else {
+ resolver = 0; // NUL character for unknown resolver
+ qWarning() << "Warning: Unknown resolver " << attributes.value( "name " ) << " while reading output from CDS Sesame";
+ }
+ qDebug() << "Resolved by " << attributes.value( "name" ) << "!";
+
+ // Start reading the data to pick out the relevant ones
+ while( xml.readNextStartElement() ) {
+ if( xml.name() == "otype" ) {
+ const QString typeString = xml.readElementText();
+ data.type = interpretObjectType( typeString );
+ }
+ else if( xml.name() == "jradeg" ) {
+ data.ra = xml.readElementText().toDouble();
+ }
+ else if( xml.name() == "jdedeg" ) {
+ data.dec = xml.readElementText().toDouble();
+ }
+ else if( xml.name() == "mag" ) {
+ attributes = xml.attributes();
+ char band;
+ if( attributes.hasAttribute( "band" ) ) {
+ attributes.value("band").at(0).toLatin1();
+ }
+ else {
+ qWarning() << "Warning: Magnitude of unknown band found while reading output from CDS Sesame";
+ band = 0;
+ }
+
+ if( band == 'V' ) {
+ data.magnitude = xml.readElementText().toFloat();
+ }
+ else if( band == 'B' ) {
+ data.flux = xml.readElementText().toFloat(); // FIXME: This is bad
+ }
+ // Don't know what to do with other magnitudes, until we have a magnitude hash
+ }
+ else
+ xml.skipCurrentElement();
+ // TODO: Parse aliases for common names
+ }
+ break;
+
+ }
+ else
+ continue;
+ }
+ }
+ if( xml.hasError() ) {
+ qDebug() << "Error parsing XML from CDS Sesame: " << xml.errorString() << " on line " << xml.lineNumber() << " @ col = " << xml.columnNumber();
+ return false;
+ }
+ qDebug() << "Resolved " << name << " successfully!";
+ qDebug() << "Object type: " << SkyObject::typeName( data.type ) << "; Coordinates: " << data.ra << ";" << data.dec;
+ return true;
+}
+
+// bool NameResolver::NameResolverInternals::getDataFromSimbad( class CatalogEntryData &data ) {
+// // TODO: Implement
+// // QUrl( QString( "http://simbad.u-strasbg.fr/simbad/sim-script?script=output%20console=off%20script=off%0Aformat%20object%20%22%25DIM%22%0A" ) + data.name );
+// }
+
+SkyObject::TYPE NameResolver::NameResolverInternals::interpretObjectType( const QString &typeString ) {
+
+ // FIXME: Due to the quirks of Sesame (SIMBAD vs NED etc), it
+ // might be very difficult to discern the type in all cases. The
+ // best way TODO things might be to first run the query with NED,
+ // and if it is extragalactic, then trust NED and
+ // accept. Otherwise, or if NED did not return a result, re-run
+ // the query on SIMBAD and VizieR and use that result, if any.
+
+ // Highest likelihood is a galaxy of some form
+ if( typeString == "G" || typeString == "LIN" || typeString == "AGN" || typeString == "GiG" || typeString == "H2G" ) {
+ // this is a galaxy
+ return SkyObject::GALAXY;
+ }
+ // Next possibility is galaxy cluster
+ if( typeString == "GClstr" || typeString == "GGroup" || typeString == "GPair" || typeString == "ClG" || typeString == "CGG" ) { // NOTE (FIXME?): Compact groups and pairs of galaxies ar treated like galaxy clusters
+ return SkyObject::GALAXY_CLUSTER;
+ }
+ if( typeString == "*Cl" || typeString == "Cl*" || typeString == "OpC" )
+ return SkyObject::OPEN_CLUSTER; // FIXME: NED doesn't distinguish between globular clusters and open clusters!!
+ if( typeString == "GlC" )
+ return SkyObject::GLOBULAR_CLUSTER;
+ if( typeString == "Neb" || typeString == "HII" )
+ return SkyObject::GASEOUS_NEBULA;
+ if( typeString == "SNR" ) // FIXME: Simbad returns "ISM" for Veil Nebula (Interstellar Medium??)
+ return SkyObject::SUPERNOVA_REMNANT;
+ if( typeString == "PN" )
+ return SkyObject::PLANETARY_NEBULA;
+ if( typeString == "*" )
+ return SkyObject::STAR;
+
+ return SkyObject::TYPE_UNKNOWN;
+ // FIXME: complete this method
+
+}
diff --git a/kstars/tools/nameresolver.h b/kstars/tools/nameresolver.h
new file mode 100644
index 0000000..ed7df8a
--- /dev/null
+++ b/kstars/tools/nameresolver.h
@@ -0,0 +1,91 @@
+/***************************************************************************
+ nameresolver.h - K Desktop Planetarium
+ -------------------
+ begin : Sat 23 Aug 2014 23:38:42 CDT
+ copyright : (c) 2014 by Akarsh Simha
+ email : akarsh.simha@kdemail.net
+***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+
+
+#ifndef NAMERESOLVER_H
+#define NAMERESOLVER_H
+
+/* #include "../../datahandlers/catalogentrydata.h" */
+#include "skyobject.h"
+
+// Forward declarations
+class QString;
+class CatalogEntryData;
+
+/**
+ * @namespace NameResolver
+ *
+ * @short Uses name resolver services to get coordinates and
+ * information about deep-sky objects, given their names
+ *
+ * This class uses the CDS Sesame name resolver (and potentially other
+ * resolvers) to resolve the names of deep-sky objects, and obtain
+ * coordinates, fluxes, alternate designations, and possibly other
+ * data.
+ *
+ * @author Akarsh Simha <akarsh.simha@kdemail.net>
+ */
+
+namespace NameResolver {
+
+ /**
+ * @short Resolve the name of the given DSO and extract data from
+ * various sources
+ */
+ class CatalogEntryData resolveName( const QString &name );
+
+ namespace NameResolverInternals {
+
+ /**
+ * @short Resolve the name and obtain basic data using CDS Sesame service
+ *
+ * @param data the structure to fill with the obtained data
+ * @param name the name (identifier) to resolve
+ * @return Success value
+ */
+ bool sesameResolver( class CatalogEntryData &data, const QString &name );
+
+ /**
+ * @short Retrieve additional data from SIMBAD
+ *
+ * If the object was resolved by SIMBAD, obtain additional data
+ * that is not available through CDS Sesame, such as the major and
+ * minor axes and position angle of the object.
+ *
+ * @param data the structure containing data from Sesame, to be
+ * filled with additional data
+ * @return Success value
+ */
+ // bool getDataFromSimbad( class CatalogEntryData &data );
+
+ /**
+ * @short Interprets object type returned by Sesame
+ *
+ * This method reads the object type string returned by Sesame
+ * / other resolvers and attempts to convert it into a
+ * SkyObject type.
+ *
+ * @return a SkyObject::TYPE.
+ */
+ SkyObject::TYPE interpretObjectType( const QString &typeString );
+
+ }
+
+};
+
+#endif