mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP37/GCS Added UAV overlay.
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1028 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
4a9cc3b790
commit
e67a955044
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
||||
|
BIN
ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.png
Normal file
BIN
ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
113
ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.svg
Normal file
113
ground/src/libs/opmapcontrol/src/mapwidget/images/airplane.svg
Normal file
@ -0,0 +1,113 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="48.248676"
|
||||
height="57.976875"
|
||||
id="svg3258"
|
||||
sodipodi:version="0.32"
|
||||
inkscape:version="0.46"
|
||||
version="1.0"
|
||||
inkscape:export-filename="/home/nathan/Desktop/Airplane.png"
|
||||
inkscape:export-xdpi="90"
|
||||
inkscape:export-ydpi="90"
|
||||
sodipodi:docname="Airplane.svg"
|
||||
inkscape:output_extension="org.inkscape.output.svg.inkscape">
|
||||
<defs
|
||||
id="defs3260">
|
||||
<inkscape:perspective
|
||||
sodipodi:type="inkscape:persp3d"
|
||||
inkscape:vp_x="0 : 526.18109 : 1"
|
||||
inkscape:vp_y="0 : 1000 : 0"
|
||||
inkscape:vp_z="744.09448 : 526.18109 : 1"
|
||||
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
|
||||
id="perspective3266" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
gridtolerance="10000"
|
||||
guidetolerance="10"
|
||||
objecttolerance="10"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="8.5206388"
|
||||
inkscape:cx="27.741397"
|
||||
inkscape:cy="28.98844"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
showguides="true"
|
||||
inkscape:guide-bbox="true"
|
||||
inkscape:window-width="953"
|
||||
inkscape:window-height="719"
|
||||
inkscape:window-x="50"
|
||||
inkscape:window-y="40">
|
||||
<sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="26.27766,35.891438"
|
||||
id="guide3269" />
|
||||
<sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="27.174946,37.173275"
|
||||
id="guide3271" />
|
||||
<sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="39.352398,24.739455"
|
||||
id="guide3279" />
|
||||
<sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="38.583296,30.635906"
|
||||
id="guide3281" />
|
||||
<sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="33.455948,30.76409"
|
||||
id="guide3283" />
|
||||
<sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="47.940706,21.663047"
|
||||
id="guide3285" />
|
||||
<sodipodi:guide
|
||||
orientation="0,1"
|
||||
position="16.663882,7.0501039"
|
||||
id="guide3289" />
|
||||
<sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="29.73862,51.017115"
|
||||
id="guide3291" />
|
||||
<sodipodi:guide
|
||||
orientation="1,0"
|
||||
position="37.301459,47.940706"
|
||||
id="guide3293" />
|
||||
</sodipodi:namedview>
|
||||
<metadata
|
||||
id="metadata3263">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-514.65866,-602.51346)">
|
||||
<path
|
||||
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 548.16497,602.51404 C 544.39599,602.46904 542.44425,605.04177 541.83361,608.31962 C 540.93632,614.84219 541.66412,623.09869 541.00272,629.48244 C 533.06041,629.79211 528.86793,629.98585 522.28689,630.32396 C 522.24907,622.18823 521.69223,620.46085 519.24954,620.32938 C 516.84341,620.19987 516.43479,622.22062 516.36689,624.22196 C 516.29899,626.22329 516.32318,628.43173 516.27856,630.60655 C 516.27857,630.60654 515.08466,630.61705 514.84893,630.99902 C 514.6298,631.35409 514.59266,632.11082 514.7756,632.50911 C 514.94453,632.87689 516.31523,633.00615 516.31522,633.00616 C 516.31522,633.00616 516.33136,637.10623 516.27314,639.12944 C 516.2056,641.33883 516.35322,643.4298 519.26147,643.48735 C 522.16877,643.54488 522.25969,638.97649 522.28689,633.37701 C 531.05333,633.92589 531.54061,634.01425 541.00272,634.47368 C 541.61913,640.83085 540.93632,647.92474 541.83361,653.44029 C 542.55133,657.8521 544.39728,660.61165 548.15213,660.48623 C 551.90698,660.36081 553.24196,658.22708 553.24832,653.407 C 553.25928,644.8866 554.0194,635.28156 554.0194,635.28156 C 557.73343,635.19899 562.89282,636.13057 562.9073,632.4527 C 562.92178,628.77481 557.76024,629.44301 554.01106,629.32367 C 554.01015,624.76112 553.18728,614.79196 553.22404,608.22378 C 553.24196,605.15082 551.97086,602.55948 548.16497,602.51404 z"
|
||||
id="path3241"
|
||||
sodipodi:nodetypes="cccczzczzcczccszsczcsz" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.7 KiB |
@ -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<WayPointItem*>(i);
|
||||
if(w)
|
||||
w->RefreshPos();
|
||||
UAVItem* ww=qgraphicsitem_cast<UAVItem*>(i);
|
||||
if(ww)
|
||||
ww->RefreshPos();
|
||||
|
||||
}
|
||||
}
|
||||
void MapGraphicItem::ConstructLastImage(int const& zoomdiff)
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <QFont>
|
||||
#include <QObject>
|
||||
#include "waypointitem.h"
|
||||
//#include "uavitem.h"
|
||||
namespace mapcontrol
|
||||
{
|
||||
class OPMapWidget;
|
||||
|
@ -3,5 +3,6 @@
|
||||
<file>images/bigMarkerGreen.png</file>
|
||||
<file>images/marker.png</file>
|
||||
<file>images/compas.svg</file>
|
||||
<file>images/airplane.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -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
|
||||
|
@ -30,16 +30,19 @@
|
||||
#include <QtGui>
|
||||
#include <QMetaObject>
|
||||
#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;
|
||||
|
@ -37,8 +37,10 @@
|
||||
#include <QtOpenGL/QGLWidget>
|
||||
#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);
|
||||
|
57
ground/src/libs/opmapcontrol/src/mapwidget/trailitem.cpp
Normal file
57
ground/src/libs/opmapcontrol/src/mapwidget/trailitem.cpp
Normal file
@ -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 <QDateTime>
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
63
ground/src/libs/opmapcontrol/src/mapwidget/trailitem.h
Normal file
63
ground/src/libs/opmapcontrol/src/mapwidget/trailitem.h
Normal file
@ -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 <QGraphicsItem>
|
||||
#include <QPainter>
|
||||
#include <QLabel>
|
||||
#include "../internals/pointlatlng.h"
|
||||
#include <QObject>
|
||||
|
||||
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
|
||||
|
||||
|
@ -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<TrailItem*>(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;
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,13 @@
|
||||
#include <QObject>
|
||||
#include "uavmapfollowtype.h"
|
||||
#include "uavtrailtype.h"
|
||||
#include <QtSvg/QSvgRenderer>
|
||||
#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:
|
||||
|
Loading…
Reference in New Issue
Block a user