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

743 lines
21 KiB
C++

#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"
#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("<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>Ҫģ<EFBFBD><EFBFBD>....."));
onInitCoreCtrl();
ui.setupUi(this);
{
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()));
}
{//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
QSettings languageSetting("hubdetect.ini", QSettings::IniFormat);
QString strLangeage = languageSetting.value("language", "Chinese").toString();
SetLanguage(strLangeage);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
loadUserModel();
//<2F><>ʼ<EFBFBD><CABC>ģ<EFBFBD>͹<EFBFBD><CDB9><EFBFBD>ģ<EFBFBD><C4A3>
{
m_pCtrl = new WheelCtrl(QCoreApplication::applicationDirPath(), &m_screen);
pWorkCtrl = new QWorkMgrCtlr(m_pCtrl);
pWorkCtrl->readManageFile();
pworkUI = new QWorkMgrUI(pWorkCtrl, m_pCtrl);
pworkUI->InitUI();
connect(pworkUI, SIGNAL(sgUpdatedefect()), this, SLOT(onUpdateDefect()));
m_pState = m_pCtrl->getDetectState();
}
{
/*<2A><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>*/
SendModelLibTask = new QMyThread();
SendModelLibTask->setUser(true);
SendModelLibTask->loadfunc(this, &lpMainWin::SendModelKuTskFun);
SendTiskTsk = new QMyThread();
SendTiskTsk->loadfunc(this, &lpMainWin::SendTickTskFun);
m_screen.ShowMsg(tr("ϵͳ<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..."));
}
{
onSetModel();
/*<2A><><EFBFBD><EFBFBD>ͨ<EFBFBD>ż<EFBFBD><C5BC><EFBFBD>*/
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<65><74>ʾ
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)));//ǿ<><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
QTimer::singleShot(500, m_pNet, SLOT(onOpenServer()));//<2F>ӳ<EFBFBD>2s<32><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TCP<43><50><EFBFBD><EFBFBD>
}
{
connect(&m_PulseTimer, SIGNAL(timeout()), this, SLOT(onPulseTimer()));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
connect(&m_wfPulseTimer, SIGNAL(timeout()), this, SLOT(onwfPulseTimer()));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
connect(&m_ThicknessTimer, SIGNAL(timeout()), this, SLOT(onThicknessTimer()));// <20><><EFBFBD>Ȳ<EFBFBD>ѯ
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)));//<2F><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>Ī<EFBFBD><C4AA><EFBFBD><EFBFBD>
connect(this, SIGNAL(sgTskSendDetectState(int, QString, int)), this, SLOT(onTaskSendDetectState(int, QString, int)));//<2F><><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><E2B7A2> <20><><EFBFBD>ڷ<EFBFBD><DAB7>ͼ<EFBFBD><CDBC><EFBFBD>״̬
connect(this, SIGNAL(sgTskSendCheck(int, int, QString)), this, SLOT(onTaskCheck(int, int, QString)));//<2F><><EFBFBD>߼<EFBFBD><DFBC><EFBFBD>״̬<D7B4><CCAC>ѯ <20><><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD>߳<EFBFBD>
// 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)));
}
{
/*<2A><><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>һֱ<D2BB><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><CDBA>Ȳ<EFBFBD>ѯ*/
if (m_pState->m_AutoSendTick2Net)
{
SendTiskTsk->setSleepTime(1000);
SendTiskTsk->start();
}
if (m_pState->m_StartAndDetect == 1)//m_sysType <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD>
{
// 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 (m_pState->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()));
m_pTableCheck->setModelList(forDefectList);
}
}
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_pCtrl)
{
delete m_pCtrl;
m_pCtrl = nullptr;
}
if (pWorkCtrl)
{
delete pWorkCtrl;
pWorkCtrl = nullptr;
}
if (pworkUI)
{
delete pworkUI;
pworkUI = 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); // <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// ת<><D7AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>List
QFileInfoList list = dir.entryInfoList();
if (list.size() < 1)
{
return;
}
int i = 0;
do
{
QFileInfo fileInfo = list.at(i);
QString tt = fileInfo.fileName();
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
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)) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>سɹ<D8B3>
{
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)
{
}
void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap)
{
}
QVariant lpMainWin::IGetVariantById(int id)
{
return QVariant();
}
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("ע <20><>"));
// m_pUi->onUserRole();
// }
// else
// {
// m_pCtrl->setUser(strName, level);
// if (main_loginIn)
// main_loginIn->setText(tr("<22><> ¼"));
// m_pUi->onUserRole();
// }
}
Q_SLOT void lpMainWin::onActionClicked()
{
QString strObj = sender()->objectName();
if ("action_userManager" == strObj) {
}
else if ("action_Login" == strObj) {
}
else if ("action_about" == strObj) {
}
else if ("action_setting_ip" == strObj) {
}
else if ("action_cali_raster" == strObj) {
}
else if ("action_setting_ban" == strObj) {
}
else if ("action_debug" == strObj) {
}
else if ("action_connect_mode" == strObj) {
if (pworkUI)
{
pworkUI->onExec();
}
}
else if ("action_checkdata" == strObj) {
}
else if ("action_modelmgr" == strObj) {
}
}
void lpMainWin::timerEvent(QTimerEvent *event)
{
}
void lpMainWin::closeEvent(QCloseEvent *event)
{
}
void lpMainWin::SendModelKuTskFun()
{
/*
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PLC<EFBFBD><EFBFBD>
*/
m_pState->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(m_pState->m_ThreadWaitTime);
if (!b) {
nError++;
if (m_pState->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("ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")));
}
void lpMainWin::SendTickTskFun()
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (m_pNet)
{
m_pNet->sendPulse(6000, m_pState->IsDetect, m_pState->IsOnline);
//m_TimerID = startTimer(500);
}
}
void lpMainWin::onSetModel()
{
/*
<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>
*/
forDefectList = pWorkCtrl->getDefectList();
if (m_pTableCheck) {
m_pTableCheck->setModelList(forDefectList);
}
// 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();
//IWheelUi *pMainWidget = m_pUi->getItemWidget(WHEEL_UI_MAINWINDOW);
//if (pMainWidget)
{
// pMainWidget->setViewList(forDefectList);//<2F><><EFBFBD><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD>б<EFBFBD>
QString str = QString("%1:%2(%3)").arg(tr("<EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͺ<EFBFBD><EFBFBD><EFBFBD>")).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)
{
/*<2A>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ӵĻ<D3B5><C4BB><EFBFBD>IP<49><50>ַ<EFBFBD>Dz<EFBFBD><C7B2>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>úõ<C3BA>IP<49><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ĭ<>Ͻ<EFBFBD><CFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
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 == m_pState->IsOnline) {
//m_pUi->onSwitchOnlineModel(m_pState->IsOnline);//<2F><><EFBFBD><EFBFBD>ģʽ <20><><EFBFBD><EFBFBD>ģʽ<C4A3>л<EFBFBD>
}
QString strMsg;
if (bConnect)
{
strMsg += QString("IP:%1 %2").arg(addr).arg(tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
}
else
{
strMsg += QString("IP:%1 %2").arg(addr).arg(tr("<EFBFBD>ѶϿ<EFBFBD>"));
}
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)
{
/*<2A><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>*/
if (SendModelLibTask) {
if (SendModelLibTask->isRunning())
SendModelLibTask->stop();
if (m_pNet)
m_pNet->sendModelNum(m_pCtrl->getAllModelMapPtr()->size());
SendModelLibTask->start();
}
}
//<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>رն<D8B1>ʱ<EFBFBD><CAB1>
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<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")));
}
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)
{
/*<2A><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD>PLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD> <20>Լ<EFBFBD><D4BC>Ƿ<EFBFBD><C7B7>յ<EFBFBD>ͼ<EFBFBD><CDBC> */
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)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if (m_pState->m_CameraTrigeType == 0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
{
if (m_pState->bLockDetect == true) {
//CC_Action(CC_AC_NEXT);
// trigerCamera();
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("<EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>"));
else
str = QString(tr("<EFBFBD>ѹر<EFBFBD>"));
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()
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (m_pNet)
{
m_pNet->sendPulse(6000, m_pState->IsDetect, m_pState->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);}"));
}
//չʾ<D5B9><CABE>Ϣ
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);
}