Commit eab5a16a authored by lm's avatar lm

Improved map caching, waypoints and lines now colored with UAV colors,...

Improved map caching, waypoints and lines now colored with UAV colors, debugging map drag / zoom issue with waypoint lines
parent 28534a58
......@@ -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;}
......
......@@ -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());
......
......@@ -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)
{
......
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