1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

GCS-Several changes according to review comments

This commit is contained in:
PT_Dreamer 2012-08-11 23:36:00 +01:00
parent f4bd4c3120
commit 1a22eef491
10 changed files with 57 additions and 102 deletions

View File

@ -221,10 +221,10 @@ Point PureProjection::FromLatLngToPixel(const PointLatLng &p,const int &zoom)
double PureProjection::courseBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2)
{
double lon1=p1.Lng()* (M_PI / 180);;
double lat1=p1.Lat()* (M_PI / 180);;
double lon2=p2.Lng()* (M_PI / 180);;
double lat2=p2.Lat()* (M_PI / 180);;
double lon1=p1.Lng()* (M_PI / 180);
double lat1=p1.Lat()* (M_PI / 180);
double lon2=p2.Lng()* (M_PI / 180);
double lat2=p2.Lat()* (M_PI / 180);
return 2*M_PI-myfmod(atan2(sin(lon1-lon2)*cos(lat2),
cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon1-lon2)), 2*M_PI);

View File

@ -37,9 +37,9 @@ namespace mapcontrol
localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition());
this->setPos(localposition.X(),localposition.Y());
this->setZValue(4);
trail=new QGraphicsItemGroup();
trail=new QGraphicsItemGroup(this);
trail->setParentItem(map);
trailLine=new QGraphicsItemGroup();
trailLine=new QGraphicsItemGroup(this);
trailLine->setParentItem(map);
this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true);
mapfollowtype=UAVMapFollowType::None;
@ -48,16 +48,14 @@ namespace mapcontrol
}
GPSItem::~GPSItem()
{
delete trail;
}
void GPSItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(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 GPSItem::boundingRect()const
{
@ -97,48 +95,6 @@ namespace mapcontrol
coord=position;
this->altitude=altitude;
RefreshPos();
/*if(mapfollowtype==UAVMapFollowType::CenterAndRotateMap||mapfollowtype==UAVMapFollowType::CenterMap)
{
mapwidget->SetCurrentPosition(coord);
}*/
this->update();
/*if(autosetreached)
{
foreach(QGraphicsItem* i,map->childItems())
{
WayPointItem* wp=qgraphicsitem_cast<WayPointItem*>(i);
if(wp)
{
if(Distance3D(wp->Coord(),wp->Altitude())<autosetdistance)
{
wp->SetReached(true);
emit UAVReachedWayPoint(wp->Number(),wp);
}
}
}
}
if(mapwidget->Home!=0)
{
//verify if the UAV is inside the safety bouble
if(Distance3D(mapwidget->Home->Coord(),mapwidget->Home->Altitude())>mapwidget->Home->SafeArea())
{
if(mapwidget->Home->safe!=false)
{
mapwidget->Home->safe=false;
mapwidget->Home->update();
emit UAVLeftSafetyBouble(this->coord);
}
}
else
{
if(mapwidget->Home->safe!=true)
{
mapwidget->Home->safe=true;
mapwidget->Home->update();
}
}
}*/
}
}

View File

@ -33,7 +33,8 @@
namespace mapcontrol
{
OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config):QGraphicsView(parent),configuration(config),UAV(0),GPS(0),Home(0),followmouse(true),compass(0),showuav(false),showhome(false),showDiag(false),diagGraphItem(0),diagTimer(0)
OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config):QGraphicsView(parent),configuration(config),UAV(0),GPS(0),Home(0)
,followmouse(true),compass(0),showuav(false),showhome(false),showDiag(false),diagGraphItem(0),diagTimer(0),overlayOpacity(1)
{
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
core=new internals::Core;
@ -59,7 +60,6 @@ namespace mapcontrol
SetShowDiagnostics(showDiag);
this->setMouseTracking(followmouse);
SetShowCompass(true);
overlayOpacity=1;
}
void OPMapWidget::SetShowDiagnostics(bool const& value)
@ -111,7 +111,7 @@ namespace mapcontrol
if(!from|!to)
return NULL;
WayPointLine* ret= new WayPointLine(from,to,map,color);
setOverlayOpacity(overlayOpacity);
ret->setOpacity(overlayOpacity);
return ret;
}
WayPointLine * OPMapWidget::WPLineCreate(HomeItem *from, WayPointItem *to,QColor color)
@ -119,7 +119,7 @@ namespace mapcontrol
if(!from|!to)
return NULL;
WayPointLine* ret= new WayPointLine(from,to,map,color);
setOverlayOpacity(overlayOpacity);
ret->setOpacity(overlayOpacity);
return ret;
}
WayPointCircle * OPMapWidget::WPCircleCreate(WayPointItem *center, WayPointItem *radius, bool clockwise,QColor color)
@ -127,7 +127,7 @@ namespace mapcontrol
if(!center|!radius)
return NULL;
WayPointCircle* ret= new WayPointCircle(center,radius,clockwise,map,color);
setOverlayOpacity(overlayOpacity);
ret->setOpacity(overlayOpacity);
return ret;
}
@ -136,7 +136,7 @@ namespace mapcontrol
if(!center|!radius)
return NULL;
WayPointCircle* ret= new WayPointCircle(center,radius,clockwise,map,color);
setOverlayOpacity(overlayOpacity);
ret->setOpacity(overlayOpacity);
return ret;
}
void OPMapWidget::SetShowUAV(const bool &value)
@ -147,14 +147,14 @@ namespace mapcontrol
UAV->setParentItem(map);
connect(this,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)),UAV,SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)));
connect(this,SIGNAL(UAVReachedWayPoint(int,WayPointItem*)),UAV,SIGNAL(UAVReachedWayPoint(int,WayPointItem*)));
setOverlayOpacity(overlayOpacity);
UAV->setOpacity(overlayOpacity);
}
else if(!value)
{
if(UAV!=0)
{
delete UAV;
UAV=0;
UAV=NULL;
}
}
@ -186,14 +186,20 @@ namespace mapcontrol
}
OPMapWidget::~OPMapWidget()
{
delete UAV;
delete Home;
delete map;
delete core;
delete configuration;
if(UAV)
delete UAV;
if(Home)
delete Home;
if(map)
delete map;
if(core)
delete core;
if(configuration)
delete configuration;
foreach(QGraphicsItem* i,this->items())
{
delete i;
if(i)
delete i;
}
}
void OPMapWidget::closeEvent(QCloseEvent *event)

