Newer
Older
/*==================================================================
======================================================================*/
/**
* @file
lm
committed
#include "QGC.h"
#include "UASInterface.h"
#include "UASManager.h"
lm
committed
#include "MAV2DIcon.h"
#include "Waypoint2DIcon.h"
pixhawk
committed
#include "UASWaypointManager.h"
MapWidget::MapWidget(QWidget *parent) :
QWidget(parent),
zoomLevel(0),
uasIcons(),
uasTrails(),
pixhawk
committed
mav(NULL),
lm
committed
mc = new qmapcontrol::MapControl(QSize(320, 240));
// VISUAL MAP STYLE
pixhawk
committed
QString buttonStyle("QAbstractButton { background-color: rgba(20, 20, 20, 45%); border-color: rgba(10, 10, 10, 50%)} QAbstractButton:checked { border: 2px solid #379AC3; }");
lm
committed
mc->setPen(QGC::colorCyan.darker(400));
tecnosapiens
committed
waypointIsDrag = false;
// Accept focus by clicking or keyboard
this->setFocusPolicy(Qt::StrongFocus);
lm
committed
Mariano Lizarraga
committed
mc->showCoord(true);
Mariano Lizarraga
committed
mc->setMouseTracking(true); // required to update the mouse position for diplay and capture
//TileMapAdapter* osmAdapter = new TileMapAdapter("tile.openstreetmap.org", "/%1/%2/%3.png", 256, 0, 17);
lm
committed
qmapcontrol::MapAdapter* mapadapter_overlay = new qmapcontrol::YahooMapAdapter("us.maps3.yimg.com", "/aerial.maps.yimg.com/png?v=2.2&t=h&s=256&x=%2&y=%3&z=%1");
lm
committed
mapadapter = new qmapcontrol::GoogleSatMapAdapter();
l = new qmapcontrol::MapLayer("Google Satellite", mapadapter);
lm
committed
overlay = new qmapcontrol::MapLayer("Overlay", mapadapter_overlay);
overlay->setVisible(false);
mc->addLayer(overlay);
// MAV FLIGHT TRACKS
tracks = new qmapcontrol::MapLayer("Tracking", mapadapter);
mc->addLayer(tracks);
// WAYPOINT LAYER
// create a layer with the mapadapter and type GeometryLayer (for waypoints)
lm
committed
geomLayer = new qmapcontrol::GeometryLayer("Waypoints", mapadapter);
Mariano Lizarraga
committed
mc->addLayer(geomLayer);
//
// Layer* gsatLayer = new Layer("Google Satellite", gsat, Layer::MapLayer);
// mc->addLayer(gsatLayer);
// SET INITIAL POSITION AND ZOOM
// Set default zoom level
mc->setZoom(16);
// Zurich, ETH
// Veracruz Mexico
//mc->setView(QPointF(-96.105208,19.138955));
// Add controls to select map provider
/////////////////////////////////////////////////
QActionGroup* mapproviderGroup = new QActionGroup(this);
osmAction = new QAction(QIcon(":/images/mapproviders/openstreetmap.png"), tr("OpenStreetMap"), mapproviderGroup);
yahooActionMap = new QAction(QIcon(":/images/mapproviders/yahoo.png"), tr("Yahoo: Map"), mapproviderGroup);
yahooActionSatellite = new QAction(QIcon(":/images/mapproviders/yahoo.png"), tr("Yahoo: Satellite"), mapproviderGroup);
googleActionMap = new QAction(QIcon(":/images/mapproviders/google.png"), tr("Google: Map"), mapproviderGroup);
googleSatAction = new QAction(QIcon(":/images/mapproviders/google.png"), tr("Google: Sat"), mapproviderGroup);
osmAction->setCheckable(true);
yahooActionMap->setCheckable(true);
yahooActionSatellite->setCheckable(true);
googleActionMap->setCheckable(true);
googleSatAction->setCheckable(true);
googleSatAction->setChecked(true);
connect(mapproviderGroup, SIGNAL(triggered(QAction*)),
this, SLOT(mapproviderSelected(QAction*)));
// yahooActionOverlay = new QAction(tr("Yahoo: street overlay"), this);
// yahooActionOverlay->setCheckable(true);
// yahooActionOverlay->setChecked(overlay->isVisible());
// connect(yahooActionOverlay, SIGNAL(toggled(bool)),
// overlay, SLOT(setVisible(bool)));
// mapproviderGroup->addAction(googleSatAction);
// mapproviderGroup->addAction(osmAction);
// mapproviderGroup->addAction(yahooActionOverlay);
// mapproviderGroup->addAction(googleActionMap);
// mapproviderGroup->addAction(yahooActionMap);
// mapproviderGroup->addAction(yahooActionSatellite);
// Create map provider selection menu
mapMenu = new QMenu(this);
mapMenu->addActions(mapproviderGroup->actions());
mapMenu->addSeparator();
// mapMenu->addAction(yahooActionOverlay);
mapButton = new QPushButton(this);
mapButton->setText("Map Source");
mapButton->setMenu(mapMenu);
lm
committed
mapButton->setStyleSheet(buttonStyle);
lm
committed
layout->setSpacing(0);
layout->addWidget(mc, 0, 0);
Mariano Lizarraga
committed
// create buttons to control the map (zoom, GPS tracking and WP capture)
QPushButton* zoomin = new QPushButton(QIcon(":/images/actions/list-add.svg"), "", this);
lm
committed
zoomin->setStyleSheet(buttonStyle);
QPushButton* zoomout = new QPushButton(QIcon(":/images/actions/list-remove.svg"), "", this);
lm
committed
zoomout->setStyleSheet(buttonStyle);
Mariano Lizarraga
committed
createPath = new QPushButton(QIcon(":/images/actions/go-bottom.svg"), "", this);
lm
committed
createPath->setStyleSheet(buttonStyle);
clearTracking = new QPushButton(QIcon(""), "", this);
lm
committed
clearTracking->setStyleSheet(buttonStyle);
followgps = new QPushButton(QIcon(":/images/actions/system-lock-screen.svg"), "", this);
lm
committed
followgps->setStyleSheet(buttonStyle);
QPushButton* goToButton = new QPushButton(QIcon(""), "T", this);
goToButton->setStyleSheet(buttonStyle);
zoomin->setMaximumWidth(30);
zoomout->setMaximumWidth(30);
createPath->setMaximumWidth(30);
clearTracking->setMaximumWidth(30);
followgps->setMaximumWidth(30);
lm
committed
goToButton->setMaximumWidth(30);
Mariano Lizarraga
committed
// Set checkable buttons
// TODO: Currently checked buttons are are very difficult to distinguish when checked.
// create a style and the slots to change the background so it is easier to distinguish
followgps->setCheckable(true);
createPath->setCheckable(true);
Mariano Lizarraga
committed
// add buttons to control the map (zoom, GPS tracking and WP capture)
QGridLayout* innerlayout = new QGridLayout(mc);
lm
committed
innerlayout->setMargin(3);
innerlayout->setSpacing(3);
innerlayout->addWidget(zoomin, 0, 0);
innerlayout->addWidget(zoomout, 1, 0);
innerlayout->addWidget(followgps, 2, 0);
innerlayout->addWidget(createPath, 3, 0);
innerlayout->addWidget(clearTracking, 4, 0);
// Add spacers to compress buttons on the top left
innerlayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 5, 0);
lm
committed
innerlayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding), 0, 1, 0, 7);
innerlayout->addWidget(mapButton, 0, 6);
innerlayout->addWidget(goToButton, 0, 7);
innerlayout->setRowStretch(0, 1);
innerlayout->setRowStretch(1, 100);
Mariano Lizarraga
committed
// Connect the required signals-slots
Mariano Lizarraga
committed
connect(zoomin, SIGNAL(clicked(bool)),
mc, SLOT(zoomIn()));
Mariano Lizarraga
committed
connect(zoomout, SIGNAL(clicked(bool)),
mc, SLOT(zoomOut()));
lm
committed
connect(goToButton, SIGNAL(clicked()), this, SLOT(goTo()));
QList<UASInterface*> systems = UASManager::instance()->getUASList();
foreach(UASInterface* system, systems)
{
addUAS(system);
}
Mariano Lizarraga
committed
connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)),
this, SLOT(addUAS(UASInterface*)));
activeUASSet(UASManager::instance()->getActiveUAS());
lm
committed
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(activeUASSet(UASInterface*)));
Mariano Lizarraga
committed
connect(mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)),
this, SLOT(captureMapClick(const QMouseEvent*, const QPointF)));
Mariano Lizarraga
committed
connect(createPath, SIGNAL(clicked(bool)),
this, SLOT(createPathButtonClicked(bool)));
Mariano Lizarraga
committed
connect(geomLayer, SIGNAL(geometryClicked(Geometry*,QPoint)),
this, SLOT(captureGeometryClick(Geometry*, QPoint)));
connect(geomLayer, SIGNAL(geometryDragged(Geometry*, QPointF)),
this, SLOT(captureGeometryDrag(Geometry*, QPointF)));
connect(geomLayer, SIGNAL(geometryEndDrag(Geometry*, QPointF)),
this, SLOT(captureGeometryEndDrag(Geometry*, QPointF)));
Mariano Lizarraga
committed
// Configure the WP Path's pen
pointPen = new QPen(QColor(0, 255,0));
pointPen->setWidth(3);
waypointPath = new qmapcontrol::LineString (wps, "Waypoint path", pointPen);
mc->layer("Waypoints")->addGeometry(waypointPath);
//Camera Control
// CAMERA INDICATOR LAYER
// create a layer with the mapadapter and type GeometryLayer (for camera indicator)
camLayer = new qmapcontrol::GeometryLayer("Camera", mapadapter);
mc->addLayer(camLayer);
//camLine = new qmapcontrol::LineString(camPoints,"Camera Eje", camBorderPen);
drawCamBorder = false;
radioCamera = 10;
lm
committed
void MapWidget::goTo()
{
bool ok;
QString text = QInputDialog::getText(this, tr("Please enter coordinates"),
tr("Coordinates (Lat,Lon):"), QLineEdit::Normal,
QString("%1,%2").arg(mc->currentCoordinate().x()).arg(mc->currentCoordinate().y()), &ok);
if (ok && !text.isEmpty())
{
QStringList split = text.split(",");
if (split.length() == 2)
{
bool convert;
double latitude = split.first().toDouble(&convert);
ok &= convert;
double longitude = split.last().toDouble(&convert);
ok &= convert;
if (ok)
{
mc->setView(QPointF(latitude, longitude));
}
}
}
}
Mariano Lizarraga
committed
void MapWidget::mapproviderSelected(QAction* action)
{
//delete mapadapter;
mapButton->setText(action->text());
if (action == osmAction)
{
int zoom = mapadapter->adaptedZoom();
mc->setZoom(0);
lm
committed
mapadapter = new qmapcontrol::OSMMapAdapter();
l->setMapAdapter(mapadapter);
geomLayer->setMapAdapter(mapadapter);
// yahooActionOverlay->setEnabled(false);
// yahooActionOverlay->setChecked(false);
}
else if (action == yahooActionMap)
{
int zoom = mapadapter->adaptedZoom();
mc->setZoom(0);
lm
committed
mapadapter = new qmapcontrol::YahooMapAdapter();
l->setMapAdapter(mapadapter);
geomLayer->setMapAdapter(mapadapter);
// yahooActionOverlay->setEnabled(false);
// yahooActionOverlay->setChecked(false);
}
else if (action == yahooActionSatellite)
{
int zoom = mapadapter->adaptedZoom();
QPointF a = mc->currentCoordinate();
mc->setZoom(0);
lm
committed
mapadapter = new qmapcontrol::YahooMapAdapter("us.maps3.yimg.com", "/aerial.maps.yimg.com/png?v=1.7&t=a&s=256&x=%2&y=%3&z=%1");
// yahooActionOverlay->setEnabled(true);
}
else if (action == googleActionMap)
{
int zoom = mapadapter->adaptedZoom();
mc->setZoom(0);
lm
committed
mapadapter = new qmapcontrol::GoogleMapAdapter();
l->setMapAdapter(mapadapter);
geomLayer->setMapAdapter(mapadapter);
// yahooActionOverlay->setEnabled(false);
// yahooActionOverlay->setChecked(false);
}
else if (action == googleSatAction)
{
int zoom = mapadapter->adaptedZoom();
mc->setZoom(0);
lm
committed
mapadapter = new qmapcontrol::GoogleSatMapAdapter();
l->setMapAdapter(mapadapter);
geomLayer->setMapAdapter(mapadapter);
// yahooActionOverlay->setEnabled(false);
// yahooActionOverlay->setChecked(false);
}
else
{
mapButton->setText("Select..");
}
Mariano Lizarraga
committed
}
void MapWidget::createPathButtonClicked(bool checked)
if (createPath->isChecked())
{
// change the cursor shape
this->setCursor(Qt::PointingHandCursor);
mc->setMouseMode(qmapcontrol::MapControl::None);
// emit signal start to create a Waypoint global
pixhawk
committed
//emit createGlobalWP(true, mc->currentCoordinate());
// // Clear the previous WP track
// // TODO: Move this to an actual clear track button and add a warning dialog
// mc->layer("Waypoints")->clearGeometries();
// wps.clear();
// path->setPoints(wps);
// mc->layer("Waypoints")->addGeometry(path);
// wpIndex.clear();
mc->setMouseMode(qmapcontrol::MapControl::Panning);
Mariano Lizarraga
committed
}
Mariano Lizarraga
committed
/**
* Captures a click on the map and if in create WP path mode, it adds the WP on MouseButtonRelease
*
* @param event The mouse event
* @param coordinate The coordinate in which it occured the mouse event
* @note This slot is connected to the mouseEventCoordinate of the QMapControl object
*/
Mariano Lizarraga
committed
pixhawk
committed
void MapWidget::captureMapClick(const QMouseEvent* event, const QPointF coordinate)
{
//qDebug() << mc->mouseMode();
if (QEvent::MouseButtonRelease == event->type() && createPath->isChecked())
pixhawk
committed
{
// Create waypoint name
QString str;
// create the WP and set everything in the LineString to display the path
Waypoint2DIcon* tempCirclePoint;
pixhawk
committed
mav->getWaypointManager()->addWaypoint(new Waypoint(mav->getWaypointManager()->getWaypointList().count(), coordinate.x(), coordinate.y()));
// QVector<Waypoint*> mavWps = mav->getWaypointManager()->getWaypointList();
// str = QString("%1").arg(mavWps.count());
// tempCirclePoint = new Waypoint2DIcon(coordinate.x(), coordinate.y(), 20, str, qmapcontrol::Point::Middle, new QPen(mav->getColor()));
// //mav->getWaypointManager()->addWaypoint(new Waypoint(mavWps.count(), coordinate.x(), coordinate.y()));
pixhawk
committed
str = QString("%1").arg(waypointPath->numberOfPoints());
tempCirclePoint = new Waypoint2DIcon(coordinate.x(), coordinate.y(), 20, str, qmapcontrol::Point::Middle);
pixhawk
committed
mc->layer("Waypoints")->addGeometry(tempCirclePoint);
pixhawk
committed
qmapcontrol::Point* tempPoint = new qmapcontrol::Point(coordinate.x(), coordinate.y(),str);
wps.append(tempPoint);
waypointPath->addPoint(tempPoint);
// if (mav)
// {
// QPen* pathPen = new QPen(mav->getColor());
// pathPen->setWidth(2);
// waypointPath->setPen(pathPen);
// }
pixhawk
committed
wpIndex.insert(str,tempPoint);
// Refresh the screen
mc->updateRequest(tempPoint->boundingBox().toRect());
}
pixhawk
committed
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
//emit captureMapCoordinateClick(coordinate);
}
}
void MapWidget::updateWaypoint(int uas, Waypoint* wp)
{
if (uas == this->mav->getUASID())
{
// Create waypoint name
QString str = QString("%1").arg(wp->getId());
// Check if wp exists yet
if (!wpIndex.contains(str))
{
QPointF coordinate;
coordinate.setX(wp->getX());
coordinate.setY(wp->getY());
createWaypointGraphAtMap(coordinate);
qDebug() << "Waypoint Index did not contain" << str;
}
else
{
// Waypoint exists, update it
if(!waypointIsDrag)
{
qDebug() <<"indice WP= "<< wp->getId() <<"\n";
QPointF coordinate;
coordinate.setX(wp->getX());
coordinate.setY(wp->getY());
Point* waypoint;
waypoint = wpIndex[str];
if (waypoint)
{
// First set waypoint coordinate
waypoint->setCoordinate(coordinate);
// Then waypoint line coordinate
Point* linesegment = waypointPath->points().at(wp->getId());
if (linesegment)
{
linesegment->setCoordinate(coordinate);
}
//point2Find = dynamic_cast <Point*> (mc->layer("Waypoints")->get_Geometry(wp->getId()));
//point2Find->setCoordinate(coordinate);
mc->updateRequest(waypoint->boundingBox().toRect());
}
}
}
lm
committed
}
void MapWidget::createWaypointGraphAtMap(const QPointF coordinate)
{
if (!wpExists(coordinate))
{
// Create waypoint name
QString str;
pixhawk
committed
// create the WP and set everything in the LineString to display the path
//CirclePoint* tempCirclePoint = new CirclePoint(coordinate.x(), coordinate.y(), 10, str);
Waypoint2DIcon* tempCirclePoint;
pixhawk
committed
int uas = mav->getUASID();
str = QString("%1").arg(mav->getWaypointManager()->getWaypointList().count());
qDebug() << "Waypoint list count:" << str;
tempCirclePoint = new Waypoint2DIcon(coordinate.x(), coordinate.y(), 20, str, qmapcontrol::Point::Middle, mavPens.value(uas));
pixhawk
committed
str = QString("%1").arg(waypointPath->numberOfPoints());
tempCirclePoint = new Waypoint2DIcon(coordinate.x(), coordinate.y(), 20, str, qmapcontrol::Point::Middle);
}
mc->layer("Waypoints")->addGeometry(tempCirclePoint);
Point* tempPoint = new Point(coordinate.x(), coordinate.y(),str);
wps.append(tempPoint);
waypointPath->addPoint(tempPoint);
qDebug()<<"Funcion createWaypointGraphAtMap WP= "<<str<<" -> x= "<<tempPoint->latitude()<<" y= "<<tempPoint->longitude();
pixhawk
committed
mc->updateRequest(tempPoint->boundingBox().toRect());
//// // emit signal mouse was clicked
// emit captureMapCoordinateClick(coordinate);
}
pixhawk
committed
int MapWidget::wpExists(const QPointF coordinate)
{
for (int i = 0; i < wps.size(); i++){
if (wps.at(i)->latitude() == coordinate.y() &&
pixhawk
committed
wps.at(i)->longitude()== coordinate.x())
{
pixhawk
committed
void MapWidget::captureGeometryClick(Geometry* geom, QPoint point)
{
mc->setMouseMode(qmapcontrol::MapControl::None);
pixhawk
committed
void MapWidget::captureGeometryDrag(Geometry* geom, QPointF coordinate)
{
mc->updateRequest(geom->boundingBox().toRect());
pixhawk
committed
// Get waypoint index in list
bool wpIndexOk;
int index = geom->name().toInt(&wpIndexOk);
qmapcontrol::Point* point2Find;
point2Find = wpIndex[geom->name()];
if (point2Find)
{
point2Find->setCoordinate(coordinate);
point2Find = dynamic_cast <qmapcontrol::Point*> (geom);
if (point2Find)
{
point2Find->setCoordinate(coordinate);
pixhawk
committed
if (wpIndexOk)
{
mc->updateRequest(point2Find->boundingBox().toRect());
if (mav)
{
QVector<Waypoint*> wps = mav->getWaypointManager()->getWaypointList();
if (wps.size() > index)
{
wps.at(index)->setX(coordinate.x());
wps.at(index)->setY(coordinate.y());
mav->getWaypointManager()->notifyOfChange(wps.at(index));
}
}
}
// qDebug() << geom->name();
temp = geom->get_myIndex();
//qDebug() << temp;
emit sendGeometryEndDrag(coordinate,temp);
}
}
void MapWidget::captureGeometryEndDrag(Geometry* geom, QPointF coordinate)
tecnosapiens
committed
{
Q_UNUSED(geom);
Q_UNUSED(coordinate);
// TODO: Investigate why when creating the waypoint path this slot is being called
// Only change the mouse mode back to panning when not creating a WP path
if (!createPath->isChecked())
{
waypointIsDrag = false;
mc->setMouseMode(qmapcontrol::MapControl::Panning);
}
Mariano Lizarraga
committed
}
/**
*
* @param uas the UAS/MAV to monitor/display with the HUD
*/
void MapWidget::addUAS(UASInterface* uas)
{
connect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateGlobalPosition(UASInterface*,double,double,double,quint64)));
pixhawk
committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
//connect(uas->getWaypointManager(), SIGNAL(waypointListChanged()), this, SLOT(redoWaypoints()));
}
void MapWidget::updateWaypointList(int uas)
{
// Get already existing waypoints
UASInterface* uasInstance = UASManager::instance()->getUASForId(uas);
if (uasInstance)
{
QVector<Waypoint*> wpList = uasInstance->getWaypointManager()->getWaypointList();
// Clear if necessary
if (wpList.count() == 0)
{
clearWaypoints(uas);
return;
}
// Load all existing waypoints into map view
foreach (Waypoint* wp, wpList)
{
updateWaypoint(mav->getUASID(), wp);
}
// Delete now unused wps
if (wpIndex.count() > wpList.count())
{
for (int i = wpList.count(); i < wpIndex.count(); ++i)
{
wpIndex.remove(QString("%i").arg(i));
QRect updateRect = wps.at(i)->boundingBox().toRect();
wps.removeAt(i);
waypointPath->points().removeAt(i);
mc->updateRequest(updateRect);
}
}
}
}
void MapWidget::redoWaypoints(int uas)
{
// QObject* sender = QObject::sender();
// UASWaypointManager* manager = dynamic_cast<UASWaypointManager*>(sender);
// if (sender)
// {
// Get waypoint list for this MAV
// Clear all waypoints
clearWaypoints();
// Re-add the updated waypoints
// }
updateWaypointList(uas);
lm
committed
void MapWidget::activeUASSet(UASInterface* uas)
{
pixhawk
committed
// Disconnect old MAV
if (mav)
{
// clear path create on the map
disconnect(mav->getWaypointManager(), SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int)));
// add Waypoint widget in the WaypointList widget when mouse clicked
disconnect(this, SIGNAL(waypointCreated(Waypoint*)), mav->getWaypointManager(), SLOT(addWaypoint(Waypoint*)));
// it notifies that a waypoint global goes to do create and a map graphic too
//connect(waypointsDockWidget->widget(), SIGNAL(createWaypointAtMap(QPointF)), mapWidget, SLOT(createWaypointGraphAtMap(QPointF)));
}
lm
committed
if (uas)
{
mav = uas;
pixhawk
committed
QColor color = mav->getColor().lighter(100);
color.setAlphaF(0.6);
QPen* pen = new QPen(color);
pixhawk
committed
pen->setWidth(2.0);
mavPens.insert(mav->getUASID(), pen);
// FIXME Remove after refactoring
waypointPath->setPen(pen);
// Delete all waypoints and start fresh
redoWaypoints();
// clear path create on the map
connect(mav->getWaypointManager(), SIGNAL(waypointListChanged(int)), this, SLOT(updateWaypointList(int)));
// add Waypoint widget in the WaypointList widget when mouse clicked
connect(this, SIGNAL(waypointCreated(Waypoint*)), mav->getWaypointManager(), SLOT(addWaypoint(Waypoint*)));
lm
committed
}
}
/**
* Updates the global position of one MAV and append the last movement to the trail
*
* @param uas The unmanned air system
* @param lat Latitude in WGS84 ellipsoid
* @param lon Longitutde in WGS84 ellipsoid
* @param alt Altitude over mean sea level
* @param usec Timestamp of the position message in milliseconds FIXME will move to microseconds
*/
void MapWidget::updateGlobalPosition(UASInterface* uas, double lat, double lon, double alt, quint64 usec)
{
Q_UNUSED(usec);
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
// create a LineString
//QList<Point*> points;
// Points with a circle
// A QPen can be used to customize the
//pointpen->setWidth(3);
//points.append(new CirclePoint(lat, lon, 10, uas->getUASName(), Point::Middle, pointpen));
MAV2DIcon* p;
if (!uasIcons.contains(uas->getUASID()))
{
// Get the UAS color
QColor uasColor = uas->getColor();
// Icon
QPen* pointpen = new QPen(uasColor);
qDebug() << uas->getUASName();
p = new MAV2DIcon(lat, lon, 20, uas->getUASName(), qmapcontrol::Point::Middle, pointpen);
uasIcons.insert(uas->getUASID(), p);
tracks->addGeometry(p);
// Line
// A QPen also can use transparency
QList<qmapcontrol::Point*> points;
points.append(new qmapcontrol::Point(lat, lon, ""));
QPen* linepen = new QPen(uasColor.darker());
linepen->setWidth(2);
// Create tracking line string
qmapcontrol::LineString* ls = new qmapcontrol::LineString(points, uas->getUASName(), linepen);
uasTrails.insert(uas->getUASID(), ls);
// Add the LineString to the layer
mc->layer("Tracking")->addGeometry(ls);
}
else
{
p = dynamic_cast<MAV2DIcon*>(uasIcons.value(uas->getUASID()));
if (p)
{
p->setCoordinate(QPointF(lat, lon));
p->setYaw(uas->getYaw());
}
// Extend trail
uasTrails.value(uas->getUASID())->addPoint(new qmapcontrol::Point(lat, lon, ""));
}
mc->updateRequest(p->boundingBox().toRect());
//mc->updateRequestNew();//(uasTrails.value(uas->getUASID())->boundingBox().toRect());
// Limit the position update rate
if (currTime - lastUpdate > 120)
// Sets the view to the interesting area
if (followgps->isChecked())
updatePosition(0, lat, lon);
// Refresh the screen
//mc->updateRequestNew();
/**
* Center the view on this position
*/
void MapWidget::updatePosition(float time, double lat, double lon)
//gpsposition->setText(QString::number(time) + " / " + QString::number(lat) + " / " + QString::number(lon));
}
}
void MapWidget::wheelEvent(QWheelEvent *event)
{
int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15;
// Calculate new zoom level
int newZoom = mc->currentZoom()+numSteps;
// Set new zoom level, level is bounded by map control
mc->setZoom(newZoom);
// Detail zoom level is the number of steps zoomed in further
// after the bounding has taken effect
detailZoom = qAbs(qMin(0, mc->currentZoom()-newZoom));
updateCameraPosition(20*newZoom,0,"no");
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
}
void MapWidget::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Plus:
mc->zoomIn();
break;
case Qt::Key_Minus:
mc->zoomOut();
break;
case Qt::Key_Left:
mc->scrollLeft(this->width()/scrollStep);
break;
case Qt::Key_Right:
mc->scrollRight(this->width()/scrollStep);
break;
case Qt::Key_Down:
mc->scrollDown(this->width()/scrollStep);
break;
case Qt::Key_Up:
mc->scrollUp(this->width()/scrollStep);
break;
default:
QWidget::keyPressEvent(event);
}
}
void MapWidget::resizeEvent(QResizeEvent* event )
Q_UNUSED(event);
mc->resize(this->size());
void MapWidget::showEvent(QShowEvent* event)
{
Q_UNUSED(event);
}
void MapWidget::hideEvent(QHideEvent* event)
{
Q_UNUSED(event);
}
void MapWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
pixhawk
committed
void MapWidget::clearWaypoints(int uas)
{
// Clear the previous WP track
mc->layer("Waypoints")->clearGeometries();
wps.clear();
pixhawk
committed
waypointPath->points().clear();
mc->layer("Waypoints")->addGeometry(waypointPath);
wpIndex.clear();
mc->updateRequestNew();//(waypointPath->boundingBox().toRect());
tecnosapiens
committed
if(createPath->isChecked())
{
createPath->click();
}
pixhawk
committed
qDebug() << "CLEARING WAYPOINTS";
pixhawk
committed
void MapWidget::clearPath(int uas)
{
mc->layer("Tracking")->clearGeometries();
foreach (qmapcontrol::LineString* ls, uasTrails)
{
QPen* linepen = ls->pen();
delete ls;
qmapcontrol::LineString* lsNew = new qmapcontrol::LineString(QList<qmapcontrol::Point*>(), "", linepen);
mc->layer("Tracking")->addGeometry(lsNew);
}
// FIXME update this with update request only for bounding box of trails
mc->updateRequestNew();//(QRect(0, 0, width(), height()));
tecnosapiens
committed
void MapWidget::updateCameraPosition(double radio, double bearing, QString dir)
{
//camPoints.clear();
QPointF currentPos = mc->currentCoordinate();
// QPointF actualPos = getPointxBearing_Range(currentPos.y(),currentPos.x(),bearing,distance);
// qmapcontrol::Point* tempPoint1 = new qmapcontrol::Point(currentPos.x(), currentPos.y(),"inicial",qmapcontrol::Point::Middle);
// qmapcontrol::Point* tempPoint2 = new qmapcontrol::Point(actualPos.x(), actualPos.y(),"final",qmapcontrol::Point::Middle);
// camPoints.append(tempPoint1);
// camPoints.append(tempPoint2);
QPen* camBorderPen = new QPen(QColor(255,0,0));
if(drawCamBorder)
{
//clear camera borders
mc->layer("Camera")->clearGeometries();
//create a camera borders
qmapcontrol::CirclePoint* camBorder = new qmapcontrol::CirclePoint(currentPos.x(), currentPos.y(), radio, "camBorder", qmapcontrol::Point::Middle, camBorderPen);
//camBorder->setCoordinate(currentPos);
mc->layer("Camera")->addGeometry(camBorder);
// mc->layer("Camera")->addGeometry(camLine);
else
{
//clear camera borders
mc->layer("Camera")->clearGeometries();
mc->updateRequestNew();
}
void MapWidget::drawBorderCamAtMap(bool status)
{
drawCamBorder = status;
updateCameraPosition(20,0,"no");
}
QPointF MapWidget::getPointxBearing_Range(double lat1, double lon1, double bearing, double distance)
{
QPointF temp;
bearing = bearing*rad;
temp.setX((lon1 + ((distance/60) * (sin(bearing)))));
temp.setY((lat1 + ((distance/60) * (cos(bearing)))));