2025-08-20 23:06:28 +08:00
|
|
|
|
#include "P301_PumpPage.h"
|
|
|
|
|
|
#include "ui_P301_PumpPage.h"
|
2025-09-15 22:28:43 +08:00
|
|
|
|
#include <GlobalDefinitions/Variable.h>
|
|
|
|
|
|
#include <FileOperation/ConfigFiles.h>
|
|
|
|
|
|
|
2025-08-20 23:06:28 +08:00
|
|
|
|
|
|
|
|
|
|
P301_PumpPage::P301_PumpPage(QWidget *parent) :
|
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
|
ui(new Ui::P301_PumpPage)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui->setupUi(this);
|
2025-09-15 22:28:43 +08:00
|
|
|
|
|
|
|
|
|
|
WinInit();
|
2025-09-30 15:36:46 +08:00
|
|
|
|
|
|
|
|
|
|
// QTimer::singleShot(2000, this, &P301_PumpPage::Show3D);
|
2025-09-28 17:14:34 +08:00
|
|
|
|
qDebug()<<"P301_PumpPage 初始化完成!";
|
2025-09-15 22:28:43 +08:00
|
|
|
|
|
2025-08-20 23:06:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
P301_PumpPage::~P301_PumpPage()
|
|
|
|
|
|
{
|
|
|
|
|
|
delete ui;
|
|
|
|
|
|
}
|
2025-09-28 17:14:34 +08:00
|
|
|
|
|
2025-09-15 22:28:43 +08:00
|
|
|
|
void P301_PumpPage::WinInit(){
|
|
|
|
|
|
|
2025-09-28 17:14:34 +08:00
|
|
|
|
for (int row = 1; row < PumpConditionConfigFile.size(); ++row)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString TextObjName = QString("Text_SSConditions_%1").arg(row);
|
|
|
|
|
|
QLabel* Label = findChild<QLabel*>(TextObjName);
|
|
|
|
|
|
if (Label) {
|
|
|
|
|
|
QString Text = PumpConditionConfigFile.at(row)[1];
|
|
|
|
|
|
Text.replace("\\n","\n",Qt::CaseInsensitive);
|
|
|
|
|
|
Label->setText(Text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TrueColor.append(PumpConditionConfigFile.at(row)[2]);
|
|
|
|
|
|
FalseColor.append(PumpConditionConfigFile.at(row)[3]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-15 22:28:43 +08:00
|
|
|
|
// 现在 ui->CPW_1 已经是一个 CurvePlotWidget*
|
|
|
|
|
|
ui->CPW_1->addSeries("电机电流U", Qt::green);
|
|
|
|
|
|
ui->CPW_1->addSeries("电机电流V", Qt::blue);
|
|
|
|
|
|
ui->CPW_1->addSeries("电机电流W", Qt::darkCyan);
|
|
|
|
|
|
// 现在 ui->CPW_1 已经是一个 CurvePlotWidget*
|
|
|
|
|
|
ui->CPW_2->addSeries("电机温度", Qt::green);
|
|
|
|
|
|
|
2025-09-28 17:14:34 +08:00
|
|
|
|
|
2025-09-15 22:28:43 +08:00
|
|
|
|
//所用定时器初始化
|
|
|
|
|
|
QTimer* UIRefresh_Timer = new QTimer(this);
|
|
|
|
|
|
connect(UIRefresh_Timer, &QTimer::timeout, this, &P301_PumpPage::UIRefreshTimeOut);
|
|
|
|
|
|
UIRefresh_Timer->setInterval(100); // 设置定时器间隔为 1000 毫秒(1 秒)
|
|
|
|
|
|
UIRefresh_Timer->start();
|
|
|
|
|
|
|
|
|
|
|
|
//所用定时器初始化
|
|
|
|
|
|
QTimer* TrailRefresh_Timer = new QTimer(this);
|
|
|
|
|
|
connect(TrailRefresh_Timer, &QTimer::timeout, this, &P301_PumpPage::TrailRefreshTimeOut);
|
|
|
|
|
|
TrailRefresh_Timer->setInterval(100); // 设置定时器间隔为 1000 毫秒(1 秒)
|
|
|
|
|
|
TrailRefresh_Timer->start();
|
2025-09-28 17:14:34 +08:00
|
|
|
|
}
|
2025-09-30 15:36:46 +08:00
|
|
|
|
void P301_PumpPage::Show3D()
|
|
|
|
|
|
{
|
2025-09-28 17:14:34 +08:00
|
|
|
|
DevName3D = "泵站电机";
|
|
|
|
|
|
mObjLoader = new ObjLoader();
|
2025-09-30 15:36:46 +08:00
|
|
|
|
mObjLoader->setEnDebug(true);
|
2025-09-28 17:14:34 +08:00
|
|
|
|
mObjLoader->init3DScene(ui->Frame_Dev3D);
|
2025-09-30 15:36:46 +08:00
|
|
|
|
mObjLoader->setCameraSpeed(200.0, 200.0);
|
|
|
|
|
|
|
|
|
|
|
|
// 准备模型路径
|
|
|
|
|
|
QString filePath = "./3D模型文件/掘锚一体机/电机/" + DevName3D + ".obj";
|
|
|
|
|
|
m_currentDevName = DevName3D;
|
|
|
|
|
|
m_currentFilePath = filePath;
|
|
|
|
|
|
m_currentPosition = QVector3D(-407.46, -59.49, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// 检查文件是否存在
|
|
|
|
|
|
if (!QFile::exists(filePath)) {
|
|
|
|
|
|
qCritical() << "模型文件不存在: " << filePath;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-09-28 17:14:34 +08:00
|
|
|
|
|
2025-09-30 15:36:46 +08:00
|
|
|
|
// 创建工作线程和工作对象
|
|
|
|
|
|
m_workerThread = new QThread(this);
|
|
|
|
|
|
m_workerLoader = new ObjLoader(); // 专用预处理加载器
|
|
|
|
|
|
|
|
|
|
|
|
// 移动工作对象到工作线程
|
|
|
|
|
|
m_workerLoader->moveToThread(m_workerThread);
|
|
|
|
|
|
|
|
|
|
|
|
// 连接信号槽
|
|
|
|
|
|
connect(m_workerThread, &QThread::started, [=]() {
|
|
|
|
|
|
// 在工作线程中预处理模型(仅计算中心和半径)
|
|
|
|
|
|
QVector3D center = m_workerLoader->parseObjCenter(filePath);
|
|
|
|
|
|
float radius = m_workerLoader->calculateModelRadiusFromFile(filePath);
|
|
|
|
|
|
emit preprocessFinished(center, radius);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 预处理完成后,在主线程加载模型
|
|
|
|
|
|
connect(this, &P301_PumpPage::preprocessFinished, this, [=](QVector3D center, float radius) {
|
|
|
|
|
|
m_modelCenter = center;
|
|
|
|
|
|
m_modelRadius = radius;
|
|
|
|
|
|
|
|
|
|
|
|
// 使用定时器确保在主线程事件循环中执行
|
|
|
|
|
|
QTimer::singleShot(0, this, [=]() {
|
|
|
|
|
|
emit loadModelRequest(m_currentDevName, m_currentFilePath, center, radius);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 清理工作线程
|
|
|
|
|
|
m_workerThread->quit();
|
|
|
|
|
|
m_workerThread->wait();
|
|
|
|
|
|
m_workerLoader->deleteLater();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 主线程中实际加载模型
|
|
|
|
|
|
connect(this, &P301_PumpPage::loadModelRequest, this, [=](const QString& devName, const QString& filePath, QVector3D center, float radius) {
|
|
|
|
|
|
bool LoaderOK = mObjLoader->loadModelAsync(devName, filePath, QVector3D(0, 0, 0), center, radius);
|
|
|
|
|
|
if (!LoaderOK) {
|
|
|
|
|
|
qCritical() << "泵站电机加载:失败";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-09-28 17:14:34 +08:00
|
|
|
|
|
2025-09-30 15:36:46 +08:00
|
|
|
|
mObjLoader->addAxisGizmo(nullptr, 5.0f);
|
|
|
|
|
|
mObjLoader->addAxisGizmo(mObjLoader->getDevice(devName)->entity, 3.0f);
|
|
|
|
|
|
SetPos(0.005,QVector3D(-407.46, -59.49, 0),QVector3D(0, 0, 0));//409.5, 59.5, 0
|
2025-09-28 17:14:34 +08:00
|
|
|
|
|
2025-09-30 15:36:46 +08:00
|
|
|
|
if (LoaderOK) {
|
|
|
|
|
|
QTimer *RotateDev_Timer = new QTimer(this);
|
|
|
|
|
|
connect(RotateDev_Timer, &QTimer::timeout, this, &P301_PumpPage::RotateDev);
|
|
|
|
|
|
RotateDev_Timer->setInterval(33);
|
|
|
|
|
|
RotateDev_Timer->start();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 启动工作线程
|
|
|
|
|
|
m_workerThread->start();
|
2025-09-28 17:14:34 +08:00
|
|
|
|
}
|
2025-09-30 15:36:46 +08:00
|
|
|
|
|
2025-09-28 17:14:34 +08:00
|
|
|
|
void P301_PumpPage::SetPos(float Zoom,QVector3D Move,QVector3D Pos){
|
2025-09-15 22:28:43 +08:00
|
|
|
|
|
2025-09-28 17:14:34 +08:00
|
|
|
|
mObjLoader->scaleDevice(DevName3D,Zoom);
|
|
|
|
|
|
mObjLoader->moveArmLocalOriginTo(DevName3D, Move);//14.1, -1.4, 3.4
|
|
|
|
|
|
mObjLoader->setParentDevicePosition(DevName3D, Pos); // 世界坐标
|
2025-09-15 22:28:43 +08:00
|
|
|
|
|
2025-09-28 17:14:34 +08:00
|
|
|
|
// 6. 重置相机(确保能看到所有设备)
|
|
|
|
|
|
Qt3DRender::QCamera* cam = mObjLoader->getCamera();
|
|
|
|
|
|
if (cam) {
|
|
|
|
|
|
cam->setPosition(QVector3D(0, 3, 12)); // 相机在 Z 轴 30 位置,远离模型
|
|
|
|
|
|
cam->setViewCenter(QVector3D(0, 0, 0)); // 看向电控箱体的世界位置
|
2025-09-15 22:28:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void P301_PumpPage::SetProgressBar(QProgressBar *PB,uint16_t Value,uint8_t ColorIndex,QStringList Color){
|
|
|
|
|
|
PB->setValue(Value);
|
|
|
|
|
|
if(ColorIndex < Color.length()){
|
|
|
|
|
|
PB->setStyleSheet("QProgressBar {\n background-color: transparent;\n border: 2px solid #888888;\n border-radius: 3px;\n}\nQProgressBar::chunk {\n background-color:"+Color[ColorIndex]+";\n}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
void P301_PumpPage::UIRefreshTimeOut()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(this->isHidden())
|
|
|
|
|
|
return;
|
|
|
|
|
|
uint32_t PB_Group1 = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PB_Curr_Pump.PageGroup1"] .toUInt();
|
|
|
|
|
|
uint32_t PB_Group2 = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PB_Curr_Pump.PageGroup2"] .toUInt();
|
|
|
|
|
|
uint32_t PB_GroupOilLevel = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PB_Curr_Pump.PageGroup2"] .toUInt();
|
|
|
|
|
|
uint32_t PB_GroupOilTemp = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PB_Curr_Pump.PageGroup2"] .toUInt();
|
|
|
|
|
|
uint32_t PB_MotorTemp = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PB_Temp_Pump.PageGroup"] .toUInt();
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t SSConditions = gOPC_NodeValue["ns=6;s=::AsGlobalPV:StartStopConditions.Pump"] .toUInt();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t PercentageCurU = static_cast<uint16_t>(PB_Group1 >> 16); // 高 16 位
|
|
|
|
|
|
uint16_t PercentageCurV = static_cast<uint16_t>(PB_Group1 & 0xFFFF);// 低 16 位
|
|
|
|
|
|
uint16_t PercentageCurW = static_cast<uint16_t>(PB_Group2 >> 16); // 高 16 位
|
|
|
|
|
|
uint16_t PercentageTmpColor = static_cast<uint16_t>(PB_Group2 & 0xFFFF);// 低 16 位
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t ColorU = (PercentageTmpColor / 10) % 10;
|
|
|
|
|
|
uint8_t ColorV = (PercentageTmpColor / 100) % 10;
|
|
|
|
|
|
uint8_t ColorW = PercentageTmpColor % 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t PercentageOilLevel = static_cast<uint16_t>(PB_GroupOilLevel >> 16); // 高 16 位
|
|
|
|
|
|
uint16_t ColorOilLevel = static_cast<uint16_t>(PB_GroupOilLevel & 0xFFFF);// 低 16 位
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t PercentageOilTemp = static_cast<uint16_t>(PB_GroupOilTemp >> 16); // 高 16 位
|
|
|
|
|
|
uint16_t ColorOilTemp = static_cast<uint16_t>(PB_GroupOilTemp & 0xFFFF);// 低 16 位
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t PercentageMotorTemp = static_cast<uint16_t>(PB_MotorTemp >> 16); // 高 16 位
|
|
|
|
|
|
uint16_t ColorTemp = static_cast<uint16_t>(PB_MotorTemp & 0xFFFF);// 低 16 位
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetProgressBar(ui->PB_Cur_1,PercentageCurU,ColorU,glMotorCurColor);
|
|
|
|
|
|
SetProgressBar(ui->PB_Cur_2,PercentageCurV,ColorV,glMotorCurColor);
|
|
|
|
|
|
SetProgressBar(ui->PB_Cur_3,PercentageCurW,ColorW,glMotorCurColor);
|
|
|
|
|
|
SetProgressBar(ui->PB_Temp,PercentageMotorTemp,ColorTemp,glMotorTempColor);
|
|
|
|
|
|
SetProgressBar(ui->PB_OilLevel,PercentageOilLevel,ColorOilLevel,slOilLevel);
|
|
|
|
|
|
SetProgressBar(ui->PB_OilTemp,PercentageOilTemp,ColorOilTemp,slOilTemp);
|
|
|
|
|
|
|
|
|
|
|
|
ui->LCD_Cur_1->display( gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_PhasePump.Filtered30_U"] .toReal());
|
|
|
|
|
|
ui->LCD_Cur_2->display( gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_PhasePump.Filtered30_V"] .toReal());
|
|
|
|
|
|
ui->LCD_Cur_3->display( gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_PhasePump.Filtered30_W"] .toReal());
|
|
|
|
|
|
|
|
|
|
|
|
ui->LCD_Temp->display( gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_PhasePump.Filtered_Temp"] .toReal());
|
|
|
|
|
|
ui->LCD_OilLevel->display( gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_Sersor.OilLevel "] .toReal());
|
|
|
|
|
|
ui->LCD_OilTemp->display( gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_Sersor.OilTemp "] .toReal());
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 32; ++i) {
|
|
|
|
|
|
QLabel* Label = findChild<QLabel*>(QString("Text_SSConditions_%1").arg(i));
|
|
|
|
|
|
if (Label) {
|
|
|
|
|
|
QString StyleStr = "border-image: url(:/Frames/null.png);\n";
|
|
|
|
|
|
if(getBitOf32Data(SSConditions, i,false)){
|
|
|
|
|
|
StyleStr = StyleStr + TrueColor[i]+"\n";
|
|
|
|
|
|
}else{
|
|
|
|
|
|
StyleStr = StyleStr + FalseColor[i]+"\n";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Label->setStyleSheet(StyleStr);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void P301_PumpPage::TrailRefreshTimeOut(){
|
|
|
|
|
|
if(this->isHidden())
|
|
|
|
|
|
return;
|
|
|
|
|
|
ui->CPW_1->appendPoint(0, gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_PhaseCut.Filtered30_U"] .toReal());
|
|
|
|
|
|
ui->CPW_1->appendPoint(1, gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_PhaseCut.Filtered30_V"] .toReal());
|
|
|
|
|
|
ui->CPW_1->appendPoint(2, gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_PhaseCut.Filtered30_W"] .toReal());
|
|
|
|
|
|
ui->CPW_2->appendPoint(0,gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_PhaseCut.Filtered_Temp"] .toDouble());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-28 17:14:34 +08:00
|
|
|
|
|
|
|
|
|
|
void P301_PumpPage::RotateDev(){
|
|
|
|
|
|
mAngle = mAngle + 1;
|
|
|
|
|
|
if(mAngle > 360) mAngle =0;
|
|
|
|
|
|
mObjLoader->rotateArmToAbsoluteYAngle(DevName3D, mAngle);
|
|
|
|
|
|
|
|
|
|
|
|
}
|