From bc3471de9809644bddfe11c7363c68de788d92a9 Mon Sep 17 00:00:00 2001 From: lm Date: Sat, 19 Feb 2011 10:43:01 +0100 Subject: [PATCH] Improved Google Earth interface, clearing trails works, switching views works (but is not yet perfect), switching editing mode on/off works --- images/earth.html | 41 ++++++++++++---- qgroundcontrol.pro | 1 - src/ui/map3D/QGCGoogleEarthView.cc | 71 +++++++++++++++++++-------- src/ui/map3D/QGCGoogleEarthView.h | 4 +- src/ui/map3D/QGCGoogleEarthView.ui | 42 +++++----------- src/ui/map3D/QGCGoogleEarthViewWin.ui | 19 ------- 6 files changed, 99 insertions(+), 79 deletions(-) delete mode 100644 src/ui/map3D/QGCGoogleEarthViewWin.ui diff --git a/images/earth.html b/images/earth.html index 41d7d6a82..ee4242812 100644 --- a/images/earth.html +++ b/images/earth.html @@ -102,7 +102,7 @@ function setDistanceMode(mode) function setDraggingAllowed(allowed) { - //draggingAllowed = allowed; + draggingAllowed = allowed; } function setNewWaypointPending(pending) @@ -369,6 +369,18 @@ trailsVisible[id] = false; } function clearTrail(id) +{ + ge.getFeatures().removeChild(trailPlacemarks[id]); + trailPlacemarks[id] = null; + var isVisible = trailsVisible[id]; + createTrail(id, trailColors[id]); + if (isVisible) + { + showTrail(id); + } +} + +function hideTrail(id) { trailsVisible[id] = false; ge.getFeatures().removeChild(trailPlacemarks[id]); @@ -501,16 +513,14 @@ function setCurrentAircraft(id) */ function setViewMode(mode) { - viewMode = mode; - var currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE); if (mode == 0) { - currView.setTilt(0); - currView.setHeading(0); + currView.setTilt(lastTilt); + currView.setHeading(lastHeading); } - if (mode == 1) + if (mode == 1 && viewMode != mode) { lastTilt = currView.getTilt(); lastHeading = currView.getHeading(); @@ -524,6 +534,8 @@ function setViewMode(mode) currView.setAltitude(lastAlt2); } + viewMode = mode; + ge.getView().setAbstractView(currView); } @@ -532,11 +544,22 @@ function updateFollowAircraft() currView = ge.getView().copyAsLookAt(ge.ALTITUDE_ABSOLUTE); currView.setLatitude(lastLat); currView.setLongitude(lastLon); - currView.setAltitude(lastAlt); + + if (distanceMode == 1) + { + var groundAltitude = ge.getGlobe().getGroundAltitude(lastLat, lastLon); + currView.setAltitude(groundAltitude); + } + + if (distanceMode == 0) currView.setAltitude(lastAlt); currView.setRange(currViewRange); - currView.setTilt(currFollowTilt); - currView.setHeading(currFollowHeading); + + if (viewMode != 3) // VIEW_MODE_CHASE_FREE + { + currView.setTilt(currFollowTilt); + currView.setHeading(currFollowHeading); + } ge.getView().setAbstractView(currView); } diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index bbcfd5fd4..40b68c247 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -144,7 +144,6 @@ FORMS += src/ui/MainWindow.ui \ src/ui/QMap3D.ui \ src/ui/QGCWebView.ui \ src/ui/map3D/QGCGoogleEarthView.ui \ - src/ui/map3D/QGCGoogleEarthViewWin.ui \ src/ui/SlugsDataSensorView.ui \ src/ui/SlugsHilSim.ui \ src/ui/SlugsPIDControl.ui \ diff --git a/src/ui/map3D/QGCGoogleEarthView.cc b/src/ui/map3D/QGCGoogleEarthView.cc index f2a50bc3b..591479235 100644 --- a/src/ui/map3D/QGCGoogleEarthView.cc +++ b/src/ui/map3D/QGCGoogleEarthView.cc @@ -83,6 +83,7 @@ QGCGoogleEarthView::QGCGoogleEarthView(QWidget *parent) : connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateState())); connect(ui->resetButton, SIGNAL(clicked()), this, SLOT(reloadHTML())); connect(ui->changeViewButton, SIGNAL(clicked()), this, SLOT(toggleViewMode())); + connect(ui->clearTrailsButton, SIGNAL(clicked()), this, SLOT(clearTrails())); } QGCGoogleEarthView::~QGCGoogleEarthView() @@ -205,6 +206,7 @@ void QGCGoogleEarthView::setActiveUAS(UASInterface* uas) { mav = uas; javaScript(QString("setCurrAircraft(%1);").arg(uas->getUASID())); + updateWaypointList(uas->getUASID()); } } @@ -271,6 +273,15 @@ void QGCGoogleEarthView::updateGlobalPosition(UASInterface* uas, double lat, dou //qDebug() << QString("addTrailPosition(%1, %2, %3, %4);").arg(uas->getUASID()).arg(lat, 0, 'f', 15).arg(lon, 0, 'f', 15).arg(alt, 0, 'f', 15); } +void QGCGoogleEarthView::clearTrails() +{ + QList mavs = UASManager::instance()->getUASList(); + foreach (UASInterface* currMav, mavs) + { + javaScript(QString("clearTrail(%1);").arg(currMav->getUASID())); + } +} + void QGCGoogleEarthView::showTrail(bool state) { // Check if the current trail has to be hidden @@ -304,8 +315,19 @@ void QGCGoogleEarthView::showWaypoints(bool state) void QGCGoogleEarthView::follow(bool follow) { ui->followAirplaneCheckbox->setChecked(follow); + if (follow != followCamera) + { + if (follow) + { + setViewMode(VIEW_MODE_CHASE_LOCKED); + } + else + { + setViewMode(VIEW_MODE_SIDE); + } + } followCamera = follow; - if (gEarthInitialized) javaScript(QString("setFollowEnabled(%1)").arg(follow)); + javaScript(QString("setFollowEnabled(%1)").arg(follow)); } void QGCGoogleEarthView::goHome() @@ -368,7 +390,14 @@ void QGCGoogleEarthView::printWinException(int no, QString str1, QString str2, Q QVariant QGCGoogleEarthView::javaScript(QString javaScript) { #ifdef Q_OS_MAC - return webViewMac->page()->currentFrame()->evaluateJavaScript(javaScript); + if (!gEarthInitialized) + { + return QVariant(false); + } + else + { + return webViewMac->page()->currentFrame()->evaluateJavaScript(javaScript); + } #endif #ifdef _MSC_VER if(!jScriptInitialized) @@ -381,7 +410,8 @@ QVariant QGCGoogleEarthView::javaScript(QString javaScript) QVariantList params; params.append(javaScript); params.append("JScript"); - return jScriptWin->dynamicCall("execScript(QString, QString)", params); + QVariant result = jScriptWin->dynamicCall("execScript(QString, QString)", params); + return result; } #endif } @@ -391,7 +421,6 @@ QVariant QGCGoogleEarthView::documentElement(QString name) #ifdef Q_OS_MAC QString javaScript("getGlobal(%1)"); QVariant result = webViewMac->page()->currentFrame()->evaluateJavaScript(javaScript.arg(name)); - //qDebug() << "DOC ELEM:" << name << ":" << result; return result; #endif #ifdef _MSC_VER @@ -402,20 +431,22 @@ QVariant QGCGoogleEarthView::documentElement(QString name) } else { - if (documentWin) - { - // Get HTMLElement object - QVariantList params; - params.append(name); - //QAxObject* elementWin = documentWin->dynamicCall("getElementById(QString)", params); - QVariant result =documentWin->dynamicCall("toString()"); - qDebug() << "GOT RESULT" << result; - return QVariant(0);//QVariant(result); - } - //QVariantList params; - //params.append(javaScript); - //params.append("JScript"); - //return jScriptWin->dynamicCall("execScript(QString, QString)", params); + QVariantList params; + QString javaScript("getGlobal(%1)"); + params.append(javaScript.arg(name)); + params.append("JScript"); + QVariant result = jScriptWin->dynamicCall("execScript(QString, QString)", params); + qDebug() << "JScript result: " << result << result.toDouble(); +// if (documentWin) +// { +// // Get HTMLElement object +// QVariantList params; +// params.append(name); +// //QAxObject* elementWin = documentWin->dynamicCall("getElementById(QString)", params); +// QVariant result =documentWin->dynamicCall("toString()"); +// qDebug() << "GOT RESULT" << result; +// return QVariant(0);//QVariant(result); +// } } #endif } @@ -469,6 +500,8 @@ void QGCGoogleEarthView::initializeGoogleEarth() } else { + gEarthInitialized = true; + // Set home location setHome(47.3769, 8.549444, 500); @@ -522,8 +555,6 @@ void QGCGoogleEarthView::initializeGoogleEarth() setDistanceMode(ui->camDistanceComboBox->currentIndex()); enableEditMode(ui->editButton->isChecked()); follow(this->followCamera); - - gEarthInitialized = true; } } } diff --git a/src/ui/map3D/QGCGoogleEarthView.h b/src/ui/map3D/QGCGoogleEarthView.h index 183d85891..a86deee37 100644 --- a/src/ui/map3D/QGCGoogleEarthView.h +++ b/src/ui/map3D/QGCGoogleEarthView.h @@ -73,7 +73,7 @@ public: enum VIEW_MODE { - VIEW_MODE_SIDE, ///< View from above, orientation is free + VIEW_MODE_SIDE = 0, ///< View from above, orientation is free VIEW_MODE_MAP, ///< View from above, orientation is north (map view) VIEW_MODE_CHASE_LOCKED, ///< Locked chase camera VIEW_MODE_CHASE_FREE, ///< Position is chasing object, but view can rotate around object @@ -94,6 +94,8 @@ public slots: void updateWaypointList(int uas); /** @brief Show the vehicle trail */ void showTrail(bool state); + /** @brief Clear the current vehicle trails and start with new ones */ + void clearTrails(); /** @brief Show the waypoints */ void showWaypoints(bool state); /** @brief Follow the aircraft during flight */ diff --git a/src/ui/map3D/QGCGoogleEarthView.ui b/src/ui/map3D/QGCGoogleEarthView.ui index 81140f1d2..15ebd3c4e 100644 --- a/src/ui/map3D/QGCGoogleEarthView.ui +++ b/src/ui/map3D/QGCGoogleEarthView.ui @@ -13,7 +13,7 @@ Form - + 8 @@ -23,7 +23,7 @@ 2 - + @@ -58,7 +58,7 @@ - + Qt::Horizontal @@ -71,7 +71,7 @@ - + Distance of the chase camera to the MAV @@ -96,23 +96,7 @@ - - - - Show waypoints - - - Show waypoints - - - Show waypoints - - - WPs - - - - + Chase the MAV @@ -128,7 +112,7 @@ - + Select the MAV to chase @@ -141,38 +125,38 @@ - Ground Distance + MAV Distance - MAV Distance + Ground Distance - + Qt::Vertical - + Reset - + Overhead - + Delete all waypoints @@ -188,7 +172,7 @@ - + Qt::Vertical diff --git a/src/ui/map3D/QGCGoogleEarthViewWin.ui b/src/ui/map3D/QGCGoogleEarthViewWin.ui deleted file mode 100644 index 6191eaebb..000000000 --- a/src/ui/map3D/QGCGoogleEarthViewWin.ui +++ /dev/null @@ -1,19 +0,0 @@ - - - QGCGoogleEarthViewWin - - - - 0 - 0 - 400 - 300 - - - - Form - - - - - -- 2.22.0