实现多条航线同时显示
This commit is contained in:
+112
-87
@@ -154,6 +154,10 @@ OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config) : QGraphicsView
|
||||
this,SLOT(NOPTimeout()));
|
||||
NoOperationTimer->start(20000);//20s不操作
|
||||
|
||||
|
||||
|
||||
currentGroup = 3;
|
||||
|
||||
}
|
||||
|
||||
void OPMapWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
@@ -178,11 +182,7 @@ void OPMapWidget::dropEvent(QDropEvent *event)
|
||||
|
||||
if(fileName.right(5) == ".plan")
|
||||
{
|
||||
//setCommandFile(fileName);
|
||||
//loadCommandJson(fileName);
|
||||
|
||||
WPLoad(fileName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,13 +372,13 @@ void OPMapWidget::setUAVPos(int sysid,int compid,double x,double y,double z)
|
||||
|
||||
void OPMapWidget::setUAVHeading(int sysid,int compid,float Heading)
|
||||
{
|
||||
Q_UNUSED(compid)
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
UAVItem *u = qgraphicsitem_cast<UAVItem *>(i);
|
||||
if (u) {
|
||||
if(u->SysID() == sysid)
|
||||
{
|
||||
u->SetUAVHeading(Heading);
|
||||
//qDebug() << Heading;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -427,6 +427,7 @@ WayPointLine *OPMapWidget::WPLineCreate(WayPointItem *from, WayPointItem *to, QC
|
||||
ret->setOpacity(overlayOpacity);
|
||||
return ret;
|
||||
}
|
||||
|
||||
WayPointLine *OPMapWidget::WPLineCreate(HomeItem *from, WayPointItem *to, QColor color, bool dashed, int width)
|
||||
{
|
||||
if (!from | !to) {
|
||||
@@ -437,6 +438,11 @@ WayPointLine *OPMapWidget::WPLineCreate(HomeItem *from, WayPointItem *to, QColor
|
||||
return ret;
|
||||
}
|
||||
|
||||
void OPMapWidget::WPLineUpdate(int group)//调用这个,刷新连接线
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void OPMapWidget::WPLineDelete(WayPointItem *from, WayPointItem *to)
|
||||
{
|
||||
do
|
||||
@@ -456,11 +462,12 @@ void OPMapWidget::WPLineDelete(WayPointItem *from, WayPointItem *to)
|
||||
WayPointLine *OPMapWidget::WPLineFind(WayPointItem *from, WayPointItem *to)
|
||||
{
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointLine *w = qgraphicsitem_cast<WayPointLine *>(i);
|
||||
WayPointLine *l = qgraphicsitem_cast<WayPointLine *>(i);
|
||||
|
||||
if (w) {
|
||||
if (w->WPLineFrom() == from) {
|
||||
return w;
|
||||
if (l) {
|
||||
if ((l->WPLineFrom() == from) && (l->WPLineTo() == to) )
|
||||
{
|
||||
return l;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -496,8 +503,6 @@ void OPMapWidget::SetShowHome(const bool &value)
|
||||
|
||||
void OPMapWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
|
||||
|
||||
if (scene()) {
|
||||
scene()->setSceneRect(
|
||||
QRect(QPoint(0,0), event->size()));
|
||||
@@ -763,6 +768,7 @@ void OPMapWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
isLNOP = false;
|
||||
|
||||
//生成一个列表
|
||||
//如果是点击生成,那么就获取当前的编辑组,使用当前编辑组的编号
|
||||
if(isWPCreate == true)
|
||||
{
|
||||
if(event->button() == Qt::LeftButton)
|
||||
@@ -773,11 +779,19 @@ void OPMapWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
LatLng = map->FromLocalToLatLng(p.x(), p.y());
|
||||
WayPointItem *Item = WPCreate(LatLng,50);
|
||||
|
||||
WPLineCreate(WPFind(Item->Number() - 1),Item,Qt::green,false,2);
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
qDebug() << "WPCreate Point"
|
||||
<< QThread::currentThreadId();
|
||||
if (w) {
|
||||
if (w->MissionType() == Item->MissionType()) {
|
||||
if(w->Number() == (Item->Number() - 1))
|
||||
{
|
||||
WPLineCreate(w,Item,Qt::green,false,2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
emit MouseDoubleClickEvent(event);
|
||||
@@ -789,7 +803,10 @@ void OPMapWidget::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
////////////////WAYPOINT////////////////////////
|
||||
WayPointItem *OPMapWidget::WPCreate()
|
||||
{
|
||||
WayPointItem *item = new WayPointItem(this->CurrentPosition(), 0,1, map);
|
||||
//获取当前组下面的seq最大值
|
||||
int seq = getWaypointSize(currentGroup);
|
||||
|
||||
WayPointItem *item = new WayPointItem(this->CurrentPosition(), 0,seq,currentGroup, map);
|
||||
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
@@ -800,7 +817,10 @@ WayPointItem *OPMapWidget::WPCreate()
|
||||
}
|
||||
WayPointItem *OPMapWidget::magicWPCreate()
|
||||
{
|
||||
WayPointItem *item = new WayPointItem(1,map, true);
|
||||
//获取当前组下面的seq最大值
|
||||
int seq = getWaypointSize(currentGroup);
|
||||
|
||||
WayPointItem *item = new WayPointItem(seq,currentGroup,map, true);
|
||||
|
||||
item->SetShowNumber(false);
|
||||
item->setParentItem(map);
|
||||
@@ -818,7 +838,10 @@ void OPMapWidget::WPCreate(WayPointItem *item)
|
||||
}
|
||||
WayPointItem *OPMapWidget::WPCreate(internals::PointLatLng const & coord, int const & altitude)
|
||||
{
|
||||
WayPointItem *item = new WayPointItem(coord, altitude,1, map);
|
||||
//获取当前组下面的seq最大值
|
||||
int seq = getWaypointSize(currentGroup);
|
||||
|
||||
WayPointItem *item = new WayPointItem(coord, altitude,seq,currentGroup, map);
|
||||
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
@@ -830,7 +853,10 @@ WayPointItem *OPMapWidget::WPCreate(internals::PointLatLng const & coord, int co
|
||||
}
|
||||
WayPointItem *OPMapWidget::WPCreate(internals::PointLatLng const & coord, int const & altitude, QString const & description)
|
||||
{
|
||||
WayPointItem *item = new WayPointItem(coord, altitude,1, description, map);
|
||||
//获取当前组下面的seq最大值
|
||||
int seq = getWaypointSize(currentGroup);
|
||||
|
||||
WayPointItem *item = new WayPointItem(coord, altitude,seq,currentGroup, description, map);
|
||||
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
@@ -842,7 +868,10 @@ WayPointItem *OPMapWidget::WPCreate(internals::PointLatLng const & coord, int co
|
||||
}
|
||||
WayPointItem *OPMapWidget::WPCreate(const distBearingAltitude &relativeCoord, const QString &description)
|
||||
{
|
||||
WayPointItem *item = new WayPointItem(relativeCoord,1, description, map);
|
||||
//获取当前组下面的seq最大值
|
||||
int seq = getWaypointSize(currentGroup);
|
||||
|
||||
WayPointItem *item = new WayPointItem(relativeCoord,seq,currentGroup, description, map);
|
||||
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
@@ -853,6 +882,23 @@ WayPointItem *OPMapWidget::WPCreate(const distBearingAltitude &relativeCoord, co
|
||||
return item;
|
||||
}
|
||||
|
||||
int OPMapWidget::getWaypointSize(int group)
|
||||
{
|
||||
QList<WayPointItem *> list;
|
||||
list.clear();
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
if (w) {
|
||||
if (w->MissionType() == group) {
|
||||
list.append(w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list.size();
|
||||
}
|
||||
|
||||
void OPMapWidget::WPInsert()
|
||||
{
|
||||
@@ -880,15 +926,11 @@ void OPMapWidget::WPInsert()
|
||||
if((item_old1)&&(item_old2))
|
||||
{
|
||||
WPLineDelete(item_old1,item_old2);
|
||||
//WPLineDelete(item_old1,item_old2);
|
||||
//WPLineDelete(item_old1,item_old2);
|
||||
}
|
||||
//删除连线
|
||||
if((item_old1)&&(item_old0))
|
||||
{
|
||||
WPLineDelete(item_old0,item_old1);
|
||||
//WPLineDelete(item_old0,item_old1);
|
||||
//WPLineDelete(item_old0,item_old1);
|
||||
|
||||
internals::PointLatLng latlng1 = item_old0->Coord();
|
||||
internals::PointLatLng latlng2 = item_old1->Coord();
|
||||
@@ -907,7 +949,7 @@ void OPMapWidget::WPInsert()
|
||||
|
||||
if(item_old1)//如果指定的点存在,那么就可以在这之前插入一个点
|
||||
{
|
||||
WayPointItem *item = new WayPointItem(latlng, item_old1->Altitude(), 1,map);
|
||||
WayPointItem *item = new WayPointItem(latlng, item_old1->Altitude(), position,currentGroup,map);
|
||||
|
||||
ConnectWP(item);
|
||||
item->SetNumber(position);
|
||||
@@ -949,21 +991,6 @@ void OPMapWidget::WPInsert()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
WayPointItem *w_last = WPFind(item->Number() - 1);
|
||||
if(w_last)
|
||||
{
|
||||
WPLineCreate(w_last,item,Qt::green,false,2);
|
||||
|
||||
WayPointItem *w_last2 = WPFind(item->Number() - 2);
|
||||
if(w_last2)
|
||||
{
|
||||
WPLineCreate(w_last2,w_last,Qt::green,false,2);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -971,9 +998,6 @@ void OPMapWidget::WPInsert()
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
if (w) {
|
||||
//qDebug() << "all number" << w->Number() << w->snumber;
|
||||
|
||||
|
||||
WPFollowPrevious(w->FollowPrevious(),w);
|
||||
}
|
||||
}
|
||||
@@ -990,7 +1014,7 @@ void OPMapWidget::WPInsert(WayPointItem *item, const int &position)
|
||||
}
|
||||
WayPointItem *OPMapWidget::WPInsert(internals::PointLatLng const & coord, int const & altitude, const int &position)
|
||||
{
|
||||
WayPointItem *item = new WayPointItem(coord, altitude,1, map);
|
||||
WayPointItem *item = new WayPointItem(coord, altitude,position,currentGroup, map);
|
||||
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
@@ -1011,7 +1035,7 @@ WayPointItem *OPMapWidget::WPInsert(internals::PointLatLng const & coord, int co
|
||||
} else {
|
||||
mcoord = coord;
|
||||
}
|
||||
WayPointItem *item = new WayPointItem(mcoord, altitude,1, description, map);
|
||||
WayPointItem *item = new WayPointItem(mcoord, altitude,position,currentGroup, description, map);
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
item->setParentItem(map);
|
||||
@@ -1025,7 +1049,7 @@ WayPointItem *OPMapWidget::WPInsert(internals::PointLatLng const & coord, int co
|
||||
}
|
||||
WayPointItem *OPMapWidget::WPInsert(distBearingAltitude const & relative, QString const & description, const int &position)
|
||||
{
|
||||
WayPointItem *item = new WayPointItem(relative,1, description, map);
|
||||
WayPointItem *item = new WayPointItem(relative,position,currentGroup, description, map);
|
||||
|
||||
item->SetNumber(position);
|
||||
ConnectWP(item);
|
||||
@@ -1050,10 +1074,18 @@ void OPMapWidget::WPDelete(WayPointItem *item)
|
||||
setSelectedWP(w);
|
||||
w->emitWPProperty();
|
||||
|
||||
WayPointItem *w_next = WPFind(w->Number() + 1);
|
||||
if(w_next)
|
||||
{
|
||||
WPLineCreate(w,w_next,Qt::green,false,2);
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w_next = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
if (w_next) {
|
||||
if (w->MissionType() == w_next->MissionType()) {
|
||||
if(w->Number() == (w_next->Number() + 1))
|
||||
{
|
||||
WPLineCreate(w,w_next,Qt::green,false,2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1102,14 +1134,18 @@ void OPMapWidget::WPDelete(void)
|
||||
setSelectedWP(item);
|
||||
item->emitWPProperty();
|
||||
|
||||
WayPointItem *item_next = WPFind(item->Number() + 1);
|
||||
if(item_next)
|
||||
{
|
||||
WPLineCreate(item,item_next,Qt::green,false,2);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "can not find next fine";
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *item_next = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
if (item_next) {
|
||||
if (item->MissionType() == item_next->MissionType()) {
|
||||
if(item->Number() == (item_next->Number() + 1))
|
||||
{
|
||||
WPLineCreate(item,item_next,Qt::green,false,2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1265,6 +1301,8 @@ void OPMapWidget::ConnectWP(WayPointItem *item)
|
||||
this,SLOT(setCurrentPoint(int)), Qt::DirectConnection);
|
||||
|
||||
|
||||
connect(item,SIGNAL(currentMissiontype(int)),
|
||||
this,SLOT(WPGroup(int)), Qt::DirectConnection);
|
||||
|
||||
|
||||
//生成后立即选中,并且把信息发给ui界面
|
||||
@@ -1756,7 +1794,10 @@ void OPMapWidget::WPLoad(QString path)//带文件目录参数
|
||||
|
||||
QJsonObject json = doc.object();
|
||||
|
||||
//解码
|
||||
//安全区解码
|
||||
|
||||
|
||||
//任务解码
|
||||
QJsonArray itemsArray = json.value("mission").toObject().value("items").toArray();
|
||||
|
||||
for(QJsonValue item: itemsArray) {
|
||||
@@ -1902,7 +1943,6 @@ void OPMapWidget::WPSave(QString path)//带文件目录参数
|
||||
item.insert("params",params);
|
||||
item.insert("type",w->MissionType());
|
||||
|
||||
//这里有问题
|
||||
items.append(item);
|
||||
}
|
||||
|
||||
@@ -1915,10 +1955,6 @@ void OPMapWidget::WPSave(QString path)//带文件目录参数
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
mission.insert("cruiseSpeed",2);
|
||||
mission.insert("firmwareType",0);
|
||||
mission.insert("hoverSpeed",2);
|
||||
@@ -2029,7 +2065,7 @@ void OPMapWidget::WPUpload(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//飞行界面收到的当前航点的消息
|
||||
void OPMapWidget::groupchanged(int value)
|
||||
{
|
||||
//如果当前是在飞行界面,那么就下载,否则不动
|
||||
@@ -2040,6 +2076,7 @@ void OPMapWidget::groupchanged(int value)
|
||||
}
|
||||
else//飞行界面
|
||||
{
|
||||
/*
|
||||
WPDeleteAll();
|
||||
|
||||
int sysid = 0;
|
||||
@@ -2057,6 +2094,7 @@ void OPMapWidget::groupchanged(int value)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -2064,6 +2102,7 @@ void OPMapWidget::groupchanged(int value)
|
||||
update();
|
||||
}
|
||||
|
||||
//编辑界面收到的组切换的消息
|
||||
void OPMapWidget::WPGroup(int value)
|
||||
{
|
||||
currentGroup = value;
|
||||
@@ -2072,34 +2111,35 @@ void OPMapWidget::WPGroup(int value)
|
||||
|
||||
//切换当前航线,其他都隐藏,或者高亮当前
|
||||
|
||||
/*
|
||||
//将不是当前的全部变成灰色,当前的显示
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
if (w) {
|
||||
|
||||
if(w->MissionType() != currentGroup)
|
||||
qDebug() << "missiontype" << w->MissionType();
|
||||
if(w->MissionType() == currentGroup)
|
||||
{
|
||||
w->setVisible(false);
|
||||
w->setisActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
w->setVisible(true);
|
||||
w->setisActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//将不是当前的先全部变成灰色,当前的显示
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointLine *l = qgraphicsitem_cast<WayPointLine *>(i);
|
||||
if (l) {
|
||||
|
||||
/*
|
||||
if(l->MissionType() != currentGroup)
|
||||
{
|
||||
l->setVisible(false);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//按照当前的组生成新的航点和航线
|
||||
/*
|
||||
@@ -2111,23 +2151,8 @@ void OPMapWidget::WPGroup(int value)
|
||||
*/
|
||||
|
||||
|
||||
WPDeleteAll();
|
||||
|
||||
int sysid = 0;
|
||||
int compid = 0;
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
UAVItem *u = qgraphicsitem_cast<UAVItem *>(i);
|
||||
if (u) {
|
||||
if(u->Select() == true)
|
||||
{
|
||||
sysid = u->SysID();
|
||||
compid = u->CompID();
|
||||
|
||||
emit signal_WPDownload(sysid,compid,currentGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user