2 #include "FeatureNomenclature.h" 10 #include <QNetworkAccessManager> 11 #include <QNetworkRequest> 12 #include <QNetworkReply> 40 QUrl(
"https://planetarynames.wr.usgs.gov/nomenclature/SearchResults"));
42 "Mozilla/5.0 (X11; Linux i686; rv:6.0) " 43 "Gecko/20100101 Firefox/6.0");
44 m_request->setHeader(QNetworkRequest::ContentTypeHeader,
45 "application/x-www-form-urlencoded");
106 if (!range.isEmpty()) {
107 startLon = range[0].first;
108 endLon = range[0].second;
111 if (range.size() > 1) {
116 runQuery(target, startLat, startLon, endLat, endLon);
117 runQuery(target, startLat, startLon2, endLat, endLon2);
122 runQuery(target, startLat, startLon, endLat, endLon);
199 bool greaterThan =
false;
201 greaterThan = (lhsDiameter > rhsDiameter);
204 greaterThan = lhsDiameter.
isValid();
224 m_xmlRepresenation = NULL;
225 m_xmlRepresenation =
new QDomElement(searchResultFeature);
226 m_approvalStatus = status;
236 m_xmlRepresenation = NULL;
247 delete m_xmlRepresenation;
248 m_xmlRepresenation = NULL;
262 QGridLayout *layout =
new QGridLayout;
263 widget->setLayout(layout);
267 QLabel *titleLabel =
new QLabel(
"<h2>Feature Details</h2>");
268 layout->addWidget(titleLabel, row, 0, 1, 2);
277 displayValue.first =
"Feature Name:";
279 displayValues.append(displayValue);
285 displayValue.first =
"Feature ID:";
287 displayValues.append(displayValue);
289 displayValue.first =
"Target:";
291 displayValues.append(displayValue);
293 displayValue.first =
"System:";
295 displayValues.append(displayValue);
297 displayValue.first =
"Control Network:";
299 displayValues.append(displayValue);
301 displayValue.first =
"Diameter:";
303 displayValues.append(displayValue);
305 displayValue.first =
"Originating Continent:";
306 displayValue.second =
308 displayValues.append(displayValue);
310 displayValue.first =
"Originating Ethnicity:";
311 displayValue.second =
313 displayValues.append(displayValue);
315 displayValue.first =
"Feature Type:";
316 displayValue.second =
318 displayValues.append(displayValue);
320 displayValue.first =
"Center Latitude:";
321 displayValue.second =
323 displayValues.append(displayValue);
325 displayValue.first =
"Center Longitude:";
326 displayValue.second =
328 displayValues.append(displayValue);
330 displayValue.first =
"Northern Latitude:";
331 displayValue.second =
333 displayValues.append(displayValue);
335 displayValue.first =
"Southern Latitude:";
336 displayValue.second =
338 displayValues.append(displayValue);
340 displayValue.first =
"Eastern Longitude:";
341 displayValue.second =
343 displayValues.append(displayValue);
345 displayValue.first =
"Western Longitude:";
346 displayValue.second =
348 displayValues.append(displayValue);
350 displayValue.first =
"Approval Date:";
351 displayValue.second =
353 displayValues.append(displayValue);
355 displayValue.first =
"Approval Status:";
356 displayValue.second =
358 displayValues.append(displayValue);
360 displayValue.first =
"Last Updated:";
361 displayValue.second =
363 displayValues.append(displayValue);
365 displayValue.first =
"Reference:";
366 displayValue.second =
368 displayValues.append(displayValue);
370 displayValue.first =
"Origin:";
371 displayValue.second =
373 displayValues.append(displayValue);
375 displayValue.first =
"URL:";
376 displayValue.second =
378 displayValues.append(displayValue);
380 for (
int i = 0; i < displayValues.count(); i++) {
381 QLabel *titleLabel =
new QLabel(displayValues[i].first);
382 QLabel *valueLabel =
new QLabel( (this->*(displayValues[i].second))() );
383 valueLabel->setOpenExternalLinks(
true);
384 valueLabel->setWordWrap(
true);
386 if (valueLabel->text() !=
"") {
387 layout->addWidget(titleLabel, row, 0);
388 layout->addWidget(valueLabel, row, 1);
406 return getTagText(
"id");
414 return getTagText(
"name");
422 return getTagText(
"cleanName");
432 QString targetStr = target();
435 if (targetStr.toUpper() ==
"MOON")
437 else if (targetStr.toUpper() ==
"MARS")
439 else if (targetStr.toUpper() ==
"MERCURY")
440 cnet =
"Preliminary MESSENGER";
450 QString nameString = name();
451 QString cleanNameString = cleanName();
453 QString displayNameString = nameString;
455 if (nameString != cleanNameString)
456 displayNameString = nameString +
" (" + cleanNameString +
")";
458 return displayNameString;
466 return getTagText(
"target");
474 return getTagText(
"system");
499 return diameter().toString();
523 return centerLatitude().toString();
548 return centerLongitude().toString();
573 return northernLatitude().toString();
598 return southernLatitude().toString();
624 return easternLongitude().toString();
650 return westernLongitude().toString();
659 return getTagText(
"continent");
667 return getTagText(
"ethnicity");
675 return getTagText(
"approvalstatus");
683 return getTagText(
"approvaldate");
691 return getTagText(
"featuretype");
699 return getTagText(
"reference");
707 return getTagText(
"origin");
715 return getTagText(
"lastUpdated");
723 return QUrl(
"http://planetarynames.wr.usgs.gov/Feature/" +
id());
731 return "<a href='" + referenceUrl().toString() +
"'>" +
732 referenceUrl().toString() +
741 return m_approvalStatus;
782 if (m_xmlRepresenation) {
784 m_xmlRepresenation->elementsByTagName(tagName);
787 text = nodes.at(0).toElement().text().trimmed();
802 if (reply->error() == QNetworkReply::NoError) {
808 QDomDocument xmlResultDocument;
809 if (xmlResultDocument.setContent(reply->readAll(),
810 &errorMsg, &errorLine, &errorCol)) {
811 for (QDomNode node = xmlResultDocument.firstChild();
813 node = node.nextSibling()) {
814 QDomElement element = node.toElement();
815 if (element.tagName() ==
"searchresults") {
820 else if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 301) {
821 IString msg =
"The URL has been permanently moved to " +
822 reply->attribute(QNetworkRequest::RedirectionTargetAttribute)
827 QMessageBox::warning(NULL,
"Failed to read nomenclature database result",
828 "An error occurred when parsing the data sent back " 829 "from the nomenclature database. " 830 "The XML result was invalid. The parse is [" +
831 errorMsg +
"] on line [" +
832 QString::number(errorLine) +
"], column [" +
833 QString::number(errorCol) +
"]");
837 QMessageBox::warning(NULL,
"Failed to query nomenclature database",
838 "An error occurred when querying the nomenclature " 839 "database for features that intersect the queried " 840 "ground range. Please make sure you have an active " 841 "internet connection. The error returned was [" +
842 reply->errorString() +
"]");
845 reply->deleteLater();
861 ASSERT(xmlSearchResults.tagName() ==
"searchresults");
866 for (QDomNode node = xmlSearchResults.firstChild();
868 node = node.nextSibling()) {
869 QDomElement element = node.toElement();
870 QString approvalID = element.childNodes().item(15).toElement().attribute(
"id");
872 if (element.tagName() ==
"feature") {
874 if(approvalID ==
"5") {
877 else if(approvalID ==
"6") {
880 else if(approvalID ==
"7") {
914 formQuery.addQueryItem(
"additionalInfoColumn",
"true");
915 formQuery.addQueryItem(
"approvalDateColumn",
"true");
916 formQuery.addQueryItem(
"approvalStatusColumn",
"true");
917 formQuery.addQueryItem(
"centerLatLonColumn",
"true");
918 formQuery.addQueryItem(
"cleanFeatureNameColumn",
"true");
919 formQuery.addQueryItem(
"contEthColumn",
"true");
920 formQuery.addQueryItem(
"coordSystemColumn",
"true");
921 formQuery.addQueryItem(
"diameterColumn",
"true");
922 formQuery.addQueryItem(
"featureIDColumn",
"true");
923 formQuery.addQueryItem(
"featureNameColumn",
"true");
924 formQuery.addQueryItem(
"featureTypeCodeColumn",
"true");
925 formQuery.addQueryItem(
"featureTypeColumn",
"true");
926 formQuery.addQueryItem(
"lastUpdatedColumn",
"true");
927 formQuery.addQueryItem(
"latLonColumn",
"true");
928 formQuery.addQueryItem(
"originColumn",
"true");
929 formQuery.addQueryItem(
"quadColumn",
"true");
930 formQuery.addQueryItem(
"referenceColumn",
"true");
931 formQuery.addQueryItem(
"targetColumn",
"true");
934 formQuery.addQueryItem(
"is_0_360",
"true");
935 formQuery.addQueryItem(
"is_planetographic",
"false");
936 formQuery.addQueryItem(
"is_positive_east",
"true");
939 formQuery.addQueryItem(
"displayType",
"XML");
940 formQuery.addQueryItem(
"sort_asc",
"true");
941 formQuery.addQueryItem(
"sort_column",
"name");
944 formQuery.addQueryItem(
"approvalStatus",
"");
945 formQuery.addQueryItem(
"beginDate",
"");
946 formQuery.addQueryItem(
"continent",
"");
947 formQuery.addQueryItem(
"endDate",
"");
948 formQuery.addQueryItem(
"ethnicity",
"");
949 formQuery.addQueryItem(
"feature",
"");
950 formQuery.addQueryItem(
"featureType",
"");
951 formQuery.addQueryItem(
"minFeatureDiameter",
"");
952 formQuery.addQueryItem(
"maxFeatureDiameter",
"");
953 formQuery.addQueryItem(
"reference",
"");
954 formQuery.addQueryItem(
"system",
"");
956 formQuery.addQueryItem(
"target", target.toUpper());
957 formQuery.addQueryItem(
"easternLongitude",
958 QString::number(endLon.
degrees()));
959 formQuery.addQueryItem(
"westernLongitude",
960 QString::number(startLon.
degrees()));
961 formQuery.addQueryItem(
"northernLatitude",
962 QString::number(endLat.
degrees()));
963 formQuery.addQueryItem(
"southernLatitude",
964 QString::number(startLat.
degrees()));
QString westernLongitudeString() const
Longitude easternLongitude() const
When this status is assigned to a feature, there will be no status displayed and the feature will not...
void queryFeatures(QString target, Latitude startLat, Longitude startLon, Latitude endLat, Longitude endLon)
Makes sure the longitudinal ranges are correct.
QNetworkRequest * m_request
Network request sent.
QString referenceUrlString() const
void readSearchResults(QDomElement)
This is a helper method for requestFinished.
When this status is assigned to a feature, the displayed status will be "Dropped, disallowed" and the...
QString originatingEthnicity() const
IAUStatus m_statusApproval
The approval status of the feature from the database.
QString lastUpdated() const
FeatureNomenclature()
Instantiate a feature nomenclature.
QString centerLatitudeString() const
QString southernLatitudeString() const
Feature nomenclature database querier.
IAUStatus m_approvalStatus
The approval status of the feature.
QList< Feature > features() const
This gives you the features found in all of the queries so far.
QString easternLongitudeString() const
When this status is assigned to a feature, the displayed status will be "Adopted by the IAU" and the ...
void swap(Feature &other)
Swap the member data of this feature with another feature.
QString referenceString() const
This class is designed to encapsulate the concept of a Latitude.
The distance is being specified in kilometers.
~FeatureNomenclature()
Frees allocated memory.
Feature & operator=(const Feature &rhs)
Assign the values of this feature from the values of rhs.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
double toDouble(const QString &string)
Global function to convert from a string to a double.
This error is for when a programmer made an API call that was illegal.
Feature()
Construct a feature with no data.
Distance measurement, usually in meters.
QString northernLatitudeString() const
QList< Feature > * m_features
These are the features identified by the nomenclature database.
Longitude centerLongitude() const
double degrees() const
Get the angle in units of Degrees.
QString approvalDate() const
QString centerLongitudeString() const
QNetworkAccessManager * m_networkMgr
Network manager does request.
Latitude centerLatitude() const
Latitude southernLatitude() const
This class is designed to encapsulate the concept of a Longitude.
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
bool m_lastQuery
True if all queries have finished.
QString diameterString() const
QString getTagText(QString tagName) const
Get the string value of an element of the XML.
When this status is assigned to a feature, the displayed status will be "Never approved by the IAU" a...
#define _FILEINFO_
Macro for the filename and line number.
QString controlNet() const
QString displayName() const
static QList< QPair< Longitude, Longitude > > to360Range(Longitude startLon, Longitude endLon)
Calculates where the longitude range is in 0-360.
void runQuery(QString target, Latitude startLat, Longitude startLon, Latitude endLat, Longitude endLon)
Query the nomenclature database for features inside the given range on the target.
bool isValid() const
Test if this distance has been initialized or not.
QString approvalStatus() const
QString cleanName() const
Latitude northernLatitude() const
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
QString featureType() const
void swap(FeatureNomenclature &other)
Swap the instances *this and other.
QWidget * toWidget() const
This converts the data in this feature to a widget.
QString originatingContinent() const
QUrl referenceUrl() const
QDomElement * m_xmlRepresenation
This is the XML returned by the nomenclature DB.
~Feature()
Clean up allocated memory by this feature.
Adds specific functionality to C++ strings.
Namespace for ISIS/Bullet specific routines.
void requestFinished(QNetworkReply *)
This is called when a query is done.
static bool featureDiameterGreaterThan(const FeatureNomenclature::Feature &lhs, const FeatureNomenclature::Feature &rhs)
Compare the diameter of two features.
Longitude westernLongitude() const
void featuresIdentified(FeatureNomenclature *)
This is emitted when a query is completed.
Distance diameter() const
bool hasResult() const
Test if any understandable results have been received from the nomenclature database.
FeatureNomenclature & operator=(const FeatureNomenclature &other)
This takes on the data from rhs.
A named feature on a target.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
IAUStatus
Enumeration of approval statuses.