diff --git a/ground/src/libs/qmapcontrol/src/mapcontrol.cpp b/ground/src/libs/qmapcontrol/src/mapcontrol.cpp index 8df71f761..d93ed7525 100644 --- a/ground/src/libs/qmapcontrol/src/mapcontrol.cpp +++ b/ground/src/libs/qmapcontrol/src/mapcontrol.cpp @@ -292,14 +292,17 @@ namespace qmapcontrol layermanager->scrollView(offset); pre_click_px = QPoint(evnt->x(), evnt->y()); } - else if (mousepressed && mymousemode == Dragging) + else + if (mousepressed && mymousemode == Dragging) { current_mouse_pos = QPoint(evnt->x(), evnt->y()); } - // emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos()))); + + emit mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos())); // cathy .. uncommented to produce mouse move events update(); - // emit(mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos()))); + +// emit mouseEventCoordinate(evnt, clickToWorldCoordinate(evnt->pos())); } // added by cathy diff --git a/ground/src/plugins/map/images/gsc.png b/ground/src/plugins/map/images/gsc.png new file mode 100644 index 000000000..8c569c441 Binary files /dev/null and b/ground/src/plugins/map/images/gsc.png differ diff --git a/ground/src/plugins/map/images/uav.png b/ground/src/plugins/map/images/uav.png new file mode 100644 index 000000000..f9e14fd7a Binary files /dev/null and b/ground/src/plugins/map/images/uav.png differ diff --git a/ground/src/plugins/map/images/waypoint.png b/ground/src/plugins/map/images/waypoint.png new file mode 100644 index 000000000..de4473078 Binary files /dev/null and b/ground/src/plugins/map/images/waypoint.png differ diff --git a/ground/src/plugins/map/map.pro b/ground/src/plugins/map/map.pro index 1b7e43e4f..2fb6e0d11 100644 --- a/ground/src/plugins/map/map.pro +++ b/ground/src/plugins/map/map.pro @@ -1,20 +1,21 @@ -TEMPLATE = lib -TARGET = MapGadget -include(../../openpilotgcsplugin.pri) -include(../../plugins/coreplugin/coreplugin.pri) -include(../../libs/qmapcontrol/qmapcontrol.pri) -include(../../plugins/uavobjects/uavobjects.pri) -HEADERS += mapplugin.h \ - mapgadgetconfiguration.h \ - mapgadget.h \ - mapgadgetwidget.h \ - mapgadgetfactory.h \ - mapgadgetoptionspage.h -SOURCES += mapplugin.cpp \ - mapgadgetconfiguration.cpp \ - mapgadget.cpp \ - mapgadgetfactory.cpp \ - mapgadgetwidget.cpp \ - mapgadgetoptionspage.cpp -OTHER_FILES += MapGadget.pluginspec -FORMS += mapgadgetoptionspage.ui +TEMPLATE = lib +TARGET = MapGadget +include(../../openpilotgcsplugin.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(../../libs/qmapcontrol/qmapcontrol.pri) +include(../../plugins/uavobjects/uavobjects.pri) +HEADERS += mapplugin.h \ + mapgadgetconfiguration.h \ + mapgadget.h \ + mapgadgetwidget.h \ + mapgadgetfactory.h \ + mapgadgetoptionspage.h +SOURCES += mapplugin.cpp \ + mapgadgetconfiguration.cpp \ + mapgadget.cpp \ + mapgadgetfactory.cpp \ + mapgadgetwidget.cpp \ + mapgadgetoptionspage.cpp +OTHER_FILES += MapGadget.pluginspec +FORMS += mapgadgetoptionspage.ui +RESOURCES += map.qrc diff --git a/ground/src/plugins/map/map.qrc b/ground/src/plugins/map/map.qrc new file mode 100644 index 000000000..3ddd5f458 --- /dev/null +++ b/ground/src/plugins/map/map.qrc @@ -0,0 +1,7 @@ + + + images/uav.png + images/gsc.png + images/waypoint.png + + diff --git a/ground/src/plugins/map/mapgadgetwidget.cpp b/ground/src/plugins/map/mapgadgetwidget.cpp index 0169b653e..2f312aab0 100644 --- a/ground/src/plugins/map/mapgadgetwidget.cpp +++ b/ground/src/plugins/map/mapgadgetwidget.cpp @@ -30,27 +30,50 @@ #include #include "extensionsystem/pluginmanager.h" +// ************************************************************************************* +// constructor + MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent) { int size = 256; - gscButton = 0; // added by cathy - uavButton = 0; // added by cathy + gscButton = NULL; + uavButton = NULL; - follow_uav = false; // added by cathy + follow_uav = false; + + gsc_pixmap.load(QString::fromUtf8(":/map/images/gsc.png")); + uav_pixmap.load(QString::fromUtf8(":/map/images/uav.png")); + waypoint_pixmap.load(QString::fromUtf8(":/map/images/waypoint.png")); +// waypoint_pixmap.load(QCoreApplication::applicationDirPath() + "/images/waypoint.png"); + + // test + if (gsc_pixmap.isNull()) QMessageBox::warning(this, tr("Image Error"), tr("Missing ") + QString::fromUtf8(":/map/images/gsc.png")); + if (uav_pixmap.isNull()) QMessageBox::warning(this, tr("Image Error"), tr("Missing ") + QString::fromUtf8(":/map/images/uav.png")); + if (waypoint_pixmap.isNull()) QMessageBox::warning(this, tr("Image Error"), tr("Missing ") + QString::fromUtf8(":/map/images/waypoint.png")); + + // test + gsc_pixmap.save(QCoreApplication::applicationDirPath() + "/images/gsc2.png", "PNG"); + + // Get required UAVObjects + ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); + UAVObjectManager* objManager = pm->getObject(); + m_positionActual = PositionActual::GetInstance(objManager); m_mc = new MapControl(QSize(size, size)); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); +// setMouseTracking(true); + m_mc->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); m_mc->setMinimumSize(64, 64); m_mc->showScale(true); - m_mc->showLatLon(true); // added by cathy + m_mc->showLatLon(true); m_osmAdapter = new OSMMapAdapter(); - m_googleSatAdapter = new GoogleSatMapAdapter(); m_googleAdapter = new GoogleMapAdapter(); + m_googleSatAdapter = new GoogleSatMapAdapter(); m_yahooAdapter = new YahooMapAdapter(); m_osmLayer = new MapLayer("OpenStreetMap", m_osmAdapter); @@ -58,23 +81,46 @@ MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent) m_googleSatLayer = new MapLayer("Google Sat", m_googleSatAdapter); m_yahooLayer = new MapLayer("Yahoo", m_yahooAdapter); + // gsc and uav position layer + m_positionLayer = new GeometryLayer("PositionsLayer", m_osmAdapter); + + // Waypoint layer + m_wayPointLayer = new GeometryLayer("WayPointsLayer", m_osmAdapter); + m_osmLayer->setVisible(true); m_googleLayer->setVisible(false); m_googleSatLayer->setVisible(false); m_yahooLayer->setVisible(false); + m_positionLayer->setVisible(true); + m_wayPointLayer->setVisible(true); m_mc->addLayer(m_osmLayer); m_mc->addLayer(m_googleLayer); m_mc->addLayer(m_googleSatLayer); m_mc->addLayer(m_yahooLayer); + m_mc->addLayer(m_wayPointLayer); + m_mc->addLayer(m_positionLayer); + + PositionActual::DataFields data = m_positionActual->getData(); // get current position data + + heading = data.Heading; + + addCompass(QPointF(100, 100), 200); + + // create and add the GSC icon + gscPoint = new ImagePoint(data.Longitude, data.Latitude, &gsc_pixmap, "GSC", Point::Middle); + m_positionLayer->addGeometry(gscPoint); + connect(gscPoint, SIGNAL(geometryClicked(Geometry*, QPoint)), this, SLOT(gsc_uav_ClickEvent(Geometry*, QPoint))); + + // create and add the UAV icon + uavPoint = new ImagePoint(data.Longitude, data.Latitude, &uav_pixmap, "UAV", Point::Middle); + m_positionLayer->addGeometry(uavPoint); + connect(uavPoint, SIGNAL(geometryClicked(Geometry*, QPoint)), this, SLOT(gsc_uav_ClickEvent(Geometry*, QPoint))); addUserControls(); - gscPosition.setX(5.718888888888); // longitude - gscPosition.setY(58.963333333333); // latitude - - m_mc->setView(gscPosition); - m_mc->setZoom(10); + m_mc->setView(gscPoint->coordinate()); + m_mc->setZoom(2); m_mc->updateRequestNew(); QVBoxLayout *layout = new QVBoxLayout; @@ -83,13 +129,9 @@ MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent) layout->addWidget(m_mc); setLayout(layout); - // Get required UAVObjects - ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance(); - UAVObjectManager* objManager = pm->getObject(); - m_positionActual = PositionActual::GetInstance(objManager); + connect(m_mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(coordinateEvent(const QMouseEvent*, const QPointF))); - // added by cathy .. slot for receiving mouse click Coordinate events -// connect(m_mc, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(coordinateClicked(const QMouseEvent*, const QPointF))); // cmoss +// connect(m_wayPointLayer, SIGNAL(geometryClicked(Geometry*, QPoint)), this, SLOT(wayPointClickEvent(Geometry*, QPoint))); m_updateTimer = new QTimer(); m_updateTimer->setInterval(250); @@ -97,11 +139,16 @@ MapGadgetWidget::MapGadgetWidget(QWidget *parent) : QWidget(parent) m_updateTimer->start(); } +// ************************************************************************************* +// destructor + MapGadgetWidget::~MapGadgetWidget() { // Do nothing } +// ************************************************************************************* + void MapGadgetWidget::setZoom(int value) { m_mc->setZoom(value); @@ -114,19 +161,47 @@ void MapGadgetWidget::setPosition(QPointF pos) m_mc->updateRequestNew(); } -void MapGadgetWidget::updatePosition() -{ - if (follow_uav) - { - PositionActual::DataFields data = m_positionActual->getData(); - setPosition(QPointF(data.Longitude, data.Latitude)); - } -} - void MapGadgetWidget::setMapProvider(QString provider) { - foreach(QString layerName, m_mc->layers()) - m_mc->layer(layerName)->setVisible(layerName == provider); + foreach (QString layerName, m_mc->layers()) + { + Layer *layer = m_mc->layer(layerName); + MapAdapter *ma = (MapAdapter*)layer->mapadapter(); + + bool visible = layerName == provider; + + if (layerName == "WayPointsLayer" || layerName == "PositionsLayer") + { // leave the way points & positions layers visible + continue; + } + + layer->setVisible(visible); + + if (visible) + { // move the geomtery layers over to the selected map + m_positionLayer->setMapAdapter(ma); + m_wayPointLayer->setMapAdapter(ma); + } + } + + m_positionLayer->setVisible(true); + m_wayPointLayer->setVisible(true); + + m_mc->updateRequestNew(); +} + +// ************************************************************************************* + +void MapGadgetWidget::updatePosition() +{ + PositionActual::DataFields data = m_positionActual->getData(); // get current position data + + heading = data.Heading; // save the current UAV heading + + uavPoint->setCoordinate(QPointF(data.Longitude, data.Latitude)); // move the UAV icon + + if (follow_uav) + setPosition(uavPoint->coordinate()); // center the map onto the UAV } void MapGadgetWidget::resizeEvent(QResizeEvent *event) @@ -136,34 +211,34 @@ void MapGadgetWidget::resizeEvent(QResizeEvent *event) QWidget::resizeEvent(event); } +// ************************************************************************************* + void MapGadgetWidget::addUserControls() { // create the user controls - // cathy - gscButton = new QPushButton("GCS"); + gscButton = new QPushButton(tr("GCS")); gscButton->setMinimumWidth(50); gscButton->setMaximumWidth(50); - gscButton->setToolTip("Jump too ground station control"); + gscButton->setToolTip(tr("Center onto ground station control")); connect(gscButton, SIGNAL(clicked(bool)), this, SLOT(gscButtonClick())); - // cathy - uavButton = new QPushButton("UAV"); + uavButton = new QPushButton(tr("UAV")); uavButton->setMinimumWidth(50); uavButton->setMaximumWidth(50); uavButton->setCheckable(true); - uavButton->setToolTip("Stay centered on the UAV"); + uavButton->setToolTip(tr("Stay centered on the UAV")); connect(uavButton, SIGNAL(clicked(bool)), this, SLOT(uavButtonClick(bool))); QPushButton* zoomin = new QPushButton("+"); zoomin->setMinimumWidth(50); zoomin->setMaximumWidth(50); - zoomin->setToolTip("Zoom in"); + zoomin->setToolTip(tr("Zoom in")); connect(zoomin, SIGNAL(clicked(bool)), m_mc, SLOT(zoomIn())); QPushButton* zoomout = new QPushButton("-"); zoomout->setMinimumWidth(50); zoomout->setMaximumWidth(50); - zoomout->setToolTip("Zoom out"); + zoomout->setToolTip(tr("Zoom out")); connect(zoomout, SIGNAL(clicked(bool)), m_mc, SLOT(zoomOut())); // add zoom buttons to the layout of the MapControl @@ -180,63 +255,181 @@ void MapGadgetWidget::addUserControls() m_mc->setLayout(innerlayout); } -void MapGadgetWidget::gscButtonClick() // added by cathy +// ************************************************************************************* + +void MapGadgetWidget::gscButtonClick() { follow_uav = false; uavButton->setChecked(follow_uav); - // jump straight too the GSC location - setPosition(gscPosition); + setPosition(gscPoint->coordinate()); // center the map onto the ground station } -void MapGadgetWidget::uavButtonClick(bool checked) // added by cathy +// ************************************************************************************* + +void MapGadgetWidget::uavButtonClick(bool checked) { follow_uav = checked; -// follow_uav = uavButton->isChecked(); if (follow_uav) - { -// PositionActual::DataFields data = m_positionActual->getData(); -// setPosition(QPointF(data.Longitude, data.Latitude)); + { // immediately center the map onto the UAV .. rather than waiting for the timer to it +// PositionActual::DataFields data = m_positionActual->getData(); // get the current position data +// heading = data.Heading; // save the current UAV heading +// uavPoint->setCoordinate(QPointF(data.Longitude, data.Latitude)); // move the UAV icon +// setPosition(uavPoint->coordinate()); // center the map on the UAV } } -/* -// added by cathy .. comes here when the user mouse clicks on the map -void MapGadgetWidget::coordinateClicked(const QMouseEvent * evnt, const QPointF coordinate) // cmoss -{ - if (evnt->type() == QEvent::MouseButtonPress && evnt->buttons() == Qt::LeftButton) - { - QString coord_str = "lat " + QString::number(coordinate.y(), 'f', 6) + ", lon " + QString::number(coordinate.x(), 'f', 6); +// ************************************************************************************* - qDebug() << coordinate << ": " << evnt->x() << " / " << evnt->y() << " / " << coord_str; - - QMessageBox::information(this, "Coordinate Clicked", coord_str); - } -} -*/ -// added by cathy .. comes here when the user mouse clicks on an added geometry feature (ie, way points etc) -void MapGadgetWidget::geometryClicked(Geometry* geom, QPoint) // cmoss +void MapGadgetWidget::coordinateEvent(const QMouseEvent * evnt, const QPointF coordinate) // cmoss { - qDebug() << "parent: " << geom->parentGeometry(); - qDebug() << "Element clicked: " << geom->name(); - if (geom->hasClickedPoints()) + QString coord_str = "lat " + QString::number(coordinate.y(), 'f', 6) + ", lon " + QString::number(coordinate.x(), 'f', 6); + + if (evnt->type() == QEvent::MouseButtonPress) + { // mouse click event + if (evnt->buttons() == Qt::RightButton) { - QList pp = geom->clickedPoints(); - qDebug() << "number of child elements: " << pp.size(); - for (int i=0; iname(), pp.at(i)->name()); - } + qDebug() << coordinate << ": " << evnt->x() << " / " << evnt->y() << " / " << coord_str; + + QMessageBox::information(this, "Coordinate Clicked", coord_str); + } + } + else + { // mouse move event + qDebug() << coordinate << ": " << evnt->x() << " / " << evnt->y() << " / " << coord_str; + } +} + +// ************************************************************************************* +// comes here when the user mouse clicks on the GSC or the UAV + +void MapGadgetWidget::gsc_uav_ClickEvent(Geometry* geom, QPoint) +{ + qDebug() << "parent: " << geom->parentGeometry(); + qDebug() << "Element clicked: " << geom->name(); + + if (geom->hasClickedPoints()) + { + QList pp = geom->clickedPoints(); + + qDebug() << "number of child elements: " << pp.size(); + + for (int i=0; iname(), pp.at(i)->name()); + } + } + else + if (geom->GeometryType == "Point") + { + if (geom->name() == "UAV") + { + QMessageBox::information(this, geom->name(), tr("The UAV location")); } else - if (geom->GeometryType == "Point") + if (geom->name() == "GSC") { - QMessageBox::information(this, geom->name(), "just a point"); + QMessageBox::information(this, geom->name(), tr("The GSC location")); } + else + QMessageBox::information(this, geom->name(), tr("just a point")); + } } -// added by cathy +// ************************************************************************************* +// comes here when the user mouse clicks on a waypoint + +void MapGadgetWidget::wayPointClickEvent(Geometry* geom, QPoint) +{ + qDebug() << "parent: " << geom->parentGeometry(); + qDebug() << "Element clicked: " << geom->name(); + + if (geom->hasClickedPoints()) + { + QList pp = geom->clickedPoints(); + + qDebug() << "number of child elements: " << pp.size(); + + for (int i=0; iname(), pp.at(i)->name()); + } + } + else + if (geom->GeometryType == "Point") + { + QMessageBox::information(this, geom->name(), tr("just a point")); + } +} + +// ************************************************************************************* +// add a way point + +void MapGadgetWidget::addWayPoint(QPointF pos, QString name) +{ + if (waypoint_pixmap.isNull()) return; + + ImagePoint *waypoint = new ImagePoint(pos.x(), pos.y(), &waypoint_pixmap, name, qmapcontrol::Point::BottomRight); +// waypoint->setBaselevel(0); + connect(waypoint, SIGNAL(geometryClicked(Geometry *, QPoint)), this, SLOT(wayPointClickEvent(Geometry *, QPoint))); + + m_wayPointLayer->addGeometry(waypoint); +} + +// ************************************************************************************* +// add the compass + +void MapGadgetWidget::addCompass(QPointF pos, int size, QString name) +{ + + return; + +// if (compass_background_pixmap.isNull()) + { // create the compass background image + QImage image(size, size, QImage::Format_ARGB32_Premultiplied); + if (image.isNull()) return; + + image.fill(QColor(0, 0, 0, 0).rgba()); + + QPainter painter(&image); + painter.setRenderHints(QPainter::SmoothPixmapTransform | QPainter::Antialiasing | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing, true); + painter.setFont(font()); + + QPen pen = QPen(Qt::NoPen); + pen.setStyle(Qt::SolidLine); + pen.setWidth(1); + pen.setBrush(Qt::black); + painter.setPen(pen); + + QRadialGradient gradient(size / 2, size / 2, size / 2); + gradient.setColorAt(0.0, QColor(0, 0, 0, 0)); + gradient.setColorAt(0.05, QColor(0, 0, 0, 160)); + gradient.setColorAt(1.0, QColor(0, 0, 0, 160)); + +// QGradient gradient = QLinearGradient(0, 0, 0, 1); + gradient.setCoordinateMode(QGradient::ObjectBoundingMode); + gradient.setSpread(QGradient::PadSpread); + painter.setBrush(gradient); + +// painter.drawRect(image.rect()); + painter.drawEllipse(image.rect()); + + compass_background_pixmap = QPixmap::fromImage(image); + } + +// ImagePoint *compass = new ImagePoint(pos.x(), pos.y(), &compass_background_pixmap, name, qmapcontrol::Point::Middle); +// connect(compass, SIGNAL(geometryClicked(Geometry *, QPoint)), this, SLOT(compassClickEvent(Geometry *, QPoint))); + + m_compassImageOverlay = new FixedImageOverlay(0, 0, size, size, &compass_background_pixmap, "compass_background"); +// m_compassImageOverlay->setBaselevel(0); +// m_compassImageOverlay->setPen(); + + m_positionLayer->addGeometry(m_compassImageOverlay); +} + +// ************************************************************************************* + void MapGadgetWidget::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) // ESC @@ -286,3 +479,5 @@ void MapGadgetWidget::keyPressEvent(QKeyEvent* event) qDebug() << event->key() << endl; } } + +// ************************************************************************************* diff --git a/ground/src/plugins/map/mapgadgetwidget.h b/ground/src/plugins/map/mapgadgetwidget.h index 78f1d32b0..4bcde1bc2 100644 --- a/ground/src/plugins/map/mapgadgetwidget.h +++ b/ground/src/plugins/map/mapgadgetwidget.h @@ -33,6 +33,8 @@ #include "uavobjects/uavobjectmanager.h" #include "uavobjects/positionactual.h" +#include + using namespace qmapcontrol; class MapGadgetWidget : public QWidget @@ -47,8 +49,9 @@ public: void setMapProvider(QString provider); public slots: -// void coordinateClicked(const QMouseEvent* evnt, const QPointF coordinate); // added by cathy - void geometryClicked(Geometry* geom, QPoint coord_px); // added by cathy + void coordinateEvent(const QMouseEvent* evnt, const QPointF coordinate); // added by cathy + void gsc_uav_ClickEvent(Geometry* geom, QPoint coord_px); // added by cathy + void wayPointClickEvent(Geometry* geom, QPoint coord_px); // added by cathy void gscButtonClick(); // added by cathy void uavButtonClick(bool checked); // added by cathy @@ -65,6 +68,8 @@ private: bool follow_uav; // true if the map is to stay centered on the UAV + double heading; // compass/uav heading + MapControl *m_mc; MapAdapter *m_osmAdapter; @@ -77,14 +82,29 @@ private: Layer *m_googleSatLayer; Layer *m_yahooLayer; + Layer *m_positionLayer; + Layer *m_wayPointLayer; + + FixedImageOverlay *m_compassImageOverlay; + + ImagePoint *gscPoint; + ImagePoint *uavPoint; + QTimer *m_updateTimer; PositionActual *m_positionActual; - QPointF gscPosition; - QPushButton *gscButton; // added by cathy QPushButton *uavButton; // added by cathy + + QPixmap gsc_pixmap; + QPixmap uav_pixmap; + QPixmap waypoint_pixmap; + QPixmap compass_background_pixmap; + QPixmap compass_needle_pixmap; + + void addWayPoint(QPointF pos, QString name); + void addCompass(QPointF pos, int size = 200, QString name = "compass"); }; #endif /* MAPGADGETWIDGET_H_ */