mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
GCS - MapLib change relative waypoint to distance and
bearing definition
This commit is contained in:
parent
7a1501eea3
commit
28b754183f
@ -217,8 +217,13 @@ Point PureProjection::FromLatLngToPixel(const PointLatLng &p,const int &zoom)
|
||||
}
|
||||
double PureProjection::courseBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2)
|
||||
{
|
||||
return fmod(atan2(sin(p1.Lng()-p2.Lng())*cos(p2.Lat()),
|
||||
cos(p1.Lat())*sin(p2.Lat())-sin(p1.Lat())*cos(p2.Lat())*cos(p1.Lng()-p2.Lng())), 2*PI);
|
||||
double lon1=p1.Lng()* (PI / 180);;
|
||||
double lat1=p1.Lat()* (PI / 180);;
|
||||
double lon2=p2.Lng()* (PI / 180);;
|
||||
double lat2=p2.Lat()* (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*PI);
|
||||
|
||||
}
|
||||
|
||||
@ -237,22 +242,22 @@ Point PureProjection::FromLatLngToPixel(const PointLatLng &p,const int &zoom)
|
||||
return d;
|
||||
}
|
||||
|
||||
void PureProjection::offSetFromLatLngs(PointLatLng p1,PointLatLng p2,double &dX,double &dY)
|
||||
void PureProjection::offSetFromLatLngs(PointLatLng p1,PointLatLng p2,double &distance,double &bearing)
|
||||
{
|
||||
dX=DistanceBetweenLatLng(p1,p2)*sin(courseBetweenLatLng(p1,p2));
|
||||
dY=DistanceBetweenLatLng(p1,p2)*sin(courseBetweenLatLng(p1,p2));
|
||||
}
|
||||
distance=DistanceBetweenLatLng(p1,p2)*1000;
|
||||
bearing=courseBetweenLatLng(p1,p2);
|
||||
}
|
||||
|
||||
double PureProjection::myfmod(double x,double y)
|
||||
{
|
||||
return x - y*floor(x/y);
|
||||
}
|
||||
|
||||
PointLatLng PureProjection::translate(PointLatLng p1,double dX,double dY)
|
||||
PointLatLng PureProjection::translate(PointLatLng p1,double distance,double bearing)
|
||||
{
|
||||
PointLatLng ret;
|
||||
double d=sqrt(pow(dX,2)+pow(dY,2));
|
||||
double tc=(atan2(dY,dX));
|
||||
double d=distance;
|
||||
double tc=bearing;
|
||||
double lat1=p1.Lat()*M_PI/180;
|
||||
double lon1=p1.Lng()*M_PI/180;
|
||||
double R=6378137;
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
void FromCartesianTGeodetic(const double &X,const double &Y,const double &Z, double &Lat, double &Lng);
|
||||
static double DistanceBetweenLatLng(PointLatLng const& p1,PointLatLng const& p2);
|
||||
|
||||
PointLatLng translate(PointLatLng p1, double dX, double dY);
|
||||
PointLatLng translate(PointLatLng p1, double distance, double bearing);
|
||||
double courseBetweenLatLng(const PointLatLng &p1, const PointLatLng &p2);
|
||||
void offSetFromLatLngs(PointLatLng p1, PointLatLng p2, double &dX, double &dY);
|
||||
protected:
|
||||
|
@ -42,7 +42,7 @@ namespace mapcontrol
|
||||
this->setScene(&mscene);
|
||||
Home=new HomeItem(map,this);
|
||||
Home->setParentItem(map);
|
||||
setStyleSheet("QToolTip {font-size:8pt; color:yellow;background-color : transparent; padding:2px; border-width:2px; border-style:solid; border-radius:4px }");
|
||||
setStyleSheet("QToolTip {font-size:8pt; color:blue;opacity: 223; padding:2px; border-width:2px; border-style:solid; border-color: rgb(170, 170, 127);border-radius:4px }");
|
||||
this->adjustSize();
|
||||
connect(map,SIGNAL(zoomChanged(double,double,double)),this,SIGNAL(zoomChanged(double,double,double)));
|
||||
connect(map->core,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)),this,SIGNAL(OnCurrentPositionChanged(internals::PointLatLng)));
|
||||
@ -211,7 +211,7 @@ namespace mapcontrol
|
||||
item->setParentItem(map);
|
||||
return item;
|
||||
}
|
||||
WayPointItem* OPMapWidget::WPCreate(const QPoint &relativeCoord, const int &altitude, const QString &description)
|
||||
WayPointItem* OPMapWidget::WPCreate(const distBearing &relativeCoord, const int &altitude, const QString &description)
|
||||
{
|
||||
WayPointItem* item=new WayPointItem(relativeCoord,altitude,description,map);
|
||||
ConnectWP(item);
|
||||
|
@ -286,7 +286,7 @@ namespace mapcontrol
|
||||
* @param description the description of the WayPoint
|
||||
* @return WayPointItem a pointer to the WayPoint created
|
||||
*/
|
||||
WayPointItem *WPCreate(const QPoint &relativeCoord, const int &altitude, const QString &description);
|
||||
WayPointItem *WPCreate(const distBearing &relativeCoord, const int &altitude, const QString &description);
|
||||
/**
|
||||
* @brief Inserts a new WayPoint on the specified position
|
||||
*
|
||||
|
@ -42,25 +42,19 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
|
||||
SetShowNumber(shownumber);
|
||||
RefreshToolTip();
|
||||
RefreshPos();
|
||||
if(relativeCoord.isNull())
|
||||
|
||||
HomeItem* home=NULL;
|
||||
QList<QGraphicsItem *> list=map->childItems();
|
||||
foreach(QGraphicsItem * obj,list)
|
||||
{
|
||||
HomeItem* home=NULL;
|
||||
QList<QGraphicsItem *> list=map->childItems();
|
||||
foreach(QGraphicsItem * obj,list)
|
||||
{
|
||||
HomeItem* h=qgraphicsitem_cast <HomeItem*>(obj);
|
||||
if(h)
|
||||
home=h;
|
||||
}
|
||||
|
||||
double X;
|
||||
double Y;
|
||||
map->Projection()->offSetFromLatLngs(home->Coord(),coord,X,Y);
|
||||
relativeCoord.setX(X);
|
||||
relativeCoord.setY(Y);
|
||||
|
||||
HomeItem* h=qgraphicsitem_cast <HomeItem*>(obj);
|
||||
if(h)
|
||||
home=h;
|
||||
}
|
||||
HomeItem * home=this->parent()->findChild<HomeItem *>();
|
||||
|
||||
if(home)
|
||||
map->Projection()->offSetFromLatLngs(home->Coord(),coord,relativeCoord.distante,relativeCoord.bearing);
|
||||
|
||||
connect(home,SIGNAL(homePositionChanged(internals::PointLatLng)),this,SLOT(onHomePositionChanged(internals::PointLatLng)));
|
||||
}
|
||||
WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitude, const QString &description, MapGraphicItem *map,wptype type):coord(coord),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map),myType(type)
|
||||
@ -76,35 +70,22 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
|
||||
SetShowNumber(shownumber);
|
||||
RefreshToolTip();
|
||||
RefreshPos();
|
||||
if(relativeCoord.isNull())
|
||||
{
|
||||
HomeItem* home=NULL;
|
||||
QList<QGraphicsItem *> list=map->childItems();
|
||||
foreach(QGraphicsItem * obj,list)
|
||||
{
|
||||
HomeItem* h=qgraphicsitem_cast <HomeItem*>(obj);
|
||||
if(h)
|
||||
home=h;
|
||||
}
|
||||
double X;
|
||||
double Y;
|
||||
map->Projection()->offSetFromLatLngs(home->Coord(),coord,X,Y);
|
||||
relativeCoord.setX(X);
|
||||
relativeCoord.setY(Y);
|
||||
|
||||
}
|
||||
HomeItem* home=NULL;
|
||||
QList<QGraphicsItem *> list=map->childItems();
|
||||
foreach(QGraphicsItem * obj,list)
|
||||
{
|
||||
HomeItem* h=qgraphicsitem_cast <HomeItem*>(obj);
|
||||
if(h)
|
||||
home=h;
|
||||
home=h;
|
||||
}
|
||||
if(home)
|
||||
{
|
||||
map->Projection()->offSetFromLatLngs(home->Coord(),coord,relativeCoord.distante,relativeCoord.bearing);
|
||||
connect(home,SIGNAL(homePositionChanged(internals::PointLatLng)),this,SLOT(onHomePositionChanged(internals::PointLatLng)));
|
||||
}
|
||||
connect(home,SIGNAL(homePositionChanged(internals::PointLatLng)),this,SLOT(onHomePositionChanged(internals::PointLatLng)));
|
||||
}
|
||||
|
||||
WayPointItem::WayPointItem(const QPoint &relativeCoord, const int &altitude, const QString &description, MapGraphicItem *map):relativeCoord(relativeCoord),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map)
|
||||
WayPointItem::WayPointItem(const distBearing &relativeCoord, const int &altitude, const QString &description, MapGraphicItem *map):relativeCoord(relativeCoord),reached(false),description(description),shownumber(true),isDragging(false),altitude(altitude),map(map)
|
||||
{
|
||||
HomeItem* home=NULL;
|
||||
QList<QGraphicsItem *> list=map->childItems();
|
||||
@ -115,7 +96,7 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
|
||||
home=h;
|
||||
}
|
||||
connect(home,SIGNAL(homePositionChanged(internals::PointLatLng)),this,SLOT(onHomePositionChanged(internals::PointLatLng)));
|
||||
coord=map->Projection()->translate(home->Coord(),relativeCoord.x(),relativeCoord.y());
|
||||
coord=map->Projection()->translate(home->Coord(),relativeCoord.distante,relativeCoord.bearing);
|
||||
myType=relative;
|
||||
text=0;
|
||||
numberI=0;
|
||||
@ -130,6 +111,15 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
|
||||
RefreshPos();
|
||||
}
|
||||
|
||||
void WayPointItem::changeWPType(wptype type)
|
||||
{
|
||||
myType=type;
|
||||
emit WPValuesChanged(this);
|
||||
RefreshPos();
|
||||
RefreshToolTip();
|
||||
this->update();
|
||||
}
|
||||
|
||||
QRectF WayPointItem::boundingRect() const
|
||||
{
|
||||
return QRectF(-picture.width()/2,-picture.height(),picture.width(),picture.height());
|
||||
@ -164,9 +154,18 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
|
||||
{
|
||||
if(event->button()==Qt::LeftButton)
|
||||
{
|
||||
HomeItem* home=NULL;
|
||||
QList<QGraphicsItem *> list=map->childItems();
|
||||
foreach(QGraphicsItem * obj,list)
|
||||
{
|
||||
HomeItem* h=qgraphicsitem_cast <HomeItem*>(obj);
|
||||
if(h)
|
||||
home=h;
|
||||
}
|
||||
delete text;
|
||||
delete textBG;
|
||||
coord=map->FromLocalToLatLng(this->pos().x(),this->pos().y());
|
||||
map->Projection()->offSetFromLatLngs(home->Coord(),coord,relativeCoord.distante,relativeCoord.bearing);
|
||||
isDragging=false;
|
||||
RefreshToolTip();
|
||||
|
||||
@ -277,7 +276,7 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
|
||||
{
|
||||
if(myType==relative)
|
||||
{
|
||||
coord=map->Projection()->translate(homepos,relativeCoord.x(),relativeCoord.y());
|
||||
coord=map->Projection()->translate(homepos,relativeCoord.distante,relativeCoord.bearing);
|
||||
emit WPValuesChanged(this);
|
||||
RefreshPos();
|
||||
RefreshToolTip();
|
||||
@ -328,8 +327,14 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
|
||||
}
|
||||
void WayPointItem::RefreshToolTip()
|
||||
{
|
||||
QString type_str;
|
||||
if(myType==relative)
|
||||
type_str="Relative";
|
||||
else
|
||||
type_str="Absolute";
|
||||
QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6);
|
||||
setToolTip(QString("WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nAltitude:%5").arg(QString::number(WayPointItem::number)).arg(description).arg(coord_str).arg(QString::number(altitude)));
|
||||
QString relativeCoord_str = " Distance:" + QString::number(relativeCoord.distante) + " Bearing:" + QString::number(relativeCoord.bearing*180/M_PI);
|
||||
setToolTip(QString("WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nFrom Home:%5\nAltitude:%6\nType:%7").arg(QString::number(WayPointItem::number)).arg(description).arg(coord_str).arg(relativeCoord_str).arg(QString::number(altitude)).arg(type_str));
|
||||
}
|
||||
|
||||
int WayPointItem::snumber=0;
|
||||
|
@ -37,6 +37,12 @@
|
||||
|
||||
namespace mapcontrol
|
||||
{
|
||||
struct distBearing
|
||||
{
|
||||
double distante;
|
||||
double bearing;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A QGraphicsItem representing a WayPoint
|
||||
*
|
||||
@ -68,7 +74,7 @@ public:
|
||||
* @return
|
||||
*/
|
||||
WayPointItem(internals::PointLatLng const& coord,int const& altitude,QString const& description,MapGraphicItem* map,wptype type=absolute);
|
||||
WayPointItem(QPoint const& relativeCoord,int const& altitude,QString const& description,MapGraphicItem* map);
|
||||
WayPointItem(distBearing const& relativeCoord,int const& altitude,QString const& description,MapGraphicItem* map);
|
||||
|
||||
/**
|
||||
* @brief Returns the WayPoint description
|
||||
@ -149,6 +155,7 @@ public:
|
||||
~WayPointItem();
|
||||
|
||||
static int snumber;
|
||||
void changeWPType(wptype type);
|
||||
protected:
|
||||
void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
|
||||
void mousePressEvent ( QGraphicsSceneMouseEvent * event );
|
||||
@ -156,7 +163,7 @@ protected:
|
||||
|
||||
private:
|
||||
internals::PointLatLng coord;//coordinates of this WayPoint
|
||||
QPoint relativeCoord;
|
||||
distBearing relativeCoord;
|
||||
bool reached;
|
||||
QString description;
|
||||
bool shownumber;
|
||||
|
Loading…
x
Reference in New Issue
Block a user