185 lines
7.9 KiB
C++
185 lines
7.9 KiB
C++
#include "P301_PumpPage.h"
|
||
#include "ui_P301_PumpPage.h"
|
||
#include <GlobalDefinitions/Variable.h>
|
||
#include <FileOperation/ConfigFiles.h>
|
||
|
||
|
||
P301_PumpPage::P301_PumpPage(QWidget *parent) :
|
||
QWidget(parent),
|
||
ui(new Ui::P301_PumpPage)
|
||
{
|
||
ui->setupUi(this);
|
||
|
||
WinInit();
|
||
// QTimer::singleShot(0, this, [this]() {
|
||
// Show3D();
|
||
// });
|
||
//QTimer::singleShot(2000, this, &P301_PumpPage::Show3D);
|
||
qDebug()<<"P301_PumpPage 初始化完成!";
|
||
|
||
}
|
||
|
||
P301_PumpPage::~P301_PumpPage()
|
||
{
|
||
delete ui;
|
||
}
|
||
|
||
void P301_PumpPage::WinInit(){
|
||
|
||
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]);
|
||
}
|
||
|
||
// 现在 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);
|
||
|
||
|
||
//所用定时器初始化
|
||
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();
|
||
}
|
||
void P301_PumpPage::Show3D(){
|
||
|
||
DevName3D = "泵站电机";
|
||
// ui->Frame_Dev3D->setStyleSheet("background: transparent;");
|
||
// ui->Frame_Dev3D->setAttribute(Qt::WA_TranslucentBackground);
|
||
mObjLoader = new ObjLoader();
|
||
mObjLoader->init3DScene(ui->Frame_Dev3D);
|
||
mObjLoader->setCameraSpeed(200.0,200.0);
|
||
|
||
|
||
|
||
bool LoaderOK = mObjLoader->loadDevice(DevName3D, "./3D模型文件/掘锚一体机/电机/"+DevName3D+".obj");
|
||
if(!LoaderOK) {qCritical() << "泵站电机加载:失败";return;}
|
||
// mObjLoader->addAxisGizmo(nullptr, 5.0f); // 全局坐标轴(原点)
|
||
// mObjLoader->addAxisGizmo(mObjLoader->getDevice(DevName3D)->entity, 3.0f); // 局部坐标轴
|
||
SetPos(0.005,QVector3D(-407.46, -59.49, 0),QVector3D(0, 0, 0));//409.5, 59.5, 0
|
||
if(LoaderOK){
|
||
// 初始化定时器(作为成员变量)
|
||
QTimer *RotateDev_Timer = new QTimer(this);
|
||
connect(RotateDev_Timer, &QTimer::timeout, this, &P301_PumpPage::RotateDev);
|
||
RotateDev_Timer->setInterval(33);
|
||
RotateDev_Timer->start();
|
||
}
|
||
}
|
||
void P301_PumpPage::SetPos(float Zoom,QVector3D Move,QVector3D Pos){
|
||
|
||
mObjLoader->scaleDevice(DevName3D,Zoom);
|
||
mObjLoader->moveArmLocalOriginTo(DevName3D, Move);//14.1, -1.4, 3.4
|
||
mObjLoader->setParentDevicePosition(DevName3D, Pos); // 世界坐标
|
||
|
||
// 6. 重置相机(确保能看到所有设备)
|
||
Qt3DRender::QCamera* cam = mObjLoader->getCamera();
|
||
if (cam) {
|
||
cam->setPosition(QVector3D(0, 3, 12)); // 相机在 Z 轴 30 位置,远离模型
|
||
cam->setViewCenter(QVector3D(0, 0, 0)); // 看向电控箱体的世界位置
|
||
}
|
||
}
|
||
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());
|
||
|
||
}
|
||
|
||
void P301_PumpPage::RotateDev(){
|
||
mAngle = mAngle + 1;
|
||
if(mAngle > 360) mAngle =0;
|
||
mObjLoader->rotateArmToAbsoluteYAngle(DevName3D, mAngle);
|
||
|
||
}
|