|
@@ -2,54 +2,158 @@
|
|
|
|
|
|
SimulationControl::SimulationControl(QObject *parent) : QObject(parent)
|
|
|
{
|
|
|
- // 添加场景平台
|
|
|
-// allyplane.push_back(new Platform(this, 1001, QString::fromLocal8Bit("弹道导弹1"),120,27,8000,-600,600,-900));
|
|
|
+ // 想定文件路径
|
|
|
+ QFile file(QString::fromLocal8Bit("C:\\Users\\luo_h\\Downloads\\突防想定002.json"));
|
|
|
+ if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
|
|
+ qDebug() << "can't open error!";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 读取文件的全部内容
|
|
|
+ QTextStream stream(&file);
|
|
|
+ stream.setCodec("UTF-8"); // 设置读取编码是UTF8
|
|
|
+ QString str = stream.readAll();
|
|
|
+
|
|
|
+ file.close();
|
|
|
+
|
|
|
+ // QJsonParseError类用于在JSON解析期间报告错误。
|
|
|
+ QJsonParseError jsonError;
|
|
|
+ // 将json解析为UTF-8编码的json文档,并从中创建一个QJsonDocument。
|
|
|
+ // 如果解析成功,返回QJsonDocument对象,否则返回null
|
|
|
+ QJsonDocument doc = QJsonDocument::fromJson(str.toUtf8(), &jsonError);
|
|
|
+ // 判断是否解析失败
|
|
|
+ if (jsonError.error != QJsonParseError::NoError && !doc.isNull()) {
|
|
|
+ qDebug() << "Json格式错误!" << jsonError.error;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ qDebug() << QString::fromLocal8Bit("想定文件读取成功");
|
|
|
+
|
|
|
+ if (doc.isObject()) {
|
|
|
+ QJsonObject docobj = doc.object();
|
|
|
+ qDebug() << QString::fromLocal8Bit("想定编号:") << docobj.value("id").toString();
|
|
|
+ qDebug() << QString::fromLocal8Bit("想定名称:") << docobj.value("xdname").toString();
|
|
|
+ qDebug() << QString::fromLocal8Bit("想定类型:") << docobj.value("type").toString();
|
|
|
+ qDebug() << QString::fromLocal8Bit("开始时间:") << docobj.value("starttime").toString();
|
|
|
+ qDebug() << QString::fromLocal8Bit("结束时间:") << docobj.value("endtime").toString();
|
|
|
+ qDebug() << QString::fromLocal8Bit("仿真步长:") << docobj.value("steptime").toDouble();
|
|
|
+ int redcnt = docobj.value("redcnt").toInt();
|
|
|
+ int bluecnt = docobj.value("bluecnt").toInt();
|
|
|
+
|
|
|
+ qDebug() << QString::fromLocal8Bit("红方作战单元数:") << redcnt;
|
|
|
+ QJsonArray redunits = docobj.value("redunit").toArray();
|
|
|
+ for (int i = 0; i < redcnt; i++) {
|
|
|
+ QJsonObject unit = redunits.at(i).toObject();
|
|
|
+ int unitid = unit.value("unitID").toInt();
|
|
|
+ QString unitType = unit.value("type").toString();
|
|
|
+ QString unitName = unit.value("name").toString();
|
|
|
+ QString unitTask = unit.value("task").toString();
|
|
|
+ int unitMovementID = unit.value("component_movementid").toInt();
|
|
|
+
|
|
|
+ if (i == 0) {
|
|
|
+ allymissile.push_back(new Platform(this, unitid, unitName, 120,27, 8000, -600, 600, -900));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ allymissile.push_back(new Platform(this, unitid, unitName, 120.5,27.5, 8000, -600, 600, -900));
|
|
|
+ }
|
|
|
|
|
|
- allymissile.push_back(new Platform(this, 1001, QString::fromLocal8Bit("弹道导弹1"),120,27,8000,-600,600,-900));
|
|
|
- allymissile.push_back(new Platform(this, 1002, QString::fromLocal8Bit("弹道导弹2"),120.3,27,8000,-600,600,-900));
|
|
|
- allymissile.push_back(new Platform(this, 1003, QString::fromLocal8Bit("弹道导弹3"),120,27.3,8000,-600,600,-900));
|
|
|
- allymissile.push_back(new Platform(this, 1004, QString::fromLocal8Bit("弹道导弹4"),120.3,27.3,8000,-600,600,-900));
|
|
|
+ qDebug() << "\t" << QString::fromLocal8Bit("初始化作战单元:") << unitid << unitName;
|
|
|
+ qDebug() << "\t" << QString::fromLocal8Bit("作战单元类型:") << unitType;
|
|
|
+ qDebug() << "\t" << QString::fromLocal8Bit("作战单元意图:") << unitTask;
|
|
|
+ qDebug() << "\t" << QString::fromLocal8Bit("作战单元运动模型ID:") << unitMovementID;
|
|
|
|
|
|
- allymissile.push_back(new Platform(this, 1005, QString::fromLocal8Bit("弹道导弹5"),117,33,0));
|
|
|
- allymissile.push_back(new Platform(this, 1006, QString::fromLocal8Bit("弹道导弹6"),117,33,0));
|
|
|
- allymissile.push_back(new Platform(this, 1007, QString::fromLocal8Bit("弹道导弹7"),117,33,0));
|
|
|
+ int componentCnt = unit.value("components_ids").toInt();
|
|
|
+ QJsonObject componentsJson = unit.value("components_json").toObject();
|
|
|
+ for (auto i : componentsJson.keys())
|
|
|
+ {
|
|
|
+ QJsonObject componentNow = componentsJson.value(i).toObject();
|
|
|
+ int componentID = componentNow.value("id").toInt();
|
|
|
+ QString componentName = componentNow.value("number").toString();
|
|
|
+ QString componentType = componentNow.value("type").toString();
|
|
|
+ QString componentUrl = componentNow.value("url").toString();
|
|
|
+
|
|
|
+ Jamming *jammingtmp = new Jamming(this, unitid, componentID, true, componentName,
|
|
|
+ componentUrl, 1);
|
|
|
+ allyJammingSim.insert(std::pair<int, Jamming*>(componentID, jammingtmp));
|
|
|
+
|
|
|
+ qDebug() << "\t\t" << QString::fromLocal8Bit("初始化单元组件:") << i << componentID << (componentName);
|
|
|
+ qDebug() << "\t\t" << QString::fromLocal8Bit("单元组件类型:") << (componentType) << (componentUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ qDebug() << QString::fromLocal8Bit("蓝方作战单元数:") << ":" << bluecnt;
|
|
|
+ QJsonArray blueunits = docobj.value("blueunit").toArray();
|
|
|
+ for (int i = 0; i < bluecnt; i++) {
|
|
|
+ QJsonObject unit = blueunits.at(i).toObject();
|
|
|
+ int unitid = unit.value("unitID").toInt();
|
|
|
+ QString unitType = unit.value("type").toString();
|
|
|
+ QString unitName = unit.value("name").toString();
|
|
|
+ QString unitTask = unit.value("task").toString();
|
|
|
+ int unitMovementID = unit.value("component_movementid").toInt();
|
|
|
+
|
|
|
+ qDebug() << "\t" << QString::fromLocal8Bit("初始化作战单元:") << unitid << unitName;
|
|
|
+ qDebug() << "\t" << QString::fromLocal8Bit("作战单元类型:") << unitType;
|
|
|
+ qDebug() << "\t" << QString::fromLocal8Bit("作战单元意图:") << unitTask;
|
|
|
+ qDebug() << "\t" << QString::fromLocal8Bit("作战单元运动模型ID:") << unitMovementID;
|
|
|
+
|
|
|
+ if (unitType.compare(QString::fromLocal8Bit("末端拦截系统"))==0) {
|
|
|
+ if (i == 0) {
|
|
|
+ enemyradar.push_back(new Platform(this,unitid,unitName,121,24.5,0));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ enemyradar.push_back(new Platform(this,unitid,unitName,121,22.5,0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (unitType.compare(QString::fromLocal8Bit("预警卫星"))==0){
|
|
|
+ // ...
|
|
|
+ enemysat.push_back(new Platform(this,unitid,unitName));
|
|
|
+ }
|
|
|
+
|
|
|
+ int componentCnt = unit.value("components_ids").toInt();
|
|
|
+ QJsonObject componentsJson = unit.value("components_json").toObject();
|
|
|
+ for (auto i : componentsJson.keys())
|
|
|
+ {
|
|
|
+ QJsonObject componentNow = componentsJson.value(i).toObject();
|
|
|
+ int componentID = componentNow.value("id").toInt();
|
|
|
+ QString componentName = componentNow.value("name").toString();
|
|
|
+ QString componentType = componentNow.value("type").toString();
|
|
|
+ QString componentUrl = componentNow.value("url").toString();
|
|
|
+
|
|
|
+ if (componentType.compare(QString::fromLocal8Bit("雷达"))==0)
|
|
|
+ {
|
|
|
+ Radar *radarNow = new Radar(this, unitid, componentID, true, componentName,
|
|
|
+ componentUrl);
|
|
|
+ enemyThaadRadarSim.insert(std::pair<int, Radar*>(componentID, radarNow));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // ...
|
|
|
+ }
|
|
|
+
|
|
|
+ qDebug() << "\t\t" << QString::fromLocal8Bit("初始化单元组件:") << i << componentID << (componentName);
|
|
|
+ qDebug() << "\t\t" << QString::fromLocal8Bit("单元组件类型:") << (componentType) << (componentUrl);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ qDebug() << QString::fromLocal8Bit("启动推演...");
|
|
|
+
|
|
|
+ // 添加场景平台
|
|
|
+// allyplane.push_back(new Platform(this, 1001, QString::fromLocal8Bit("弹道导弹1"),120,27,8000,-600,600,-900));
|
|
|
+// allymissile.push_back(new Platform(this, 1004, QString::fromLocal8Bit("弹道导弹4"),120.3,27.3,8000,-600,600,-900));
|
|
|
|
|
|
ally.push_back(allyplane);
|
|
|
ally.push_back(allymissile);
|
|
|
|
|
|
- enemyradar.push_back(new Platform(this,6001,QString::fromLocal8Bit("Thaad系统1"),121,24.5,0));
|
|
|
- enemyradar.push_back(new Platform(this,6002,QString::fromLocal8Bit("Thaad系统2"),121,22.5,0));
|
|
|
-
|
|
|
enemy.push_back(enemyradar);
|
|
|
enemy.push_back(enemysat);
|
|
|
|
|
|
- // 添加雷达模拟器
|
|
|
- Radar *radar1 = new Radar(this, 6001, 12, true, QString::fromLocal8Bit("AN-TPY/2雷达-1"),
|
|
|
- QStringLiteral("ws://localhost:1235"));
|
|
|
- Radar *radar2 = new Radar(this, 6002, 13, false, QString::fromLocal8Bit("AN-TPY/2雷达-2"),
|
|
|
- QStringLiteral("ws://localhost:1236"));
|
|
|
-// connect(this,&SimulationControl::SigRadarStyleUpdate,
|
|
|
-// radar1,&Radar::StyleUpdate);
|
|
|
-// connect(this,&SimulationControl::SigRadarStyleUpdate,
|
|
|
-// radar2,&Radar::StyleUpdate);
|
|
|
- enemyThaadRadarSim.insert(std::pair<int, Radar*>(12, radar1));
|
|
|
- enemyThaadRadarSim.insert(std::pair<int, Radar*>(13, radar2));
|
|
|
-
|
|
|
-
|
|
|
- Jamming *jamming1 = new Jamming(this, 1001, 20, true, QString::fromLocal8Bit("干扰器1"),
|
|
|
- QStringLiteral("ws://localhost:1240"),1);
|
|
|
- Jamming *jamming2 = new Jamming(this, 1002, 21, true, QString::fromLocal8Bit("干扰器2"),
|
|
|
- QStringLiteral("ws://localhost:1241"),1);
|
|
|
- Jamming *jamming3 = new Jamming(this, 1003, 22, true, QString::fromLocal8Bit("干扰器3"),
|
|
|
- QStringLiteral("ws://localhost:1242"),1);
|
|
|
- Jamming *jamming4 = new Jamming(this, 1004, 23, true, QString::fromLocal8Bit("干扰器4"),
|
|
|
- QStringLiteral("ws://localhost:1243"),1);
|
|
|
- // 添加干扰器
|
|
|
- allyJammingSim.insert(std::pair<int, Jamming*>(20, jamming1));
|
|
|
- allyJammingSim.insert(std::pair<int, Jamming*>(21, jamming2));
|
|
|
- allyJammingSim.insert(std::pair<int, Jamming*>(22, jamming3));
|
|
|
- allyJammingSim.insert(std::pair<int, Jamming*>(23, jamming4));
|
|
|
+// // 添加雷达模拟器
|
|
|
+// Radar *radar1 = new Radar(this, 6001, 12, true, QString::fromLocal8Bit("AN-TPY/2雷达-1"),
|
|
|
+// QStringLiteral("ws://localhost:1235"));
|
|
|
+// enemyThaadRadarSim.insert(std::pair<int, Radar*>(12, radar1));
|
|
|
|
|
|
+// // 添加干扰器
|
|
|
+// Jamming *jamming1 = new Jamming(this, 1001, 20, true, QString::fromLocal8Bit("干扰器1"),
|
|
|
+// QStringLiteral("ws://localhost:1240"),1);
|
|
|
+// allyJammingSim.insert(std::pair<int, Jamming*>(20, jamming1));
|
|
|
}
|
|
|
|
|
|
void SimulationControl::SlotGetInit(QWebSocket *pSender, QJsonObject obj)
|