diff --git a/ground/src/plugins/opmap/opmap_widget.ui b/ground/src/plugins/opmap/opmap_widget.ui index 4bc825949..e05289c0b 100644 --- a/ground/src/plugins/opmap/opmap_widget.ui +++ b/ground/src/plugins/opmap/opmap_widget.ui @@ -432,32 +432,6 @@ border-radius: 2px; - - - - - 0 - 0 - - - - Move the magic waypoint to center of map - - - Center WP - - - - :/opmap/images/center_wp.png:/opmap/images/center_wp.png - - - - 28 - 28 - - - - diff --git a/ground/src/plugins/opmap/opmapgadgetwidget.cpp b/ground/src/plugins/opmap/opmapgadgetwidget.cpp index 2a80f7372..2e96d152a 100644 --- a/ground/src/plugins/opmap/opmapgadgetwidget.cpp +++ b/ground/src/plugins/opmap/opmapgadgetwidget.cpp @@ -609,7 +609,6 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) case MagicWaypoint_MapMode: menu.addSeparator()->setText(tr("Waypoints")); menu.addAction(homeMagicWaypointAct); - menu.addAction(centerMagicWaypointAct); break; } @@ -1111,11 +1110,6 @@ void OPMapGadgetWidget::on_toolButtonHomeWaypoint_clicked() homeMagicWaypoint(); } -void OPMapGadgetWidget::on_toolButtonCenterWaypoint_clicked() -{ - centerMagicWaypoint(); -} - void OPMapGadgetWidget::on_toolButtonMoveToWP_clicked() { moveToMagicWaypointPosition(); @@ -1141,6 +1135,9 @@ void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon) m_map->Home->SetCoord(home_position.coord); m_map->Home->RefreshPos(); + + // move the magic waypoint to keep it within the safe area boundry + keepMagicWaypointWithInSafeArea(); } void OPMapGadgetWidget::goHome() @@ -1493,10 +1490,6 @@ void OPMapGadgetWidget::createActions() homeMagicWaypointAct->setStatusTip(tr("Move the magic waypoint to the home position")); connect(homeMagicWaypointAct, SIGNAL(triggered()), this, SLOT(onHomeMagicWaypointAct_triggered())); - centerMagicWaypointAct = new QAction(tr("Center magic waypoint"), this); - centerMagicWaypointAct->setStatusTip(tr("Move the magic waypoint to the center of the map")); - connect(centerMagicWaypointAct, SIGNAL(triggered()), this, SLOT(onCenterMagicWaypointAct_triggered())); - mapModeActGroup = new QActionGroup(this); connect(mapModeActGroup, SIGNAL(triggered(QAction *)), this, SLOT(onMapModeActGroup_triggered(QAction *))); mapModeAct.clear(); @@ -1975,12 +1968,6 @@ void OPMapGadgetWidget::onHomeMagicWaypointAct_triggered() homeMagicWaypoint(); } -void OPMapGadgetWidget::onCenterMagicWaypointAct_triggered() -{ - // center the magic waypoint on the map - centerMagicWaypoint(); -} - void OPMapGadgetWidget::onShowSafeAreaAct_toggled(bool show) { if (!m_widget || !m_map) @@ -1999,6 +1986,9 @@ void OPMapGadgetWidget::onSafeAreaActGroup_triggered(QAction *action) m_map->Home->SetSafeArea(radius); // set the radius (meters) m_map->Home->RefreshPos(); + + // move the magic waypoint if need be to keep it within the safe area around the home position + keepMagicWaypointWithInSafeArea(); } // ************************************************************************************* @@ -2018,23 +2008,6 @@ void OPMapGadgetWidget::homeMagicWaypoint() magic_waypoint.map_wp_item->SetCoord(magic_waypoint.coord); } -// ************************************************************************************* -// move the magic waypoint to the center of the map - -void OPMapGadgetWidget::centerMagicWaypoint() -{ - if (!m_widget || !m_map) - return; - - if (m_map_mode != MagicWaypoint_MapMode) - return; - - magic_waypoint.coord = m_map->CurrentPosition(); - - if (magic_waypoint.map_wp_item) - magic_waypoint.map_wp_item->SetCoord(magic_waypoint.coord); -} - // ************************************************************************************* // move the UAV to the magic waypoint position @@ -2108,7 +2081,6 @@ void OPMapGadgetWidget::hideMagicWaypointControls() { m_widget->lineWaypoint->setVisible(false); m_widget->toolButtonHomeWaypoint->setVisible(false); - m_widget->toolButtonCenterWaypoint->setVisible(false); m_widget->toolButtonMoveToWP->setVisible(false); } @@ -2116,10 +2088,38 @@ void OPMapGadgetWidget::showMagicWaypointControls() { m_widget->lineWaypoint->setVisible(true); m_widget->toolButtonHomeWaypoint->setVisible(true); - m_widget->toolButtonCenterWaypoint->setVisible(true); m_widget->toolButtonMoveToWP->setVisible(true); } +// ************************************************************************************* +// move the magic waypoint to keep it within the safe area boundry + +void OPMapGadgetWidget::keepMagicWaypointWithInSafeArea() +{ + + // calcute the bearing and distance from the home position to the magic waypoint + double dist = distance(home_position.coord, magic_waypoint.coord); + double bear = bearing(home_position.coord, magic_waypoint.coord); + + // get the maximum safe distance - in kilometers + double boundry_dist = (double)m_map->Home->SafeArea() / 1000; + +// if (dist <= boundry_dist) +// return; // the magic waypoint is still within the safe area, don't move it + + if (dist > boundry_dist) dist = boundry_dist; + + // move the magic waypoint + + magic_waypoint.coord = destPoint(home_position.coord, bear, dist); + + if (m_map_mode == MagicWaypoint_MapMode) + { // move the on-screen waypoint + if (magic_waypoint.map_wp_item) + magic_waypoint.map_wp_item->SetCoord(magic_waypoint.coord); + } +} + // ************************************************************************************* // return the distance between two points .. in kilometers diff --git a/ground/src/plugins/opmap/opmapgadgetwidget.h b/ground/src/plugins/opmap/opmapgadgetwidget.h index 746732b4e..8c209cb13 100644 --- a/ground/src/plugins/opmap/opmapgadgetwidget.h +++ b/ground/src/plugins/opmap/opmapgadgetwidget.h @@ -156,7 +156,6 @@ private slots: void on_toolButtonMagicWaypointMapMode_clicked(); void on_toolButtonNormalMapMode_clicked(); void on_toolButtonHomeWaypoint_clicked(); - void on_toolButtonCenterWaypoint_clicked(); void on_toolButtonMoveToWP_clicked(); /** @@ -208,7 +207,6 @@ private slots: void onMapModeActGroup_triggered(QAction *action); void onZoomActGroup_triggered(QAction *action); void onHomeMagicWaypointAct_triggered(); - void onCenterMagicWaypointAct_triggered(); void onShowSafeAreaAct_toggled(bool show); void onSafeAreaActGroup_triggered(QAction *action); void onUAVTrailTypeActGroup_triggered(QAction *action); @@ -293,7 +291,6 @@ private: QAction *deleteWayPointAct; QAction *clearWayPointsAct; QAction *homeMagicWaypointAct; - QAction *centerMagicWaypointAct; QAction *showSafeAreaAct; QActionGroup *safeAreaActGroup; @@ -314,7 +311,6 @@ private: QList zoomAct; void homeMagicWaypoint(); - void centerMagicWaypoint(); void moveToMagicWaypointPosition(); @@ -324,6 +320,8 @@ private: void hideMagicWaypointControls(); void showMagicWaypointControls(); + void keepMagicWaypointWithInSafeArea(); + double distance(internals::PointLatLng from, internals::PointLatLng to); double bearing(internals::PointLatLng from, internals::PointLatLng to); internals::PointLatLng destPoint(internals::PointLatLng source, double bear, double dist);