Skip to content

Commit

Permalink
Updating WP coordinates from map via drag and drop works. Working now…
Browse files Browse the repository at this point in the history
… on list enumeration changes
  • Loading branch information
pixhawk-students committed Jun 25, 2011
1 parent 9683bd1 commit 82acad4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
43 changes: 41 additions & 2 deletions src/ui/map/QGCMapWidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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*)));
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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());
}
}
Expand Down Expand Up @@ -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

Expand All @@ -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) {
Expand All @@ -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)) {
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/ui/map/QGCMapWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class UASInterface;
class UASWaypointManager;
class Waypoint;
typedef mapcontrol::WayPointItem WayPointItem;

/**
* @brief Class representing a 2D map using aerial imagery
Expand All @@ -20,6 +21,9 @@ class QGCMapWidget : public mapcontrol::OPMapWidget

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 */
Expand All @@ -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);
Expand All @@ -47,6 +55,7 @@ public slots:
UASWaypointManager* currWPManager; ///< The current waypoint manager
QMap<Waypoint* , mapcontrol::WayPointItem*> waypointsToIcons;
QMap<mapcontrol::WayPointItem*, Waypoint*> iconsToWaypoints;
Waypoint* firingWaypointChange;
// enum editMode {
// NONE,
// WAYPOINTS,
Expand Down

0 comments on commit 82acad4

Please sign in to comment.