1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

GCS/MapLib-Added lines and circles between WPs overlay.

This commit is contained in:
PT_Dreamer 2012-06-01 15:28:35 +01:00
parent f7f6ffcab1
commit 78db6d9853
12 changed files with 414 additions and 57 deletions

View File

@ -1,50 +1,54 @@
TEMPLATE = lib
TARGET = opmapwidget
DEFINES += OPMAPWIDGET_LIBRARY
include(../../../../openpilotgcslibrary.pri)
# DESTDIR = ../build
SOURCES += mapgraphicitem.cpp \
opmapwidget.cpp \
configuration.cpp \
waypointitem.cpp \
uavitem.cpp \
gpsitem.cpp \
trailitem.cpp \
homeitem.cpp \
mapripform.cpp \
mapripper.cpp \
traillineitem.cpp
LIBS += -L../build \
-lcore \
-linternals \
-lcore
# order of linking matters
include(../../../utils/utils.pri)
POST_TARGETDEPS += ../build/libcore.a
POST_TARGETDEPS += ../build/libinternals.a
HEADERS += mapgraphicitem.h \
opmapwidget.h \
configuration.h \
waypointitem.h \
uavitem.h \
gpsitem.h \
uavmapfollowtype.h \
uavtrailtype.h \
trailitem.h \
homeitem.h \
mapripform.h \
mapripper.h \
traillineitem.h
QT += opengl
QT += network
QT += sql
QT += svg
RESOURCES += mapresources.qrc
FORMS += \
mapripform.ui
TEMPLATE = lib
TARGET = opmapwidget
DEFINES += OPMAPWIDGET_LIBRARY
include(../../../../openpilotgcslibrary.pri)
# DESTDIR = ../build
SOURCES += mapgraphicitem.cpp \
opmapwidget.cpp \
configuration.cpp \
waypointitem.cpp \
uavitem.cpp \
gpsitem.cpp \
trailitem.cpp \
homeitem.cpp \
mapripform.cpp \
mapripper.cpp \
traillineitem.cpp \
waypointline.cpp \
waypointcircle.cpp
LIBS += -L../build \
-lcore \
-linternals \
-lcore
# order of linking matters
include(../../../utils/utils.pri)
POST_TARGETDEPS += ../build/libcore.a
POST_TARGETDEPS += ../build/libinternals.a
HEADERS += mapgraphicitem.h \
opmapwidget.h \
configuration.h \
waypointitem.h \
uavitem.h \
gpsitem.h \
uavmapfollowtype.h \
uavtrailtype.h \
trailitem.h \
homeitem.h \
mapripform.h \
mapripper.h \
traillineitem.h \
waypointline.h \
waypointcircle.h
QT += opengl
QT += network
QT += sql
QT += svg
RESOURCES += mapresources.qrc
FORMS += \
mapripform.ui

View File

