35 #include "ui_opmap_widget.h"
36 #include <QInputDialog>
37 #include <QApplication>
38 #include <QHBoxLayout>
39 #include <QVBoxLayout>
42 #include <QStringList>
55 #include "positionactual.h"
56 #include "homelocation.h"
57 #include "gpsposition.h"
59 #include "attitudeactual.h"
60 #include "positionactual.h"
61 #include "velocityactual.h"
62 #include "windvelocityactual.h"
64 #include "../pathplanner/pathplannergadgetwidget.h"
65 #include "../pathplanner/waypointdialog.h"
69 #define deg_to_rad ((double)M_PI / 180.0)
70 #define rad_to_deg (180.0 / (double)M_PI)
72 #define earth_mean_radius 6371 // kilometers
74 #define max_digital_zoom 3 // maximum allowed digital zoom level
98 findPlaceCompleter = NULL;
100 m_mouse_waypoint = NULL;
104 uavo_util_mgr = NULL;
106 m_prev_tile_number = 0;
108 m_min_zoom = m_max_zoom = 0;
115 m_telemetry_connected =
false;
119 setMouseTracking(
true);
121 pm = ExtensionSystem::PluginManager::instance();
131 double longitude = 0;
135 getUAVPosition(latitude, longitude, altitude);
142 m_home_position.
coord = pos_lat_lon;
143 m_home_position.
altitude = altitude;
144 m_home_position.
locked =
false;
149 m_widget =
new Ui::OPMap_Widget();
150 m_widget->setupUi(
this);
157 m_map->setFrameStyle(QFrame::NoFrame);
161 m_widget->horizontalSliderZoom->setMinimum(m_map->
MinZoom());
162 m_widget->horizontalSliderZoom->setMaximum(m_map->
MaxZoom() + max_digital_zoom);
164 m_min_zoom = m_widget->horizontalSliderZoom->minimum();
165 m_max_zoom = m_widget->horizontalSliderZoom->maximum();
168 internals::MouseWheelZoomType::MousePositionWithoutCenter);
175 m_map->
Home->SetSafeArea(
177 m_map->
Home->SetShowSafeArea(
179 m_map->
Home->SetToggleRefresh(
true);
183 &OPMapGadgetWidget::onHomeDoubleClick);
187 m_map->
UAV->SetTrailType(UAVTrailType::ByTimeElapsed);
192 m_map->
GPS->SetTrailType(UAVTrailType::ByTimeElapsed);
196 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
198 QVBoxLayout *layout =
new QVBoxLayout;
199 layout->setSpacing(0);
200 layout->setContentsMargins(0, 0, 0, 0);
201 layout->addWidget(m_map);
202 m_widget->mapWidget->setLayout(layout);
204 m_widget->toolButtonMagicWaypointMapMode->setChecked(
false);
205 m_widget->toolButtonNormalMapMode->setChecked(
true);
206 hideMagicWaypointControls();
208 m_widget->labelUAVPos->setText(
"---");
209 m_widget->labelMapPos->setText(
"---");
210 m_widget->labelMousePos->setText(
"---");
211 m_widget->labelMapZoom->setText(
"---");
212 m_widget->labelNEDCoords->setText(
"---");
214 m_widget->progressBarMap->setMaximum(1);
217 &OPMapGadgetWidget::zoomChanged);
219 &OPMapGadgetWidget::OnCurrentPositionChanged);
221 &OPMapGadgetWidget::OnTileLoadComplete);
223 &OPMapGadgetWidget::OnTileLoadStart);
225 &OPMapGadgetWidget::OnTilesStillToLoad);
227 &OPMapGadgetWidget::wpDoubleClickEvent);
229 m_map->
Home->SetCoord(m_home_position.
coord);
230 m_map->
UAV->SetUAVPos(m_home_position.
coord, 0.0);
231 m_map->
UAV->update();
233 m_map->
GPS->SetUAVPos(m_home_position.
coord, 0.0);
241 selectionModel = pm->getObject<QItemSelectionModel>();
242 Q_ASSERT(selectionModel);
243 mapProxy =
new ModelMapProxy(
this, m_map, model, selectionModel);
246 magicWayPoint->setVisible(
false);
292 m_updateTimer =
new QTimer();
293 m_updateTimer->setInterval(m_maxUpdateRate);
294 connect(m_updateTimer, &QTimer::timeout,
this, &OPMapGadgetWidget::updatePosition);
295 m_updateTimer->start();
297 m_statusUpdateTimer =
new QTimer();
298 m_statusUpdateTimer->setInterval(200);
299 connect(m_statusUpdateTimer, &QTimer::timeout,
this, &OPMapGadgetWidget::updateMousePos);
300 m_statusUpdateTimer->start();
304 WindVelocityActual *windVelocityActual = WindVelocityActual::GetInstance(uavo_mgr);
306 &OPMapGadgetWidget::updateWindspeed);
315 disconnect(m_map,
nullptr,
nullptr,
nullptr);
325 if (!mapProxy.isNull())
334 QWidget::resizeEvent(event);
339 if (m_widget && m_map) {
342 if (event->buttons() & Qt::LeftButton) {
344 QWidget::mouseMoveEvent(event);
346 void OPMapGadgetWidget::wpDoubleClickEvent(WayPointItem *wp)
348 m_mouse_waypoint = wp;
349 onEditWayPointAct_triggered();
357 if (!m_widget || !m_map)
360 if (event->reason() != QContextMenuEvent::Mouse)
364 QPoint p = m_map->mapFromGlobal(event->globalPos());
367 if (!m_map->contentsRect().contains(p))
371 s = QString::number(m_context_menu_lat_lon.
Lat(),
'f', 7) +
" "
372 + QString::number(m_context_menu_lat_lon.
Lng(),
'f', 7);
373 m_widget->labelMousePos->setText(s);
376 QGraphicsItem *item = m_map->itemAt(p);
380 bool waypoint_locked =
false;
381 if (m_mouse_waypoint)
382 waypoint_locked = (m_mouse_waypoint->flags() & QGraphicsItem::ItemIsMovable) == 0;
387 contextMenu.addAction(closeAct1);
388 contextMenu.addSeparator();
389 contextMenu.addAction(reloadAct);
390 contextMenu.addSeparator();
391 contextMenu.addAction(ripAct);
392 contextMenu.addSeparator();
394 QMenu maxUpdateRateSubMenu(
395 tr(
"&Max Update Rate ") +
"(" + QString::number(m_maxUpdateRate) +
" ms)",
this);
396 for (
int i = 0;
i < maxUpdateRateAct.count();
i++)
397 maxUpdateRateSubMenu.addAction(maxUpdateRateAct.at(
i));
398 contextMenu.addMenu(&maxUpdateRateSubMenu);
400 contextMenu.addSeparator();
402 switch (m_map_mode) {
407 s = tr(
" (Magic Waypoint)");
410 s = tr(
" (Unknown)");
413 for (
int i = 0;
i < mapModeAct.count();
i++) {
414 QAction *act = mapModeAct.at(
i);
417 if (act->data().toInt() == (int)m_map_mode)
418 act->setChecked(
true);
420 QMenu mapModeSubMenu(tr(
"Map mode") + s,
this);
421 for (
int i = 0;
i < mapModeAct.count();
i++)
422 mapModeSubMenu.addAction(mapModeAct.at(
i));
423 contextMenu.addMenu(&mapModeSubMenu);
425 contextMenu.addSeparator();
427 QMenu copySubMenu(tr(
"Copy"),
this);
428 copySubMenu.addAction(copyMouseLatLonToClipAct);
429 copySubMenu.addAction(copyMouseLatToClipAct);
430 copySubMenu.addAction(copyMouseLonToClipAct);
431 contextMenu.addMenu(©SubMenu);
433 contextMenu.addSeparator();
434 contextMenu.addAction(changeDefaultLocalAndZoom);
435 contextMenu.addSeparator();
437 QMenu safeArea(
"Safety Area definitions");
439 QMenu safeAreaSubMenu(
440 tr(
"Safe Area Radius") +
" (" + QString::number(m_map->
Home->SafeArea()) +
"m)",
this);
441 for (
int i = 0;
i < safeAreaAct.count();
i++)
442 safeAreaSubMenu.addAction(safeAreaAct.at(
i));
443 safeArea.addMenu(&safeAreaSubMenu);
444 safeArea.addAction(showSafeAreaAct);
445 contextMenu.addMenu(&safeArea);
447 contextMenu.addSeparator();
449 contextMenu.addAction(showCompassRoseAct);
450 contextMenu.addAction(showWindCompassAction);
452 contextMenu.addAction(showDiagnostics);
454 contextMenu.addAction(showUAVInfo);
456 contextMenu.addSeparator()->setText(tr(
"Zoom"));
458 contextMenu.addAction(zoomInAct);
459 contextMenu.addAction(zoomOutAct);
461 QMenu zoomSubMenu(tr(
"&Zoom ") +
"(" + QString::number(m_map->
ZoomTotal()) +
")",
this);
462 for (
int i = 0;
i < zoomAct.count();
i++)
463 zoomSubMenu.addAction(zoomAct.at(
i));
464 contextMenu.addMenu(&zoomSubMenu);
466 contextMenu.addSeparator();
468 contextMenu.addAction(goMouseClickAct);
470 contextMenu.addSeparator()->setText(tr(
"HOME"));
472 contextMenu.addAction(setHomeAct);
473 contextMenu.addAction(showHomeAct);
474 contextMenu.addAction(goHomeAct);
478 QMenu uav_menu(tr(
"UAV"));
479 uav_menu.addSeparator()->setText(tr(
"UAV Trail"));
480 contextMenu.addMenu(&uav_menu);
481 QMenu uavTrailTypeSubMenu(
482 tr(
"UAV trail type") +
" ("
485 for (
int i = 0;
i < uavTrailTypeAct.count();
i++)
486 uavTrailTypeSubMenu.addAction(uavTrailTypeAct.at(
i));
487 uav_menu.addMenu(&uavTrailTypeSubMenu);
489 QMenu uavTrailTimeSubMenu(
490 tr(
"UAV trail time") +
" (" + QString::number(m_map->
UAV->TrailTime()) +
" sec)",
this);
491 for (
int i = 0;
i < uavTrailTimeAct.count();
i++)
492 uavTrailTimeSubMenu.addAction(uavTrailTimeAct.at(
i));
493 uav_menu.addMenu(&uavTrailTimeSubMenu);
495 QMenu uavTrailDistanceSubMenu(tr(
"UAV trail distance") +
" ("
496 + QString::number(m_map->
UAV->TrailDistance()) +
" meters)",
498 for (
int i = 0;
i < uavTrailDistanceAct.count();
i++)
499 uavTrailDistanceSubMenu.addAction(uavTrailDistanceAct.at(
i));
500 uav_menu.addMenu(&uavTrailDistanceSubMenu);
502 uav_menu.addAction(showTrailAct);
504 uav_menu.addAction(showTrailLineAct);
506 uav_menu.addAction(clearUAVtrailAct);
510 uav_menu.addSeparator()->setText(tr(
"UAV"));
512 uav_menu.addAction(showUAVAct);
513 uav_menu.addAction(followUAVpositionAct);
514 uav_menu.addAction(followUAVheadingAct);
515 uav_menu.addAction(goUAVAct);
518 switch (m_map_mode) {
522 contextMenu.addSeparator()->setText(tr(
"Waypoints"));
524 contextMenu.addAction(wayPointEditorAct);
525 contextMenu.addAction(addWayPointActFromContextMenu);
527 if (m_mouse_waypoint) {
528 contextMenu.addAction(editWayPointAct);
530 lockWayPointAct->setChecked(waypoint_locked);
531 contextMenu.addAction(lockWayPointAct);
533 if (!waypoint_locked)
534 contextMenu.addAction(deleteWayPointAct);
538 contextMenu.addAction(clearWayPointsAct);
543 contextMenu.addSeparator()->setText(tr(
"Waypoints"));
544 contextMenu.addAction(homeMagicWaypointAct);
549 QMenu overlaySubMenu(tr(
"&Overlay Opacity "),
this);
550 for (
int i = 0;
i < overlayOpacityAct.count();
i++)
551 overlaySubMenu.addAction(overlayOpacityAct.at(
i));
552 contextMenu.addMenu(&overlaySubMenu);
553 contextMenu.addSeparator();
555 contextMenu.addAction(closeAct2);
557 contextMenu.exec(event->globalPos());
564 QWidget::closeEvent(event);
574 void OPMapGadgetWidget::updatePosition()
576 double uav_latitude, uav_longitude, uav_altitude, uav_yaw;
577 double gps_latitude, gps_longitude, gps_altitude, gps_heading;
582 if (!m_widget || !m_map)
589 if (!getUAVPosition(uav_latitude, uav_longitude, uav_altitude))
593 uav_yaw = getUAV_Yaw();
599 GPSPosition *gpsPositionObj = GPSPosition::GetInstance(uavo_mgr);
600 Q_ASSERT(gpsPositionObj);
602 GPSPosition::DataFields gpsPositionData = gpsPositionObj->getData();
605 gps_heading = gpsPositionData.Heading;
606 gps_latitude = gpsPositionData.Latitude;
607 gps_longitude = gpsPositionData.Longitude;
608 gps_altitude = gpsPositionData.Altitude;
614 AttitudeActual *attitudeActualObj = AttitudeActual::GetInstance(uavo_mgr);
615 PositionActual *positionActualObj = PositionActual::GetInstance(uavo_mgr);
616 VelocityActual *velocityActualObj = VelocityActual::GetInstance(uavo_mgr);
617 Gyros *gyrosObj = Gyros::GetInstance(uavo_mgr);
619 Q_ASSERT(attitudeActualObj);
620 Q_ASSERT(positionActualObj);
621 Q_ASSERT(velocityActualObj);
624 AttitudeActual::DataFields attitudeActualData = attitudeActualObj->getData();
625 PositionActual::DataFields positionActualData = positionActualObj->getData();
626 VelocityActual::DataFields velocityActualData = velocityActualObj->getData();
627 Gyros::DataFields gyrosData = gyrosObj->getData();
629 double NED[3] = { positionActualData.North, positionActualData.East, positionActualData.Down };
630 double vNED[3] = { velocityActualData.North, velocityActualData.East, velocityActualData.Down };
633 m_map->
UAV->SetNED(NED);
634 m_map->
UAV->SetCAS(-1);
635 m_map->
UAV->SetGroundspeed(vNED, m_maxUpdateRate);
640 float psiRate_dps = 0 * gyrosData.z
641 + sin(attitudeActualData.Roll * deg_to_rad) / cos(attitudeActualData.Pitch * deg_to_rad)
643 + cos(attitudeActualData.Roll * deg_to_rad) / cos(attitudeActualData.Pitch * deg_to_rad)
647 m_map->
UAV->SetYawRate(psiRate_dps);
652 QString str =
"lat: " + QString::number(uav_pos.
Lat(),
'f', 7) +
" lon: "
653 + QString::number(uav_pos.
Lng(),
'f', 7) +
" " + QString::number(uav_yaw,
'f', 1) +
"deg"
654 +
" " + QString::number(uav_altitude,
'f', 1) +
"m";
656 m_widget->labelUAVPos->setText(str);
661 m_map->
UAV->SetUAVPos(uav_pos, uav_altitude);
663 m_map->
UAV->SetUAVHeading(uav_yaw);
668 m_map->
GPS->SetUAVPos(gps_pos, gps_altitude);
669 m_map->
GPS->SetUAVHeading(gps_heading);
671 m_map->
UAV->updateTextOverlay();
672 m_map->
UAV->update();
680 void OPMapGadgetWidget::updateMousePos()
682 if (!m_widget || !m_map)
685 QPoint p = m_map->mapFromGlobal(QCursor::pos());
688 lastLatLngMouse = lat_lon;
689 if (!m_map->contentsRect().contains(p))
692 QGraphicsItem *item = m_map->itemAt(p);
700 if (m_mouse_lat_lon == lat_lon)
703 m_mouse_lat_lon = lat_lon;
707 QString
s1 = QString::number(m_mouse_lat_lon.
Lat(),
'f', 7) +
" "
708 + QString::number(m_mouse_lat_lon.
Lng(),
'f', 7);
710 s1 +=
" wp[" + QString::number(wp->numberAdjusted()) +
"]";
712 double dist = distance(home_lat_lon, wp->Coord());
713 double bear = bearing(home_lat_lon, wp->Coord());
714 s1 +=
" " + QString::number(dist * 1000,
'f', 1) +
"m";
715 s1 +=
" " + QString::number(bear,
'f', 1) +
"deg";
719 double dist = distance(home_lat_lon, m_mouse_lat_lon);
720 double bear = bearing(home_lat_lon, m_mouse_lat_lon);
721 s1 +=
" " + QString::number(dist * 1000,
'f', 1) +
"m";
722 s1 +=
" " + QString::number(bear,
'f', 1) +
"deg";
724 m_widget->labelMousePos->setText(s1);
727 double homeLLA[3] = { home_lat_lon.
Lat(), home_lat_lon.
Lng(), 0 };
728 double LLA[3] = { m_mouse_lat_lon.
Lat(), m_mouse_lat_lon.
Lng(), 0 };
734 QString
s2 = QString::number(NED[0],
'g', 5) +
" " + QString::number(NED[1],
'g', 5);
735 m_widget->labelNEDCoords->setText(s2);
744 void OPMapGadgetWidget::zoomChanged(
double zoomt,
double zoom,
double zoomd)
746 if (!m_widget || !m_map)
749 QString
s =
"tot:" + QString::number(zoomt,
'f', 1) +
" rea:" + QString::number(zoom,
'f', 1)
750 +
" dig:" + QString::number(zoomd,
'f', 1);
751 m_widget->labelMapZoom->setText(s);
753 int i_zoom = (int)(zoomt + 0.5);
755 if (i_zoom < m_min_zoom)
757 else if (i_zoom > m_max_zoom)
760 if (m_widget->horizontalSliderZoom->value() != i_zoom)
761 m_widget->horizontalSliderZoom->setValue(i_zoom);
763 int index0_zoom = i_zoom - m_min_zoom;
764 if (index0_zoom < zoomAct.count())
765 zoomAct.at(index0_zoom)->setChecked(
true);
770 if (!m_widget || !m_map)
774 QString::number(point.
Lat(),
'f', 7) +
" " + QString::number(point.
Lng(),
'f', 7) +
" ";
775 m_widget->labelMapPos->setText(coord_str);
781 void OPMapGadgetWidget::OnTilesStillToLoad(
int number)
783 if (!m_widget || !m_map)
786 if (m_widget->progressBarMap->maximum() < number)
787 m_widget->progressBarMap->setMaximum(number);
789 m_widget->progressBarMap->setValue(m_widget->progressBarMap->maximum()
792 m_prev_tile_number = number;
798 void OPMapGadgetWidget::OnTileLoadStart()
800 if (!m_widget || !m_map)
802 m_widget->progressBarMap->setVisible(
true);
811 void OPMapGadgetWidget::OnTileLoadComplete()
813 if (!m_widget || !m_map)
816 m_widget->progressBarMap->setVisible(
false);
819 void OPMapGadgetWidget::on_toolButtonZoomP_clicked()
824 void OPMapGadgetWidget::on_toolButtonZoomM_clicked()
829 void OPMapGadgetWidget::on_toolButtonMapHome_clicked()
834 void OPMapGadgetWidget::on_toolButtonMapUAV_clicked()
836 if (!m_widget || !m_map)
839 followUAVpositionAct->toggle();
842 void OPMapGadgetWidget::on_toolButtonMapUAVheading_clicked()
844 if (!m_widget || !m_map)
847 followUAVheadingAct->toggle();
850 void OPMapGadgetWidget::on_horizontalSliderZoom_sliderMoved(
int position)
852 if (!m_widget || !m_map)
858 void OPMapGadgetWidget::on_toolButtonNormalMapMode_clicked()
863 void OPMapGadgetWidget::on_toolButtonMagicWaypointMapMode_clicked()
868 void OPMapGadgetWidget::on_toolButtonHomeWaypoint_clicked()
873 void OPMapGadgetWidget::on_toolButtonMoveToWP_clicked()
875 moveToMagicWaypointPosition();
883 m_telemetry_connected =
true;
900 if (m_map->
UAV->GetMapFollowType() != UAVMapFollowType::None)
908 m_telemetry_connected =
false;
932 if (!m_widget || !m_map)
935 double latitude = pos.x();
936 double longitude = pos.y();
940 else if (latitude < -90)
943 if (longitude != longitude)
945 else if (longitude > 180)
947 else if (longitude < -180)
958 if (!m_widget || !m_map)
961 if (pos_lat_lon.
Lat() != pos_lat_lon.
Lat() || pos_lat_lon.
Lng() != pos_lat_lon.
Lng())
965 double latitude = pos_lat_lon.
Lat();
966 double longitude = pos_lat_lon.
Lng();
968 if (latitude != latitude)
970 else if (latitude > 90)
972 else if (latitude < -90)
975 if (longitude != longitude)
977 else if (longitude > 180)
979 else if (longitude < -180)
985 m_home_position.
altitude = altitude;
987 m_map->
Home->SetCoord(m_home_position.
coord);
988 m_map->
Home->SetAltitude(altitude);
992 keepMagicWaypointWithInSafeArea();
1000 if (!m_widget || !m_map)
1003 followUAVpositionAct->setChecked(
false);
1009 void OPMapGadgetWidget::zoomIn()
1011 if (!m_widget || !m_map)
1016 if (zoom < m_min_zoom)
1018 else if (zoom > m_max_zoom)
1024 void OPMapGadgetWidget::zoomOut()
1026 if (!m_widget || !m_map)
1031 if (zoom < m_min_zoom)
1033 else if (zoom > m_max_zoom)
1041 if (!m_widget || !m_map)
1048 if (update_rate < min_rate)
1049 update_rate = min_rate;
1050 else if (update_rate > max_rate)
1051 update_rate = max_rate;
1053 m_maxUpdateRate = update_rate;
1056 m_updateTimer->setInterval(m_maxUpdateRate);
1064 if (!m_widget || !m_map)
1067 if (zoom < m_min_zoom)
1069 else if (zoom > m_max_zoom)
1081 if (!m_widget || !m_map)
1084 overlayOpacityAct.at(value * 10)->setChecked(
true);
1089 if (!m_widget || !m_map)
1092 double latitude = pos.y();
1093 double longitude = pos.x();
1095 if (latitude != latitude || longitude != longitude)
1100 else if (latitude < -90)
1103 if (longitude > 180)
1105 else if (longitude < -180)
1113 if (!m_widget || !m_map)
1116 double latitude = pos.y();
1117 double longitude = pos.x();
1119 if (latitude != latitude || longitude != longitude)
1124 else if (latitude < -90)
1127 if (longitude > 180)
1129 else if (longitude < -180)
1136 if (!m_widget || !m_map)
1143 if (!m_widget || !m_map)
1150 if (!m_widget || !m_map)
1158 if (!m_widget || !m_map)
1166 if (!m_widget || !m_map)
1174 if (!m_widget || !m_map)
1177 cacheLocation = cacheLocation.simplified();
1179 if (cacheLocation.isEmpty())
1182 if (!cacheLocation.endsWith(QDir::separator()))
1183 cacheLocation += QDir::separator();
1186 if (!dir.exists(cacheLocation))
1187 if (!dir.mkpath(cacheLocation))
1194 if (!m_widget || !m_map)
1200 if (m_map_mode == mode) {
1203 m_widget->toolButtonMagicWaypointMapMode->setChecked(
false);
1204 m_widget->toolButtonNormalMapMode->setChecked(
true);
1207 m_widget->toolButtonNormalMapMode->setChecked(
false);
1208 m_widget->toolButtonMagicWaypointMapMode->setChecked(
true);
1218 m_widget->toolButtonMagicWaypointMapMode->setChecked(
false);
1219 m_widget->toolButtonNormalMapMode->setChecked(
true);
1221 hideMagicWaypointControls();
1223 magicWayPoint->setVisible(
false);
1231 m_widget->toolButtonNormalMapMode->setChecked(
false);
1232 m_widget->toolButtonMagicWaypointMapMode->setChecked(
true);
1234 showMagicWaypointControls();
1239 magicWayPoint->setVisible(
true);
1261 void OPMapGadgetWidget::createActions()
1265 if (!m_widget || !m_map)
1271 closeAct1 =
new QAction(tr(
"Close menu"),
this);
1272 closeAct1->setStatusTip(tr(
"Close the context menu"));
1274 closeAct2 =
new QAction(tr(
"Close menu"),
this);
1275 closeAct2->setStatusTip(tr(
"Close the context menu"));
1277 reloadAct =
new QAction(tr(
"&Reload map"),
this);
1278 reloadAct->setShortcut(tr(
"F5"));
1279 reloadAct->setStatusTip(tr(
"Reload the map tiles"));
1280 connect(reloadAct, &QAction::triggered,
this, &OPMapGadgetWidget::onReloadAct_triggered);
1281 this->addAction(reloadAct);
1282 ripAct =
new QAction(tr(
"&Rip map"),
this);
1283 ripAct->setStatusTip(tr(
"Rip the map tiles"));
1284 connect(ripAct, &QAction::triggered,
this, &OPMapGadgetWidget::onRipAct_triggered);
1286 copyMouseLatLonToClipAct =
new QAction(tr(
"Mouse latitude and longitude"),
this);
1287 copyMouseLatLonToClipAct->setStatusTip(
1288 tr(
"Copy the mouse latitude and longitude to the clipboard"));
1289 connect(copyMouseLatLonToClipAct, &QAction::triggered,
this,
1290 &OPMapGadgetWidget::onCopyMouseLatLonToClipAct_triggered);
1292 copyMouseLatToClipAct =
new QAction(tr(
"Mouse latitude"),
this);
1293 copyMouseLatToClipAct->setStatusTip(tr(
"Copy the mouse latitude to the clipboard"));
1294 connect(copyMouseLatToClipAct, &QAction::triggered,
this,
1295 &OPMapGadgetWidget::onCopyMouseLatToClipAct_triggered);
1297 copyMouseLonToClipAct =
new QAction(tr(
"Mouse longitude"),
this);
1298 copyMouseLonToClipAct->setStatusTip(tr(
"Copy the mouse longitude to the clipboard"));
1299 connect(copyMouseLonToClipAct, &QAction::triggered,
this,
1300 &OPMapGadgetWidget::onCopyMouseLonToClipAct_triggered);
1302 showCompassRoseAct =
new QAction(tr(
"Show compass"),
this);
1303 showCompassRoseAct->setStatusTip(tr(
"Show/Hide the compass"));
1304 showCompassRoseAct->setCheckable(
true);
1305 showCompassRoseAct->setChecked(
true);
1306 connect(showCompassRoseAct, &QAction::toggled,
this,
1307 &OPMapGadgetWidget::onShowCompassRoseAct_toggled);
1309 showWindCompassAction =
new QAction(tr(
"Show wind compass"),
this);
1310 showWindCompassAction->setStatusTip(tr(
"Show/Hide the wind compass"));
1311 showWindCompassAction->setCheckable(
true);
1312 showWindCompassAction->setChecked(
false);
1313 connect(showWindCompassAction, &QAction::toggled,
this,
1314 &OPMapGadgetWidget::onShowWindCompassAction_toggled);
1316 showDiagnostics =
new QAction(tr(
"Show Diagnostics"),
this);
1317 showDiagnostics->setStatusTip(tr(
"Show/Hide the diagnostics"));
1318 showDiagnostics->setCheckable(
true);
1319 showDiagnostics->setChecked(
false);
1320 connect(showDiagnostics, &QAction::toggled,
this,
1321 &OPMapGadgetWidget::onShowDiagnostics_toggled);
1323 showUAVInfo =
new QAction(tr(
"Show UAV Info"),
this);
1324 showUAVInfo->setStatusTip(tr(
"Show/Hide the UAV info"));
1325 showUAVInfo->setCheckable(
true);
1326 showUAVInfo->setChecked(
false);
1327 connect(showUAVInfo, &QAction::toggled,
this, &OPMapGadgetWidget::onShowUAVInfo_toggled);
1329 showHomeAct =
new QAction(tr(
"Show Home"),
this);
1330 showHomeAct->setStatusTip(tr(
"Show/Hide the Home location"));
1331 showHomeAct->setCheckable(
true);
1332 showHomeAct->setChecked(
true);
1333 connect(showHomeAct, &QAction::toggled,
this, &OPMapGadgetWidget::onShowHomeAct_toggled);
1335 showUAVAct =
new QAction(tr(
"Show UAV"),
this);
1336 showUAVAct->setStatusTip(tr(
"Show/Hide the UAV"));
1337 showUAVAct->setCheckable(
true);
1338 showUAVAct->setChecked(
true);
1339 connect(showUAVAct, &QAction::toggled,
this, &OPMapGadgetWidget::onShowUAVAct_toggled);
1341 changeDefaultLocalAndZoom =
new QAction(tr(
"Set default zoom and location"),
this);
1342 changeDefaultLocalAndZoom->setStatusTip(
1343 tr(
"Changes the map default zoom and location to the current values"));
1344 connect(changeDefaultLocalAndZoom, &QAction::triggered,
this,
1345 &OPMapGadgetWidget::onChangeDefaultLocalAndZoom);
1347 zoomInAct =
new QAction(tr(
"Zoom &In"),
this);
1348 zoomInAct->setShortcut(Qt::Key_PageUp);
1349 zoomInAct->setStatusTip(tr(
"Zoom the map in"));
1350 connect(zoomInAct, &QAction::triggered,
this, &OPMapGadgetWidget::onGoZoomInAct_triggered);
1351 this->addAction(zoomInAct);
1353 zoomOutAct =
new QAction(tr(
"Zoom &Out"),
this);
1354 zoomOutAct->setShortcut(Qt::Key_PageDown);
1355 zoomOutAct->setStatusTip(tr(
"Zoom the map out"));
1356 connect(zoomOutAct, &QAction::triggered,
this, &OPMapGadgetWidget::onGoZoomOutAct_triggered);
1357 this->addAction(zoomOutAct);
1359 goMouseClickAct =
new QAction(tr(
"Go to where you right clicked the mouse"),
this);
1360 goMouseClickAct->setStatusTip(tr(
"Center the map onto where you right clicked the mouse"));
1361 connect(goMouseClickAct, &QAction::triggered,
this,
1362 &OPMapGadgetWidget::onGoMouseClickAct_triggered);
1364 setHomeAct =
new QAction(tr(
"Set the home location"),
this);
1365 setHomeAct->setStatusTip(tr(
"Set the home location to where you clicked"));
1366 connect(setHomeAct, &QAction::triggered,
this, &OPMapGadgetWidget::onSetHomeAct_triggered);
1368 goHomeAct =
new QAction(tr(
"Go to &Home location"),
this);
1369 goHomeAct->setShortcut(tr(
"Ctrl+H"));
1370 goHomeAct->setStatusTip(tr(
"Center the map onto the home location"));
1371 connect(goHomeAct, &QAction::triggered,
this, &OPMapGadgetWidget::onGoHomeAct_triggered);
1373 goUAVAct =
new QAction(tr(
"Go to &UAV location"),
this);
1374 goUAVAct->setShortcut(tr(
"Ctrl+U"));
1375 goUAVAct->setStatusTip(tr(
"Center the map onto the UAV location"));
1376 connect(goUAVAct, &QAction::triggered,
this, &OPMapGadgetWidget::onGoUAVAct_triggered);
1378 followUAVpositionAct =
new QAction(tr(
"Follow UAV position"),
this);
1379 followUAVpositionAct->setShortcut(tr(
"Ctrl+F"));
1380 followUAVpositionAct->setStatusTip(tr(
"Keep the map centered onto the UAV"));
1381 followUAVpositionAct->setCheckable(
true);
1382 followUAVpositionAct->setChecked(
false);
1383 connect(followUAVpositionAct, &QAction::toggled,
this,
1384 &OPMapGadgetWidget::onFollowUAVpositionAct_toggled);
1386 followUAVheadingAct =
new QAction(tr(
"Follow UAV heading"),
this);
1387 followUAVheadingAct->setShortcut(tr(
"Ctrl+F"));
1388 followUAVheadingAct->setStatusTip(tr(
"Keep the map rotation to the UAV heading"));
1389 followUAVheadingAct->setCheckable(
true);
1390 followUAVheadingAct->setChecked(
false);
1391 connect(followUAVheadingAct, &QAction::toggled,
this,
1392 &OPMapGadgetWidget::onFollowUAVheadingAct_toggled);
1394 wayPointEditorAct =
new QAction(tr(
"&Waypoint editor"),
this);
1395 wayPointEditorAct->setShortcut(tr(
"Ctrl+W"));
1396 wayPointEditorAct->setStatusTip(tr(
"Open the waypoint editor"));
1397 connect(wayPointEditorAct, &QAction::triggered,
this,
1398 &OPMapGadgetWidget::onOpenWayPointEditorAct_triggered);
1400 addWayPointActFromContextMenu =
new QAction(tr(
"&Add waypoint"),
this);
1401 addWayPointActFromContextMenu->setShortcut(tr(
"Ctrl+A"));
1402 addWayPointActFromContextMenu->setStatusTip(tr(
"Add waypoint"));
1403 connect(addWayPointActFromContextMenu, &QAction::triggered,
this,
1404 &OPMapGadgetWidget::onAddWayPointAct_triggeredFromContextMenu);
1406 addWayPointActFromThis =
new QAction(tr(
"&Add waypoint"),
this);
1407 addWayPointActFromThis->setShortcut(tr(
"Ctrl+A"));
1408 addWayPointActFromThis->setStatusTip(tr(
"Add waypoint"));
1409 connect(addWayPointActFromThis, &QAction::triggered,
this,
1410 &OPMapGadgetWidget::onAddWayPointAct_triggeredFromThis);
1411 this->addAction(addWayPointActFromThis);
1413 editWayPointAct =
new QAction(tr(
"&Edit waypoint"),
this);
1414 editWayPointAct->setShortcut(tr(
"Ctrl+E"));
1415 editWayPointAct->setStatusTip(tr(
"Edit waypoint"));
1416 connect(editWayPointAct, &QAction::triggered,
this,
1417 &OPMapGadgetWidget::onEditWayPointAct_triggered);
1419 lockWayPointAct =
new QAction(tr(
"&Lock waypoint"),
this);
1420 lockWayPointAct->setStatusTip(tr(
"Lock/Unlock a waypoint"));
1421 lockWayPointAct->setCheckable(
true);
1422 lockWayPointAct->setChecked(
false);
1423 connect(lockWayPointAct, &QAction::triggered,
this,
1424 &OPMapGadgetWidget::onLockWayPointAct_triggered);
1426 deleteWayPointAct =
new QAction(tr(
"&Delete waypoint"),
this);
1427 deleteWayPointAct->setShortcut(tr(
"Ctrl+D"));
1428 deleteWayPointAct->setStatusTip(tr(
"Delete waypoint"));
1429 connect(deleteWayPointAct, &QAction::triggered,
this,
1430 &OPMapGadgetWidget::onDeleteWayPointAct_triggered);
1432 clearWayPointsAct =
new QAction(tr(
"&Clear waypoints"),
this);
1433 clearWayPointsAct->setShortcut(tr(
"Ctrl+C"));
1434 clearWayPointsAct->setStatusTip(tr(
"Clear waypoints"));
1435 connect(clearWayPointsAct, &QAction::triggered,
this,
1436 &OPMapGadgetWidget::onClearWayPointsAct_triggered);
1438 overlayOpacityActGroup =
new QActionGroup(
this);
1439 connect(overlayOpacityActGroup, &QActionGroup::triggered,
this,
1440 &OPMapGadgetWidget::onOverlayOpacityActGroup_triggered);
1441 overlayOpacityAct.clear();
1442 for (
int i = 0;
i <= 10;
i++) {
1443 QAction *overlayAct =
new QAction(QString::number(
i * 10), overlayOpacityActGroup);
1444 overlayAct->setCheckable(
true);
1445 overlayAct->setData(
i * 10);
1446 overlayOpacityAct.append(overlayAct);
1449 homeMagicWaypointAct =
new QAction(tr(
"Home magic waypoint"),
this);
1450 homeMagicWaypointAct->setStatusTip(tr(
"Move the magic waypoint to the home position"));
1451 connect(homeMagicWaypointAct, &QAction::triggered,
this,
1452 &OPMapGadgetWidget::onHomeMagicWaypointAct_triggered);
1454 mapModeActGroup =
new QActionGroup(
this);
1455 connect(mapModeActGroup, &QActionGroup::triggered,
this,
1456 &OPMapGadgetWidget::onMapModeActGroup_triggered);
1459 QAction *map_mode_act;
1461 map_mode_act =
new QAction(tr(
"Normal"), mapModeActGroup);
1462 map_mode_act->setCheckable(
true);
1465 mapModeAct.append(map_mode_act);
1467 map_mode_act =
new QAction(tr(
"Magic Waypoint"), mapModeActGroup);
1468 map_mode_act->setCheckable(
true);
1471 mapModeAct.append(map_mode_act);
1474 zoomActGroup =
new QActionGroup(
this);
1475 connect(zoomActGroup, &QActionGroup::triggered,
this,
1476 &OPMapGadgetWidget::onZoomActGroup_triggered);
1478 for (
int i = m_min_zoom;
i <= m_max_zoom;
i++) {
1479 QAction *zoom_act =
new QAction(QString::number(
i), zoomActGroup);
1480 zoom_act->setCheckable(
true);
1481 zoom_act->setData(
i);
1482 zoomAct.append(zoom_act);
1485 maxUpdateRateActGroup =
new QActionGroup(
this);
1486 connect(maxUpdateRateActGroup, &QActionGroup::triggered,
this,
1487 &OPMapGadgetWidget::onMaxUpdateRateActGroup_triggered);
1488 maxUpdateRateAct.clear();
1490 for (
int i = 0;
i < list_size;
i++) {
1491 QAction *maxUpdateRate_act;
1493 maxUpdateRate_act =
new QAction(QString::number(j), maxUpdateRateActGroup);
1494 maxUpdateRate_act->setCheckable(
true);
1495 maxUpdateRate_act->setData(j);
1496 maxUpdateRate_act->setChecked(j == m_maxUpdateRate);
1497 maxUpdateRateAct.append(maxUpdateRate_act);
1503 showSafeAreaAct =
new QAction(tr(
"Show Safe Area"),
this);
1504 showSafeAreaAct->setStatusTip(tr(
"Show/Hide the Safe Area around the home location"));
1505 showSafeAreaAct->setCheckable(
true);
1506 showSafeAreaAct->setChecked(m_map->
Home->ShowSafeArea());
1507 connect(showSafeAreaAct, &QAction::toggled,
this,
1508 &OPMapGadgetWidget::onShowSafeAreaAct_toggled);
1510 safeAreaActGroup =
new QActionGroup(
this);
1511 connect(safeAreaActGroup, &QActionGroup::triggered,
this,
1512 &OPMapGadgetWidget::onSafeAreaActGroup_triggered);
1513 safeAreaAct.clear();
1515 for (
int i = 0;
i < list_size;
i++) {
1517 QAction *safeArea_act =
new QAction(QString::number(safeArea) +
"m", safeAreaActGroup);
1518 safeArea_act->setCheckable(
true);
1519 safeArea_act->setChecked(safeArea == m_map->
Home->SafeArea());
1520 safeArea_act->setData(safeArea);
1521 safeAreaAct.append(safeArea_act);
1527 uavTrailTypeActGroup =
new QActionGroup(
this);
1528 connect(uavTrailTypeActGroup, &QActionGroup::triggered,
this,
1529 &OPMapGadgetWidget::onUAVTrailTypeActGroup_triggered);
1530 uavTrailTypeAct.clear();
1532 for (
int i = 0;
i < uav_trail_type_list.count();
i++) {
1533 mapcontrol::UAVTrailType::Types uav_trail_type =
1535 QAction *uavTrailType_act =
new QAction(
1537 uavTrailType_act->setCheckable(
true);
1538 uavTrailType_act->setChecked(uav_trail_type == m_map->
UAV->GetTrailType());
1539 uavTrailType_act->setData(
i);
1540 uavTrailTypeAct.append(uavTrailType_act);
1543 showTrailAct =
new QAction(tr(
"Show Trail dots"),
this);
1544 showTrailAct->setStatusTip(tr(
"Show/Hide the Trail dots"));
1545 showTrailAct->setCheckable(
true);
1546 showTrailAct->setChecked(
true);
1547 connect(showTrailAct, &QAction::toggled,
this, &OPMapGadgetWidget::onShowTrailAct_toggled);
1549 showTrailLineAct =
new QAction(tr(
"Show Trail lines"),
this);
1550 showTrailLineAct->setStatusTip(tr(
"Show/Hide the Trail lines"));
1551 showTrailLineAct->setCheckable(
true);
1552 showTrailLineAct->setChecked(
true);
1553 connect(showTrailLineAct, &QAction::toggled,
this,
1554 &OPMapGadgetWidget::onShowTrailLineAct_toggled);
1556 clearUAVtrailAct =
new QAction(tr(
"Clear UAV trail"),
this);
1557 clearUAVtrailAct->setStatusTip(tr(
"Clear the UAV trail"));
1558 connect(clearUAVtrailAct, &QAction::triggered,
this,
1559 &OPMapGadgetWidget::onClearUAVtrailAct_triggered);
1561 uavTrailTimeActGroup =
new QActionGroup(
this);
1562 connect(uavTrailTimeActGroup, &QActionGroup::triggered,
this,
1563 &OPMapGadgetWidget::onUAVTrailTimeActGroup_triggered);
1564 uavTrailTimeAct.clear();
1566 for (
int i = 0;
i < list_size;
i++) {
1568 QAction *uavTrailTime_act =
1569 new QAction(QString::number(uav_trail_time) +
" sec", uavTrailTimeActGroup);
1570 uavTrailTime_act->setCheckable(
true);
1571 uavTrailTime_act->setChecked(uav_trail_time == m_map->
UAV->TrailTime());
1572 uavTrailTime_act->setData(uav_trail_time);
1573 uavTrailTimeAct.append(uavTrailTime_act);
1576 uavTrailDistanceActGroup =
new QActionGroup(
this);
1577 connect(uavTrailDistanceActGroup, &QActionGroup::triggered,
this,
1578 &OPMapGadgetWidget::onUAVTrailDistanceActGroup_triggered);
1579 uavTrailDistanceAct.clear();
1581 for (
int i = 0;
i < list_size;
i++) {
1583 QAction *uavTrailDistance_act =
1584 new QAction(QString::number(uav_trail_distance) +
" meters", uavTrailDistanceActGroup);
1585 uavTrailDistance_act->setCheckable(
true);
1586 uavTrailDistance_act->setChecked(uav_trail_distance == m_map->
UAV->TrailDistance());
1587 uavTrailDistance_act->setData(uav_trail_distance);
1588 uavTrailDistanceAct.append(uavTrailDistance_act);
1592 void OPMapGadgetWidget::onReloadAct_triggered()
1594 if (!m_widget || !m_map)
1600 void OPMapGadgetWidget::onRipAct_triggered()
1605 void OPMapGadgetWidget::onCopyMouseLatLonToClipAct_triggered()
1607 QClipboard *clipboard = QApplication::clipboard();
1608 clipboard->setText(QString::number(m_context_menu_lat_lon.
Lat(),
'f', 7) +
", "
1609 + QString::number(m_context_menu_lat_lon.
Lng(),
'f', 7),
1610 QClipboard::Clipboard);
1613 void OPMapGadgetWidget::onCopyMouseLatToClipAct_triggered()
1615 QClipboard *clipboard = QApplication::clipboard();
1616 clipboard->setText(QString::number(m_context_menu_lat_lon.
Lat(),
'f', 7),
1617 QClipboard::Clipboard);
1620 void OPMapGadgetWidget::onCopyMouseLonToClipAct_triggered()
1622 QClipboard *clipboard = QApplication::clipboard();
1623 clipboard->setText(QString::number(m_context_menu_lat_lon.
Lng(),
'f', 7),
1624 QClipboard::Clipboard);
1627 void OPMapGadgetWidget::onShowCompassRoseAct_toggled(
bool show)
1629 if (!m_widget || !m_map)
1635 void OPMapGadgetWidget::onShowWindCompassAction_toggled(
bool show)
1637 if (!m_widget || !m_map)
1643 void OPMapGadgetWidget::onShowDiagnostics_toggled(
bool show)
1645 if (!m_widget || !m_map)
1651 void OPMapGadgetWidget::onShowUAVInfo_toggled(
bool show)
1653 if (!m_widget || !m_map)
1656 m_map->
UAV->SetShowUAVInfo(show);
1659 void OPMapGadgetWidget::onShowHomeAct_toggled(
bool show)
1661 if (!m_widget || !m_map)
1664 m_map->
Home->setVisible(show);
1667 void OPMapGadgetWidget::onShowUAVAct_toggled(
bool show)
1669 if (!m_widget || !m_map)
1672 m_map->
UAV->setVisible(show);
1674 m_map->
GPS->setVisible(show);
1677 void OPMapGadgetWidget::onShowTrailAct_toggled(
bool show)
1679 if (!m_widget || !m_map)
1682 m_map->
UAV->SetShowTrail(show);
1684 m_map->
GPS->SetShowTrail(show);
1687 void OPMapGadgetWidget::onShowTrailLineAct_toggled(
bool show)
1689 if (!m_widget || !m_map)
1692 m_map->
UAV->SetShowTrailLine(show);
1694 m_map->
GPS->SetShowTrailLine(show);
1697 void OPMapGadgetWidget::onMapModeActGroup_triggered(QAction *action)
1699 if (!m_widget || !m_map || !action)
1707 void OPMapGadgetWidget::onGoZoomInAct_triggered()
1712 void OPMapGadgetWidget::onGoZoomOutAct_triggered()
1717 void OPMapGadgetWidget::onZoomActGroup_triggered(QAction *action)
1719 if (!m_widget || !m_map || !action)
1722 setZoom(action->data().toInt());
1725 void OPMapGadgetWidget::onMaxUpdateRateActGroup_triggered(QAction *action)
1727 if (!m_widget || !m_map || !action)
1733 void OPMapGadgetWidget::onChangeDefaultLocalAndZoom()
1739 void OPMapGadgetWidget::onGoMouseClickAct_triggered()
1741 if (!m_widget || !m_map)
1748 void OPMapGadgetWidget::onSetHomeAct_triggered()
1750 if (!m_widget || !m_map)
1758 altitude = QInputDialog::getDouble(
this, tr(
"Set home altitude"),
1759 tr(
"In [m], referenced to WGS84 geoid:"), altitude, -100,
1763 setHome(m_context_menu_lat_lon, altitude);
1766 setHomeLocationObject();
1769 void OPMapGadgetWidget::onGoHomeAct_triggered()
1771 if (!m_widget || !m_map)
1777 void OPMapGadgetWidget::onGoUAVAct_triggered()
1779 if (!m_widget || !m_map)
1785 if (getUAVPosition(latitude, longitude, altitude))
1790 if (map_pos != uav_pos)
1795 void OPMapGadgetWidget::onFollowUAVpositionAct_toggled(
bool checked)
1797 if (!m_widget || !m_map)
1800 if (m_widget->toolButtonMapUAV->isChecked() != checked)
1801 m_widget->toolButtonMapUAV->setChecked(checked);
1803 setMapFollowingMode();
1806 void OPMapGadgetWidget::onFollowUAVheadingAct_toggled(
bool checked)
1808 if (!m_widget || !m_map)
1811 if (m_widget->toolButtonMapUAVheading->isChecked() != checked)
1812 m_widget->toolButtonMapUAVheading->setChecked(checked);
1814 setMapFollowingMode();
1817 void OPMapGadgetWidget::onUAVTrailTypeActGroup_triggered(QAction *action)
1819 if (!m_widget || !m_map || !action)
1822 int trail_type_idx = action->data().toInt();
1825 mapcontrol::UAVTrailType::Types uav_trail_type =
1828 m_map->
UAV->SetTrailType(uav_trail_type);
1831 void OPMapGadgetWidget::onClearUAVtrailAct_triggered()
1833 if (!m_widget || !m_map)
1836 m_map->
UAV->DeleteTrail();
1838 m_map->
GPS->DeleteTrail();
1841 void OPMapGadgetWidget::onUAVTrailTimeActGroup_triggered(QAction *action)
1843 if (!m_widget || !m_map || !action)
1846 int trail_time = (double)action->data().toInt();
1848 m_map->
UAV->SetTrailTime(trail_time);
1851 void OPMapGadgetWidget::onUAVTrailDistanceActGroup_triggered(QAction *action)
1853 if (!m_widget || !m_map || !action)
1856 int trail_distance = action->data().toInt();
1858 m_map->
UAV->SetTrailDistance(trail_distance);
1865 void OPMapGadgetWidget::onOpenWayPointEditorAct_triggered()
1868 pathPlannerDialog =
new QDialog(
this);
1869 pathPlannerDialog->setModal(
true);
1872 QHBoxLayout *dialogLayout =
new QHBoxLayout(pathPlannerDialog);
1873 pathPlannerDialog->setLayout(dialogLayout);
1876 dialogLayout->addWidget(widget);
1877 pathPlannerDialog->show();
1878 pathPlannerDialog->resize(850, 300);
1881 void OPMapGadgetWidget::onAddWayPointAct_triggeredFromContextMenu()
1883 onAddWayPointAct_triggered(m_context_menu_lat_lon);
1885 void OPMapGadgetWidget::onAddWayPointAct_triggeredFromThis()
1887 onAddWayPointAct_triggered(lastLatLngMouse);
1892 if (!m_widget || !m_map)
1895 if (m_map_mode != Normal_MapMode)
1898 mapProxy->createWayPoint(coord);
1906 void OPMapGadgetWidget::onEditWayPointAct_triggered()
1918 void OPMapGadgetWidget::onLockWayPointAct_triggered()
1920 if (!m_widget || !m_map || !m_mouse_waypoint)
1923 if (m_map_mode != Normal_MapMode)
1926 bool locked = (m_mouse_waypoint->flags() & QGraphicsItem::ItemIsMovable) == 0;
1927 m_mouse_waypoint->setFlag(QGraphicsItem::ItemIsMovable, locked);
1930 m_mouse_waypoint->picture.load(QString::fromUtf8(
":/opmap/images/waypoint_marker2.png"));
1932 m_mouse_waypoint->picture.load(QString::fromUtf8(
":/opmap/images/waypoint_marker1.png"));
1933 m_mouse_waypoint->update();
1935 m_mouse_waypoint = NULL;
1938 void OPMapGadgetWidget::onDeleteWayPointAct_triggered()
1940 if (!m_widget || !m_map)
1943 if (m_map_mode != Normal_MapMode)
1946 if (!m_mouse_waypoint)
1949 mapProxy->deleteWayPoint(m_mouse_waypoint->Number());
1952 void OPMapGadgetWidget::onClearWayPointsAct_triggered()
1956 QMessageBox msgBox(
this);
1957 msgBox.setText(tr(
"Are you sure you want to clear waypoints?"));
1958 msgBox.setInformativeText(tr(
"All associated data will be lost."));
1959 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
1960 int ret = msgBox.exec();
1962 if (ret == QMessageBox::No) {
1966 if (!m_widget || !m_map)
1969 if (m_map_mode != Normal_MapMode)
1972 mapProxy->deleteAll();
1975 void OPMapGadgetWidget::onHomeMagicWaypointAct_triggered()
1978 homeMagicWaypoint();
1981 void OPMapGadgetWidget::onShowSafeAreaAct_toggled(
bool show)
1983 if (!m_widget || !m_map)
1986 m_map->
Home->SetShowSafeArea(show);
1987 m_map->
Home->SetToggleRefresh(
true);
1991 void OPMapGadgetWidget::onSafeAreaActGroup_triggered(QAction *action)
1993 if (!m_widget || !m_map || !action)
1996 int radius = action->data().toInt();
1998 m_map->
Home->SetSafeArea(radius);
2002 keepMagicWaypointWithInSafeArea();
2008 void OPMapGadgetWidget::homeMagicWaypoint()
2010 if (!m_widget || !m_map)
2013 if (m_map_mode != MagicWaypoint_MapMode)
2016 magicWayPoint->SetCoord(m_home_position.
coord);
2022 void OPMapGadgetWidget::moveToMagicWaypointPosition()
2024 if (!m_widget || !m_map)
2027 if (m_map_mode != MagicWaypoint_MapMode)
2034 void OPMapGadgetWidget::hideMagicWaypointControls()
2036 m_widget->lineWaypoint->setVisible(
false);
2037 m_widget->toolButtonHomeWaypoint->setVisible(
false);
2038 m_widget->toolButtonMoveToWP->setVisible(
false);
2041 void OPMapGadgetWidget::showMagicWaypointControls()
2043 m_widget->lineWaypoint->setVisible(
true);
2044 m_widget->toolButtonHomeWaypoint->setVisible(
true);
2046 m_widget->toolButtonMoveToWP->setVisible(
true);
2052 void OPMapGadgetWidget::keepMagicWaypointWithInSafeArea()
2056 double dist = distance(m_home_position.
coord, magicWayPoint->Coord());
2057 double bear = bearing(m_home_position.
coord, magicWayPoint->Coord());
2060 double boundry_dist = (double)m_map->
Home->SafeArea() / 1000;
2062 if (dist > boundry_dist)
2063 dist = boundry_dist;
2067 if (m_map_mode == MagicWaypoint_MapMode) {
2069 magicWayPoint->SetCoord(destPoint(m_home_position.
coord, bear, dist));
2078 double lat1 = from.
Lat() * deg_to_rad;
2079 double lon1 = from.
Lng() * deg_to_rad;
2081 double lat2 = to.
Lat() * deg_to_rad;
2082 double lon2 = to.
Lng() * deg_to_rad;
2084 return (acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1))
2085 * earth_mean_radius);
2095 double lat1 = from.
Lat() * deg_to_rad;
2096 double lon1 = from.
Lng() * deg_to_rad;
2098 double lat2 = to.
Lat() * deg_to_rad;
2099 double lon2 = to.
Lng() * deg_to_rad;
2102 double delta_lon = lon2 - lon1;
2104 double y = sin(delta_lon) * cos(lat2);
2105 double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(delta_lon);
2106 double bear = atan2(y, x) * rad_to_deg;
2124 double lat1 = source.
Lat() * deg_to_rad;
2125 double lon1 = source.
Lng() * deg_to_rad;
2129 double ad = dist / earth_mean_radius;
2131 double lat2 = asin(sin(lat1) * cos(ad) + cos(lat1) * sin(ad) * cos(bear));
2132 double lon2 = lon1 + atan2(sin(bear) * sin(ad) * cos(lat1), cos(ad) - sin(lat1) * sin(lat2));
2139 bool OPMapGadgetWidget::getUAVPosition(
double &latitude,
double &longitude,
double &altitude)
2145 Q_ASSERT(uavo_mgr != NULL);
2147 HomeLocation *homeLocation = HomeLocation::GetInstance(uavo_mgr);
2148 Q_ASSERT(homeLocation != NULL);
2149 HomeLocation::DataFields homeLocationData = homeLocation->getData();
2151 homeLLA[0] = homeLocationData.Latitude / 1e7;
2152 homeLLA[1] = homeLocationData.Longitude / 1e7;
2153 homeLLA[2] = homeLocationData.Altitude;
2155 PositionActual *positionActual = PositionActual::GetInstance(uavo_mgr);
2156 Q_ASSERT(positionActual != NULL);
2157 PositionActual::DataFields positionActualData = positionActual->getData();
2159 NED[0] = positionActualData.North;
2160 NED[1] = positionActualData.East;
2161 NED[2] = positionActualData.Down;
2169 if (latitude != latitude)
2171 else if (latitude > 90)
2173 else if (latitude < -90)
2176 if (longitude != longitude)
2178 else if (longitude > 180)
2180 else if (longitude < -180)
2183 if (altitude != altitude)
2189 double OPMapGadgetWidget::getUAV_Yaw()
2209 void OPMapGadgetWidget::setMapFollowingMode()
2211 if (!m_widget || !m_map)
2214 if (!followUAVpositionAct->isChecked()) {
2215 m_map->
UAV->SetMapFollowType(UAVMapFollowType::None);
2217 }
else if (!followUAVheadingAct->isChecked()) {
2218 m_map->
UAV->SetMapFollowType(UAVMapFollowType::CenterMap);
2221 m_map->
UAV->SetMapFollowType(UAVMapFollowType::CenterMap);
2225 m_map->
UAV->SetUAVHeading(0);
2226 m_map->
UAV->SetMapFollowType(UAVMapFollowType::CenterAndRotateMap);
2233 bool OPMapGadgetWidget::setHomeLocationObject()
2238 double LLA[3] = { m_home_position.
coord.
Lat(), m_home_position.
coord.
Lng(),
2251 void OPMapGadgetWidget::on_tbFind_clicked()
2253 QPalette pal = m_widget->leFind->palette();
2255 GeoCoderStatusCode::Types result =
2257 if (result == core::GeoCoderStatusCode::OK) {
2258 pal.setColor(m_widget->leFind->backgroundRole(), Qt::green);
2259 m_widget->leFind->setPalette(pal);
2262 pal.setColor(m_widget->leFind->backgroundRole(), Qt::red);
2263 m_widget->leFind->setPalette(pal);
2267 void OPMapGadgetWidget::onHomeDoubleClick(HomeItem *)
2272 void OPMapGadgetWidget::onOverlayOpacityActGroup_triggered(QAction *action)
2274 if (!m_widget || !m_map || !action)
2281 void OPMapGadgetWidget::on_leFind_returnPressed()
2283 on_tbFind_clicked();
2286 void OPMapGadgetWidget::updateWindspeed(
UAVObject *obj)
2290 WindVelocityActual *windVelocityActual = WindVelocityActual::GetInstance(uavo_mgr);
2291 WindVelocityActual::DataFields windVelocityActualData;
2292 windVelocityActualData = windVelocityActual->getData();
2294 double windVelocity_NED[3] = { windVelocityActualData.North, windVelocityActualData.East,
2295 windVelocityActualData.Down };
void contextMenuEvent(QContextMenuEvent *event)
void setHomePosition(QPointF pos)
void setUseMemoryCache(bool useMemoryCache)
void setCacheLocation(QString cacheLocation)
void SetUavPic(QString UAVPic)
void closeEvent(QCloseEvent *)
const int safe_area_radius_list[]
void setMapProvider(QString provider)
double getDouble(int index=0) const
Core plugin system that manages the plugins, their life cycle and their registered objects...
void overlayOpacityChanged(qreal)
void setGeoCodingLanguage(QString language)
axis equal end function NED
void LLA2NED_HomeLLA(double LLA[3], double homeLLA[3], double NED[3])
void setShowTileGridLines(bool showTileGridLines)
void objectUpdated(UAVObject *obj)
Signal sent whenever any field of the object is updated.
void setUserImageHorizontalScale(double userImageHorizontalScale)
The WaypointDialog class creates a dialog for editing the properties of a single waypoint.
void setMaxUpdateRate(int update_rate)
The ModelMapProxy class maps from the FlightDataModel to the OPMap and provides synchronization, both when the model changes updating the UI and if it is modified on the UI propagating changes to the model.
void homePositionUpdated(UAVObject *)
void setUserImageVerticalScale(double userImageVerticalScale)
UAVObjectField * getField(const QString &name)
void setPosition(QPointF pos)
void defaultLocationAndZoomChanged(double lng, double lat, double zoom)
void setOverlayOpacity(qreal value)
int NED2LLA_HomeLLA(double homeLLA[3], double NED[3], double LLA[3])
void onTelemetryConnect()
const int max_update_rate_list[]
const int uav_trail_time_list[]
void setMapMode(opMapModeType mode)
A QGraphicsItem representing a WayPoint.
int setHomeLocation(double LLA[3], bool save_to_sdcard)
const int uav_trail_distance_list[]
internals::PointLatLng coord
void setHome(QPointF pos)
public functions
OPMapGadgetWidget(QWidget *parent=nullptr)
UAVObject * getObject(const QString &name, quint32 instId=0)
void setUserImageLocation(QString userImageLocation)
void onTelemetryDisconnect()
void resizeEvent(QResizeEvent *event)
void setAccessMode(QString accessMode)
int getHomeLocation(bool &set, double LLA[3])
void mouseMoveEvent(QMouseEvent *event)