Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
if (!uasIcons.contains(uas->getUASID()))
{
// Get the UAS color
QColor uasColor = uas->getColor();
// Icon
//QPen* pointpen = new QPen(uasColor);
qDebug() << "2D MAP: ADDING" << uas->getUASName() << __FILE__ << __LINE__;
p = new MAV2DIcon(uas, 68, uas->getSystemType(), uas->getColor(), QString("%1").arg(uas->getUASID()), qmapcontrol::Point::Middle);
uasIcons.insert(uas->getUASID(), p);
mc->layer("Waypoints")->addGeometry(p);
// Line
// A QPen also can use transparency
// QList<qmapcontrol::Point*> points;
// points.append(new qmapcontrol::Point(coordinate.x(), coordinate.y()));
// QPen* linepen = new QPen(uasColor.darker());
// linepen->setWidth(2);
// // Create tracking line string
// qmapcontrol::LineString* ls = new qmapcontrol::LineString(points, QString("%1").arg(uas->getUASID()), linepen);
// uasTrails.insert(uas->getUASID(), ls);
// // Add the LineString to the layer
// mc->layer("Waypoints")->addGeometry(ls);
}
else
{
// p = dynamic_cast<MAV2DIcon*>(uasIcons.value(uas->getUASID()));
// if (p)
// {
p = uasIcons.value(uas->getUASID());
p->setCoordinate(QPointF(lon, lat));
//p->setYaw(uas->getYaw());
// }
// Extend trail
// uasTrails.value(uas->getUASID())->addPoint(new qmapcontrol::Point(coordinate.x(), coordinate.y()));
}
if (isVisible()) mc->updateRequest(p->boundingBox().toRect());
//if (isVisible()) mc->updateRequestNew();//(uasTrails.value(uas->getUASID())->boundingBox().toRect());
if (this->mav && uas->getUASID() == this->mav->getUASID())
// Limit the position update rate
quint64 currTime = MG::TIME::getGroundTimeNow();
if (currTime - lastUpdate > 120)
{
lastUpdate = currTime;
// Sets the view to the interesting area
if (followgps->isChecked())
{
updatePosition(0, lon, lat);
}
else
{
// Refresh the screen
//if (isVisible()) 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));
if (followgps->isChecked() && isVisible() && mc)
if (mc) mc->setView(QPointF(lat, lon));
}
}
void MapWidget::wheelEvent(QWheelEvent *event)
{
if (mc)
{
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));
// visual field of camera
//updateCameraPosition(20*newZoom,0,"no");
}
void MapWidget::keyPressEvent(QKeyEvent *event)
{
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
if (mc)
{
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);
void MapWidget::showEvent(QShowEvent* event)
{
Q_UNUSED(event);
// if (isVisible())
// {
// if (!initialized)
// {
// init();
// }
// }
}
void MapWidget::hideEvent(QHideEvent* event)
{
Q_UNUSED(event);
if (mc)
{
QSettings settings;
settings.beginGroup("QGC_MAPWIDGET");
QPointF currentPos = mc->currentCoordinate();
settings.setValue("LAST_LATITUDE", currentPos.y());
settings.setValue("LAST_LONGITUDE", currentPos.x());
settings.setValue("LAST_ZOOM", mc->currentZoom());
settings.endGroup();
settings.beginGroup("QGC_MAPINDEX");
settings.setValue("MAP_INDEX", index);
settings.endGroup();
settings.beginGroup("QGC_HOMEPOSITION");
settings.setValue("HOME_LATITUDE", homeCoordinate.y());
settings.setValue("HOME_LONGITUDE", homeCoordinate.x());
settings.endGroup();
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)
pixhawk
committed
{
Q_UNUSED(uas);
// Clear the previous WP track
pixhawk
committed
//mc->layer("Waypoints")->clearGeometries();
wps.clear();
foreach (Point* p, wpIcons)
{
mc->layer("Waypoints")->removeGeometry(p);
}
wpIcons.clear();
pixhawk
committed
// Get bounding box of this object BEFORE deleting the content
QRect box = waypointPath->boundingBox().toRect();
pixhawk
committed
// Delete the content
waypointPath->points().clear();
//delete waypointPath;
//waypointPath = new
//mc->layer("Waypoints")->addGeometry(waypointPath);
//wpIndex.clear();
if (isVisible()) mc->updateRequest(box);//(waypointPath->boundingBox().toRect());
pixhawk
committed
if(createPath->isChecked())
{
createPath->click();
}
}
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
if (isVisible()) mc->updateRequestNew();//(QRect(0, 0, width(), height()));
tecnosapiens
committed
void MapWidget::createHomePosition(const QMouseEvent *event, const QPointF coordinate)
{
if (QEvent::MouseButtonRelease == event->type() && setHome->isChecked())
{
this->createHomePosition(coordinate);
}
}
void MapWidget::createHomePosition(const QPointF coordinate)
{
homeCoordinate= coordinate;
Waypoint2DIcon* tempCirclePoint;
double latitude = homeCoordinate.y();
double longitude = homeCoordinate.x();
tempCirclePoint = new Waypoint2DIcon(
longitude,
latitude,
20, "g", qmapcontrol::Point::Middle);
QPen* pencil = new QPen(Qt::blue);
tempCirclePoint->setPen(pencil);
mc->layer("Station")->clearGeometries();
mc->layer("Station")->addGeometry(tempCirclePoint);
qmapcontrol::Point* tempPoint = new qmapcontrol::Point(latitude, longitude,"g");
if (isVisible())
{
mc->updateRequest(tempPoint->boundingBox().toRect());
}
}
void MapWidget::createHomePositionClick(bool click)
{
Q_UNUSED(click);
if (!setHome->isChecked())
{
if(mav)
{
UASManager::instance()->setHomePosition(
static_cast<double>(homeCoordinate.y()),
static_cast<double>(homeCoordinate.x()), 0);
qDebug()<<"Set home position "<<homeCoordinate.y()<<" "<<homeCoordinate.x();
}