@ -42,6 +42,7 @@ namespace mapcontrol
this->setScene(&mscene);
Home=new HomeItem(map,this);
Home->setParentItem(map);
Home->setZValue(-1);
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)));
@ -103,6 +104,15 @@ namespace mapcontrol
}
WayPointLine * OPMapWidget::WPLineCreate(WayPointItem *from, WayPointItem *to)
{
return new WayPointLine(from,to,map);
}
WayPointCircle * OPMapWidget::WPCircleCreate(WayPointItem *from, WayPointItem *to, bool clockwise)
{
return new WayPointCircle(from,to,clockwise,map);
}
void OPMapWidget::SetShowUAV(const bool &value)
{
if(value && UAV==0)

View File

@ -41,6 +41,8 @@
#include "gpsitem.h"
#include "homeitem.h"
#include "mapripper.h"
#include "waypointline.h"
#include "waypointcircle.h"
namespace mapcontrol
{
class UAVItem;
@ -358,6 +360,8 @@ namespace mapcontrol
bool ShowHome()const{return showhome;}
void SetShowDiagnostics(bool const& value);
void SetUavPic(QString UAVPic);
WayPointLine * WPLineCreate(WayPointItem *from,WayPointItem *to);
WayPointCircle *WPCircleCreate(WayPointItem *from, WayPointItem *to,bool clockwise);
private:
internals::Core *core;
MapGraphicItem *map;

View File

@ -0,0 +1,97 @@
/**
******************************************************************************
*
* @file waypointcircle.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief A graphicsItem representing a circle connecting 2 waypoints
* @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 "waypointcircle.h"
#include <math.h>
const qreal Pi = 3.14;
namespace mapcontrol
{
WayPointCircle::WayPointCircle(WayPointItem *from, WayPointItem *to,bool clockwise, MapGraphicItem *map,QColor color):source(from),
destination(to),my_map(map),QGraphicsEllipseItem(map),myColor(color),myClockWise(clockwise)
{
QLineF line(from->pos(),to->pos());
this->setRect(from->pos().x(),from->pos().y(),2*line.length(),2*line.length());
connect(source,SIGNAL(localPositionChanged(QPointF)),this,SLOT(refreshLocations()));
connect(destination,SIGNAL(localPositionChanged(QPointF)),this,SLOT(refreshLocations()));
connect(source,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted()));
connect(destination,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted()));
}
int WayPointCircle::type() const
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
QPainterPath WayPointCircle::shape() const
{
QPainterPath path = QGraphicsEllipseItem::shape();
path.addPolygon(arrowHead);
return path;
}
void WayPointCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QLineF line(destination->pos(),source->pos());
QPen myPen = pen();
myPen.setColor(myColor);
qreal arrowSize = 10;
painter->setPen(myPen);
QBrush brush=painter->brush();
painter->setBrush(myColor);
double angle = ::acos(line.dx() / line.length());
angle=angle+90*2*Pi/360;
if(myClockWise)
angle+=Pi;
if (line.dy() >= 0)
angle = (Pi) - angle;
QPointF arrowP1 = line.p1() + QPointF(sin(angle + Pi / 3) * arrowSize,
cos(angle + Pi / 3) * arrowSize);
QPointF arrowP2 = line.p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
cos(angle + Pi - Pi / 3) * arrowSize);
arrowHead.clear();
arrowHead << line.p1() << arrowP1 << arrowP2;
painter->drawPolygon(arrowHead);
painter->translate(-line.length(),-line.length());
painter->setBrush(brush);
painter->drawEllipse(this->rect());
}
void WayPointCircle::refreshLocations()
{
QLineF line(source->pos(),destination->pos());
this->setRect(source->pos().x(),source->pos().y(),2*line.length(),2*line.length());
}
void WayPointCircle::waypointdeleted()
{
this->deleteLater();
}
}

View File

@ -0,0 +1,67 @@
/**
******************************************************************************
*
* @file waypointcircle.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief A graphicsItem representing a circle connecting 2 waypoints
* @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 WAYPOINTCIRCLE_H
#define WAYPOINTCIRCLE_H
#include <QGraphicsItem>
#include <QPainter>
#include <QLabel>
#include "../internals/pointlatlng.h"
#include "mapgraphicitem.h"
#include "waypointitem.h"
#include <QObject>
#include <QPoint>
namespace mapcontrol
{
class WayPointCircle:public QObject,public QGraphicsEllipseItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
enum { Type = UserType + 9 };
WayPointCircle(WayPointItem * from, WayPointItem * to,bool clockwise,MapGraphicItem * map,QColor color=Qt::green);
int type() const;
QPainterPath shape() const;
void setColor(const QColor &color)
{ myColor = color; }
private:
WayPointItem * source;
WayPointItem * destination;
MapGraphicItem * my_map;
QPolygonF arrowHead;
QColor myColor;
bool myClockWise;
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
public slots:
void refreshLocations();
void waypointdeleted();
};
}
#endif // WAYPOINTCIRCLE_H

View File

@ -42,7 +42,6 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
SetShowNumber(shownumber);
RefreshToolTip();
RefreshPos();
myHome=NULL;
QList<QGraphicsItem *> list=map->childItems();
foreach(QGraphicsItem * obj,list)
@ -184,7 +183,7 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
isDragging=false;
RefreshToolTip();
emit localPositionChanged(this->pos());
emit WPValuesChanged(this);
}
QGraphicsItem::mouseReleaseEvent(event);
@ -204,7 +203,7 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
QString relativeCoord_str = QString::number(relativeCoord.distance) + "m " + QString::number(relativeCoord.bearing*180/M_PI)+"deg";
text->setText(coord_str+"\n"+relativeCoord_str);
textBG->setRect(text->boundingRect());
emit localPositionChanged(this->pos());
emit WPValuesChanged(this);
}
QGraphicsItem::mouseMoveEvent(event);
@ -232,6 +231,8 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
void WayPointItem::SetCoord(const internals::PointLatLng &value)
{
coord=value;
if(myHome)
map->Projection()->offSetFromLatLngs(myHome->Coord(),coord,relativeCoord.distance,relativeCoord.bearing);
emit WPValuesChanged(this);
RefreshPos();
RefreshToolTip();
@ -352,12 +353,14 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
WayPointItem::~WayPointItem()
{
emit aboutToBeDeleted(this);
--WayPointItem::snumber;
}
void WayPointItem::RefreshPos()
{
core::Point point=map->FromLatLngToLocal(coord);
this->setPos(point.X(),point.Y());
emit localPositionChanged(this->pos());
}
void WayPointItem::RefreshToolTip()
{
@ -368,7 +371,7 @@ WayPointItem::WayPointItem(const internals::PointLatLng &coord,int const& altitu
type_str="Absolute";
QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6);
QString relativeCoord_str = " Distance:" + QString::number(relativeCoord.distance) + " 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));
setToolTip(QString("WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nFrom Home:%5\nAltitude:%6\nType:%7\n%8").arg(QString::number(WayPointItem::number)).arg(description).arg(coord_str).arg(relativeCoord_str).arg(QString::number(altitude)).arg(type_str).arg(myCustomString));
}
int WayPointItem::snumber=0;

View File

@ -154,6 +154,10 @@ public:
void RefreshPos();
void RefreshToolTip();
QPixmap picture;
QVariant customData(){return myCustomData;}
void setCustomData(QVariant arg){myCustomData=arg;}
QString customString(){return myCustomString;}
void setCustomString(QString arg){myCustomString=arg;}
~WayPointItem();
static int snumber;
@ -183,6 +187,8 @@ private:
QTransform transf;
HomeItem * myHome;
wptype myType;
QVariant myCustomData;
QString myCustomString;
public slots:
/**
@ -224,6 +230,8 @@ signals:
*/
void WPValuesChanged(WayPointItem* waypoint);
void waypointdoubleclick(WayPointItem* waypoint);
void localPositionChanged(QPointF point);
void aboutToBeDeleted(WayPointItem *);
};
}
#endif // WAYPOINTITEM_H

