Commit 82acad45 authored by pixhawk's avatar pixhawk

Updating WP coordinates from map via drag and drop works. Working now on list enumeration changes

parent 9683bd14
......@@ -7,7 +7,8 @@
QGCMapWidget::QGCMapWidget(QWidget *parent) :
mapcontrol::OPMapWidget(parent),
currWPManager(NULL)
currWPManager(NULL),
firingWaypointChange(NULL)
{
connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*)));
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(activeUASSet(UASInterface*)));
......@@ -81,6 +82,11 @@ QGCMapWidget::QGCMapWidget(QWidget *parent) :
// FIXME XXX this is a hack to trick OPs current 1-system design
SetShowUAV(false);
// Connect map updates to the adapter slots
connect(this, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(handleMapWaypointEdit(WayPointItem*)));
setFocus();
}
......@@ -113,6 +119,7 @@ void QGCMapWidget::activeUASSet(UASInterface* uas)
disconnect(currWPManager, SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int)));
disconnect(currWPManager, SIGNAL(waypointChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
disconnect(this, SIGNAL(waypointCreated(Waypoint*)), currWPManager, SLOT(addWaypoint(Waypoint*)));
disconnect(this, SIGNAL(waypointChanged(Waypoint*)), currWPManager, SLOT(notifyOfChange(Waypoint*)));
}
if (uas) {
......@@ -132,7 +139,7 @@ void QGCMapWidget::activeUASSet(UASInterface* uas)
connect(currWPManager, SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int)));
connect(currWPManager, SIGNAL(waypointChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*)));
connect(this, SIGNAL(waypointCreated(Waypoint*)), currWPManager, SLOT(addWaypoint(Waypoint*)));
connect(this, SIGNAL(waypointChanged(Waypoint*)), currWPManager, SLOT(notifyOfChange(Waypoint*)));
updateSelectedSystem(uas->getUASID());
}
}
......@@ -233,6 +240,32 @@ void QGCMapWidget::updateHomePosition(double latitude, double longitude, double
}
// WAYPOINT MAP INTERACTION FUNCTIONS
//void QGCMapWidget::createWaypointAtMousePos(QMouseEvent)
//{
//}
void QGCMapWidget::handleMapWaypointEdit(mapcontrol::WayPointItem* waypoint)
{
qDebug() << "UPDATING WP FROM MAP";
// Block circle updates
Waypoint* wp = iconsToWaypoints.value(waypoint, NULL);
// Protect from vicious double update cycle
if (firingWaypointChange == wp || !wp) return;
// Not in cycle, block now from entering it
firingWaypointChange = wp;
// Update WP values
internals::PointLatLng pos = waypoint->Coord();
wp->setLatitude(pos.Lat());
wp->setLongitude(pos.Lng());
wp->setAltitude(waypoint->Altitude());
emit waypointChanged(wp);
firingWaypointChange = NULL;
}
// WAYPOINT UPDATE FUNCTIONS
......@@ -242,6 +275,8 @@ void QGCMapWidget::updateHomePosition(double latitude, double longitude, double
*/
void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp)
{
// Source of the event was in this widget, do nothing
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) {
......@@ -255,6 +290,8 @@ void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp)
int wpindex = UASManager::instance()->getUASForId(uas)->getWaypointManager()->getGlobalFrameAndNavTypeIndexOf(wp);
// If not found, return (this should never happen, but helps safety)
if (wpindex == -1) return;
// Mark this wp as currently edited
firingWaypointChange = wp;
// Check if wp exists yet in map
if (!waypointsToIcons.contains(wp)) {
......@@ -281,6 +318,8 @@ void QGCMapWidget::updateWaypoint(int uas, Waypoint* wp)
// Re-enable signals again
this->blockSignals(false);
}
firingWaypointChange = NULL;
} else {
// Check if the index of this waypoint is larger than the global
// waypoint list. This implies that the coordinate frame of this
......
......@@ -7,6 +7,7 @@
class UASInterface;
class UASWaypointManager;
class Waypoint;
typedef mapcontrol::WayPointItem WayPointItem;
/**
* @brief Class representing a 2D map using aerial imagery
......@@ -20,6 +21,9 @@ public:
signals:
void homePositionChanged(double latitude, double longitude, double altitude);
/** @brief Signal for newly created map waypoints */
void waypointCreated(Waypoint* wp);
void waypointChanged(Waypoint* wp);
public slots:
/** @brief Add system to map view */
......@@ -39,6 +43,10 @@ public slots:
/** @brief Update the home position on the map */
void updateHomePosition(double latitude, double longitude, double altitude);
protected slots:
/** @brief Convert a map edit into a QGC waypoint event */
void handleMapWaypointEdit(WayPointItem* waypoint);
protected:
/** @brief Update the highlighting of the currently controlled system */
void updateSelectedSystem(int uas);
......@@ -47,6 +55,7 @@ protected:
UASWaypointManager* currWPManager; ///< The current waypoint manager
QMap<Waypoint* , mapcontrol::WayPointItem*> waypointsToIcons;
QMap<mapcontrol::WayPointItem*, Waypoint*> iconsToWaypoints;
Waypoint* firingWaypointChange;
// enum editMode {
// NONE,
// WAYPOINTS,
......
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