#include "CMainWin.h" #include #include #include #include #include #include #include #include "quserinfo_global.h" #include "Serialport_global.h" #include "WfCtrl.h" #include "lpGlobalConfig.h" #include "lpGlobalData.h" #include "lpSysConfig.h" #include "lpSysLog.h" #include "lpCryptokey.h" #include "saveimgthread.h" #include "QDiskCleanThread.h" #define LEAPER_LOGO ":/leaper/Resource/app.png" #define WINDOWS_ICON ":/leaper/Resource/app.png" #define DELETE_POINTER(p) if (p) {delete p; p = NULL;} #pragma execution_character_set("utf-8") static QImage cvMat2QImage(const cv::Mat& mat) { if (mat.type() == CV_8UC1) { QImage image(mat.cols, mat.rows, QImage::Format_Indexed8); image.setColorCount(256); for (int i = 0; i < 256; i++) { image.setColor(i, qRgb(i, i, i)); } uchar *pSrc = mat.data; for (int row = 0; row < mat.rows; row++) { uchar *pDest = image.scanLine(row); memcpy(pDest, pSrc, mat.cols); pSrc += mat.step; } return image; } else if (mat.type() == CV_8UC3) { const uchar *pSrc = (const uchar*)mat.data; QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_RGB888); if (image.isNull()) return QImage(); return image.rgbSwapped(); } else if (mat.type() == CV_8UC4) { const uchar *pSrc = (const uchar*)mat.data; QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_ARGB32); return image.copy(); } else { qDebug() << "ERROR: Mat could not be converted to QImage."; return QImage(); } } static cv::Mat QImageToMat(QImage image) { cv::Mat mat; switch (image.format()) { case QImage::Format_ARGB32: case QImage::Format_RGB32: case QImage::Format_ARGB32_Premultiplied: mat = cv::Mat(image.height(), image.width(), CV_8UC4, (void*)image.constBits(), image.bytesPerLine()); break; case QImage::Format_RGB888: mat = cv::Mat(image.height(), image.width(), CV_8UC3, (void*)image.constBits(), image.bytesPerLine()); cv::cvtColor(mat, mat, CV_BGR2RGB); break; case QImage::Format_Grayscale8: case QImage::Format_Indexed8: mat = cv::Mat(image.height(), image.width(), CV_8UC1, (void*)image.constBits(), image.bytesPerLine()); break; } return mat; } CMainWin::CMainWin(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); lpSysLog::instance()->Init(); lpSysConfig::instance()->readConfig(); lpSysConfig::instance()->writeConfig(); lpGlobalConfig::instance()->readConfig(); setWindowIcon(QIcon(LEAPER_LOGO)); onInitCoreCtrl(); onInitSerial(); onInitUser(); onInitUI(); onInitStatus(); onInitDiskClean(); SYSLOG_STATUS << "系统启动"; { QString strPath = QCoreApplication::applicationDirPath(); QString DBFilePath = strPath + "\\DBFiles"; QDir dbDir; dbDir.mkpath(DBFilePath); m_db = new StationDB(DBFilePath + "\\AntMan.db"); m_db->InitDatabase(); } m_pCameraTrig = new AutoTrigger; connect(m_pCameraTrig, SIGNAL(sgTrig()), this, SLOT(onTrigImage())); connect(&m_devMgrWid, SIGNAL(sgChangeLanguage(QString)), this, SLOT(onLanguageChange(QString))); connect(&m_testWid, SIGNAL(sgTestMode(int)), this, SLOT(onTestMode(int))); m_pWfCtrl = new CWfCtrl(m_pDetectorEngine); m_pWfCtrl->onInit(); m_mangeWid.onInitModelList(m_pWfCtrl); QStringList strList = m_pWfCtrl->IGetStationKeys(); foreach(QString str, strList) { IStation *pS = m_pWfCtrl->IGetStationByKey(str); connect(pS, SIGNAL(sgShowModeName(QString, QString)), this, SLOT(onShowName(QString, QString))); } { // if (m_pDetectorEngine) // { // QStringList Names = m_pDetectorEngine->getSolutionMgr()->GetAllSolutions().keys(); // // } } m_pWfCtrl->ISelModel(lpGlobalConfig::instance()->m_StationSolution_1, lpGlobalConfig::instance()->m_StationRunModel_1); m_pWfCtrl->ISelModel(lpGlobalConfig::instance()->m_StationSolution_2, lpGlobalConfig::instance()->m_StationRunModel_2); m_pImageCaliUI = new lpImageCaliUI();//图像标定页面 lpGlobalData::instance()->m_bCheckLinese = lpCheckKey::instance()->checkLinese(); m_pCheckLineseUI = new QCryptokeyUI(); connect(m_pCheckLineseUI, SIGNAL(sgRegisterFinish(bool)), this, SLOT(onLineseCheck(bool))); onLineseCheck(lpGlobalData::instance()->m_bCheckLinese); m_TimerID_Status = startTimer(1000); } CMainWin::~CMainWin() { DELETE_POINTER(m_pCameraTrig); if (m_db) { delete m_db; m_db = NULL; } if (m_pUserCtrl) { delete m_pUserCtrl; m_pUserCtrl = NULL; } if (m_pSerialPort) { m_HeartBit.stop(); m_pSerialPort->CloseCom(); delete m_pSerialPort; m_pSerialPort = NULL; } if (m_pDesigner) { delete m_pDesigner; m_pDesigner = nullptr; } if (m_pDllDesigner) { delete m_pDllDesigner; m_pDllDesigner = nullptr; } if (m_pDllDetectorEngine) { delete m_pDllDetectorEngine; m_pDllDetectorEngine = nullptr; } //load coretrl if (m_pDllCoreCtrl) { delete m_pDllCoreCtrl; m_pDllCoreCtrl = nullptr; } if (m_pWfCtrl) { delete m_pWfCtrl; m_pWfCtrl = nullptr; } if (m_pLabelInfo) { delete m_pLabelInfo; m_pLabelInfo = nullptr; } if (m_pLbCurrentTime) { delete m_pLbCurrentTime; m_pLbCurrentTime = nullptr; } if (m_pLbOnLine) { delete m_pLbOnLine; m_pLbOnLine = nullptr; } if (m_pLbUser) { delete m_pLbUser; m_pLbUser = nullptr; } if (m_pLbConnect) { delete m_pLbConnect; m_pLbConnect = nullptr; } if (m_pImageCaliUI) { delete m_pImageCaliUI; m_pImageCaliUI = nullptr; } if (m_pCheckLineseUI) { delete m_pCheckLineseUI; m_pCheckLineseUI = nullptr; } if (m_pDCThreadList.size() > 0){ for (int nIndex = 0; nIndex < m_pDCThreadList.size(); nIndex++) { QDiskCleanThread *pDCThread = m_pDCThreadList.at(nIndex); if (pDCThread) { pDCThread->ExitThread(); pDCThread->quit(); pDCThread->wait(); delete pDCThread; pDCThread = NULL; } } } m_pDCThreadList.clear(); lpSysConfig::uninstance(); rmTranslator(); lpSysLog::uninstance(); } //相机原图接收回调 用于展示图像 void CMainWin::INewCameraImage(const QString& camKey, QImage img) { emit sgShowSrcImg(camKey, img); QString solutionName; QString strRunModel; int stationID = 0; if (camKey == lpGlobalConfig::instance()->m_StationCamKey_1) { solutionName = lpGlobalConfig::instance()->m_StationSolution_1; strRunModel = lpGlobalConfig::instance()->m_StationRunModel_1; stationID = 1; } else if (camKey == lpGlobalConfig::instance()->m_StationCamKey_2) { solutionName = lpGlobalConfig::instance()->m_StationSolution_2; strRunModel = lpGlobalConfig::instance()->m_StationRunModel_2; stationID = 2; } onShowImage(stationID, img); if (solutionName.isEmpty()) { } else { QString strMode = strRunModel; cv::Mat srcMat = QImageToMat(img); AlgResultCallBack func = std::bind(&CMainWin::IEngineResult, this, std::placeholders::_1); m_pDetectorEngine->detectByName(srcMat, solutionName, strMode, func); } } //算法结果接收 void CMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap) { } QVariant CMainWin::IGetVariantById(int id) { return QVariant(); } QString CMainWin::genSaveSrcImgPath(int stationID, QString modelName, QImage &img) { QString strStation = (stationID == 1 ? "Station1" : "Station2"); QString strApp = QApplication::applicationDirPath(); QString targetPath = strApp + "/DBFiles/SrcImages"; QString strData = QDateTime::currentDateTime().toString("yyyy-MM-dd"); QString strFileName = QDateTime::currentDateTime().toString("yyyy_MM_dd_hhmmsszzz") + ".jpg"; targetPath = targetPath + "/" + strData + "/" + strStation + "/" + modelName; QDir dir; dir.mkpath(strApp + targetPath); if (!img.isNull()) { saveImage(img, targetPath, strFileName); } targetPath = targetPath + "/" + strFileName; return targetPath; } QString CMainWin::genSavePath(int stationID, QString modelName, QImage &img) { QString strStation = (stationID == 1 ? "Station1" : "Station2"); QString strApp = QApplication::applicationDirPath(); QString targetPath = strApp + "/DBFiles/Images"; QString strData = QDateTime::currentDateTime().toString("yyyy-MM-dd"); QString strFileName = QDateTime::currentDateTime().toString("yyyy_MM_dd_hhmmsszzz") + ".jpg"; targetPath = targetPath + "/" + strData + "/" + strStation + "/"+ modelName; QDir dir; dir.mkpath(strApp + targetPath); if (!img.isNull()) { saveImage(img, targetPath, strFileName); } targetPath = targetPath + "/" + strFileName; return targetPath; } Q_SLOT void CMainWin::onAppanalysis(SComFrame frame) { //数据接收 int nCmd = frame.cmd; if (0x43 == nCmd)//心跳 型号切换 { onHeartComm(frame); m_heartTimeOut = 0; m_bPLCConnect = true; return; } else if (0x50 == nCmd) {//触发相机 int nCameraID = -1; if (5 == frame.data1) { nCameraID = 1; } else if (6 == frame.data1) { nCameraID = 2; } if (lpGlobalConfig::instance()->m_bOnlineMode == true)//是PLC控制台切换型号模式 进入型号判断 { if (nCameraID == 1) { if (m_StationInfo_1.m_bRunEnable == true) { QString strCam = lpGlobalConfig::instance()->m_StationCamKey_1; m_pCoreCtrl->ISnapImage(QStringList() << strCam); } else { QString strMsg = QString("%1:该型号ID:%2在模型库中不存在,不能拍照!!!").arg(QTime::currentTime().toString("hh:mm:ss zzz:")).arg(m_StationInfo_1.m_PLCID); emit sgShowLog(1, strMsg); if (m_StationInfo_1.m_PLCID > 0) { sendResult(1, 999, 0, 0); SYSLOG_STATUS << QString("●工位%1:收到触发信号,因索引不合法所以没触发相机拍照,发送了999角度数据,型号为[%2],型号索引ID为[%3],时间:%4") .arg(nCameraID) .arg(m_StationInfo_1.strModelName.isEmpty() == true ? "空" : m_StationInfo_1.strModelName) .arg(m_StationInfo_1.m_PLCID) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); } else { SYSLOG_STATUS << QString("●工位%1:收到触发信号,因索引不合法所以没触发相机拍照,型号为[%2],型号索引ID为[%3],时间:%4") .arg(nCameraID) .arg(m_StationInfo_1.strModelName.isEmpty() == true ? "空" : m_StationInfo_1.strModelName) .arg(m_StationInfo_1.m_PLCID) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); } } } else if (nCameraID == 2) { if (m_StationInfo_2.m_bRunEnable == true) { QString strCam = lpGlobalConfig::instance()->m_StationCamKey_2; m_pCoreCtrl->ISnapImage(QStringList() << strCam); } else { QString strMsg = QString("%1:该型号ID:%2在模型库中不存在,不能拍照!!!").arg(QTime::currentTime().toString("hh:mm:ss zzz:")).arg(m_StationInfo_2.m_PLCID); emit sgShowLog(2, strMsg); if (m_StationInfo_2.m_PLCID > 0) { sendResult(2, 999, 0, 0); SYSLOG_STATUS << QString("●工位%1:收到触发信号,因索引不合法所以没触发相机拍照,发送了999角度数据,型号为[%2],型号索引ID为[%3],时间:%4") .arg(nCameraID) .arg(m_StationInfo_2.strModelName.isEmpty() == true ? "空" : m_StationInfo_2.strModelName) .arg(m_StationInfo_2.m_PLCID) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); } else { SYSLOG_STATUS << QString("●工位%1:收到触发信号,因索引不合法所以没触发相机拍照,型号为[%2],型号索引ID为[%3],时间:%4") .arg(nCameraID) .arg(m_StationInfo_2.strModelName.isEmpty() == true ? "空" : m_StationInfo_2.strModelName) .arg(m_StationInfo_2.m_PLCID) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); } } } } else//不是PLC切换型号模式 可以触发拍照 { if (nCameraID == 1) { QString strCam = lpGlobalConfig::instance()->m_StationCamKey_1; m_pCoreCtrl->ISnapImage(QStringList() << strCam); } else if (nCameraID == 2) { QString strCam = lpGlobalConfig::instance()->m_StationCamKey_2; m_pCoreCtrl->ISnapImage(QStringList() << strCam); } } } else if (0xf1 == nCmd) {//接收到下位机的命令关闭所有窗口 关机 qApp->closeAllWindows(); } } void CMainWin::onHeartComm(SComFrame &frame) { static int nS1 = -1; static int nS2 = -1; if (lpGlobalConfig::instance()->m_bOnlineMode == true) { int nSta1 = frame.data1; int nSta2 = frame.data2; if (nS1 != nSta1 || nS2 != nSta2) { nS1 = nSta1; nS2 = nSta2; } else return; QStringList lstKeys = m_pWfCtrl->IGetStationKeys(); for each (QString var in lstKeys) { IStation *pStation = m_pWfCtrl->IGetStationByKey(var); if (!pStation) { continue; } int mmCmd = 0; if (var == lpGlobalConfig::instance()->m_StationSolution_1) { mmCmd = frame.data1; QString strModel = pStation->modelByPlcCmd(mmCmd); if (!strModel.isEmpty()) { if (m_StationInfo_1.m_PLCID != mmCmd) { m_StationInfo_1.m_PLCID = mmCmd; m_StationInfo_1.strModelName = strModel; SYSLOG_STATUS << QString("★工位%1:切换型号为[%2],型号索引ID为[%3],时间:%4") .arg(1) .arg(strModel) .arg(mmCmd) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); if (m_pWfCtrl) { m_pWfCtrl->ISelModel(var, strModel); } } m_StationInfo_1.m_bRunEnable = true; } else { if (m_StationInfo_1.m_PLCID != mmCmd) { m_StationInfo_1.m_PLCID = mmCmd; m_StationInfo_1.strModelName = strModel; if (mmCmd <= 0) SYSLOG_STATUS << QString("★工位%1:型号清零,型号索引ID为[%2],时间:%3") .arg(1) .arg(mmCmd) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); else SYSLOG_STATUS << QString("★工位%1:型号切换失败,对应的索引不存在,型号索引ID为[%2],时间:%3") .arg(1) .arg(mmCmd) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); } m_StationInfo_1.m_bRunEnable = false; if (mmCmd > 0) { QString strMsg = QString("%1:型号设置失败,模型库中不存在索引%2").arg(QTime::currentTime().toString("hh:mm:ss zzz:")).arg(mmCmd); emit sgShowLog(1, strMsg); } } } else if (var == lpGlobalConfig::instance()->m_StationSolution_2) { mmCmd = frame.data2; QString strModel = pStation->modelByPlcCmd(mmCmd); if (!strModel.isEmpty()) { if (m_StationInfo_2.m_PLCID != mmCmd) { m_StationInfo_2.m_PLCID = mmCmd; m_StationInfo_2.strModelName = strModel; SYSLOG_STATUS << QString("★工位%1:切换型号为[%2],型号索引ID为[%3],时间:%4") .arg(2) .arg(strModel) .arg(mmCmd) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); if (m_pWfCtrl) { m_pWfCtrl->ISelModel(var, strModel); } } m_StationInfo_2.m_bRunEnable = true; } else { if (m_StationInfo_2.m_PLCID != mmCmd) { m_StationInfo_2.m_PLCID = mmCmd; m_StationInfo_2.strModelName = strModel; if (mmCmd <= 0) SYSLOG_STATUS << QString("★工位%1:型号清零,型号索引ID为[%2],时间:%3") .arg(2) .arg(mmCmd) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); else SYSLOG_STATUS << QString("★工位%1:型号切换失败,对应的索引不存在,型号索引ID为[%2],时间:%3") .arg(2) .arg(mmCmd) .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); } m_StationInfo_2.m_bRunEnable = false; if (mmCmd > 0) { QString strMsg = QString("%1:型号设置失败,模型库中不存在索引%2").arg(QTime::currentTime().toString("hh:mm:ss zzz:")).arg(mmCmd); emit sgShowLog(2, strMsg); } } } } } } Q_SLOT void CMainWin::onHeardBit() { if (m_pSerialPort) { SComFrame frame; memset(&frame, 0, sizeof(SComFrame)); frame.cmd = 0x43; frame.data7 = 200; frame.data8 = 0x50; m_pSerialPort->enquequeData(frame); } } Q_SLOT void CMainWin::onActionClicked() { QString strObj = sender()->objectName(); if ("actionSetting" == strObj) {//标定 if (m_pDesigner) { m_pDesigner->ShowMainFrame(this); } } else if ("actionManage" == strObj) {//模板管理 m_mangeWid.setParent(this); m_mangeWid.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); m_mangeWid.setWindowModality(Qt::ApplicationModal); m_mangeWid.setAttribute(Qt::WA_ShowModal, true); m_mangeWid.show(); } else if ("actionTest" == strObj) {//测试 m_testWid.setParent(this); m_testWid.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); m_testWid.setWindowModality(Qt::ApplicationModal); m_testWid.setAttribute(Qt::WA_ShowModal, true); m_testWid.show(); } else if ("actionHelp" == strObj) {//帮助 m_aboutWid.setParent(this); m_aboutWid.setWindowIcon(QIcon(LEAPER_LOGO)); m_aboutWid.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); m_aboutWid.setWindowModality(Qt::ApplicationModal); m_aboutWid.setAttribute(Qt::WA_ShowModal, true); m_aboutWid.show(); } else if ("action_Check" == strObj) {//历史记录查询 QProcess process; process.setWorkingDirectory(QCoreApplication::applicationDirPath()); #ifdef _DEBUG QString strTaskName = "Reportd.exe"; #else QString strTaskName = "Report.exe"; #endif process.startDetached(strTaskName); } else if ("actionSystem" == strObj) {//系统参数设置 m_devMgrWid.setParent(this); m_devMgrWid.setWindowIcon(QIcon(LEAPER_LOGO)); m_devMgrWid.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); m_devMgrWid.setWindowModality(Qt::ApplicationModal); m_devMgrWid.setAttribute(Qt::WA_ShowModal, true); QStringList camkeys = m_pCoreCtrl->ICameraKeys(); QStringList solutions = m_pDetectorEngine->getSolutionMgr()->GetAllSolutions().keys(); m_devMgrWid.setSystemConfig(camkeys, solutions); m_devMgrWid.show(); } else if ("main_Login_action" == strObj) {//用户登陆 if (m_pUserCtrl) { if (m_pUserCtrl->getLoginState() == EM_LOGIN) { QMessageBox infobox(QMessageBox::Information, QString(QObject::tr("提示")), QString(QObject::tr("你确定要注销%1 ?")).arg(m_pUserCtrl->CurUser()), QMessageBox::Yes | QMessageBox::No, NULL); infobox.setWindowIcon(QIcon(":/image/leaper")); infobox.setButtonText(QMessageBox::Yes, QString("确认")); infobox.setButtonText(QMessageBox::No, QString("取消")); if (infobox.exec() == QMessageBox::Yes) { m_pUserCtrl->LogOutUser(); } } else m_pUserCtrl->CheckLogin(this); } else { QMessageBox infobox(QMessageBox::Information, QString(QObject::tr("提示")), QString(QObject::tr("该功能未启用.")), QMessageBox::Yes, NULL); infobox.setWindowIcon(QIcon(":/image/leaper")); infobox.setButtonText(QMessageBox::Yes, QString(QObject::tr("确认"))); infobox.exec(); } } else if ("main_action_userManager" == strObj) {//用户管理 if (m_pUserCtrl) { m_pUserCtrl->ShowUserMgrDlg(this); } else { QMessageBox infobox(QMessageBox::Information, QString(QObject::tr("提示")), QString(QObject::tr("该功能未启用.")), QMessageBox::Yes, NULL); infobox.setWindowIcon(QIcon(":/image/leaper")); infobox.setButtonText(QMessageBox::Yes, QString(QObject::tr("确认"))); infobox.exec(); } } else if ("actionStandard" == strObj) { if (m_pImageCaliUI) { m_pImageCaliUI->setParent(this); m_pImageCaliUI->setWindowTitle(tr("图像标定")); m_pImageCaliUI->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); m_pImageCaliUI->setWindowIcon(QIcon(WINDOWS_ICON)); m_pImageCaliUI->setWindowModality(Qt::ApplicationModal); m_pImageCaliUI->setAttribute(Qt::WA_ShowModal, true); m_pImageCaliUI->show(); } } else if ("actionRegister" == strObj) { if (m_pCheckLineseUI) { m_pCheckLineseUI->setInfo(lpCheckKey::instance()->getSerialNo(), lpGlobalData::instance()->m_bCheckLinese); m_pCheckLineseUI->setParent(this); m_pCheckLineseUI->setWindowTitle(tr("注册")); m_pCheckLineseUI->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); m_pCheckLineseUI->setWindowIcon(QIcon(WINDOWS_ICON)); m_pCheckLineseUI->setWindowModality(Qt::ApplicationModal); m_pCheckLineseUI->setAttribute(Qt::WA_ShowModal, true); m_pCheckLineseUI->show(); } } } void CMainWin::timerEvent(QTimerEvent *event) { if (m_TimerID_Status == event->timerId()) { onUpdateStatus(); } } void CMainWin::closeEvent(QCloseEvent *event) { QMessageBox info(this); info.setWindowIcon(QIcon(LEAPER_LOGO)); info.setWindowTitle(QObject::tr("警告")); info.setText(QObject::tr("本检测系统正在运行,您真的要关闭?")); info.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); info.setButtonText(QMessageBox::Ok, QObject::tr("确定")); info.setButtonText(QMessageBox::Cancel, QObject::tr("取消")); if (info.exec() != QMessageBox::Ok) { event->ignore(); } else event->accept(); } void CMainWin::changeEvent(QEvent *event) { if (event->type() == QEvent::LanguageChange) { ui.retranslateUi(this); } } //初始化状态栏 void CMainWin::onInitStatus() { m_pLbCurrentTime = new QLabel(QObject::tr("系统时间")); m_pLbCurrentTime->setMinimumHeight(40); m_pLbOnLine = new QLabel(QObject::tr("模式:")); m_pLbUser = new QLabel(QObject::tr("用户:无")); m_pLbConnect = new QLabel(QObject::tr("连接状态:")); m_pLbOnLine->setAlignment(Qt::AlignCenter); m_pLbConnect->setAlignment(Qt::AlignCenter); m_pLbUser->setAlignment(Qt::AlignCenter); m_pLbCurrentTime->setAlignment(Qt::AlignCenter); ui.statusBar->addWidget(m_pLbConnect,50); ui.statusBar->addWidget(m_pLbOnLine,50); ui.statusBar->addWidget(m_pLbUser,50); ui.statusBar->addPermanentWidget(m_pLbCurrentTime,50); } void CMainWin::onUpdateStatus() { m_tickCount++; m_heartTimeOut++; if (m_heartTimeOut > 5)//统计心跳超时次数 用于判断连接是否超时 { m_bPLCConnect = false; m_heartTimeOut = 0; } if (m_pLbCurrentTime) { QString currentTime = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); QString strlong = SecondTimeString(m_tickCount); QString strTimeTitle = tr("运行时长:"); QString strShow = QString("%1 %2 %3").arg(currentTime).arg(strTimeTitle).arg(strlong); m_pLbCurrentTime->setText(strShow); m_pLbCurrentTime->setStyleSheet("font: 14px;"); } if (m_pLbOnLine) { QString strOnlineState = QString(QObject::tr("检测模式:")) + (lpGlobalConfig::instance()->m_bOnlineMode == true ? QObject::tr("在线模式") : QObject::tr("离线模式")); m_pLbOnLine->setText(strOnlineState); m_pLbOnLine->setStyleSheet("font: 14px;"); } if (m_pLbConnect) { QString strOnlineState = QString(QObject::tr("连接状态:")) + (m_bPLCConnect == true ? QObject::tr("连接正常") : QObject::tr("连接异常")); m_pLbConnect->setText(strOnlineState); if (m_bPLCConnect == true) { m_pLbConnect->setStyleSheet("font: 14px;background-color: rgb(63, 170, 24);"); } else { m_pLbConnect->setStyleSheet("font: 14px;background-color: rgb(200, 10, 10);"); } } if (m_pLbUser) { m_pLbUser->setText(QObject::tr("用户: %1").arg(m_strUserName.isEmpty()==true?QObject::tr("未登录"):m_strUserName)); } } bool CMainWin::onInitCoreCtrl() { //load coretrl 初始化框架模块 if (NULL == m_pDllCoreCtrl) { m_pDllCoreCtrl = new CDllCoreCtrl(QStringList()); if (NULL == m_pDllCoreCtrl) { return false; } m_pCoreCtrl = m_pDllCoreCtrl->m_pCoreCtrl; if (m_pCoreCtrl == nullptr)//corectrl 加载失败 { QMessageBox infobox(QMessageBox::Critical, tr("提示"), tr("Corectrl模块加载失败,请检查!"), QMessageBox::Yes, this); infobox.setWindowIcon(QIcon(":/image/leaper")); infobox.setButtonText(QMessageBox::Yes, tr("确认")); infobox.exec(); exit(0); } FuncCallBack_VarInt getVarfunc = std::bind(&CMainWin::IGetVariantById, this, std::placeholders::_1); m_pCoreCtrl->IRegisterGetVariant(getVarfunc); FuncCallBack_StrMap strMapfunc = std::bind(&CMainWin::IVariantMapToUI, this, std::placeholders::_1, std::placeholders::_2); m_pCoreCtrl->IRegisterResultCallBack(strMapfunc); FuncCallBack_StrImg strImgfunc = std::bind(&CMainWin::INewCameraImage, this, std::placeholders::_1, std::placeholders::_2); m_pCoreCtrl->IRegisterImageCallBack(strImgfunc); if (m_pCoreCtrl->ICameraKeys().size() <= 0) { QMessageBox infobox(QMessageBox::Critical, tr("提示"), tr("camera.json文件出错,请检查!"), QMessageBox::Yes, this); infobox.setWindowIcon(QIcon(":/image/leaper")); infobox.setButtonText(QMessageBox::Yes, tr("确认")); infobox.exec(); exit(0); } } //load engine if (NULL == m_pDllDetectorEngine) { m_pDllDetectorEngine = new CDllDetectorEngine(); if (NULL == m_pDllDetectorEngine) { return false; } m_pDetectorEngine = m_pDllDetectorEngine->m_pDE; if (m_pDetectorEngine == nullptr) { QMessageBox infobox(QMessageBox::Critical, tr("提示"), tr("lpbengine模块加载失败,请检查!"), QMessageBox::Yes, this); infobox.setWindowIcon(QIcon(":/image/leaper")); infobox.setButtonText(QMessageBox::Yes, tr("确认")); infobox.exec(); exit(0); } } if (m_pDllDesigner == nullptr) { m_pDllDesigner = new CDllDesigner(); if (m_pDllDesigner != nullptr) { m_pDesigner = m_pDllDesigner->GetDesignerInterface(); if (m_pDesigner && m_pDetectorEngine) { m_pDesigner->Initialize(m_pDetectorEngine); } else { QMessageBox infobox(QMessageBox::Critical, tr("提示"), tr("lpdesigner模块加载失败,请检查!"), QMessageBox::Yes, this); infobox.setWindowIcon(QIcon(":/image/leaper")); infobox.setButtonText(QMessageBox::Yes, tr("确认")); infobox.exec(); exit(0); } } } return true; } void CMainWin::onInitDevice() { QStringList strCamKeys = m_pCoreCtrl->ICameraKeys(); for (int nIndex = 0; nIndex < strCamKeys.size(); nIndex++) { QString camKey = strCamKeys.at(nIndex); m_pCoreCtrl->IOpenCamera(camKey); m_pCoreCtrl->IStartCamera(camKey); } } void CMainWin::onInitUser() { {//用户管理模块加载 #ifdef _DEBUG QLibrary lib("QUserInfod"); #else QLibrary lib("QUserInfo"); #endif _UserCtrlCreate func = (_UserCtrlCreate)lib.resolve("UserCtrlCreate"); if (func) { m_pUserCtrl = func(); connect(m_pUserCtrl, SIGNAL(sgCurrentUserInfo(QString, int, int)), this, SLOT(onLogInOut(QString, int, int))); } } } void CMainWin::onInitSerial() { {//串口设备加载 #ifdef _DEBUG QLibrary lib("SerialPortToold");//库文件名 #else QLibrary lib("SerialPortTool");//库文件名 #endif _SerialPortCreate func = (_SerialPortCreate)lib.resolve("SerialPortCreate"); if (func) m_pSerialPort = func(); //load seriport dll if (m_pSerialPort)//如果文件存在 使用自定义的串口 { m_pSerialPort->loadAnalysefunc(this, &CMainWin::onAppanalysis); //关闭框架的串口使用 QString strDefaultPort = lpSysConfig::instance()->m_ComName; int baut = lpSysConfig::instance()->m_Baut; bool bOpen = m_pSerialPort->OpenCom(strDefaultPort, QString::number(baut)); if (bOpen == false) { QMessageBox infobox(QMessageBox::Information, QString(QObject::tr("提示")), QString("Com %1 %2 open failed").arg(strDefaultPort).arg(baut), QMessageBox::Yes | QMessageBox::No, NULL); infobox.setWindowIcon(QIcon(LEAPER_LOGO)); infobox.exec(); } connect(&m_HeartBit, SIGNAL(timeout()), this, SLOT(onHeardBit())); m_HeartBit.start(300); } } } void CMainWin::onInitUI() { QFont font; //工具栏菜单 QMenu *pToolMenu = new QMenu(this); pToolMenu->addAction(ui.actionStandard);//系统配置 pToolMenu->addAction(ui.actionSystem);//测试调试 pToolMenu->addAction(ui.actionTest); QToolButton* pbutton = new QToolButton(this); pbutton->setMenu(pToolMenu); pbutton->setIcon(QIcon(":/toolbar/Resource/toolBar/setting.png")); pbutton->setText(tr("工具")); pbutton->setToolTip(tr("工具")); pbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); pbutton->setPopupMode(QToolButton::InstantPopup); font.setBold(false); font.setPixelSize(16); pbutton->setFont(font); ui.mainToolBar->addWidget(pbutton); QMenu *pHelpMenu = new QMenu(this); pHelpMenu->addAction(ui.actionHelp); pHelpMenu->addAction(ui.actionRegister); QToolButton* pHelptool = new QToolButton(this); pHelptool->setMenu(pHelpMenu); pHelptool->setIcon(QIcon(":/toolbar/Resource/toolBar/help.png")); pHelptool->setText(tr("帮助")); pHelptool->setToolTip(tr("帮助")); pHelptool->setFont(font); pHelptool->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); pHelptool->setPopupMode(QToolButton::InstantPopup); ui.mainToolBar->addWidget(pHelptool); ui.mainToolBar->addSeparator(); m_pLabelInfo = new QLabel(this); m_pLabelInfo->setText(tr("本系统未注册激活")); m_pLabelInfo->setStyleSheet("font: bold 14px; color: red;"); ui.mainToolBar->addWidget(m_pLabelInfo); //工具栏按钮事件绑定 connect(ui.actionSetting, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.actionManage, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.actionTest, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.actionHelp, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.action_Check, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.actionSystem, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.main_Login_action, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.main_action_userManager, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.actionStandard, SIGNAL(triggered()), this, SLOT(onActionClicked())); connect(ui.actionRegister, SIGNAL(triggered()), this, SLOT(onActionClicked())); //图像结果展示 connect(this, SIGNAL(sgShowImg(int, QImage)), this, SLOT(onShowImage(int, QImage))); connect(this, SIGNAL(sgSelModel(int, QString)), this, SLOT(onSelModel(int, QString))); connect(this, SIGNAL(sgShowLog(int, QString)), this, SLOT(onShowLog(int, QString))); ui.main_action_userManager->setVisible(false); QTextDocument *pDoc = ui.wf_text_edit_result_1->document(); pDoc->setMaximumBlockCount(200); pDoc = ui.wf_text_edit_result_2->document(); pDoc->setMaximumBlockCount(200); ui.wf_lb_image_show_1->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui.wf_lb_image_show_1, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onPopMenu(const QPoint&))); ui.wf_lb_image_show_2->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui.wf_lb_image_show_2, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onPopMenu(const QPoint&))); connect(this, SIGNAL(sgShowSrcImg(QString, QImage)), &m_camSetWid, SLOT(onShowImage(QString, QImage))); } //======系统翻译相关 void CMainWin::SearchQmFile(const QString & strDir) { QDir dir(strDir); if (!dir.exists()) { return; } dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); dir.setSorting(QDir::DirsFirst); // 文件夹优先 // 转换成一个List QFileInfoList list = dir.entryInfoList(); if (list.size() < 1) { return; } int i = 0; do { QFileInfo fileInfo = list.at(i); QString tt = fileInfo.fileName(); // 如果是文件夹 bool bisDir = fileInfo.isDir(); if (bisDir) { SearchQmFile(fileInfo.filePath()); } else { bool bQm = fileInfo.fileName().endsWith(".qm"); SetTranslator(fileInfo.filePath()); } i++; } while (i < list.size()); } void CMainWin::SetTranslator(const QString strPath) { if (strPath.isEmpty()) { return; } QTranslator *pTrans = new QTranslator; if (pTrans->load(strPath)) // 如果加载成功 { qApp->installTranslator(pTrans); m_VecTranPtr.append(pTrans); } else { delete pTrans; pTrans = NULL; } } Q_SLOT void CMainWin::onLanguageChange(QString strLanguage) { // QSettings languageSetting(lpSysConfig::instance()->getCfgPath(), QSettings::IniFormat); // languageSetting.value("language/select", "Chinese").toString(); SetLanguage(strLanguage); } void CMainWin::SetLanguage(QString strLangage) { QString strDirPath = QString(QCoreApplication::applicationDirPath() + "/language/"); QString translatorFileName = strLangage; if (!translatorFileName.isEmpty()) { rmTranslator(); QLocale::setDefault(QLocale(translatorFileName)); QString transDir = strDirPath + translatorFileName; SearchQmFile(transDir); } } void CMainWin::rmTranslator() { if (m_VecTranPtr.size() > 0) { while (m_VecTranPtr.size()) { QTranslator *pVa = m_VecTranPtr.takeFirst(); qApp->removeTranslator(pVa); delete pVa; pVa = NULL; } } } //相机触发 Q_SLOT void CMainWin::onSnapImage(int nCamera /*= -1*/) { if (nCamera == 1) { QString camKey = lpGlobalConfig::instance()->m_StationCamKey_1; m_pCoreCtrl->ISnapImage(QStringList() << camKey); } else if (nCamera == 2) { QString camKey = lpGlobalConfig::instance()->m_StationCamKey_2; m_pCoreCtrl->ISnapImage(QStringList() << camKey); } } Q_SLOT void CMainWin::onTrigImage() { onSnapImage(1); onSnapImage(2); } Q_SLOT void CMainWin::onChangeUI(QString strUsr, int nLevel) { switch (nLevel) { case 9: case 8: case 7: case 6: ui.main_action_userManager->setVisible(true); ui.actionSystem->setEnabled(true); ui.actionTest->setEnabled(true); break; case 5: ui.main_action_userManager->setVisible(true); ui.actionSystem->setEnabled(true); ui.actionTest->setEnabled(true); break; case 4: case 3: case 2: case 1: case 0: ui.main_action_userManager->setVisible(false); ui.actionSystem->setEnabled(false); ui.actionTest->setEnabled(false); break; default: break; } } Q_SLOT void CMainWin::onLogInOut(QString strName, int level, int state) { onChangeUI(strName, level); m_strUserName = strName; if (state == 0) { ui.main_Login_action->setText(QObject::tr("注 销")); } else { ui.main_Login_action->setText(QObject::tr("登 录")); } } Q_SLOT void CMainWin::onTestMode(int val) { if (val == 0) { m_pCameraTrig->start(1000); } else if(val ==1){ m_pCameraTrig->stop(); } else if (val == 2) { onSnapImage(1); } else if (val == 3) { onSnapImage(2); } } //展示结果图片 Q_SLOT void CMainWin::onShowImage(int ID, QImage img) { auto ShowImg=[&](QLabel* pLab ,QImage& img) { if (!pLab) { qDebug() << "label image is null"; return; } if (img.isNull()) { QString str = QObject::tr("检测到错误: 模型与图像尺寸不匹配,请重新标定模型!!!"); pLab->setText(str); } else { QRect rt = pLab->rect(); int h = img.height(); int w = img.width(); float d = w * 1.0 / h; if (d > 0) { int h2 = rt.width() / d; rt.setHeight(h2); } QImage imgShow = img.scaled(QSize(rt.size())); pLab->setPixmap(QPixmap::fromImage(imgShow)); } }; if (ID == 1) { ShowImg(ui.wf_lb_image_show_1,img); } else if (ID == 2) { ShowImg(ui.wf_lb_image_show_2, img); } } //展示正在检测的型号名 Q_SLOT void CMainWin::onShowName(QString ID, QString strName) { if (ID == lpGlobalConfig::instance()->m_StationSolution_1) { ui.wf_lb_station_name_1->setText(strName); } else if (ID == lpGlobalConfig::instance()->m_StationSolution_2) { ui.wf_lb_station_name_2->setText(strName); } } //展示log Q_SLOT void CMainWin::onShowLog(int nID, QString strMsg) { if (nID == 1) { if (ui.wf_text_edit_result_1->toPlainText().size() > 50000) ui.wf_text_edit_result_1->clear(); ui.wf_text_edit_result_1->append(strMsg); } else if (nID == 2) { if (ui.wf_text_edit_result_2->toPlainText().size() > 50000) ui.wf_text_edit_result_2->clear(); ui.wf_text_edit_result_2->append(strMsg); } } Q_SLOT void CMainWin::onPopMenu(const QPoint& pt) { /*根据UI名判断是哪个工位需要设置相机*/ QString strCamKey; QString strObj = sender()->objectName(); if ("wf_lb_image_show_1" == strObj) { strCamKey = lpGlobalConfig::instance()->m_StationCamKey_1; } else if ("wf_lb_image_show_2" == strObj) { strCamKey = lpGlobalConfig::instance()->m_StationCamKey_2; } QStringList camkeys = m_pCoreCtrl->ICameraKeys(); if (!camkeys.contains(strCamKey) || strCamKey.isEmpty()) { QMessageBox infobox(QMessageBox::Critical, tr("提示"), tr("请对该工位的相机进行绑定!"), QMessageBox::Yes, this); infobox.setWindowIcon(QIcon(WINDOWS_ICON)); infobox.setButtonText(QMessageBox::Yes, tr("确认")); infobox.exec(); return ; } QMenu menu; QAction *pSetAction = menu.addAction(tr("相机配置")); pSetAction->setObjectName("setAction"); QAction *pSelect = menu.exec(QCursor::pos()); if (!pSelect) { menu.clear(); return; } QString strObjAction = pSelect->objectName(); if (strObjAction == "setAction") { m_camSetWid.setParent(this); m_camSetWid.setWindowIcon(QIcon(LEAPER_LOGO)); m_camSetWid.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); m_camSetWid.setWindowModality(Qt::ApplicationModal); m_camSetWid.setAttribute(Qt::WA_ShowModal, true); m_camSetWid.setCamParam(m_pCoreCtrl, strCamKey); m_camSetWid.show(); } menu.clear(); } Q_SLOT void CMainWin::onSlotAddNewModel(QString strName) { if (m_pDetectorEngine) { IDetectorSolutionMgr* pMgr = m_pDetectorEngine->getSolutionMgr(); if (pMgr) { IDetectorSolution* pSolution = pMgr->GetRunSolution(); if (pSolution) { pSolution->AddTaskByTemplate(strName); pSolution->SaveTaskByName(strName); } } } } Q_SLOT void CMainWin::onSlotDelOldModel(QString strName) { if (m_pDetectorEngine) { IDetectorSolutionMgr* pMgr = m_pDetectorEngine->getSolutionMgr(); if (pMgr) { IDetectorSolution* pSolution = pMgr->GetRunSolution(); if (pSolution) { pSolution->DeleteTask(strName); pSolution->SaveTaskByName(""); } } } } void CMainWin::IEngineResult(QVariantMap vMap) { QImage srcImg = vMap.value("originImage").value(); bool taskCali = vMap.value("taskCali").toBool();//标定标志位 使用有标定图来判断 QString solutionName = vMap.value("solutionName").toString(); QString taskName = vMap.value("taskName").toString(); double taskTime = vMap.value("tasktime").toDouble(); if (taskCali == false)//模板未标定 { int stationID = 0; if (solutionName == lpGlobalConfig::instance()->m_StationSolution_1) { stationID = 1; } else if (solutionName == lpGlobalConfig::instance()->m_StationSolution_2) { stationID = 2; } QString strResult = QTime::currentTime().toString("hh:mm:ss zzz:") + taskName; strResult += " No Cali!!!"; emit sgShowLog(stationID, strResult); sendResult(stationID, 361, 0, 0); //只保存原图 if ((lpSysConfig::instance()->m_bSaveSrcImg_st1 == true && stationID == 1) || (lpSysConfig::instance()->m_bSaveSrcImg_st2 == true && stationID == 2)) genSaveSrcImgPath(stationID, taskName, srcImg); return; } //不包含算法检测结果,表示没有相关task if (!vMap.contains("AlgoResult")) { int stationID = 0; if (solutionName == lpGlobalConfig::instance()->m_StationSolution_1) { stationID = 1; } else if (solutionName == lpGlobalConfig::instance()->m_StationSolution_2) { stationID = 2; } onShowImage(stationID, srcImg); QString strResult = QTime::currentTime().toString("hh:mm:ss zzz:") + taskName; strResult += " No Task!!!"; emit sgShowLog(stationID, strResult); sendResult(stationID, 361, 0, 0); if ((lpSysConfig::instance()->m_bSaveSrcImg_st1 == true && stationID == 1) || (lpSysConfig::instance()->m_bSaveSrcImg_st2 == true && stationID == 2)) genSaveSrcImgPath(stationID, taskName, srcImg); } else { QVariantMap algResult = vMap.value("AlgoResult").toMap(); double dAngle = algResult.contains("angle") ? algResult.value("angle").toDouble() : 365; int errorType = algResult.contains("error") ? algResult.value("error").toInt() : 16; double matchScore = algResult.value("score").toDouble() * 100; QImage rltImg = algResult.value("image").value(); QString strResultTip = algResult.value("resultTip").toString(); QPointF centerPoint = algResult.value("centerPoint").toPointF(); double centerX = 0.0; double centerY = 0.0; int stationID = 0; if (solutionName == lpGlobalConfig::instance()->m_StationSolution_1) { centerX = centerPoint.x() * lpGlobalConfig::instance()->m_StationScale_1 + lpGlobalConfig::instance()->m_StationXOffset_1; centerY = centerPoint.y() * lpGlobalConfig::instance()->m_StationScale_1 + lpGlobalConfig::instance()->m_StationYOffset_1; sendResult(1, dAngle, centerX, centerY); stationID = 1; } else if (solutionName == lpGlobalConfig::instance()->m_StationSolution_2) { centerX = centerPoint.x() * lpGlobalConfig::instance()->m_StationScale_2 + lpGlobalConfig::instance()->m_StationXOffset_2; centerY = centerPoint.y() * lpGlobalConfig::instance()->m_StationScale_2 + lpGlobalConfig::instance()->m_StationYOffset_2; sendResult(2, dAngle, centerX, centerY); stationID = 2; } /******保存数据********/ QString strImgPath; if ((lpSysConfig::instance()->m_bSaveRltImg_st1 == true && stationID == 1) || (lpSysConfig::instance()->m_bSaveRltImg_st2 == true && stationID == 2)) strImgPath = genSavePath(stationID,taskName, rltImg); if ((lpSysConfig::instance()->m_bSaveSrcImg_st1 == true && stationID == 1) || (lpSysConfig::instance()->m_bSaveSrcImg_st2 == true && stationID == 2)) genSaveSrcImgPath(stationID,taskName, srcImg); QString str2 = taskName; int ID = stationID; QString strModelName = QString("%1_%2").arg(ID).arg(str2); Struct2SaveData nStructData; nStructData.dAngle = dAngle; nStructData.errorType = errorType; nStructData.matchScore = matchScore; //nStructData.threshBenchMark = threshBenchMark; nStructData.resultTip = strResultTip; nStructData.stationName = QString("Station_%1").arg(stationID); nStructData.value1 = strImgPath; nStructData.value2 = str2; m_db->addData2DB(nStructData); /*展示结果*/ onShowImage(stationID, rltImg); /********打印检测结果到ui上*********/ QString strResult = QTime::currentTime().toString("hh:mm:ss zzz:") + taskName; strResult += " angle result : " + QString::number(dAngle, 'f', 3); if (dAngle >= 361) { dAngle = 361.0; strResult += " no found Value"; } else { strResult += tr(" center:(%1,%2)").arg(centerX).arg(centerY); } emit sgShowLog(stationID, strResult); } } bool CMainWin::sendResult(int nID, double angleValue, double centerX, double centerY) { if (m_pSerialPort) { const int c_nDataNum = 8; const double c_dMaxAngle = 360.0; if (angleValue < 0) { angleValue += c_dMaxAngle; } unsigned short data[c_nDataNum] = { 0 }; data[2] = int(angleValue);//角度整数部分 double tmp = angleValue - int(angleValue); tmp *= 1000.0; data[3] = int(tmp);//角度小数部分 data[4] = int(centerX); double tmpX = centerX - int(centerX); tmpX *= 1000.0; data[5] = int(tmpX); data[6] = int(centerY); double tmpY = centerY - int(centerY); tmpY *= 1000.0; data[7] = int(tmpY); SComFrame sendFram; int nCmd = (nID == 1 ? 0x46 : 0x47);//stion1 0x46 /station2 0x47 sendFram.cmd = nCmd; sendFram.data1 = data[0]; sendFram.data2 = data[1]; sendFram.data3 = data[2]; sendFram.data4 = data[3]; sendFram.data5 = data[4]; sendFram.data6 = data[5]; sendFram.data7 = data[6]; sendFram.data8 = data[7]; m_pSerialPort->enquequeData(sendFram); if (angleValue >= c_dMaxAngle) { unsigned short data2[c_nDataNum] = { 0 }; data2[0] = 6 + nID - 1; data2[1] = 50; // for (int i = 0; i < c_nDataNum; i++) { // swapBigEndian(data2[i]); // } SComFrame sendFram2; sendFram2.cmd = 0x48; sendFram2.data1 = data2[0]; sendFram2.data2 = data2[1]; sendFram2.data3 = data2[2]; sendFram2.data4 = data2[3]; sendFram2.data5 = data2[4]; sendFram2.data6 = data2[5]; sendFram2.data7 = data2[6]; sendFram2.data8 = data2[7]; m_pSerialPort->enquequeData(sendFram2); } } return true; } QString CMainWin::SecondTimeString(quint64 value) { QString strTime; int seconds = value % 60; int minutes = value / 60; QString strDay = tr("天"); QString strHour = tr("时"); QString strMinute = tr("分"); QString strSecond = tr("秒"); strTime = QString("%1%2%3%4").arg(minutes).arg(strMinute).arg(seconds).arg(strSecond); if (minutes >= 60) { minutes = (value / 60) % 60; int hours = (value / 60) / 60; strTime = QString("%1%2%3%4%5%6").arg(hours).arg(strHour).arg(minutes).arg(strMinute).arg(seconds).arg(strSecond); if (hours >= 24) { hours = ((value / 60) / 60) % 24; int day = ((value / 60) / 60) / 24; strTime = QString("%1%2%3%4%5%6%7%8").arg(day).arg(strDay).arg(hours).arg(strHour).arg(minutes).arg(strMinute).arg(seconds).arg(strSecond); } } return strTime; } //根据注册状态启用相关功能 Q_SLOT void CMainWin::onLineseCheck(bool bFlag) { ui.actionSetting->setDisabled(!bFlag); ui.actionManage->setDisabled(!bFlag); ui.actionTest->setDisabled(!bFlag); ui.action_Check->setDisabled(!bFlag); ui.actionSystem->setDisabled(!bFlag); ui.main_Login_action->setDisabled(!bFlag); ui.actionStandard->setDisabled(!bFlag); if (m_pLabelInfo) { if (bFlag) { m_pLabelInfo->setText(tr("")); m_pLabelInfo->setStyleSheet(""); } else { m_pLabelInfo->setText(tr("本系统未注册激活")); m_pLabelInfo->setStyleSheet("font: bold 14px; color: red;"); } } } void CMainWin::saveImage(const QImage& m_pixmap, QString m_path, QString filename) {//启动多线程保存图像 SaveImgThread *workTread = new SaveImgThread(this); workTread->setPixmap(m_pixmap, m_path, filename); connect(workTread, &SaveImgThread::finished, workTread, &QObject::deleteLater); workTread->start(); } void CMainWin::onInitDiskClean() { { QString strSrcImgPath = QCoreApplication::applicationDirPath() + "/DBFiles/SrcImages/"; QDiskCleanThread *pDCleanThread = new QDiskCleanThread; pDCleanThread->setModel(CleanDir); pDCleanThread->setUseFlag(lpSysConfig::instance()->m_CheckEnable_SrcImg); pDCleanThread->setDays(lpSysConfig::instance()->m_CheckFileDays); pDCleanThread->SetImgStorageFolder(strSrcImgPath); pDCleanThread->setMiniSize(lpSysConfig::instance()->m_MinSpaceSizeG); pDCleanThread->start(); m_pDCThreadList.append(pDCleanThread); QString strRltImgPath = QCoreApplication::applicationDirPath() + "/DBFiles/Images/"; QDiskCleanThread *pCleanDir = new QDiskCleanThread; pCleanDir->setModel(CleanDir); pCleanDir->setUseFlag(lpSysConfig::instance()->m_CheckEnable_RltImg); pCleanDir->setDays(lpSysConfig::instance()->m_CheckFileDays); pCleanDir->SetImgStorageFolder(strRltImgPath); pCleanDir->setMiniSize(lpSysConfig::instance()->m_MinSpaceSizeG); pCleanDir->start(); m_pDCThreadList.append(pCleanDir); } }