2.0 KiB
2.0 KiB
QT GUI 自定义路径修改方案
快速修改步骤
第1步: 添加头文件
在 qt_gui_demo.cpp 第15行后添加:
#include <QFileDialog>
#include <QMessageBox>
#include <QInputDialog>
第2步: 添加路径选项
在第278行后添加两个选项:
path_combo_->addItem("Load from CSV");
path_combo_->addItem("Custom Spline");
第3步: 添加成员变量
在MainWindow类private部分最后添加:
PathCurve custom_path_;
bool custom_path_loaded_ = false;
第4步: 修改 generateControl 方法
在 if (path_type == "Circle Arc") 之前添加:
if (path_type == "Load from CSV") {
QString filename = QFileDialog::getOpenFileName(
this, "Open CSV", "", "CSV Files (*.csv)");
if (filename.isEmpty()) return;
if (!path.loadFromCSV(filename.toStdString(), true)) {
QMessageBox::warning(this, "Error", "Load failed!");
return;
}
QMessageBox::information(this, "OK",
QString("%1 points loaded").arg(path.getPathPoints().size()));
}
else if (path_type == "Custom Spline") {
bool ok;
int n = QInputDialog::getInt(this, "Spline", "Key points:", 4, 2, 10, 1, &ok);
if (!ok) return;
std::vector<PathPoint> kp;
for (int i = 0; i < n; ++i) {
double x = QInputDialog::getDouble(this, "Input",
QString("P%1 X:").arg(i+1), i*3.0, -100, 100, 2, &ok);
if (!ok) return;
double y = QInputDialog::getDouble(this, "Input",
QString("P%1 Y:").arg(i+1), (i%2)*3.0, -100, 100, 2, &ok);
if (!ok) return;
kp.push_back(PathPoint(x, y));
}
path.generateSpline(kp, 200, 0.5);
}
完整代码参考
见: examples/qt_gui_demo.cpp
修改位置:
- 行 15: 添加头文件
- 行 278: 添加选项
- 行 330: 修改方法
- 行 529: 添加变量
编译运行
cd build
cmake ..
cmake --build . --config Release · 编译到Release ,默认是Debug
./agv_qt_gui
使用说明
- 选择 "Load from CSV"
- 点击 "Generate Control"
- 选择CSV文件
- 点击 "Start Animation"