161 lines
5.7 KiB
C++
161 lines
5.7 KiB
C++
#include "ImportLocalRadarDialog.hpp"
|
|
|
|
#include <QDateTime>
|
|
#include <QDir>
|
|
#include <QFileDialog>
|
|
#include <QHBoxLayout>
|
|
#include <QHeaderView>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QMessageBox>
|
|
#include <QPushButton>
|
|
#include <QStandardPaths>
|
|
#include <QTreeWidget>
|
|
#include <QVBoxLayout>
|
|
#include "data/LocalRadarDatasetStore.hpp"
|
|
#include "data/LocalRadarScanner.hpp"
|
|
|
|
namespace geopro::app {
|
|
|
|
ImportLocalRadarDialog::ImportLocalRadarDialog(const QString& tmObjectId,
|
|
QWidget* parent)
|
|
: QDialog(parent), tmObjectId_(tmObjectId) {
|
|
setWindowTitle(QStringLiteral("导入本地雷达数据"));
|
|
setMinimumSize(560, 380);
|
|
|
|
auto* lay = new QVBoxLayout(this);
|
|
lay->setSpacing(12);
|
|
|
|
// 路径选择行
|
|
auto* pathLay = new QHBoxLayout();
|
|
pathLay->addWidget(new QLabel(QStringLiteral("雷达数据文件夹:"), this));
|
|
pathEdit_ = new QLineEdit(this);
|
|
pathEdit_->setReadOnly(true);
|
|
pathEdit_->setPlaceholderText(QStringLiteral("请选择包含 .data/.head 的文件夹"));
|
|
pathLay->addWidget(pathEdit_, 1);
|
|
auto* browseBtn = new QPushButton(QStringLiteral("浏览…"), this);
|
|
pathLay->addWidget(browseBtn);
|
|
lay->addLayout(pathLay);
|
|
|
|
// 扫描按钮
|
|
scanBtn_ = new QPushButton(QStringLiteral("扫描测线"), this);
|
|
scanBtn_->setEnabled(false);
|
|
lay->addWidget(scanBtn_);
|
|
|
|
// 扫描结果树
|
|
resultTree_ = new QTreeWidget(this);
|
|
resultTree_->setHeaderLabels(
|
|
QStringList() << QStringLiteral("测线名称") << QStringLiteral("类型")
|
|
<< QStringLiteral("通道数") << QStringLiteral("采样点数")
|
|
<< QStringLiteral("道数") << QStringLiteral("频率(MHz)"));
|
|
resultTree_->header()->setStretchLastSection(false);
|
|
resultTree_->setColumnWidth(0, 180);
|
|
resultTree_->setColumnWidth(1, 70);
|
|
resultTree_->setColumnWidth(2, 60);
|
|
resultTree_->setColumnWidth(3, 80);
|
|
resultTree_->setColumnWidth(4, 60);
|
|
resultTree_->setColumnWidth(5, 80);
|
|
lay->addWidget(resultTree_, 1);
|
|
|
|
// 状态标签
|
|
statusLabel_ = new QLabel(this);
|
|
statusLabel_->setWordWrap(true);
|
|
lay->addWidget(statusLabel_);
|
|
|
|
// 底部按钮
|
|
auto* btnLay = new QHBoxLayout();
|
|
btnLay->addStretch();
|
|
okBtn_ = new QPushButton(QStringLiteral("导入"), this);
|
|
okBtn_->setEnabled(false);
|
|
okBtn_->setDefault(true);
|
|
auto* cancelBtn = new QPushButton(QStringLiteral("取消"), this);
|
|
btnLay->addWidget(okBtn_);
|
|
btnLay->addWidget(cancelBtn);
|
|
lay->addLayout(btnLay);
|
|
|
|
QObject::connect(browseBtn, &QPushButton::clicked, this,
|
|
&ImportLocalRadarDialog::chooseFolder);
|
|
QObject::connect(scanBtn_, &QPushButton::clicked, this,
|
|
&ImportLocalRadarDialog::performScan);
|
|
QObject::connect(okBtn_, &QPushButton::clicked, this,
|
|
&ImportLocalRadarDialog::onConfirm);
|
|
QObject::connect(cancelBtn, &QPushButton::clicked, this, &QDialog::reject);
|
|
}
|
|
|
|
void ImportLocalRadarDialog::chooseFolder() {
|
|
const QString dir = QFileDialog::getExistingDirectory(
|
|
this, QStringLiteral("选择雷达数据文件夹"), QString(),
|
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
|
|
if (!dir.isEmpty()) {
|
|
sourceDir_ = dir;
|
|
pathEdit_->setText(dir);
|
|
scanBtn_->setEnabled(true);
|
|
okBtn_->setEnabled(false);
|
|
resultTree_->clear();
|
|
statusLabel_->clear();
|
|
}
|
|
}
|
|
|
|
void ImportLocalRadarDialog::performScan() {
|
|
if (sourceDir_.isEmpty()) return;
|
|
resultTree_->clear();
|
|
scanResults_ = geopro::data::LocalRadarScanner::scan(sourceDir_);
|
|
|
|
for (const auto& s : scanResults_) {
|
|
auto* item = new QTreeWidgetItem(resultTree_);
|
|
item->setText(0, s.surveyName);
|
|
item->setText(1, s.channelCount == 1 ? QStringLiteral("2D") : QStringLiteral("3D"));
|
|
item->setText(2, QString::number(s.channelCount));
|
|
item->setText(3, QString::number(s.meta.samples));
|
|
item->setText(4, QString::number(s.meta.lastTrace));
|
|
item->setText(5, QString::number(s.meta.frequency));
|
|
}
|
|
|
|
statusLabel_->setText(
|
|
QStringLiteral("发现 %1 条测线").arg(scanResults_.size()));
|
|
okBtn_->setEnabled(!scanResults_.empty());
|
|
}
|
|
|
|
void ImportLocalRadarDialog::copyDirectory(const QString& src, const QString& dst) {
|
|
QDir srcDir(src);
|
|
if (!srcDir.exists()) return;
|
|
QDir dstDir(dst);
|
|
if (!dstDir.exists()) dstDir.mkpath(QStringLiteral("."));
|
|
|
|
for (const QString& entry : srcDir.entryList(QDir::Files)) {
|
|
QFile::copy(srcDir.filePath(entry), dstDir.filePath(entry));
|
|
}
|
|
for (const QString& subdir : srcDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
|
copyDirectory(srcDir.filePath(subdir), dstDir.filePath(subdir));
|
|
}
|
|
}
|
|
|
|
void ImportLocalRadarDialog::onConfirm() {
|
|
if (scanResults_.empty()) return;
|
|
|
|
// 目标目录:<AppData>/geopro/local_radar/<timestamp>/
|
|
const QString baseDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
|
|
+ QStringLiteral("/local_radar/");
|
|
const QString ts = QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_hhmmss"));
|
|
const QString targetDir = baseDir + ts + QStringLiteral("/");
|
|
|
|
// 复制源文件夹到目标目录
|
|
copyDirectory(sourceDir_, targetDir);
|
|
|
|
// 更新扫描结果的 folderPath 为复制后的路径
|
|
for (auto& s : scanResults_) {
|
|
s.folderPath = targetDir;
|
|
}
|
|
|
|
// 生成 DsRow
|
|
auto rows = geopro::data::LocalRadarScanner::toDsRows(scanResults_);
|
|
for (auto& row : rows) {
|
|
row.structParentId = tmObjectId_.toStdString();
|
|
}
|
|
|
|
emit imported(tmObjectId_, rows);
|
|
accept();
|
|
}
|
|
|
|
} // namespace geopro::app
|