diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index 9146e347ab0093e32dd03e5d3f0da6e169af3195..4b90ab327760384f2a2196660f14bf94a4fe59f5 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -38,6 +38,7 @@ QGCMapWidget::QGCMapWidget(QWidget *parent) : this->setContextMenuPolicy(Qt::ActionsContextMenu); + // Got to options QAction *guidedaction = new QAction(this); guidedaction->setText("Go To Here (Guided Mode)"); connect(guidedaction,SIGNAL(triggered()),this,SLOT(guidedActionTriggered())); @@ -46,10 +47,16 @@ QGCMapWidget::QGCMapWidget(QWidget *parent) : guidedaction->setText("Go To Here Alt (Guided Mode)"); connect(guidedaction,SIGNAL(triggered()),this,SLOT(guidedAltActionTriggered())); this->addAction(guidedaction); + // Point camera option QAction *cameraaction = new QAction(this); cameraaction->setText("Point Camera Here"); connect(cameraaction,SIGNAL(triggered()),this,SLOT(cameraActionTriggered())); this->addAction(cameraaction); + // Set home location option + QAction *sethomeaction = new QAction(this); + sethomeaction->setText("Set Home Location Here"); + connect(sethomeaction,SIGNAL(triggered()),this,SLOT(setHomeActionTriggered())); + this->addAction(sethomeaction); } void QGCMapWidget::guidedActionTriggered() { @@ -111,6 +118,35 @@ void QGCMapWidget::cameraActionTriggered() } } +/** + * @brief QGCMapWidget::setHomeActionTriggered + */ +bool QGCMapWidget::setHomeActionTriggered() +{ + if (!uas) + { + QMessageBox::information(0,"Error","Please connect first"); + return false; + } + UASManager *uasManager = UASManager::instance(); + if (!uasManager) { return false; } + + // Enter an altitude + bool ok = false; + int alt = QInputDialog::getInt(this,"Altitude","Enter default altitude (in meters) of destination point for guided mode",100,0,30000,1,&ok); + if (!ok) return false; //Use has chosen cancel. Do not send the waypoint + + // Create new waypoint and send it to the WPManager to send out. + internals::PointLatLng pos = map->FromLocalToLatLng(mousePressPos.x(), mousePressPos.y()); + qDebug() << "Set home location sent. Lat:" << pos.Lat() << ", Lon:" << pos.Lng() << ", Alt: " << alt; + + bool success = uasManager->setHomePositionAndNotify(pos.Lat(),pos.Lng(), alt); + + qDebug() << ((success)? "Set new home location." : "Failed to set new home location."); + + return success; +} + void QGCMapWidget::mousePressEvent(QMouseEvent *event) { mapcontrol::OPMapWidget::mousePressEvent(event); diff --git a/src/ui/map/QGCMapWidget.h b/src/ui/map/QGCMapWidget.h index d6f3b53d790be4564280fb1330423f46a0190736..48ba49618ab6596cd1eb1bdca90416f9e56e1b50 100644 --- a/src/ui/map/QGCMapWidget.h +++ b/src/ui/map/QGCMapWidget.h @@ -46,6 +46,8 @@ public slots: void guidedActionTriggered(); /** @brief Action triggered when guided action is selected from the context menu, allows for altitude selection */ bool guidedAltActionTriggered(); + /** @brief Action triggered when set home action is selected from the context menu. */ + bool setHomeActionTriggered(); /** @brief Add system to map view */ void addUAS(UASInterface* uas); /** @brief Update the global position of a system */