diff --git a/ground/src/libs/opmapcontrol/src/core/opmaps.h b/ground/src/libs/opmapcontrol/src/core/opmaps.h index e6d6cfdea..fe81b93f1 100644 --- a/ground/src/libs/opmapcontrol/src/core/opmaps.h +++ b/ground/src/libs/opmapcontrol/src/core/opmaps.h @@ -65,8 +65,8 @@ namespace core { void setUseMemoryCache(const bool& value){useMemoryCache=value;} void setLanguage(const LanguageType::Types& language){Language=language;}//TODO LanguageType::Types GetLanguage(){return Language;}//TODO - AccessMode::Types GetAccessMode()const{return accessmode;}; - void setAccessMode(const AccessMode::Types& mode){accessmode=mode;}; + AccessMode::Types GetAccessMode()const{return accessmode;} + void setAccessMode(const AccessMode::Types& mode){accessmode=mode;} int MaxZoom; int RetryLoadTile; private: @@ -77,7 +77,7 @@ namespace core { TileCacheQueue TileDBcacheQueue; OPMaps(); - OPMaps(OPMaps const&){}; + OPMaps(OPMaps const&){} OPMaps& operator=(OPMaps const&){ return *this; } static OPMaps* m_pInstance; diff --git a/ground/src/libs/opmapcontrol/src/internals/pureprojection.cpp b/ground/src/libs/opmapcontrol/src/internals/pureprojection.cpp index 2e198705d..2f554ee50 100644 --- a/ground/src/libs/opmapcontrol/src/internals/pureprojection.cpp +++ b/ground/src/libs/opmapcontrol/src/internals/pureprojection.cpp @@ -178,7 +178,7 @@ Point PureProjection::FromLatLngToPixel(const PointLatLng::PointLatLng &p,const } - void PureProjection::FromGeodeticToCartesian(double Lat,double Lng,const double &Height, double &X, double &Y, double &Z) + void PureProjection::FromGeodeticToCartesian(double Lat,double Lng,double Height, double &X, double &Y, double &Z) { Lat = (PI / 180) * Lat; Lng = (PI / 180) * Lng; @@ -205,4 +205,18 @@ Point PureProjection::FromLatLngToPixel(const PointLatLng::PointLatLng &p,const Lat /= (PI / 180); Lng /= (PI / 180); } + double PureProjection::DistanceBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2) + { + double R = 6371; // km + double lat1=p1.Lat(); + double lat2=p2.Lat(); + double lon1=p1.Lng(); + double lon2=p2.Lng(); + double dLat = (lat2-lat1)* (PI / 180); + double dLon = (lon2-lon1)* (PI / 180); + double a = sin(dLat/2) * sin(dLat/2) + cos(lat1* (PI / 180)) * cos(lat2* (PI / 180)) * sin(dLon/2) * sin(dLon/2); + double c = 2 * atan2(sqrt(a), sqrt(1-a)); + double d = R * c; + return d; + } } diff --git a/ground/src/libs/opmapcontrol/src/internals/pureprojection.h b/ground/src/libs/opmapcontrol/src/internals/pureprojection.h index 97337c8e5..48699b86c 100644 --- a/ground/src/libs/opmapcontrol/src/internals/pureprojection.h +++ b/ground/src/libs/opmapcontrol/src/internals/pureprojection.h @@ -78,8 +78,9 @@ public: { return (R2D * rad); } - void FromGeodeticToCartesian(double Lat,double Lng,const double &Height, double &X, double &Y, double &Z); + void FromGeodeticToCartesian(double Lat,double Lng,double Height, double &X, double &Y, double &Z); void FromCartesianTGeodetic(const double &X,const double &Y,const double &Z, double &Lat, double &Lng); + static double DistanceBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2); protected: diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.png b/ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.png new file mode 100644 index 000000000..81c73a7c4 Binary files /dev/null and b/ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.png differ diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.svg b/ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.svg new file mode 100644 index 000000000..da6977bec --- /dev/null +++ b/ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp b/ground/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp index 425462881..8f02a8876 100644 --- a/ground/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp +++ b/ground/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.cpp @@ -25,7 +25,9 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "uavitem.h" #include "mapgraphicitem.h" + namespace mapcontrol { MapGraphicItem::MapGraphicItem(internals::Core *core, Configuration *configuration):core(core),config(configuration),MapRenderTransform(1), maxZoom(17),minZoom(2),zoomReal(0),isSelected(false),rotation(0) @@ -78,6 +80,10 @@ namespace mapcontrol WayPointItem* w=qgraphicsitem_cast(i); if(w) w->RefreshPos(); + UAVItem* ww=qgraphicsitem_cast(i); + if(ww) + ww->RefreshPos(); + } } void MapGraphicItem::ConstructLastImage(int const& zoomdiff) diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h b/ground/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h index e4804942e..1e6a327a5 100644 --- a/ground/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h +++ b/ground/src/libs/opmapcontrol/src/mapwidget/mapgraphicitem.h @@ -40,6 +40,7 @@ #include #include #include "waypointitem.h" +//#include "uavitem.h" namespace mapcontrol { class OPMapWidget; diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/mapresources.qrc b/ground/src/libs/opmapcontrol/src/mapwidget/mapresources.qrc index 938e0a82e..26a124e02 100644 --- a/ground/src/libs/opmapcontrol/src/mapwidget/mapresources.qrc +++ b/ground/src/libs/opmapcontrol/src/mapwidget/mapresources.qrc @@ -3,5 +3,6 @@ images/bigMarkerGreen.png images/marker.png images/compas.svg + images/airplane.svg diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/mapwidget.pro b/ground/src/libs/opmapcontrol/src/mapwidget/mapwidget.pro index c1524c3ef..635cfd94a 100644 --- a/ground/src/libs/opmapcontrol/src/mapwidget/mapwidget.pro +++ b/ground/src/libs/opmapcontrol/src/mapwidget/mapwidget.pro @@ -8,7 +8,8 @@ SOURCES += mapgraphicitem.cpp \ opmapwidget.cpp \ configuration.cpp \ waypointitem.cpp \ - uavitem.cpp + uavitem.cpp \ + trailitem.cpp LIBS += -L../build \ -lcore \ -linternals \ @@ -19,7 +20,8 @@ HEADERS += mapgraphicitem.h \ waypointitem.h \ uavitem.h \ uavmapfollowtype.h \ - uavtrailtype.h + uavtrailtype.h \ + trailitem.h QT += opengl QT += network QT += sql diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp b/ground/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp index ea2714aa5..75d53a4e4 100644 --- a/ground/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp +++ b/ground/src/libs/opmapcontrol/src/mapwidget/opmapwidget.cpp @@ -30,16 +30,19 @@ #include #include #include "waypointitem.h" + namespace mapcontrol { - OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config):QGraphicsView(parent),configuration(config),followmouse(true),compass(0) + OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config):QGraphicsView(parent),configuration(config),UAV(0),followmouse(true),compass(0),showuav(false) { setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); core=new internals::Core; map=new MapGraphicItem(core,config); mscene.addItem(map); this->setScene(&mscene); + +// uav->setPos(30,30); this->adjustSize(); connect(&mscene,SIGNAL(sceneRectChanged(QRectF)),map,SLOT(resize(QRectF))); connect(map,SIGNAL(zoomChanged(double)),this,SIGNAL(zoomChanged(double))); @@ -53,6 +56,25 @@ namespace mapcontrol connect(map->core,SIGNAL(OnTilesStillToLoad(int)),this,SIGNAL(OnTilesStillToLoad(int))); this->setMouseTracking(followmouse); SetShowCompass(true); + + } + + void OPMapWidget::SetShowUAV(const bool &value) + { + if(value && UAV==0) + { + UAV=new UAVItem(map,this); + UAV->setParentItem(map); + } + else if(!value) + { + if(UAV!=0) + { + delete UAV; + UAV=0; + } + + } } void OPMapWidget::resizeEvent(QResizeEvent *event) @@ -76,6 +98,7 @@ namespace mapcontrol } OPMapWidget::~OPMapWidget() { + delete UAV; delete map; delete core; delete configuration; diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h b/ground/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h index bf581dcaf..74296b2df 100644 --- a/ground/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h +++ b/ground/src/libs/opmapcontrol/src/mapwidget/opmapwidget.h @@ -37,8 +37,10 @@ #include #include "waypointitem.h" #include "QtSvg/QGraphicsSvgItem" +#include "uavitem.h" namespace mapcontrol { + class UAVItem; /** * @brief Collection of static functions to help dealing with various enums used * Contains functions for enumToString conversio, StringToEnum, QStringList of enum values... @@ -113,6 +115,31 @@ namespace mapcontrol * @brief Returns QStringList with string representing all the enum values */ static QStringList AccessModeTypes(){return core::AccessMode::TypesList();} + + /** + * @brief Converts from String to Type + */ + static UAVMapFollowType::Types UAVMapFollowFromString(QString const& value){return UAVMapFollowType::TypeByStr(value);} + /** + * @brief Converts from Type to String + */ + static QString StrFromUAVMapFollow(UAVMapFollowType::Types const& value){return UAVMapFollowType::StrByType(value);} + /** + * @brief Returns QStringList with string representing all the enum values + */ + static QStringList UAVMapFollowTypes(){return UAVMapFollowType::TypesList();} + /** + * @brief Converts from String to Type + */ + static UAVTrailType::Types UAVTrailTypeFromString(QString const& value){return UAVTrailType::TypeByStr(value);} + /** + * @brief Converts from Type to String + */ + static QString StrFromUAVTrailType(UAVTrailType::Types const& value){return UAVTrailType::StrByType(value);} + /** + * @brief Returns QStringList with string representing all the enum values + */ + static QStringList UAVTrailTypes(){return UAVTrailType::TypesList();} }; class OPMapWidget:public QGraphicsView @@ -304,7 +331,10 @@ namespace mapcontrol void SetShowCompass(bool const& value); - QImage X(){return map->lastimage;} + UAVItem* UAV; + + void SetShowUAV(bool const& value); + bool ShowUAV()const{return showuav;} private: internals::Core *core; @@ -318,6 +348,7 @@ namespace mapcontrol bool followmouse; void ConnectWP(WayPointItem* item); QGraphicsSvgItem *compass; + bool showuav; // WayPointItem* item;//apagar protected: void resizeEvent(QResizeEvent *event); diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/trailitem.cpp b/ground/src/libs/opmapcontrol/src/mapwidget/trailitem.cpp new file mode 100644 index 000000000..611623a0f --- /dev/null +++ b/ground/src/libs/opmapcontrol/src/mapwidget/trailitem.cpp @@ -0,0 +1,57 @@ +/** +****************************************************************************** +* +* @file trailitem.cpp +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. +* @brief A graphicsItem representing a trail point +* @see The GNU Public License (GPL) Version 3 +* @defgroup OPMapWidget +* @{ +* +*****************************************************************************/ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include "trailitem.h" +#include +namespace mapcontrol +{ + TrailItem::TrailItem(internals::PointLatLng const& coord,int const& altitude,QGraphicsItem* parent):QGraphicsItem(parent),coord(coord) + { + QDateTime time=QDateTime::currentDateTime(); + QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); + setToolTip(QString(tr("Position:")+"%1\n"+tr("Altitude:")+"%2\n"+tr("Time:")+"%3").arg(coord_str).arg(QString::number(altitude)).arg(time.toString())); + } + + void TrailItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + // painter->drawRect(QRectF(-3,-3,6,6)); + painter->setBrush(Qt::red); + painter->drawEllipse(-2,-2,4,4); + } + QRectF TrailItem::boundingRect()const + { + return QRectF(-2,-2,4,4); + } + + + int TrailItem::type()const + { + return Type; + } + + +} diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/trailitem.h b/ground/src/libs/opmapcontrol/src/mapwidget/trailitem.h new file mode 100644 index 000000000..dd2dba1c5 --- /dev/null +++ b/ground/src/libs/opmapcontrol/src/mapwidget/trailitem.h @@ -0,0 +1,63 @@ +/** +****************************************************************************** +* +* @file trailitem.h +* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. +* Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009. +* @brief A graphicsItem representing a WayPoint +* @see The GNU Public License (GPL) Version 3 +* @defgroup OPMapWidget +* @{ +* +*****************************************************************************/ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifndef TRAILITEM_H +#define TRAILITEM_H + +#include +#include +#include +#include "../internals/pointlatlng.h" +#include + +namespace mapcontrol +{ + + class TrailItem:public QObject,public QGraphicsItem + { + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + public: + enum { Type = UserType + 3 }; + TrailItem(internals::PointLatLng const& coord,int const& altitude,QGraphicsItem* parent); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + QRectF boundingRect() const; + int type() const; + internals::PointLatLng coord; + private: + + + public slots: + + signals: + + }; +} +#endif // TRAILITEM_H + + diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp b/ground/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp index f3620654e..638966766 100644 --- a/ground/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp +++ b/ground/src/libs/opmapcontrol/src/mapwidget/uavitem.cpp @@ -25,8 +25,117 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "../internals/pureprojection.h" #include "uavitem.h" namespace mapcontrol { + UAVItem::UAVItem(MapGraphicItem* map,OPMapWidget* parent):map(map),mapwidget(parent),showtrail(true),trailtime(5),traildistance(100) + { + pic.load(QString::fromUtf8(":/markers/images/airplane.svg")); + pic=pic.scaled(30,30,Qt::IgnoreAspectRatio); + localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition()); + this->setPos(localposition.X(),localposition.Y()); + this->setZValue(4); + trail=new QGraphicsItemGroup(); + trail->setParentItem(map); + + this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true); + mapfollowtype=UAVMapFollowType::None; + trailtype=UAVTrailType::ByDistance; + timer.start(); + + // rect=QRectF(0,0,renderer.defaultSize().width()*0.05,renderer.defaultSize().height()*0.05); + + } + UAVItem::~UAVItem() + { + delete trail; + } + + void UAVItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + painter->rotate(-90); + painter->drawPixmap(-pic.width()/2,-pic.height()/2,pic); + // painter->drawRect(QRectF(-pic.width()/2,-pic.height()/2,pic.width()-1,pic.height()-1)); + } + QRectF UAVItem::boundingRect()const + { + return QRectF(-pic.width()/2,-pic.height()/2,pic.width(),pic.height());; + } + void UAVItem::SetUAVPos(const internals::PointLatLng &position, const int &altitude) + { + if(coord.IsEmpty()) + lastcoord=coord; + if(coord!=position) + { + + if(trailtype==UAVTrailType::ByTimeElapsed) + { + if(timer.elapsed()>trailtime*1000) + { + trail->addToGroup(new TrailItem(position,altitude,this)); + timer.restart(); + } + + } + else if(trailtype==UAVTrailType::ByDistance) + { + if(qAbs(internals::PureProjection::DistanceBetweenLatLng(lastcoord,position)*1000)>traildistance) + { + trail->addToGroup(new TrailItem(position,altitude,this)); + lastcoord=position; + } + } + coord=position; + this->altitude=altitude; + RefreshPos(); + if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap||mapfollowtype==UAVMapFollowType::CenterMap) + { + mapwidget->SetCurrentPosition(coord); + } + this->update(); + } + } + void UAVItem::SetUAVHeading(const qreal &value) + { + if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap) + { + mapwidget->SetRotate(-value); + } + else + this->setRotation(value); + } + int UAVItem::type()const + { + return Type; + } + void UAVItem::RefreshPos() + { + localposition=map->FromLatLngToLocal(coord); + this->setPos(localposition.X(),localposition.Y()); + foreach(QGraphicsItem* i,trail->childItems()) + { + TrailItem* w=qgraphicsitem_cast(i); + if(w) + w->setPos(map->FromLatLngToLocal(w->coord).X(),map->FromLatLngToLocal(w->coord).Y()); + //this->update(); + } + } + void UAVItem::SetTrailType(const UAVTrailType::Types &value) + { + trailtype=value; + if(trailtype==UAVTrailType::ByTimeElapsed) + timer.restart(); + } + void UAVItem::SetShowTrail(const bool &value) + { + showtrail=value; + trail->setVisible(value); + } + void UAVItem::DeleteTrail()const + { + foreach(QGraphicsItem* i,trail->childItems()) + delete i; + } } diff --git a/ground/src/libs/opmapcontrol/src/mapwidget/uavitem.h b/ground/src/libs/opmapcontrol/src/mapwidget/uavitem.h index 8a349d7c4..a29262752 100644 --- a/ground/src/libs/opmapcontrol/src/mapwidget/uavitem.h +++ b/ground/src/libs/opmapcontrol/src/mapwidget/uavitem.h @@ -37,8 +37,13 @@ #include #include "uavmapfollowtype.h" #include "uavtrailtype.h" +#include +#include "opmapwidget.h" +#include "trailitem.h" namespace mapcontrol { + class WayPointItem; + class OPMapWidget; /** * @brief A QGraphicsItem representing the UAV * @@ -50,10 +55,47 @@ namespace mapcontrol Q_INTERFACES(QGraphicsItem) public: enum { Type = UserType + 2 }; + UAVItem(MapGraphicItem* map,OPMapWidget* parent); + ~UAVItem(); + void SetUAVPos(internals::PointLatLng const& position,int const& altitude); + void SetUAVHeading(qreal const& value); + internals::PointLatLng UAVPos()const{return coord;} + void SetMapFollowType(UAVMapFollowType::Types const& value){mapfollowtype=value;} + void SetTrailType(UAVTrailType::Types const& value); + UAVMapFollowType::Types GetMapFollowType()const{return mapfollowtype;} + UAVTrailType::Types GetTrailType()const{return trailtype;} + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + void RefreshPos(); + QRectF boundingRect() const; + void SetTrailTime(int const& seconds){trailtime=seconds;} + int TrailTime()const{return trailtime;} + void SetTrailDistance(int const& distance){traildistance=distance;} + int TrailDistance()const{return traildistance;} + bool ShowTrail()const{return showtrail;} + void SetShowTrail(bool const& value); + void DeleteTrail()const; + + int type() const; private: + MapGraphicItem* map; + + int altitude; + UAVMapFollowType::Types mapfollowtype; + UAVTrailType::Types trailtype; + internals::PointLatLng coord; + internals::PointLatLng lastcoord; + QPixmap pic; + core::Point localposition; + OPMapWidget* mapwidget; + QGraphicsItemGroup* trail; + QTime timer; + bool showtrail; int trailtime; int traildistance; + // QRectF rect; + public slots: signals: