1 、增加算法参数调试UI

2、调整与MainUI主从之间的展示逻辑(show状态)
3、通讯更换为libtcp库
master
bob.pan 5 years ago
parent 2b98d59329
commit e4cb943bf5

@ -0,0 +1,85 @@
#ifndef __LIBTCP_H__
#define __LIBTCP_H__
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QTextStream>
#include <QQueue>
#include <QByteArray>
#include <QMap>
#include <QDateTime>
#include <QSharedPointer>
#include <QTcpSocket>
#include <QSslSocket>
#include <QSsl>
#include <QSslCertificate>
#include <QSslKey>
typedef struct tagTP_TCP_CLIENT_PARAM{
QString user_; // 用户名
QString host_ip_; // 服务器地址
quint16 port_{6677}; // 服务器端口
bool enable_ssl_{false}; // 是否启用SSL
bool auto_reconnect_{false}; // 是否自动重连
}TP_TCP_CLIENT_PARAM;
typedef struct tagTP_TCP_SERVER_PARAM{
QString host_ip_; // 监听地址, *为所有可用地址
quint16 port_{6677}; // 监听端口
bool enable_ssl_{false}; // 是否启用SSL
QList<QString> user_list_; // 允许的用户列表。空代表无用户验证
}TP_TCP_SERVER_PARAM;
typedef enum TpServerStatus
{
ON_RUNNING = 0,
ON_SHUTDOWN = 1,
}TpServerStatus;
typedef struct tagTP_CLIENT_STATUS
{
QString client_name_;
QString client_ip_;
QString host_ip_;
QAbstractSocket::SocketState status;
int session_id_;
QDateTime last_active_time_;
}TP_CLIENT_STATUS;
typedef QMap<QString, TP_CLIENT_STATUS> ClientsStatusMap;
typedef enum TpProtoParserStatus
{
ON_PARSER_INIT = 0,
ON_PARSER_HAED = 1,
ON_PARSER_BODY = 2,
}TpProtoParserStatus;
typedef struct tagTP_PROTOCOL_HEAD
{
quint8 version_;
quint8 magic_;
quint16 server_;
quint32 length_;
}TP_PROTOCOL_HEAD;
class TP_PROTOCOL_MESSAGE
{
public:
TP_PROTOCOL_MESSAGE(){}
~TP_PROTOCOL_MESSAGE(){}
public:
TP_PROTOCOL_HEAD head;
QJsonObject body;
};
Q_DECLARE_METATYPE(QSharedPointer<TP_PROTOCOL_MESSAGE>)
#ifndef LPQSHAREDPOINTERQBYTEARRAY
#define LPQSHAREDPOINTERQBYTEARRAY
Q_DECLARE_METATYPE(QSharedPointer<QByteArray>)
#endif
Q_DECLARE_METATYPE(QSharedPointer<QJsonObject>)
#endif //__TP_PROTOCOL_H__

@ -0,0 +1,42 @@
#ifndef LIBTCPCLIENT_H
#define LIBTCPCLIENT_H
#include <QtCore/qglobal.h>
#include "libTcp.h"
#include <QThread>
class TPTcpClient;
class lpTcpClient : public QObject
{
Q_OBJECT
public:
lpTcpClient(const TP_TCP_CLIENT_PARAM& init_param,
QObject *parent = 0);
~lpTcpClient();
void IGetVersion(QString &version);
void IGetClientStatus(TP_CLIENT_STATUS& clistatus);
void ISendMessage(TP_PROTOCOL_MESSAGE& msg);
void ISendBinaryData(TP_PROTOCOL_MESSAGE& msg, QByteArray& binaryData);
void onStartDevice();
void onStopDevice();
signals:
void signal_connected();
void signal_disconnected();
void signal_message_receive(QSharedPointer<TP_PROTOCOL_MESSAGE>);
void signal_data_send_completed(QSharedPointer<TP_PROTOCOL_MESSAGE>);
void signal_data_recv_completed(QSharedPointer<TP_PROTOCOL_MESSAGE>,
QSharedPointer<QByteArray> );
void signal_device_start();
void signal_send_binary_data(QSharedPointer<TP_PROTOCOL_MESSAGE>,QSharedPointer<QByteArray>);
void signal_send_package(QSharedPointer<TP_PROTOCOL_MESSAGE>);
private:
QThread tcp_thread_;
};
#endif // LIBTCPCLIENT_GLOBAL_H

@ -0,0 +1,48 @@
#ifndef LIBTCPSERVER_H
#define LIBTCPSERVER_H
#include <QtCore/qglobal.h>
//#if defined(LIBTCPSERVER_LIBRARY)
//# define LIBTCPSERVERSHARED_EXPORT Q_DECL_EXPORT
//#else
# define LIBTCPSERVERSHARED_EXPORT Q_DECL_IMPORT
//#endif
#include "libTcp.h"
#include <QTcpServer>
class TPTcpServer;
class lpTcpServer : public QObject
{
Q_OBJECT
public:
lpTcpServer(const TP_TCP_SERVER_PARAM& init_param,
QObject *parent = 0);
~lpTcpServer();
ClientsStatusMap IGetClientsStatus();
const TpServerStatus IGetServerStatus() { return server_status_; }
void IGetVersion(QString& version);
bool IStartServer();
void IStopServer();
void ISendMessage(const QString& strClient, TP_PROTOCOL_MESSAGE& msg);
void ISendBinaryData(const QString& strClient, TP_PROTOCOL_MESSAGE& msg, QByteArray& binaryData);
signals:
void signal_client_connected(const QString&);
void signal_client_disconnected(const QString&);
void signal_message_received(const QString&, QSharedPointer<TP_PROTOCOL_MESSAGE>);
void signal_data_send_completed(QSharedPointer<TP_PROTOCOL_MESSAGE>);
void signal_data_recv_completed(const QString& , QSharedPointer<TP_PROTOCOL_MESSAGE>, QSharedPointer<QByteArray> );
void signal_data_recv_completed_client(QSharedPointer<TP_PROTOCOL_MESSAGE>, QSharedPointer<QByteArray>);
private:
QSharedPointer<TPTcpServer> tcp_server_{nullptr};
QHostAddress listen_addr_;
quint16 listen_port_;
TpServerStatus server_status_;
};
#endif // LIBTCPSERVER_H

@ -27,6 +27,9 @@ public:
double m_dMinDis;//匹配特征值
int m_channel;//通道
};
//enum ResultType {
// EM_DETECT
// };
/*定位检测结果*/
struct ValueResult {
QString strModel{ "NG" };//型号名
@ -39,6 +42,7 @@ struct ValueResult {
double runtime{ 0 };//定位算法运行时间
QPixmap pixmap;
QString strRunState;//运行状态 字符串
int resultType{-1};// 0 识别OK定位OK 1 识别OK定位异常 2识别OK定位未标定 3 识别OK,但没有相关task 4识别NG
};
#endif

@ -0,0 +1,132 @@
#include "QAlgParamDlg.h"
#include "qshowimg.h"
#include <QFileDialog>
#include <QMessageBox>
#include "lpGlobalConfig.h"
#pragma execution_character_set("utf-8")
QAlgParamDlg::QAlgParamDlg(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.m_pbShowBackImage, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.m_pbApply, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.m_pbExit, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
ui.label->setVisible(false);
}
QAlgParamDlg::~QAlgParamDlg()
{
}
Q_SLOT void QAlgParamDlg::onButtonClicked()
{
QString strObj = sender()->objectName();
if (strObj == "m_pbShowBackImage")
{
QShowImg m_showImgDlg(this);
m_showImgDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_showImgDlg.setWindowModality(Qt::ApplicationModal);
m_showImgDlg.setAttribute(Qt::WA_ShowModal, true);
m_showImgDlg.setWindowIcon(QIcon(":/image/leaper"));
QString DstPath = ".\\user\\background.png";
connect(&m_showImgDlg, SIGNAL(sgChangeImg()), this, SLOT(onChangeBG()));
connect(this, SIGNAL(sgChangeBG(QString)), &m_showImgDlg, SLOT(setPicPath(QString)));
m_showImgDlg.setPicPath(DstPath);
m_showImgDlg.exec();
}
else if (strObj == "m_pbApply")
{
getParam();
ui.label->setVisible(true);
m_timeID = startTimer(1000);
emit sgParamChange();
}
else if (strObj == "m_pbExit")
{
close();
}
}
void QAlgParamDlg::showEvent(QShowEvent *event)
{
setParam();
}
void QAlgParamDlg::timerEvent(QTimerEvent *event)
{
if (m_timeID == event->timerId())
{
killTimer(m_timeID);
m_timeID = 0;
ui.label->setVisible(false);
}
}
void QAlgParamDlg::setParam()
{
ui.checkBox->setChecked(lpGlobalConfig::instance()->algParam.m_UseBackground == 0 ? false : true);
ui.checkBox_equal->setChecked(lpGlobalConfig::instance()->algParam.m_bUseEqual);
ui.spinBox_filterSize->setValue(lpGlobalConfig::instance()->algParam.m_filterSize);
ui.spinBox_circle_ACThres->setValue(lpGlobalConfig::instance()->algParam.m_Circle_ACThres);
ui.spinBox_circle_EdgeWidth->setValue(lpGlobalConfig::instance()->algParam.m_Circle_EdgeWidth);
ui.comboBox_transform->setCurrentIndex(lpGlobalConfig::instance()->algParam.m_Circle_Polarity);
//ui.checkBox_ratio->setChecked(lpGlobalConfig::instance()->algParam.m_RatioDetectType==0?false:true);
}
void QAlgParamDlg::getParam()
{
lpGlobalConfig::instance()->algParam.m_UseBackground = ui.checkBox->isChecked();
lpGlobalConfig::instance()->algParam.m_bUseEqual = ui.checkBox_equal->isChecked();
lpGlobalConfig::instance()->algParam.m_filterSize = ui.spinBox_filterSize->value();
lpGlobalConfig::instance()->algParam.m_Circle_ACThres = ui.spinBox_circle_ACThres->value();
lpGlobalConfig::instance()->algParam.m_Circle_EdgeWidth = ui.spinBox_circle_EdgeWidth->value();
lpGlobalConfig::instance()->algParam.m_Circle_Polarity = ui.comboBox_transform->currentIndex();
//lpGlobalConfig::instance()->algParam.m_RatioDetectType = ui.checkBox_ratio->isChecked();
lpGlobalConfig::instance()->save();
}
Q_SLOT void QAlgParamDlg::onChangeBG()
{
QFileDialog fileDialog;
fileDialog.setWindowTitle(tr("请选择您的背景图"));
fileDialog.setNameFilter("Picture(*.bmp *.jpg *.png)");
fileDialog.setFileMode(QFileDialog::ExistingFiles);
if (fileDialog.exec() == QDialog::Accepted)
{
QStringList backgroundFile = fileDialog.selectedFiles();
if (backgroundFile.size() > 0)
{
QString DstPath = QApplication::applicationDirPath() + "\\user\\background.png";
QString sourcePath = backgroundFile.at(0);
DstPath.replace("\\", "/");
if (sourcePath == DstPath) {
// //return;
// //return true;
}
if (!QFile::exists(sourcePath)) {
//return false;
}
QDir *createfile = new QDir;
bool exist = createfile->exists(DstPath);
if (exist) {
//if (converFileIfExist){
createfile->remove(DstPath);
//}
}
if (!QFile::copy(sourcePath, DstPath)) {
//return false;
}
//emit sgChangeBG(DstPath);
QMessageBox infobox(QMessageBox::Information, tr("提示"), tr("背景图更新完成,请重启本软件."), QMessageBox::Yes, NULL);
infobox.setWindowIcon(QIcon(":/image/leaper"));
infobox.setButtonText(QMessageBox::Yes, tr("确认"));
infobox.exec();
}
}
}

@ -0,0 +1,28 @@
#ifndef _QALGPARAMDLG_H_
#define _QALGPARAMDLG_H_
#include <QWidget>
#include "ui_QAlgParamDlg.h"
class QAlgParamDlg : public QWidget
{
Q_OBJECT
public:
QAlgParamDlg(QWidget *parent = Q_NULLPTR);
~QAlgParamDlg();
Q_SLOT void onButtonClicked();
signals:
void sgParamChange();
protected:
virtual void showEvent(QShowEvent *event);
virtual void timerEvent(QTimerEvent *event);
void setParam();
void getParam();
Q_SLOT void onChangeBG();
private:
Ui::QAlgParamDlg ui;
int m_timeID{ 0 };
};
#endif

@ -0,0 +1,294 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QAlgParamDlg</class>
<widget class="QWidget" name="QAlgParamDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>331</width>
<height>286</height>
</rect>
</property>
<property name="windowTitle">
<string>算法参数设置</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>圆半径大小过滤:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_filterSize">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_4">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>检测背景图更换:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_pbShowBackImage">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>查看检测背景</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="title">
<string>二级圆定位:</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_circle_ACThres">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>边缘宽度:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBox_circle_EdgeWidth">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBox_transform">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<item>
<property name="text">
<string>从深到浅</string>
</property>
</item>
<item>
<property name="text">
<string>从浅到深</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>边缘对比度:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_6">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>边缘转换:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBox_equal">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>是否使用图像增强</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>是否使用背景图找圆算法</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>参数已生效!!!</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="m_pbApply">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>应用</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_pbExit">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>退出</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

@ -614,6 +614,7 @@ void lpMainWin::IVariantMapToUI(const QString& camKey, const QVariantMap& vMap)
if(!srcImg.isNull())
valueRlt.pixmap = QPixmap::fromImage(srcImg);
valueRlt.strRunState = "no task";
valueRlt.resultType = 4;//识别出型号 但未标定
onSaveValveResult(valueRlt);
}
emit(sgShowImgState(tr("显示识别结果")));
@ -687,6 +688,7 @@ void lpMainWin::IEngineResult(QVariantMap vMap)
valueRlt.score = 0;
valueRlt.strRunState = "no Cali";
valueRlt.pixmap = QPixmap::fromImage(srcImg);
valueRlt.resultType = 2;//识别出型号 但未标定
onSaveValveResult(valueRlt);
return;
}
@ -707,6 +709,7 @@ void lpMainWin::IEngineResult(QVariantMap vMap)
valueRlt.score = 0;
valueRlt.strRunState = "no task";
valueRlt.pixmap = QPixmap::fromImage(srcImg);
valueRlt.resultType = 3;//识别出型号 但未标定
onSaveValveResult(valueRlt);
}
else {
@ -745,12 +748,14 @@ void lpMainWin::IEngineResult(QVariantMap vMap)
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);
/*展示结果*/
@ -773,6 +778,8 @@ void lpMainWin::showWidget()
else {
setMainWindowVisibility(false);
}
if(m_trayIcon)
m_trayIcon->show();
}
Q_SLOT void lpMainWin::onLogInOut(QString strName, int level, int state)
@ -1691,6 +1698,7 @@ Q_SLOT void lpMainWin::onWebSocketRecvData(QWebSocket* p, QByteArray data)
}
else if (strcmd == "showWidget")
{
this->setWindowFlags(Qt::WindowStaysOnTopHint);
this->show();
}
else if (strcmd == "hideWidget")
@ -1728,7 +1736,7 @@ void lpMainWin::sendWebAlgRlt(const ValueResult& rlt)
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");
@ -1770,13 +1778,13 @@ void lpMainWin::setupTrayIcon()
QIcon icon(":/image/leaper");
m_trayIcon->setIcon(icon);
m_trayIcon->setContextMenu(m_trayIconMenu);
m_trayIcon->show();
//m_trayIcon->show();
connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onActivated(QSystemTrayIcon::ActivationReason)));
connect(m_restoreAction, &QAction::triggered, this, [this]() {
setMainWindowVisibility(isHidden()
|| windowState() == Qt::WindowMinimized
|| (qApp->applicationState() == Qt::ApplicationInactive));
setMainWindowVisibility(isHidden());
// || windowState() == Qt::WindowMinimized
// || (qApp->applicationState() == Qt::ApplicationInactive));
});
connect(m_quitAction, &QAction::triggered, this, &lpMainWin::onQuitApplication);
}
@ -1792,11 +1800,10 @@ Q_SLOT void lpMainWin::onActivated(QSystemTrayIcon::ActivationReason reason)
void lpMainWin::setMainWindowVisibility(bool state)
{
if (state) {
show();
//showMaximized();
qApp->processEvents();
qApp->setActiveWindow(this);
qApp->processEvents();
onShowMainWindow();
// qApp->processEvents();
// qApp->setActiveWindow(this);
// qApp->processEvents();
m_restoreAction->setText(tr("后台运行"));
}
else {
@ -1923,7 +1930,7 @@ void lpMainWin::paraJson(const QJsonObject& json)
}
else if (strcmd == "showWidget")
{
this->show();
onShowMainWindow();
}
else if (strcmd == "hideWidget")
{
@ -1934,4 +1941,48 @@ void lpMainWin::paraJson(const QJsonObject& json)
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();
}
}

