diff --git a/release/气门芯定位检测更新内容.txt b/release/气门芯定位检测更新内容.txt index 207da2b..e0a7dc8 100644 --- a/release/气门芯定位检测更新内容.txt +++ b/release/气门芯定位检测更新内容.txt @@ -8,4 +8,7 @@ 2021-10-18 2 1、恢复检测数据结果保存和检测图片保存功能 2、移除不需要的代码和接口 -3、UI布局调整 \ No newline at end of file +3、UI布局调整 + +2021-10-18 3 +1、修复串口不能正常打开问题 \ No newline at end of file diff --git a/runner17/Report.exe b/runner17/Report.exe index a0bc3ff..756a089 100644 Binary files a/runner17/Report.exe and b/runner17/Report.exe differ diff --git a/runner17/lpMain.dll b/runner17/lpMain.dll index e97e0dd..0d20963 100644 Binary files a/runner17/lpMain.dll and b/runner17/lpMain.dll differ diff --git a/runner17/lpMaind.dll b/runner17/lpMaind.dll index 6053877..9b39163 100644 Binary files a/runner17/lpMaind.dll and b/runner17/lpMaind.dll differ diff --git a/src/lpMain/IWfCtrl.h b/src/lpMain/IWfCtrl.h index b4314bf..1a1db79 100644 --- a/src/lpMain/IWfCtrl.h +++ b/src/lpMain/IWfCtrl.h @@ -19,6 +19,7 @@ public: virtual bool ISelModel(QString, QString) = 0; virtual bool ISaveModel(QString, QString) = 0; virtual bool IStandard(QString strName ,QString strModel) = 0; + virtual QImage IGetStandardImg(QString strName, QString strModel) = 0; virtual int IGetPLCIndex(QString strName, QString strModel) = 0; virtual bool ISetPLCIndex(QString strName, QString strModel, int plcIndex) = 0; virtual QString IFindModelName(QString strName, int plcIndex) = 0; diff --git a/src/lpMain/Resource/no-img.png b/src/lpMain/Resource/no-img.png new file mode 100644 index 0000000..9d06a0d Binary files /dev/null and b/src/lpMain/Resource/no-img.png differ diff --git a/src/lpMain/Station.cpp b/src/lpMain/Station.cpp index 79f7e62..c5ff541 100644 --- a/src/lpMain/Station.cpp +++ b/src/lpMain/Station.cpp @@ -144,7 +144,7 @@ bool Station::updateCurrentModel2Label() bool bCali = false; bCali = IStandard(m_strCurrentModel); - QString strText = "

%2: %3 __ %4< /span>< /h4>< /body>< /html>"; + QString strText = "

