|
|
|
|
|
#include "lpMainWin.h"
|
|
|
|
|
|
#include "quserinfo_global.h"
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
#include "qmysplashscreen.h"
|
|
|
|
|
|
#include "InfoFile.h"
|
|
|
|
|
|
#include "WheelCtrl.h"
|
|
|
|
|
|
#include "QWorkMgrCtrl.h"
|
|
|
|
|
|
#include "qworkmgrui.h"
|
|
|
|
|
|
#include "IWheelModel.h"
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
#include "HubBase.h"
|
|
|
|
|
|
#include <QToolButton>
|
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
|
#include "saveimgthread.h"
|
|
|
|
|
|
#include "lpGlobalData.h"
|
|
|
|
|
|
#include "qpulpewidget.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "QZkJsonParser.h"
|
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
#include "databasesql.h"
|
|
|
|
|
|
#include "lpCryptokey.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define VERSION_HUB "3.0.1.4"
|
|
|
|
|
|
#define VERSION_ALG "3.0.1.3"
|
|
|
|
|
|
#define UPDATE_TIME "2021-09-30"
|
|
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lpMainWin::lpMainWin(QWidget *parent)
|
|
|
|
|
|
: QMainWindow(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
{//加载语言设置
|
|
|
|
|
|
QSettings languageSetting("hubdetect.ini", QSettings::IniFormat);
|
|
|
|
|
|
QString strLanguage = languageSetting.value("language", "Chinese").toString();
|
|
|
|
|
|
SetLanguage(strLanguage);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this->setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
qRegisterMetaType<TimeStruct>("TimeStruct");
|
|
|
|
|
|
onInitCoreCtrl();//初始化CoreCtrl模块 相机相关处理模块
|
|
|
|
|
|
onInitEngineCtrl();
|
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
onInitAbout();
|
|
|
|
|
|
setupTrayIcon();
|
|
|
|
|
|
|
|
|
|
|
|
lpGlobalConfig::instance()->loadStandParam();
|
|
|
|
|
|
{
|
|
|
|
|
|
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()));//IP设置
|
|
|
|
|
|
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.action_designer, SIGNAL(triggered()), this, SLOT(onActionClicked()));//模板标定
|
|
|
|
|
|
connect(ui.action_ImageCali, SIGNAL(triggered()), this, SLOT(onActionClicked()));//图像标定
|
|
|
|
|
|
connect(ui.action_register, SIGNAL(triggered()), this, SLOT(onActionClicked()));//
|
|
|
|
|
|
connect(ui.actionalgo, 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()));
|
|
|
|
|
|
|
|
|
|
|
|
ui.action_userManager->setVisible(false);
|
|
|
|
|
|
|
|
|
|
|
|
QMenu *pToolMenu = new QMenu(this);
|
|
|
|
|
|
pToolMenu->addAction(ui.action_ImageCali);//图像标定
|
|
|
|
|
|
pToolMenu->addAction(ui.action_debug);
|
|
|
|
|
|
pToolMenu->addAction(ui.actionSystemSeting);
|
|
|
|
|
|
pToolMenu->addAction(ui.actioncamSetting);
|
|
|
|
|
|
pToolMenu->addAction(ui.actionalgo);
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
QMenu *pHelpMenu = new QMenu(this);
|
|
|
|
|
|
pHelpMenu->addAction(ui.action_about);
|
|
|
|
|
|
pHelpMenu->addAction(ui.action_register);
|
|
|
|
|
|
QToolButton* pHelptool = new QToolButton(this);
|
|
|
|
|
|
pHelptool->setMenu(pHelpMenu);
|
|
|
|
|
|
pHelptool->setIcon(QIcon(":/ToolBarPic/ToolBarpic/help.png"));
|
|
|
|
|
|
pHelptool->setText(tr("帮助"));
|
|
|
|
|
|
pHelptool->setToolTip(tr("帮助"));
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{//系统状态栏展示UI初始化
|
|
|
|
|
|
m_pLbCurrentTime = 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_pLbDetectState->setMinimumWidth(200);
|
|
|
|
|
|
m_pLbDetectState->setFont(m_font);
|
|
|
|
|
|
m_pLbDetectState->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
|
|
|
|
|
|
|
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,1);
|
|
|
|
|
|
ui.statusBar->addPermanentWidget(m_pLbCurrentTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
//加载用户管理模块
|
|
|
|
|
|
loadUserModel();
|
|
|
|
|
|
//初始化模型管理模块
|
|
|
|
|
|
{//模板库核心管理模块 wheelctrl
|
|
|
|
|
|
m_pCtrl = new WheelCtrl(QCoreApplication::applicationDirPath(), nullptr);
|
|
|
|
|
|
m_pWorkCtrl = new QWorkMgrCtrl(m_pCtrl);//工单管理模块
|
|
|
|
|
|
m_pWorkCtrl->readManageFile();
|
|
|
|
|
|
m_pWorkUI = new QWorkMgrUI(m_pWorkCtrl, m_pCtrl);//工单管理UI
|
|
|
|
|
|
m_pWorkUI->InitUI();
|
|
|
|
|
|
connect(m_pWorkUI, SIGNAL(sgUpdatedefect()), this, SLOT(onUpdateDefect()));
|
|
|
|
|
|
|
|
|
|
|
|
m_pModelMgrDlg = new QModelMgrDlg(m_pCtrl);//模板管理
|
|
|
|
|
|
//当某个模板加入训练或者不加入训练时修改原来工作单中的模板信息
|
|
|
|
|
|
connect(m_pModelMgrDlg, SIGNAL(sgModifyModel(QString)), this, SLOT(modWorkMgr(QString)));//修改模板名
|
|
|
|
|
|
connect(m_pModelMgrDlg, SIGNAL(sgUpdatedefect()), this, SLOT(onUpdateDefect()));//更新检测列表
|
|
|
|
|
|
connect(m_pModelMgrDlg, SIGNAL(sgAddNewModel(QString)), this, SLOT(onSlotAddNewModel(QString)));//新建模板型号
|
|
|
|
|
|
connect(m_pModelMgrDlg, SIGNAL(sgDelOldModel(QString)), this, SLOT(onSlotDelOldModel(QString)));//删除模板型号
|
|
|
|
|
|
|
|
|
|
|
|
m_pDebugDlg = new QDebugDlg();//调试界面
|
|
|
|
|
|
m_pDebugDlg->onSetCtrl(m_pCtrl);
|
|
|
|
|
|
connect(m_pDebugDlg, SIGNAL(sgTriggerCam()), this, SLOT(onTriggerCam()));
|
|
|
|
|
|
|
|
|
|
|
|
m_pSystemConfigUI = new lpSystemConfigUI();//系统参数配置页面
|
|
|
|
|
|
m_CamSettingDlg = new QCamSettingDlg();//相机设置页面
|
|
|
|
|
|
m_CamSettingDlg->setCoreCtrlPtr(m_pCoreCtrl);
|
|
|
|
|
|
|
|
|
|
|
|
//检测结果预览图UI初始化
|
|
|
|
|
|
m_pixMapList = new QPixmapListBar(ui.tp_main_tabWidget);
|
|
|
|
|
|
ui.tp_main_tabWidget->insertTab(0, m_pixMapList, tr("历史"));
|
|
|
|
|
|
ui.tp_main_tabWidget->setCurrentIndex(0);
|
|
|
|
|
|
|
|
|
|
|
|
m_pImageCaliUI = new lpImageCaliUI();//图像标定页面
|
|
|
|
|
|
m_pAlgParamDlg = new QAlgParamDlg();//算法参数调试页面
|
|
|
|
|
|
|
|
|
|
|
|
connect(m_pSystemConfigUI, SIGNAL(sgUpdateInfo()), this, SLOT(setWindowTitleInfo()));//系统标题
|
|
|
|
|
|
}
|
|
|
|
|
|
onSetModel();
|
|
|
|
|
|
{
|
|
|
|
|
|
connect(this, SIGNAL(sgShowMsg(QString, bool)), this, SLOT(onTcpConnet(QString, bool)));
|
|
|
|
|
|
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)));
|
|
|
|
|
|
}
|
|
|
|
|
|
//{//PLC tcp 通讯
|
|
|
|
|
|
// m_pPlcDevice = new QPLCDevice();
|
|
|
|
|
|
// m_pPlcDevice->onInitDevice();
|
|
|
|
|
|
// m_pPlcDevice->onStartServer(lpGlobalConfig::instance()->tcpServerPort);
|
|
|
|
|
|
// connect(m_pPlcDevice, SIGNAL(sgTrigerCam(int)), this, SLOT(onPLCTrigerCam(int)));
|
|
|
|
|
|
//}
|
|
|
|
|
|
{
|
|
|
|
|
|
QTimer::singleShot(3000, [&]() {
|
|
|
|
|
|
ui.btn_start_detect->setText(tr("停止检测"));
|
|
|
|
|
|
lpGlobalConfig::instance()->IsDetect = true;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (lpGlobalConfig::instance()->m_AutoSendTick2COM)
|
|
|
|
|
|
m_wfPulseTimer.start(1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
connect(this, SIGNAL(sgAutoExposure()), this, SLOT(onAutoExposure()));
|
|
|
|
|
|
QString strPath = QApplication::applicationDirPath();
|
|
|
|
|
|
readExposureTimeConfig(strPath);
|
|
|
|
|
|
m_appRootPath = strPath;
|
|
|
|
|
|
|
|
|
|
|
|
connect(this, SIGNAL(sgShowDetectLog(QString)), this, SLOT(onShowDetectLog(QString)));
|
|
|
|
|
|
setWindowTitleInfo();
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
tcpServerInit();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 (m_pLbCurrentTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pLbCurrentTime;
|
|
|
|
|
|
m_pLbCurrentTime = 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 (m_pWorkCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pWorkCtrl;
|
|
|
|
|
|
m_pWorkCtrl = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pWorkUI)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pWorkUI;
|
|
|
|
|
|
m_pWorkUI = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pAlgParamDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pAlgParamDlg;
|
|
|
|
|
|
m_pAlgParamDlg = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pModelMgrDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pModelMgrDlg;
|
|
|
|
|
|
m_pModelMgrDlg = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pDebugDlg) {
|
|
|
|
|
|
delete m_pDebugDlg;
|
|
|
|
|
|
m_pDebugDlg = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pSystemConfigUI)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pSystemConfigUI;
|
|
|
|
|
|
m_pSystemConfigUI = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_CamSettingDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_CamSettingDlg;
|
|
|
|
|
|
m_CamSettingDlg = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_ImgViewer) {
|
|
|
|
|
|
delete m_ImgViewer;
|
|
|
|
|
|
m_ImgViewer = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pixMapList) {
|
|
|
|
|
|
delete m_pixMapList;
|
|
|
|
|
|
m_pixMapList = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pImageCaliUI)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pImageCaliUI;
|
|
|
|
|
|
m_pImageCaliUI = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pCheckLineseUI)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pCheckLineseUI;
|
|
|
|
|
|
m_pCheckLineseUI = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pLabelInfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pLabelInfo;
|
|
|
|
|
|
m_pLabelInfo = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pDesigner)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pDesigner;
|
|
|
|
|
|
m_pDesigner = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
//if (m_pPlcDevice)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// delete m_pPlcDevice;
|
|
|
|
|
|
// m_pPlcDevice = nullptr;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_pDllCoreCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pDllCoreCtrl;
|
|
|
|
|
|
m_pDllCoreCtrl = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pDllDesigner)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pDllDesigner;
|
|
|
|
|
|
m_pDllDesigner = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pDllEngineCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pDllEngineCtrl;
|
|
|
|
|
|
m_pDllEngineCtrl = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool lpMainWin::onInitCoreCtrl()
|
|
|
|
|
|
{//corectrl 核心相机、算法检测等管理模块初始化
|
|
|
|
|
|
//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(&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);
|
|
|
|
|
|
|
|
|
|
|
|
if(m_pCoreCtrl->ICameraKeys().size()>0)
|
|
|
|
|
|
m_camKey = m_pCoreCtrl->ICameraKeys().first();
|
|
|
|
|
|
else {
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool lpMainWin::onInitEngineCtrl()
|
|
|
|
|
|
{//定位检测算法管理模块 初始化
|
|
|
|
|
|
if (m_pDllEngineCtrl == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pDllEngineCtrl = new CDllDetectorEngine();
|
|
|
|
|
|
if (m_pDllEngineCtrl != nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pEngineCtrl = m_pDllEngineCtrl->m_pDE;
|
|
|
|
|
|
if (m_pEngineCtrl == 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_pEngineCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pDesigner->Initialize(m_pEngineCtrl);
|
|
|
|
|
|
}
|
|
|
|
|
|
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 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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
QLocale::setDefault(QLocale(translatorFileName));
|
|
|
|
|
|
QString transDir = strDirPath + translatorFileName;
|
|
|
|
|
|
SearchQmFile(transDir);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*主线程接收图像 camKey 相机唯一序列号名 img 图像*/
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_CamSettingDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_CamSettingDlg->isHidden())
|
|
|
|
|
|
return;
|
|
|
|
|
|
m_CamSettingDlg->onShowImage(img);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*多线程发送算法结果 camKey 相机唯一序列号 vMap 图像检测结果*/
|
|
|
|
|
|
void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap)
|
|
|
|
|
|
{
|
|
|
|
|
|
QImage srcImg = vMap.value("srcImage").value<QImage>();
|
|
|
|
|
|
cv::Mat srcMat = QImageToMat(srcImg);
|
|
|
|
|
|
Result2Ui *pResult = parseMap(vMap.value("result").toMap());
|
|
|
|
|
|
if (pResult == nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
pResult = new Result2Ui();
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
(1)解析出型号识别的结果,如果识别结果是有字符的,表示识别型号成功,执行后续的定位操作;如果识别结果是NG,则直接返回退出,发送识别失败给PLC。
|
|
|
|
|
|
(2)执行定位算法,解析定位算法的结果
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
pResult->m_pixSrc = QPixmap::fromImage(srcImg);
|
|
|
|
|
|
if (!pResult->m_strModel.isEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.main_value_Result->setText("定位中");
|
|
|
|
|
|
QString strMode = pResult->m_strModel;
|
|
|
|
|
|
AlgResultCallBack func = std::bind(&lpMainWin::IEngineResult, this, std::placeholders::_1);
|
|
|
|
|
|
m_pEngineCtrl->detect(srcMat, strMode, func);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
/*型号识别失败,*/
|
|
|
|
|
|
ui.main_value_Result->setText("没有找到相关task");
|
|
|
|
|
|
ui.main_label_angle->setText("-");
|
|
|
|
|
|
ui.main_value_DetectTime->setText("-");
|
|
|
|
|
|
ui.main_value_Score->setText("-");
|
|
|
|
|
|
|
|
|
|
|
|
ValueResult valueRlt;
|
|
|
|
|
|
valueRlt.angle = 361;
|
|
|
|
|
|
valueRlt.strModel = "NG";
|
|
|
|
|
|
valueRlt.score = 0;
|
|
|
|
|
|
int h = srcImg.height();
|
|
|
|
|
|
int w = srcImg.width();
|
|
|
|
|
|
uchar* p = srcImg.bits();
|
|
|
|
|
|
if(!srcImg.isNull())
|
|
|
|
|
|
valueRlt.pixmap = QPixmap::fromImage(srcImg);
|
|
|
|
|
|
valueRlt.strRunState = "no task";
|
|
|
|
|
|
valueRlt.resultType = 4;//识别出型号 但未标定
|
|
|
|
|
|
onSaveValveResult(valueRlt);
|
|
|
|
|
|
}
|
|
|
|
|
|
emit(sgShowImgState(tr("显示识别结果")));
|
|
|
|
|
|
if (pResult)
|
|
|
|
|
|
{
|
|
|
|
|
|
onShowResult(pResult);
|
|
|
|
|
|
if (m_pDebugDlg) {
|
|
|
|
|
|
m_pDebugDlg->onShowResult(pResult);
|
|
|
|
|
|
}
|
|
|
|
|
|
saveImage(pResult);
|
|
|
|
|
|
m_pCtrl->saveResult(pResult);
|
|
|
|
|
|
delete pResult;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*多线程获取算法参数*/
|
|
|
|
|
|
QVariant lpMainWin::IGetVariantById(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_nDiffTrigNum--;//进入到这里 表示获取到了图片
|
|
|
|
|
|
emit(sgShowImgState(tr("获得图像,正在计算中...")));
|
|
|
|
|
|
emit(sgGetImg());
|
|
|
|
|
|
|
|
|
|
|
|
QVariantMap vMap;
|
|
|
|
|
|
int nThickness = 0;
|
|
|
|
|
|
vMap.insert("thickness", QVariant(nThickness));
|
|
|
|
|
|
double dDiameter = 0;// = (-794.25 * nThickness / 1000000.0 + 0.775960);
|
|
|
|
|
|
dDiameter = (lpGlobalConfig::instance()->m_k * nThickness + lpGlobalConfig::instance()->m_b);
|
|
|
|
|
|
vMap.insert("d2h", dDiameter);
|
|
|
|
|
|
vMap.insert("useThickness", lpGlobalConfig::instance()->bUseThickness);
|
|
|
|
|
|
vMap.insert("useDiameter", lpGlobalConfig::instance()->bUseDiameter);
|
|
|
|
|
|
vMap.insert("IsCutImg", lpGlobalConfig::instance()->m_UseCutImg);
|
|
|
|
|
|
|
|
|
|
|
|
vMap.insert("Threshold", lpGlobalConfig::instance()->algParam.m_AlgThres);//算法图像阈值
|
|
|
|
|
|
vMap.insert("useBackground", lpGlobalConfig::instance()->algParam.m_UseBackground > 0 ? true : false);//使用背景图
|
|
|
|
|
|
vMap.insert("RatioType", lpGlobalConfig::instance()->algParam.m_RatioDetectType);//偏距检测模式 启用方式
|
|
|
|
|
|
vMap.insert("bEqual", lpGlobalConfig::instance()->algParam.m_bUseEqual);//使用使用图像增强
|
|
|
|
|
|
vMap.insert("filterSize", lpGlobalConfig::instance()->algParam.m_filterSize);//过滤圆大小
|
|
|
|
|
|
|
|
|
|
|
|
vMap.insert("Circle_ACThres", lpGlobalConfig::instance()->algParam.m_Circle_ACThres);//
|
|
|
|
|
|
vMap.insert("Circle_EdgeWidth", lpGlobalConfig::instance()->algParam.m_Circle_EdgeWidth);//
|
|
|
|
|
|
vMap.insert("Circle_Polarity", lpGlobalConfig::instance()->algParam.m_Circle_Polarity);//
|
|
|
|
|
|
vMap.insert("AppPath", m_appRootPath);
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
return vMap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::IEngineResult(QVariantMap vMap)
|
|
|
|
|
|
{
|
|
|
|
|
|
QImage srcImg = vMap.value("originImage").value<QImage>();
|
|
|
|
|
|
bool taskCali = vMap.value("taskCali").toBool();
|
|
|
|
|
|
if (taskCali == false)//模板未标定
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.main_value_Result->setText("该型号未标定");
|
|
|
|
|
|
ui.main_value_Result->setStyleSheet("background-color: rgb(255, 212, 83);");
|
|
|
|
|
|
ui.main_label_angle->setText("-");
|
|
|
|
|
|
ui.main_value_Center_point->setText("-");
|
|
|
|
|
|
ui.main_value_DetectTime->setText("-");
|
|
|
|
|
|
ui.main_value_Score->setText("-");
|
|
|
|
|
|
//获取图像 保存到当天NG图
|
|
|
|
|
|
|
|
|
|
|
|
ValueResult valueRlt;
|
|
|
|
|
|
valueRlt.angle = 361;
|
|
|
|
|
|
valueRlt.strModel = "NG";
|
|
|
|
|
|
valueRlt.score = 0;
|
|
|
|
|
|
valueRlt.strRunState = "no Cali";
|
|
|
|
|
|
valueRlt.pixmap = QPixmap::fromImage(srcImg);
|
|
|
|
|
|
valueRlt.resultType = 2;//识别出型号 但未标定
|
|
|
|
|
|
onSaveValveResult(valueRlt);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
//不包含算法检测结果,表示没有相关task
|
|
|
|
|
|
if (!vMap.contains("AlgoResult"))
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.main_value_Result->setText("没有找到相关task");
|
|
|
|
|
|
ui.main_value_Result->setStyleSheet("background-color: rgb(255, 212, 83);");
|
|
|
|
|
|
ui.main_label_angle->setText("-");
|
|
|
|
|
|
ui.main_value_Center_point->setText("-");
|
|
|
|
|
|
ui.main_value_DetectTime->setText("-");
|
|
|
|
|
|
ui.main_value_Score->setText("-");
|
|
|
|
|
|
//获取图像 保存到当天NG图
|
|
|
|
|
|
|
|
|
|
|
|
ValueResult valueRlt;
|
|
|
|
|
|
valueRlt.angle = 361;
|
|
|
|
|
|
valueRlt.strModel = "NG";
|
|
|
|
|
|
valueRlt.score = 0;
|
|
|
|
|
|
valueRlt.strRunState = "no task";
|
|
|
|
|
|
valueRlt.pixmap = QPixmap::fromImage(srcImg);
|
|
|
|
|
|
valueRlt.resultType = 3;//识别出型号 但未标定
|
|
|
|
|
|
onSaveValveResult(valueRlt);
|
|
|
|
|
|
}
|
|
|
|
|
|
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 maskImg = algResult.value("image").value<QImage>();
|
|
|
|
|
|
QString str = algResult.value("resultTip").toString();
|
|
|
|
|
|
QPointF centerPoint = algResult.value("centerPoint").toPointF();
|
|
|
|
|
|
QString taskName = vMap.value("taskName").toString();
|
|
|
|
|
|
double taskTime = vMap.value("tasktime").toDouble();
|
|
|
|
|
|
ui.main_label_angle->setText(QString("%1").arg(dAngle));
|
|
|
|
|
|
|
|
|
|
|
|
ValueResult valueRlt;
|
|
|
|
|
|
valueRlt.angle = dAngle;
|
|
|
|
|
|
valueRlt.strModel = taskName;
|
|
|
|
|
|
valueRlt.centerPix = centerPoint;
|
|
|
|
|
|
|
|
|
|
|
|
valueRlt.score = matchScore;
|
|
|
|
|
|
valueRlt.errorCode = errorType;
|
|
|
|
|
|
valueRlt.runtime = taskTime;
|
|
|
|
|
|
valueRlt.pixmap = QPixmap::fromImage(maskImg);
|
|
|
|
|
|
valueRlt.strRunState = "run Alg success";
|
|
|
|
|
|
/*中心坐标偏移值计算*/
|
|
|
|
|
|
int centerX = centerPoint.x() * lpGlobalConfig::instance()->fScale + lpGlobalConfig::instance()->pointXOffset;
|
|
|
|
|
|
int centerY = centerPoint.y() * lpGlobalConfig::instance()->fScale + lpGlobalConfig::instance()->pointYOffset;
|
|
|
|
|
|
valueRlt.center.setX(centerX);
|
|
|
|
|
|
valueRlt.center.setY(centerY);
|
|
|
|
|
|
|
|
|
|
|
|
if (dAngle >= 361)//NG
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.main_value_Result->setStyleSheet("background-color: rgb(250, 0, 0);");
|
|
|
|
|
|
ui.main_value_Result->setText("找不到气门芯");
|
|
|
|
|
|
ui.main_value_Center_point->setText("-");
|
|
|
|
|
|
ui.main_value_Score->setText(QString("%1").arg(matchScore));
|
|
|
|
|
|
valueRlt.strModel = "NG";
|
|
|
|
|
|
valueRlt.resultType = 1;//识别出型号 但未标定
|
|
|
|
|
|
}
|
|
|
|
|
|
else {//OK
|
|
|
|
|
|
ui.main_value_Result->setStyleSheet("background-color: rgb(0, 250, 0);");
|
|
|
|
|
|
ui.main_value_Result->setText("定位成功");
|
|
|
|
|
|
ui.main_value_Center_point->setText(QString("(%1,%2)").arg(centerPoint.x()).arg(centerPoint.y()));
|
|
|
|
|
|
ui.main_value_Score->setText(QString("%1").arg(matchScore));
|
|
|
|
|
|
valueRlt.resultType = 0;//识别出型号 但未标定
|
|
|
|
|
|
}
|
|
|
|
|
|
onSaveValveResult(valueRlt);
|
|
|
|
|
|
/*展示结果*/
|
|
|
|
|
|
ui.main_value_DetectTime->setText(QString("%1s").arg(taskTime));
|
|
|
|
|
|
if (m_ImgViewer)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!maskImg.isNull())
|
|
|
|
|
|
m_ImgViewer->setImg(maskImg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::showWidget()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (lpGlobalConfig::instance()->bRunBackRunning == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
setMainWindowVisibility(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
setMainWindowVisibility(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
if(m_trayIcon)
|
|
|
|
|
|
m_trayIcon->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onLogInOut(QString strName, int level, int state)
|
|
|
|
|
|
{
|
|
|
|
|
|
lpGlobalData::instance()->m_curUser = strName;
|
|
|
|
|
|
lpGlobalData::instance()->m_level = level;
|
|
|
|
|
|
if (state == 0) {
|
|
|
|
|
|
m_pCtrl->setUser(strName, level);
|
|
|
|
|
|
ui.action_Login->setText(tr("注 销"));
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pCtrl->setUser(strName, level);
|
|
|
|
|
|
ui.action_Login->setText(tr("登 录"));
|
|
|
|
|
|
}
|
|
|
|
|
|
onUpdateByLevel(level);
|
|
|
|
|
|
if (m_pModelMgrDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pModelMgrDlg->onUserLevel(level);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onActionClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strObj = sender()->objectName();
|
|
|
|
|
|
if ("action_userManager" == strObj) {
|
|
|
|
|
|
/*用户管理*/
|
|
|
|
|
|
if (m_pUserCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pUserCtrl->ShowUserMgrDlg(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("提示"), tr("该功能未启用."), QMessageBox::Yes, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Yes, tr("确认"));
|
|
|
|
|
|
infobox.exec();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("action_Login" == strObj) {
|
|
|
|
|
|
/*用户登陆*/
|
|
|
|
|
|
if (m_pUserCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_pUserCtrl->getLoginState() == EM_LOGIN)
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("提示"), QString("%1 %2 ?").arg(tr("你确定要注销")).arg(m_pUserCtrl->CurUser()), QMessageBox::Yes | QMessageBox::No, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Yes, tr("确认"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::No, tr("取消"));
|
|
|
|
|
|
if (infobox.exec() == QMessageBox::Yes) {
|
|
|
|
|
|
m_pUserCtrl->LogOutUser();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pUserCtrl->CheckLogin(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("提示"), tr("该功能未启用."), QMessageBox::Yes, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Yes, tr("确认"));
|
|
|
|
|
|
infobox.exec();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("action_about" == strObj) {
|
|
|
|
|
|
m_aboutDlg.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
m_aboutDlg.setParent(this);
|
|
|
|
|
|
m_aboutDlg.setWindowTitle(tr("关于"));
|
|
|
|
|
|
m_aboutDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
|
|
|
m_aboutDlg.setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
m_aboutDlg.setAttribute(Qt::WA_ShowModal, true);
|
|
|
|
|
|
m_aboutDlg.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(":/image/leaper"));
|
|
|
|
|
|
//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::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint );
|
|
|
|
|
|
m_pWorkUI->setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
m_pWorkUI->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
m_pWorkUI->setAttribute(Qt::WA_ShowModal, true);
|
|
|
|
|
|
m_pWorkUI->onExec();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("action_checkdata" == strObj) {//历史数据查询
|
|
|
|
|
|
QProcess process;
|
|
|
|
|
|
process.setWorkingDirectory(QCoreApplication::applicationDirPath());
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
|
QString strTaskName = "lpReportd.exe";
|
|
|
|
|
|
#else
|
|
|
|
|
|
QString strTaskName = "lpReport.exe";
|
|
|
|
|
|
#endif
|
|
|
|
|
|
process.startDetached(strTaskName);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("action_modelmgr" == strObj) {//模板管理
|
|
|
|
|
|
if (lpGlobalConfig::instance()->IsDetect == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//正在检测 不能使用模板管理功能
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("提示"), tr("请停止检测再使用该功能."), QMessageBox::Yes, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Yes, tr("确认"));
|
|
|
|
|
|
infobox.exec();
|
|
|
|
|
|
onStrongButton();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_pModelMgrDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pModelMgrDlg->setParent(this);
|
|
|
|
|
|
m_pModelMgrDlg->setWindowTitle(tr("模板管理"));
|
|
|
|
|
|
m_pModelMgrDlg->setWindowFlags(Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
|
|
|
|
|
|
m_pModelMgrDlg->setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
m_pModelMgrDlg->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
m_pModelMgrDlg->setAttribute(Qt::WA_ShowModal, true);
|
|
|
|
|
|
m_pModelMgrDlg->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("actionSystemSeting" == strObj) {//系统参数设置
|
|
|
|
|
|
if (m_pSystemConfigUI)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pSystemConfigUI->setParent(this);
|
|
|
|
|
|
m_pSystemConfigUI->setWindowTitle(tr("系统参数设置"));
|
|
|
|
|
|
m_pSystemConfigUI->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
|
|
|
m_pSystemConfigUI->setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
m_pSystemConfigUI->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
m_pSystemConfigUI->setAttribute(Qt::WA_ShowModal, true);
|
|
|
|
|
|
m_pSystemConfigUI->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("actioncamSetting" == strObj) {
|
|
|
|
|
|
if (m_CamSettingDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_CamSettingDlg->setParent(this);
|
|
|
|
|
|
m_CamSettingDlg->setWindowTitle(tr("相机配置"));
|
|
|
|
|
|
m_CamSettingDlg->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
|
|
|
m_CamSettingDlg->setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
m_CamSettingDlg->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
m_CamSettingDlg->setAttribute(Qt::WA_ShowModal, true);
|
|
|
|
|
|
m_CamSettingDlg->onInitWidget();
|
|
|
|
|
|
m_CamSettingDlg->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("action_designer" == strObj) {
|
|
|
|
|
|
if (lpGlobalConfig::instance()->IsDetect == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
//正在检测 不能使用模板管理功能
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("提示"), tr("请停止检测再使用该功能."), QMessageBox::Yes, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Yes, tr("确认"));
|
|
|
|
|
|
infobox.exec();
|
|
|
|
|
|
onStrongButton();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pDesigner) {
|
|
|
|
|
|
m_pDesigner->ShowMainFrame(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("action_ImageCali" == strObj) {
|
|
|
|
|
|
if (m_pImageCaliUI) {
|
|
|
|
|
|
m_pImageCaliUI->setParent(this);
|
|
|
|
|
|
m_pImageCaliUI->setWindowTitle(tr("图像标定"));
|
|
|
|
|
|
m_pImageCaliUI->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
|
|
|
m_pImageCaliUI->setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
m_pImageCaliUI->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
m_pImageCaliUI->setAttribute(Qt::WA_ShowModal, true);
|
|
|
|
|
|
m_pImageCaliUI->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("action_register" == 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(":/image/leaper"));
|
|
|
|
|
|
m_pCheckLineseUI->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
m_pCheckLineseUI->setAttribute(Qt::WA_ShowModal, true);
|
|
|
|
|
|
m_pCheckLineseUI->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ("actionalgo" == strObj) {
|
|
|
|
|
|
if (m_pAlgParamDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pAlgParamDlg->setParent(this);
|
|
|
|
|
|
m_pAlgParamDlg->setWindowTitle(tr("算法参数"));
|
|
|
|
|
|
m_pAlgParamDlg->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
|
|
|
m_pAlgParamDlg->setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
//m_pAlgParamDlg->setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
//m_pAlgParamDlg->setAttribute(Qt::WA_ShowModal, true);
|
|
|
|
|
|
m_pAlgParamDlg->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onButtonClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strObj = sender()->objectName();
|
|
|
|
|
|
if ("btn_start_detect" == strObj)//开始
|
|
|
|
|
|
{
|
|
|
|
|
|
//开始检测按钮
|
|
|
|
|
|
if (lpGlobalConfig::instance()->IsDetect == false) {
|
|
|
|
|
|
ui.btn_start_detect->setText(tr("停止检测"));
|
|
|
|
|
|
QString str = tr("按下了开始检测按钮,检测功能开启");
|
|
|
|
|
|
m_pCtrl->addLog(str, emTypeRunState);
|
|
|
|
|
|
|
|
|
|
|
|
lpGlobalConfig::instance()->bLockDetect = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
ui.btn_start_detect->setText(tr("开始检测"));
|
|
|
|
|
|
QString str = tr("按下了停止检测按钮,检测功能关闭");
|
|
|
|
|
|
m_pCtrl->addLog(str, emTypeRunState);
|
|
|
|
|
|
lpGlobalConfig::instance()->bLockDetect = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
lpGlobalConfig::instance()->IsDetect = !lpGlobalConfig::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()) {
|
|
|
|
|
|
QString str = m_pCtrl->getUserName() + ":" + tr("按下了清零按钮,数据全部清零");
|
|
|
|
|
|
m_pCtrl->addLog(str, emTypeUseState);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString lpMainWin::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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::timerEvent(QTimerEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (event->timerId() == m_timerID) {
|
|
|
|
|
|
m_runTimeCount++;
|
|
|
|
|
|
|
|
|
|
|
|
if (m_pLbCurrentTime) {
|
|
|
|
|
|
QString m_currentTime = hubBase::genDateTime();
|
|
|
|
|
|
QString strlong = SecondTimeString(m_runTimeCount);
|
|
|
|
|
|
QString strTimeTitle = tr("运行时长:");
|
|
|
|
|
|
QString strShow = QString("%1 %2 %3").arg(m_currentTime).arg(strTimeTitle).arg(strlong);
|
|
|
|
|
|
m_pLbCurrentTime->setText(strShow);
|
|
|
|
|
|
m_pLbCurrentTime->setStyleSheet("font: 14px;");
|
|
|
|
|
|
}
|
|
|
|
|
|
// state
|
|
|
|
|
|
if (m_pLbDetectState) {
|
|
|
|
|
|
QString strDetectState = lpGlobalConfig::instance()->IsDetect == true ? tr("检测中...") : tr("已停止检测...");
|
|
|
|
|
|
m_pLbDetectState->setText(strDetectState);
|
|
|
|
|
|
if (lpGlobalConfig::instance()->IsDetect) {
|
|
|
|
|
|
m_pLbDetectState->setStyleSheet("font: bold 14px;background-color: green;");
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
m_pLbDetectState->setStyleSheet("font: bold 14px;background-color: red;");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_pLbUser) {
|
|
|
|
|
|
QString show_label = m_pCtrl->getUserName();
|
|
|
|
|
|
//m_pLbUser->setText(tr("当前用户:") + show_label);
|
|
|
|
|
|
m_pLbUser->setText("");
|
|
|
|
|
|
m_pLbUser->setStyleSheet("font: 14px;");
|
|
|
|
|
|
}
|
|
|
|
|
|
onTcpHeartBit();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (event->timerId() == m_timerID_btn)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.btn_start_detect->setStyleSheet("");
|
|
|
|
|
|
killTimer(m_timerID_btn);
|
|
|
|
|
|
m_timerID_btn = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::closeEvent(QCloseEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (lpGlobalConfig::instance()->bRunBackClosing == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_bExit == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
setMainWindowVisibility(false);
|
|
|
|
|
|
return event->ignore();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return event->accept();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::changeEvent(QEvent *event)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.retranslateUi(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::onSetModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
|
|
|
*重新加载模板
|
|
|
|
|
|
重新设置模板到算法中使用
|
|
|
|
|
|
*/
|
|
|
|
|
|
forDefectList = m_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->getAllTrainModelName().size() - 1);
|
|
|
|
|
|
ui.main_showWorkLabel->setText(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
///*******************************************************************************
|
|
|
|
|
|
Q_SLOT void lpMainWin::onUpdateDefect() {
|
|
|
|
|
|
forDefectList = m_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->getAllTrainModelName().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::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::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)
|
|
|
|
|
|
{
|
|
|
|
|
|
onTriggerCam();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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::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);}"));
|
|
|
|
|
|
ui.main_value_Result->setText("获取到图像");
|
|
|
|
|
|
ui.main_value_Result->setStyleSheet("");
|
|
|
|
|
|
ui.main_label_angle->setText("-");
|
|
|
|
|
|
ui.main_value_DetectTime->setText("-");
|
|
|
|
|
|
ui.main_lb_res_model_time->setText("-");
|
|
|
|
|
|
ui.main_lb_res_model_id->setText("-");
|
|
|
|
|
|
ui.main_lb_res_model_score->setText("-");
|
|
|
|
|
|
ui.main_value_Center_point->setText("-");
|
|
|
|
|
|
ui.main_value_Score->setText("-");
|
|
|
|
|
|
ui.main_lb_res_model_pic->clear();
|
|
|
|
|
|
ui.main_lb_res_okng->setText("None");
|
|
|
|
|
|
ui.main_lb_res_okng->setStyleSheet("background-color: rgb(200, 255, 100);font: 75 24pt \"Consolas\"; ");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//展示信息
|
|
|
|
|
|
Q_SLOT void lpMainWin::onShowMsg(QString str)
|
|
|
|
|
|
{
|
|
|
|
|
|
QPulpewidget *pw = new QPulpewidget();
|
|
|
|
|
|
pw->setParent(this);
|
|
|
|
|
|
pw->showmessage(str);
|
|
|
|
|
|
connect(pw, SIGNAL(finished()), pw, SLOT(deleteLater()));
|
|
|
|
|
|
connect(pw, SIGNAL(finished()), this, SLOT(onInitPW()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onTriggerCam()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (lpGlobalConfig::instance()->IsDetect == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strMsg = QString("当前为停止检测状态,请按下开始检测再触发相机拍照");
|
|
|
|
|
|
emit sgShowDetectLog(strMsg);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_pCoreCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
QStringList strLst = m_pCoreCtrl->ICameraKeys();
|
|
|
|
|
|
m_pCoreCtrl->ISnapImage(strLst);
|
|
|
|
|
|
}
|
|
|
|
|
|
AckTriggerCam();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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>%10</p>"
|
|
|
|
|
|
).arg(tr("轮毂型号识别定位一体系统"))
|
|
|
|
|
|
.arg(tr("本软件由杭州利珀科技开发,用于轮毂型号识别和分类,可搭配流水线运输系统使用"))
|
|
|
|
|
|
.arg(tr("若需要进一步了解该产品的相关信息,请访问我们的网站"))
|
|
|
|
|
|
.arg(tr("软件版本")).arg(VERSION_HUB)
|
|
|
|
|
|
.arg(tr("算法版本")).arg(VERSION_ALG)
|
|
|
|
|
|
.arg(tr("最后更新时间")).arg(UPDATE_TIME)
|
|
|
|
|
|
.arg(tr("版权 (c) 属 杭州利珀科技有限公司 所有"));
|
|
|
|
|
|
m_aboutDlg.setFixedSize(500, 300);
|
|
|
|
|
|
QTextEdit* pEdit = new QTextEdit(&m_aboutDlg);
|
|
|
|
|
|
pEdit->setReadOnly(true);
|
|
|
|
|
|
pEdit->append(aboutString);
|
|
|
|
|
|
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_aboutDlg);
|
|
|
|
|
|
lbLayout->addWidget(pEdit, 2, 1, 1, 3);
|
|
|
|
|
|
|
|
|
|
|
|
lbLayout->addWidget(lbClose, 3, 2);
|
|
|
|
|
|
lbClose->setMaximumSize(QSize(100, 50));
|
|
|
|
|
|
connect(lbClose, SIGNAL(clicked()), &m_aboutDlg, SLOT(hide()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onLanguageChange(QString strLanguage)
|
|
|
|
|
|
{
|
|
|
|
|
|
QSettings languageSetting("hubdetect.ini", QSettings::IniFormat);
|
|
|
|
|
|
languageSetting.setValue("language", strLanguage);
|
|
|
|
|
|
SetLanguage(strLanguage);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
|
|
lpGlobalConfig::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("font: 75 24pt \"Consolas\";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("font: 75 24pt \"Consolas\";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());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
lpGlobalConfig::instance()->totalDetectNum++;
|
|
|
|
|
|
|
|
|
|
|
|
//show
|
|
|
|
|
|
ui.main_lb_res_model_time->setText(QString::number(pRlt->m_dRunTime, 'f', 2)+"s");
|
|
|
|
|
|
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::saveImage(Result2Ui* pRes)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (pRes == nullptr)
|
|
|
|
|
|
return;
|
|
|
|
|
|
qDebug() << "satrt tread save Image";
|
|
|
|
|
|
QString curExposureTimeStr = QString::number(getCurExposureTime());
|
|
|
|
|
|
|
|
|
|
|
|
QDir testDir;
|
|
|
|
|
|
bool IsTestDir = testDir.exists(lpGlobalConfig::instance()->m_SaveImgDirPath);
|
|
|
|
|
|
if (!IsTestDir)
|
|
|
|
|
|
lpGlobalConfig::instance()->m_SaveImgDirPath = lpGlobalConfig::instance()->m_applicationDirPath;
|
|
|
|
|
|
|
|
|
|
|
|
QString baseSavePath = lpGlobalConfig::instance()->m_SaveImgDirPath + "\\Data\\";
|
|
|
|
|
|
IsTestDir = testDir.exists(baseSavePath);
|
|
|
|
|
|
if (!IsTestDir)
|
|
|
|
|
|
testDir.mkpath(baseSavePath);
|
|
|
|
|
|
|
|
|
|
|
|
QString dataTime = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
|
|
|
|
|
QString fileSavePath = baseSavePath + "\\" + dataTime;
|
|
|
|
|
|
QString filename = pRes->m_strModel;
|
|
|
|
|
|
if (pRes->m_strModel != "NG")
|
|
|
|
|
|
{
|
|
|
|
|
|
QString goodsourceDir = fileSavePath + "\\Good";
|
|
|
|
|
|
filename += QString("_%1_%2_").arg((int)pRes->m_dThickness).arg((int)pRes->m_dDiameter);
|
|
|
|
|
|
filename += QDateTime::currentDateTime().toString("hhmmsszzz");
|
|
|
|
|
|
if (lpGlobalConfig::instance()->bSaveSrcOKImg == true) {
|
|
|
|
|
|
goodsourceDir += "\\Source";
|
|
|
|
|
|
goodsourceDir += "\\";
|
|
|
|
|
|
goodsourceDir += pRes->m_strModel;
|
|
|
|
|
|
QString resultpath = goodsourceDir + "\\" + filename + ".png";
|
|
|
|
|
|
saveImage(pRes->m_pixSrc, goodsourceDir + "\\", filename + ".png");
|
|
|
|
|
|
}
|
|
|
|
|
|
QString goodtargetDir = fileSavePath + "\\Good";
|
|
|
|
|
|
if (lpGlobalConfig::instance()->bSaveCutOKImg == true) {
|
|
|
|
|
|
goodtargetDir += "\\Target";
|
|
|
|
|
|
goodtargetDir += "\\";
|
|
|
|
|
|
goodtargetDir += pRes->m_strModel;
|
|
|
|
|
|
QString resultpath = goodtargetDir + "\\" + filename + "Res.png";
|
|
|
|
|
|
saveImage(pRes->m_pixResult, goodtargetDir + "\\", filename + "Res.png");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
QString errorSourceDir = fileSavePath + "\\Error";
|
|
|
|
|
|
filename += QString("_%1_%2_").arg((int)pRes->m_dThickness).arg((int)pRes->m_dDiameter);
|
|
|
|
|
|
filename += QDateTime::currentDateTime().toString("hhmmsszzz");
|
|
|
|
|
|
filename = filename + "_" + curExposureTimeStr;
|
|
|
|
|
|
if (lpGlobalConfig::instance()->bSaveSrcNGImg == true) {
|
|
|
|
|
|
errorSourceDir += "\\Source";
|
|
|
|
|
|
QString resultpath = errorSourceDir + "\\" + filename + ".png";
|
|
|
|
|
|
saveImage(pRes->m_pixSrc, errorSourceDir + "\\", filename + ".png");
|
|
|
|
|
|
}
|
|
|
|
|
|
QString errortargetDir = fileSavePath + "\\Error";
|
|
|
|
|
|
if (lpGlobalConfig::instance()->bSaveCutNGImg == true) {
|
|
|
|
|
|
errortargetDir += "\\Target";
|
|
|
|
|
|
QString resultpath = errortargetDir + "\\" + filename + "Res.png";
|
|
|
|
|
|
if (pRes->m_pixResult.isNull())
|
|
|
|
|
|
saveImage(pRes->m_pixSrc, errortargetDir + "\\", filename + "Res.png");
|
|
|
|
|
|
else
|
|
|
|
|
|
saveImage(pRes->m_pixResult, errortargetDir + "\\", filename + "Res.png");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::saveImage(const QPixmap& 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 lpMainWin::onUpdateByLevel(int nlevel)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(nlevel>4)
|
|
|
|
|
|
ui.action_userManager->setVisible(true);
|
|
|
|
|
|
else
|
|
|
|
|
|
ui.action_userManager->setVisible(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::modWorkMgr(QString str)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pWorkUI->modWorkMgr(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool lpMainWin::readExposureTimeConfig(const QString& strPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString filePath = strPath + "\\config\\exposure.json";
|
|
|
|
|
|
QJsonObject jsonObj = QZkJsonParser::ReadJsonAuto(filePath);
|
|
|
|
|
|
if (jsonObj.empty())
|
|
|
|
|
|
{
|
|
|
|
|
|
qDebug() << "Json file parsing failed!";
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject rootObj;
|
|
|
|
|
|
QJsonArray exposttime;
|
|
|
|
|
|
exposttime.append("1000");
|
|
|
|
|
|
rootObj.insert("exposureTime", exposttime);
|
|
|
|
|
|
rootObj.insert("switch", 0);
|
|
|
|
|
|
QZkJsonParser::WriteJsonObject(filePath, rootObj);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject exposureObj = jsonObj.value("exposureTime").toObject();
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject::iterator objIterEnd = exposureObj.end();
|
|
|
|
|
|
for (auto objIter = exposureObj.begin(); objIter != objIterEnd; objIter++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int exposureTime = objIter.value().toInt();
|
|
|
|
|
|
m_exposureTimeArray.emplace_back(exposureTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
m_autoExposureSwitch = jsonObj.value("switch").toInt();
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int lpMainWin::getCurExposureTime()
|
|
|
|
|
|
{
|
|
|
|
|
|
TP_CAMERA_OPTION camOpt;
|
|
|
|
|
|
m_pCoreCtrl->IGetCameraOption(m_camKey, camOpt);
|
|
|
|
|
|
return camOpt.exposure;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onAutoExposure()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_exposureTimeCount >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_exposureTimeArray.size() <= m_exposureTimeCount)
|
|
|
|
|
|
return;
|
|
|
|
|
|
int exp = m_exposureTimeArray[m_exposureTimeCount];
|
|
|
|
|
|
qDebug() << "exp:" << exp;
|
|
|
|
|
|
m_pCoreCtrl->ISetExposureTime(m_camKey, exp);
|
|
|
|
|
|
}
|
|
|
|
|
|
onTriggerCam();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Result2Ui *lpMainWin::parseMap(const QVariantMap &vMap)
|
|
|
|
|
|
{
|
|
|
|
|
|
Result2Ui* pRes = new Result2Ui();
|
|
|
|
|
|
pRes->m_strModel = vMap.value("modeName").toString();
|
|
|
|
|
|
pRes->m_dMinDis = vMap.value("minDis").toDouble();
|
|
|
|
|
|
pRes->m_dScore = vMap.value("score").toDouble();
|
|
|
|
|
|
pRes->m_dDiameter = vMap.value("diameter").toDouble();
|
|
|
|
|
|
pRes->m_dThickness = vMap.value("thickness").toDouble();
|
|
|
|
|
|
|
|
|
|
|
|
pRes->m_pixResult = QPixmap::fromImage(vMap.value("pixResult").value<QImage>());
|
|
|
|
|
|
pRes->m_dRunTime = vMap.value("runTime").toDouble();
|
|
|
|
|
|
return pRes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onSlotAddNewModel(QString strName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_pEngineCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
IDetectorSolutionMgr* pMgr = m_pEngineCtrl->getSolutionMgr();
|
|
|
|
|
|
if (pMgr)
|
|
|
|
|
|
{
|
|
|
|
|
|
IDetectorSolution* pSolution = pMgr->GetRunSolution();
|
|
|
|
|
|
if (pSolution) {
|
|
|
|
|
|
pSolution->AddTaskByTemplate(strName);
|
|
|
|
|
|
pSolution->SaveTaskByName(strName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onSlotDelOldModel(QString strName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_pEngineCtrl) {
|
|
|
|
|
|
IDetectorSolutionMgr* pMgr = m_pEngineCtrl->getSolutionMgr();
|
|
|
|
|
|
if (pMgr) {
|
|
|
|
|
|
IDetectorSolution* pSolution = pMgr->GetRunSolution();
|
|
|
|
|
|
if (pSolution) {
|
|
|
|
|
|
pSolution->DeleteTask(strName);
|
|
|
|
|
|
pSolution->SaveTaskByName("");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
保存定位检测结果数据
|
|
|
|
|
|
(1)把定位检测的对于图片保存起来,供后期核查
|
|
|
|
|
|
(2)将定位的结果保存到数据库中,包括型号名,图片路径,角度、中心坐标等等
|
|
|
|
|
|
*/
|
|
|
|
|
|
void lpMainWin::onSaveValveResult(ValueResult &rlt)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strModeName = rlt.strModel;//型号名
|
|
|
|
|
|
QDir testDir;
|
|
|
|
|
|
bool IsTestDir = testDir.exists(lpGlobalConfig::instance()->m_SaveImgDirPath);
|
|
|
|
|
|
if (!IsTestDir)
|
|
|
|
|
|
lpGlobalConfig::instance()->m_SaveImgDirPath = lpGlobalConfig::instance()->m_applicationDirPath;
|
|
|
|
|
|
|
|
|
|
|
|
QString baseSavePath = lpGlobalConfig::instance()->m_SaveImgDirPath + "\\Data\\";
|
|
|
|
|
|
IsTestDir = testDir.exists(baseSavePath);
|
|
|
|
|
|
if (!IsTestDir)
|
|
|
|
|
|
testDir.mkpath(baseSavePath);
|
|
|
|
|
|
|
|
|
|
|
|
QString dataTime = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
|
|
|
|
|
QString fileSavePath = baseSavePath + "\\" + dataTime;
|
|
|
|
|
|
QString filename = strModeName;
|
|
|
|
|
|
if (filename != "NG")
|
|
|
|
|
|
{
|
|
|
|
|
|
QString goodsourceDir = fileSavePath + "\\Good";
|
|
|
|
|
|
goodsourceDir += "\\ValueImg\\";
|
|
|
|
|
|
goodsourceDir += strModeName;
|
|
|
|
|
|
filename = QString("%1_%2").arg(strModeName).arg(QDateTime::currentDateTime().toString("hh-mm-ss zzz"));
|
|
|
|
|
|
QString resultpath = goodsourceDir + "\\" + filename + ".jpeg";
|
|
|
|
|
|
rlt.strImagePath = resultpath;
|
|
|
|
|
|
if(lpGlobalConfig::instance()->bSaveSrcOKImg_value == true)
|
|
|
|
|
|
saveImage(rlt.pixmap, goodsourceDir + "\\", filename + ".jpeg");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
QString errorSourceDir = fileSavePath + "\\Error";
|
|
|
|
|
|
filename = QString("%1_%2").arg(strModeName).arg(QDateTime::currentDateTime().toString("hh-mm-ss zzz"));
|
|
|
|
|
|
errorSourceDir += "\\ValueImg";
|
|
|
|
|
|
QString resultpath = errorSourceDir + "\\" + filename + ".jepg";
|
|
|
|
|
|
rlt.strImagePath = resultpath;
|
|
|
|
|
|
if(lpGlobalConfig::instance()->bSaveSrcNGImg_value == true)
|
|
|
|
|
|
saveImage(rlt.pixmap, errorSourceDir + "\\", filename + ".jpeg");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*数据保存到数据库中*/
|
|
|
|
|
|
if (m_pCtrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
DataBaseSql *pDB = m_pCtrl->getDB();
|
|
|
|
|
|
if (pDB) {
|
|
|
|
|
|
pDB->InsertValueRlt(rlt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//if (m_pPlcDevice)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// m_pPlcDevice->onSendValueRlt(rlt);
|
|
|
|
|
|
//}
|
|
|
|
|
|
sendWebAlgRlt(rlt);
|
|
|
|
|
|
|
|
|
|
|
|
QString strMsg = QString("%1 识别结果:%2 定位角度:%3").arg(QDateTime::currentDateTime().toString("hh:mm:ss")).arg(rlt.strModel).arg(rlt.angle);
|
|
|
|
|
|
emit sgShowDetectLog(strMsg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::saveValveImage(QImage image, QString strName)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strModeName = strName;//型号名
|
|
|
|
|
|
QPixmap pixmap = QPixmap::fromImage(image);
|
|
|
|
|
|
|
|
|
|
|
|
QDir testDir;
|
|
|
|
|
|
bool IsTestDir = testDir.exists(lpGlobalConfig::instance()->m_SaveImgDirPath);
|
|
|
|
|
|
if (!IsTestDir)
|
|
|
|
|
|
lpGlobalConfig::instance()->m_SaveImgDirPath = lpGlobalConfig::instance()->m_applicationDirPath;
|
|
|
|
|
|
|
|
|
|
|
|
QString baseSavePath = lpGlobalConfig::instance()->m_SaveImgDirPath + "\\Data\\";
|
|
|
|
|
|
IsTestDir = testDir.exists(baseSavePath);
|
|
|
|
|
|
if (!IsTestDir)
|
|
|
|
|
|
testDir.mkpath(baseSavePath);
|
|
|
|
|
|
|
|
|
|
|
|
QString dataTime = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
|
|
|
|
|
QString fileSavePath = baseSavePath + "\\" + dataTime;
|
|
|
|
|
|
QString filename = strModeName;
|
|
|
|
|
|
if (filename != "NG")
|
|
|
|
|
|
{
|
|
|
|
|
|
QString goodsourceDir = fileSavePath + "\\Good";
|
|
|
|
|
|
goodsourceDir += "\\ValueImg\\";
|
|
|
|
|
|
goodsourceDir += strModeName;
|
|
|
|
|
|
filename = QString("%1_%2").arg(strModeName).arg(QDateTime::currentDateTime().toString("hh-mm-ss zzz"));
|
|
|
|
|
|
QString resultpath = goodsourceDir + "\\" + filename + ".jpeg";
|
|
|
|
|
|
saveImage(pixmap, goodsourceDir + "\\", filename + ".jpeg");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
QString errorSourceDir = fileSavePath + "\\Error";
|
|
|
|
|
|
filename = QString("%1_%2").arg(strModeName).arg(QDateTime::currentDateTime().toString("hh-mm-ss zzz"));
|
|
|
|
|
|
errorSourceDir += "\\ValueImg";
|
|
|
|
|
|
QString resultpath = errorSourceDir + "\\" + filename + ".jpeg";
|
|
|
|
|
|
saveImage(pixmap, errorSourceDir + "\\", filename + ".jpeg");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onPLCTrigerCam(int camID)
|
|
|
|
|
|
{
|
|
|
|
|
|
onTriggerCam();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::onTcpHeartBit()
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject heartObj;
|
|
|
|
|
|
heartObj.insert("deviceName", "A");
|
|
|
|
|
|
heartObj.insert("cmd", "heartbit");
|
|
|
|
|
|
heartObj.insert("runState", lpGlobalConfig::instance()->IsDetect);
|
|
|
|
|
|
heartObj.insert("time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss zzz"));
|
|
|
|
|
|
if (tcp_server_ptr_)
|
|
|
|
|
|
{
|
|
|
|
|
|
TP_PROTOCOL_MESSAGE msg;
|
|
|
|
|
|
msg.body = heartObj;
|
|
|
|
|
|
tcp_server_ptr_->ISendMessage("*", msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::sendWebAlgRlt(const ValueResult& rlt)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject sAlgRltObj;
|
|
|
|
|
|
sAlgRltObj.insert("cmd", "algRlt");
|
|
|
|
|
|
sAlgRltObj.insert("modeName", rlt.strModel);
|
|
|
|
|
|
sAlgRltObj.insert("score", rlt.score);
|
|
|
|
|
|
sAlgRltObj.insert("angle", rlt.angle);
|
|
|
|
|
|
sAlgRltObj.insert("center_x", rlt.center.x());
|
|
|
|
|
|
sAlgRltObj.insert("center_y", rlt.center.y());
|
|
|
|
|
|
sAlgRltObj.insert("imagePath", rlt.strImagePath);
|
|
|
|
|
|
sAlgRltObj.insert("resultType", rlt.resultType);
|
|
|
|
|
|
QByteArray imgBuf;
|
|
|
|
|
|
QBuffer buf(&imgBuf);
|
|
|
|
|
|
rlt.pixmap.save(&buf, "jpeg");
|
|
|
|
|
|
QString strBase64 = QString(imgBuf.toBase64());
|
|
|
|
|
|
buf.close();
|
|
|
|
|
|
sAlgRltObj.insert("imageData_base64", strBase64);
|
|
|
|
|
|
|
|
|
|
|
|
if (tcp_server_ptr_)
|
|
|
|
|
|
{
|
|
|
|
|
|
TP_PROTOCOL_MESSAGE msg;
|
|
|
|
|
|
msg.body = sAlgRltObj;
|
|
|
|
|
|
tcp_server_ptr_->ISendMessage("*", msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QJsonObject lpMainWin::byte2Json(QByteArray data)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(data);
|
|
|
|
|
|
return doc.object();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QByteArray lpMainWin::Json2byte(QJsonObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonDocument doc = QJsonDocument(obj);
|
|
|
|
|
|
return doc.toJson();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::setupTrayIcon()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_trayIcon = new QSystemTrayIcon(this);
|
|
|
|
|
|
m_trayIconMenu = new QMenu(this);
|
|
|
|
|
|
m_restoreAction = new QAction(tr("后台运行"), this);
|
|
|
|
|
|
m_quitAction = new QAction(tr("退出"), this);
|
|
|
|
|
|
|
|
|
|
|
|
m_trayIconMenu->addAction(m_restoreAction);
|
|
|
|
|
|
m_trayIconMenu->addSeparator();
|
|
|
|
|
|
m_trayIconMenu->addAction(m_quitAction);
|
|
|
|
|
|
|
|
|
|
|
|
QIcon icon(":/image/leaper");
|
|
|
|
|
|
m_trayIcon->setIcon(icon);
|
|
|
|
|
|
m_trayIcon->setContextMenu(m_trayIconMenu);
|
|
|
|
|
|
|
|
|
|
|
|
connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onActivated(QSystemTrayIcon::ActivationReason)));
|
|
|
|
|
|
connect(m_restoreAction, &QAction::triggered, this, [this]() {
|
|
|
|
|
|
setMainWindowVisibility(isHidden());
|
|
|
|
|
|
});
|
|
|
|
|
|
connect(m_quitAction, &QAction::triggered, this, &lpMainWin::onQuitApplication);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onActivated(QSystemTrayIcon::ActivationReason reason)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (reason == QSystemTrayIcon::DoubleClick)
|
|
|
|
|
|
{
|
|
|
|
|
|
setMainWindowVisibility(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::setMainWindowVisibility(bool state)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (state) {
|
|
|
|
|
|
onShowMainWindow();
|
|
|
|
|
|
m_restoreAction->setText(tr("后台运行"));
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
m_restoreAction->setText(tr("显示界面"));
|
|
|
|
|
|
hide();
|
|
|
|
|
|
/*防止子窗口没有关闭的情况下,主窗口关闭了,再关闭子窗口时整个应用被退出*/
|
|
|
|
|
|
if (m_pAlgParamDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_pAlgParamDlg->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pAlgParamDlg->hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pDebugDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_pDebugDlg->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pDebugDlg->hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pModelMgrDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_pModelMgrDlg->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pModelMgrDlg->hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_CamSettingDlg)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_CamSettingDlg->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_CamSettingDlg->hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pSystemConfigUI)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_pSystemConfigUI->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pSystemConfigUI->hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pWorkUI) {
|
|
|
|
|
|
if (!m_pWorkUI->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pWorkUI->hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!m_aboutDlg.isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_aboutDlg.hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pImageCaliUI)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_pImageCaliUI->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pImageCaliUI->hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pDesigner) {
|
|
|
|
|
|
if (!m_pDesigner->IsMainFrameHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pDesigner->HideMainFrame();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pCheckLineseUI)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_pCheckLineseUI->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pCheckLineseUI->hide();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::onQuitApplication()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_bExit = true;
|
|
|
|
|
|
lpMainWin::close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::setWindowTitleInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
setWindowTitle(lpGlobalConfig::instance()->strSysTitle);
|
|
|
|
|
|
ui.m_winTitle->setText(lpGlobalConfig::instance()->strSysTitle);
|
|
|
|
|
|
if (m_trayIcon)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_trayIcon->setToolTip(lpGlobalConfig::instance()->strSysTitle);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//展示检测日志记录
|
|
|
|
|
|
Q_SLOT void lpMainWin::onShowDetectLog(QString strMsg)
|
|
|
|
|
|
{
|
|
|
|
|
|
int size = ui.main_textBrowser->toPlainText().size();
|
|
|
|
|
|
if (size > 100000)
|
|
|
|
|
|
ui.main_textBrowser->clear();
|
|
|
|
|
|
ui.main_textBrowser->append(strMsg);
|
|
|
|
|
|
}
|
|
|
|
|
|
//根据注册状态启用相关功能
|
|
|
|
|
|
Q_SLOT void lpMainWin::onLineseCheck(bool bFlag)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.action_modelmgr->setDisabled(!bFlag);
|
|
|
|
|
|
ui.action_checkdata->setDisabled(!bFlag);
|
|
|
|
|
|
ui.action_connect_mode->setDisabled(!bFlag);
|
|
|
|
|
|
ui.action_connect_mode->setDisabled(!bFlag);
|
|
|
|
|
|
ui.action_debug->setDisabled(!bFlag);
|
|
|
|
|
|
ui.action_designer->setDisabled(!bFlag);
|
|
|
|
|
|
ui.action_ImageCali->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 lpMainWin::onStrongButton()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_timerID_btn == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_timerID_btn = startTimer(500);
|
|
|
|
|
|
ui.btn_start_detect->setStyleSheet("font: bold 14px;background-color: rgb(210, 255, 44);");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::tcpServerInit()
|
|
|
|
|
|
{
|
|
|
|
|
|
int port = lpGlobalConfig::instance()->tcpServerPort;
|
|
|
|
|
|
TP_TCP_SERVER_PARAM init_param;
|
|
|
|
|
|
init_param.host_ip_ = "*";
|
|
|
|
|
|
init_param.port_ = port;
|
|
|
|
|
|
init_param.enable_ssl_ = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (!tcp_server_ptr_) {
|
|
|
|
|
|
tcp_server_ptr_ = QSharedPointer<lpTcpServer>(new lpTcpServer(init_param, this));
|
|
|
|
|
|
connect(tcp_server_ptr_.data(), &lpTcpServer::signal_client_connected, this, &lpMainWin::on_client_connected);
|
|
|
|
|
|
connect(tcp_server_ptr_.data(), &lpTcpServer::signal_client_disconnected, this, &lpMainWin::on_client_disconnected);
|
|
|
|
|
|
connect(tcp_server_ptr_.data(), &lpTcpServer::signal_message_received, this, &lpMainWin::on_message_received);
|
|
|
|
|
|
connect(tcp_server_ptr_.data(), &lpTcpServer::signal_data_send_completed, this, &lpMainWin::on_data_send_completed);
|
|
|
|
|
|
connect(tcp_server_ptr_.data(), &lpTcpServer::signal_data_recv_completed, this, &lpMainWin::on_data_recv_completed);
|
|
|
|
|
|
tcp_server_ptr_->IStartServer();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::on_client_connected(const QString &client_name)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::on_client_disconnected(const QString &client_name)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::on_message_received(const QString &client_name, QSharedPointer<TP_PROTOCOL_MESSAGE> pmsg)
|
|
|
|
|
|
{
|
|
|
|
|
|
paraJson(pmsg->body);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::on_data_send_completed(QSharedPointer<TP_PROTOCOL_MESSAGE> pmsg)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void lpMainWin::on_data_recv_completed(const QString &client_name,
|
|
|
|
|
|
QSharedPointer<TP_PROTOCOL_MESSAGE> msg_ptr,
|
|
|
|
|
|
QSharedPointer<QByteArray> pData)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::paraJson(const QJsonObject& json)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!json.empty())
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strcmd = json.value("cmd").toString();
|
|
|
|
|
|
if (strcmd == "trigerCam")
|
|
|
|
|
|
{
|
|
|
|
|
|
onTriggerCam();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (strcmd == "heartbit")
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (strcmd == "showWidget")//接收到显示窗口的命令
|
|
|
|
|
|
{
|
|
|
|
|
|
onShowMainWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (strcmd == "hideWidget")
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (strcmd == "exitApp")
|
|
|
|
|
|
{
|
|
|
|
|
|
onQuitApplication();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::onShowMainWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this->isMinimized() == true)//如果窗口是最小化 还原展示
|
|
|
|
|
|
{
|
|
|
|
|
|
Qt::WindowStates winStatus = Qt::WindowNoState;
|
|
|
|
|
|
if (this->windowState() & Qt::WindowMaximized)
|
|
|
|
|
|
{
|
|
|
|
|
|
winStatus = Qt::WindowMaximized;
|
|
|
|
|
|
}
|
|
|
|
|
|
this->setWindowState(Qt::WindowMinimized);
|
|
|
|
|
|
this->setWindowState(Qt::WindowActive | winStatus);
|
|
|
|
|
|
this->activateWindow();
|
|
|
|
|
|
this->showNormal();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (this->isHidden())//如果窗口是隐藏 在后台运行的,展示为活动窗口
|
|
|
|
|
|
{
|
|
|
|
|
|
Qt::WindowStates winStatus = Qt::WindowNoState;
|
|
|
|
|
|
if (this->windowState() & Qt::WindowMaximized)
|
|
|
|
|
|
{
|
|
|
|
|
|
winStatus = Qt::WindowMaximized;
|
|
|
|
|
|
}
|
|
|
|
|
|
this->setWindowState(Qt::WindowMinimized);
|
|
|
|
|
|
this->setWindowState(Qt::WindowActive | winStatus);
|
|
|
|
|
|
this->activateWindow();
|
|
|
|
|
|
this->raise();
|
|
|
|
|
|
this->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
else {//如果窗口已经展示,在其他程序后面,则把窗口重新展示到桌面的最顶层
|
|
|
|
|
|
QRect curGemRect = this->geometry();
|
|
|
|
|
|
|
|
|
|
|
|
//激活mpWindow窗体为桌面的顶层窗体
|
|
|
|
|
|
Qt::WindowStates winStatus = Qt::WindowNoState;
|
|
|
|
|
|
if (this->windowState() & Qt::WindowMaximized)
|
|
|
|
|
|
{
|
|
|
|
|
|
winStatus = Qt::WindowMaximized;
|
|
|
|
|
|
}
|
|
|
|
|
|
this->setWindowState(Qt::WindowMinimized);
|
|
|
|
|
|
this->setWindowState(Qt::WindowActive | winStatus);
|
|
|
|
|
|
this->setGeometry(curGemRect);
|
|
|
|
|
|
this->activateWindow();
|
|
|
|
|
|
this->raise();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void lpMainWin::AckTriggerCam()
|
|
|
|
|
|
{//相机触发应答数据 应答数据发给valueMain应用程序 tcp发送
|
|
|
|
|
|
if (tcp_server_ptr_)
|
|
|
|
|
|
{
|
|
|
|
|
|
QJsonObject ackObj;
|
|
|
|
|
|
ackObj.insert("deviceName", "A");
|
|
|
|
|
|
ackObj.insert("cmd", "triggerAck");
|
|
|
|
|
|
ackObj.insert("runState", lpGlobalConfig::instance()->IsDetect);
|
|
|
|
|
|
ackObj.insert("time", QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss zzz"));
|
|
|
|
|
|
|
|
|
|
|
|
TP_PROTOCOL_MESSAGE msg;
|
|
|
|
|
|
msg.body = ackObj;
|
|
|
|
|
|
tcp_server_ptr_->ISendMessage("*", msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|