Files
HPPA/HPPA/View3DModelManager.cpp
tangchao0503 30e63899a8 1、美化:轮播看板+3d模型看板;
2、优化3d模型看板:使用时加载3D模型,避免内存泄漏,使用QStackedWidget进行切换;
2026-01-29 14:17:27 +08:00

69 lines
1.7 KiB
C++

#include "View3DModelManager.h"
View3DModelManager::View3DModelManager(QWidget* parent)
: QWidget(parent)
{
m_stackedWidget = new QStackedWidget();
m_stackedWidget->setContentsMargins(0, 0, 0, 0);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(m_stackedWidget);
layout->setContentsMargins(0, 0, 0, 0);
}
void View3DModelManager::switchScenario(ScenarioType type)
{
if (type == ScenarioType::PlantPhenotype) {
ensurePlantPhenotypeView();
m_stackedWidget->setCurrentWidget(m_viewPlant);
}
else {
ensureOneMotorView();
m_stackedWidget->setCurrentWidget(m_viewMotor);
}
emit scenarioChanged(type);
}
void View3DModelManager::ensurePlantPhenotypeView()
{
if (m_viewPlant)
return;
QString basePath = QCoreApplication::applicationDirPath();
m_viewPlant = new View3DPlantPhenotype(
basePath + "/3DModel/HPPA_frame.obj",
basePath + "/3DModel/HPPA_camera.obj",
m_stackedWidget
);
m_viewPlant->setViewCenter(1000, 1000, -1000);
m_viewPlant->setDistance(5000);
m_stackedWidget->addWidget(m_viewPlant);
emit created3DModelPlantPhenotype();
}
void View3DModelManager::ensureOneMotorView()
{
if (m_viewMotor)
return;
QString basePath = QCoreApplication::applicationDirPath();
m_viewMotor = new View3DLinearStage(
basePath + "/3DModel/linear_stage_indoor1.obj",
basePath + "/3DModel/linear_stage_indoor2.obj",
m_stackedWidget
);
m_viewMotor->setViewCenter(500, 100, 500);
m_viewMotor->setDistance(1000);
m_stackedWidget->addWidget(m_viewMotor);
emit created3DModelOneMotor();
}