74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
#include "PosParser.h"
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
#include <QDebug>
|
|
#include <QRegularExpression>
|
|
|
|
bool PosParser::loadPosFile(const QString &posFilePath, QVector<QVector3D> &outPositions) {
|
|
outPositions.clear();
|
|
|
|
QFile file(posFilePath);
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
qDebug() << "PosParser: Cannot open pos file:" << posFilePath;
|
|
return false;
|
|
}
|
|
|
|
QTextStream in(&file);
|
|
QRegularExpression reLineComment("^\\s*%");
|
|
|
|
while (!in.atEnd()) {
|
|
QString line = in.readLine().trimmed();
|
|
if (line.isEmpty()) continue;
|
|
if (reLineComment.match(line).hasMatch()) continue; // 跳过注释行
|
|
|
|
QStringList parts = line.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
|
if (parts.size() < 4) continue;
|
|
|
|
bool okX = false, okY = false, okZ = false;
|
|
// 列顺序: 道号(忽略) X Y Z
|
|
double x = parts[1].toDouble(&okX);
|
|
double y = parts[2].toDouble(&okY);
|
|
double z = parts[3].toDouble(&okZ);
|
|
|
|
if (okX && okY && okZ) {
|
|
outPositions.append(QVector3D(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z)));
|
|
}
|
|
}
|
|
|
|
file.close();
|
|
qDebug() << "PosParser: Loaded" << outPositions.size() << "GPS points from" << posFilePath;
|
|
return !outPositions.isEmpty();
|
|
}
|
|
|
|
bool PosParser::loadCenterCcc(const QString &cccFilePath, double &outLat, double &outLon) {
|
|
QFile file(cccFilePath);
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
qDebug() << "PosParser: Cannot open center.ccc:" << cccFilePath;
|
|
return false;
|
|
}
|
|
|
|
QTextStream in(&file);
|
|
QRegularExpression reLineComment("^\\s*%");
|
|
|
|
while (!in.atEnd()) {
|
|
QString line = in.readLine().trimmed();
|
|
if (line.isEmpty()) continue;
|
|
if (reLineComment.match(line).hasMatch()) continue;
|
|
|
|
QStringList parts = line.split(QRegularExpression("\\s+"), Qt::SkipEmptyParts);
|
|
if (parts.size() < 2) continue;
|
|
|
|
bool okLat = false, okLon = false;
|
|
outLat = parts[0].toDouble(&okLat);
|
|
outLon = parts[1].toDouble(&okLon);
|
|
|
|
if (okLat && okLon) {
|
|
file.close();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
file.close();
|
|
return false;
|
|
}
|