Commit 28534a58 authored by lm's avatar lm

Added waypoint connecting lines

parent 69229517
......@@ -40,6 +40,7 @@
#include "uavitem.h"
#include "gpsitem.h"
#include "homeitem.h"
#include "waypointlineitem.h"
#include "mapripper.h"
namespace mapcontrol
{
......
#include "waypointlineitem.h"
WaypointLineItem::WaypointLineItem()
namespace mapcontrol
{
WaypointLineItem::WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor color, mapcontrol::MapGraphicItem* map) :
wp1(wp1),
wp2(wp2),
map(map)
{
core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord());
core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord());
QPen pen(color);
pen.setWidth(2);
setPen(pen);
setLine(localPoint1.X(), localPoint1.Y(), localPoint2.X(), localPoint2.Y());
// Update line from both waypoints
connect(wp1, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(updateWPValues(WayPointItem*)));
connect(wp2, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(updateWPValues(WayPointItem*)));
// Delete line if one of the waypoints get deleted
connect(wp1, SIGNAL(destroyed()), this, SLOT(deleteLater()));
connect(wp2, SIGNAL(destroyed()), this, SLOT(deleteLater()));
}
void WaypointLineItem::updateWPValues(WayPointItem* waypoint)
{
Q_UNUSED(waypoint);
if (!wp1 || !wp2)
{
this->deleteLater();
}
else
{
core::Point localPoint1 = map->FromLatLngToLocal(wp1->Coord());
core::Point localPoint2 = map->FromLatLngToLocal(wp2->Coord());
setLine(localPoint1.X(), localPoint1.Y(), localPoint2.X(), localPoint2.Y());
}
}
}
......@@ -2,11 +2,31 @@
#define WAYPOINTLINEITEM_H
#include <QGraphicsLineItem>
#include "opmapcontrol.h"
class WaypointLineItem : public QGraphicsLineItem
namespace mapcontrol {
class WaypointLineItem : public QObject,public QGraphicsLineItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
WaypointLineItem();
WaypointLineItem(WayPointItem* wp1, WayPointItem* wp2, QColor color=QColor(Qt::red), MapGraphicItem* parent=0);
public slots:
/**
* @brief Update waypoint values
*
* @param waypoint The waypoint object that just changed
*/
void updateWPValues(WayPointItem* waypoint);
protected:
internals::PointLatLng point1;
internals::PointLatLng point2;
WayPointItem* wp1;
WayPointItem* wp2;
MapGraphicItem* map; ///< The map this item is parent of
};
}
#endif // WAYPOINTLINEITEM_H
......@@ -156,6 +156,8 @@ void QGCMapWidget::storeSettings()
void QGCMapWidget::mouseDoubleClickEvent(QMouseEvent* event)
{
OPMapWidget::mouseDoubleClickEvent(event);
// FIXME HACK!
currEditMode = EDIT_MODE_WAYPOINTS;
if (currEditMode == EDIT_MODE_WAYPOINTS)
{
// If a waypoint manager is available
......@@ -164,8 +166,13 @@ void QGCMapWidget::mouseDoubleClickEvent(QMouseEvent* event)
// Create new waypoint
internals::PointLatLng pos = this->currentMousePosition();
Waypoint* wp = currWPManager->createWaypoint();
// wp->blockSignals(true);
wp->setFrame(MAV_FRAME_GLOBAL_RELATIVE_ALT);
wp->setLatitude(pos.Lat());
wp->setLongitude(pos.Lng());
wp->setAltitude(0);
// wp->blockSignals(false);
// currWPManager->notifyOfChange(wp);
}
}
}
......@@ -199,13 +206,6 @@ void QGCMapWidget::activeUASSet(UASInterface* uas)
if (uas) {
currWPManager = uas->getWaypointManager();
// QColor color = mav->getColor();
// color.setAlphaF(0.9);
// QPen* pen = new QPen(color);
// pen->setWidth(3.0);
// mavPens.insert(mav->getUASID(), pen);
// // FIXME Remove after refactoring
// waypointPath->setPen(pen);
// Delete all waypoints and add waypoint from new system
updateWaypointList(uas->getUASID());
......@@ -461,16 +461,25 @@ void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp)
waypointsToIcons.insert(wp, icon);
iconsToWaypoints.insert(icon, wp);
// Add line element
qDebug() << "ADDING LINE";
mapcontrol::TrailLineItem* line = new mapcontrol::TrailLineItem(internals::PointLatLng(0.2, 0.2), icon->Coord(), QBrush(Qt::red), map);
// Add line element if this is NOT the first waypoint
if (wpindex > 0)
{
// Get predecessor of this WP
QVector<Waypoint* > wps = currWPManager->getGlobalFrameAndNavTypeWaypointList();
Waypoint* wp1 = wps.at(wpindex-1);
mapcontrol::WayPointItem* prevIcon = waypointsToIcons.value(wp1, NULL);
// If we got a valid graphics item, continue
if (prevIcon)
{
mapcontrol::WaypointLineItem* line = new mapcontrol::WaypointLineItem(prevIcon, icon, Qt::red, map);
QGraphicsItemGroup* group = waypointLines.value(uas, NULL);
if (group)
{
group->addToGroup(line);
qDebug() << "ADDED LINE!";
}
line->setVisible(true);
}
}
} else {
// Waypoint exists, block it's signals and update it
mapcontrol::WayPointItem* icon = waypointsToIcons.value(wp);
......@@ -523,7 +532,8 @@ 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.
if (UASManager::instance()->getUASForId(uas)->getWaypointManager() == currWPManager) {
UASInterface* uasInstance = UASManager::instance()->getUASForId(uas);
if (uasInstance->getWaypointManager() == currWPManager) {
qDebug() << "UPDATING WP LIST";
// Get current WP list
// compare to local WP maps and
......@@ -562,6 +572,38 @@ void QGCMapWidget::updateWaypointList(int uas)
// Update / add only if new
if (!waypointsToIcons.contains(wp)) updateWaypoint(uas, wp);
}
// Delete connecting waypoint lines
QGraphicsItemGroup* group = waypointLines.value(uas, NULL);
if (group)
{
foreach (QGraphicsItem* item, group->childItems())
{
delete item;
}
}
// Add line element if this is NOT the first waypoint
mapcontrol::WayPointItem* prevIcon = NULL;
foreach (Waypoint* wp, wps)
{
mapcontrol::WayPointItem* currIcon = waypointsToIcons.value(wp, NULL);
// Do not work on first waypoint, but only increment counter
// do not continue if icon is invalid
if (prevIcon && currIcon)
{
// If we got a valid graphics item, continue
mapcontrol::WaypointLineItem* line = new mapcontrol::WaypointLineItem(prevIcon, currIcon, uasInstance->getColor(), map);
QGraphicsItemGroup* group = waypointLines.value(uas, NULL);
if (group)
{
group->addToGroup(line);
qDebug() << "ADDED LINE!";
}
line->setVisible(true);
}
prevIcon = currIcon;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment