添加多机显示
This commit is contained in:
@@ -74,7 +74,6 @@ void Index1::setInstallWidget(QWidget *w)
|
||||
|
||||
paramInspector = w;
|
||||
paramInspector->setParent(this);
|
||||
qDebug() << w << paramInspector;
|
||||
|
||||
if(paramInspector)
|
||||
{
|
||||
|
||||
@@ -39,7 +39,6 @@ void Tools_Index0::setInstallWidget(QWidget *w)
|
||||
|
||||
Inspect = w;
|
||||
Inspect->setParent(this);
|
||||
qDebug() << w << Inspect;
|
||||
|
||||
if(Inspect)
|
||||
{
|
||||
|
||||
+6
-5
@@ -76,8 +76,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
internals::PointLatLng position;
|
||||
position.SetLat(0);
|
||||
position.SetLng(0);
|
||||
map->UAV->SetUAVPos(position,10);
|
||||
map->UAV->SetShowTrail(false);
|
||||
//map->UAV->SetUAVPos(position,10);
|
||||
//map->UAV->SetShowTrail(false);
|
||||
|
||||
map->setGeometry(0,
|
||||
0,
|
||||
@@ -182,7 +182,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(map,SIGNAL(WPProperty(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)),
|
||||
dlink->mavlinknode->Mission,SLOT(transmitPoint(float,float,float,float,int32_t,int32_t,float,uint16_t,uint16_t,uint16_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t,uint8_t)),Qt::DirectConnection);
|
||||
|
||||
|
||||
connect(dlink->mavlinknode,SIGNAL(addVehicles(int,int)),
|
||||
map,SLOT(addUAV(int,int)));
|
||||
|
||||
|
||||
|
||||
@@ -558,13 +559,13 @@ void MainWindow::updateUI()//事件驱动式更新数据
|
||||
LatLng.SetLat((double)(dlink->mavlinknode->vehicle.gps_raw_int.lat * 10e-8));
|
||||
LatLng.SetLng((double)(dlink->mavlinknode->vehicle.gps_raw_int.lon * 10e-8));
|
||||
|
||||
map->UAV->SetUAVPos(LatLng,dlink->mavlinknode->vehicle.gps_raw_int.alt * 10e-4);
|
||||
//map->UAV->SetUAVPos(LatLng,dlink->mavlinknode->vehicle.gps_raw_int.alt * 10e-4);
|
||||
//qDebug() << LatLng.Lat()
|
||||
// << LatLng.Lng();
|
||||
|
||||
|
||||
|
||||
map->UAV->SetUAVHeading(dlink->mavlinknode->vehicle.attitude.yaw * 57.3);
|
||||
//map->UAV->SetUAVHeading(dlink->mavlinknode->vehicle.attitude.yaw * 57.3);
|
||||
|
||||
|
||||
update();
|
||||
|
||||
@@ -61,18 +61,20 @@ void ParameterInspector::resizeEvent(QResizeEvent * event)
|
||||
|
||||
|
||||
//添加一个设备,
|
||||
void ParameterInspector::addVehicles(uint16_t id)
|
||||
void ParameterInspector::addVehicles(uint16_t sysid, uint16_t compid)
|
||||
{
|
||||
if(!vehicles.keys().contains(id))
|
||||
Q_UNUSED(compid)
|
||||
|
||||
if(!vehicles.keys().contains(sysid))
|
||||
{
|
||||
//如果还没有这个设备,就添加一个
|
||||
QMap<int, mavlink_param_value_t> param;
|
||||
vehicles.insert(id,param);
|
||||
vehicles.insert(sysid,param);
|
||||
|
||||
//同时检查combox有没有,没有就添加
|
||||
if(ui->systemComboBox->findText(tr("Vehicle %1").arg(id)) == (-1))
|
||||
if(ui->systemComboBox->findText(tr("Vehicle %1").arg(sysid)) == (-1))
|
||||
{
|
||||
ui->systemComboBox->addItem(tr("Vehicle %1").arg(id), id);
|
||||
ui->systemComboBox->addItem(tr("Vehicle %1").arg(sysid), sysid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ signals:
|
||||
|
||||
public slots:
|
||||
|
||||
void addVehicles(uint16_t id);
|
||||
void addVehicles(uint16_t sysid,uint16_t compid);
|
||||
void appendParameter(mavlink_message_t msg);
|
||||
|
||||
|
||||
|
||||
@@ -306,9 +306,7 @@ void MavLinkNode::MAVLinkRcv_Handler(mavlink_message_t msg)
|
||||
{
|
||||
//用于给参数添加设备,便于读取
|
||||
//qDebug() << "msg.sysid" <<msg.sysid << "msg.compid" << msg.compid;
|
||||
|
||||
Parameter->paramInspect->addVehicles(msg.sysid);
|
||||
|
||||
CheckVehicle(msg.sysid,msg.compid);
|
||||
|
||||
switch (msg.msgid) {
|
||||
//状态
|
||||
@@ -450,7 +448,21 @@ void MavLinkNode::CommandParse(mavlink_message_t msg)
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MavLinkNode::CheckVehicle(int sysid,int compid)
|
||||
{
|
||||
if(!vehicleList.contains(sysid))
|
||||
{
|
||||
vehicleList.insert(sysid,compid);
|
||||
Parameter->paramInspect->addVehicles(sysid,compid);
|
||||
|
||||
emit addVehicles(sysid,compid);
|
||||
|
||||
for (QHash<int,int>::iterator i = vehicleList.begin();i!= vehicleList.end();++i)
|
||||
{
|
||||
qDebug() << "add vehicle" << i.key() << i.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -77,6 +77,9 @@ public:
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
void addVehicles(int sysid,int compid);
|
||||
|
||||
void SendMessageTo(quint8 ch, quint8 *data,quint16 len);
|
||||
void recievemsg(mavlink_message_t msg);
|
||||
|
||||
@@ -110,6 +113,10 @@ private slots:
|
||||
void CommandParse(mavlink_message_t msg);
|
||||
//
|
||||
|
||||
//check for new vehicle
|
||||
void CheckVehicle(int sysid, int compid);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
enum SourceType{
|
||||
@@ -118,7 +125,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
uint8_t GCS_System_ID;
|
||||
uint8_t GCS_System_ID;
|
||||
|
||||
bool running_flag = false;
|
||||
quint32 running_frq = 200;//200Hz
|
||||
@@ -129,6 +136,10 @@ protected:
|
||||
QThread *Parameterthread;
|
||||
|
||||
|
||||
QHash<int,int> vehicleList;
|
||||
|
||||
|
||||
|
||||
_buffdef serial_buff;
|
||||
_buffdef client_buff;
|
||||
};
|
||||
|
||||
@@ -25,3 +25,8 @@
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "placemark.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace mapcontrol {
|
||||
|
||||
AltitudeItem::AltitudeItem(MapGraphicItem *map, QColor background) : myMap(map), myColor(background)
|
||||
{
|
||||
this->setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
this->setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
|
||||
|
||||
connect(map, SIGNAL(childRefreshPosition()), this, SLOT(RefreshPos()));
|
||||
@@ -77,7 +77,7 @@ void AltitudeItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
|
||||
qDebug() << event;
|
||||
|
||||
//QGraphicsItem::mousePressEvent(event);
|
||||
QGraphicsItem::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void AltitudeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
@@ -87,7 +87,7 @@ void AltitudeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
|
||||
}
|
||||
//QGraphicsItem::mouseReleaseEvent(event);
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
|
||||
}
|
||||
void AltitudeItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
@@ -101,7 +101,7 @@ void AltitudeItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
if (isDragging) {
|
||||
//this->setPos(event->pos());
|
||||
}
|
||||
//QGraphicsItem::mouseMoveEvent(event);
|
||||
QGraphicsItem::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
|
||||
|
||||
namespace mapcontrol {
|
||||
|
||||
class WayPointItem;
|
||||
class OPMapWidget;
|
||||
|
||||
#ifdef QtopmapWidget
|
||||
#include <mapwidgetglobal.h>
|
||||
|
||||
@@ -77,15 +77,18 @@ OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config) : QGraphicsView
|
||||
QPixmapCache::setCacheLimit(1024 * 1024);//set 1M byte
|
||||
|
||||
|
||||
|
||||
altitudeitem = new AltitudeItem(map,Qt::red);
|
||||
altitudeitem->setParentItem(map);
|
||||
setOverlayOpacity(overlayOpacity);
|
||||
|
||||
|
||||
|
||||
}
|
||||
void OPMapWidget::SetShowDiagnostics(bool const & value)
|
||||
{
|
||||
showDiag = value;
|
||||
/*
|
||||
if (!showDiag) {
|
||||
if (diagGraphItem != 0) {
|
||||
delete diagGraphItem;
|
||||
@@ -112,6 +115,7 @@ void OPMapWidget::SetShowDiagnostics(bool const & value)
|
||||
setOverlayOpacity(overlayOpacity);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
void OPMapWidget::SetUavPic(QString UAVPic)
|
||||
{
|
||||
@@ -123,6 +127,37 @@ void OPMapWidget::SetUavPic(QString UAVPic)
|
||||
}
|
||||
}
|
||||
|
||||
void OPMapWidget::SetShowUAV(const bool &value)
|
||||
{
|
||||
|
||||
if (value && UAV == 0) {
|
||||
UAV = new UAVItem(map, this);
|
||||
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 *)));
|
||||
UAV->setOpacity(overlayOpacity);
|
||||
} else if (!value) {
|
||||
if (UAV != 0) {
|
||||
delete UAV;
|
||||
UAV = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OPMapWidget::addUAV(int sysid,int compid)
|
||||
{
|
||||
UAVItem *uavItem = new UAVItem(map, this);
|
||||
uavItem->setParentItem(map);
|
||||
connect(this, SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)), uavItem, SIGNAL(UAVLeftSafetyBouble(internals::PointLatLng)));
|
||||
connect(this, SIGNAL(UAVReachedWayPoint(int, WayPointItem *)), uavItem, SIGNAL(UAVReachedWayPoint(int, WayPointItem *)));
|
||||
uavItem->setOpacity(overlayOpacity);
|
||||
|
||||
uavItem->setID(sysid,compid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
WayPointLine *OPMapWidget::WPLineCreate(WayPointItem *from, WayPointItem *to, QColor color, bool dashed, int width)
|
||||
{
|
||||
if (!from | !to) {
|
||||
@@ -187,21 +222,7 @@ WayPointCircle *OPMapWidget::WPCircleCreate(HomeItem *center, double radius, boo
|
||||
ret->setOpacity(overlayOpacity);
|
||||
return ret;
|
||||
}
|
||||
void OPMapWidget::SetShowUAV(const bool &value)
|
||||
{
|
||||
if (value && UAV == 0) {
|
||||
UAV = new UAVItem(map, this);
|
||||
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 *)));
|
||||
UAV->setOpacity(overlayOpacity);
|
||||
} else if (!value) {
|
||||
if (UAV != 0) {
|
||||
delete UAV;
|
||||
UAV = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OPMapWidget::SetShowHome(const bool &value)
|
||||
{
|
||||
Home->setVisible(value);
|
||||
|
||||
@@ -554,6 +554,8 @@ signals:
|
||||
|
||||
public slots:
|
||||
|
||||
void addUAV(int sysid, int compid);
|
||||
|
||||
|
||||
void getMapTypes(void);
|
||||
void setMapTypes(QVariant value);
|
||||
|
||||
@@ -31,12 +31,21 @@
|
||||
namespace mapcontrol {
|
||||
double UAVItem::groundspeed_mps_filt = 0;
|
||||
|
||||
UAVItem::UAVItem(MapGraphicItem *map, OPMapWidget *parent, QString uavPic) : map(map), mapwidget(parent), altitude(0), showtrail(true), showtrailline(true),
|
||||
trailtime(100), traildistance(5), autosetreached(true), autosetdistance(100), showUAVInfo(false)
|
||||
UAVItem::UAVItem(MapGraphicItem *map, OPMapWidget *parent, QString uavPic ,uint8_t sysid,uint8_t compid) : map(map), mapwidget(parent), altitude(0), showtrail(true), showtrailline(true),
|
||||
trailtime(100), traildistance(5), autosetreached(true), autosetdistance(100), showUAVInfo(false),sysid(sysid),compid(compid)
|
||||
{
|
||||
pic.load(uavPic);
|
||||
|
||||
this->setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
|
||||
this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
|
||||
pic.load(uavPic);
|
||||
//this->setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
//this->setFlag(QGraphicsItem::ItemIsSelectable, false);
|
||||
|
||||
//this->setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
//this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
|
||||
localposition = map->FromLatLngToLocal(mapwidget->CurrentPosition());
|
||||
this->setPos(localposition.X(), localposition.Y());
|
||||
this->setZValue(4);
|
||||
@@ -44,7 +53,12 @@ UAVItem::UAVItem(MapGraphicItem *map, OPMapWidget *parent, QString uavPic) : map
|
||||
trail->setParentItem(map);
|
||||
trailLine = new QGraphicsItemGroup(this);
|
||||
trailLine->setParentItem(map);
|
||||
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
|
||||
|
||||
//this->setFlag(QGraphicsItem::ItemIgnoresTransformations, false);
|
||||
//this->setFlag(QGraphicsItem::ItemIsMovable, false);
|
||||
//this->setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||
|
||||
|
||||
setCacheMode(QGraphicsItem::ItemCoordinateCache);
|
||||
mapfollowtype = UAVMapFollowType::None;
|
||||
trailtype = UAVTrailType::ByDistance;
|
||||
@@ -65,6 +79,15 @@ void UAVItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
|
||||
qDebug() << "selected" << sysid << compid << this->isSelected();
|
||||
|
||||
if (this->isSelected()) {
|
||||
qDebug() << "selected" << sysid << compid;
|
||||
painter->setPen(Qt::red);
|
||||
painter->drawRect(QRectF(boundingRect()));
|
||||
}
|
||||
|
||||
|
||||
// Draw plane
|
||||
painter->drawPixmap(-pic.width() / 2, -pic.height() / 2, pic);
|
||||
|
||||
@@ -126,6 +149,54 @@ void UAVItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
|
||||
painter->drawPath(textPath);
|
||||
}
|
||||
|
||||
|
||||
void UAVItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void UAVItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
qDebug() << "UAV mousePressEvent";
|
||||
//this->setSelected(true);
|
||||
update();
|
||||
}
|
||||
|
||||
//QGraphicsItem::mousePressEvent(event);
|
||||
}
|
||||
void UAVItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
qDebug() << "UAV mouseReleaseEvent";
|
||||
|
||||
//this->setSelected(true);
|
||||
|
||||
emit selected(sysid,compid);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
//QGraphicsItem::mouseReleaseEvent(event);
|
||||
|
||||
}
|
||||
void UAVItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UAVItem::setID(int sys,int comp)
|
||||
{
|
||||
sysid = sys;
|
||||
compid = comp;
|
||||
}
|
||||
|
||||
|
||||
void UAVItem::updateTextOverlay()
|
||||
{
|
||||
QPainterPath temp;
|
||||
|
||||
@@ -61,7 +61,7 @@ class UAVItem : public QObject, public QGraphicsItem {
|
||||
Q_OBJECT Q_INTERFACES(QGraphicsItem)
|
||||
public:
|
||||
enum { Type = UserType + 2 };
|
||||
UAVItem(MapGraphicItem *map, OPMapWidget *parent, QString uavPic = QString::fromUtf8(":/uavs/images/mapquad.png"));
|
||||
UAVItem(MapGraphicItem *map, OPMapWidget *parent, QString uavPic = QString::fromUtf8(":/uavs/images/mapquad.png"), uint8_t sysid = 0, uint8_t compid = 0);
|
||||
~UAVItem();
|
||||
|
||||
/**
|
||||
@@ -311,11 +311,28 @@ private:
|
||||
|
||||
QPainterPath textPath;
|
||||
|
||||
//bool isSelected = false;
|
||||
|
||||
uint8_t sysid;
|
||||
uint8_t compid;
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
void setID(int sys,int comp);
|
||||
|
||||
void RefreshPos();
|
||||
void setOpacitySlot(qreal opacity);
|
||||
void zoomChangedSlot();
|
||||
signals:
|
||||
|
||||
void selected(uint8_t sys,uint8_t comp);
|
||||
|
||||
void UAVReachedWayPoint(int const & waypointnumber, WayPointItem *waypoint);
|
||||
void UAVLeftSafetyBouble(internals::PointLatLng const & position);
|
||||
void setChildPosition();
|
||||
|
||||
Reference in New Issue
Block a user