242 lines
9.9 KiB
C++
242 lines
9.9 KiB
C++
#include "P01_MianPage.h"
|
||
#include "ui_P01_MianPage.h"
|
||
#include <QDebug>
|
||
#include <QMovie>
|
||
#include <QDir>
|
||
#include <QVBoxLayout>
|
||
#include <QTimer>
|
||
#include <GlobalDefinitions/Variable.h>
|
||
#include <QImage>
|
||
|
||
#include <QPainter>
|
||
#include <QPen>
|
||
#include <QImage>
|
||
|
||
|
||
int TransportPosMaxX = 0;
|
||
int TransportPosMaxY = 0;
|
||
|
||
int OldRollerPos[2][2]={{0,0},{0,0}};
|
||
QImage Brush[2];
|
||
|
||
P01_MianPage::P01_MianPage(QWidget *parent) :
|
||
QWidget(parent),
|
||
ui(new Ui::P01_MianPage)
|
||
{
|
||
ui->setupUi(this);
|
||
|
||
|
||
PageInit();
|
||
uiSetHaulSpeed(-200,135);
|
||
uiSetMining(1823);
|
||
|
||
|
||
|
||
}
|
||
|
||
void P01_MianPage::PageInit()
|
||
{
|
||
QPixmap pix(":/Icos/Icos/Sursor.png");
|
||
QCursor custom(pix, pix.width()/2, pix.height()/2);
|
||
setCursor(custom);
|
||
setWindowFlag(Qt::FramelessWindowHint); // 设置窗口无边框,设置后窗口无法移动
|
||
uiInitHaulSpeed(255);
|
||
uiInitMining(-1000,10000);
|
||
uiInitTransportPos(85,85);
|
||
|
||
|
||
QMovie *MLoading = new QMovie("./Gif/Radar.gif");
|
||
//qDebug() << "当前工作文件夹:" << QDir::currentPath();
|
||
ui->Gif_Radar->setMovie(MLoading); // 1. 设置要显示的 GIF 动画图片
|
||
ui->Gif_Radar->setScaledContents(true);
|
||
MLoading->start(); // 2. 启动动画
|
||
ui->Gif_Radar->show();
|
||
|
||
//所用定时器初始化
|
||
QTimer* UIRefresh_Timer = new QTimer(this);
|
||
connect(UIRefresh_Timer, &QTimer::timeout, this, &P01_MianPage::UIRefreshTimeOut);
|
||
UIRefresh_Timer->setInterval(100); // 设置定时器间隔为 1000 毫秒(1 秒)
|
||
UIRefresh_Timer->start();
|
||
|
||
//所用定时器初始化
|
||
QTimer* TrailRefresh_Timer = new QTimer(this);
|
||
connect(TrailRefresh_Timer, &QTimer::timeout, this, &P01_MianPage::TrailRefreshTimeOut);
|
||
TrailRefresh_Timer->setInterval(1000); // 设置定时器间隔为 1000 毫秒(1 秒)
|
||
TrailRefresh_Timer->start();
|
||
}
|
||
P01_MianPage::~P01_MianPage()
|
||
{
|
||
delete ui;
|
||
}
|
||
uint32_t TCount =0 ;
|
||
void P01_MianPage::UIRefreshTimeOut()
|
||
{
|
||
if(this->isHidden())
|
||
return;
|
||
uint32_t Diameter = gOPC_NodeValue["ns=6;s=::AsGlobalPV:RollerPosition.Diameter"] .toUInt();
|
||
float CenterHeight = gOPC_NodeValue["ns=6;s=::AsGlobalPV:RollerPosition.CenterHeight"] .toFloat();
|
||
uint16_t Roller_Diameter_mm = static_cast<int16_t>(Diameter & 0xFFFF); // 低 16 位
|
||
|
||
|
||
|
||
ui->Slider_Mining1->setValue(CenterHeight*1000);
|
||
ui->LCD_MiningB1->display(QString::number(CenterHeight - Roller_Diameter_mm * 0.001, 'f', 2));
|
||
ui->LCD_MiningT1->display(QString::number(CenterHeight + Roller_Diameter_mm * 0.001, 'f', 2));
|
||
|
||
PB_Refresh("Pump");
|
||
PB_Refresh("Cut");
|
||
PB_Refresh("LoaderL");
|
||
PB_Refresh("LoaderR");
|
||
PB_Refresh("TransportL");
|
||
PB_Refresh("TransportR");
|
||
PB_Refresh("Standby");
|
||
|
||
}
|
||
void P01_MianPage::PB_Refresh(QString Dev){
|
||
uint32_t PB_Group1 = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PB_Curr_"+Dev+".PageGroup1"] .toUInt();
|
||
uint32_t PB_Group2 = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PB_Curr_"+Dev+".PageGroup2"] .toUInt();
|
||
uint32_t PB_MotorTemp = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PB_Temp_"+Dev+".PageGroup"] .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 PercentageMotorTemp = static_cast<uint16_t>(PB_MotorTemp >> 16); // 高 16 位
|
||
uint16_t ColorTemp = static_cast<uint16_t>(PB_MotorTemp & 0xFFFF);// 低 16 位
|
||
|
||
qreal CurrU = gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_Phase"+Dev+".Filtered30_U"] .toReal();
|
||
qreal CurrV = gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_Phase"+Dev+".Filtered30_V"] .toReal();
|
||
qreal CurrW = gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_Phase"+Dev+".Filtered30_W"] .toReal();
|
||
qreal Temp = gOPC_NodeValue["ns=6;s=::AsGlobalPV:IN_Phase"+Dev+".Filtered_Temp"] .toReal();
|
||
qreal Curr = fmax(CurrU,fmax(CurrV,CurrW));
|
||
|
||
qreal Rated;
|
||
if (Dev == "LoaderL" || Dev == "LoaderR" )
|
||
Rated = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PS.gRatedCur_Loader"] .toReal();
|
||
else if(Dev == "TransportL" || Dev == "TransportR" )
|
||
Rated = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PS.gRatedCur_Transport"] .toReal();
|
||
else{
|
||
Rated = gOPC_NodeValue["ns=6;s=::AsGlobalPV:PS.gRatedCur_"+Dev] .toReal();
|
||
}
|
||
|
||
|
||
QProgressBar* CurPB_1 = findChild<QProgressBar*>("PB_Cur"+Dev+"_1");
|
||
QProgressBar* CurPB_2 = findChild<QProgressBar*>("PB_Cur"+Dev+"_2");
|
||
QProgressBar* CurPB_3 = findChild<QProgressBar*>("PB_Cur"+Dev+"_3");
|
||
QProgressBar* TempPB = findChild<QProgressBar*>("PB_Temp"+Dev);
|
||
|
||
QLCDNumber* CurLCD_1 = findChild<QLCDNumber*>("LCD_Cur"+Dev+"_1");
|
||
QLCDNumber* CurLCD_2 = findChild<QLCDNumber*>("LCD_Cur"+Dev+"_2");
|
||
QLCDNumber* CurLCD_3 = findChild<QLCDNumber*>("LCD_Cur"+Dev+"_3");
|
||
QLCDNumber* CurLCD = findChild<QLCDNumber*>("LCD_Cur"+Dev);
|
||
QLCDNumber* TempLCD = findChild<QLCDNumber*>("LCD_Temp"+Dev);
|
||
|
||
QLabel* CurRated_Label = findChild<QLabel*>("Label_UnitCur"+Dev);
|
||
SetProgressBar(CurPB_1,PercentageCurU,ColorU,glMotorCurColor);
|
||
SetProgressBar(CurPB_2,PercentageCurV,ColorV,glMotorCurColor);
|
||
SetProgressBar(CurPB_3,PercentageCurW,ColorW,glMotorCurColor);
|
||
SetProgressBar(TempPB,PercentageMotorTemp,ColorTemp,glMotorTempColor);
|
||
|
||
CurLCD_1->display(QString::number(CurrU,'f',2));
|
||
CurLCD_2->display(QString::number(CurrV,'f',2));
|
||
CurLCD_3->display(QString::number(CurrW,'f',2));
|
||
CurLCD->display(QString::number(Curr,'f',2));
|
||
TempLCD->display(QString::number(Temp,'f',2));
|
||
CurRated_Label->setText("A/"+QString::number(Rated,'f',1)+"A");
|
||
|
||
}
|
||
void P01_MianPage::SetProgressBar(QProgressBar *PB,uint16_t Value,uint8_t ColorIndex,QStringList Color){
|
||
PB->setValue(Value);
|
||
if(ColorIndex < Color.length()){
|
||
QString Style = "QProgressBar {\n background-color: transparent;\n border: 2px solid #888888;\n border-radius: 3px;\n}\nQProgressBar::chunk {\n background-color:"+Color[ColorIndex]+";\n}";
|
||
if(PB->styleSheet() != Style){
|
||
PB->setStyleSheet(Style);
|
||
}
|
||
}
|
||
}
|
||
uint16_t OldRoller_Length = 0;
|
||
void P01_MianPage::TrailRefreshTimeOut(){
|
||
if(this->isHidden())
|
||
return;
|
||
|
||
uint32_t Diameter = gOPC_NodeValue["ns=6;s=::AsGlobalPV:RollerPosition.Diameter"] .toUInt();
|
||
uint32_t LengthHeight = gOPC_NodeValue["ns=6;s=::AsGlobalPV:RollerPosition.LengthHeight"] .toUInt();
|
||
uint32_t SideView = gOPC_NodeValue["ns=6;s=::AsGlobalPV:RollerPosition.SideView"] .toUInt();
|
||
uint32_t FaceView = gOPC_NodeValue["ns=6;s=::AsGlobalPV:RollerPosition.FaceView"] .toUInt();
|
||
uint16_t Roller_Diameter_Img = static_cast<int16_t>(Diameter >> 16); // 高 16 位
|
||
uint32_t TransPos = gOPC_NodeValue["ns=6;s=::AsGlobalPV:RollerPosition.TransportPos"] .toUInt();
|
||
|
||
|
||
int16_t Roller_SideX = static_cast<int16_t>(SideView >> 16); // 高 16 位
|
||
int16_t Roller_SideY = static_cast<int16_t>(SideView & 0xFFFF);// 低 16 位
|
||
int16_t Roller_FaceX = static_cast<int16_t>(FaceView >> 16); // 高 16 位
|
||
int16_t Roller_FaceY = static_cast<int16_t>(FaceView & 0xFFFF);// 低 16 位
|
||
int16_t Roller_Length = static_cast<int16_t>(LengthHeight >> 16); // 高 16 位
|
||
int16_t Roller_Height = static_cast<int16_t>(LengthHeight & 0xFFFF); // 低 16 位
|
||
int16_t TransPos_SideX = static_cast<int16_t>(TransPos >> 16); // 高 16 位
|
||
int16_t TransPos_SideY = static_cast<int16_t>(TransPos & 0xFFFF);// 低 16 位
|
||
|
||
if(Brush[0].isNull()){
|
||
Brush[0] = QImage(":/Devices/Devices/ICO_Cutting1.png");
|
||
Brush[0] = Brush[0].scaled(Roller_Diameter_Img, Roller_Diameter_Img, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||
ui->TrailDisplay_1->setBrushImage(Brush[0]);
|
||
}
|
||
if(Brush[1].isNull() || OldRoller_Length != Roller_Length){
|
||
Brush[1] = QImage(Roller_Length, Roller_Diameter_Img, QImage::Format_ARGB32);
|
||
Brush[1].fill(Qt::green);
|
||
ui->TrailDisplay_2->setBrushImage(Brush[1]);
|
||
OldRoller_Length = Roller_Length;
|
||
}
|
||
uiRollerPosition(0,Roller_SideX,Roller_SideY);
|
||
uiRollerPosition(1,Roller_FaceX,Roller_FaceY);
|
||
uiSetTransportPos(TransPos_SideX,TransPos_SideY);
|
||
}
|
||
void P01_MianPage::uiRollerPosition(uint8_t Index,uint16_t aX,uint16_t aY){
|
||
//qDebug()<<Index<<aX<<aY<<OldRollerPos[Index][0]<<OldRollerPos[Index][1] ;
|
||
if(OldRollerPos[Index][0] != aX || OldRollerPos[Index][1] != aY){
|
||
QPoint localPos(aX,aY);
|
||
if(Index == 0)
|
||
ui->TrailDisplay_1->moveBrush(localPos);
|
||
else
|
||
ui->TrailDisplay_2->moveBrush(localPos);
|
||
}
|
||
OldRollerPos[Index][0] = aX;
|
||
OldRollerPos[Index][1] = aY;
|
||
}
|
||
void P01_MianPage::uiInitHaulSpeed(int Max){
|
||
ui->Slider_Haul_L->setMinimum(0-Max);
|
||
ui->Slider_Haul_L->setMaximum(Max);
|
||
ui->Slider_Haul_R->setMinimum(0-Max);
|
||
ui->Slider_Haul_R->setMaximum(Max);
|
||
}
|
||
void P01_MianPage::uiInitMining(int Max,int Min){
|
||
ui->Slider_Mining1->setMinimum(Min);
|
||
ui->Slider_Mining1->setMaximum(Max);
|
||
}
|
||
void P01_MianPage::uiInitTransportPos(int MaxX,int MaxY){
|
||
TransportPosMaxX = MaxX;
|
||
TransportPosMaxY = MaxY;
|
||
}
|
||
void P01_MianPage::uiSetHaulSpeed(int SpeedL,int SpeedR){
|
||
ui->Slider_Haul_L->setValue(SpeedL);
|
||
ui->LCD_MainHaul_L->display(QString::number(SpeedL));
|
||
ui->Slider_Haul_R->setValue(SpeedR);
|
||
ui->LCD_MainHaul_R->display(QString::number(SpeedR));
|
||
}
|
||
void P01_MianPage::uiSetMining(int Value){
|
||
ui->Slider_Mining1->setValue(Value);
|
||
ui->LCD_MiningT1->display(QString::number(Value/1000.0,'f',2));
|
||
ui->LCD_MiningB1->display(QString::number(Value/1000.0,'f',2));
|
||
}
|
||
void P01_MianPage::uiSetTransportPos(int rx,int ry){
|
||
int NewRX = 850+(130/2)+rx-10;
|
||
int NewRY = 10+(130/2)+ry-7;
|
||
//qDebug()<<NewRX<<NewRY;
|
||
ui->Label_TransportPos->move(NewRX,NewRY);
|
||
}
|