From b4d59d3e3ed25add34e6519a7a7afdc14a07372c Mon Sep 17 00:00:00 2001 From: James Cotton Date: Tue, 5 Jun 2012 10:01:12 -0500 Subject: [PATCH] Dragging and dropping waypoints now works and updates the FC immediately. --- .../src/mapwidget/waypointitem.cpp | 3 +- .../opmapcontrol/src/mapwidget/waypointitem.h | 8 ++++ .../src/plugins/opmap/opmapgadgetwidget.cpp | 43 ++++++++++++------- .../src/plugins/opmap/opmapgadgetwidget.h | 1 + .../src/plugins/opmap/pathcompiler.cpp | 29 +++++++++++-- .../src/plugins/opmap/pathcompiler.h | 2 +- 6 files changed, 65 insertions(+), 21 deletions(-) diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp index 8f1892a61..5fd972502 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.cpp @@ -95,6 +95,7 @@ namespace mapcontrol } void WayPointItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + QGraphicsItem::mouseReleaseEvent(event); if(event->button()==Qt::LeftButton) { if(text) { @@ -110,8 +111,8 @@ namespace mapcontrol RefreshToolTip(); emit WPValuesChanged(this); + emit WPDropped(this); } - QGraphicsItem::mouseReleaseEvent(event); } void WayPointItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { diff --git a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h index b9bee5ce5..b8fbd70cb 100644 --- a/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h +++ b/ground/openpilotgcs/src/libs/opmapcontrol/src/mapwidget/waypointitem.h @@ -198,6 +198,7 @@ signals: * @param waypoint a pointer to this WayPoint */ void WPNumberChanged(int const& oldnumber,int const& newnumber,WayPointItem* waypoint); + /** * @brief Fired when the description, altitude or coordinates change * @@ -205,6 +206,13 @@ signals: */ void WPValuesChanged(WayPointItem* waypoint); + /** + * @brief Fired when the waypoint is dropped somewhere + * + * @param waypoint a pointer to this WayPoint + */ + void WPDropped(WayPointItem* waypoint); + }; } #endif // WAYPOINTITEM_H diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp index 1466032e3..e7381d976 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.cpp @@ -887,26 +887,19 @@ void OPMapGadgetWidget::WPNumberChanged(int const &oldnumber, int const &newnumb Q_UNUSED(waypoint); } +/** + * Called whenever a waypoint item is changed on the mapcontrol. Needs to update + * the backend appropriately + */ void OPMapGadgetWidget::WPValuesChanged(WayPointItem *waypoint) { - // qDebug("opmap: 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(); + { + // TODO: We don't parse changes in position here as it's too dense + // however a change in something like + } break; case MagicWaypoint_MapMode: @@ -2359,6 +2352,7 @@ void OPMapGadgetWidget::SetUavPic(QString UAVPic) */ void OPMapGadgetWidget::doVisualizationChanged(QList waypoints) { + disconnect(this,SLOT(WPDropped(WayPointItem*))); m_map->WPDeleteAll(); int index = 0; foreach (PathCompiler::waypoint waypoint, waypoints) { @@ -2371,5 +2365,24 @@ void OPMapGadgetWidget::doVisualizationChanged(QList way wayPointItem->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker1.png")); index++; } + connect(wayPointItem, SIGNAL(WPDropped(WayPointItem*)), this, SLOT(WPDropped(WayPointItem*))); + } +} + +/** + * Called when a waypoint is dropped at a new location. Waypoint changed + * can't be used as it is updated too frequently and we don't want to + * overload the pathcompiler with unnecessary updates + */ +void OPMapGadgetWidget::WPDropped(WayPointItem *waypoint) +{ + switch (m_map_mode) + { + case Normal_MapMode: + PathCompiler::waypoint newWaypoint; + newWaypoint.latitude = waypoint->Coord().Lat(); + newWaypoint.longitude = waypoint->Coord().Lng(); + pathCompiler->doUpdateWaypoints(newWaypoint,waypoint->Number()); + break; } } diff --git a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h index 65f4e25b9..38fa52c36 100644 --- a/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/opmap/opmapgadgetwidget.h @@ -179,6 +179,7 @@ private slots: /** * Unused for now, hooks for future waypoint support */ + void WPDropped(WayPointItem *waypoint); void WPNumberChanged(int const& oldnumber,int const& newnumber, WayPointItem* waypoint); void WPValuesChanged(WayPointItem* waypoint); void WPInserted(int const& number, WayPointItem* waypoint); diff --git a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp index 1a9564c0e..f8d4dca1b 100644 --- a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp +++ b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.cpp @@ -140,6 +140,7 @@ void PathCompiler::doAddWaypoint(waypoint newWaypointInternal, int /*position*/) if(waypointData.Action == Waypoint::ACTION_STOP) { waypointData.Action = Waypoint::ACTION_PATHTONEXT; waypoint->setData(waypointData); + waypoint->updated(); break; } } @@ -169,6 +170,30 @@ void PathCompiler::doAddWaypoint(waypoint newWaypointInternal, int /*position*/) } } +/** + * Update waypoint + */ +void PathCompiler::doUpdateWaypoints(PathCompiler::waypoint changedWaypoint, int position) +{ + int numWaypoints = getObjectManager()->getNumInstances(Waypoint::OBJID); + Q_ASSERT(position < numWaypoints); + if (position >= numWaypoints) + return; + + Waypoint *waypointInst = Waypoint::GetInstance(getObjectManager(), position); + Q_ASSERT(waypointInst); + + // Mirror over the updated position. We don't just use the changedWaypoint + // because things like action might need to be preserved + Waypoint::DataFields changedWaypointUAVO = InternalToUavo(changedWaypoint); + Waypoint::DataFields oldWaypointUAVO = waypointInst->getData(); + oldWaypointUAVO.Position[0] = changedWaypointUAVO.Position[0]; + oldWaypointUAVO.Position[1] = changedWaypointUAVO.Position[1]; + oldWaypointUAVO.Position[2] = changedWaypointUAVO.Position[2]; + waypointInst->setData(oldWaypointUAVO); + waypointInst->updated(); +} + /** * Delete a waypoint * @param index which waypoint to delete @@ -255,10 +280,6 @@ void PathCompiler::doUpdateFromUAV(UAVObject *obj) if (!objManager) return; - if(obj) { - qDebug() << "Update:" << obj->getInstID(); - } - Waypoint *waypointObj = Waypoint::GetInstance(getObjectManager()); Q_ASSERT(waypointObj); if (waypointObj == NULL) diff --git a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h index 4e04fcd10..f3bdc95c4 100644 --- a/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h +++ b/ground/openpilotgcs/src/plugins/opmap/pathcompiler.h @@ -118,7 +118,7 @@ public slots: /** * Update waypoint */ - //void doUpdateWaypoints(struct PathCompiler::waypoint, int position); + void doUpdateWaypoints(PathCompiler::waypoint, int position); /** * Delete a waypoint