%2: %3_%4< /span>< /h4>< /body>< /html>"; strText = strText.arg("color:#ff0000;") .arg(tr("当前检测型号")) .arg(m_strCurrentModel == "" ? "?" : m_strCurrentModel) diff --git a/src/lpMain/WfCtrl.cpp b/src/lpMain/WfCtrl.cpp index 0f8d048..bbe5eb4 100644 --- a/src/lpMain/WfCtrl.cpp +++ b/src/lpMain/WfCtrl.cpp @@ -14,6 +14,39 @@ #pragma execution_character_set("utf-8") +static QImage cvMat2QImage_2(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(); + } +} + CWfCtrl::CWfCtrl(IDetectorEngine* ptr) { m_rootPath = QApplication::applicationDirPath(); @@ -304,3 +337,28 @@ bool CWfCtrl::IStandard(QString strName, QString strModel) } return false; } + +QImage CWfCtrl::IGetStandardImg(QString strName, QString strModel) +{ + if (m_pEngine) + { + IDetectorSolutionMgr* pSolutionMgr = m_pEngine->getSolutionMgr(); + if (!pSolutionMgr) + return QImage(); + + QMap solutionMap = pSolutionMgr->GetAllSolutions(); + QMap::iterator it = solutionMap.find(strName); + if (it != solutionMap.end()) + { + IDetectorSolution *p = *it; + IDetectorTask* pTask = p->GetTaskByName(strModel); + if (pTask->GetTaskInfo()->templateImg.data == nullptr) + return QImage(); + else + { + return cvMat2QImage_2(pTask->GetTaskInfo()->templateImg); + } + } + } + return QImage(); +} diff --git a/src/lpMain/WfCtrl.h b/src/lpMain/WfCtrl.h index 32714c4..c41e13b 100644 --- a/src/lpMain/WfCtrl.h +++ b/src/lpMain/WfCtrl.h @@ -6,7 +6,7 @@ #include #include "IWfCtrl.h" #include "lpbengine.h" - +#include class CWfCtrl : public IWfCtrl { Q_OBJECT @@ -18,6 +18,7 @@ public: virtual IStation* IGetStationByKey(QString); virtual bool IStandard(QString strName,QString strModel); + virtual QImage IGetStandardImg(QString strName, QString strModel); virtual int IGetPLCIndex(QString strName, QString strModel); virtual bool ISetPLCIndex(QString strName, QString strModel, int plcIndex); virtual QString IFindModelName(QString strName, int plcIndex); diff --git a/src/lpMain/lpMain.qrc b/src/lpMain/lpMain.qrc index a317cf5..78c45a9 100644 --- a/src/lpMain/lpMain.qrc +++ b/src/lpMain/lpMain.qrc @@ -22,4 +22,7 @@ Resource/app.png Resource/app2.png + + Resource/no-img.png + diff --git a/tpvs17/Report/Report.cpp b/tpvs17/Report/Report.cpp deleted file mode 100644 index 92cdc86..0000000 --- a/tpvs17/Report/Report.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "Report.h" - -Report::Report(QWidget *parent) - : QMainWindow(parent) -{ - ui.setupUi(this); -} diff --git a/tpvs17/Report/Report.h b/tpvs17/Report/Report.h deleted file mode 100644 index b0162fa..0000000 --- a/tpvs17/Report/Report.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include -#include "ui_Report.h" - -class Report : public QMainWindow -{ - Q_OBJECT - -public: - Report(QWidget *parent = Q_NULLPTR); - -private: - Ui::ReportClass ui; -}; diff --git a/tpvs17/Report/Report.ui b/tpvs17/Report/Report.ui deleted file mode 100644 index 8c7908b..0000000 --- a/tpvs17/Report/Report.ui +++ /dev/null @@ -1,29 +0,0 @@ - - ReportClass - - - ReportClass - - - - 0 - 0 - 600 - 400 - - - - Report - - - - - - - - - - - - - diff --git a/tpvs17/Report/Report.vcxproj b/tpvs17/Report/Report.vcxproj index 5f39c45..cc384b5 100644 --- a/tpvs17/Report/Report.vcxproj +++ b/tpvs17/Report/Report.vcxproj @@ -122,14 +122,9 @@ - - - - - diff --git a/tpvs17/Report/Report.vcxproj.filters b/tpvs17/Report/Report.vcxproj.filters index 28ccb2c..2474d7f 100644 --- a/tpvs17/Report/Report.vcxproj.filters +++ b/tpvs17/Report/Report.vcxproj.filters @@ -36,9 +36,6 @@ Source Files - - Source Files - db @@ -62,9 +59,6 @@ - - Header Files - db @@ -79,9 +73,6 @@ - - Form Files - Form Files diff --git a/tpvs17/Report/main.cpp b/tpvs17/Report/main.cpp index 1eb8ac2..033955d 100644 --- a/tpvs17/Report/main.cpp +++ b/tpvs17/Report/main.cpp @@ -1,4 +1,3 @@ -#include "Report.h" #include #include "stationdb.h" #include "qcheckdatadlg.h" diff --git a/tpvs17/Report/qcheckdatadlg.cpp b/tpvs17/Report/qcheckdatadlg.cpp index 7ba34b9..70ffae8 100644 --- a/tpvs17/Report/qcheckdatadlg.cpp +++ b/tpvs17/Report/qcheckdatadlg.cpp @@ -329,8 +329,6 @@ Q_SLOT void QCheckDataDlg::onTBUI_ItemClick(const QModelIndex & index) } } } - - int i = 0; } Q_SLOT void QCheckDataDlg::onSlowPixmap(QSqlQuery sql) diff --git a/tpvs17/Report/qcheckdatadlg.ui b/tpvs17/Report/qcheckdatadlg.ui index 35b6ac5..dbb721b 100644 --- a/tpvs17/Report/qcheckdatadlg.ui +++ b/tpvs17/Report/qcheckdatadlg.ui @@ -6,8 +6,8 @@ 0 0 - 902 - 598 + 978 + 633 @@ -81,6 +81,11 @@ + + + 12 + + 查询操作 @@ -192,6 +197,11 @@ 8 + + + 12 + + @@ -276,7 +286,13 @@ - + + + + 12 + + + @@ -304,6 +320,11 @@ 0 + + + 12 + + QFrame::StyledPanel diff --git a/tpvs17/lpMain/CMainWin.cpp b/tpvs17/lpMain/CMainWin.cpp index c837966..7072664 100644 --- a/tpvs17/lpMain/CMainWin.cpp +++ b/tpvs17/lpMain/CMainWin.cpp @@ -82,7 +82,11 @@ CMainWin::CMainWin(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); - + lpSysLog::instance()->Init(); + lpSysConfig::instance()->readConfig(); + lpSysConfig::instance()->writeConfig(); + lpGlobalConfig::instance()->readConfig(); + setWindowIcon(QIcon(LEAPER_LOGO)); onInitCoreCtrl(); onInitSerial(); @@ -90,10 +94,7 @@ CMainWin::CMainWin(QWidget *parent) onInitUI(); onInitStatus(); onInitDiskClean(); - lpSysLog::instance()->Init(); - lpSysConfig::instance()->readConfig(); - lpSysConfig::instance()->writeConfig(); - lpGlobalConfig::instance()->readConfig(); + SYSLOG_STATUS << "系统启动"; { QString strPath = QCoreApplication::applicationDirPath(); @@ -1071,10 +1072,6 @@ void CMainWin::saveSolution() } -Q_SLOT void CMainWin::onMainFrameClose() -{ - -} //相机触发 Q_SLOT void CMainWin::onSnapImage(int nCamera /*= -1*/) { @@ -1096,11 +1093,6 @@ Q_SLOT void CMainWin::onTrigImage() onSnapImage(2); } -Q_SLOT void CMainWin::onSelModel(int nId, QString strModel) -{ - -} - Q_SLOT void CMainWin::onChangeUI(QString strUsr, int nLevel) { switch (nLevel) { @@ -1303,6 +1295,7 @@ void CMainWin::IEngineResult(QVariantMap vMap) bool taskCali = vMap.value("taskCali").toBool();//标定标志位 使用有标定图来判断 QString solutionName = vMap.value("solutionName").toString(); QString taskName = vMap.value("taskName").toString(); + double taskTime = vMap.value("tasktime").toDouble(); if (taskCali == false)//模板未标定 { int stationID = 0; @@ -1318,6 +1311,11 @@ void CMainWin::IEngineResult(QVariantMap vMap) strResult += " No Cali!!!"; emit sgShowLog(stationID, strResult); sendResult(stationID, 361, 0, 0); + //只保存原图 + if ((lpSysConfig::instance()->m_bSaveSrcImg_st1 == true && stationID == 1) + || (lpSysConfig::instance()->m_bSaveSrcImg_st2 == true && stationID == 2)) + genSaveSrcImgPath(taskName, srcImg); + return; } //不包含算法检测结果,表示没有相关task @@ -1338,6 +1336,10 @@ void CMainWin::IEngineResult(QVariantMap vMap) strResult += " No Task!!!"; emit sgShowLog(stationID, strResult); sendResult(stationID, 361, 0, 0); + + if ((lpSysConfig::instance()->m_bSaveSrcImg_st1 == true && stationID == 1) + || (lpSysConfig::instance()->m_bSaveSrcImg_st2 == true && stationID == 2)) + genSaveSrcImgPath(taskName, srcImg); } else { QVariantMap algResult = vMap.value("AlgoResult").toMap(); @@ -1348,8 +1350,6 @@ void CMainWin::IEngineResult(QVariantMap vMap) QImage rltImg = algResult.value("image").value(); QString strResultTip = algResult.value("resultTip").toString(); QPointF centerPoint = algResult.value("centerPoint").toPointF(); - QString taskName = vMap.value("taskName").toString(); - double taskTime = vMap.value("tasktime").toDouble(); double centerX = 0.0; double centerY = 0.0; @@ -1392,8 +1392,6 @@ void CMainWin::IEngineResult(QVariantMap vMap) nStructData.value1 = strImgPath; nStructData.value2 = str2; m_db->addData2DB(nStructData); -// onSaveValveResult(valueRlt); - /*展示结果*/ onShowImage(stationID, rltImg); diff --git a/tpvs17/lpMain/CMainWin.h b/tpvs17/lpMain/CMainWin.h index ed3ea80..2e82f1a 100644 --- a/tpvs17/lpMain/CMainWin.h +++ b/tpvs17/lpMain/CMainWin.h @@ -95,11 +95,9 @@ private:// private: void saveSolution(); int lastNum(QString str); - Q_SLOT void onMainFrameClose(); Q_SLOT void onSnapImage(int nCamera = -1); Q_SLOT void onTrigImage(); - Q_SLOT void onSelModel(int, QString); Q_SLOT void onChangeUI(QString strUsr, int nLevel); Q_SLOT void onLogInOut(QString strName, int level, int state); Q_SLOT void onTestMode(int); diff --git a/tpvs17/lpMain/QModelMangerUI.cpp b/tpvs17/lpMain/QModelMangerUI.cpp index a29d604..9a20257 100644 --- a/tpvs17/lpMain/QModelMangerUI.cpp +++ b/tpvs17/lpMain/QModelMangerUI.cpp @@ -14,6 +14,14 @@ QModelMangerUI::QModelMangerUI(QWidget *parent) : QWidget(parent) { ui.setupUi(this); + + m_srcImgView = replaceWidget(ui.widget); + //connect(m_srcImgView, SIGNAL(filterroiChanged(const AwesomeRoiInfo&, QString)), this, SLOT(onROIChange(const AwesomeRoiInfo&, QString))); + //connect(m_srcImgView, SIGNAL(pixelClicked(QPoint)), this, SLOT(onPixelClicked(QPoint))); + //connect(m_srcImgView, SIGNAL(roiLockIng(QString)), this, SLOT(onRoiLockIng(QString))); + //connect(m_srcImgView, SIGNAL(sgImageScale(qreal)), this, SLOT(onImageScale(qreal))); + + ui.wf_model_mod_button->setVisible(false); connect(ui.wf_model_select_button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); connect(ui.wf_model_add_button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); @@ -24,6 +32,27 @@ QModelMangerUI::QModelMangerUI(QWidget *parent) QModelMangerUI::~QModelMangerUI() { + if (m_srcImgView) { + delete m_srcImgView; + m_srcImgView = nullptr; + } +} + +template +_Widget* QModelMangerUI::replaceWidget(QWidget* pSrcWidget) +{ + if (!pSrcWidget) { + return nullptr; + } + QWidget* pParent = qobject_cast(pSrcWidget->parent()); + if (!pParent) { + return nullptr; + } + _Widget* pDstWidget = new _Widget; + auto *pFrom = pParent->layout()->replaceWidget(pSrcWidget, pDstWidget); + delete pFrom; + delete pSrcWidget; + return pDstWidget; } Q_SLOT void QModelMangerUI::onButtonClicked() @@ -117,6 +146,44 @@ int QModelMangerUI::lastNum(QString str) return str.right(1).toInt(); } +Q_SLOT bool QModelMangerUI::OnCellClicked(const QModelIndex &index) +{ + QString strListName = sender()->objectName(); + if (1 != index.column()) { + return false; + } + QString key = m_tabViewKeys.value(strListName); + int stationID = lastNum(strListName); + IStation *pStation = m_pCtrl->IGetStationByKey(key); + if (pStation) { + QString strModel = pStation->model(index.row()); + QString strName = QObject::tr("ģͺ:") + strModel; + int plcIndex = m_pCtrl->IGetPLCIndex(key, strModel); + ui.label_Name->setText(strModel); + + QImage img = m_pCtrl->IGetStandardImg(key, strModel); + if (img.isNull()) + { + img.load(":/Resource/no-img.png"); + } + int widgetWidth = m_srcImgView->width(); + int imgWidth = img.width(); + float scalew = (widgetWidth*1.0) / (imgWidth*1.0); + + int widgetHeight = m_srcImgView->height(); + int imgHeight = img.height(); + float scaleh = (widgetHeight*1.0) / (imgHeight*1.0); + float minScale = scalew < scaleh ? scalew : scaleh; +// m_srcImgView->setIsAutoResetToWindowSize(true); +// m_srcImgView->setIsAutoResetTransform(true); + m_srcImgView->setInitScale(minScale - 0.01); + m_srcImgView->clear(); + m_srcImgView->setImg(img); + + } + return true; +} + Q_SLOT bool QModelMangerUI::OnCellDoubleClicked(const QModelIndex &index) { QString strListName = sender()->objectName(); @@ -175,31 +242,16 @@ Q_SLOT void QModelMangerUI::onCheckBoxChange(int state) if (state > 0) { ui.wf_model_select_button->setDisabled(true); -// if (m_pCtrl) -// m_pCtrl->ISetOnlineModel(true); lpGlobalConfig::instance()->m_bOnlineMode = true; lpGlobalConfig::instance()->writeConfig(); } else { ui.wf_model_select_button->setDisabled(false); -// if (m_pCtrl) -// m_pCtrl->ISetOnlineModel(false); lpGlobalConfig::instance()->m_bOnlineMode = false; lpGlobalConfig::instance()->writeConfig(); } } -// IStation * QModelMangerUI::getStation(int nIndex) -// { -// if (nIndex == -1) { -// QWidget *pWidget = ui.tabWidgetStation->currentWidget(); -// if (pWidget) { -// nIndex = lastNum(pWidget->objectName()); -// } -// } -// return m_pCtrl->IGetStationById(nIndex); -// } - void QModelMangerUI::showEvent(QShowEvent *event) { if (m_pCtrl) { @@ -247,6 +299,7 @@ void QModelMangerUI::onInitModelList(IWfCtrl *pCtrl) pW->setObjectName(strObjName); ui.tabWidgetStation->addTab((QWidget*)pW, var); pStation->setView(pW); + connect(pW, SIGNAL(clicked(const QModelIndex &)), this, SLOT(OnCellClicked(const QModelIndex &))); connect(pW, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(OnCellDoubleClicked(const QModelIndex &))); nIndex++; } diff --git a/tpvs17/lpMain/QModelMangerUI.h b/tpvs17/lpMain/QModelMangerUI.h index b6c75d8..e0c5089 100644 --- a/tpvs17/lpMain/QModelMangerUI.h +++ b/tpvs17/lpMain/QModelMangerUI.h @@ -3,6 +3,7 @@ #include #include "ui_QModelMangerUI.h" #include "Station.h" +#include "lpImgViewer.h" class QModelMangerUI : public QWidget { @@ -16,9 +17,13 @@ public: Q_SLOT void onButtonClicked(); int lastNum(QString str); - Q_SLOT bool OnCellDoubleClicked(const QModelIndex &index); + Q_SLOT bool OnCellClicked(const QModelIndex &index);//¼ + Q_SLOT bool OnCellDoubleClicked(const QModelIndex &index);//˫¼ Q_SLOT void onCheckBoxChange(int state); QString currentTab(); + + template + _Widget* replaceWidget(QWidget* pSrcWidget); protected: virtual void showEvent(QShowEvent *event); virtual void closeEvent(QCloseEvent *event); @@ -27,6 +32,9 @@ private: Ui::QModelMangerUI ui; IWfCtrl *m_pCtrl{ nullptr }; QMap m_tabViewKeys; + lpImgViewer *m_srcImgView{ nullptr }; }; + + #endif diff --git a/tpvs17/lpMain/QModelMangerUI.ui b/tpvs17/lpMain/QModelMangerUI.ui index be423c0..523b728 100644 --- a/tpvs17/lpMain/QModelMangerUI.ui +++ b/tpvs17/lpMain/QModelMangerUI.ui @@ -6,8 +6,8 @@ 0 0 - 671 - 450 + 856 + 509 @@ -20,172 +20,250 @@ - - - - 0 - 0 - + + + QLayout::SetMaximumSize - - - 0 - 23 - - - - - 16777215 - 44444 - - - - QTabWidget::North - - - QTabWidget::Rounded - - - -1 - - + + + + + 5 + 0 + + + + + 0 + 23 + + + + + 16777215 + 44444 + + + + QTabWidget::North + + + QTabWidget::Rounded + + + -1 + + + + + + + + 4 + 0 + + + + 标定图: + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 358 + 358 + + + + + 358 + 358 + + + + background-color: rgb(170, 255, 127); + + + + + + + + + 型号名: + + + + + + + + 0 + 0 + + + + xxxx + + + + + + + + + - - - - 16777215 - 50 - - - - QFrame::Box - - - QFrame::Raised - - - 2 - - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 0 - 25 - - - - - 12 - - - - 添加 + + + + + + 16777215 + 50 + + + + QFrame::Box + + + QFrame::Raised + + + 2 + + + + 3 - - - - - - - 0 - 25 - + + 3 - - - 12 - + + 3 - - 修改 + + 3 - - - - - - - 0 - 25 - - - - - 12 - - - - 删除 - - - - - - - - 0 - 25 - - - - - 12 - - - - 设置为当前运行模型 - - - - - - - - 0 - 25 - - - - - 微软雅黑 - 12 - - - - 从PLC获取当前模型 - - - - - - - - - - - 16777215 - 25 - - - - - - + + + + + 0 + 25 + + + + + 12 + + + + 添加 + + + + + + + + 0 + 25 + + + + + 12 + + + + 修改 + + + + + + + + 0 + 25 + + + + + 12 + + + + 删除 + + + + + + + + 0 + 25 + + + + + 12 + + + + 设置为当前运行模型 + + + + + + + + 0 + 25 + + + + + 微软雅黑 + 12 + + + + 从PLC获取当前模型 + + + + + + + + + + + 16777215 + 25 + + + + + + + + diff --git a/tpvs17/lpMain/lpMain.cpp b/tpvs17/lpMain/lpMain.cpp index 74f2626..7e328db 100644 --- a/tpvs17/lpMain/lpMain.cpp +++ b/tpvs17/lpMain/lpMain.cpp @@ -25,6 +25,6 @@ lpMain::~lpMain() void lpMain::showWidget() { - m_wid.show(); + m_wid.showMaximized(); }