diff --git a/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h b/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h index 2c78d27f57020418fb349040852e85281006faa9..5fd18c9810eb7c7601fd0e827d55da7d2fd5c61b 100644 --- a/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h +++ b/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h @@ -116,6 +116,9 @@ namespace mapcontrol */ internals::RectLatLng SelectedArea()const{return selectedArea;} + public slots: + void SetSelectedArea(internals::RectLatLng const& value){selectedArea = value;this->update();} + protected: void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); void mousePressEvent ( QGraphicsSceneMouseEvent * event ); @@ -196,7 +199,6 @@ namespace mapcontrol */ int MinZoom()const{return minZoom;} internals::MouseWheelZoomType::Types GetMouseWheelZoomType(){return core->GetMouseWheelZoomType();} - void SetSelectedArea(internals::RectLatLng const& value){selectedArea = value;this->update();} internals::RectLatLng BoundsOfMap; void Offset(int const& x, int const& y); bool CanDragMap()const{return core->CanDragMap;} diff --git a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp index 2034fbaf24cf87549eef996bffb866419c70bb31..67b448f007ac6929a08712b7e504d6e44fedca4b 100644 --- a/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp +++ b/src/libs/opmapcontrol/src/mapwidget/waypointlineitem.cpp @@ -7,15 +7,23 @@ WaypointLineItem::WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor wp2(wp2), map(map) { - core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord()); - core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord()); + // Make sure this stick to the map + this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + setParentItem(map); + // Set up the pen for this icon with the UAV color QPen pen(color); pen.setWidth(2); setPen(pen); + // Pixel coordinates of the local points + core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord()); + core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord()); + // Draw line setLine(localPoint1.X(), localPoint1.Y(), localPoint2.X(), localPoint2.Y()); + // Connect updates + // Update line from both waypoints connect(wp1, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(updateWPValues(WayPointItem*))); connect(wp2, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(updateWPValues(WayPointItem*))); @@ -27,12 +35,14 @@ WaypointLineItem::WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor void WaypointLineItem::updateWPValues(WayPointItem* waypoint) { Q_UNUSED(waypoint); + // Delete if either waypoint got deleted if (!wp1 || !wp2) { this->deleteLater(); } else { + // Set new pixel coordinates based on new global coordinates core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord()); core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord()); diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index df0198bd19b6c5d7669ca3d94999f8417a46ce79..1d1fa2581fedfa147a2b32fcfb889bb84ed1e74d 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -378,20 +378,17 @@ void QGCMapWidget::cacheVisibleRegion() msgBox.setDefaultButton(QMessageBox::Ok); msgBox.exec(); } - - RipMap(); - - // FIXME UNSELECT AREA NOW + else + { + RipMap(); + // Set empty area = unselect area + map->SetSelectedArea(internals::RectLatLng()); + } } // WAYPOINT MAP INTERACTION FUNCTIONS -//void QGCMapWidget::createWaypointAtMousePos(QMouseEvent) -//{ - -//} - void QGCMapWidget::handleMapWaypointEdit(mapcontrol::WayPointItem* waypoint) { // Block circle updates @@ -436,7 +433,8 @@ void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp) if (firingWaypointChange == wp) return; // Currently only accept waypoint updates from the UAS in focus // this has to be changed to accept read-only updates from other systems as well. - if (UASManager::instance()->getUASForId(uas)->getWaypointManager() == currWPManager) { + UASInterface* uasInstance = UASManager::instance()->getUASForId(uas); + if (uasInstance->getWaypointManager() == currWPManager || uas == -1) { // Only accept waypoints in global coordinate frame if (((wp->getFrame() == MAV_FRAME_GLOBAL) || (wp->getFrame() == MAV_FRAME_GLOBAL_RELATIVE_ALT)) && wp->isNavigationType()) { // We're good, this is a global waypoint @@ -444,8 +442,7 @@ void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp) // Get the index of this waypoint // note the call to getGlobalFrameAndNavTypeIndexOf() // as we're only handling global waypoints - int wpindex = UASManager::instance()->getUASForId(uas)->getWaypointManager()->getGlobalFrameAndNavTypeIndexOf(wp); - UASInterface* uasInstance = UASManager::instance()->getUASForId(uas); + int wpindex = currWPManager->getGlobalFrameAndNavTypeIndexOf(wp); // If not found, return (this should never happen, but helps safety) if (wpindex == -1) return; // Mark this wp as currently edited @@ -454,7 +451,9 @@ void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp) // Check if wp exists yet in map if (!waypointsToIcons.contains(wp)) { // Create icon for new WP - Waypoint2DIcon* icon = new Waypoint2DIcon(map, this, wp, uasInstance->getColor(), wpindex); + QColor wpColor(Qt::red); + if (uasInstance) wpColor = uasInstance->getColor(); + Waypoint2DIcon* icon = new Waypoint2DIcon(map, this, wp, wpColor, wpindex); ConnectWP(icon); icon->setParentItem(map); // Update maps to allow inverse data association @@ -471,7 +470,7 @@ void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp) // If we got a valid graphics item, continue if (prevIcon) { - mapcontrol::WaypointLineItem* line = new mapcontrol::WaypointLineItem(prevIcon, icon, Qt::red, map); + mapcontrol::WaypointLineItem* line = new mapcontrol::WaypointLineItem(prevIcon, icon, wpColor, map); QGraphicsItemGroup* group = waypointLines.value(uas, NULL); if (group) { @@ -516,7 +515,7 @@ void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp) // waypoint list. This implies that the coordinate frame of this // waypoint was changed and the list containing only global // waypoints was shortened. Thus update the whole list - if (waypointsToIcons.size() > UASManager::instance()->getUASForId(uas)->getWaypointManager()->getGlobalFrameAndNavTypeCount()) { + if (waypointsToIcons.size() > currWPManager->getGlobalFrameAndNavTypeCount()) { updateWaypointList(uas); } } @@ -533,14 +532,7 @@ void QGCMapWidget::updateWaypointList(int uas) // Currently only accept waypoint updates from the UAS in focus // this has to be changed to accept read-only updates from other systems as well. UASInterface* uasInstance = UASManager::instance()->getUASForId(uas); - if (uasInstance->getWaypointManager() == currWPManager) { - qDebug() << "UPDATING WP LIST"; - // Get current WP list - // compare to local WP maps and - // update / remove all WPs - - // int localCount = waypointsToIcons.count(); - + if ((uasInstance && (uasInstance->getWaypointManager() == currWPManager)) || uas == -1) { // ORDER MATTERS HERE! // TWO LOOPS ARE NEEDED - INFINITY LOOP ELSE @@ -593,7 +585,9 @@ void QGCMapWidget::updateWaypointList(int uas) if (prevIcon && currIcon) { // If we got a valid graphics item, continue - mapcontrol::WaypointLineItem* line = new mapcontrol::WaypointLineItem(prevIcon, currIcon, uasInstance->getColor(), map); + QColor wpColor(Qt::red); + if (uasInstance) wpColor = uasInstance->getColor(); + mapcontrol::WaypointLineItem* line = new mapcontrol::WaypointLineItem(prevIcon, currIcon, wpColor, map); QGraphicsItemGroup* group = waypointLines.value(uas, NULL); if (group) {