Commit bc3471de authored by lm's avatar lm

Improved Google Earth interface, clearing trails works, switching views works...

Improved Google Earth interface, clearing trails works, switching views works (but is not yet perfect), switching editing mode on/off works
parent 76d8491c
......@@ -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);
}
......
......@@ -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 \
......
......@@ -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<UASInterface*> 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;
}
}
}
......
......@@ -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 */
......
......@@ -13,7 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="1,1,1,1,1,1,30,1,100,1,1,1,1,1,1">
<layout class="QGridLayout" name="gridLayout" columnstretch="1,0,0,0,0,0,0,0,0,0,0,0,0,0">
<property name="horizontalSpacing">
<number>8</number>
</property>
......@@ -23,7 +23,7 @@
<property name="margin">
<number>2</number>
</property>
<item row="0" column="0" colspan="15">
<item row="0" column="0" colspan="14">
<layout class="QVBoxLayout" name="webViewLayout"/>
</item>
<item row="1" column="1">
......@@ -58,7 +58,7 @@
</property>
</widget>
</item>
<item row="1" column="14">
<item row="1" column="13">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -71,7 +71,7 @@
</property>
</spacer>
</item>
<item row="1" column="8">
<item row="1" column="7">
<widget class="QSlider" name="camDistanceSlider">
<property name="toolTip">
<string>Distance of the chase camera to the MAV</string>
......@@ -96,23 +96,7 @@
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QCheckBox" name="waypointsCheckbox">
<property name="toolTip">
<string>Show waypoints</string>
</property>
<property name="statusTip">
<string>Show waypoints</string>
</property>
<property name="whatsThis">
<string>Show waypoints</string>
</property>
<property name="text">
<string>WPs</string>
</property>
</widget>
</item>
<item row="1" column="9">
<item row="1" column="8">
<widget class="QCheckBox" name="followAirplaneCheckbox">
<property name="toolTip">
<string>Chase the MAV</string>
......@@ -128,7 +112,7 @@
</property>
</widget>
</item>
<item row="1" column="6">
<item row="1" column="5">
<widget class="QComboBox" name="camDistanceComboBox">
<property name="toolTip">
<string>Select the MAV to chase</string>
......@@ -141,38 +125,38 @@
</property>
<item>
<property name="text">
<string>Ground Distance</string>
<string>MAV Distance</string>
</property>
</item>
<item>
<property name="text">
<string>MAV Distance</string>
<string>Ground Distance</string>
</property>
</item>
</widget>
</item>
<item row="1" column="5">
<item row="1" column="4">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="1" column="13">
<item row="1" column="12">
<widget class="QPushButton" name="resetButton">
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item row="1" column="10">
<item row="1" column="9">
<widget class="QPushButton" name="changeViewButton">
<property name="text">
<string>Overhead</string>
</property>
</widget>
</item>
<item row="1" column="12">
<item row="1" column="11">
<widget class="QPushButton" name="clearTrailsButton">
<property name="toolTip">
<string>Delete all waypoints</string>
......@@ -188,7 +172,7 @@
</property>
</widget>
</item>
<item row="1" column="11">
<item row="1" column="10">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QGCGoogleEarthViewWin</class>
<widget class="QWidget" name="QGCGoogleEarthViewWin">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment