diff --git a/images/earth.html b/images/earth.html index b1379fe7380f909a73305c2b46a4775d6e4f0509..052dd957a441a2a39c28e50cf30816a4a9e0b4fb 100644 --- a/images/earth.html +++ b/images/earth.html @@ -53,6 +53,8 @@ var trails = []; var trailPlacemarks = []; var trailsVisible = []; var trailColors = []; +var waypoints = []; +//var waypointLines = []; //var trailPlacemarks[id]; var lineStyle; @@ -116,6 +118,60 @@ function setGCSHome(lat, lon, alt) } } +function updateWaypointListLength(id, len) +{ + // Delete any non-needed waypoints + if (waypoints.length > len) + { + for (var i=len; i index) + { + // Waypoint exists + // Set the placemark's location. + var location = ge.createPoint(''); + location.setLatitude(lat); + location.setLongitude(lon); + location.setAltitude(alt); + waypoints[index].setGeometry(location); + } + else + { + // Waypoint does not exist yet + var placemark = ge.createPlacemark(''); + var icon = ge.createIcon(''); + var numberstring = index; + if (index < 10) numberstring = '0' + numberstring + icon.setHref('http://google-maps-icons.googlecode.com/files/red' + numberstring +'.png'); + var style = ge.createStyle(''); + style.getIconStyle().setIcon(icon); + //style.getIconStyle().setScale(0.5); + placemark.setStyleSelector(style); + + // Set the placemark's location. + var location = ge.createPoint(''); + location.setLatitude(lat); + location.setLongitude(lon); + location.setAltitude(alt); + placemark.setGeometry(location); + + // Add the placemark to Earth. + ge.getFeatures().appendChild(placemark); + waypoints[index] = placemark; + } + // Add connecting line + +} + function createAircraft(id, type, color) { planePlacemark = ge.createPlacemark(''); diff --git a/src/ui/map3D/QGCGoogleEarthView.cc b/src/ui/map3D/QGCGoogleEarthView.cc index 52cbb30f0b825769eb144c9eeaba930756e57b27..ca397c99d22803e28cdafb5b26a16cdf1b9ec963 100644 --- a/src/ui/map3D/QGCGoogleEarthView.cc +++ b/src/ui/map3D/QGCGoogleEarthView.cc @@ -23,6 +23,7 @@ #include "QGC.h" #include "ui_QGCGoogleEarthView.h" #include "QGCGoogleEarthView.h" +#include "UASWaypointManager.h" #define QGCGOOGLEEARTHVIEWSETTINGS QString("GoogleEarthViewSettings_") @@ -82,6 +83,7 @@ QGCGoogleEarthView::QGCGoogleEarthView(QWidget *parent) : #endif connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateState())); + connect(ui->resetButton, SIGNAL(clicked()), this, SLOT(reloadHTML())); } QGCGoogleEarthView::~QGCGoogleEarthView() @@ -107,6 +109,15 @@ void QGCGoogleEarthView::setViewRangeScaledInt(int range) setViewRange(range/100.0f); } +void QGCGoogleEarthView::reloadHTML() +{ + hide(); + webViewInitialized = false; + jScriptInitialized = false; + gEarthInitialized = false; + show(); +} + /** * @param range in meters (SI-units) */ @@ -129,9 +140,14 @@ void QGCGoogleEarthView::addUAS(UASInterface* uas) if (trailEnabled) javaScript(QString("showTrail(%1);").arg(uas->getUASID())); - //javaScript(QString("createAircraft(%1, %2, %3);").arg(uas->getUASID()).arg(uas->getSystemType()).arg("0")); // Automatically receive further position updates connect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateGlobalPosition(UASInterface*,double,double,double,quint64))); + // Receive waypoint updates + // Connect the waypoint manager / data storage to the UI + connect(uas->getWaypointManager(), SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int))); + connect(uas->getWaypointManager(), SIGNAL(waypointChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*))); + //connect(this, SIGNAL(waypointCreated(Waypoint*)), uas->getWaypointManager(), SLOT(addWaypoint(Waypoint*))); + // TODO Update waypoint list on UI changes here } void QGCGoogleEarthView::setActiveUAS(UASInterface* uas) @@ -143,6 +159,70 @@ void QGCGoogleEarthView::setActiveUAS(UASInterface* uas) } } +/** + * This function is called if a a single waypoint is updated and + * also if the whole list changes. + */ +void QGCGoogleEarthView::updateWaypoint(int uas, Waypoint* wp) +{ + // Only accept waypoints in global coordinate frame + if (wp->getFrame() == MAV_FRAME_GLOBAL) + { + // We're good, this is a global waypoint + + // Get the index of this waypoint + // note the call to getGlobalFrameIndexOf() + // as we're only handling global waypoints + int wpindex = UASManager::instance()->getUASForId(uas)->getWaypointManager()->getGlobalFrameIndexOf(wp); + // If not found, return (this should never happen, but helps safety) + if (wpindex == -1) + { + return; + } + else + { + javaScript(QString("updateWaypoint(%1,%2,%3,%4,%5,%6);").arg(uas).arg(wpindex).arg(wp->getY()).arg(wp->getX()).arg(wp->getZ()).arg(wp->getAction())); + } + + } + else + { + // Check if the index of this waypoint is larger than the global + // waypoint list. This implies that the coordinate frame of this + // waypoint was changed and the list containing only global + // waypoints was shortened. Thus update the whole list + // if (waypointPath->points().count() > UASManager::instance()->getUASForId(uas)->getWaypointManager()->getGlobalFrameCount()) + // { + // updateWaypointList(uas); + // } + } +} + +/** + * Update the whole list of waypoints. This is e.g. necessary if the list order changed. + * The UAS manager will emit the appropriate signal whenever updating the list + * is necessary. + */ +void QGCGoogleEarthView::updateWaypointList(int uas) +{ + // Get already existing waypoints + UASInterface* uasInstance = UASManager::instance()->getUASForId(uas); + if (uasInstance) + { + // Get all waypoints, including non-global waypoints + QVector wpList = uasInstance->getWaypointManager()->getGlobalFrameWaypointList(); + + // Trim internal list to number of global waypoints in the waypoint manager list + javaScript(QString("updateWaypointListLength(%1,%2);").arg(uas).arg(wpList.count())); + + // Load all existing waypoints into map view + foreach (Waypoint* wp, wpList) + { + updateWaypoint(uas, wp); + } + } +} + void QGCGoogleEarthView::updateGlobalPosition(UASInterface* uas, double lon, double lat, double alt, quint64 usec) { Q_UNUSED(usec); diff --git a/src/ui/map3D/QGCGoogleEarthView.h b/src/ui/map3D/QGCGoogleEarthView.h index 80131dc7ed1079d3a23d133a797a2a4169c0450f..b770756d1e53d56056ce10a5fda154fffe07ce37 100644 --- a/src/ui/map3D/QGCGoogleEarthView.h +++ b/src/ui/map3D/QGCGoogleEarthView.h @@ -58,13 +58,11 @@ protected: #endif namespace Ui { -#ifdef _MSC_VER - class QGCGoogleEarthView; -#else class QGCGoogleEarthView; -#endif } +class Waypoint; + class QGCGoogleEarthView : public QWidget { Q_OBJECT @@ -82,6 +80,10 @@ public slots: void setActiveUAS(UASInterface* uas); /** @brief Update the global position */ void updateGlobalPosition(UASInterface* uas, double lon, double lat, double alt, quint64 usec); + /** @brief Update a single waypoint */ + void updateWaypoint(int uas, Waypoint* wp); + /** @brief Update the waypoint list */ + void updateWaypointList(int uas); /** @brief Show the vehicle trail */ void showTrail(bool state); /** @brief Show the waypoints */ @@ -96,6 +98,8 @@ public slots: void setViewRange(float range); /** @brief Set camera view range to aircraft in centimeters */ void setViewRangeScaledInt(int range); + /** @brief Reset Google Earth View */ + void reloadHTML(); /** @brief Initialize Google Earth */ void initializeGoogleEarth(); diff --git a/src/ui/map3D/QGCGoogleEarthView.ui b/src/ui/map3D/QGCGoogleEarthView.ui index 56f0f4eb51c97041b3a4047d81fe7e173c5e7736..b98f097e08c420889bc982028dfa1aeb21540b82 100644 --- a/src/ui/map3D/QGCGoogleEarthView.ui +++ b/src/ui/map3D/QGCGoogleEarthView.ui @@ -23,7 +23,7 @@ 2 - + @@ -58,7 +58,7 @@ - + Qt::Horizontal @@ -180,6 +180,13 @@ + + + + Reset + + +