View File

@ -38,7 +38,6 @@ namespace mapcontrol
void TrailItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// painter->drawRect(QRectF(-3,-3,6,6));
painter->setBrush(m_brush);
painter->drawEllipse(-2,-2,4,4);
}

View File

@ -44,8 +44,6 @@ namespace mapcontrol
enum { Type = UserType + 7 };
TrailLineItem(internals::PointLatLng const& coord1,internals::PointLatLng const& coord2, QBrush color, QGraphicsItem* parent);
int type() const;
// void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
// QWidget *widget);
internals::PointLatLng coord1;
internals::PointLatLng coord2;
private:

View File

@ -26,8 +26,8 @@
*/
#include "../internals/pureprojection.h"
#include "uavitem.h"
#include <math.h>
const qreal Pi = 3.14;
static double groundspeed_mps_filt;
namespace mapcontrol
@ -41,9 +41,9 @@ namespace mapcontrol
localposition=map->FromLatLngToLocal(mapwidget->CurrentPosition());
this->setPos(localposition.X(),localposition.Y());
this->setZValue(4);
trail=new QGraphicsItemGroup();
trail=new QGraphicsItemGroup(this);
trail->setParentItem(map);
trailLine=new QGraphicsItemGroup();
trailLine=new QGraphicsItemGroup(this);
trailLine->setParentItem(map);
this->setFlag(QGraphicsItem::ItemIgnoresTransformations,true);
mapfollowtype=UAVMapFollowType::None;
@ -52,7 +52,7 @@ namespace mapcontrol
}
UAVItem::~UAVItem()
{
delete trail;
}
void UAVItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
@ -97,12 +97,12 @@ namespace mapcontrol
//Form arrowhead
double angle = ::acos(line.dx() / line.length());
if (line.dy() <= 0)
angle = (Pi * 2) - angle;
angle = (M_PI * 2) - angle;
QPointF arrowP1 = line.pointAt(1) + QPointF(sin(angle + Pi / 3) * arrowSize,
cos(angle + Pi / 3) * arrowSize);
QPointF arrowP2 = line.pointAt(1) + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
cos(angle + Pi - Pi / 3) * arrowSize);
QPointF arrowP1 = line.pointAt(1) + QPointF(sin(angle + M_PI / 3) * arrowSize,
cos(angle + M_PI / 3) * arrowSize);
QPointF arrowP2 = line.pointAt(1) + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
cos(angle + M_PI - M_PI / 3) * arrowSize);
//Generate arrowhead
arrowHead.clear();
@ -122,7 +122,7 @@ namespace mapcontrol
//Calculate radius in [m], and then convert to pixels in local frame (not the same frame as is displayed on the map widget)
double groundspeed_mps=groundspeed_kph/3.6;
radius=fabs(groundspeed_mps/(yawRate_dps*Pi/180))*meters2pixels;
radius=fabs(groundspeed_mps/(yawRate_dps*M_PI/180))*meters2pixels;
// qDebug() << "Scale: " << meters2pixels;
// qDebug() << "Zoom: " << map->ZoomTotal();

View File