@ -117,7 +117,7 @@ protected:
Q_SLOT void onPLCTrigerCam(int camID);
Q_SLOT void onWebSocketRecvData(QWebSocket* p, QByteArray data);
void onWebHeartBit();//websocket 通讯心跳
void onTcpHeartBit();//websocket 通讯心跳
void sendWebAlgRlt(const ValueResult& rlt);
QJsonObject byte2Json(QByteArray data);
QByteArray Json2byte(QJsonObject obj);
@ -146,6 +146,7 @@ private:
Q_SLOT void on_data_send_completed(QSharedPointer<TP_PROTOCOL_MESSAGE> pmsg);
Q_SLOT void on_data_recv_completed(const QString &client_name, QSharedPointer<TP_PROTOCOL_MESSAGE> msg_ptr, QSharedPointer<QByteArray> pData);
void paraJson(const QJsonObject& obj);
void onShowMainWindow();
protected:
virtual void timerEvent(QTimerEvent *event);
virtual void closeEvent(QCloseEvent *event);

@ -4,7 +4,10 @@ lpDebugUI::lpDebugUI(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.m_pbTrigerA, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.m_pbTrigerB, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.m_pbTimerA, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.m_pbTimerB, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
setWindowIcon(QIcon(":/Resources/icon.png"));
}
@ -15,7 +18,19 @@ lpDebugUI::~lpDebugUI()
Q_SLOT void lpDebugUI::onButtonClicked()
{
QString strObj = sender()->objectName();
if (strObj == "pushButton") {
if (strObj == "m_pbTrigerA") {
emit sgButtonClicked(1);
}
else if (strObj == "m_pbTrigerB")
{
emit sgButtonClicked(2);
}
else if (strObj == "m_pbTimerA")
{
emit sgButtonClicked(3);
}
else if (strObj == "m_pbTimerB")
{
emit sgButtonClicked(4);
}
}

@ -6,31 +6,87 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>257</width>
<height>134</height>
</rect>
</property>
<property name="windowTitle">
<string>lpDebugUI</string>
</property>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>90</x>
<y>40</y>
<width>101</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>定时触发</string>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QPushButton" name="m_pbTrigerA">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>A侧触发一次</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="m_pbTrigerB">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>B侧触发一次</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="m_pbTimerA">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>A侧定时触发</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="m_pbTimerB">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>B侧定时触发</string>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>

@ -143,6 +143,7 @@ Q_SLOT void valueMainUI::onRecvDataStr_A(const QJsonObject& json)
double angle = json.value("angle").toDouble();
double cnt_x = json.value("center_x").toDouble();
double cnt_y = json.value("center_y").toDouble();
int resultType = json.value("resultType").toInt(-1);
QString strPath = json.value("imagePath").toString();
QString strBase64 = json.value("imageData_base64").toString();
QByteArray imgbase64 = strBase64.toUtf8();
@ -155,6 +156,43 @@ Q_SLOT void valueMainUI::onRecvDataStr_A(const QJsonObject& json)
.arg(QDateTime::currentDateTime().toString("hh:mm:ss"))
.arg(strName).arg(score).arg(angle).arg(cnt_x).arg(cnt_y);
ui.textEdit->append(sMsg);
switch (resultType)
{
case 0://识别OK定位OK
{
ui.label_A->setText(tr("型号 %1,定位角度 %2°").arg(strName).arg(angle));
ui.label_A->setStyleSheet("font: bold 14px;background-color: rgb(0, 170, 0);");
}
break;
case 1://识别OK定位异常
{
ui.label_A->setText(tr("型号 %1,定位异常").arg(strName));
ui.label_A->setStyleSheet("font: bold 14px;background-color: rgb(255, 0, 0);");
}
break;
case 2://识别OK定位未标定
{
ui.label_A->setText(tr("型号 %1,定位模板未标定").arg(strName));
ui.label_A->setStyleSheet("font: bold 14px;background-color: rgb(255, 170, 0);");
}
break;
case 3://识别OK,但没有相关task
{
ui.label_A->setText(tr("型号 %1,没有相关定位模板").arg(strName));
ui.label_A->setStyleSheet("font: bold 14px;background-color: rgb(255, 0, 0);");
}
break;
case 4:
{
ui.label_A->setText(tr("型号识别失败"));
ui.label_A->setStyleSheet("font: bold 14px;background-color: rgb(255, 0, 0);");
}
break;
default:
break;
}
}
else if (strcmd == "heartbit")
{
@ -176,6 +214,7 @@ Q_SLOT void valueMainUI::onRecvDataStr_B(const QJsonObject& json)
double angle = json.value("angle").toDouble();
double cnt_x = json.value("center_x").toDouble();
double cnt_y = json.value("center_y").toDouble();
int resultType = json.value("resultType").toInt(-1);
QString strPath = json.value("imagePath").toString();
QString strBase64 = json.value("imageData_base64").toString();
QByteArray imgbase64 = strBase64.toUtf8();
@ -188,6 +227,43 @@ Q_SLOT void valueMainUI::onRecvDataStr_B(const QJsonObject& json)
.arg(QDateTime::currentDateTime().toString("hh:mm:ss"))
.arg(strName).arg(score).arg(angle).arg(cnt_x).arg(cnt_y);
ui.textEdit_2->append(sMsg);
switch (resultType)
{
case 0://识别OK定位OK
{
ui.label_B->setText(tr("型号 %1,定位角度 %2°").arg(strName).arg(angle));
ui.label_B->setStyleSheet("font: bold 14px;background-color: rgb(0, 170, 0);");
}
break;
case 1://识别OK定位异常
{
ui.label_B->setText(tr("型号 %1,定位异常").arg(strName));
ui.label_B->setStyleSheet("font: bold 14px;background-color: rgb(255, 0, 0);");
}
break;
case 2://识别OK定位未标定
{
ui.label_B->setText(tr("型号 %1,定位模板未标定").arg(strName));
ui.label_B->setStyleSheet("font: bold 14px;background-color: rgb(255, 170, 0);");
}
break;
case 3://识别OK,但没有相关task
{
ui.label_B->setText(tr("型号 %1,没有相关定位模板").arg(strName));
ui.label_B->setStyleSheet("font: bold 14px;background-color: rgb(255, 0, 0);");
}
break;
case 4:
{
ui.label_B->setText(tr("型号识别失败"));
ui.label_B->setStyleSheet("font: bold 14px;background-color: rgb(255, 0, 0);");
}
break;
default:
break;
}
}
else if (strcmd == "heartbit")
{
@ -256,6 +332,17 @@ Q_SLOT void valueMainUI::onButtonClicked()
QString strObj = sender()->objectName();
if (strObj == "actionsettingA")
{
if (m_bServerA == false)
{
QMessageBox info(this);
info.setWindowIcon(QIcon(WINDOWICON));
info.setWindowTitle(QObject::tr("警告"));
info.setText(QObject::tr("A侧检测程序未连接,请检查配置或通讯"));
info.setStandardButtons(QMessageBox::Ok);
info.setButtonText(QMessageBox::Ok, QObject::tr("关闭"));
info.exec();
return;
}
if (tcp_client_ptr_A)
{
TP_PROTOCOL_MESSAGE msg;
@ -267,6 +354,17 @@ Q_SLOT void valueMainUI::onButtonClicked()
}
else if (strObj == "actionsettingB")
{
if (m_bServerB == false)
{
QMessageBox info(this);
info.setWindowIcon(QIcon(WINDOWICON));
info.setWindowTitle(QObject::tr("警告"));
info.setText(QObject::tr("B侧检测程序未连接,请检查配置或通讯"));
info.setStandardButtons(QMessageBox::Ok);
info.setButtonText(QMessageBox::Ok, QObject::tr("关闭"));
info.exec();
return;
}
if (tcp_client_ptr_B)
{
TP_PROTOCOL_MESSAGE msg;
@ -281,7 +379,7 @@ Q_SLOT void valueMainUI::onButtonClicked()
m_pDebugUI->setParent(this);
m_pDebugUI->setWindowTitle(tr("调试页面"));
m_pDebugUI->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_pDebugUI->setWindowIcon(QIcon(":/image/leaper"));
m_pDebugUI->setWindowIcon(QIcon(WINDOWICON));
m_pDebugUI->setWindowModality(Qt::ApplicationModal);
m_pDebugUI->setAttribute(Qt::WA_ShowModal, true);
m_pDebugUI->show();
@ -292,7 +390,7 @@ Q_SLOT void valueMainUI::onButtonClicked()
m_pConfigUI->setParent(this);
m_pConfigUI->setWindowTitle(tr("系统参数配置页面"));
m_pConfigUI->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_pConfigUI->setWindowIcon(QIcon(":/image/leaper"));
m_pConfigUI->setWindowIcon(QIcon(WINDOWICON));
m_pConfigUI->setWindowModality(Qt::ApplicationModal);
m_pConfigUI->setAttribute(Qt::WA_ShowModal, true);
m_pConfigUI->show();
@ -314,14 +412,23 @@ QByteArray valueMainUI::Json2byte(QJsonObject obj)
void valueMainUI::timerEvent(QTimerEvent *event)
{
if (m_timer == event->timerId())
if (m_timerA == event->timerId())
{
TP_PROTOCOL_MESSAGE msg;
QJsonObject sObj;
sObj.insert("cmd", "trigerCam");
msg.body = sObj;
tcp_client_ptr_A->ISendMessage(msg);
tcp_client_ptr_B->ISendMessage(msg);
if(tcp_client_ptr_A)
tcp_client_ptr_A->ISendMessage(msg);
}
else if (m_timerB == event->timerId())
{
TP_PROTOCOL_MESSAGE msg;
QJsonObject sObj;
sObj.insert("cmd", "trigerCam");
msg.body = sObj;
if (tcp_client_ptr_B)
tcp_client_ptr_B->ISendMessage(msg);
}
else if (m_SysTimerID == event->timerId())
{
@ -418,13 +525,42 @@ Q_SLOT void valueMainUI::onDebugClicked(int nID)
{
if (nID == 1)
{
if (m_timer != 0)
TP_PROTOCOL_MESSAGE msg;
QJsonObject sObj;
sObj.insert("cmd", "trigerCam");
msg.body = sObj;
if (tcp_client_ptr_A)
tcp_client_ptr_A->ISendMessage(msg);
}
else if (nID == 2)
{
TP_PROTOCOL_MESSAGE msg;
QJsonObject sObj;
sObj.insert("cmd", "trigerCam");
msg.body = sObj;
if (tcp_client_ptr_B)
tcp_client_ptr_B->ISendMessage(msg);
}
else if (nID == 3)
{
if (m_timerA != 0)
{
killTimer(m_timer);
m_timer = 0;
killTimer(m_timerA);
m_timerA = 0;
}
else {
m_timer = startTimer(5000);
m_timerA = startTimer(5000);
}
}
else if (nID == 4)
{
if (m_timerB != 0)
{
killTimer(m_timerB);
m_timerB = 0;
}
else {
m_timerB = startTimer(5000);
}
}
}
@ -537,9 +673,7 @@ void valueMainUI::setupTrayIcon()
connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onActivated(QSystemTrayIcon::ActivationReason)));
connect(m_restoreAction, &QAction::triggered, this, [this]() {
setMainWindowVisibility(isHidden()
|| windowState() == Qt::WindowMinimized
|| (qApp->applicationState() == Qt::ApplicationInactive));
setMainWindowVisibility(isHidden());
});
connect(m_quitAction, &QAction::triggered, this, &valueMainUI::onQuitApplication);
}
@ -555,10 +689,7 @@ Q_SLOT void valueMainUI::onActivated(QSystemTrayIcon::ActivationReason reason)
void valueMainUI::setMainWindowVisibility(bool state)
{
if (state) {
show();
qApp->processEvents();
qApp->setActiveWindow(this);
qApp->processEvents();
onShowMainWindow();
m_restoreAction->setText(tr("后台运行"));
}
else {
@ -593,9 +724,11 @@ Q_SLOT void valueMainUI::onShowUI(bool bDouble)
if (bDouble == true)
{
ui.groupBox_2->setVisible(true);
ui.actionsettingB->setVisible(true);
}
else {
ui.groupBox_2->setVisible(false);
ui.actionsettingB->setVisible(false);
}
}
@ -655,4 +788,38 @@ Q_SLOT void valueMainUI::on_disconnected_B()
onConnected_B(false);
}
void valueMainUI::onShowMainWindow()
{
if (this->isMinimized() == true)
{
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();
}
}

@ -57,6 +57,7 @@ private://trayIcon
Q_SLOT void on_data_recv_completed_B(QSharedPointer<TP_PROTOCOL_MESSAGE> msg_ptr, QSharedPointer<QByteArray> pData);
Q_SLOT void on_connected_B();
Q_SLOT void on_disconnected_B();
void onShowMainWindow();
protected:
virtual void timerEvent(QTimerEvent *event);
virtual void closeEvent(QCloseEvent *event);
@ -70,7 +71,8 @@ private:
QLabel* m_pLabelB{ nullptr };
QLabel* m_pLabelSystem{ nullptr };
private:
int m_timer{ 0 };
int m_timerA{ 0 };
int m_timerB{ 0 };
int m_timerStartID{ 0 };
lpConfigUI *m_pConfigUI{ nullptr };

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>918</width>
<height>617</height>
<width>1043</width>
<height>682</height>
</rect>
</property>
<property name="windowTitle">
@ -15,8 +15,8 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<item row="0" column="1">
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>5</horstretch>
@ -29,27 +29,69 @@
</font>
</property>
<property name="title">
<string>A侧检测工位</string>
<string>B侧检测工位</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<widget class="QSplitter" name="splitter_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QWidget" name="widget_A" native="true">
<widget class="QFrame" name="frame_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>8</verstretch>
<verstretch>7</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QWidget" name="widget_B" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_B">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>检测结果</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QTextEdit" name="textEdit">
<widget class="QTextEdit" name="textEdit_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
@ -58,8 +100,8 @@
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QGroupBox" name="groupBox_2">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>5</horstretch>
@ -72,27 +114,69 @@
</font>
</property>
<property name="title">
<string>B侧检测工位</string>
<string>A侧检测工位</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QSplitter" name="splitter_2">
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<widget class="QWidget" name="widget_B" native="true">
<widget class="QFrame" name="frame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>8</verstretch>
<verstretch>7</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QWidget" name="widget_A" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_A">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
<property name="text">
<string>检测结果</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QTextEdit" name="textEdit_2">
<widget class="QTextEdit" name="textEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
@ -171,6 +255,10 @@
</property>
</action>
<action name="actiondebug">
<property name="icon">
<iconset resource="valueMainUI.qrc">
<normaloff>:/Resources/Setting.png</normaloff>:/Resources/Setting.png</iconset>
</property>
<property name="text">
<string>调试</string>
</property>

Loading…
Cancel
Save