添加了围栏的删除功能
This commit is contained in:
@@ -66,10 +66,22 @@ void geoFencecircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
||||
painter->setBrush(m_brush);
|
||||
}
|
||||
|
||||
|
||||
|
||||
painter->drawPoint(0, 0);
|
||||
//painter->drawEllipse(QPointF(0,0),line.length(),line.length());
|
||||
painter->drawEllipse(rectangle);
|
||||
|
||||
QFont font;
|
||||
font.setWeight(QFont::ExtraBold);
|
||||
font.setFamily("Arial");//非衬线
|
||||
font.setPixelSize(40);
|
||||
painter->setFont(font);
|
||||
|
||||
myPen.setWidth(lineWidth);
|
||||
myPen.setColor(QColor("#FFFFFF"));
|
||||
painter->setPen(myPen);
|
||||
painter->drawText(rectangle,Qt::AlignCenter,QString::number(m_group));
|
||||
|
||||
}
|
||||
|
||||
void geoFencecircle::refreshLocations()
|
||||
|
||||
@@ -52,6 +52,19 @@ void geoFenceitem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
|
||||
painter->drawPoint(0, 0);
|
||||
painter->drawPolygon(polygon());
|
||||
|
||||
|
||||
QFont font;
|
||||
font.setWeight(QFont::ExtraBold);
|
||||
font.setFamily("Arial");//非衬线
|
||||
font.setPixelSize(40);
|
||||
painter->setFont(font);
|
||||
|
||||
myPen.setWidth(lineWidth);
|
||||
myPen.setColor(QColor("#FFFFFF"));
|
||||
painter->setPen(myPen);
|
||||
painter->drawText(boundingRect(),Qt::AlignCenter,QString::number(m_group));
|
||||
|
||||
}
|
||||
|
||||
int geoFenceitem::type() const
|
||||
|
||||
@@ -30,6 +30,11 @@ public:
|
||||
QList<internals::PointLatLng> points;
|
||||
|
||||
void setPoints(QList<internals::PointLatLng> p);
|
||||
QList<internals::PointLatLng> Points(void)
|
||||
{
|
||||
return points;
|
||||
}
|
||||
|
||||
|
||||
int Group(void)
|
||||
{
|
||||
|
||||
+227
-37
@@ -1447,6 +1447,26 @@ void OPMapWidget::WPDeleteAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(currentGroup == 1)
|
||||
{
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFencecircle *w = qgraphicsitem_cast<geoFencecircle *>(i);
|
||||
if (w) {
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFenceitem *w = qgraphicsitem_cast<geoFenceitem *>(i);
|
||||
if (w) {
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
bool OPMapWidget::WPPresent()
|
||||
{
|
||||
@@ -1529,9 +1549,6 @@ void OPMapWidget::ConnectWP(WayPointItem *item)
|
||||
connect(item,SIGNAL(SetCurrent(int)),
|
||||
this,SIGNAL(setCurrent(int)), Qt::DirectConnection);
|
||||
|
||||
|
||||
|
||||
|
||||
connect(item,SIGNAL(ElevationChanged(int,double)),
|
||||
this,SLOT(ElevationChanged(int,double)), Qt::DirectConnection);
|
||||
|
||||
@@ -1786,9 +1803,6 @@ void OPMapWidget::WPSetCurrent(int seq)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void OPMapWidget::WPsearchall(void)
|
||||
{
|
||||
//重新排序一下
|
||||
@@ -2062,12 +2076,96 @@ void OPMapWidget::setFencePolygon(int group,qreal vertex,bool inclusion,QList<QP
|
||||
}
|
||||
}
|
||||
|
||||
void OPMapWidget::addCircle()
|
||||
{
|
||||
bool inclusion = true;
|
||||
int version = 1;
|
||||
|
||||
internals::PointLatLng center = GetFromLocalToLatLng(QPointF(this->pos().x() + this->width()/2,this->pos().y() + this->height()/2));
|
||||
|
||||
qreal lat = center.Lat();
|
||||
qreal lng = center.Lng();
|
||||
qreal radius = 10000;
|
||||
|
||||
//生成一个⚪
|
||||
geoFencecircle *c = new geoFencecircle(fenceCount,inclusion,version,internals::PointLatLng(lat,lng),radius,QColor("#FF8000"),map);
|
||||
emit createFenceCircle(fenceCount++,radius,inclusion,lat,lng);
|
||||
}
|
||||
|
||||
void OPMapWidget::addPolygon()
|
||||
{
|
||||
|
||||
//找到地图中心,做4个点
|
||||
bool inclusion = true;
|
||||
int version = 1;
|
||||
|
||||
internals::PointLatLng center = GetFromLocalToLatLng(QPointF(this->pos().x() + this->width()/2,this->pos().y() + this->height()/2));
|
||||
|
||||
QList<QPointF> latlng;
|
||||
QList<internals::PointLatLng> points;
|
||||
latlng.clear();
|
||||
points.clear();
|
||||
|
||||
|
||||
|
||||
qreal lat = center.Lat();
|
||||
qreal lng = center.Lng();
|
||||
|
||||
//生成一个多边形
|
||||
points.push_back(internals::PointLatLng(lat + 0.2,lng - 0.2));
|
||||
points.push_back(internals::PointLatLng(lat + 0.2,lng + 0.2));
|
||||
points.push_back(internals::PointLatLng(lat - 0.2,lng + 0.2));
|
||||
points.push_back(internals::PointLatLng(lat - 0.2,lng - 0.2));
|
||||
|
||||
latlng.push_back(QPointF(points.value(0).Lat(),points.value(0).Lng()));
|
||||
latlng.push_back(QPointF(points.value(1).Lat(),points.value(1).Lng()));
|
||||
latlng.push_back(QPointF(points.value(2).Lat(),points.value(2).Lng()));
|
||||
latlng.push_back(QPointF(points.value(3).Lat(),points.value(3).Lng()));
|
||||
|
||||
|
||||
|
||||
geoFenceitem *polyitem = new geoFenceitem(fenceCount,inclusion,version,center,QColor("#FF8000"),map);
|
||||
|
||||
polyitem->setPoints(points);
|
||||
|
||||
emit createFencePolygon(fenceCount++,latlng.size(),inclusion,latlng);
|
||||
|
||||
}
|
||||
|
||||
void OPMapWidget::delFence(int group)
|
||||
{
|
||||
//找出编号为group的栅栏,删除
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFenceitem *w = qgraphicsitem_cast<geoFenceitem *>(i);
|
||||
if (w) {
|
||||
|
||||
if(w->Group() == group)
|
||||
{
|
||||
w->deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFencecircle *w = qgraphicsitem_cast<geoFencecircle *>(i);
|
||||
if (w) {
|
||||
if(w->Group() == group)
|
||||
{
|
||||
w->deleteLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//先清除再读取
|
||||
void OPMapWidget::WPLoad(QString path)//带文件目录参数
|
||||
{
|
||||
//清除所有
|
||||
WPDeleteAll();//清除当前航线
|
||||
//fenceCount = 0;
|
||||
qDebug() << "WPLoad" << path;
|
||||
//读取
|
||||
QFile jsonFile(path);
|
||||
@@ -2089,27 +2187,6 @@ void OPMapWidget::WPLoad(QString path)//带文件目录参数
|
||||
QJsonObject json = doc.object();
|
||||
|
||||
//栅栏解码
|
||||
int fenceCount = 0;
|
||||
QJsonArray circlesArray = json.value("geoFence").toObject().value("circles").toArray();
|
||||
for(QJsonValue item: circlesArray) {
|
||||
|
||||
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();
|
||||
|
||||
qreal lat = center.at(0).toDouble();
|
||||
qreal lng = center.at(1).toDouble();
|
||||
qreal radius = circle.value("radius").toDouble();
|
||||
|
||||
|
||||
//生成一个⚪
|
||||
geoFencecircle *c = new geoFencecircle(fenceCount,inclusion,version,internals::PointLatLng(lat,lng),radius,QColor("#FF8000"),map);
|
||||
emit createFenceCircle(fenceCount++,radius,inclusion,lat,lng);
|
||||
|
||||
}
|
||||
|
||||
QJsonArray polygonsArray = json.value("geoFence").toObject().value("polygons").toArray();
|
||||
for(QJsonValue item: polygonsArray) {
|
||||
|
||||
@@ -2151,6 +2228,26 @@ void OPMapWidget::WPLoad(QString path)//带文件目录参数
|
||||
emit createFencePolygon(fenceCount++,points.size(),inclusion,latlng);
|
||||
}
|
||||
|
||||
QJsonArray circlesArray = json.value("geoFence").toObject().value("circles").toArray();
|
||||
for(QJsonValue item: circlesArray) {
|
||||
|
||||
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();
|
||||
|
||||
qreal lat = center.at(0).toDouble();
|
||||
qreal lng = center.at(1).toDouble();
|
||||
qreal radius = circle.value("radius").toDouble();
|
||||
|
||||
|
||||
//生成一个⚪
|
||||
geoFencecircle *c = new geoFencecircle(fenceCount,inclusion,version,internals::PointLatLng(lat,lng),radius,QColor("#FF8000"),map);
|
||||
emit createFenceCircle(fenceCount++,radius,inclusion,lat,lng);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//任务解码
|
||||
@@ -2362,6 +2459,11 @@ void OPMapWidget::WPDownload(void)
|
||||
|
||||
WPDeleteAll();
|
||||
|
||||
if(currentGroup == 1)
|
||||
{
|
||||
//fenceCount = 0;
|
||||
}
|
||||
|
||||
int sysid = 0;
|
||||
int compid = 0;
|
||||
|
||||
@@ -2383,7 +2485,98 @@ void OPMapWidget::WPUpload(void)
|
||||
{
|
||||
if(currentGroup == 1)//这是栅栏
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int FecneSeq = 0;
|
||||
|
||||
//查找所有的子类
|
||||
bool FenceItemExit = false;
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFenceitem *w = qgraphicsitem_cast<geoFenceitem *>(i);
|
||||
if (w) {
|
||||
FenceItemExit = true;
|
||||
|
||||
QList<internals::PointLatLng> latlng = w->Points();
|
||||
bool inclusion = w->Inclusion();
|
||||
qreal Vertex = w->Vertex();
|
||||
qreal group = w->Group();
|
||||
|
||||
for(internals::PointLatLng p:latlng)
|
||||
{
|
||||
emit sendFence(Vertex,
|
||||
group,
|
||||
p.Lat(),
|
||||
p.Lng(),
|
||||
FecneSeq++,
|
||||
(inclusion)?(MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION):(MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION) ,
|
||||
sysid,
|
||||
compid,
|
||||
1);
|
||||
|
||||
qDebug() << "send fence to thread";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFencecircle *w = qgraphicsitem_cast<geoFencecircle *>(i);
|
||||
if (w) {
|
||||
FenceItemExit = true;
|
||||
|
||||
internals::PointLatLng p = w->coord;
|
||||
bool inclusion = w->Inclusion();
|
||||
qreal Vertex = w->Radius();
|
||||
qreal group = w->Group();
|
||||
|
||||
emit sendFence(Vertex,
|
||||
group,
|
||||
p.Lat(),
|
||||
p.Lng(),
|
||||
FecneSeq++,
|
||||
(inclusion)?(MAV_CMD_NAV_FENCE_CIRCLE_INCLUSION ):(MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION ),
|
||||
sysid,
|
||||
compid,
|
||||
1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(FenceItemExit == false)
|
||||
{
|
||||
emit showMessage("请先载入围栏");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
emit showMessage(tr("开始上传围栏,总数%1").arg(FecneSeq));
|
||||
|
||||
//选择当前ID号
|
||||
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_WPUpload(sysid,compid,FecneSeq,1);//直接发送全部围栏到
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2520,7 +2713,6 @@ void OPMapWidget::groupchanged(int value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2665,7 +2857,7 @@ void OPMapWidget::receivedPoint(float param1,float param2,float param3,float par
|
||||
|
||||
if((mission_type - 2) == -1)
|
||||
{
|
||||
qDebug() << command << param1 << param2 << param3 << param4 << x << y;
|
||||
qDebug() << command << seq << param1 << param2 << param3 << param4 << x << y;
|
||||
|
||||
if(command == MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION )
|
||||
{
|
||||
@@ -2675,10 +2867,8 @@ void OPMapWidget::receivedPoint(float param1,float param2,float param3,float par
|
||||
PolygonCount ++;
|
||||
bool inclusion = true;
|
||||
|
||||
|
||||
PolygonPoints.push_back(internals::PointLatLng(x * 10e-8,y * 10e-8));
|
||||
|
||||
|
||||
if(PolygonCount >= param1)
|
||||
{
|
||||
|
||||
@@ -2701,11 +2891,11 @@ void OPMapWidget::receivedPoint(float param1,float param2,float param3,float par
|
||||
center.SetLat(lat_sum/latlng.size());
|
||||
center.SetLng(lng_sum/latlng.size());
|
||||
|
||||
geoFenceitem *polyitem = new geoFenceitem(PolygonCount,inclusion,0,center,QColor("#FF8000"),map);
|
||||
geoFenceitem *polyitem = new geoFenceitem(fenceCount,inclusion,0,center,QColor("#FF8000"),map);
|
||||
|
||||
polyitem->setPoints(PolygonPoints);
|
||||
|
||||
emit createFencePolygon(PolygonCount,PolygonPoints.size(),inclusion,latlng);
|
||||
emit createFencePolygon(fenceCount++,PolygonPoints.size(),inclusion,latlng);
|
||||
|
||||
PolygonCount = 0;
|
||||
PolygonPoints.clear();
|
||||
@@ -2745,11 +2935,11 @@ void OPMapWidget::receivedPoint(float param1,float param2,float param3,float par
|
||||
center.SetLat(lat_sum/latlng.size());
|
||||
center.SetLng(lng_sum/latlng.size());
|
||||
|
||||
geoFenceitem *polyitem = new geoFenceitem(PolygonCount,inclusion,0,center,QColor("#FF8000"),map);
|
||||
geoFenceitem *polyitem = new geoFenceitem(fenceCount,inclusion,0,center,QColor("#FF8000"),map);
|
||||
|
||||
polyitem->setPoints(PolygonPoints);
|
||||
|
||||
emit createFencePolygon(PolygonCount,PolygonPoints.size(),inclusion,latlng);
|
||||
emit createFencePolygon(fenceCount++,PolygonPoints.size(),inclusion,latlng);
|
||||
|
||||
PolygonCount = 0;
|
||||
PolygonPoints.clear();
|
||||
@@ -2760,7 +2950,7 @@ void OPMapWidget::receivedPoint(float param1,float param2,float param3,float par
|
||||
bool inclusion = true;
|
||||
qreal radius = param1;
|
||||
|
||||
geoFencecircle *c = new geoFencecircle(1,inclusion,0,internals::PointLatLng(x * 10e-8,y * 10e-8),radius,QColor("#FF8000"),map);
|
||||
geoFencecircle *c = new geoFencecircle(fenceCount++,inclusion,0,internals::PointLatLng(x * 10e-8,y * 10e-8),radius,QColor("#FF8000"),map);
|
||||
emit createFenceCircle(0,radius,inclusion,x * 10e-8,y * 10e-8);
|
||||
|
||||
}
|
||||
@@ -2769,7 +2959,7 @@ void OPMapWidget::receivedPoint(float param1,float param2,float param3,float par
|
||||
bool inclusion = false;
|
||||
qreal radius = param1;
|
||||
|
||||
geoFencecircle *c = new geoFencecircle(1,inclusion,0,internals::PointLatLng(x * 10e-8,y * 10e-8),radius,QColor("#FF8000"),map);
|
||||
geoFencecircle *c = new geoFencecircle(fenceCount++,inclusion,0,internals::PointLatLng(x * 10e-8,y * 10e-8),radius,QColor("#FF8000"),map);
|
||||
emit createFenceCircle(0,radius,inclusion,x * 10e-8,y * 10e-8);
|
||||
}
|
||||
else if(command == MAV_CMD_NAV_RALLY_POINT )
|
||||
|
||||
@@ -513,6 +513,7 @@ private:
|
||||
|
||||
bool isShowTip = false;
|
||||
|
||||
int fenceCount = 0;
|
||||
|
||||
private slots:
|
||||
void diagRefresh();
|
||||
@@ -622,6 +623,7 @@ signals:
|
||||
void signal_WPDownload(uint8_t m_sysid, uint8_t m_compid,int missiontype);
|
||||
void signal_WPUpload(uint8_t m_sysid, uint8_t m_compid, uint32_t count,int missiontype);
|
||||
|
||||
void signal_FenceUpload(uint8_t m_sysid, uint8_t m_compid, uint32_t count,int missiontype);
|
||||
|
||||
void transmitPoint(float param1,float param2,float param3,float param4,
|
||||
int32_t x,int32_t y,float z,
|
||||
@@ -649,6 +651,18 @@ signals:
|
||||
void createFenceCircle(int group,qreal radius,bool inclusion,qreal lat,qreal lng);
|
||||
void createFencePolygon(int group,qreal vertex,bool inclusion,QList<QPointF> latlng);
|
||||
|
||||
void sendFence(qreal Vertex,
|
||||
qreal group,
|
||||
qreal Lat,
|
||||
qreal Lng,
|
||||
uint16_t FecneSeq,
|
||||
uint16_t command,
|
||||
uint16_t sysid,
|
||||
uint16_t compid,
|
||||
uint16_t currentGroup);
|
||||
|
||||
|
||||
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -736,6 +750,12 @@ public slots:
|
||||
void setFenceCircle(int group,qreal radius, bool inclusion, qreal lat, qreal lng);
|
||||
void setFencePolygon(int group,qreal vertex,bool inclusion,QList<QPointF> latlng);
|
||||
|
||||
void addCircle();
|
||||
void addPolygon();
|
||||
void delFence(int group);
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
#endif // OPMAPWIDGET_H
|
||||
|
||||
Reference in New Issue
Block a user