8#include "nameresolver.h"
9#include "catalogobject.h"
13#include <kio/filecopyjob.h>
15#include "kstarslite.h"
20#include <QTemporaryFile>
22#include <QXmlStreamReader>
23#include <QNetworkRequest>
24#include <QNetworkReply>
25#include <QNetworkAccessManager>
28#include <kstars_debug.h>
32 const auto &found_sesame{ NameResolverInternals::sesameResolver(name) };
33 if (!found_sesame.first)
36 xi18n(
"Error: sesameResolver failed. Could not resolve name on CDS Sesame.");
37 qCDebug(KSTARS) << msg;
47std::pair<bool, CatalogObject>
48NameResolver::NameResolverInternals::sesameResolver(
const QString &name)
51 QString(
"http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame/-oxpFI/SNV?%1").arg(name));
53 QString msg =
xi18n(
"Attempting to resolve object %1 using CDS Sesame.", name);
54 qCDebug(KSTARS) << msg;
71 msg =
xi18n(
"Error trying to get XML response from CDS Sesame server: %1",
86 msg =
xi18n(
"Empty result instead of expected XML from CDS Sesame. Maybe bad "
87 "Internet connection?");
88 qCDebug(KSTARS) << msg;
101 while (!xml.atEnd() && !xml.hasError())
105 if (xml.isStartDocument())
110 qCDebug(KSTARS) <<
"Parsing token with name " << xml.name();
112 if (xml.name().toString() ==
"Resolver")
120 attributes.
value(
"name")
126 qWarning() <<
"Warning: Unknown resolver "
127 << attributes.
value(
"name ")
128 <<
" while reading output from CDS Sesame";
132 <<
"Resolved by " << resolver << attributes.
value(
"name") <<
"!";
135 while (xml.readNextStartElement())
137 if (xml.name().toString() ==
"otype")
139 const QString typeString = xml.readElementText();
140 data.setType(interpretObjectType(typeString));
142 else if (xml.name().toString() ==
"jradeg")
144 data.setRA0(
dms{ xml.readElementText().toDouble() });
146 else if (xml.name().toString() ==
"jdedeg")
148 data.setDec0(
dms{ xml.readElementText().toDouble() });
150 else if (xml.name().toString() ==
"mag")
152 attributes = xml.attributes();
160 qWarning() <<
"Warning: Magnitude of unknown band found "
161 "while reading output from CDS Sesame";
167 if (xml.isCharacters())
169 qCDebug(KSTARS) <<
"characters: " << xml.tokenString();
170 mag = xml.tokenString().toFloat();
172 else if (xml.isStartElement())
174 while (xml.name().toString() !=
"v")
176 qCDebug(KSTARS) <<
"element: " << xml.name();
177 xml.readNextStartElement();
179 mag = xml.readElementText().toFloat();
181 <<
"Got " << xml.tokenString() <<
" mag = " << mag;
182 while (!xml.atEnd() && xml.readNext() && xml.name().toString() !=
"mag")
187 <<
"Failed to parse Xml token in magnitude element: "
188 << xml.tokenString();
194 else if (band ==
'B')
197 if (std::isnan(data.mag()))
202 else if (xml.name().toString() ==
"oname")
204 QString contents = xml.readElementText();
205 data.setCatalogIdentifier(contents);
208 xml.skipCurrentElement();
219 msg =
xi18n(
"Error parsing XML from CDS Sesame: %1 on line %2 @ col = %3",
220 xml.errorString(), xml.lineNumber(), xml.columnNumber());
221 qCDebug(KSTARS) << msg;
226 return {
false, {} };
230 return {
false, {} };
232 msg =
xi18n(
"Resolved %1 successfully.", name);
233 qCDebug(KSTARS) << msg;
239 <<
"; Coordinates: " << data.ra0().Degrees() <<
";"
240 << data.dec().Degrees();
241 return {
true, data };
249SkyObject::TYPE NameResolver::NameResolverInternals::interpretObjectType(
const QString &typeString,
bool caseSensitive)
288 galaxyGroupTypes <<
"GClstr"
298 openClusterTypes <<
"*Cl"
305 radioSourceTypes <<
"Rad"
315 return SkyObject::GALAXY;
317 if (galaxyGroupTypes.
contains(s, cs))
318 return SkyObject::GALAXY_CLUSTER;
320 if (openClusterTypes.
contains(s, cs))
321 return SkyObject::OPEN_CLUSTER;
325 if (check(
"GlC") || check(
"GlCl"))
326 return SkyObject::GLOBULAR_CLUSTER;
327 if (check(
"Neb") || check(
"HII") || check(
"HH"))
328 return SkyObject::GASEOUS_NEBULA;
330 return SkyObject::SUPERNOVA_REMNANT;
331 if (check(
"PN") || check(
"PNeb") || check(
"PNe") || check(
"pA*"))
332 return SkyObject::PLANETARY_NEBULA;
333 if (typeString ==
"*")
334 return SkyObject::CATALOG_STAR;
336 return SkyObject::QUASAR;
337 if (check(
"DN") || check(
"DNe") || check(
"DNeb") || check(
"glb"))
338 return SkyObject::DARK_NEBULA;
339 if (radioSourceTypes.
contains(s, cs))
340 return SkyObject::RADIO_SOURCE;
341 if (typeString ==
"**")
342 return SkyObject::MULT_STAR;
343 if (typeString.
contains(
'*') && !check(
"C?*"))
344 return SkyObject::CATALOG_STAR;
346 return SkyObject::TYPE_UNKNOWN;
A simple container object to hold the minimum information for a Deep Sky Object to be drawn on the sk...
static KStarsLite * Instance()
void notificationMessage(QString msg)
Once this signal is emitted, notification with text msg will appear on the screen.
TYPE
The type classification of the SkyObject.
An angle, stored as degrees, but expressible in many ways.
QString xi18n(const char *text, const TYPE &arg...)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QString name(StandardAction id)
std::pair< bool, CatalogObject > resolveName(const QString &name)
Resolve the name of the given DSO and extract data from various sources.
char toLatin1() const const
QString errorString() const const
QNetworkReply * get(const QNetworkRequest &request)
NetworkError error() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
QChar at(qsizetype n) const const
bool hasAttribute(QAnyStringView namespaceUri, QAnyStringView name) const const
QStringView value(QAnyStringView namespaceUri, QAnyStringView name) const const