修改航线为表格,并且支持csv格式
This commit is contained in:
@@ -99,7 +99,7 @@ MissionUI::MissionUI(QWidget *parent) :
|
||||
QFileDialog *dlg = new QFileDialog();
|
||||
QString fileName = dlg->getOpenFileName(this, tr("Selete Way Point File..."),
|
||||
"./plan/",
|
||||
tr("plan file (*.plan)"));
|
||||
tr("plan file (*.plan);;csv file(*.csv)"));
|
||||
if(!fileName.isEmpty())
|
||||
{
|
||||
emit WPLoad(fileName);
|
||||
@@ -110,7 +110,7 @@ MissionUI::MissionUI(QWidget *parent) :
|
||||
QFileDialog *dlg = new QFileDialog();
|
||||
QString fileName = dlg->getSaveFileName(this, tr("Selete Way Point File..."),
|
||||
"./plan/",
|
||||
tr("plan file (*.plan)"));
|
||||
tr("plan file (*.plan);;csv file(*.csv)"));
|
||||
if(!fileName.isEmpty())
|
||||
{
|
||||
emit WPSave(fileName);
|
||||
@@ -937,6 +937,7 @@ void MissionUI::pointCreate(float param1,float param2,float param3,float param4,
|
||||
|
||||
if(command == 16)
|
||||
{
|
||||
/*
|
||||
QString par1Name;
|
||||
switch ((int)param1) {
|
||||
case 0:
|
||||
@@ -959,6 +960,10 @@ void MissionUI::pointCreate(float param1,float param2,float param3,float param4,
|
||||
}
|
||||
tableWidget->removeCellWidget(idx,2);
|
||||
tableWidget->setItem(idx,2,new QTableWidgetItem(par1Name));
|
||||
*/
|
||||
|
||||
tableWidget->removeCellWidget(idx,2);
|
||||
tableWidget->setItem(idx,2,new QTableWidgetItem(QString::number(param1)));
|
||||
}
|
||||
else if(command == 20)
|
||||
{
|
||||
|
||||
+531
-309
@@ -2228,393 +2228,615 @@ void OPMapWidget::delFence(int group)
|
||||
//先清除再读取
|
||||
void OPMapWidget::WPLoad(QString path)//带文件目录参数
|
||||
{
|
||||
//fenceCount = 0;
|
||||
qDebug() << "WPLoad" << path;
|
||||
//读取
|
||||
QFile jsonFile(path);
|
||||
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "Unable to open file" << path << jsonFile.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray bytes = jsonFile.readAll();
|
||||
QString fileName, filePath,fileSuffix;
|
||||
QFileInfo fileInfo = QFileInfo(path);
|
||||
//文件名
|
||||
fileName = fileInfo.fileName();
|
||||
//文件后缀
|
||||
fileSuffix = fileInfo.suffix();
|
||||
//绝对路径
|
||||
filePath = fileInfo.absolutePath();
|
||||
|
||||
jsonFile.close();
|
||||
QJsonParseError jsonParseError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError);
|
||||
if (jsonParseError.error != QJsonParseError::NoError) {
|
||||
qWarning() << path << "Unable to open json document" << jsonParseError.errorString();
|
||||
return;
|
||||
}
|
||||
//KT16的舵机情况 5ms之后,75% -40℃,80% 25℃,83% 60℃,70N·m;
|
||||
|
||||
QJsonObject json = doc.object();
|
||||
|
||||
if(currentGroup == 1)
|
||||
if(fileSuffix == "csv")
|
||||
{
|
||||
emit showMessage(tr("Load Geo Fence File :%1").arg(path));
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFencecircle *w = qgraphicsitem_cast<geoFencecircle *>(i);
|
||||
if (w) {
|
||||
delete w;
|
||||
}
|
||||
//读取
|
||||
QFile csvFile(path);
|
||||
if (!csvFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "Unable to open file" << path << csvFile.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFenceitem *w = qgraphicsitem_cast<geoFenceitem *>(i);
|
||||
if (w) {
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
QString bytes = csvFile.readAll();
|
||||
|
||||
fenceCount = 1;
|
||||
QStringList infolist = bytes.split('\n');
|
||||
|
||||
//栅栏解码
|
||||
QJsonArray polygonsArray = json.value("geoFence").toObject().value("polygons").toArray();
|
||||
for(QJsonValue item: polygonsArray) {
|
||||
|
||||
//每个item是一个组
|
||||
QList<internals::PointLatLng> points;
|
||||
QList<QPointF> latlng;
|
||||
//获得边界
|
||||
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));
|
||||
|
||||
lat_sum += lat;
|
||||
lng_sum += lng;
|
||||
|
||||
|
||||
latlng.push_back(QPointF(lat,lng));
|
||||
if(infolist.size() > 1)
|
||||
{
|
||||
emit showMessage(tr("Load Mission File:Group %1,%2").arg(QString::number(currentGroup)).arg(path));
|
||||
//清除所有
|
||||
//删除一个组
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
if (w) {
|
||||
if(w->MissionType() == currentGroup)
|
||||
{
|
||||
emit WPDeleted(w->Number(), w);
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internals::PointLatLng center;
|
||||
for (QString info:infolist) {
|
||||
|
||||
center.SetLat(lat_sum/polygon.size());
|
||||
center.SetLng(lng_sum/polygon.size());
|
||||
|
||||
geoFenceitem *polyitem = new geoFenceitem(fenceCount,inclusion,version,center,QColor("#FF8000"),map);
|
||||
|
||||
polyitem->setPoints(points);
|
||||
|
||||
emit createFencePolygon(fenceCount++,points.size(),inclusion,latlng);
|
||||
|
||||
connect(polyitem,SIGNAL(updateFencePolygon(int,qreal,bool,QList<QPointF>)),
|
||||
this,SIGNAL(updateFencePolygon(int,qreal,bool,QList<QPointF>)));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
connect(c,SIGNAL(updateFenceCircle(int,qreal,bool,qreal,qreal)),
|
||||
this,SIGNAL(updateFenceCircle(int,qreal,bool,qreal,qreal)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if(currentGroup >= 3)
|
||||
{
|
||||
|
||||
emit showMessage(tr("Load Mission File:Group %1,%2").arg(QString::number(currentGroup)).arg(path));
|
||||
//清除所有
|
||||
//删除一个组
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
if (w) {
|
||||
if(w->MissionType() == currentGroup)
|
||||
if(info == infolist.first())
|
||||
{
|
||||
emit WPDeleted(w->Number(), w);
|
||||
qDebug() << "title" << info;
|
||||
}
|
||||
else if(info != infolist.last())
|
||||
{
|
||||
QStringList p;
|
||||
if(info.contains('\t'))
|
||||
{
|
||||
p = info.split('\t');
|
||||
}
|
||||
else if(info.contains(' '))
|
||||
{
|
||||
p = info.split(' ');
|
||||
}
|
||||
else if(info.contains(','))
|
||||
{
|
||||
p = info.split(',');
|
||||
}
|
||||
|
||||
if(p.size() >= 11)
|
||||
{
|
||||
|
||||
|
||||
uint8_t autocontinue = 1;//bool
|
||||
uint16_t command = QString(p.at(9)).toInt();
|
||||
uint16_t seq = QString(p.at(0)).toUInt();
|
||||
uint8_t frame = (QString(p.at(1)) == "abs")?(0):(1);
|
||||
//QJsonArray params = item.toObject().find("params").value().toArray();//array
|
||||
uint8_t mission_type = currentGroup;
|
||||
|
||||
float param1 = QString(p.at(10)).toDouble();//cmd2
|
||||
float param2 = QString(p.at(7)).toDouble();//threshold
|
||||
float param3 = QString(p.at(6)).toDouble();//radius
|
||||
float param4 = QString(p.at(8)).toDouble();//speed
|
||||
int32_t x = QString(p.at(3)).toDouble() * 10e6;
|
||||
int32_t y = QString(p.at(4)).toDouble() * 10e6;
|
||||
float z = QString(p.at(5)).toDouble();
|
||||
|
||||
internals::PointLatLng LatLng;
|
||||
LatLng.SetLat(x * 10e-8);
|
||||
LatLng.SetLng(y * 10e-8);
|
||||
|
||||
qDebug() << "LatLng" << LatLng.Lat() << LatLng.Lng();
|
||||
|
||||
WayPointItem *Item = WPCreate(LatLng,z);
|
||||
|
||||
Item->SetNumber(seq);
|
||||
|
||||
emit setWPProperty(param1,param2,param3,param4,
|
||||
x,y,z,
|
||||
seq,
|
||||
mission_type,//当前组
|
||||
command,
|
||||
0,
|
||||
0,
|
||||
frame,
|
||||
0,
|
||||
autocontinue,
|
||||
mission_type);
|
||||
|
||||
|
||||
Item->emitWPProperty();
|
||||
|
||||
|
||||
|
||||
WayPointItem *w_last = WPFind(Item->MissionType(),Item->Number() - 1);
|
||||
|
||||
if(w_last)
|
||||
{
|
||||
WPLineCreate(w_last,Item,Qt::green,false,2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if(fileSuffix == "plan")
|
||||
{
|
||||
//读取
|
||||
QFile jsonFile(path);
|
||||
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "Unable to open file" << path << jsonFile.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray bytes = jsonFile.readAll();
|
||||
|
||||
jsonFile.close();
|
||||
QJsonParseError jsonParseError;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(bytes, &jsonParseError);
|
||||
if (jsonParseError.error != QJsonParseError::NoError) {
|
||||
qWarning() << path << "Unable to open json document" << jsonParseError.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject json = doc.object();
|
||||
|
||||
if(currentGroup == 1)
|
||||
{
|
||||
emit showMessage(tr("Load Geo Fence File :%1").arg(path));
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFencecircle *w = qgraphicsitem_cast<geoFencecircle *>(i);
|
||||
if (w) {
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//任务解码
|
||||
QJsonArray itemsArray = json.value("mission").toObject().value("items").toArray();
|
||||
|
||||
for(QJsonValue item: itemsArray) {
|
||||
if (!item.isObject()) {
|
||||
return;
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFenceitem *w = qgraphicsitem_cast<geoFenceitem *>(i);
|
||||
if (w) {
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t AMSLAltAboveTerrain = item.toObject().find("AMSLAltAboveTerrain").value().toInt();
|
||||
uint8_t Altitude = item.toObject().find("Altitude").value().toDouble();
|
||||
uint8_t AltitudeMode = item.toObject().find("AltitudeMode").value().toInt();
|
||||
uint8_t autocontinue = item.toObject().find("autoContinue").value().toBool()?(1):(0);//bool
|
||||
uint16_t command = item.toObject().find("command").value().toInt();
|
||||
uint16_t seq = item.toObject().find("doJumpId").value().toInt();
|
||||
uint8_t frame = item.toObject().find("frame").value().toInt();
|
||||
QJsonArray params = item.toObject().find("params").value().toArray();//array
|
||||
//uint8_t mission_type = item.toObject().find("type").value().toInt();
|
||||
uint8_t mission_type = currentGroup;
|
||||
fenceCount = 1;
|
||||
|
||||
float param1 = params.at(0).toDouble();
|
||||
float param2 = params.at(1).toDouble();
|
||||
float param3 = params.at(2).toDouble();
|
||||
float param4 = params.at(3).toDouble();
|
||||
int32_t x = params.at(4).toDouble() * 10e6;
|
||||
int32_t y = params.at(5).toDouble() * 10e6;
|
||||
float z = params.at(6).toDouble();
|
||||
//栅栏解码
|
||||
QJsonArray polygonsArray = json.value("geoFence").toObject().value("polygons").toArray();
|
||||
for(QJsonValue item: polygonsArray) {
|
||||
|
||||
internals::PointLatLng LatLng;
|
||||
LatLng.SetLat(x * 10e-8);
|
||||
LatLng.SetLng(y * 10e-8);
|
||||
//每个item是一个组
|
||||
QList<internals::PointLatLng> points;
|
||||
QList<QPointF> latlng;
|
||||
//获得边界
|
||||
bool inclusion = item.toObject().value("inclusion").toBool();
|
||||
QJsonArray polygon = item.toObject().value("polygon").toArray();
|
||||
int version = item.toObject().value("version").toInt();
|
||||
|
||||
qDebug() << "LatLng" << LatLng.Lat() << LatLng.Lng();
|
||||
qreal lat_sum = 0;
|
||||
qreal lng_sum = 0;
|
||||
|
||||
WayPointItem *Item = WPCreate(LatLng,z);
|
||||
for (QJsonValue point: polygon) {
|
||||
qreal lat = point.toArray().at(0).toDouble();
|
||||
qreal lng = point.toArray().at(1).toDouble();
|
||||
|
||||
Item->SetNumber(seq);
|
||||
//生成一个多边形
|
||||
points.push_back(internals::PointLatLng(lat,lng));
|
||||
|
||||
emit setWPProperty(param1,param2,param3,param4,
|
||||
x,y,z,
|
||||
seq,
|
||||
mission_type,//当前组
|
||||
command,
|
||||
0,
|
||||
0,
|
||||
frame,
|
||||
0,
|
||||
autocontinue,
|
||||
mission_type);
|
||||
lat_sum += lat;
|
||||
lng_sum += lng;
|
||||
|
||||
|
||||
Item->emitWPProperty();
|
||||
latlng.push_back(QPointF(lat,lng));
|
||||
|
||||
}
|
||||
|
||||
internals::PointLatLng center;
|
||||
|
||||
center.SetLat(lat_sum/polygon.size());
|
||||
center.SetLng(lng_sum/polygon.size());
|
||||
|
||||
geoFenceitem *polyitem = new geoFenceitem(fenceCount,inclusion,version,center,QColor("#FF8000"),map);
|
||||
|
||||
polyitem->setPoints(points);
|
||||
|
||||
emit createFencePolygon(fenceCount++,points.size(),inclusion,latlng);
|
||||
|
||||
connect(polyitem,SIGNAL(updateFencePolygon(int,qreal,bool,QList<QPointF>)),
|
||||
this,SIGNAL(updateFencePolygon(int,qreal,bool,QList<QPointF>)));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
connect(c,SIGNAL(updateFenceCircle(int,qreal,bool,qreal,qreal)),
|
||||
this,SIGNAL(updateFenceCircle(int,qreal,bool,qreal,qreal)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if(currentGroup >= 3)
|
||||
{
|
||||
|
||||
emit showMessage(tr("Load Mission File:Group %1,%2").arg(QString::number(currentGroup)).arg(path));
|
||||
//清除所有
|
||||
//删除一个组
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
|
||||
if (w) {
|
||||
if(w->MissionType() == currentGroup)
|
||||
{
|
||||
emit WPDeleted(w->Number(), w);
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//任务解码
|
||||
QJsonArray itemsArray = json.value("mission").toObject().value("items").toArray();
|
||||
|
||||
for(QJsonValue item: itemsArray) {
|
||||
if (!item.isObject()) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t AMSLAltAboveTerrain = item.toObject().find("AMSLAltAboveTerrain").value().toInt();
|
||||
uint8_t Altitude = item.toObject().find("Altitude").value().toDouble();
|
||||
uint8_t AltitudeMode = item.toObject().find("AltitudeMode").value().toInt();
|
||||
uint8_t autocontinue = item.toObject().find("autoContinue").value().toBool()?(1):(0);//bool
|
||||
uint16_t command = item.toObject().find("command").value().toInt();
|
||||
uint16_t seq = item.toObject().find("doJumpId").value().toInt();
|
||||
uint8_t frame = item.toObject().find("frame").value().toInt();
|
||||
QJsonArray params = item.toObject().find("params").value().toArray();//array
|
||||
//uint8_t mission_type = item.toObject().find("type").value().toInt();
|
||||
uint8_t mission_type = currentGroup;
|
||||
|
||||
float param1 = params.at(0).toDouble();
|
||||
float param2 = params.at(1).toDouble();
|
||||
float param3 = params.at(2).toDouble();
|
||||
float param4 = params.at(3).toDouble();
|
||||
int32_t x = params.at(4).toDouble() * 10e6;
|
||||
int32_t y = params.at(5).toDouble() * 10e6;
|
||||
float z = params.at(6).toDouble();
|
||||
|
||||
internals::PointLatLng LatLng;
|
||||
LatLng.SetLat(x * 10e-8);
|
||||
LatLng.SetLng(y * 10e-8);
|
||||
|
||||
qDebug() << "LatLng" << LatLng.Lat() << LatLng.Lng();
|
||||
|
||||
WayPointItem *Item = WPCreate(LatLng,z);
|
||||
|
||||
Item->SetNumber(seq);
|
||||
|
||||
emit setWPProperty(param1,param2,param3,param4,
|
||||
x,y,z,
|
||||
seq,
|
||||
mission_type,//当前组
|
||||
command,
|
||||
0,
|
||||
0,
|
||||
frame,
|
||||
0,
|
||||
autocontinue,
|
||||
mission_type);
|
||||
|
||||
|
||||
Item->emitWPProperty();
|
||||
|
||||
|
||||
|
||||
WayPointItem *w_last = WPFind(Item->MissionType(),Item->Number() - 1);
|
||||
WayPointItem *w_last = WPFind(Item->MissionType(),Item->Number() - 1);
|
||||
|
||||
if(w_last)
|
||||
{
|
||||
WPLineCreate(w_last,Item,Qt::green,false,2);
|
||||
if(w_last)
|
||||
{
|
||||
WPLineCreate(w_last,Item,Qt::green,false,2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OPMapWidget::WPSave(QString path)//带文件目录参数
|
||||
{
|
||||
qDebug() << "WPSave" << path;
|
||||
//保存到文件 *.plan,使用qgc的协议 json读写
|
||||
QJsonDocument *doc = new QJsonDocument();
|
||||
QJsonObject root= doc->object();
|
||||
|
||||
QJsonObject geoFence;
|
||||
QJsonObject mission;
|
||||
QJsonObject rallyPoints;
|
||||
|
||||
|
||||
if(currentGroup == 1)
|
||||
QString fileName, filePath,fileSuffix;
|
||||
QFileInfo fileInfo = QFileInfo(path);
|
||||
//文件名
|
||||
fileName = fileInfo.fileName();
|
||||
//文件后缀
|
||||
fileSuffix = fileInfo.suffix();
|
||||
//绝对路径
|
||||
filePath = fileInfo.absolutePath();
|
||||
|
||||
|
||||
|
||||
|
||||
//KT16的舵机情况 5ms之后,75% -40℃,80% 25℃,83% 60℃,70N·m;
|
||||
|
||||
if(fileSuffix == "csv")
|
||||
{
|
||||
//geoFence节点写入 (mission type == 1,2)
|
||||
//判断围栏数量大于0时写入,否则不写
|
||||
|
||||
emit showMessage(tr("Save Fence File:%1").arg(path));
|
||||
|
||||
QJsonArray circles;
|
||||
QJsonArray polygons;
|
||||
if(currentGroup == 1)
|
||||
{
|
||||
|
||||
}
|
||||
else if(currentGroup == 2)
|
||||
{
|
||||
|
||||
}
|
||||
else if(currentGroup >= 3)
|
||||
{
|
||||
emit showMessage(tr("Save Mission File:Group %1,%2").arg(QString::number(currentGroup)).arg(path));
|
||||
|
||||
|
||||
QByteArray missions;
|
||||
missions.clear();
|
||||
|
||||
missions.append("index"); missions.append(',');
|
||||
missions.append("frame"); missions.append(',');
|
||||
missions.append("group"); missions.append(',');
|
||||
missions.append("latitude"); missions.append(',');
|
||||
missions.append("longitude"); missions.append(',');
|
||||
missions.append("altitude"); missions.append(',');
|
||||
missions.append("radius"); missions.append(',');
|
||||
missions.append("threshold"); missions.append(',');
|
||||
missions.append("speed"); missions.append(',');
|
||||
missions.append("cmd"); missions.append(',');
|
||||
missions.append("param"); missions.append('\n');
|
||||
|
||||
QMap<int,WayPointItem *> wlist;
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFenceitem *w = qgraphicsitem_cast<geoFenceitem *>(i);
|
||||
if (w) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
if (w) {//逐渐往下增加
|
||||
if(w->MissionType() == currentGroup)
|
||||
{
|
||||
wlist.insert(w->Number(),w);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QJsonArray polygon;
|
||||
QJsonObject polygonObj;
|
||||
for (QMap<int,WayPointItem *>::iterator i = wlist.begin(); i != wlist.end(); ++i) {
|
||||
|
||||
QList<internals::PointLatLng> points = w->points;
|
||||
WayPointItem *w = i.value();
|
||||
|
||||
for(internals::PointLatLng ll:points)
|
||||
if (w) {//逐渐往下增加
|
||||
if(w->Number()>0)
|
||||
{
|
||||
|
||||
QJsonArray latlng;
|
||||
latlng.append(ll.Lat());
|
||||
latlng.append(ll.Lng());
|
||||
missions.append(QString::number(w->Number())); missions.append(',');
|
||||
missions.append((w->Frame())?("rel"):("abs")); missions.append(',');
|
||||
missions.append(QString::number(currentGroup)); missions.append(',');
|
||||
missions.append(QString::number(w->Coord().Lat(),'f',8)); missions.append(',');
|
||||
missions.append(QString::number(w->Coord().Lng(),'f',8)); missions.append(',');
|
||||
missions.append(QString::number(w->Alt())); missions.append(',');
|
||||
missions.append(QString::number(w->Param3())); missions.append(',');
|
||||
missions.append(QString::number(w->Param2())); missions.append(',');
|
||||
missions.append(QString::number(w->Param4())); missions.append(',');
|
||||
missions.append(QString::number(w->Command())); missions.append(',');
|
||||
missions.append(QString::number(w->Param1())); missions.append('\n');
|
||||
|
||||
polygon.push_back(latlng);
|
||||
}
|
||||
}
|
||||
|
||||
polygonObj["inclusion"] = w->Inclusion();
|
||||
polygonObj["polygon"] = polygon;
|
||||
polygonObj["version"] = 1;
|
||||
QFile file(path);
|
||||
if(!file.open(QIODevice::ReadWrite|QFile::Truncate)) {
|
||||
qDebug() << "File open error";
|
||||
}
|
||||
|
||||
file.write(missions);
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(fileSuffix == "plan")
|
||||
{
|
||||
//保存到文件 *.plan,使用qgc的协议 json读写
|
||||
QJsonDocument *doc = new QJsonDocument();
|
||||
QJsonObject root= doc->object();
|
||||
|
||||
QJsonObject geoFence;
|
||||
QJsonObject mission;
|
||||
QJsonObject rallyPoints;
|
||||
|
||||
|
||||
polygons.push_back(polygonObj);
|
||||
if(currentGroup == 1)
|
||||
{
|
||||
//geoFence节点写入 (mission type == 1,2)
|
||||
//判断围栏数量大于0时写入,否则不写
|
||||
|
||||
emit showMessage(tr("Save Fence File:%1").arg(path));
|
||||
|
||||
QJsonArray circles;
|
||||
QJsonArray polygons;
|
||||
{
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFenceitem *w = qgraphicsitem_cast<geoFenceitem *>(i);
|
||||
if (w) {
|
||||
|
||||
QJsonArray polygon;
|
||||
QJsonObject polygonObj;
|
||||
|
||||
QList<internals::PointLatLng> points = w->points;
|
||||
|
||||
for(internals::PointLatLng ll:points)
|
||||
{
|
||||
|
||||
QJsonArray latlng;
|
||||
latlng.append(ll.Lat());
|
||||
latlng.append(ll.Lng());
|
||||
|
||||
polygon.push_back(latlng);
|
||||
}
|
||||
|
||||
polygonObj["inclusion"] = w->Inclusion();
|
||||
polygonObj["polygon"] = polygon;
|
||||
polygonObj["version"] = 1;
|
||||
|
||||
|
||||
polygons.push_back(polygonObj);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFencecircle *w = qgraphicsitem_cast<geoFencecircle *>(i);
|
||||
if (w) {
|
||||
QJsonObject circle;
|
||||
QJsonObject circleObj;
|
||||
|
||||
|
||||
QJsonArray center;
|
||||
center.append(w->Latitude());
|
||||
center.append(w->Longitude());
|
||||
|
||||
double radius = w->Radius();
|
||||
|
||||
circle["center"] = center;
|
||||
circle["radius"] = radius;
|
||||
|
||||
|
||||
circleObj["inclusion"] = w->Inclusion();
|
||||
circleObj["circle"] = circle;
|
||||
circleObj["version"] = 1;
|
||||
|
||||
|
||||
circles.push_back(circleObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
geoFence.insert("circles",circles);
|
||||
geoFence.insert("polygons",polygons);
|
||||
geoFence.insert("version",2);
|
||||
|
||||
}
|
||||
else if(currentGroup == 2)
|
||||
{
|
||||
//rallyPoints节点写入
|
||||
|
||||
QJsonArray points;
|
||||
rallyPoints.insert("points",points);
|
||||
rallyPoints.insert("version",2);
|
||||
|
||||
}
|
||||
else if(currentGroup >= 3)
|
||||
{
|
||||
emit showMessage(tr("Save Mission File:Group %1,%2").arg(QString::number(currentGroup)).arg(path));
|
||||
|
||||
|
||||
QJsonArray items;
|
||||
|
||||
QJsonArray plannedHomePosition;
|
||||
|
||||
QMap<int,WayPointItem *> wlist;
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
geoFencecircle *w = qgraphicsitem_cast<geoFencecircle *>(i);
|
||||
if (w) {
|
||||
QJsonObject circle;
|
||||
QJsonObject circleObj;
|
||||
|
||||
|
||||
QJsonArray center;
|
||||
center.append(w->Latitude());
|
||||
center.append(w->Longitude());
|
||||
|
||||
double radius = w->Radius();
|
||||
|
||||
circle["center"] = center;
|
||||
circle["radius"] = radius;
|
||||
|
||||
|
||||
circleObj["inclusion"] = w->Inclusion();
|
||||
circleObj["circle"] = circle;
|
||||
circleObj["version"] = 1;
|
||||
|
||||
|
||||
circles.push_back(circleObj);
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
if (w) {//逐渐往下增加
|
||||
if(w->MissionType() == currentGroup)
|
||||
{
|
||||
wlist.insert(w->Number(),w);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
geoFence.insert("circles",circles);
|
||||
geoFence.insert("polygons",polygons);
|
||||
geoFence.insert("version",2);
|
||||
|
||||
}
|
||||
else if(currentGroup == 2)
|
||||
{
|
||||
//rallyPoints节点写入
|
||||
for (QMap<int,WayPointItem *>::iterator i = wlist.begin(); i != wlist.end(); ++i) {
|
||||
|
||||
QJsonArray points;
|
||||
rallyPoints.insert("points",points);
|
||||
rallyPoints.insert("version",2);
|
||||
WayPointItem *w = i.value();
|
||||
|
||||
}
|
||||
else if(currentGroup >= 3)
|
||||
{
|
||||
emit showMessage(tr("Save Mission File:Group %1,%2").arg(QString::number(currentGroup)).arg(path));
|
||||
if (w) {//逐渐往下增加
|
||||
if(w->Number()>0)
|
||||
{
|
||||
|
||||
//存到items
|
||||
QJsonArray params;
|
||||
params.append(w->Param1());
|
||||
params.append(w->Param2());
|
||||
params.append(w->Param3());
|
||||
params.append(w->Param4());
|
||||
params.append(w->Coord().Lat());
|
||||
params.append(w->Coord().Lng());
|
||||
params.append(w->Alt());
|
||||
|
||||
QJsonArray items;
|
||||
//可能有点问题
|
||||
QJsonObject item;
|
||||
|
||||
QJsonArray plannedHomePosition;
|
||||
//如果这个点是指令,那么不会有高度信息
|
||||
|
||||
QMap<int,WayPointItem *> wlist;
|
||||
if(w->Command() < MAV_CMD::MAV_CMD_NAV_LAST) {
|
||||
|
||||
foreach(QGraphicsItem * i, map->childItems()) {
|
||||
WayPointItem *w = qgraphicsitem_cast<WayPointItem *>(i);
|
||||
if (w) {//逐渐往下增加
|
||||
if(w->MissionType() == currentGroup)
|
||||
{
|
||||
wlist.insert(w->Number(),w);
|
||||
}
|
||||
}
|
||||
}
|
||||
item.insert("AMSLAltAboveTerrain",w->Alt());
|
||||
item.insert("Altitude",w->Alt());
|
||||
item.insert("AltitudeMode",2);
|
||||
}
|
||||
|
||||
for (QMap<int,WayPointItem *>::iterator i = wlist.begin(); i != wlist.end(); ++i) {
|
||||
item.insert("autoContinue",w->AutoContinue()?true:false);
|
||||
item.insert("command",w->Command());
|
||||
item.insert("doJumpId",w->Number());
|
||||
item.insert("frame",w->Frame());
|
||||
item.insert("params",params);
|
||||
item.insert("type",w->MissionType());
|
||||
|
||||
WayPointItem *w = i.value();
|
||||
|
||||
if (w) {//逐渐往下增加
|
||||
if(w->Number()>0)
|
||||
{
|
||||
|
||||
//存到items
|
||||
QJsonArray params;
|
||||
params.append(w->Param1());
|
||||
params.append(w->Param2());
|
||||
params.append(w->Param3());
|
||||
params.append(w->Param4());
|
||||
params.append(w->Coord().Lat());
|
||||
params.append(w->Coord().Lng());
|
||||
params.append(w->Alt());
|
||||
|
||||
//可能有点问题
|
||||
QJsonObject item;
|
||||
|
||||
//如果这个点是指令,那么不会有高度信息
|
||||
|
||||
if(w->Command() < MAV_CMD::MAV_CMD_NAV_LAST) {
|
||||
|
||||
item.insert("AMSLAltAboveTerrain",w->Alt());
|
||||
item.insert("Altitude",w->Alt());
|
||||
item.insert("AltitudeMode",2);
|
||||
items.append(item);
|
||||
}
|
||||
|
||||
item.insert("autoContinue",w->AutoContinue()?true:false);
|
||||
item.insert("command",w->Command());
|
||||
item.insert("doJumpId",w->Number());
|
||||
item.insert("frame",w->Frame());
|
||||
item.insert("params",params);
|
||||
item.insert("type",w->MissionType());
|
||||
|
||||
items.append(item);
|
||||
}
|
||||
|
||||
if(w->Number() == 1)
|
||||
{
|
||||
plannedHomePosition.append(w->Coord().Lat());
|
||||
plannedHomePosition.append(w->Coord().Lng());
|
||||
plannedHomePosition.append(w->Alt());
|
||||
if(w->Number() == 1)
|
||||
{
|
||||
plannedHomePosition.append(w->Coord().Lat());
|
||||
plannedHomePosition.append(w->Coord().Lng());
|
||||
plannedHomePosition.append(w->Alt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mission.insert("cruiseSpeed",2);
|
||||
mission.insert("firmwareType",0);
|
||||
mission.insert("hoverSpeed",2);
|
||||
mission.insert("items",items);
|
||||
mission.insert("plannedHomePosition",plannedHomePosition);
|
||||
mission.insert("vehicleType",1);
|
||||
mission.insert("version",2);
|
||||
}
|
||||
|
||||
mission.insert("cruiseSpeed",2);
|
||||
mission.insert("firmwareType",0);
|
||||
mission.insert("hoverSpeed",2);
|
||||
mission.insert("items",items);
|
||||
mission.insert("plannedHomePosition",plannedHomePosition);
|
||||
mission.insert("vehicleType",1);
|
||||
mission.insert("version",2);
|
||||
|
||||
|
||||
//根节点写入
|
||||
root.insert("fileType","Plan");
|
||||
root.insert("geoFence",geoFence);
|
||||
root.insert("groundStation","GCS_nf");
|
||||
root.insert("mission", mission);
|
||||
root.insert("rallyPoints", rallyPoints);
|
||||
root.insert("version", 1);
|
||||
|
||||
//设置文档
|
||||
doc->setObject(root);
|
||||
|
||||
//如果没有后缀名,那就追加
|
||||
if(path.right(5) != ".plan")
|
||||
{
|
||||
path.append(".plan");
|
||||
}
|
||||
|
||||
QFile file(path);
|
||||
if(!file.open(QIODevice::ReadWrite|QFile::Truncate)) {
|
||||
qDebug() << "File open error";
|
||||
}
|
||||
|
||||
file.write(doc->toJson());
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//根节点写入
|
||||
root.insert("fileType","Plan");
|
||||
root.insert("geoFence",geoFence);
|
||||
root.insert("groundStation","GCS_nf");
|
||||
root.insert("mission", mission);
|
||||
root.insert("rallyPoints", rallyPoints);
|
||||
root.insert("version", 1);
|
||||
|
||||
//设置文档
|
||||
doc->setObject(root);
|
||||
|
||||
//如果没有后缀名,那就追加
|
||||
if(path.right(5) != ".plan")
|
||||
{
|
||||
path.append(".plan");
|
||||
}
|
||||
|
||||
QFile file(path);
|
||||
if(!file.open(QIODevice::ReadWrite|QFile::Truncate)) {
|
||||
qDebug() << "File open error";
|
||||
}
|
||||
|
||||
file.write(doc->toJson());
|
||||
file.close();
|
||||
}
|
||||
|
||||
void OPMapWidget::WPDownload(void)
|
||||
|
||||
Reference in New Issue
Block a user