You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wheeldetect/tpvs17/tpMain/lpMainWin.cpp

1381 lines
41 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "lpMainWin.h"
#include "quserinfo_global.h"
#include <QDir>
#include <QFileInfo>
#include "qmysplashscreen.h"
#include "InfoFile.h"
#include "WheelCtrl.h"
#include "QWorkMgrCtlr.h"
#include "qworkmgrui.h"
#include "IWheelModel.h"
#include <QDebug>
#include "qnettickthread.h"
#include "QMessageBox"
#include "ChannelInfo.h"
#include "HubBase.h"
#include <QToolButton>
#include <QMenu>
#pragma execution_character_set("utf-8")
lpMainWin::lpMainWin(QWidget *parent)
: QMainWindow(parent)
{
QMySplashScreen m_screen;
m_screen.show();
qRegisterMetaType<TimeStruct>("TimeStruct");
m_screen.ShowMsg(tr("¼ÓÔØ±ØÒªÄ£¿é....."));
onInitCoreCtrl();
ui.setupUi(this);
onInitAbout();
{
QGridLayout *pLayout = new QGridLayout(ui.cam_win_1);
m_ImgViewer = new RoiImgViewer(ui.cam_win_1);
m_ImgViewer->setObjectName("Imageview");
pLayout->addWidget(m_ImgViewer);
ui.cam_win_1->setLayout(pLayout);
}
{
connect(ui.action_userManager, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.action_Login, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.action_about, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.action_setting_ip, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.action_cali_raster, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.action_setting_ban, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.action_debug, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.action_connect_mode, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.action_checkdata, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.action_modelmgr, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.actionSystemSeting, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.actioncamSetting, SIGNAL(triggered()), this, SLOT(onActionClicked()));
connect(ui.btn_start_detect, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.btn_clear_data, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
QMenu *pToolMenu = new QMenu(this);
// QFont font;
// font.setPixelSize(24);
// pToolMenu->setFont(font);
pToolMenu->addAction(ui.action_cali_raster);
pToolMenu->addAction(ui.action_setting_ban);
pToolMenu->addAction(ui.action_setting_ip);
pToolMenu->addAction(ui.action_debug);
pToolMenu->addAction(ui.actionSystemSeting);
pToolMenu->addAction(ui.actioncamSetting);
QToolButton* pbutton = new QToolButton(this);
pbutton->setMenu(pToolMenu);
pbutton->setIcon(QIcon(":/ToolBarPic/ToolButon"));
pbutton->setText(tr("¹¤¾ß"));
pbutton->setToolTip(tr("¹¤¾ß"));
pbutton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
pbutton->setPopupMode(QToolButton::InstantPopup);
ui.mainToolBar->addWidget(pbutton);
ui.mainToolBar->addAction(ui.action_about);
}
{//¼ÓÔØÓïÑÔÉèÖÃ
QSettings languageSetting("hubdetect.ini", QSettings::IniFormat);
QString strLangeage = languageSetting.value("language", "Chinese").toString();
SetLanguage(strLangeage);
}
{
m_pLbCurrentTime = new QLabel(tr("ϵͳʱ¼ä"));
m_pLbBanci = new QLabel(tr("°à´ÎÐÅÏ¢"));
m_pLbDetectState = new QLabel(tr("¼ì²â״̬"));
m_pLbUser = new QLabel(tr("Óû§£º"));
QFont m_font;
m_font.setBold(true);
m_font.setPixelSize(12);
m_pLbCurrentTime->setFont(m_font);
m_pLbCurrentTime->setMinimumHeight(40);
m_pLbCurrentTime->setMinimumWidth(200);
m_pLbCurrentTime->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
m_pLbBanci->setMinimumWidth(200);
m_pLbBanci->setFont(m_font);
m_pLbBanci->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
m_pLbDetectState->setMinimumWidth(200);
m_pLbDetectState->setFont(m_font);
m_pLbDetectState->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
//m_pLbOnLine = new class QLabel("ģʽ£º");
//m_pLbOnLine->setMinimumWidth(c_nWidth);
m_pLbUser->setFont(m_font);
m_pLbUser->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ui.statusBar->addWidget(m_pLbDetectState, 1);
ui.statusBar->addWidget(m_pLbUser, 1);
ui.statusBar->addWidget(m_pLbBanci);
ui.statusBar->addPermanentWidget(m_pLbCurrentTime);
}
//¼ÓÔØÓû§¹ÜÀíÄ£¿é
loadUserModel();
//³õʼ»¯Ä£Ð͹ÜÀíÄ£¿é
{
m_pCtrl = new WheelCtrl(QCoreApplication::applicationDirPath(), &m_screen);
pWorkCtrl = new QWorkMgrCtlr(m_pCtrl);
pWorkCtrl->readManageFile();
m_pworkUI = new QWorkMgrUI(pWorkCtrl, m_pCtrl);
m_pworkUI->InitUI();
connect(m_pworkUI, SIGNAL(sgUpdatedefect()), this, SLOT(onUpdateDefect()));
m_pModelMgrDlg = new QModelMgrDlg(m_pCtrl);
m_pDebugDlg = new QDebugDlg();
m_pTimerMgrDlg = new QTimeMgrDlg();
connect(m_pDebugDlg, SIGNAL(sgTriggerCam()), this, SLOT(onTriggerCam()));
m_pDebugDlg->onSetCtrl(m_pCtrl);
m_pixMapList = new QPixmapListBar(ui.tp_main_tabWidget);
ui.tp_main_tabWidget->insertTab(0, m_pixMapList, tr("ÀúÊ·"));
ui.tp_main_tabWidget->setCurrentIndex(0);
}
{
/*·¢ËÍÄ£°å¿âÏß³Ì*/
SendModelLibTask = new QMyThread();
SendModelLibTask->setUser(true);
TaskFunc KuTaskFunc = std::bind(&lpMainWin::SendModelKuTskFun,this);
SendModelLibTask->loadfunc(KuTaskFunc);
SendTiskTsk = new QMyThread();
TaskFunc TickFunc = std::bind(&lpMainWin::SendTickTskFun, this);
SendTiskTsk->loadfunc(TickFunc);
m_screen.ShowMsg(tr("ϵͳ³õʼ»¯Íê³É..."));
}
{
onSetModel();
/*ÍøÂçͨÐżÓÔØ*/
m_pNet = ((WheelCtrl*)m_pCtrl)->getNet();
connect(m_pNet, SIGNAL(sgShow2UI(QString, bool)), this, SLOT(onTcpConnet(QString, bool)));//net
connect(m_pNet, SIGNAL(sgClientConnect(QString, bool)), this, SLOT(onClientConnect(QString, bool)));//net
//connect(m_pNet, SIGNAL(sgRecv(const QString &)), this, SLOT(onTcpRecv(const QString &)));// netÏÔʾ
connect(m_pNet, SIGNAL(sgThickness(double)), this, SLOT(onThickness(double)));//xy height
connect(m_pNet, SIGNAL(sgRecvDetectState(int, int)), this, SLOT(onDetectStateRecv(int, int)));//xy check
connect(m_pNet, SIGNAL(sgClearRev(bool)), this, SLOT(onClearLibRev(bool)));//xy clearlib
connect(m_pNet, SIGNAL(sgPulseRev()), this, SLOT(onPulseRev()));
// connect(m_pNet, SIGNAL(sgResultRev()), this, SLOT(onResultRev()));
connect(m_pNet, SIGNAL(sgRecvTrigPara()), this, SLOT(onRecvTrigPara()));
connect(m_pNet, SIGNAL(sgReadDetectState(int, QString)), this, SLOT(onReadDetectState(int, QString)));
connect(m_pNet, SIGNAL(sgReadDetectStateASK()), this, SLOT(onReadDetectStateASK()));
connect(m_pNet, SIGNAL(sgCameraTrig(int)), this, SLOT(onTrigRecv(int)));
connect(m_pNet, SIGNAL(sgServerState(QString, int, bool)), this, SLOT(onServerState(QString, int, bool)));
connect(m_pNet, SIGNAL(sgShutDownComputer()), this, SLOT(onShutDownComputer()));
connect(m_pNet, SIGNAL(sgLibRev(bool)), SendModelLibTask, SLOT(WaitSingleIn(bool)));//xy lib
// connect(m_pNet, SIGNAL(sgChangeOnlineState(int)), m_pUi, SLOT(onSwitchOnlineModel(int)));//Ç¿ÖÆÔÚÏß ÀëÏß
QTimer::singleShot(500, m_pNet, SLOT(onOpenServer()));//ÑÓ³Ù2s´ò¿ªÍøÂçTCP·þÎñ
}
{
connect(&m_PulseTimer, SIGNAL(timeout()), this, SLOT(onPulseTimer()));//ÐÄÌø°ü
connect(&m_wfPulseTimer, SIGNAL(timeout()), this, SLOT(onwfPulseTimer()));//ÐÄÌø°ü
connect(&m_ThicknessTimer, SIGNAL(timeout()), this, SLOT(onThicknessTimer()));// ºñ¶È²éѯ
connect(&m_ReadLibTimer, SIGNAL(timeout()), this, SLOT(onSendReadOnlineLib()));
connect(this, SIGNAL(sgTickTsk()), this, SLOT(onPulseTimer()));
connect(this, SIGNAL(sgShowMsg(QString, bool)), this, SLOT(onTcpConnet(QString, bool)));
connect(this, SIGNAL(sgTaskSendModels(int, QString, double, double)), this, SLOT(onTaskSendModels(int, QString, double, double)));//ÓÃÓÚ·¢ËÍΰå¿â
connect(this, SIGNAL(sgTskSendDetectState(int, QString, int)), this, SLOT(onTaskSendDetectState(int, QString, int)));//ÀëÏß¼ì²â·¢ËÍ ÓÃÓÚ·¢Ëͼì²â״̬
connect(this, SIGNAL(sgTskSendCheck(int, int, QString)), this, SLOT(onTaskCheck(int, int, QString)));//ÔÚÏß¼ì²â״̬²éѯ ÓÃÓÚ²éѯÏß³Ì
// connect(this, SIGNAL(sgCheckEnd()), this, SLOT(onCheckEnd()));
connect(this, SIGNAL(sgShowImgState(QString)), this, SLOT(onShowImgState(QString)));
connect(this, SIGNAL(sgGetImg()), this, SLOT(onGetImg()));
connect(this, SIGNAL(sgShowMsgdlg(QString)), this, SLOT(onShowMsg(QString)));
connect(this, SIGNAL(sgSendDisLib(int, QString)), this, SLOT(onSendDisLib(int, QString)));
connect(this, SIGNAL(sgSendDisLibDone()), this, SLOT(onSendDisLibDone()));
connect(this, SIGNAL(sgShowChannelRes(QString)), this, SLOT(onShowChannel(QString)));
}
{
/*Æô¶¯Ö®ºó¾ÍÒ»Ö±·¢ËÍÐÄÌø°üºÍºñ¶È²éѯ*/
if (DetectState::instance()->m_AutoSendTick2Net)
{
SendTiskTsk->setSleepTime(1000);
SendTiskTsk->start();
}
if (DetectState::instance()->m_StartAndDetect == 1)//m_sysType ±íʾÍò·á¿Æ¼¼µÄ
{
// m_timerDetect.setSingleShot(true);
// connect(&m_timerDetect, SIGNAL(timeout()), m_pUi, SLOT(onStartDetect()));
// m_timerDetect.start(5000);
//QTimer::singleShot(1000, m_pUi, SLOT(onStartDetect()));
// QTimer::singleShot(3000, [&](){
// m_pState->bLockDetect = true;
// m_pCtrl->onStart();
// });
}
if (DetectState::instance()->m_AutoSendTick2COM)
m_wfPulseTimer.start(1000);
pTickThread = new QThread(this);
QNetTickThread *pNetTick = new QNetTickThread;
pNetTick->setNetPtr(m_pNet);
pNetTick->moveToThread(pTickThread);
connect(pTickThread, &QThread::finished, pNetTick, &QObject::deleteLater);
connect(this, SIGNAL(sgNetData(int, QVariantMap)), pNetTick, SLOT(doWork(int, QVariantMap)));
connect(pNetTick, SIGNAL(resultReady(int, QVariantMap)), m_pNet, SLOT(onSendDataByType(int, QVariantMap)));
pTickThread->start();
}
{
m_pTableCheck = new ModelsView(ui.tableview_checkstate, m_pCtrl->getAllModelMapPtr());
m_pTableCheck->setEnable(false);
connect(m_pCtrl, SIGNAL(sgModelChanged()), m_pTableCheck, SLOT(updateModels()));
QStringList strList = forDefectList;
if (!strList.contains("NG"))
strList.append("NG");
m_pTableCheck->setModelList(strList);
}
m_timerID = startTimer(1000);
}
lpMainWin::~lpMainWin()
{
m_timer.stop();
if (m_VecTranPtr.size() > 0) {
while (m_VecTranPtr.size()) {
QTranslator *pTrans = m_VecTranPtr.takeFirst();
qApp->removeTranslator(pTrans);
delete pTrans;
}
}
if (m_pUserCtrl) {
delete m_pUserCtrl;
m_pUserCtrl = NULL;
}
if (SendModelLibTask)
{
qDebug() << "delete SendModelLibTak";
if (SendModelLibTask->isRunning())
SendModelLibTask->stop();
SendModelLibTask->wait(50);
delete SendModelLibTask;
SendModelLibTask = NULL;
qDebug() << "delete SendModelLibTak end";
}
if (SendTiskTsk)
{
qDebug() << "delete SendTiskTsk";
if (SendTiskTsk->isRunning())
SendTiskTsk->stop();
SendTiskTsk->wait(50);
delete SendTiskTsk;
SendTiskTsk = NULL;
qDebug() << "delete SendTiskTsk end";
}
if (pTickThread)
{
qDebug() << "delete pTickThread";
if (pTickThread->isRunning())
{
pTickThread->quit();
pTickThread->wait(50);
}
delete pTickThread;
pTickThread = NULL;
qDebug() << "delete pTickThread end";
}
{
if (m_pLbCurrentTime)
{
delete m_pLbCurrentTime;
m_pLbCurrentTime = nullptr;
}
if (m_pLbBanci)
{
delete m_pLbBanci;
m_pLbBanci = nullptr;
}
if (m_pLbDetectState)
{
delete m_pLbDetectState;
m_pLbDetectState = nullptr;
}
if (m_pLbUser)
{
delete m_pLbUser;
m_pLbUser = nullptr;
}
}
if (m_pCtrl)
{
delete m_pCtrl;
m_pCtrl = nullptr;
}
if (pWorkCtrl)
{
delete pWorkCtrl;
pWorkCtrl = nullptr;
}
if (m_pworkUI)
{
delete m_pworkUI;
m_pworkUI = nullptr;
}
if (m_pModelMgrDlg)
{
delete m_pModelMgrDlg;
m_pModelMgrDlg = nullptr;
}
if (m_pDebugDlg) {
delete m_pDebugDlg;
m_pDebugDlg = nullptr;
}
if (m_pTimerMgrDlg) {
delete m_pTimerMgrDlg;
m_pTimerMgrDlg = nullptr;
}
if (m_ImgViewer) {
delete m_ImgViewer;
m_ImgViewer = nullptr;
}
if (m_pixMapList) {
delete m_pixMapList;
m_pixMapList = nullptr;
}
if (m_pDllCoreCtrl)
{
delete m_pDllCoreCtrl;
m_pDllCoreCtrl = nullptr;
}
}
bool lpMainWin::onInitCoreCtrl()
{
//load coretrl
if (NULL == m_pDllCoreCtrl)
{
m_pDllCoreCtrl = new CDllCoreCtrl(QStringList(), nullptr);
if (NULL == m_pDllCoreCtrl)
{
return false;
}
m_pCoreCtrl = m_pDllCoreCtrl->m_pCoreCtrl;
FuncCallBack_VarInt getVarfunc = std::bind(&lpMainWin::IGetVariantById, this, std::placeholders::_1);
m_pCoreCtrl->IRegisterGetVariant(getVarfunc);
FuncCallBack_StrMap strMapfunc = std::bind(&lpMainWin::IVariantMapToUI, this, std::placeholders::_1, std::placeholders::_2);
m_pCoreCtrl->IRegisterResultCallBack(strMapfunc);
FuncCallBack_StrImg strImgfunc = std::bind(&lpMainWin::INewCameraImage, this, std::placeholders::_1, std::placeholders::_2);
m_pCoreCtrl->IRegisterImageCallBack(strImgfunc);
return true;
}
return false;
}
void lpMainWin::loadUserModel()
{
//userctrel
#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 lpMainWin::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 lpMainWin::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;
}
}
void lpMainWin::SetLanguage(QString strLangage)
{
QString strDirPath = QString(QCoreApplication::applicationDirPath() + "/language/");
QString translatorFileName = strLangage;
if (!translatorFileName.isEmpty())
{
if (m_VecTranPtr.size() > 0)
{
while (m_VecTranPtr.size())
{
QTranslator *pVa = m_VecTranPtr.takeFirst();
qApp->removeTranslator(pVa);
delete pVa;
pVa = NULL;
}
}
//if (strLangage == "Chinese")
// return;
QLocale::setDefault(QLocale(translatorFileName));
QString transDir = strDirPath + translatorFileName;
SearchQmFile(transDir);
}
}
/*Ö÷Ï߳̽ÓÊÕͼÏñ*/
void lpMainWin::INewCameraImage(const QString& camKey, QImage img)
{
if (m_ImgViewer)
{
int widgetWidth = m_ImgViewer->width();
int imgWidth = img.width();
float scalew = (widgetWidth*1.0) / (imgWidth*1.0);
int widgetHeight = m_ImgViewer->height();
int imgHeight = img.height();
float scaleh = (widgetHeight*1.0) / (imgHeight*1.0);
float minScale = scalew < scaleh ? scalew : scaleh;
m_ImgViewer->setInitScale(minScale-0.01);
m_ImgViewer->setImg(img);
}
}
/*¶àÏ̷߳¢ËÍËã·¨½á¹û*/
void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap)
{
emit(sgShowImgState(tr("ÏÔʾʶ±ð½á¹û")));
if (vMap.contains("error"))
{
emit(sgShowMsgdlg(tr("Ïà»úͼÏñºÍ±³¾°Í¼²»Ò»Ñù£¬Çë¸ü»»¼ì²â±³¾°£¡")));
return;
}
Result2Ui *pResult = (Result2Ui*)vMap.value("result").toLongLong();
onShowResult(pResult);
if (m_pDebugDlg) {
m_pDebugDlg->onShowResult(pResult);
}
// m_pUi->processResult(pResult);
static int ErrorNum = 0;
if (m_pNet) {
if (pResult->m_strModel == "NG") {
//m_pNet->sendLight(0, 1, 1000, 10);//ºìµÆ
SendResultBee(LIGHT_REDBEE, 1);
SendResultBee(LIGHT_BEE, 1);
ErrorNum++;
}
else {
//m_pNet->sendLight(2, 1, 1000, 100);
SendResultBee(LIGHT_GREENBEE, 1);
ErrorNum = 0;
}
if (ErrorNum >= 3) {
QString str = tr("¾¯¸æ!!!Á¬Ðø³öÏÖ%1¸öδʶ±ðÐͺÅ").arg(ErrorNum);
if (DetectState::instance()->IsDetect == false)
str += tr(",먦Æô¼ì²â¹¦ÄÜÔì³ÉµÄ");
m_pCtrl->addLog(str, emTypeWaring);
//m_pNet->sendLight(0, 1, 2000, 100);
//m_pNet->sendLight(3, 1, 3000, 100);
SendResultBee(LIGHT_REDBEE, 3);
SendResultBee(LIGHT_BEE, 3);
}
}
if (DetectState::instance()->m_SendDetectStr2Net)
SendResultStr2PLC(pResult);//·¢Ëͼì²â½á¹û×Ö·ûµ½PLC
if (DetectState::instance()->m_SendChannelRes2COM)
SendResultChannelCOM(pResult);//·¢Ëͼì²â½á¹ûͨµÀµ½´®¿Ú
if (DetectState::instance()->m_SendChannelRes2Net)
SendResultChannel2PLC(pResult);//·¢Ëͼì²â½á¹ûͨµÀµ½PLC
m_pCtrl->saveResult(pResult);
delete pResult;
// m_IsDetected--;
// if (m_IsDetected <= 0)
// {
// m_IsDetected = 0;
// //emit(sgFinish());
// }
}
/*¶àÏ̻߳ñÈ¡Ëã·¨²ÎÊý*/
QVariant lpMainWin::IGetVariantById(int id)
{
m_nDiffTrigNum--;//½øÈëµ½ÕâÀï ±íʾ»ñÈ¡µ½ÁËͼƬ
qWarning() << "Alg get An Image:" << "(" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss zzz") << ")";
emit(sgShowImgState(tr("»ñµÃͼÏñ,ÕýÔÚ¼ÆËãÖÐ...")));
emit(sgGetImg());
qDebug() << "get one Pic ,id=" << id;
if (DetectState::instance()->m_showThressList == 1) {
QString str = m_pCtrl->getThicknessStr();
emit(sgShowMsg(str, true));
}
QVariantMap vMap;
int nThickness = 0;
if (DetectState::instance()->m_IsUseRaster == 0)
nThickness = m_nWfThress;
else
nThickness = m_pCtrl->getThickness();// m_houduVec.first();
//nThickness = 209;
vMap.insert("thickness", QVariant(nThickness));
double dDiameter;// = (-794.25 * nThickness / 1000000.0 + 0.775960);
dDiameter = (DetectState::instance()->m_k * nThickness + DetectState::instance()->m_b);
vMap.insert("d2h", dDiameter);
vMap.insert("useThickness", DetectState::instance()->bUseThickness);
vMap.insert("useDiameter", DetectState::instance()->bUseDiameter);
vMap.insert("Threshold", DetectState::instance()->m_AlgThres);
vMap.insert("IsCutImg", DetectState::instance()->m_UseCutImg);
void* address = (void*)m_pCtrl->getAllModelMapPtr();
long long varadr = (long long)address;
vMap.insert("modelMap", varadr);
void* pdefectList = (void*)&forDefectList;
long long val = (long long)pdefectList;
vMap.insert("defectList", val);
qDebug() << "end get one pic" << id;
if (DetectState::instance()->m_showThressValue == 1) {
QString str = QString("thickness value = %1,dDiameter value = %2").arg(nThickness).arg(dDiameter);
emit(sgShowMsg(str, true));
}
return vMap;
}
Q_SLOT void lpMainWin::onLogInOut(QString strName, int level, int state)
{
// if (state == 0) {
// m_pCtrl->setUser(strName, level);
// if (main_loginIn)
// main_loginIn->setText(tr("×¢ Ïú"));
// m_pUi->onUserRole();
// }
// else
// {
// m_pCtrl->setUser(strName, level);
// if (main_loginIn)
// main_loginIn->setText(tr("µÇ ¼"));
// m_pUi->onUserRole();
// }
}
Q_SLOT void lpMainWin::onActionClicked()
{
QString strObj = sender()->objectName();
if ("action_userManager" == strObj) {
/*Óû§¹ÜÀí*/
if (m_pUserCtrl)
{
m_pUserCtrl->ShowUserMgrDlg(this);
}
}
else if ("action_Login" == strObj) {
/*Óû§µÇ½*/
if (m_pUserCtrl)
{
m_pUserCtrl->CheckLogin(this);
}
}
else if ("action_about" == strObj) {
m_aboutDlg.setParent(this);
m_aboutDlg.setWindowTitle(tr("¹ØÓÚ"));
m_aboutDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_aboutDlg.setWindowIcon(QIcon(":/resource/logo-8.png"));
m_aboutDlg.setWindowModality(Qt::ApplicationModal);
m_aboutDlg.setAttribute(Qt::WA_ShowModal, true);
m_aboutDlg.show();
}
else if ("action_setting_ip" == strObj) {
if(m_pNet)
m_pNet->onShowIpDlg(this);
}
else if ("action_cali_raster" == strObj) {
}
else if ("action_setting_ban" == strObj) {
if (m_pTimerMgrDlg) {
m_pTimerMgrDlg->setParent(this);
m_pTimerMgrDlg->setWindowTitle(tr("°à´Î¹ÜÀí"));
m_pTimerMgrDlg->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_pTimerMgrDlg->setWindowIcon(QIcon(":/resource/logo-8.png"));
m_pTimerMgrDlg->setWindowModality(Qt::ApplicationModal);
m_pTimerMgrDlg->setAttribute(Qt::WA_ShowModal, true);
m_pTimerMgrDlg->show();
}
}
else if ("action_debug" == strObj) {
if (m_pDebugDlg) {
m_pDebugDlg->setParent(this);
m_pDebugDlg->setWindowTitle(tr("µ÷ÊÔ¹¤¾ß"));
m_pDebugDlg->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_pDebugDlg->setWindowIcon(QIcon(":/resource/logo-8.png"));
m_pDebugDlg->setWindowModality(Qt::ApplicationModal);
m_pDebugDlg->setAttribute(Qt::WA_ShowModal, true);
m_pDebugDlg->show();
}
}
else if ("action_connect_mode" == strObj) {//¼ì²âÄ£°å¹´Ñ¡
if (m_pworkUI)
{
m_pworkUI->setParent(this);
m_pworkUI->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_pworkUI->setWindowIcon(QIcon(":/resource/logo-8.png"));
m_pworkUI->setWindowModality(Qt::ApplicationModal);
m_pworkUI->setAttribute(Qt::WA_ShowModal, true);
m_pworkUI->onExec();
}
}
else if ("action_checkdata" == strObj) {
}
else if ("action_modelmgr" == strObj) {//Ä£°å¹ÜÀí
if (m_pModelMgrDlg)
{
m_pModelMgrDlg->setParent(this);
m_pModelMgrDlg->setWindowTitle(tr("Ä£°å¹ÜÀí"));
m_pModelMgrDlg->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_pModelMgrDlg->setWindowIcon(QIcon(":/resource/logo-8.png"));
m_pModelMgrDlg->setWindowModality(Qt::ApplicationModal);
m_pModelMgrDlg->setAttribute(Qt::WA_ShowModal, true);
m_pModelMgrDlg->show();
}
}
else if ("actionSystemSeting" == strObj) {
}
else if ("actioncamSetting" == strObj) {
}
}
Q_SLOT void lpMainWin::onButtonClicked()
{
QString strObj = sender()->objectName();
if ("btn_start_detect" == strObj)//¿ªÊ¼
{
//¿ªÊ¼¼ì²â°´Å¥
if (DetectState::instance()->IsDetect == false) {
ui.btn_start_detect->setText(tr("Í£Ö¹¼ì²â"));
m_pCtrl->onStart();
QString str = tr("°´ÏÂÁË¿ªÊ¼¼ì²â°´Å¥£¬¼ì²â¹¦ÄÜ¿ªÆô");
m_pCtrl->addLog(str, emTypeRunState);
//QTimer::singleShot(3000, [&](){m_pState->bLockDetect = true; });
QTimer::singleShot(3000, this, SLOT(onChangeDetect()));
}
else {
m_pCtrl->onFinish();
ui.btn_start_detect->setText(tr("¿ªÊ¼¼ì²â"));
QString str = tr("°´ÏÂÁËÍ£Ö¹¼ì²â°´Å¥£¬¼ì²â¹¦ÄܹرÕ");
m_pCtrl->addLog(str, emTypeRunState);
DetectState::instance()->bLockDetect = false;
}
DetectState::instance()->IsDetect = !DetectState::instance()->IsDetect;
}
else if ("btn_clear_data" == strObj) {//½»°àÇåÁã
QMessageBox infobox(QMessageBox::Warning, tr("Ìáʾ"), tr("½«Çå¿ÕËùÓÐÊý¾Ý"), QMessageBox::Yes | QMessageBox::Cancel, this);
infobox.setButtonText(QMessageBox::Yes, tr("È·¶¨"));
infobox.setButtonText(QMessageBox::Cancel, tr("È¡Ïû"));
infobox.setWindowIcon(QIcon(":/image/leaper"));
if (QMessageBox::Cancel != infobox.exec()) {
m_pCtrl->onClear();
ui.main_lb_res_ok_num->setText(QString::number(0));
ui.main_lb_res_ng_num->setText(QString::number(0));
QString str = m_pCtrl->getUserName() + ":" + tr("°´ÏÂÁËÇåÁã°´Å¥£¬Êý¾ÝÈ«²¿ÇåÁã");
m_pCtrl->addLog(str, emTypeUseState);
}
}
}
void lpMainWin::timerEvent(QTimerEvent *event)
{
if (event->timerId() == m_timerID) {
QString str = tr("ϵͳʱ¼ä£º ");
QString strDetectState = tr("¼ì²â״̬:") + (DetectState::instance()->IsDetect == true ? tr("¼ì²âÖÐ...") : tr("δ¼ì²â..."));
// if (strLanguage != "Chinese")
// {
// str = "Time:";
// strDetectState = tr("State:") + (m_pState->IsDetect == true ? tr("Detecting...") : tr("Undetect..."));
// }
if (m_pLbCurrentTime) {
QString m_currentTimerString = hubBase::genDateTime();
m_pLbCurrentTime->setText(str + m_currentTimerString + " ");
m_pLbCurrentTime->setStyleSheet("font: 14px;");
}
// state
if (m_pLbDetectState) {
m_pLbDetectState->setText(strDetectState);
if (DetectState::instance()->IsDetect) {
m_pLbDetectState->setStyleSheet("font: bold 14px;background-color: green;");
}
else {
m_pLbDetectState->setStyleSheet("font: bold 14px;background-color: red;");
}
}
if (m_pLbBanci) {
QString show_label;
if (m_pCtrl)
show_label = m_pCtrl->getCurrentBan();
QString strMsg = tr("°à´ÎÐÅÏ¢£º") + (show_label.isEmpty() == true ? tr("¸Ãʱ¼ä¶ÎδÉèÖðà´Î") : show_label);
// if (strLanguage != "Chinese")
// {
// strMsg = tr("Classes:")
// + (show_label.isEmpty() == true ? tr("No set Times") : show_label);
// }
m_pLbBanci->setText(strMsg);
m_pLbBanci->setStyleSheet("font: 14px;");
}
if (m_pLbUser) {
QString show_label = m_pCtrl->getUserName();
// if (strLanguage != "Chinese")
// m_pLbUser->setText(tr("User:") + show_label);
// else
m_pLbUser->setText(tr("µ±Ç°Óû§£º") + show_label);
m_pLbUser->setStyleSheet("font: 14px;");
}
}
}
void lpMainWin::closeEvent(QCloseEvent *event)
{
}
void lpMainWin::SendModelKuTskFun()
{
/*
·¢ËÍÄ£°å¿âÏß³Ì
°ÑÒÑÓеÄËùÓÐÄ£°å¿âÈ«²¿·¢ËÍÖÁPLCÖÐ
*/
DetectState::instance()->m_ThreadWaitTime = 100;
const int c_nErrorTime = 3;
int nError = 0;
QMap<QString, IWheelModel*>*ptr = m_pCtrl->getAllModelMapPtr();
QList<QString> lst = ptr->keys();
if (ptr->size() > 0 && lst.size() > 0)
{
int nIndex = 0;
do
{
IWheelModel *p = ptr->value(lst.at(nIndex));
emit sgTaskSendModels(nIndex + 1, lst.at(nIndex), p->getDiameter(), p->getThickness());
bool b = this->SendModelLibTask->WaitForSingle(DetectState::instance()->m_ThreadWaitTime);
if (!b) {
nError++;
if (DetectState::instance()->m_PLC_ASK == 1) {
if (nError > c_nErrorTime) {
++nIndex;
nError = 0;
qDebug() << "timeout, more than 3 times, cannot rev ask";
}
}
else {
++nIndex;
nError = 0;
}
}
else {
nError = 0;
nIndex++;
}
} while (nIndex < lst.size());
}
emit(sgShowMsgdlg(tr("Ä£°å¿â·¢ËÍÍê³É")));
}
void lpMainWin::SendTickTskFun()
{
//ÐÄÌø°ü·¢ËÍ
if (m_pNet)
{
m_pNet->sendPulse(6000, DetectState::instance()->IsDetect, DetectState::instance()->IsOnline);
//m_TimerID = startTimer(500);
}
}
void lpMainWin::onSetModel()
{
/*
ÖØÐ¼ÓÔØÄ£°å
ÖØÐÂÉèÖÃÄ£°åµ½Ëã·¨ÖÐʹÓÃ
*/
forDefectList = pWorkCtrl->getDefectList();
if (m_pTableCheck) {
QStringList strList = forDefectList;
if (!strList.contains("NG"))
strList.append("NG");
m_pTableCheck->setModelList(strList);
}
QString str = QString("%1:%2(%3)").arg(tr("ÕýÔÚ¼ì²âÐͺÅÊý")).arg(forDefectList.size()).arg(m_pCtrl->getAllModelName().size() - 1);
ui.main_showWorkLabel->setText(str);
// IWheelUi *pMainWidget = m_pUi->getItemWidget(WHEEL_UI_MAINWINDOW);
// if (pMainWidget) {
// pMainWidget->setViewList(forDefectList);
// }
// void* address = (void*)m_pCtrl->getAllModelMapPtr();
// gpTpCoreCtrl->ISetAlgorithmShared("modelMap", (int)address);
// QVariant filepath = QVariant(QCoreApplication::applicationDirPath());
// gpTpCoreCtrl->ISetAlgorithmShared("filepath", filepath);
//
// void* pdefectList = (void*)&forDefectList;
// gpTpCoreCtrl->ISetAlgorithmShared("defectList", (int)pdefectList);
}
///*******************************************************************************
Q_SLOT void lpMainWin::onUpdateDefect() {
forDefectList = pWorkCtrl->getDefectList();
if (m_pTableCheck) {
QStringList strList = forDefectList;
if (!strList.contains("NG"))
strList.append("NG");
m_pTableCheck->setModelList(strList);
}
QString str = QString("%1:%2(%3)").arg(tr("ÕýÔÚ¼ì²âÐͺÅÊý")).arg(forDefectList.size()).arg(m_pCtrl->getAllModelName().size() - 1);
ui.main_showWorkLabel->setText(str);
}
Q_SLOT void lpMainWin::onTcpConnet(QString str, bool bConnect)
{
static bool nTcpConnetSetting = true;
QTextBrowser *m_Tcp_textbrower = ui.main_textBrowser;
if (m_Tcp_textbrower && nTcpConnetSetting == true) {
m_Tcp_textbrower->clear();
QTextDocument *pDoc = m_Tcp_textbrower->document();
pDoc->setMaximumBlockCount(10244);
nTcpConnetSetting = false;
}
if (m_Tcp_textbrower) {
if (!bConnect) {
QColor m_color(255, 0, 0);
m_Tcp_textbrower->setTextColor(m_color);
}
else {
QColor m_color(16, 67, 24);
m_Tcp_textbrower->setTextColor(m_color);
}
m_Tcp_textbrower->append(str);
QTextCursor cursor = m_Tcp_textbrower->textCursor();
cursor.movePosition(QTextCursor::End);
m_Tcp_textbrower->setTextCursor(cursor);
}
}
Q_SLOT void lpMainWin::onClientConnect(QString addr, bool bConnect)
{
/*ÅжÏÁ¬½ÓµÄ»úÆ÷IPµØÖ·ÊDz»ÊDZ¾µØÉèÖúõÄIP£¬²¢¼ì²âËûµÄÁ¬½Ó״̬£¬Èç¹ûÊÇ Ä¬ÈϽ«·¢ËÍÄ£°å¿â¸øËû*/
QString m_addr = NetProtocol::genAddressPort(m_pNet->getIp(emNetClient), m_pNet->getPort(emNetClient));
if (m_addr == addr && bConnect)
{
QTimer::singleShot(200, this, SLOT(onSendClearLib2PLC()));
}
if (bConnect == true && 1 == DetectState::instance()->IsOnline) {
//m_pUi->onSwitchOnlineModel(m_pState->IsOnline);//ÔÚÏßģʽ ÀëÏßģʽÇл»
}
QString strMsg;
if (bConnect)
{
strMsg += QString("IP:%1 %2").arg(addr).arg(tr("ÒÑÁ¬½Ó"));
}
else
{
strMsg += QString("IP:%1 %2").arg(addr).arg(tr("ÒѶϿª"));
}
m_pCtrl->addLog(strMsg, emTypeRunState);
ui.main_textBrowser->append(strMsg);
}
Q_SLOT void lpMainWin::onThickness(double dValue)
{
m_pCtrl->appendThicknessValue(dValue);
}
Q_SLOT void lpMainWin::onDetectStateRecv(int nIndex, int value)
{
nIndex -= 1;
QMap<QString, IWheelModel*> *ptr = m_pCtrl->getAllModelMapPtr();
if (ptr) {
QList<QString> lst = ptr->keys();
if (nIndex < lst.size() && nIndex >= 0) {
IWheelModel*pModel = ptr->value(lst.at(nIndex));
pModel->setDetectState(value);
emit(m_pCtrl->sgModelChanged(lst.at(nIndex)));
}
else {
qDebug() << "rev detect state, index big than lst size";
}
}
}
Q_SLOT void lpMainWin::onClearLibRev(bool state)
{
/*½ÓÊÕµ½¿âÇå¿ÕÓ¦´ð*/
if (SendModelLibTask) {
if (SendModelLibTask->isRunning())
SendModelLibTask->stop();
if (m_pNet)
m_pNet->sendModelNum(m_pCtrl->getAllModelMapPtr()->size());
SendModelLibTask->start();
}
}
//½ÓÊÕµ½ÐÄÌø°ü ¹Ø±Õ¶¨Ê±Æ÷
Q_SLOT void lpMainWin::onPulseRev()
{
if (m_TimerID != 0)
{
killTimer(m_TimerID);
m_TimerOutCount = 0;
m_RestartServerCount = 0;
}
}
Q_SLOT void lpMainWin::onRecvTrigPara()
{
emit(sgShowMsgdlg(tr("PLCÒÑÊÕµ½Ïà¹ØÉèÖòÎÊý£¡")));
}
Q_SLOT void lpMainWin::onReadDetectState(int nIndex, QString strModel)
{
nIndex -= 1;
QMap<QString, IWheelModel*> *ptr = m_pCtrl->getAllModelMapPtr();
if (ptr) {
QList<QString> lst = ptr->keys();
/*if (nIndex < lst.size() && nIndex >= 0)*/ {
IWheelModel*pModel = ptr->value(strModel);
if (pModel) {
pModel->setDetectState(1);
emit(m_pCtrl->sgModelChanged(strModel));
}
}
}
}
Q_SLOT void lpMainWin::onReadDetectStateASK()
{
QMap<QString, IWheelModel*> *ptr = m_pCtrl->getAllModelMapPtr();
if (ptr) {
QList<QString> lst = ptr->keys();
for (int nIndex = 0; nIndex < lst.size(); nIndex++) {
IWheelModel*pModel = ptr->value(lst.at(nIndex));
pModel->setDetectState(0);
emit(m_pCtrl->sgModelChanged(lst.at(nIndex)));
}
}
}
Q_SLOT void lpMainWin::onTrigRecv(int m_value)
{
/*ÓÃÓÚ½ÓÊÕPLC´¥·¢Ïà»úµÄÐźŠ×Ô¼ìÊÇ·ñÊÕµ½Í¼Ïñ */
qDebug() << "recv a camera trig :" << QString::number(m_value);
qWarning() << "recv a Triger signal from PLC:" << "(" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss zzz") << ")";
//if (m_pState)//Èç¹ûÊÇʹÓÃÈí¼þ´¥·¢Ïà»úÅÄÕÕ
{
if (DetectState::instance()->m_CameraTrigeType == 0)//Èí¼þ´¥·¢Ä£Ê½
{
if (DetectState::instance()->bLockDetect == true) {
//CC_Action(CC_AC_NEXT);
onTriggerCam();
qWarning() << "soft ctrol camera :" << "(" << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss zzz") << ")";
}
}
}
}
Q_SLOT void lpMainWin::onServerState(QString Addr, int port, bool m_state)
{
QString str;
if (m_state == true)
str = QString(tr("ÒÑ´ò¿ª"));
else
str = QString(tr("ÒѹرÕ"));
QString strMsg = QString("serverIP %1 port %2 %3.").arg(Addr).arg(port).arg(str);
m_pCtrl->addLog(m_pCtrl->getUserName() + ":" + strMsg, emTypeRunState);
}
Q_SLOT void lpMainWin::onShutDownComputer()
{
qApp->closeAllWindows();
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osvi) == 0)
return;
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
// Windows NT 3.51, Windows NT 4.0, Windows 2000,
// Windows XP, Windows .NET Server
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, NULL);
}
ExitWindowsEx(EWX_SHUTDOWN, SHTDN_REASON_MAJOR_OTHER);
}
//***********************************************************************
Q_SLOT void lpMainWin::onPulseTimer()
{
//ÐÄÌø°ü·¢ËÍ
if (m_pNet)
{
m_pNet->sendPulse(6000, DetectState::instance()->IsDetect, DetectState::instance()->IsOnline);
//m_TimerID = startTimer(500);
}
}
Q_SLOT void lpMainWin::onTaskSendModels(int nIndex, QString strModel, double dDiameter, double dHeight)
{
if (m_pNet)
m_pNet->sendModelList(nIndex, strModel, dDiameter, dHeight);
}
Q_SLOT void lpMainWin::onTaskSendDetectState(int nIndex, QString strModel, int IsState)
{
if (m_pNet)
m_pNet->sendDeteStateList(nIndex, IsState, strModel);
}
Q_SLOT void lpMainWin::onTaskCheck(int nIndex, int IsState, QString strModel)
{
if (m_pNet)
m_pNet->sendCheckDeteStateList(nIndex, IsState, strModel);
}
Q_SLOT void lpMainWin::onShowImgState(QString str)
{
ui.main_label_state->setText(str);
}
Q_SLOT void lpMainWin::onGetImg()
{
ui.main_lb_res_model_pic->setStyleSheet(QString("QLabel{border: 1px solid rgb(0,0,0,250);background-color: rgb(200, 200, 200);}"));
}
//չʾÐÅÏ¢
Q_SLOT void lpMainWin::onShowMsg(QString str)
{
// QPulpewidget *pw = new QPulpewidget();
// m_pw = pw;
// QMainWindow *m_pDlgMain = nullptr;// GET_WIDGET_POINTER("MainWindow", QMainWindow);
// pw->setParent(m_pDlgMain);
// pw->showmessage(str);
// connect(pw, SIGNAL(finished()), pw, SLOT(deleteLater()));
// connect(pw, SIGNAL(finished()), this, SLOT(onInitPW()));
}
Q_SLOT void lpMainWin::onSendDisLib(int nIndex, QString strModel)
{
m_pNet->sendDisLibs(nIndex, strModel);
}
Q_SLOT void lpMainWin::onSendDisLibDone()
{
m_pNet->sendDisLibsDone();
}
Q_SLOT void lpMainWin::onShowChannel(QString str)
{
ui.main_lb_res_Channle_Show->setText(str);
}
Q_SLOT void lpMainWin::onTriggerCam()
{
if (m_pCoreCtrl)
{
QStringList strLst = m_pCoreCtrl->ICameraKeys();
m_pCoreCtrl->ISnapImage(strLst);
}
}
void lpMainWin::onInitAbout()
{
QString aboutString;
aboutString = QString(
"<h1>%1</h1>"
"<p>%2.</p>"
"<p>%3:www.hzleaper.com</p>"
"<p>%4:%5</p>"
"<p>%6:%7</p>"
"<p>%8£º%9</p>"
"<p> </p>"
).arg(tr("ÂÖì±ÐͺÅʶ±ðϵͳ"))
.arg(tr("±¾Èí¼þÓɺ¼ÖÝÀûçê¿Æ¼¼¿ª·¢£¬ÓÃÓÚÂÖì±ÐͺÅʶ±ðºÍ·ÖÀ࣬¿É´îÅäÁ÷Ë®ÏßÔËÊäϵͳʹÓÃ"))
.arg(tr("ÈôÐèÒª½øÒ»²½Á˽â¸Ã²úÆ·µÄÏà¹ØÐÅÏ¢£¬Çë·ÃÎÊÎÒÃǵÄÍøÕ¾"))
.arg(tr("Èí¼þ°æ±¾")).arg(111)
//.arg(tr("Ëã·¨°æ±¾")).arg(strWhelAlgoType)
.arg(tr("Ëã·¨°æ±¾")).arg(111)
.arg(tr("×îºó¸üÐÂʱ¼ä")).arg(111)
.arg(tr("°æÈ¨ (c) Êô º¼ÖÝÀûçê¿Æ¼¼ÓÐÏÞ¹«Ë¾ ËùÓÐ"));
m_aboutDlg.setFixedSize(500, 300);
//QLabel* lbTitle = new QLabel(m_lightBox);
//QLabel* lbTitle = new QLabel(&m_mainWidget);
//lbTitle->setPixmap(QPixmap(":/image/Resource/logo-8.png").scaled(50,50));
//lbTitle->setStyleSheet("font-size: 28px; font-weight: bold; color: white");
//QTextEdit* pEdit = new QTextEdit(m_lightBox);
QTextEdit* pEdit = new QTextEdit(&m_aboutDlg);
//QLabel* pEdit = new QLabel(&m_mainWidget);
pEdit->setReadOnly(true);
pEdit->append(aboutString);
//pEdit->setText(aboutString);
//pEdit->setStyleSheet("background-color: rgb(0, 0, 0, 255);color:#1E296B;border:0px solid gray;color: black");
pEdit->setAttribute(Qt::WA_TranslucentBackground, true);
QPalette pl = pEdit->palette();
pl.setBrush(QPalette::Base, QBrush(QColor(255, 0, 0, 0)));
pEdit->setPalette(pl);
QPushButton* lbClose = new QPushButton(tr("¹Ø±Õ"));
//QGridLayout* lbLayout = new QGridLayout(m_lightBox);
QGridLayout* lbLayout = new QGridLayout(&m_aboutDlg);
//lbLayout->addWidget(lbTitle, 1, 1);
lbLayout->addWidget(pEdit, 2, 1, 1, 3);
lbLayout->addWidget(lbClose, 3, 2);
lbClose->setMaximumSize(QSize(100, 50));
//connect(lbClose, SIGNAL(clicked()), m_lightBox, SLOT(hide()));
connect(lbClose, SIGNAL(clicked()), &m_aboutDlg, SLOT(hide()));
//m_lightBox->setLayout(lbLayout);
}
void lpMainWin::onShowResult(Result2Ui* pRlt)
{
if (!pRlt)
return;
/*
ui.main_lb_res_model_pic;//Æ¥Åä½á¹ûͼ
ui.main_lb_res_okng;//Æ¥Åä½á¹û OK NG
ui.main_lb_res_model_id;//Æ¥ÅäÐͺÅ
ui.main_lb_res_model_score;//Æ¥Åä·ÖÊý
ui.main_lb_res_model_thickness;//ºñ¶È
ui.main_lb_res_model_diameter;//Ö±¾¶
ui.main_lb_res_model_time;//ʶ±ðºÄʱʱ¼ä
ui.main_lb_res_ok_num;//ʶ±ð×ÜÊý
ui.main_lb_res_ng_num;//NG ÊýÁ¿
*/
int scareh = ui.main_lb_res_model_pic->height();
int scarew = ui.main_lb_res_model_pic->width();
int scare = 0;
if (scareh > scarew)
scare = scarew;
else
scare = scareh;
if (pRlt->m_strModel.isEmpty()) {
DetectState::instance()->totalUnDetectNum++;
QPixmap pix(":/image/none.jpg");
ui.main_lb_res_model_pic->setPixmap(pix.scaled(scare - 15, scare - 15));
ui.main_lb_res_model_pic->setStyleSheet(QString("QLabel{border: 5px solid rgb(250,0,0,250);background-color: rgb(200, 200, 200);}"));
pRlt->m_strModel = "NG";
ui.main_lb_res_okng->setText("NG");
ui.main_lb_res_okng->setStyleSheet("background-color: rgb(255, 0, 0);");
IWheelModel *pModel = m_pCtrl->getModel("NG");
if (pModel) {
pModel->increCount();
emit m_pTableCheck->sgValueChange(pModel->getModelID());
}
}
else {
IWheelModel *pModel = m_pCtrl->getModel(pRlt->m_strModel);
if (pModel) {
QString filepath = m_pCtrl->appRoot() + pModel->getPicPath();
QPixmap pix(filepath);
ui.main_lb_res_model_pic->setPixmap(pix.scaled(scare - 15, scare - 15));
pModel->increCount();
ui.main_lb_res_okng->setText("OK");
ui.main_lb_res_okng->setStyleSheet("background-color: rgb(0, 255, 0);");
ui.main_lb_res_model_pic->setStyleSheet(QString("QLabel{border: 5px solid rgb(0,250,0,250);background-color: rgb(200, 200, 200);}"));
emit m_pTableCheck->sgValueChange(pModel->getModelID());
}
}
DetectState::instance()->totalDetectNum++;
//show
ui.main_lb_res_ng_num->setText(QString::number(DetectState::instance()->totalUnDetectNum));
ui.main_lb_res_ok_num->setText(QString::number(DetectState::instance()->totalDetectNum));
ui.main_lb_res_model_time->setText(QString::number(pRlt->m_dRunTime, 'f', 2));
ui.main_lb_res_model_thickness->setText(QString::number((int)pRlt->m_dThickness));
ui.main_lb_res_model_diameter->setText(QString::number((int)pRlt->m_dDiameter));
ui.main_lb_res_model_id->setText(pRlt->m_strModel);
ui.main_lb_res_model_score->setText(QString::number(pRlt->m_dScore * 100, 'f', 1) + "%");
if (m_pixMapList)
{
if (pRlt->m_pixResult.isNull())
m_pixMapList->addItemByLimit(pRlt->m_pixSrc, pRlt->m_strModel);
else
m_pixMapList->addItemByLimit(pRlt->m_pixResult, pRlt->m_strModel);
}
}
void lpMainWin::SendResultBee(emTypeBee m_Type, int num)
{
//qDebug() << "sendResultBeeLight";
//SComframe frame;
//if (m_Type == LIGHT_REDBEE) {
// frame.data1 = 1;
// frame.data2 = num;
// SendDataToCom(0x46, frame);
//}
//else if (m_Type == LIGHT_GREENBEE) {
// frame.data1 = 2;
// frame.data2 = 0;
// frame.data3 = num;
// SendDataToCom(0x46, frame);
//}
//else if (m_Type == LIGHT_YELLOWBEE) {
// frame.data1 = 4;
// frame.data2 = 0;
// frame.data3 = 0;
// frame.data4 = num;
// SendDataToCom(0x46, frame);
//}
//else if (m_Type == LIGHT_BEE) {
// frame.data1 = 8;
// frame.data2 = 0;
// frame.data3 = 0;
// frame.data4 = 0;
// frame.data5 = num;
// SendDataToCom(0x46, frame);
//}
if (m_Type == LIGHT_REDBEE) {
m_pNet->sendLight(0, 1, 500, 500);//ºìµÆ
}
else if (m_Type == LIGHT_GREENBEE) {
m_pNet->sendLight(2, 1, 500, 500);
}
else if (m_Type == LIGHT_YELLOWBEE) {
m_pNet->sendLight(1, 1, 500, 500);
}
else if (m_Type == LIGHT_BEE) {
m_pNet->sendLight(3, 1, 500, 500);
}
}
void lpMainWin::SendResultStr2PLC(Result2Ui* m_Res)
{
qDebug() << "sendResultToPLC resultName=" << m_Res->m_strModel << endl;
if (m_pNet)
m_pNet->sendDetectResult(m_Res->m_strModel, m_Res->m_dDiameter, m_Res->m_dThickness);
}
void lpMainWin::SendResultChannel2PLC(Result2Ui* m_Res)
{
qDebug() << "SendResultChannel2PLC";
CChannelInfo *pChannelInfo = m_pCtrl->getChannelInfo();
ChannelInfo *npInfo = pChannelInfo->getChannelInfo(m_Res->m_strModel);
//npInfo->m_value = 5;
if (npInfo&&DetectState::instance()->m_bObjAll2A == false) {
if (m_pNet)
m_pNet->sendResultChannel(npInfo->m_value, m_Res->m_dDiameter, m_Res->m_dThickness, m_Res->m_strModel);
emit(sgShowChannelRes(npInfo->m_ChannelName));
}
else
{
int defaultChannel = pChannelInfo->getDefaultChannel();
ChannelInfo *defaultInfo = pChannelInfo->getChannelInfo(defaultChannel);
int nResultChannel = 0;
if (defaultInfo)
{
nResultChannel = defaultInfo->m_value;
emit(sgShowChannelRes(defaultInfo->m_ChannelName + tr("(ĬÈÏ)")));
}
else
{
nResultChannel = 1000;
emit(sgShowChannelRes(tr("ĬÈÏͨµÀ Öµ1000")));
}
if (m_pNet)
m_pNet->sendResultChannel(nResultChannel, m_Res->m_dDiameter, m_Res->m_dThickness, m_Res->m_strModel);
}
}
void lpMainWin::SendResultChannelCOM(Result2Ui* m_Res)
{
qDebug() << "SendResultStr2COM";
CChannelInfo *pChannelInfo = m_pCtrl->getChannelInfo();
ChannelInfo *npInfo = pChannelInfo->getChannelInfo(m_Res->m_strModel);
//SComframe frame;
//if (npInfo&&m_pState->m_bObjAll2A == false) {
// frame.data1 = npInfo->m_value;
// SendDataToCom(0x47, frame);
// emit(sgShowChannelRes(npInfo->m_ChannelName));
//}
//else
//{
// int defaultChannel = pChannelInfo->getDefaultChannel();
// ChannelInfo *defaultInfo = pChannelInfo->getChannelInfo(defaultChannel);
// if (defaultInfo)
// {
// frame.data1 = defaultInfo->m_value;
// emit(sgShowChannelRes(defaultInfo->m_ChannelName + QString(tr("(ĬÈÏ)"))));
// }
// else
// {
// frame.data1 = 1000;
// emit(sgShowChannelRes(tr("ĬÈÏͨµÀ Öµ1000")));
// }
// SendDataToCom(0x47, frame);
//}
}