@ -27,7 +27,6 @@
#include "waypointcircle.h"
#include <math.h>
#include "homeitem.h"
const qreal Pi = 3.14;
namespace mapcontrol
{
@ -71,17 +70,17 @@ void WayPointCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
painter->setBrush(myColor);
double angle =0;
if(!myClockWise)
angle+=Pi;
angle+=M_PI;
QPointF arrowP1 = p1 + QPointF(sin(angle + Pi / 3) * arrowSize,
cos(angle + Pi / 3) * arrowSize);
QPointF arrowP2 = p1 + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
cos(angle + Pi - Pi / 3) * arrowSize);
QPointF arrowP1 = p1 + QPointF(sin(angle + M_PI / 3) * arrowSize,
cos(angle + M_PI / 3) * arrowSize);
QPointF arrowP2 = p1 + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
cos(angle + M_PI - M_PI / 3) * arrowSize);
QPointF arrowP21 = p2 + QPointF(sin(angle + Pi + Pi / 3) * arrowSize,
cos(angle + Pi + Pi / 3) * arrowSize);
QPointF arrowP22 = p2 + QPointF(sin(angle + Pi + Pi - Pi / 3) * arrowSize,
cos(angle + Pi + Pi - Pi / 3) * arrowSize);
QPointF arrowP21 = p2 + QPointF(sin(angle + M_PI + M_PI / 3) * arrowSize,
cos(angle + M_PI + M_PI / 3) * arrowSize);
QPointF arrowP22 = p2 + QPointF(sin(angle + M_PI + M_PI - M_PI / 3) * arrowSize,
cos(angle + M_PI + M_PI - M_PI / 3) * arrowSize);
arrowHead.clear();
arrowHead << p1 << arrowP1 << arrowP2;

View File

@ -277,11 +277,9 @@ WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint):reached(fals
void WayPointItem::setRelativeCoord(distBearingAltitude value)
{
qDebug()<<"SetRelative("<<value.distance<<","<<value.bearing<<")"<<"OLD:"<<relativeCoord.distance<<","<<relativeCoord.bearing;
if(qAbs(value.distance-relativeCoord.distance)<0.1
&& qAbs(value.bearing-relativeCoord.bearing)<0.01 && value.altitudeRelative==relativeCoord.altitudeRelative)
return;
qDebug()<<"setRelative values need update";
relativeCoord=value;
if(myHome)
{
@ -292,7 +290,6 @@ WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint):reached(fals
RefreshToolTip();
emit WPValuesChanged(this);
this->update();
qDebug()<<"setRelativeCoord EXIT";
}
void WayPointItem::SetCoord(const internals::PointLatLng &value)

View File

@ -27,7 +27,6 @@
#include "waypointline.h"
#include <math.h>
#include "homeitem.h"
const qreal Pi = 3.14;
namespace mapcontrol
{
@ -83,12 +82,12 @@ void WayPointLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
double angle = ::acos(line().dx() / line().length());
if (line().dy() >= 0)
angle = (Pi * 2) - angle;
angle = (M_PI * 2) - angle;
QPointF arrowP1 = line().pointAt(0.5) + QPointF(sin(angle + Pi / 3) * arrowSize,
cos(angle + Pi / 3) * arrowSize);
QPointF arrowP2 = line().pointAt(0.5) + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
cos(angle + Pi - Pi / 3) * arrowSize);
QPointF arrowP1 = line().pointAt(0.5) + QPointF(sin(angle + M_PI / 3) * arrowSize,
cos(angle + M_PI / 3) * arrowSize);
QPointF arrowP2 = line().pointAt(0.5) + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize,
cos(angle + M_PI - M_PI / 3) * arrowSize);
arrowHead.clear();
arrowHead << line().pointAt(0.5) << arrowP1 << arrowP2;
painter->drawPolygon(arrowHead);

View File

@ -1572,7 +1572,8 @@ void OPMapGadgetWidget::onShowUAVAct_toggled(bool show)
return;
m_map->UAV->setVisible(show);
m_map->GPS->setVisible(show);
if(m_map->GPS)
m_map->GPS->setVisible(show);
}
void OPMapGadgetWidget::onShowTrailAct_toggled(bool show)
@ -1581,7 +1582,8 @@ void OPMapGadgetWidget::onShowTrailAct_toggled(bool show)
return;
m_map->UAV->SetShowTrail(show);
m_map->GPS->SetShowTrail(show);
if(m_map->GPS)
m_map->GPS->SetShowTrail(show);
}
void OPMapGadgetWidget::onShowTrailLineAct_toggled(bool show)
@ -1590,7 +1592,8 @@ void OPMapGadgetWidget::onShowTrailLineAct_toggled(bool show)
return;
m_map->UAV->SetShowTrailLine(show);
m_map->GPS->SetShowTrailLine(show);
if(m_map->GPS)
m_map->GPS->SetShowTrailLine(show);
}
void OPMapGadgetWidget::onMapModeActGroup_triggered(QAction *action)
@ -2045,8 +2048,6 @@ bool OPMapGadgetWidget::getUAVPosition(double &latitude, double &longitude, doub
longitude = LLA[1];
altitude = LLA[2];
qDebug()<< " " << latitude << " " << longitude << " " << altitude;
if (latitude != latitude) latitude = 0; // nan detection
else if (latitude > 90) latitude = 90;
else if (latitude < -90) latitude = -90;