From e686ac0b1dc38f5c6a94b31d382f05fe7259bee9 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Sat, 2 Jun 2012 15:02:43 -0500 Subject: [PATCH] Start adding the ability to delete a waypoint --- .../src/plugins/opmap/opmapgadgetwidget.cpp | 68 ++++--------------- .../src/plugins/opmap/pathcompiler.cpp | 10 ++- .../src/plugins/opmap/pathcompiler.h | 5 ++ 3 files changed, 29 insertions(+), 54 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp index da41019e7..1ca72597b 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp @@ -1957,52 +1957,22 @@ void OPMapGadgetWidget::onLockWayPointAct_triggered() void OPMapGadgetWidget::onDeleteWayPointAct_triggered() { + Q_ASSERT(m_widget); + Q_ASSERT(m_map); + if (!m_widget || !m_map) return; if (m_map_mode != Normal_MapMode) return; - if (!m_mouse_waypoint) - return; + Q_ASSERT(m_mouse_waypoint); + if(m_mouse_waypoint) { + int waypointIdx = m_mouse_waypoint->Description().toInt(); - bool locked = (m_mouse_waypoint->flags() & QGraphicsItem::ItemIsMovable) == 0; - - if (locked) return; // waypoint is locked - - QMutexLocker locker(&m_waypoint_list_mutex); - - 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(wp->map_wp_item); - - // delete the waypoint from our local waypoint list - m_waypoint_list.removeOne(wp); - - delete wp; - - break; + Q_ASSERT(pathCompiler); + if(pathCompiler) + pathCompiler->doDelWaypoint(waypointIdx); } m_mouse_waypoint = NULL; @@ -2013,26 +1983,18 @@ void OPMapGadgetWidget::onDeleteWayPointAct_triggered() */ void OPMapGadgetWidget::onClearWayPointsAct_triggered() { + Q_ASSERT(m_widget); + Q_ASSERT(m_map); + if (!m_widget || !m_map) return; if (m_map_mode != Normal_MapMode) return; - QMutexLocker locker(&m_waypoint_list_mutex); - - m_map->WPDeleteAll(); - - foreach (t_waypoint *wp, m_waypoint_list) - { - if (wp) - { - delete wp; - wp = NULL; - } - } - - m_waypoint_list.clear(); + Q_ASSERT(pathCompiler); + if(pathCompiler) + pathCompiler->doDelAllWaypoints(); } void OPMapGadgetWidget::onHomeMagicWaypointAct_triggered() diff --git a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp index fc28c95a4..daa7ecd47 100644 --- a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp @@ -121,7 +121,7 @@ void PathCompiler::doAddWaypoint(struct PathCompiler::waypoint waypoint, int /*p * Delete a waypoint * @param index which waypoint to delete */ -void PathCompiler::doDelWaypoint(int /*index*/) +void PathCompiler::doDelWaypoint(int index) { // This method is awkward because there is no support // on the FC for actually deleting a waypoint. We need @@ -132,6 +132,14 @@ void PathCompiler::doDelWaypoint(int /*index*/) Q_ASSERT(false); } +/** + * Delete all the waypoints + */ +void PathCompiler::doDelAllWaypoints() +{ + +} + /** * When the UAV waypoints change trigger the pathcompiler to * get the latest version and then update the visualization diff --git a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h index db5639c9d..426d94c55 100644 --- a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h +++ b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h @@ -109,6 +109,11 @@ public slots: */ void doDelWaypoint(int index); + /** + * Delete all the waypoints + */ + void doDelAllWaypoints(); + public slots: /** * These are slots that the UAV can call to update the path.