同步了吴夏鑫代码
parent
44b60a6738
commit
3809e1ea04
|
@ -10,31 +10,216 @@
|
|||
// You may need to build the project (run Qt uic code generator) to get
|
||||
// "ui_DialogImportModelDataset.h" resolved
|
||||
|
||||
#include <vtkSTLReader.h>
|
||||
#include <QFileInfo>
|
||||
#include "dialogimportmodeldataset.h"
|
||||
#include "ui_DialogImportModelDataset.h"
|
||||
#include "MainWindow/MainWindow.h"
|
||||
#include "Settings/BusAPI.h"
|
||||
#include "Settings/GraphOption.h"
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
#include <QTextCodec>
|
||||
|
||||
namespace WBFZ {
|
||||
DialogImportModelDataset::DialogImportModelDataset(GUI::MainWindow* _mainwindow,QWidget* parent)
|
||||
: QDialog(parent)
|
||||
,_mainwindow(_mainwindow)
|
||||
, ui(new Ui::DialogImportModelDataset)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->initLibrary();
|
||||
DialogImportModelDataset::DialogImportModelDataset(GUI::MainWindow* _mainwindow, QWidget* parent)
|
||||
: QDialog(_mainwindow),
|
||||
_mainwindow(_mainwindow),
|
||||
ui(new Ui::DialogImportModelDataset)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
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()
|
||||
{
|
||||
delete ui;
|
||||
// 初始化三维模型
|
||||
void DialogImportModelDataset::importPreViewModel(QString stdPath) {
|
||||
//清楚所有模型
|
||||
// _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::initLibrary() {
|
||||
Setting::BusAPI* busapi=Setting::BusAPI::instance(); // 指针调用 -> ,类::静态方法
|
||||
// QString executablePath = QApplication::applicationDirPath(); // exe 路径
|
||||
}
|
||||
// 模型筛选
|
||||
void DialogImportModelDataset::filterModel(QString filterStr)
|
||||
{
|
||||
void DialogImportModelDataset::initVTKView() {
|
||||
// 添加控件
|
||||
_qvtkWidget = new QVTKOpenGLNativeWidget(this);
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(ui->modelViewContent);
|
||||
mainLayout->addWidget(_qvtkWidget);
|
||||
|
||||
// 初始化渲染器
|
||||
_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
|
||||
|
|
|
@ -13,40 +13,58 @@
|
|||
#include <QDialog>
|
||||
#include "ModuleBase/graph3DWindow.h"
|
||||
#include <QString>
|
||||
|
||||
#include "QVTKOpenGLNativeWidget.h"
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
#include <QListWidget>
|
||||
|
||||
|
||||
namespace GUI {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
|
||||
namespace WBFZ {
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class DialogImportModelDataset;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class DialogImportModelDataset : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogImportModelDataset(GUI::MainWindow* _mainwindow,QWidget* parent = nullptr);
|
||||
explicit DialogImportModelDataset(GUI::MainWindow* _mainwindow, QWidget* parent = nullptr);
|
||||
~DialogImportModelDataset() override;
|
||||
|
||||
public:
|
||||
void importMeshModel();
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
void initLibrary();
|
||||
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:
|
||||
GUI::MainWindow* _mainwindow;
|
||||
Ui::DialogImportModelDataset* ui;
|
||||
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
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>模型1</string>
|
||||
</property>
|
||||
|
@ -161,5 +161,38 @@
|
|||
</layout>
|
||||
</widget>
|
||||
<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>
|
||||
|
|
Loading…
Reference in New Issue