From 1741825ee25f14d1b9eec079a6327d306553a7e9 Mon Sep 17 00:00:00 2001 From: pip Date: Thu, 7 Oct 2010 07:09:00 +0000 Subject: [PATCH] Added 'map modes' to the opmap plug-in. "Nomral map mode" and "Magic waypoint map mode". Not yet complete! git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1911 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/opmap/images/minus.png | Bin 1006 -> 1006 bytes ground/src/plugins/opmap/images/plus.png | Bin 1115 -> 1115 bytes .../plugins/opmap/images/waypoint_marker3.png | Bin 0 -> 1613 bytes ground/src/plugins/opmap/opmap.qrc | 5 +- ground/src/plugins/opmap/opmap_widget.ui | 315 ++++++++++-- .../src/plugins/opmap/opmapgadgetwidget.cpp | 456 +++++++++++++++--- ground/src/plugins/opmap/opmapgadgetwidget.h | 32 +- 7 files changed, 694 insertions(+), 114 deletions(-) create mode 100644 ground/src/plugins/opmap/images/waypoint_marker3.png diff --git a/ground/src/plugins/opmap/images/minus.png b/ground/src/plugins/opmap/images/minus.png index 2088a3a58cf755ee00d2dbcc67ed1d32abc3b4ff..d0b6eb30d9c5562d137d68b94dee97a3e0228064 100644 GIT binary patch delta 124 zcmaFI{*HY@GA9>1tAYmKo8L|oa}2HQ85&U0|NV{s&(8gSYC01mLzW4{uNsE`oudCw z&-{OL^Zy42|35ws6b#W~nCG|g;VhWSq3i#8Ml9(6|C7^>-<~{|IS>FU C_dI+6 delta 125 zcmaFI{*HY@GAEn3fC)FRVq3z*97Agc28ITPh6WG?q=Cc%Ah>g2*{KhVjEttHrnR-T zU0q#g&YZb<^X7vG4<0{$3>4JT((?EB-}rDA)5H&)O8G8Lqo%Vpeg?u{(~tX R4P*g<)u~M}ljkxA0syUtI(Gm7 diff --git a/ground/src/plugins/opmap/images/plus.png b/ground/src/plugins/opmap/images/plus.png index 2b07a753f1b67d07389888433d5fd9e7ff2efcc9..56e9b4f90ca85aef32baedeedc64eea3978f2d86 100644 GIT binary patch delta 156 zcmcc3ahqd8GA9>1tAcS$r_s8JIffDT3=OF0|Nh4RXXpMuHJyQhA<|If4kzdrH*_QLw z^!V{(e}DhYjEq%GlLZ*LmHz+!uwcQGhK7d!KqLP%{0CD&8pr|y!MIyjC(mWx2LSHA BRPX=* diff --git a/ground/src/plugins/opmap/images/waypoint_marker3.png b/ground/src/plugins/opmap/images/waypoint_marker3.png new file mode 100644 index 0000000000000000000000000000000000000000..bd86af025460b0a36bdb8265d57eda59a3fc6b86 GIT binary patch literal 1613 zcmV-T2D15yP)zc>Z4l#4` zF=$W;$ym01h8t+o7BS2=3Fwg1#NThu@hu=t@e0;YRyt+HC1~Es5zc`ruO)>6y~0O9 z?g%igs;&}qUY`oAjZCaXE!g?hd|_6D)4PzMf!nt`-eBhKH45MSw8EL=0yG047e}TDu(NLuQu16uM#ttMYCrs| zWC>|FBYB^9ibn)yY1nhAGHOQaicWzHW(N?YXELzEg&1cx`54%j7;BF)`Q_m{1W^2} zRinnBZ0a(DA!W0o)%^|>2rj{T*LEeSEJ`dMOLZ5{$yCdgN-CAz=WVLL4G21p13@BL zu$)6iLbjH!W_!vVx_gsuuD?c8)Oy)-NC!Htduc7v-uByyf{K?|CKS%hSyYUgZZTpA zUeYBNZ)t2U$E-8Ye!OJHYxVEQov|2n@8r12=k14wLT>|2+ zP>Mt5txQ*G-yiQ?r0eCYF47ox1u7}oRwMuzQiSyq<_P6dc`6JVZsc$Vm%n8x`jm3g zg2{JAkLs7d_~onmrQWfybq z)q!skk?o&+E>Lamdf8`cg{4iFOf|!Hj9C#X-ZH6oXH4*{guv^0!{mgQwQAWzS2$j| zx@T11)AprI6D$D=aBPB!GinV}HkqUA-zRDGWUd4v40dT;V+DG98@SuUD*ivmvFY?1 zgLGU!BGUy!fJ0mOJ7L5qek$({9Y|yS`wVtsa$6}peMzhJP-woF{0$n|{G@oq4{cjd z!Z|K0DHkGLc)S#`XkdRr*oJeAPw)PJpDJdWDe@nWd#ZiHPt}jI>8GpPxbm3;@m7I; zM3K<+=)2+HbjoxWaqreUIY=?m7M>C0@hcRX=cAe>ehSXy`ac^rQ=4qg}8z za!AL0zi|9{M?h(tQJd_7BMn}&kXbJ95kH)Eu>*1^^rHe*M$71zOQiRr4z%lT9#^Ch&dSN zRzYJY&lIry(7mRRiiM6zWbktr6GQM8zIv4upTKq}*jky3`O~#%o!m8P%Om#$9JiHZ z$u@)pYDgIawAf`CyEA$rzLMGU#_lkUy*b<)P^N7-^6kK4V1V(Pg9PV7{gu61URjwB zogDcG0(7}1rtZjLi33`yH41Fm&48GBbU$|g1+1iv!eC&?5s1Q@?v3n~GR72^^*k`3 zOuNK@+(J&CN4#dsLNT*=;#7WY6QaR~0)%F;B3j5c6wFD=^_R2!yagIYy#8>2%mVg; zUP@X>SESAtF^images/ok.png images/uav.png images/gcs.png - images/plus.png - images/minus.png images/waypoint.png images/right_but.png images/left_but.png @@ -21,5 +19,8 @@ images/uav_heading.png images/uav_trail.png images/uav_trail_clear.png + images/minus.png + images/plus.png + images/waypoint_marker3.png diff --git a/ground/src/plugins/opmap/opmap_widget.ui b/ground/src/plugins/opmap/opmap_widget.ui index f6398b4ac..3b3ac80aa 100644 --- a/ground/src/plugins/opmap/opmap_widget.ui +++ b/ground/src/plugins/opmap/opmap_widget.ui @@ -6,8 +6,8 @@ 0 0 - 548 - 565 + 514 + 412 @@ -30,8 +30,253 @@ 0 - 0 + 1 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 32 + + + + Qt::NoContextMenu + + + QFrame{ +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(110, 110, 110, 255), stop:1 rgba(71, 71, 71, 255)); +color: rgba(0, 0, 0, 128); +} + +QLabel { +background-color: transparent; +/* background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(0, 0, 0, 80), stop:1 rgba(0, 0, 0, 80)); */ +color: rgb(255, 255, 255); +/*border: 1px solid black;*/ +border: none; +border-radius: 2px; +} + +QToolButton { /* all types of tool button */ +background-color: transparent; +color: rgb(255, 255, 255); +/*border-style: none;*/ +/* border: 1px solid rgba(0, 0, 0, 64); */ +/* border: 0px; */ +border-radius: 3px; +} +QToolButton:hover { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(255, 255, 255, 200), stop:1 rgba(180, 180, 180, 200)); +color: rgb(255, 255, 255); +border: 0px; +border-radius: 3px; +} +QToolButton:pressed { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(48, 48, 48, 255), stop:1 rgba(120, 120, 120, 255)); +color: rgb(255, 255, 255); +border: 0px; +border-radius: 3px; +} + +QToolButton:checked { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(48, 48, 48, 255), stop:1 rgba(120, 120, 120, 255)); +color: rgb(255, 255, 255); +border: 0px; +border-radius: 3px; +} + + +QComboBox { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(48, 48, 48, 255), stop:1 rgba(120, 120, 120, 255)); +color: rgba(255, 255, 255, 255); +border: 1px solid rgba(0, 0, 0, 128); +border-radius: 0px; +} +QComboBox::down-arrow:on { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(48, 48, 48, 255), stop:1 rgba(120, 120, 120, 255)); +top: 1px; left: 1px; /* move the arrow when the popup is open */ +} +QComboBox::down-arrow { + image: url(:/opmap/images/combobox_down_arrow.png); +} +QComboBox:drop-down { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(110, 110, 110, 255), stop:1 rgba(71, 71, 71, 255)); +border-left: 1px solid rgba(0, 0, 0, 128); +/* subcontrol-origin: padding; + subcontrol-position: top right; + border-top-right-radius: 1px; + border-bottom-right-radius: 1px; */ +} +QComboBox QAbstractItemView { /* the drop down list */ +background-color: rgb(255, 255, 255); +color: rgb(0, 0, 0); +border: 1px solid rgba(0, 0, 0, 128); +selection-background-color: rgb(160, 160, 255); +border-radius: 2px; +} + + + + QFrame::NoFrame + + + QFrame::Plain + + + + 0 + + + 0 + + + 2 + + + 0 + + + 2 + + + + + 5 + + + 3 + + + 8 + + + + + Qt::Horizontal + + + + 10 + 20 + + + + + + + + + + + + :/core/images/prev.png:/core/images/prev.png + + + + 32 + 32 + + + + false + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + + MS Sans Serif + 12 + 75 + false + true + true + + + + Mouse position + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + labelMapMode + + + Qt::AlignCenter + + + 5 + + + + + + + ... + + + + :/core/images/next.png:/core/images/next.png + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + + 10 + 20 + + + + + + + + + @@ -149,14 +394,14 @@ border-radius: 2px; - + 0 0 - 0 + 20 0 @@ -623,7 +868,7 @@ QTreeView::branch:open:has-children:!has-siblings, QTreeView::branch:open:has-ch false - true + false @@ -819,24 +1064,21 @@ border-radius: 3px; QFrame::NoFrame - QFrame::Raised + QFrame::Plain + + + 2 + + + 0 - 3 + 5 - + 1 - - 6 - - - 1 - - - 0 - @@ -899,7 +1141,7 @@ border-radius: 3px; 0 - 80 + 50 @@ -1119,38 +1361,6 @@ border-radius: 3px; - - - - Clear the UAV trail - - - - - - - - - - :/opmap/images/uav_trail_clear.png:/opmap/images/uav_trail_clear.png - - - - 28 - 28 - - - - false - - - false - - - false - - - @@ -1225,6 +1435,9 @@ color: rgb(255, 255, 255); QFrame::NoFrame + + QFrame::Plain + 1 diff --git a/ground/src/plugins/opmap/opmapgadgetwidget.cpp b/ground/src/plugins/opmap/opmapgadgetwidget.cpp index 9c3245eb3..8b14a3513 100644 --- a/ground/src/plugins/opmap/opmapgadgetwidget.cpp +++ b/ground/src/plugins/opmap/opmapgadgetwidget.cpp @@ -66,6 +66,17 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) min_zoom = max_zoom = 0; + m_map_mode = Normal_MapMode; + + // default magic waypoint params + magic_waypoint.map_wp_item = NULL; + magic_waypoint.coord = internals::PointLatLng(0.0, 0.0); + magic_waypoint.altitude = 0.0; + magic_waypoint.description = "Magic waypoint"; + magic_waypoint.locked = false; + magic_waypoint.time_seconds = 0; + magic_waypoint.hold_time_seconds = 0; + // ************** // fetch required UAVObjects @@ -147,6 +158,21 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) // ************** // set the user control options + switch (m_map_mode) + { + case Normal_MapMode: + m_widget->labelMapMode->setText("Normal mode"); + break; + + case MagicWaypoint_MapMode: + m_widget->labelMapMode->setText("Magic Waypoint mode"); + break; + + default: + m_widget->labelMapMode->setText("Unknown mode"); + break; + } + m_widget->labelUAVPos->setText("---"); m_widget->labelMapPos->setText("---"); m_widget->labelMousePos->setText("---"); @@ -329,7 +355,19 @@ OPMapGadgetWidget::~OPMapGadgetWidget() // #else // #endif - onClearWayPointsAct_triggered(); + m_waypoint_list_mutex.lock(); + foreach (t_waypoint *wp, m_waypoint_list) + { + if (!wp) continue; + + + // todo: + + + delete wp->map_wp_item; + } + m_waypoint_list_mutex.unlock(); + m_waypoint_list.clear(); if (m_zoom_slider_widget) delete m_zoom_slider_widget; if (m_statusbar_widget) delete m_statusbar_widget; @@ -372,6 +410,8 @@ void OPMapGadgetWidget::mouseMoveEvent(QMouseEvent *event) void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) { + QString s; + if (!m_widget || !m_map) return; @@ -409,6 +449,26 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) menu.addSeparator(); + switch (m_map_mode) + { + case Normal_MapMode: s = tr(" (Normal)"); break; + case MagicWaypoint_MapMode: s = tr(" (Magic Waypoint)"); break; + default: s = tr(" (Unknown)"); break; + } + for (int i = 0; i < mapModeAct.count(); i++) + { // set the menu to checked (or not) + QAction *act = mapModeAct.at(i); + if (!act) continue; + if (act->data().toInt() == (int)m_map_mode) + act->setChecked(true); + } + QMenu mapModeSubMenu(tr("Map mode") + s, this); + for (int i = 0; i < mapModeAct.count(); i++) + mapModeSubMenu.addAction(mapModeAct.at(i)); + menu.addMenu(&mapModeSubMenu); + + menu.addSeparator(); + QMenu copySubMenu(tr("Copy"), this); copySubMenu.addAction(copyMouseLatLonToClipAct); copySubMenu.addAction(copyMouseLatToClipAct); @@ -430,7 +490,7 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) QMenu zoomSubMenu(tr("&Zoom ") + "(" + QString::number(m_map->ZoomReal()) + ")", this); for (int i = 0; i < zoomAct.count(); i++) - zoomSubMenu.addAction(zoomAct.at(i)); + zoomSubMenu.addAction(zoomAct.at(i)); menu.addMenu(&zoomSubMenu); menu.addSeparator(); @@ -450,26 +510,36 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) menu.addAction(followUAVheadingAct); menu.addAction(goUAVAct); - menu.addSeparator()->setText(tr("Waypoints")); + menu.addAction(clearUAVtrailAct); - menu.addAction(wayPointEditorAct); - menu.addAction(addWayPointAct); + // ********* - if (m_mouse_waypoint) - { // we have a waypoint under the mouse - menu.addAction(editWayPointAct); + if (m_map_mode == Normal_MapMode) + { // only show the waypoint stuff if not in 'magic waypoint' mode - lockWayPointAct->setChecked(waypoint_locked); - menu.addAction(lockWayPointAct); + menu.addSeparator()->setText(tr("Waypoints")); - if (!waypoint_locked) - menu.addAction(deleteWayPointAct); + menu.addAction(wayPointEditorAct); + menu.addAction(addWayPointAct); + + if (m_mouse_waypoint) + { // we have a waypoint under the mouse + menu.addAction(editWayPointAct); + + lockWayPointAct->setChecked(waypoint_locked); + menu.addAction(lockWayPointAct); + + if (!waypoint_locked) + menu.addAction(deleteWayPointAct); + } + + m_waypoint_list_mutex.lock(); + if (m_waypoint_list.count() > 0) + menu.addAction(clearWayPointsAct); // we have waypoints + m_waypoint_list_mutex.unlock(); } - m_waypoint_list_mutex.lock(); - if (m_waypoint_list.count() > 0) - menu.addAction(clearWayPointsAct); // we have waypoints - m_waypoint_list_mutex.unlock(); + // ********* // menu.addSeparator(); @@ -529,6 +599,8 @@ void OPMapGadgetWidget::updatePosition() if (!m_widget || !m_map) return; + QMutexLocker locker(&m_map_mutex); + QPointF pos = getLatLon(); internals::PointLatLng uav_pos = internals::PointLatLng(pos.x(), pos.y()); // current UAV position @@ -553,6 +625,8 @@ void OPMapGadgetWidget::updateMousePos() if (!m_widget || !m_map) return; + QMutexLocker locker(&m_map_mutex); + internals::PointLatLng lat_lon = m_map->currentMousePosition(); // fetch the current lat/lon mouse position if (mouse_lat_lon == lat_lon) @@ -666,8 +740,37 @@ void OPMapGadgetWidget::WPNumberChanged(int const &oldnumber, int const &newnumb void OPMapGadgetWidget::WPValuesChanged(WayPointItem *waypoint) { - Q_UNUSED(waypoint); - // to do + qDebug("WPValuesChanged"); + + switch (m_map_mode) + { + case Normal_MapMode: + m_waypoint_list_mutex.lock(); + foreach (t_waypoint *wp, m_waypoint_list) + { // search for the waypoint in our own waypoint list and update it + if (!wp) continue; + if (!wp->map_wp_item) continue; + if (wp->map_wp_item != waypoint) continue; + // found the waypoint in our list + wp->coord = waypoint->Coord(); + wp->altitude = waypoint->Altitude(); + wp->description = waypoint->Description(); + break; + } + m_waypoint_list_mutex.unlock(); + break; + + case MagicWaypoint_MapMode: + // update our copy of the magic waypoint + if (magic_waypoint.map_wp_item && magic_waypoint.map_wp_item == waypoint) + { + magic_waypoint.coord = waypoint->Coord(); + magic_waypoint.altitude = waypoint->Altitude(); + magic_waypoint.description = waypoint->Description(); + } + break; + } + } void OPMapGadgetWidget::WPInserted(int const &number, WayPointItem *waypoint) @@ -732,16 +835,19 @@ void OPMapGadgetWidget::on_toolButtonFindPlace_clicked() void OPMapGadgetWidget::on_toolButtonZoomP_clicked() { + QMutexLocker locker(&m_map_mutex); zoomIn(); } void OPMapGadgetWidget::on_toolButtonZoomM_clicked() { + QMutexLocker locker(&m_map_mutex); zoomOut(); } void OPMapGadgetWidget::on_toolButtonMapHome_clicked() { + QMutexLocker locker(&m_map_mutex); goHome(); } @@ -750,6 +856,8 @@ void OPMapGadgetWidget::on_toolButtonMapUAV_clicked() if (!m_widget || !m_map) return; + QMutexLocker locker(&m_map_mutex); + followUAVpositionAct->toggle(); } @@ -758,6 +866,8 @@ void OPMapGadgetWidget::on_toolButtonMapUAVheading_clicked() if (!m_widget || !m_map) return; +// QMutexLocker locker(&m_map_mutex); + followUAVheadingAct->toggle(); } @@ -766,22 +876,18 @@ void OPMapGadgetWidget::on_toolButtonShowUAVtrail_clicked() if (!m_widget || !m_map) return; +// QMutexLocker locker(&m_map_mutex); + showUAVtrailAct->toggle(); } -void OPMapGadgetWidget::on_toolButtonClearUAVtrail_clicked() -{ - if (!m_widget || !m_map) - return; - - clearUAVtrailAct->trigger(); -} - void OPMapGadgetWidget::on_horizontalSliderZoom_sliderMoved(int position) { if (!m_widget || !m_map) return; + QMutexLocker locker(&m_map_mutex); + setZoom(position); } @@ -790,6 +896,8 @@ void OPMapGadgetWidget::on_toolButtonHome_clicked() if (!m_widget || !m_map) return; + QMutexLocker locker(&m_map_mutex); + // to do } @@ -799,6 +907,8 @@ void OPMapGadgetWidget::on_toolButtonPrevWaypoint_clicked() if (!m_widget || !m_map) return; +// QMutexLocker locker(&m_map_mutex); + // to do } @@ -807,6 +917,8 @@ void OPMapGadgetWidget::on_toolButtonNextWaypoint_clicked() if (!m_widget || !m_map) return; +// QMutexLocker locker(&m_map_mutex); + // to do } @@ -815,6 +927,8 @@ void OPMapGadgetWidget::on_toolButtonHoldPosition_clicked() if (!m_widget || !m_map) return; +// QMutexLocker locker(&m_map_mutex); + // to do } @@ -823,6 +937,8 @@ void OPMapGadgetWidget::on_toolButtonGo_clicked() if (!m_widget || !m_map) return; +// QMutexLocker locker(&m_map_mutex); + // to do } @@ -831,18 +947,38 @@ void OPMapGadgetWidget::on_toolButtonAddWaypoint_clicked() if (!m_widget || !m_map) return; - m_waypoint_list_mutex.lock(); + if (m_map_mode != Normal_MapMode) + return; + + QMutexLocker locker(&m_waypoint_list_mutex); +// m_waypoint_list_mutex.lock(); // create a waypoint at the center of the map - t_waypoint waypoint; - waypoint.item = m_map->WPCreate(m_map->CurrentPosition(), 0); - waypoint.time_seconds = 0; - waypoint.hold_time_seconds = 0; + t_waypoint *wp = new t_waypoint; + wp->map_wp_item = NULL; + wp->coord = m_map->CurrentPosition(); + wp->altitude = 0; + wp->description = ""; + wp->locked = false; + wp->time_seconds = 0; + wp->hold_time_seconds = 0; + wp->map_wp_item = m_map->WPCreate(wp->coord, wp->altitude, wp->description); + + wp->map_wp_item->setFlag(QGraphicsItem::ItemIsMovable, !wp->locked); + + if (wp->map_wp_item) + { + if (!wp->locked) + wp->map_wp_item->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker1.png")); + else + wp->map_wp_item->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker2.png")); + wp->map_wp_item->update(); + } // and remember it in our own local waypoint list - m_waypoint_list.append(waypoint); + m_waypoint_list.append(wp); - m_waypoint_list_mutex.unlock(); +// m_waypoint_list_mutex.unlock(); } void OPMapGadgetWidget::on_treeViewWaypoints_clicked(QModelIndex index) @@ -850,12 +986,50 @@ void OPMapGadgetWidget::on_treeViewWaypoints_clicked(QModelIndex index) if (!m_widget || !m_map) return; +// QMutexLocker locker(&m_map_mutex); + QStandardItem *item = wayPoint_treeView_model.itemFromIndex(index); if (!item) return; // to do } +void OPMapGadgetWidget::on_toolButtonMapModeLeft_clicked() +{ + switch (m_map_mode) + { + case Normal_MapMode: + setMapMode(MagicWaypoint_MapMode); + break; + + case MagicWaypoint_MapMode: + setMapMode(Normal_MapMode); + break; + + default: + setMapMode(Normal_MapMode); + break; + } +} + +void OPMapGadgetWidget::on_toolButtonMapModeRight_clicked() +{ + switch (m_map_mode) + { + case Normal_MapMode: + setMapMode(MagicWaypoint_MapMode); + break; + + case MagicWaypoint_MapMode: + setMapMode(Normal_MapMode); + break; + + default: + setMapMode(Normal_MapMode); + break; + } +} + // ************************************************************************************* // public functions @@ -991,6 +1165,81 @@ void OPMapGadgetWidget::setCacheLocation(QString cacheLocation) m_map->configuration->SetCacheLocation(cacheLocation); } +void OPMapGadgetWidget::setMapMode(opMapModeType mode) +{ + if (!m_widget || !m_map) + return; + + if (mode != Normal_MapMode && mode != MagicWaypoint_MapMode) + mode = Normal_MapMode; // fix error + + if (m_map_mode == mode) + return; // no change in map mode + + switch (mode) + { + case Normal_MapMode: + m_map_mode = Normal_MapMode; + + m_widget->labelMapMode->setText("Normal mode"); + + // delete the magic waypoint from the map + if (magic_waypoint.map_wp_item) + { + magic_waypoint.coord = magic_waypoint.map_wp_item->Coord(); + magic_waypoint.altitude = magic_waypoint.map_wp_item->Altitude(); + magic_waypoint.description = magic_waypoint.map_wp_item->Description(); + magic_waypoint.map_wp_item = NULL; + } + m_map->WPDeleteAll(); + + // restore the normal waypoints on the map + m_waypoint_list_mutex.lock(); + foreach (t_waypoint *wp, m_waypoint_list) + { + if (!wp) continue; + wp->map_wp_item = m_map->WPCreate(wp->coord, wp->altitude, wp->description); + if (!wp->map_wp_item) continue; + wp->map_wp_item->setFlag(QGraphicsItem::ItemIsMovable, !wp->locked); + if (!wp->locked) + wp->map_wp_item->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker1.png")); + else + wp->map_wp_item->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker2.png")); + wp->map_wp_item->update(); + } + m_waypoint_list_mutex.unlock(); + + break; + + case MagicWaypoint_MapMode: + m_map_mode = MagicWaypoint_MapMode; + + m_widget->labelMapMode->setText("Magic Waypoint mode"); + + // delete the normal waypoints from the map + m_waypoint_list_mutex.lock(); + foreach (t_waypoint *wp, m_waypoint_list) + { + if (!wp) continue; + if (!wp->map_wp_item) continue; + wp->coord = wp->map_wp_item->Coord(); + wp->altitude = wp->map_wp_item->Altitude(); + wp->description = wp->map_wp_item->Description(); + wp->locked = (wp->map_wp_item->flags() & QGraphicsItem::ItemIsMovable) == 0; + wp->map_wp_item = NULL; + } + m_map->WPDeleteAll(); + m_waypoint_list_mutex.unlock(); + + // restore the magic waypoint on the map + magic_waypoint.map_wp_item = m_map->WPCreate(magic_waypoint.coord, magic_waypoint.altitude, magic_waypoint.description); + magic_waypoint.map_wp_item->SetShowNumber(false); + magic_waypoint.map_wp_item->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker3.png")); + + break; + } +} + // ************************************************************************************* // Context menu stuff @@ -1126,6 +1375,25 @@ void OPMapGadgetWidget::createActions() clearWayPointsAct->setStatusTip(tr("Clear waypoints")); connect(clearWayPointsAct, SIGNAL(triggered()), this, SLOT(onClearWayPointsAct_triggered())); + mapModeActGroup = new QActionGroup(this); + connect(mapModeActGroup, SIGNAL(triggered(QAction *)), this, SLOT(onMapModeActGroup_triggered(QAction *))); + mapModeAct.clear(); + { + QAction *map_mode_act; + + map_mode_act = new QAction(tr("Normal"), mapModeActGroup); + map_mode_act->setCheckable(true); + map_mode_act->setChecked(m_map_mode == Normal_MapMode); + map_mode_act->setData((int)Normal_MapMode); + mapModeAct.append(map_mode_act); + + map_mode_act = new QAction(tr("Magic Waypoint"), mapModeActGroup); + map_mode_act->setCheckable(true); + map_mode_act->setChecked(m_map_mode == MagicWaypoint_MapMode); + map_mode_act->setData((int)MagicWaypoint_MapMode); + mapModeAct.append(map_mode_act); + } + zoomActGroup = new QActionGroup(this); connect(zoomActGroup, SIGNAL(triggered(QAction *)), this, SLOT(onZoomActGroup_triggered(QAction *))); zoomAct.clear(); @@ -1209,7 +1477,6 @@ void OPMapGadgetWidget::onShowHomeAct_toggled(bool show) if (!m_widget || !m_map) return; -// m_map->SetShowHome(show); // this can cause a rather big crash m_map->Home->setVisible(show); } @@ -1218,10 +1485,19 @@ void OPMapGadgetWidget::onShowUAVAct_toggled(bool show) if (!m_widget || !m_map) return; -// m_map->SetShowUAV(show); // this can cause a rather big crash m_map->UAV->setVisible(show); } +void OPMapGadgetWidget::onMapModeActGroup_triggered(QAction *action) +{ + if (!m_widget || !m_map || !action) + return; + + opMapModeType mode = (opMapModeType)action->data().toInt(); + + setMapMode(mode); +} + void OPMapGadgetWidget::onGoZoomInAct_triggered() { zoomIn(); @@ -1322,16 +1598,35 @@ void OPMapGadgetWidget::onAddWayPointAct_triggered() if (!m_widget || !m_map) return; + if (m_map_mode != Normal_MapMode) + return; + m_waypoint_list_mutex.lock(); // create a waypoint on the map at the last known mouse position - t_waypoint waypoint; - waypoint.item = m_map->WPCreate(mouse_lat_lon, 0); - waypoint.time_seconds = 0; - waypoint.hold_time_seconds = 0; + t_waypoint *wp = new t_waypoint; + wp->map_wp_item = NULL; + wp->coord = mouse_lat_lon; + wp->altitude = 0; + wp->description = ""; + wp->locked = false; + wp->time_seconds = 0; + wp->hold_time_seconds = 0; + wp->map_wp_item = m_map->WPCreate(wp->coord, wp->altitude, wp->description); - // and remember it in our own local waypoint list - m_waypoint_list.append(waypoint); + wp->map_wp_item->setFlag(QGraphicsItem::ItemIsMovable, !wp->locked); + + if (wp->map_wp_item) + { + if (!wp->locked) + wp->map_wp_item->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker1.png")); + else + wp->map_wp_item->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker2.png")); + wp->map_wp_item->update(); + } + + // and remember it in our own local waypoint list + m_waypoint_list.append(wp); m_waypoint_list_mutex.unlock(); } @@ -1341,7 +1636,11 @@ void OPMapGadgetWidget::onEditWayPointAct_triggered() if (!m_widget || !m_map) return; - if (!m_mouse_waypoint) return; + if (m_map_mode != Normal_MapMode) + return; + + if (!m_mouse_waypoint) + return; waypoint_edit_dialog.editWaypoint(m_mouse_waypoint); @@ -1350,14 +1649,21 @@ void OPMapGadgetWidget::onEditWayPointAct_triggered() void OPMapGadgetWidget::onLockWayPointAct_triggered() { - if (!m_widget || !m_map) + if (!m_widget || !m_map || !m_mouse_waypoint) return; - if (!m_mouse_waypoint) return; + if (m_map_mode != Normal_MapMode) + return; bool locked = (m_mouse_waypoint->flags() & QGraphicsItem::ItemIsMovable) == 0; m_mouse_waypoint->setFlag(QGraphicsItem::ItemIsMovable, locked); + if (!locked) + m_mouse_waypoint->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker2.png")); + else + m_mouse_waypoint->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker1.png")); + m_mouse_waypoint->update(); + m_mouse_waypoint = NULL; } @@ -1366,30 +1672,51 @@ void OPMapGadgetWidget::onDeleteWayPointAct_triggered() if (!m_widget || !m_map) return; - if (!m_mouse_waypoint) return; + if (m_map_mode != Normal_MapMode) + return; + + if (!m_mouse_waypoint) + return; bool locked = (m_mouse_waypoint->flags() & QGraphicsItem::ItemIsMovable) == 0; if (locked) return; // waypoint is locked - m_waypoint_list_mutex.lock(); + QMutexLocker locker(&m_waypoint_list_mutex); - for (int i = 0; i < m_waypoint_list.count(); i++) - { - t_waypoint waypoint = m_waypoint_list.at(i); - if (waypoint.item != m_mouse_waypoint) continue; + for (int i = 0; i < m_waypoint_list.count(); i++) + { + t_waypoint *wp = m_waypoint_list.at(i); + if (!wp) continue; + if (!wp->map_wp_item || wp->map_wp_item != m_mouse_waypoint) continue; + + // delete the waypoint from the map + m_map->WPDelete(wp->map_wp_item); + + // delete the waypoint from our local waypoint list + m_waypoint_list.removeAt(i); + + delete wp; + + break; + } +/* + foreach (t_waypoint *wp, m_waypoint_list) + { + if (!wp) continue; + if (!wp->map_wp_item || wp->map_wp_item != m_mouse_waypoint) continue; // delete the waypoint from the map - m_map->WPDelete(waypoint.item); + m_map->WPDelete(wp->map_wp_item); // delete the waypoint from our local waypoint list - m_waypoint_list.removeAt(i); + m_waypoint_list.removeOne(wp); + + delete wp; break; } - - m_waypoint_list_mutex.unlock(); - +*/ m_mouse_waypoint = NULL; } @@ -1398,10 +1725,23 @@ void OPMapGadgetWidget::onClearWayPointsAct_triggered() if (!m_widget || !m_map) return; - m_waypoint_list_mutex.lock(); + if (m_map_mode != Normal_MapMode) + return; + + QMutexLocker locker(&m_waypoint_list_mutex); + m_map->WPDeleteAll(); - m_waypoint_list.clear(); - m_waypoint_list_mutex.unlock(); + + foreach (t_waypoint *wp, m_waypoint_list) + { + if (wp) + { + delete wp; + wp = NULL; + } + } + + m_waypoint_list.clear(); } // ************************************************************************************* diff --git a/ground/src/plugins/opmap/opmapgadgetwidget.h b/ground/src/plugins/opmap/opmapgadgetwidget.h index ba347a842..c9a6e9098 100644 --- a/ground/src/plugins/opmap/opmapgadgetwidget.h +++ b/ground/src/plugins/opmap/opmapgadgetwidget.h @@ -28,12 +28,15 @@ #ifndef OPMAP_GADGETWIDGET_H_ #define OPMAP_GADGETWIDGET_H_ +// ****************************************************** + #include #include #include #include #include #include +#include #include #include "opmapcontrol/opmapcontrol.h" @@ -51,6 +54,8 @@ #include "utils/coordinateconversions.h" +// ****************************************************** + namespace Ui { class OPMap_Widget; @@ -63,13 +68,22 @@ using namespace mapcontrol; // local waypoint list item structure typedef struct t_waypoint { - mapcontrol::WayPointItem *item; + mapcontrol::WayPointItem *map_wp_item; + internals::PointLatLng coord; + double altitude; + QString description; + bool locked; int time_seconds; int hold_time_seconds; } t_waypoint; // ****************************************************** +enum opMapModeType { Normal_MapMode = 0, + MagicWaypoint_MapMode = 1}; + +// ****************************************************** + class OPMapGadgetWidget : public QWidget { Q_OBJECT @@ -92,6 +106,7 @@ public: void setAccessMode(QString accessMode); void setUseMemoryCache(bool useMemoryCache); void setCacheLocation(QString cacheLocation); + void setMapMode(opMapModeType mode); public slots: @@ -122,7 +137,6 @@ private slots: void on_toolButtonMapUAV_clicked(); void on_toolButtonMapUAVheading_clicked(); void on_toolButtonShowUAVtrail_clicked(); - void on_toolButtonClearUAVtrail_clicked(); void on_horizontalSliderZoom_sliderMoved(int position); void on_toolButtonAddWaypoint_clicked(); void on_treeViewWaypoints_clicked(QModelIndex index); @@ -131,6 +145,8 @@ private slots: void on_toolButtonPrevWaypoint_clicked(); void on_toolButtonHoldPosition_clicked(); void on_toolButtonGo_clicked(); + void on_toolButtonMapModeLeft_clicked(); + void on_toolButtonMapModeRight_clicked(); /** * @brief signals received from the map object @@ -179,6 +195,7 @@ private slots: void onLockWayPointAct_triggered(); void onDeleteWayPointAct_triggered(); void onClearWayPointsAct_triggered(); + void onMapModeActGroup_triggered(QAction *action); void onZoomActGroup_triggered(QAction *action); private: @@ -191,6 +208,8 @@ private: int prev_tile_number; + opMapModeType m_map_mode; + QStringList findPlaceWordList; QCompleter *findPlaceCompleter; @@ -219,9 +238,13 @@ private: mapcontrol::WayPointItem *m_mouse_waypoint; - QList m_waypoint_list; + QList m_waypoint_list; QMutex m_waypoint_list_mutex; + t_waypoint magic_waypoint; + + QMutex m_map_mutex; + void createActions(); QAction *closeAct; @@ -249,6 +272,9 @@ private: QAction *deleteWayPointAct; QAction *clearWayPointsAct; + QActionGroup *mapModeActGroup; + QList mapModeAct; + QActionGroup *zoomActGroup; QList zoomAct;