From 6f59d40b3d24b40a90da5c42030555ccad7c84f7 Mon Sep 17 00:00:00 2001 From: hm Date: Wed, 11 May 2022 15:12:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=B4=E6=A0=8F=E5=8F=AF=E4=BB=A5=E4=BB=8E?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/CommandUI/CommandUI.cpp | 54 ++++- App/CommandUI/CommandUI.h | 8 + App/CommandUI/CommandUI.ui | 41 +--- App/GCS_zh_CN.qm | Bin 19579 -> 19722 bytes App/GCS_zh_CN.ts | 114 +++++----- App/MissionUI/MissionUI.cpp | 37 +++- App/mainwindow.cpp | 3 +- opmap/MAP_zh_CN.ts | 49 +++-- opmap/mapwidget/geoFencecircle.cpp | 100 +++++++++ opmap/mapwidget/geoFencecircle.h | 56 +++++ opmap/mapwidget/geoFenceitem.cpp | 101 ++++++++- opmap/mapwidget/geoFenceitem.h | 27 ++- opmap/mapwidget/geoFenceitemline.cpp | 31 --- opmap/mapwidget/geoFenceitemline.h | 2 +- opmap/mapwidget/mapwidget.pro | 2 + opmap/mapwidget/opmapwidget.cpp | 315 ++++++++++++++++++++++----- opmap/mapwidget/opmapwidget.h | 7 +- 17 files changed, 736 insertions(+), 211 deletions(-) create mode 100644 opmap/mapwidget/geoFencecircle.cpp create mode 100644 opmap/mapwidget/geoFencecircle.h diff --git a/App/CommandUI/CommandUI.cpp b/App/CommandUI/CommandUI.cpp index 5e51e15..0698d3e 100644 --- a/App/CommandUI/CommandUI.cpp +++ b/App/CommandUI/CommandUI.cpp @@ -42,6 +42,15 @@ CommandUI::CommandUI(QWidget *parent) : connect(DoubleClickTimer,SIGNAL(timeout()), this,SLOT(DoubleClickTimeout())); + + ui->comboBox_group->addItem(tr("Group 1"),3); + ui->comboBox_group->addItem(tr("Group 2"),4); + ui->comboBox_group->addItem(tr("Group 3"),5); + ui->comboBox_group->addItem(tr("Group 4"),6); + ui->comboBox_group->setCurrentIndex(0); + + + } CommandUI::~CommandUI() @@ -689,29 +698,49 @@ void CommandUI::commandAccepted(bool flag,uint16_t command,uint8_t result) void CommandUI::setCurrent(QVariant value) { + /* if(value.toBool() == true) { emit showMessage(tr("设置航点 %1").arg(m_currentSeq)); emit SetCurrentPoint(m_currentSeq); } + */ } void CommandUI::missionConfirm(int seq) { - m_currentSeq = seq; + if(isCofirmShow == true) + { - //根据这个comfirm 确定要输入的参数 - Confirm *confirmor = new Confirm(this); - confirmor->setGeometry(0,0,this->width(),this->height()); + } + else + { + m_currentSeq = seq; - //设置警告界面 - confirmor->setNotice(tr("click confirm to set Point %1 as current point").arg(seq)); + //根据这个comfirm 确定要输入的参数 + Confirm *confirmor = new Confirm(this); + confirmor->setGeometry(0,0,this->width(),this->height()); - connect(confirmor,SIGNAL(confirmValue(QVariant)), - this,SLOT(setCurrent(QVariant))); + //设置警告界面 + confirmor->setNotice(tr("click confirm to set Point %1 as current point").arg(seq)); - confirmor->show(); + connect(confirmor,&Confirm::confirmValue,[=](QVariant value){ + if(value.toBool() == true) + { + emit showMessage(tr("设置航点 %1").arg(m_currentSeq)); + emit SetCurrentPoint(m_currentSeq); + } + isCofirmShow = false; + }); + + connect(confirmor,&Confirm::destroyed,[=](){ + isCofirmShow = false; + }); + + confirmor->show(); + isCofirmShow = true; + } } @@ -747,7 +776,7 @@ void CommandUI::setPointCount(QList nums) foreach (int i, nums) { - ui->comboBox_seq->addItem(QString::number(i),i); + ui->comboBox_seq->addItem(tr("point:") + QString::number(i),i); } ui->comboBox_seq->setCurrentIndex(0); @@ -805,3 +834,8 @@ void CommandUI::on_pushButton_setUAV_clicked() } } + +void CommandUI::on_comboBox_group_currentIndexChanged(int index) +{ + emit getAllPoint(ui->comboBox_group->currentData().toInt()); +} diff --git a/App/CommandUI/CommandUI.h b/App/CommandUI/CommandUI.h index 44aa2b9..cb45952 100644 --- a/App/CommandUI/CommandUI.h +++ b/App/CommandUI/CommandUI.h @@ -104,6 +104,8 @@ signals: void searchallUav(void); */ + void getAllPoint(int); + private slots: void updateUI(void); @@ -123,6 +125,8 @@ private slots: void on_pushButton_setUAV_clicked(); + void on_comboBox_group_currentIndexChanged(int index); + private: const char* _spacingJsonKey = "spacing"; @@ -194,6 +198,10 @@ private: int m_currentSys = 1; int m_currentComp = 1; + bool isCofirmShow = false; + + + }; #endif // COMMANDUI_H diff --git a/App/CommandUI/CommandUI.ui b/App/CommandUI/CommandUI.ui index df0c86e..a47d83f 100644 --- a/App/CommandUI/CommandUI.ui +++ b/App/CommandUI/CommandUI.ui @@ -6,7 +6,7 @@ 0 0 - 422 + 457 348 @@ -31,21 +31,10 @@ - - - - - - 无人机 - - - - - - - - + + + 切换无人机 @@ -56,27 +45,19 @@ - - - - - - 航点 - - - - - - - - - + 切换航点 + + + + + + diff --git a/App/GCS_zh_CN.qm b/App/GCS_zh_CN.qm index 86cc11042cf35b7dff3fe1c91eafaa5509982e05..4507ccb9457201e7b8b27e795a466fa833465e05 100644 GIT binary patch delta 1790 zcmYM!c}$aM90%}kkN0THr~=C2R8ULH-IkUcl!LFbeKJAfExoF*F2VD^J&+4|2X&->=>^Shqsb**e?ovhkL zwq@VA>0UJej6hHl(^Sv29AbthHrs!b`IG^(2Z4ziX3$C?{s`cD5=gKBkz;`LMSwL| z+ANC3=2d8j@eA@O6Xo z_8!3ZFf*Wy8Cbv!(lO0t%-}an%SEQunHggL*I$^S518S*nUUwfdHMqpb>NH?(l|Ld ziw+gg-Unwbp#Zv>Q5J9sR$$Cnrh5a^PX;dKDZtNTMzw$|+5vCb$k8;C_Ya9|gf$QbC3K0m8~uDoiw)M%u`9at}G5Y=tno(JKhM zDA0gV2qPOA^bi{2D5F$_R#E__3kVzaA;P3)!2CACTGo-tNb;k?yPKK5#ms;|kQ7pJ z00>kfdBZJWk{l_Soq+sX%+b?41nS8z$t29J>7cF;Abs%%fVK(?caMBmh0HvXh z2TY%aCAq=C)KX-9)JhvZWBRYgDnFV4T@FcsMCh?<<}=#QhBf@iAA9psBj=iU1Lf6C zlwU5Y)20EcmrV0f+^bCl{O`y#dG1tjH<@{xC*W{LW__^_@G6$gSkw=MSY?AsKdQ?? zX_yO%Fl8v>DrwRk@)TJHDp#zF;?ztz^~b01nB@DpV+RfO*~J-@eVWaw(^8O#VDV}jI2_24?hK_lqm-?s5CBjIj(_v5vAe8 zcgF(3D>zkl0ma5kIzgY>%dOl_A&kjqMhm2Z)}Jz?&7_jnmzmK^NsiV}n9*6IKd@4T_OzL`>71Lkw zL%H-|a-T4oymyA+)Hk1!zbs^hQ9$00g_;%j=)(-5A#(-YJv)WYV{x?6_e|q z8s;!#<3*usGbOS^4DT4}Oo+ItbuV@9h*;Tl7I115KQ{OPo@#MduMNqtOc4+N9zvO& z5s&&mpsVJlc%tt)b)iyh>!3k&GKgKbuh2>AW6oG7UQ@KtQC`oCQHl49D(Oo4QyQnz zr+%R-$a_QMd{wo1{{>)LH#4SHwfFiErP-|d@w6+A`2?nAu4>>Bg{5+08gHqc^|3T~ z_3Eg{lPLWFsZtdb{y?2`;~I5oSZzxl1RQ(Rwxc%c%3tc$ug#Qfq`I`4X2X4%x@~~Ps&7wnLcQCY)G1*dq zI?yR5#NkCcRluv~t$8(8YK2icsrIfgjdzrLeNB~o z((TwkrH!7aI1WzSL>=kSs@f?PgI(+3OYglzt#j2~z(=F?_>As*?S;}IlZ$IQH~;_Vs{A$C@7s&>*RC0PC+#t{J1NsUZH51Rs3=@sBrP|) Kx1^bUJpKWdV#urj delta 1682 zcmXZddrZ?;6bJBcAHPRiYy}@Yj6#*Rw1u`5T6sSv4hrg2d`!g6skMrlOhv>wY%;~? zRP^TAK0I5dk6Uz6;>^{-Fw@0VZBIrpA(yM4dx zRh6t_xNOOu5$XDH01m*`!HkV$##@-~_ET$qmzfp7+daT&4b%1ykbMLQJ`Uu>14&;1 z`Llue$5NR*T((83k%yaYz^Y9^`UzllHek#r-=p<)pm+m)y9ii!5y+S*^~x{!&4-}8 zxf8HNGh^O*V;|FYg6UK+6G5sf2!J zVj43o7~HY>^u7aJvlj@x#I&|T7>H*qg|K8A;5Yt2Kc>@zMY&dI;57Kw>Axms0|<*+>|)1PRh9TGt|>VI_GTxzhT=!={ z%ueK$UWXrJ=mW-hv8KHc7%NA~)-tJ)(|G1! zLq#o>_!t$_BLUS5rqhlGRUUf&flT8I1;!teIX6WB0l&#y&-VcO)v}D)cL3J~S&z~R zM2(e(@a`nXT}4(owReC|Q5Z!#mQkZPIYCZG)TlW56E&djTV_bEqP~d=Na|Ibt-C>m z_DE&CQEvZ5s^zmiIm#-}cYyga)AqiyE}C+bPh=*CDBE8@r7AvB-g}pJXZS6StES^f z-p7gW1Om>7oND0;%5Asg5=_&)+>))7!qBD6lnRpOYv||9lyjt#)~(ExKS_?(PnfBJ zBoCyfkOJwGjth2wCbz$m+S-=PRnKXmSU&Dp*EfJBhHEONT*4Z;+uc-PTtD}6(oDeJ z$0u~q)Fv(G3!nGUWXJMrH^c+#Hoh{X7!b3V_HF!N?ZKh^V9kcp{8jNH^?V(FKaMnX zG5zTq`TL9ML3pL%M7A^2(p0;y-lsB8sV>(CQ>Tw&#{H_g_n6XB1u-4-)Wb}f z)OcS?H7dKlSiR`l6*`^GYHwZ-pzTz9k9z68T&-UA%1K_7dR4))9EnrUvbeWtgeQ+^ zNPL=k3+GX5Cuw>w9RWt|4N&f%NCox>M4cg1|CY+twxHCefam#Cr@nK@)Jhk1Tcgyf zHu@b0wQ@aOz1C8#rRoV4GDO?*qLa2^rnYnT8Y;V8duMDTjqD9=&*=3uFdm(%i4r#T z>jEtFUN7o~?Y>3N_vyk8(A6IGp)PvmLGrB5`TcnshDcrJ!k=l~rSrtnpM@E^a`kY! t请不要操作过快,上一个指令未发送完成 - + 设置航点 %1 - - - click confirm to set uav %1 as current - - %1 accepted and executed %1 执行成功 @@ -533,7 +528,7 @@ %1 正在执行 - + click confirm to set Point %1 as current point 点击设置航点%1为当前航点 @@ -2746,68 +2741,68 @@ 界面 - + save 保存 - + insert 插入 - + upload 上传 - + add 增加 - + download downlload 下载 - + load 打开 - + delete 删除 - + Rectangle 围栏 - + clean 清空 - + Mission 1 航线1 - + Mssion 2 航线2 - + Mssion 3 航线3 - + Mission 4 航线4 @@ -2837,113 +2832,130 @@ 起飞 - + number 航点 - + command 类型 - + par1 参数1 - + par2 参数2 - + par3 参数3 - + par4 参数4 - + + lat 纬度 - + + lng 经度 - + + group + 组别 + + + + inclusion + 包含 + + + + par + 参数 + + + alt 海拔 - - + + 航点 - - + + 返航 - - + + 降落 - - + + 起飞 - - + + 保持 - - + + 表速 - - + + 快升 - - + + 开加力 - - + + 关加力 - - + + Selete Way Point File... 选择载入文件... - - + + plan file (*.plan) 任务文件 (*.plan) diff --git a/App/MissionUI/MissionUI.cpp b/App/MissionUI/MissionUI.cpp index 6636c45..aa9f518 100644 --- a/App/MissionUI/MissionUI.cpp +++ b/App/MissionUI/MissionUI.cpp @@ -243,7 +243,42 @@ MissionUI::MissionUI(QWidget *parent) : { if(tablelist.key(table) == 1)//围栏 { - continue; + table->setColumnCount(5); //设置列数为7 + table->setGeometry(QRect(10,455,740,95)); //设置tableWidget的大小 + table->setSelectionBehavior(QAbstractItemView::SelectRows);//设置选中模式为选中行 + table->setSelectionMode ( QAbstractItemView::SingleSelection); //设置选择模式,选择单行 + table->setAlternatingRowColors(true); + table->setEditTriggers(QAbstractItemView::NoEditTriggers);//不能编辑 + table->setMouseTracking(true); + table->setFocus(); + table->setFocusPolicy(Qt::StrongFocus); + table->setStyleSheet("QTableWidget::item:selected { background-color: rgb(85, 255, 127); color: rgb(255, 255, 255); } "); + + table->setColumnWidth(0,200); //设置第1列的列宽(group) + table->setColumnWidth(1,200); //设置第2列的列宽(par1) + table->setColumnWidth(2,150); //设置第3列的列宽(par2) + table->setColumnWidth(3,150); //设置第4列的列宽(lat) + table->setColumnWidth(4,150); //设置第5列的列宽(lng) + + + table->setHorizontalHeaderLabels(QStringList() <verticalHeader(); + V_headerView->setHidden(true); //行名隐藏 + + QHeaderView* H_headerView = table->horizontalHeader(); + H_headerView->setDefaultAlignment(Qt::AlignLeft); //表头信息显示居中靠左 + H_headerView->setHighlightSections(false); //不高亮选中内容的所在列标题 + H_headerView->setStretchLastSection(true); + + + connect(table,&QTableWidget::itemSelectionChanged, + this,&MissionUI::itemSelectionChanged); + + connect(table,&QTableWidget::itemDoubleClicked, + this,&MissionUI::itemDoubleClicked); + + connect(table,&QTableWidget::itemClicked, + this,&MissionUI::itemClicked); } else { diff --git a/App/mainwindow.cpp b/App/mainwindow.cpp index dbedb05..eb1b8f6 100644 --- a/App/mainwindow.cpp +++ b/App/mainwindow.cpp @@ -463,7 +463,8 @@ MainWindow::MainWindow(QWidget *parent) connect(commandUI,SIGNAL(SetCurrentPoint(int)), dlink->mavlinknode->Mission,SLOT(SetCurrentPoint(int)),Qt::DirectConnection); - + connect(commandUI,SIGNAL(getAllPoint(int)), + map,SLOT(find_PointNumber(int))); connect(dlink->mavlinknode->Mission,SIGNAL(currentPoint(int)), diff --git a/opmap/MAP_zh_CN.ts b/opmap/MAP_zh_CN.ts index e04b4c6..6be83b8 100644 --- a/opmap/MAP_zh_CN.ts +++ b/opmap/MAP_zh_CN.ts @@ -83,17 +83,27 @@ Please first select the area of the map to rip with <CTRL>+Left mouse clic - + 开始上传航点,总数%1 - + 上传失败%1 - + + polygons + + + + + circles + + + + recieve way point group:%1 seq:%2 收到航点:第%1组,第%2点 @@ -119,86 +129,89 @@ Please first select the area of the map to rip with <CTRL>+Left mouse clic mapcontrol::WayPointItem - waypoint - 航点 + 航点 - + return 返航 - + landing 降落 - + takeoff 起飞 - + unknow 未知类型 - + hold 保持 - + cas 表速 - + Vz 快升 - + onAB 开加力 - + offAB 关加力 - + unknow 未知指令 - + - + + + + + Speed: %1m/s 速度:%1m/s - + Height: %1m %2 高度:%1m diff --git a/opmap/mapwidget/geoFencecircle.cpp b/opmap/mapwidget/geoFencecircle.cpp new file mode 100644 index 0000000..07228ed --- /dev/null +++ b/opmap/mapwidget/geoFencecircle.cpp @@ -0,0 +1,100 @@ +#include "geoFencecircle.h" +#include +namespace mapcontrol { +geoFencecircle::geoFencecircle(int g, int count, int index, bool inclusion, geoFenceitem *center, double radius, QBrush color, MapGraphicItem *map, bool dashed, int width) : + QGraphicsEllipseItem(map),m_center(center), coord(center->coord), m_brush(color), m_map(map),dashed(dashed),lineWidth(width) +{ + + this->setZValue(3); + + m_inclusion = inclusion; + m_radius = radius; + m_group = g; //2 + m_latitude = coord.Lat();//5 + m_longitide = coord.Lng();//6 + + + connect(center, SIGNAL(localPositionChanged(QPointF, geoFenceitem *)), this, SLOT(refreshLocations())); + connect(center, SIGNAL(aboutToBeDeleted(geoFenceitem *)), this, SLOT(waypointdeleted())); + refreshLocations(); + connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal))); +} + + +int geoFencecircle::type() const +{ + return Type; +} + +void geoFencecircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + painter->setOpacity(0.4); + + QPointF p1; + QPointF p2; + p1 = QPointF(line.p1().x(), line.p1().y() + line.length()); + p2 = QPointF(line.p1().x(), line.p1().y() - line.length()); + QPen myPen = painter->pen(); + myPen.setWidth(lineWidth); + myPen.setColor(m_brush.color()); + painter->setPen(myPen); + + + if (dashed) { + QVector dashes; + dashes << 4 << 8; + myPen.setDashPattern(dashes); + } + + + painter->translate(-line.length(), -line.length()); + + + if(m_inclusion) + { + painter->setBrush(m_brush); + } + else + { + painter->setBrush(Qt::NoBrush); + } + + + painter->drawEllipse(this->rect()); +} + +void geoFencecircle::refreshLocations() +{ + + //qDebug() << my_center->pos(); + + internals::PointLatLng C; + C = m_map->FromLocalToLatLng(m_center->x(),m_center->y()); + C.SetLat(C.Lat() + m_radius/111133.3333f); + + + + line = QLineF(m_center->pos().x(),m_center->pos().y(),m_center->pos().x(),m_map->FromLatLngToLocal(C).Y()); + this->setRect(m_center->pos().x(), m_center->pos().y(), 2 * line.length(), 2 * line.length()); + this->update(); +} + +void geoFencecircle::waypointdeleted() +{ + this->deleteLater(); +} + +void geoFencecircle::setOpacitySlot(qreal opacity) +{ + setOpacity(opacity); +} + + + +} + + + diff --git a/opmap/mapwidget/geoFencecircle.h b/opmap/mapwidget/geoFencecircle.h new file mode 100644 index 0000000..48fdfb1 --- /dev/null +++ b/opmap/mapwidget/geoFencecircle.h @@ -0,0 +1,56 @@ +#ifndef GEOFENCECIRCLE_H +#define GEOFENCECIRCLE_H + +#include +#include +#include +#include "pointlatlng.h" +#include +#include "mapgraphicitem.h" +#include "geoFenceitem.h" + +namespace mapcontrol { + +#ifdef QtopmapWidget +#include +class OPMAPWIDGETSHARED_EXPORT geoFencecircle : public QObject, public QGraphicsEllipseItem { +#else +class geoFencecircle : public QObject, public QGraphicsEllipseItem { +#endif + + Q_OBJECT Q_INTERFACES(QGraphicsItem) +public: + enum { Type = UserType + 11 }; + geoFencecircle(int g, int count, int index, bool inclusion, geoFenceitem *center, double radius, QBrush color, MapGraphicItem *map, bool dashed = false, int width = 3); + + int type() const; + internals::PointLatLng coord; + int number; +private: + QBrush m_brush; + MapGraphicItem *m_map; + + bool m_inclusion = true; + qreal m_radius = 0;//1 + int m_group = 0; //2 + qreal m_latitude = 0;//5 + qreal m_longitide = 0;//6 + + QLineF line; + + geoFenceitem *m_center; + + + bool dashed; + int lineWidth; + +protected: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); +public slots: + void refreshLocations(); + void waypointdeleted(); + void setOpacitySlot(qreal opacity); + +}; +} +#endif // GEOFENCECIRCLE_H diff --git a/opmap/mapwidget/geoFenceitem.cpp b/opmap/mapwidget/geoFenceitem.cpp index 3acfd8c..64d4377 100644 --- a/opmap/mapwidget/geoFenceitem.cpp +++ b/opmap/mapwidget/geoFenceitem.cpp @@ -1,15 +1,20 @@ #include "geoFenceitem.h" #include namespace mapcontrol { -geoFenceitem::geoFenceitem(int index, internals::PointLatLng const & coord, int const & altitude, QBrush color, MapGraphicItem *map) : QGraphicsItem(map), number(index) , coord(coord), m_brush(color), m_map(map) +geoFenceitem::geoFenceitem(int g, int count, int index, bool inclusion, internals::PointLatLng const & coord, QBrush color, MapGraphicItem *map, bool dashed, int width) : + QGraphicsPolygonItem(map), number(index) , coord(coord), m_brush(color), m_map(map), dashed(dashed), lineWidth(width) { - //qDebug() << "geoFenceitem:" << index << coord.Lat() << coord.Lng(); - this->setZValue(3); - connect(map, SIGNAL(childRefreshPosition()), this, SLOT(RefreshPos())); - //qDebug() << this->pos(); + + m_inclusion = inclusion; + m_Vertex = count;//1 + m_group = g; //2 + m_latitude = coord.Lat();//5 + m_longitide = coord.Lng();//6 + + RefreshPos(); } @@ -18,12 +23,50 @@ void geoFenceitem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti Q_UNUSED(option); Q_UNUSED(widget); - painter->setBrush(m_brush); - painter->drawPoint(0,0); -} -QRectF geoFenceitem::boundingRect() const -{ - return QRectF(-2, -2, 4, 4); + painter->setOpacity(0.4); + + QPen myPen = painter->pen(); + myPen.setWidth(lineWidth); + myPen.setColor(m_brush.color()); + painter->setPen(myPen); + + + if (dashed) { + QVector dashes; + dashes << 4 << 8; + myPen.setDashPattern(dashes); + } + + if(m_inclusion) + { + painter->setBrush(m_brush); + } + else + { + painter->setBrush(Qt::NoBrush); + } + + painter->drawPoint(0, 0); + +/* + QPolygonF polygon; + for(internals::PointLatLng p:points) + { + QPointF pf; + pf.setX(m_map->FromLatLngToLocal(p).X()); + pf.setY(m_map->FromLatLngToLocal(p).Y()); + polygon.push_back(pf); + } + */ + + + + painter->drawPolygon(polygon()); + + + qDebug() << polygon(); + + } int geoFenceitem::type() const @@ -35,6 +78,19 @@ void geoFenceitem::setPosSLOT() { //qDebug() << "virtual set pos"; + QPolygonF polygon; + for(internals::PointLatLng LatLng:points) + { + QPointF pf; + pf.setX(m_map->FromLatLngToLocal(LatLng).X() - m_map->FromLatLngToLocal(this->coord).X()); + pf.setY(m_map->FromLatLngToLocal(LatLng).Y() - m_map->FromLatLngToLocal(this->coord).Y()); + + polygon.append(pf); + } + setPolygon(polygon); + + + setPos(m_map->FromLatLngToLocal(this->coord).X(), m_map->FromLatLngToLocal(this->coord).Y()); emit localPositionChanged(this->pos(),this); } @@ -44,6 +100,29 @@ void geoFenceitem::RefreshPos() setPosSLOT(); } +void geoFenceitem::setPoints(QList p) +{ + points = p; + + //QPolygonF polygon; + /* + m_polygon.clear(); + for(internals::PointLatLng LatLng:points) + { + QPointF pf; + pf.setX(m_map->FromLatLngToLocal(LatLng).X()); + pf.setY(m_map->FromLatLngToLocal(LatLng).Y()); + + m_polygon.append(pf); + } + setPolygon(m_polygon); + + qDebug() << m_polygon; + */ + + update(); +} + } diff --git a/opmap/mapwidget/geoFenceitem.h b/opmap/mapwidget/geoFenceitem.h index e46530c..520e6b2 100644 --- a/opmap/mapwidget/geoFenceitem.h +++ b/opmap/mapwidget/geoFenceitem.h @@ -12,24 +12,41 @@ namespace mapcontrol { #ifdef QtopmapWidget #include -class OPMAPWIDGETSHARED_EXPORT geoFenceitem : public QObject, public QGraphicsItem { +class OPMAPWIDGETSHARED_EXPORT geoFenceitem : public QObject, public QGraphicsPolygonItem { #else -class geoFenceitem : public QObject, public QGraphicsItem { +class geoFenceitem : public QObject, public QGraphicsPolygonItem { #endif Q_OBJECT Q_INTERFACES(QGraphicsItem) public: - enum { Type = UserType + 11 }; - geoFenceitem(int index,internals::PointLatLng const & coord, int const & altitude, QBrush color, MapGraphicItem *map); + enum { Type = UserType + 5 }; + geoFenceitem(int g,int count,int index, bool inclusion,internals::PointLatLng const & coord, QBrush color, MapGraphicItem *map, bool dashed = false, int width = 3); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget); - QRectF boundingRect() const; int type() const; internals::PointLatLng coord; int number; + + + QList points; + + void setPoints(QList p); + private: QBrush m_brush; MapGraphicItem *m_map; + + bool m_inclusion = true; + qreal m_Vertex = 0;//1 + int m_group = 0; //2 + qreal m_latitude = 0;//5 + qreal m_longitide = 0;//6 + + bool dashed; + int lineWidth; + + QPolygonF m_polygon; + public slots: void setPosSLOT(); diff --git a/opmap/mapwidget/geoFenceitemline.cpp b/opmap/mapwidget/geoFenceitemline.cpp index beee48e..19a916a 100644 --- a/opmap/mapwidget/geoFenceitemline.cpp +++ b/opmap/mapwidget/geoFenceitemline.cpp @@ -15,12 +15,6 @@ geoFenceitemline::geoFenceitemline(geoFenceitem *from, geoFenceitem *to, MapGrap connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal))); isEdit = true; - - //qDebug() << "virtual line create"; - - //qDebug() << this->pos(); - - lineWidth = 5; } @@ -41,47 +35,22 @@ void geoFenceitemline::paint(QPainter *painter, const QStyleOptionGraphicsItem * Q_UNUSED(option); Q_UNUSED(widget); - //qDebug() << "virtual line update"; - QPen myPen = pen(); - - myPen.setColor(myColor); - - - - //qreal arrowSize = 10; painter->setPen(myPen); - /* - if(isEdit == false) - { - painter->setBrush(myColor); - } - */ double angle = ::acos(line().dx() / line().length()); if (line().dy() >= 0) { angle = (M_PI * 2) - angle; } - /* - 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); - */ - if (dashed) { QVector dashes; dashes << 4 << 8; myPen.setDashPattern(dashes); } - myPen.setWidth(lineWidth); painter->setPen(myPen); diff --git a/opmap/mapwidget/geoFenceitemline.h b/opmap/mapwidget/geoFenceitemline.h index 4176a6b..160defe 100644 --- a/opmap/mapwidget/geoFenceitemline.h +++ b/opmap/mapwidget/geoFenceitemline.h @@ -26,7 +26,7 @@ class geoFenceitemline : public QObject, public QGraphicsLineItem { Q_OBJECT Q_INTERFACES(QGraphicsItem) public: enum { Type = UserType + 12 }; - geoFenceitemline(geoFenceitem *from, geoFenceitem *to, MapGraphicItem *map, QColor color = Qt::green, bool dashed = false, int width = 2); + geoFenceitemline(geoFenceitem *from, geoFenceitem *to, MapGraphicItem *map, QColor color = Qt::green, bool dashed = false, int width = 3); int type() const; QPainterPath shape() const; void setColor(const QColor &color) diff --git a/opmap/mapwidget/mapwidget.pro b/opmap/mapwidget/mapwidget.pro index f1b99f4..83ce541 100644 --- a/opmap/mapwidget/mapwidget.pro +++ b/opmap/mapwidget/mapwidget.pro @@ -51,6 +51,7 @@ SOURCES += $$PWD/mapgraphicitem.cpp \ $$PWD/AltitudeItem.cpp \ $$PWD/waypointbutton.cpp \ $$PWD/waypointsetting.cpp \ + geoFencecircle.cpp \ geoFenceitem.cpp \ geoFenceitemline.cpp \ measureline.cpp @@ -74,6 +75,7 @@ HEADERS += $$PWD/mapgraphicitem.h \ $$PWD/AltitudeItem.h \ $$PWD/waypointbutton.h \ $$PWD/waypointsetting.h \ + geoFencecircle.h \ geoFenceitem.h \ geoFenceitemline.h \ measureline.h diff --git a/opmap/mapwidget/opmapwidget.cpp b/opmap/mapwidget/opmapwidget.cpp index f8f6b1d..2d2f9b1 100644 --- a/opmap/mapwidget/opmapwidget.cpp +++ b/opmap/mapwidget/opmapwidget.cpp @@ -242,6 +242,177 @@ void OPMapWidget::table_clicked(void) } */ } +/* +void OPMapWidget::AddgeoPolygon(int type,int index,double lat,double lng,double alt,QColor color) +{ + qDebug() << "AddVirtualMargin" << type << index; + + internals::PointLatLng LatLng; + LatLng.SetLat(lat); + LatLng.SetLng(lng); + + QMap virtualmarginmap = VirtualMarginPoints.value(type); + QMap virtualmarginlinemap = VirtualMarginlinemapLines.value(type); + + + VirtualMargin *vm = new VirtualMargin(index,LatLng,alt,color,map); + virtualmarginmap.insert(index,vm); + + foreach (VirtualMarginLine *l, virtualmarginlinemap) { + if(l){ + disconnect(l,nullptr,nullptr,nullptr); + delete l; + } + } + + virtualmarginlinemap.clear(); + + + for(QMap::iterator i = virtualmarginmap.begin();i != virtualmarginmap.end();++i) + { + VirtualMargin *v = i.value(); + if(v) + { + if(v->number > 0) + { + VirtualMarginLine *l = new VirtualMarginLine(virtualmarginmap.value(v->number - 1),v,map,color); + l->setOpacity(overlayOpacity); + l->show(); + + virtualmarginlinemap.insert(virtualmarginlinemap.size(),l); + } + } + } + + if(virtualmarginmap.size() >= 2) + { + VirtualMargin *vm_first = virtualmarginmap.first(); + VirtualMargin *vm_last = virtualmarginmap.last(); + + if((vm_first)&&(vm_last)) + { + VirtualMarginLine *l = new VirtualMarginLine(vm_first,vm_last,map,color); + l->setOpacity(overlayOpacity); + l->show(); + + virtualmarginlinemap.insert(virtualmarginlinemap.size(),l); + } + } + + VirtualMarginPoints.insert(type,virtualmarginmap); + VirtualMarginlinemapLines.insert(type,virtualmarginlinemap); + + //FlushVirtualMargin(type); + + + foreach (VirtualMargin *v, virtualmarginmap) { + qDebug() << "create a virtual point" << v->number; + } + +} + +void OPMapWidget::ClosegeoPolygon(int type) +{ + if(type == 0) + { + if(virtualmarginmap_red.size() >= 2) + { + VirtualMargin *vm_first = virtualmarginmap_red.first(); + VirtualMargin *vm_last = virtualmarginmap_red.last(); + + if((vm_first)&&(vm_last)) + { + VirtualMarginLine *l = new VirtualMarginLine(vm_first,vm_last,map,WarningColor); + l->setOpacity(overlayOpacity); + l->show(); + + virtualmarginlinemap_red.insert(virtualmarginlinemap_red.size(),l); + } + } + } + else if(type == 1) + { + if(virtualmarginmap_orange.size() >= 2) + { + VirtualMargin *vm_first = virtualmarginmap_orange.first(); + VirtualMargin *vm_last = virtualmarginmap_orange.last(); + + if((vm_first)&&(vm_last)) + { + VirtualMarginLine *l = new VirtualMarginLine(vm_first,vm_last,map,NoticeColor); + l->setOpacity(overlayOpacity); + l->show(); + + virtualmarginlinemap_orange.insert(virtualmarginlinemap_orange.size(),l); + } + } + } + +} + +void OPMapWidget::RemovegeoPolygon(int type) +{ + + QMap virtualmarginmap = VirtualMarginPoints.value(type); + QMap virtualmarginlinemap = VirtualMarginlinemapLines.value(type); + + //移除虚拟边界 + foreach (VirtualMargin *vm, virtualmarginmap) { + if(vm) + { + qDebug() << "del vm" << vm->number << vm->coord.Lat() << vm->coord.Lng(); + disconnect(vm,nullptr,nullptr,nullptr); + delete vm; + } + } + //从列表删除所有 + virtualmarginmap.clear(); + + //移除虚拟边界 + foreach (VirtualMarginLine *l, virtualmarginlinemap) { + if(l) + { + disconnect(l,nullptr,nullptr,nullptr); + delete l; + } + } + //从列表删除所有 + virtualmarginlinemap.clear(); + + VirtualMarginPoints.remove(type); + VirtualMarginlinemapLines.remove(type); + +} + +void OPMapWidget::FlushgeoPolygon(int type) +{ + + + + if(type == 0) + { + for(QMap::iterator i = virtualmarginmap_red.begin();i != virtualmarginmap_red.end();++i) + { + VirtualMargin *vm = i.value(); + if(vm) + { + qDebug() << "vm" << vm->number << vm->coord.Lat() << vm->coord.Lng(); + } + } + } + else if(type == 1) + { + for(QMap::iterator i = virtualmarginmap_orange.begin();i != virtualmarginmap_orange.end();++i) + { + VirtualMargin *vm = i.value(); + if(vm) + { + qDebug() << "vm" << vm->number << vm->coord.Lat() << vm->coord.Lng(); + } + } + } +} +*/ @@ -819,6 +990,10 @@ void OPMapWidget::mouseDoubleClickEvent(QMouseEvent *event) } } } + + + + } } emit MouseDoubleClickEvent(event); @@ -1337,9 +1512,11 @@ void OPMapWidget::ConnectWP(WayPointItem *item) item, SLOT(setWPProperty(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(item, 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)), - this, SLOT(find_PointNumber()),Qt::DirectConnection); + this, SLOT(find_PointNumber(int)),Qt::DirectConnection); + */ + /* connect(item, SIGNAL(WPFollowPrevious(bool,WayPointItem*)), @@ -1877,46 +2054,13 @@ void OPMapWidget::WPLoad(QString path)//带文件目录参数 QJsonObject json = doc.object(); - - /* -"circles": [ - { - "circle": { - "center": [ - 32.04290131170435, - 118.81779757301473 - ], - "radius": 104.72920614551222 - }, - "inclusion": true, - "version": 1 - }, - { - "circle": { - "center": [ - 32.04275580264579, - 118.8194498137916 - ], - "radius": 91.2720266761384 - }, - "inclusion": true, - "version": 1 - } - ], - - - - - */ - - - - //安全区解码 + //栅栏解码 QJsonArray circlesArray = json.value("geoFence").toObject().value("circles").toArray(); for(QJsonValue item: circlesArray) { - bool inclusion = item.toObject().value("inclusion").toBool(); + bool inclusion = item.toObject().value("inclusion").toBool(); QJsonObject circle = item.toObject().value("circle").toObject(); + int version = item.toObject().value("version").toInt(); QJsonArray center = circle.value("center").toArray(); @@ -1924,26 +2068,94 @@ void OPMapWidget::WPLoad(QString path)//带文件目录参数 qreal lng = center.at(1).toDouble(); qreal radius = circle.value("radius").toDouble(); - int version = item.toObject().value("version").toInt(); - qDebug() << "circle" << inclusion << lat << lng << radius << version; + //生成一个⚪ + + + geoFenceitem *centeritem = new geoFenceitem(0,1,1, inclusion ,internals::PointLatLng(lat,lng),QColor("#FF8000"),map); + + geoFencecircle *c = new geoFencecircle(0,1,1,inclusion,centeritem,radius,QColor("#FF8000"),map); + } QJsonArray polygonsArray = json.value("geoFence").toObject().value("polygons").toArray(); for(QJsonValue item: polygonsArray) { + + //每个item是一个组 + QList points; + QList polyitems; //获得边界 bool inclusion = item.toObject().value("inclusion").toBool(); QJsonArray polygon = item.toObject().value("polygon").toArray(); + int version = item.toObject().value("version").toInt(); + + qreal lat_sum = 0; + qreal lng_sum = 0; for (QJsonValue point: polygon) { qreal lat = point.toArray().at(0).toDouble(); qreal lng = point.toArray().at(1).toDouble(); + + //生成一个多边形 + points.push_back(internals::PointLatLng(lat,lng)); + + qDebug() << "polygon" << inclusion << version << lat << lng; + + + lat_sum += lat; + lng_sum += lng; + } - int version = item.toObject().value("version").toInt(); + internals::PointLatLng center; + + center.SetLat(lat_sum/polygon.size()); + center.SetLng(lng_sum/polygon.size()); + + geoFenceitem *polyitem = new geoFenceitem(0,points.size(),0, inclusion ,center,QColor("#FF8000"),map); + + polyitem->setPoints(points); + + + /* + + int count = 0; + for(internals::PointLatLng p : points) + { + geoFenceitem *polyitem = new geoFenceitem(0,points.size(),count, inclusion ,p,QColor("#FF8000"),map); + count ++; + polyitems.push_back(polyitem); + + } + + geoFenceitem *last; + + for(geoFenceitem *p : polyitems) + { + if(p == polyitems.first()) + { + last = p; + } + else + { + if(p == polyitems.last()) + { + geoFenceitemline *polyline = new geoFenceitemline(last, polyitems.first(),map,QColor("#FF8000")); + } + else + { + geoFenceitemline *polyline = new geoFenceitemline(last, p,map,QColor("#FF8000")); + last = p; + } + } + + + + + } + */ - qDebug() << "polygon" << inclusion << version << item.toObject(); } @@ -2241,9 +2453,6 @@ void OPMapWidget::groupchanged(int value) return; } - //一下这里判断有问题,有bug - - //将不是当前的全部变成灰色,当前的显示 foreach(QGraphicsItem * i, map->childItems()) { WayPointItem *w = qgraphicsitem_cast(i); @@ -2400,6 +2609,8 @@ void OPMapWidget::WPGroup(int value) emit settableGroup(currentGroup); + find_PointNumber(currentGroup); + update(); } @@ -2645,7 +2856,7 @@ void OPMapWidget::updateMessage(void) emit TotalDistanceUpdate(totalDistance); } -void OPMapWidget::find_PointNumber() +void OPMapWidget::find_PointNumber(int group) { QList nums; nums.clear(); @@ -2656,12 +2867,14 @@ void OPMapWidget::find_PointNumber() WayPointItem *w = qgraphicsitem_cast(i); if (w) { - - number = w->Number(); - - if(w->Command() < MAV_CMD::MAV_CMD_NAV_LAST) + if(w->MissionType() == group)//如果组别一样,那么就赋值 { - nums.append(number); + number = w->Number(); + + if(w->Command() < MAV_CMD::MAV_CMD_NAV_LAST) + { + nums.append(number); + } } } } diff --git a/opmap/mapwidget/opmapwidget.h b/opmap/mapwidget/opmapwidget.h index 4e54be6..8543b43 100644 --- a/opmap/mapwidget/opmapwidget.h +++ b/opmap/mapwidget/opmapwidget.h @@ -62,6 +62,11 @@ #include "measureline.h" +#include "geoFencecircle.h" +#include "geoFenceitem.h" +#include "geoFenceitemline.h" + + namespace mapcontrol { @@ -647,7 +652,7 @@ public slots: void groupchanged(int value); - void find_PointNumber(); + void find_PointNumber(int group); void updateMessage(void);