View File

@ -0,0 +1,89 @@
/**
******************************************************************************
*
* @file waypointline.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief A graphicsItem representing a line connecting 2 waypoints
* @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 "waypointline.h"
#include <math.h>
const qreal Pi = 3.14;
namespace mapcontrol
{
WayPointLine::WayPointLine(WayPointItem *from, WayPointItem *to, MapGraphicItem *map,QColor color):source(from),
destination(to),my_map(map),QGraphicsLineItem(map),myColor(color)
{
this->setLine(to->pos().x(),to->pos().y(),from->pos().x(),from->pos().y());
connect(source,SIGNAL(localPositionChanged(QPointF)),this,SLOT(refreshLocations()));
connect(destination,SIGNAL(localPositionChanged(QPointF)),this,SLOT(refreshLocations()));
connect(source,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted()));
connect(destination,SIGNAL(aboutToBeDeleted(WayPointItem*)),this,SLOT(waypointdeleted()));
}
int WayPointLine::type() const
{
// Enable the use of qgraphicsitem_cast with this item.
return Type;
}
QPainterPath WayPointLine::shape() const
{
QPainterPath path = QGraphicsLineItem::shape();
path.addPolygon(arrowHead);
return path;
}
void WayPointLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QPen myPen = pen();
myPen.setColor(myColor);
qreal arrowSize = 10;
painter->setPen(myPen);
painter->setBrush(myColor);
double angle = ::acos(line().dx() / line().length());
if (line().dy() >= 0)
angle = (Pi * 2) - angle;
QPointF arrowP1 = line().p1() + QPointF(sin(angle + Pi / 3) * arrowSize,
cos(angle + Pi / 3) * arrowSize);
QPointF arrowP2 = line().p1() + QPointF(sin(angle + Pi - Pi / 3) * arrowSize,
cos(angle + Pi - Pi / 3) * arrowSize);
arrowHead.clear();
arrowHead << line().p1() << arrowP1 << arrowP2;
//! [6] //! [7]
painter->drawLine(line());
painter->drawPolygon(arrowHead);
}
void WayPointLine::refreshLocations()
{
this->setLine(destination->pos().x(),destination->pos().y(),source->pos().x(),source->pos().y());
}
void WayPointLine::waypointdeleted()
{
this->deleteLater();
}
}

View File

@ -0,0 +1,64 @@
/**
******************************************************************************
*
* @file waypointline.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief A graphicsItem representing a line connecting 2 waypoints
* @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 WAYPOINTLINE_H
#define WAYPOINTLINE_H
#include <QGraphicsItem>
#include <QPainter>
#include <QLabel>
#include "../internals/pointlatlng.h"
#include "mapgraphicitem.h"
#include "waypointitem.h"
#include <QObject>
#include <QPoint>
namespace mapcontrol
{
class WayPointLine:public QObject,public QGraphicsLineItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
enum { Type = UserType + 8 };
WayPointLine(WayPointItem * from, WayPointItem * to,MapGraphicItem * map,QColor color=Qt::green);
int type() const;
QPainterPath shape() const;
void setColor(const QColor &color)
{ myColor = color; }
private:
WayPointItem * source;
WayPointItem * destination;
MapGraphicItem * my_map;
QPolygonF arrowHead;
QColor myColor;
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
public slots:
void refreshLocations();
void waypointdeleted();
};
}
#endif // WAYPOINTLINE_H

View File

@ -273,7 +273,18 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent)
distBearing db;
db.distance=100;
db.bearing=0;
m_map->WPCreate(db,10,"aaa");
WayPointItem * p1=m_map->WPCreate(db,10,"aaa");
db.distance=100;
db.bearing=45;
WayPointItem * p2=m_map->WPCreate(db,10,"bbb");
m_map->WPCircleCreate(p2,p1,true);
t_waypoint *wp = new t_waypoint;
wp->map_wp_item=p1;
m_waypoint_list.append(wp);
wp=new t_waypoint;
wp->map_wp_item=p2;
m_waypoint_list.append(wp);
// **************
// create various context menu (mouse right click menu) actions

View File

@ -51,7 +51,7 @@ public:
void adjust();
enum { Type = UserType + 2 };
enum { Type = UserType + 12 };
int type() const { return Type; }
protected:

View File

@ -45,7 +45,7 @@ public:
void addEdge(Edge *edge);
QList<Edge *> edges() const;
enum { Type = UserType + 1 };
enum { Type = UserType + 10 };
int type() const { return Type; }
void verticalMove(bool flag);