同步了吴夏鑫代码
parent
44b60a6738
commit
3809e1ea04
|
|
@ -10,31 +10,216 @@
|
||||||
// You may need to build the project (run Qt uic code generator) to get
|
// You may need to build the project (run Qt uic code generator) to get
|
||||||
// "ui_DialogImportModelDataset.h" resolved
|
// "ui_DialogImportModelDataset.h" resolved
|
||||||
|
|
||||||
|
#include <vtkSTLReader.h>
|
||||||
|
#include <QFileInfo>
|
||||||
#include "dialogimportmodeldataset.h"
|
#include "dialogimportmodeldataset.h"
|
||||||
#include "ui_DialogImportModelDataset.h"
|
#include "ui_DialogImportModelDataset.h"
|
||||||
#include "MainWindow/MainWindow.h"
|
#include "MainWindow/MainWindow.h"
|
||||||
#include "Settings/BusAPI.h"
|
#include "Settings/BusAPI.h"
|
||||||
|
#include "Settings/GraphOption.h"
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QTextCodec>
|
||||||
|
|
||||||
namespace WBFZ {
|
namespace WBFZ {
|
||||||
DialogImportModelDataset::DialogImportModelDataset(GUI::MainWindow* _mainwindow,QWidget* parent)
|
DialogImportModelDataset::DialogImportModelDataset(GUI::MainWindow* _mainwindow, QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(_mainwindow),
|
||||||
,_mainwindow(_mainwindow)
|
_mainwindow(_mainwindow),
|
||||||
, ui(new Ui::DialogImportModelDataset)
|
ui(new Ui::DialogImportModelDataset)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->initLibrary();
|
this->initLibrary();
|
||||||
|
this->initVTKView();// 初始化VTK视图
|
||||||
|
// 初始化 comboBox 的选项
|
||||||
|
QMap<QString, QString> categories = {
|
||||||
|
{"forest", "森林"},
|
||||||
|
{"crop", "农作物"},
|
||||||
|
{"grass", "草地"},
|
||||||
|
{"uav", "人工"},
|
||||||
|
{"water", "水体"},
|
||||||
|
{"dwater", "动态水体"},
|
||||||
|
{"road", "道路"},
|
||||||
|
{"geo", "几何"},
|
||||||
|
{"radi", "辐射"},
|
||||||
|
{"soil", "土壤"},
|
||||||
|
{"land", "陆表"},
|
||||||
|
{"vegetation", "植被"},
|
||||||
|
{"water_scene", "水体场景"}
|
||||||
|
};
|
||||||
|
for (auto category : categories.values()) {
|
||||||
|
ui->FiltercomboBox->addItem(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 连接 comboBox 的 currentIndexChanged 信号与更新 listWidget 的槽函数
|
||||||
|
connect(ui->FiltercomboBox, QOverload<const QString &>::of(&QComboBox::currentIndexChanged),
|
||||||
|
this, &DialogImportModelDataset::updateModellistWidget);
|
||||||
|
|
||||||
|
// 初始显示第一个选项对应的 listWidget 内容
|
||||||
|
updateModellistWidget(ui->FiltercomboBox->currentText());
|
||||||
|
|
||||||
|
// 初始化其它设置
|
||||||
|
_librarySettingPath = "D:/WBFZCPP/source/FastCAE/extlib/model/library.ini"; // 替换为实际的配置文件路径
|
||||||
|
initLibrary(); // 初始化库
|
||||||
|
|
||||||
|
// 可以在这里进行其它的初始化操作
|
||||||
|
// connect(ui->ModellistWidget, QOverload<QListWidgetItem *, QListWidgetItem *>::of(&QListWidget::currentItemChanged),
|
||||||
|
// this, &DialogImportModelDataset::handleItemClicked);
|
||||||
|
connect(ui->ModellistWidget, SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
|
||||||
|
this,SLOT(handleItemClicked(QListWidgetItem*, QListWidgetItem*)));
|
||||||
|
}
|
||||||
|
|
||||||
|
DialogImportModelDataset::~DialogImportModelDataset()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
delete _qvtkWidget; // 释放内存
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化模型库
|
||||||
|
void DialogImportModelDataset::initLibrary() {
|
||||||
|
QSettings settings(_librarySettingPath, QSettings::IniFormat);
|
||||||
|
|
||||||
|
QStringList categories = {"forest", "crop", "grass", "uav", "water", "dwater", "road", "geo", "radi", "soil", "land", "vegetation", "water_scene"};
|
||||||
|
QMap<QString, QStringList> models = {
|
||||||
|
{"forest", {"forest.stl"}},
|
||||||
|
{"crop", {"crop.stl"}},
|
||||||
|
{"grass", {"grass.stl"}},
|
||||||
|
{"uav", {"uav.ply", "uav.stl"}},
|
||||||
|
{"water", {"water.stl"}},
|
||||||
|
{"dwater", {"dwater.stl"}},
|
||||||
|
{"road", {"road.ply", "road.stl"}},
|
||||||
|
{"geo", {"geo.stl"}},
|
||||||
|
{"radi", {"radi.stl"}},
|
||||||
|
{"soil", {"soil.ply", "soil.stl"}},
|
||||||
|
{"land", {"land.stl"}},
|
||||||
|
{"vegetation", {"vegetation.stl"}},
|
||||||
|
{"water_scene", {"water_scene.stl"}}
|
||||||
|
};
|
||||||
|
|
||||||
|
settings.beginGroup("Models");
|
||||||
|
for (const QString &category : categories) {
|
||||||
|
settings.setValue(category, models[category]);
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
settings.beginGroup("Detail");
|
||||||
|
for (const QString &category : categories) {
|
||||||
|
for (const QString &model : models[category]) {
|
||||||
|
QString path = QString("../../extlib/model/%1").arg(model);
|
||||||
|
// QString path = QString("D:/WBFZCPP/source/FastCAE/extlib/model/%1").arg(model);
|
||||||
|
settings.setValue(model, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
// Here you can add more initialization code if needed
|
||||||
|
Setting::BusAPI* busapi = Setting::BusAPI::instance(); // 指针调用 -> ,类::静态方法
|
||||||
|
}
|
||||||
|
|
||||||
|
// 模型筛选
|
||||||
|
void DialogImportModelDataset::filterModel(QString filterStr) {
|
||||||
|
QSettings settings(_librarySettingPath, QSettings::IniFormat);
|
||||||
|
|
||||||
|
settings.beginGroup("Models");
|
||||||
|
QString key = getEnglishCategory(filterStr);
|
||||||
|
QStringList models = settings.value(key).toStringList();
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
ui->ModellistWidget->clear();
|
||||||
|
if (!models.isEmpty()) {
|
||||||
|
ui->ModellistWidget->addItems(models);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新 listWidget 的槽函数
|
||||||
|
void DialogImportModelDataset::updateModellistWidget(const QString &filterStr) {
|
||||||
|
filterModel(filterStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据中文分类名称获取英文分类名称
|
||||||
|
QString DialogImportModelDataset::getEnglishCategory(const QString &chineseCategory) {
|
||||||
|
QMap<QString, QString> categories = {
|
||||||
|
{"森林", "forest"},
|
||||||
|
{"农作物", "crop"},
|
||||||
|
{"草地", "grass"},
|
||||||
|
{"人工", "uav"},
|
||||||
|
{"水体", "water"},
|
||||||
|
{"动态水体", "dwater"},
|
||||||
|
{"道路", "road"},
|
||||||
|
{"几何", "geo"},
|
||||||
|
{"辐射", "radi"},
|
||||||
|
{"土壤", "soil"},
|
||||||
|
{"陆表", "land"},
|
||||||
|
{"植被", "vegetation"},
|
||||||
|
{"水体场景", "water_scene"}
|
||||||
|
};
|
||||||
|
return categories.value(chineseCategory, "");
|
||||||
|
}
|
||||||
|
void DialogImportModelDataset::handleItemClicked(QListWidgetItem *current, QListWidgetItem *previous)
|
||||||
|
{
|
||||||
|
qDebug()<<"void DialogImportModelDataset::handleItemClicked(QListWidgetItem *current, QListWidgetItem *previous)";
|
||||||
|
this->importPreViewModel("D:\\WBFZCPP\\source\\FastCAE\\extlib\\model\\crop.stl");
|
||||||
|
this->importMeshModelToMainWindows("D:\\WBFZCPP\\source\\FastCAE\\extlib\\model\\crop.stl");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导入网格
|
||||||
|
void DialogImportModelDataset::importMeshModelToMainWindows(QString stdPath) {
|
||||||
|
QFileInfo info(stdPath);
|
||||||
|
QString name = info.fileName();
|
||||||
|
QString path = info.filePath();
|
||||||
|
QString suffix = "STL(*.stl)"; // 这里应该与 MeshDataExchangePlugin::install() 中的一致
|
||||||
|
//info.suffix().toLower();
|
||||||
|
emit _mainwindow->importMeshSIGN(stdPath,suffix,-1);
|
||||||
}
|
}
|
||||||
DialogImportModelDataset::~DialogImportModelDataset()
|
// 初始化三维模型
|
||||||
{
|
void DialogImportModelDataset::importPreViewModel(QString stdPath) {
|
||||||
delete ui;
|
//清楚所有模型
|
||||||
|
// _render->RemoveAllViewProps();
|
||||||
|
// 在你的主窗口或者其他适当的位置初始化 VTK 相关变量
|
||||||
|
QTextCodec *codec = QTextCodec::codecForName("GB18030");
|
||||||
|
QByteArray ba = codec->fromUnicode(stdPath);
|
||||||
|
vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
|
||||||
|
reader->SetFileName(ba); // 设置 STL 模型文件路径
|
||||||
|
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
|
mapper->SetInputConnection(reader->GetOutputPort());
|
||||||
|
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||||
|
actor->SetMapper(mapper);
|
||||||
|
_render->AddActor(actor);
|
||||||
|
// 更新渲染窗口
|
||||||
|
// _renderWindow->Render();
|
||||||
|
_qvtkWidget->update();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// 初始化模型库
|
void DialogImportModelDataset::initVTKView() {
|
||||||
void DialogImportModelDataset::initLibrary() {
|
// 添加控件
|
||||||
Setting::BusAPI* busapi=Setting::BusAPI::instance(); // 指针调用 -> ,类::静态方法
|
_qvtkWidget = new QVTKOpenGLNativeWidget(this);
|
||||||
// QString executablePath = QApplication::applicationDirPath(); // exe 路径
|
QVBoxLayout *mainLayout = new QVBoxLayout(ui->modelViewContent);
|
||||||
}
|
mainLayout->addWidget(_qvtkWidget);
|
||||||
// 模型筛选
|
|
||||||
void DialogImportModelDataset::filterModel(QString filterStr)
|
// 初始化渲染器
|
||||||
{
|
_renderWindow = _qvtkWidget->renderWindow();
|
||||||
|
_render = vtkSmartPointer<vtkOpenGLRenderer>::New();
|
||||||
|
_render->SetGradientBackground(true);
|
||||||
|
// 设置渲染背景色
|
||||||
|
Setting::GraphOption *option = Setting::BusAPI::instance()->getGraphOption();
|
||||||
|
QColor topcolor = option->getBackgroundTopColor();
|
||||||
|
QColor bottomcolor = option->getBackgroundBottomColor();
|
||||||
|
_render->SetBackground2(topcolor.redF(), topcolor.greenF(), topcolor.blueF());
|
||||||
|
_render->SetBackground(bottomcolor.redF(), bottomcolor.greenF(), bottomcolor.blueF());
|
||||||
|
|
||||||
|
// 开启硬件加速特性
|
||||||
|
_render->UseDepthPeelingOn();
|
||||||
|
_render->SetUseFXAA(true);
|
||||||
|
_interactor = _renderWindow->GetInteractor();
|
||||||
|
_renderWindow->AddRenderer(_render);
|
||||||
}
|
}
|
||||||
|
// void DialogImportModelDataset::on_TestLoadModelImport()
|
||||||
|
// {
|
||||||
|
// WBFZ::DialogImportModelDataset* dialog=new WBFZ::DialogImportModelDataset(_mainwindow);
|
||||||
|
// dialog->importPreViewModel("D:\\WBFZCPP\\source\\FastCAE\\extlib\\model\\crop.stl");
|
||||||
|
// dialog->exec();
|
||||||
|
// dialog->importMeshModelToMainWindows("D:\\WBFZCPP\\source\\FastCAE\\extlib\\model\\crop.stl");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
} // namespace WBFZ
|
} // namespace WBFZ
|
||||||
|
|
|
||||||
|
|
@ -13,40 +13,58 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "ModuleBase/graph3DWindow.h"
|
#include "ModuleBase/graph3DWindow.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include "QVTKOpenGLNativeWidget.h"
|
||||||
|
#include <QMap>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QListWidget>
|
||||||
|
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace WBFZ {
|
namespace WBFZ {
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DialogImportModelDataset;
|
class DialogImportModelDataset;
|
||||||
}
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class DialogImportModelDataset : public QDialog {
|
class DialogImportModelDataset : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DialogImportModelDataset(GUI::MainWindow* _mainwindow,QWidget* parent = nullptr);
|
explicit DialogImportModelDataset(GUI::MainWindow* _mainwindow, QWidget* parent = nullptr);
|
||||||
~DialogImportModelDataset() override;
|
~DialogImportModelDataset() override;
|
||||||
|
|
||||||
public:
|
|
||||||
void importMeshModel();
|
public:
|
||||||
|
|
||||||
public:
|
|
||||||
void initLibrary();
|
void initLibrary();
|
||||||
void filterModel(QString filterStr);// 根据条件筛选
|
void filterModel(QString filterStr);// 根据条件筛选
|
||||||
|
QString getEnglishCategory(const QString &chineseCategory); // 新增中英文转换函数声明
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
// virtual void accept();
|
||||||
|
void updateModellistWidget(const QString &filterStr); // 声明 updateModellistWidget 函数
|
||||||
|
void handleItemClicked(QListWidgetItem *current, QListWidgetItem *previous);
|
||||||
|
// void on_TestLoadModelImport();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GUI::MainWindow* _mainwindow;
|
GUI::MainWindow* _mainwindow;
|
||||||
Ui::DialogImportModelDataset* ui;
|
Ui::DialogImportModelDataset* ui;
|
||||||
QString _librarySettingPath; // ini 配置环境地址
|
QString _librarySettingPath; // ini 配置环境地址
|
||||||
|
|
||||||
|
// 三维模型操作
|
||||||
|
public: // 陈增辉
|
||||||
|
void importMeshModelToMainWindows(QString stdPath); // 最终导入模型
|
||||||
|
void importPreViewModel(QString stdPath); // 导入预览模型
|
||||||
|
void initVTKView();// 初始化VTK视图
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVTKOpenGLNativeWidget *_qvtkWidget; // 三维模型
|
||||||
|
vtkSmartPointer<vtkOpenGLRenderer> _render{};
|
||||||
|
vtkSmartPointer<vtkCubeAxesActor> _cubeAxesActor{};
|
||||||
|
vtkSmartPointer<vtkRenderWindow> _renderWindow{};
|
||||||
|
vtkSmartPointer< vtkRenderWindowInteractor > _interactor{};
|
||||||
};
|
};
|
||||||
} // namespace WBFZ
|
} // namespace WBFZ
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@
|
||||||
<height>16777215</height>
|
<height>16777215</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>模型1</string>
|
<string>模型1</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
@ -161,5 +161,38 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>WBFZ::DialogImportModelDataset</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>679</x>
|
||||||
|
<y>767</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>501</x>
|
||||||
|
<y>402</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>WBFZ::DialogImportModelDataset</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>679</x>
|
||||||
|
<y>767</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>501</x>
|
||||||
|
<y>402</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue