179 lines
6.8 KiB
C++
179 lines
6.8 KiB
C++
#include "mainwindow.h"
|
|
#include <QApplication>
|
|
#include <QSystemSemaphore>
|
|
#include <QSharedMemory>
|
|
#include <QMessageLogger>//日志
|
|
#include <QDebug>
|
|
#include <qmessagebox.h>
|
|
#include <qpushbutton.h>
|
|
#include <qlineedit.h>
|
|
#include <qlabel.h>
|
|
|
|
#include <qcombobox.h>
|
|
#include <QMetaType>
|
|
#include <globalStruct.h>
|
|
#include <back/manualDetThread.h>
|
|
#include <uiModule/uiModule_imageDoubleCheckQdialog.h>
|
|
|
|
#include <appCore.hpp>
|
|
#include <detProcess.hpp>
|
|
#include <opencv2/core/utils/logger.hpp>
|
|
#pragma region 程序启动功能
|
|
bool appIsRuning()
|
|
{
|
|
QSystemSemaphore sema("monkey", 1, QSystemSemaphore::Open);
|
|
sema.acquire();
|
|
QSharedMemory mem("DetUi");
|
|
if (mem.create(1) == false)
|
|
{
|
|
sema.release();
|
|
return false;
|
|
}
|
|
sema.release();
|
|
return true;
|
|
}
|
|
bool isRunAsAdmin()
|
|
{
|
|
BOOL fIsRunAsAdmin = FALSE;
|
|
PSID pAdministratorsGroup = NULL;
|
|
|
|
// Allocate and initialize a SID of the administrators group.
|
|
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
|
|
if (!AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
|
|
0, 0, 0, 0, 0, 0, &pAdministratorsGroup))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Determine whether the SID of administrators group is enabled in the primary access token of the process.
|
|
if (!CheckTokenMembership(NULL, pAdministratorsGroup, &fIsRunAsAdmin))
|
|
{
|
|
fIsRunAsAdmin = FALSE;
|
|
}
|
|
|
|
// Free the allocated SID.
|
|
if (pAdministratorsGroup)
|
|
{
|
|
FreeSid(pAdministratorsGroup);
|
|
}
|
|
|
|
return fIsRunAsAdmin;
|
|
}
|
|
void restartAsAdmin()
|
|
{
|
|
TCHAR szPath[MAX_PATH];
|
|
if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)))
|
|
{
|
|
SHELLEXECUTEINFO sei = { sizeof(sei) };
|
|
sei.lpVerb = TEXT("runas");
|
|
sei.lpFile = szPath;
|
|
sei.hwnd = NULL;
|
|
sei.nShow = SW_NORMAL;
|
|
|
|
if (!ShellExecuteEx(&sei))
|
|
{
|
|
DWORD dwError = GetLastError();
|
|
if (dwError == ERROR_CANCELLED)
|
|
{
|
|
//std::cout << "The user refused to allow privileges elevation.\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#pragma endregion
|
|
|
|
void connectSignalAndSlots(MainWindow* front, appCore* _core, detProcess* _detProcess)
|
|
{
|
|
//LOG
|
|
QObject::connect(&_core->_logService._logToQtWidget, &logToQtWidget::stdLogSignal,
|
|
front->_logWidget, &logWidget::recvStdLogMsg);
|
|
QObject::connect(&_core->_logService._logToQtWidget, &logToQtWidget::qtLogSignal,
|
|
front->_logWidget, &logWidget::recvQtLogMsg);
|
|
QObject::connect(&_core->_logService._logToQtWidget, &logToQtWidget::mainWindowStdLogSignal,
|
|
front->_displayWidget, &displayWidget::recvMainWindowStdLogMsg);
|
|
|
|
///////////TEMP
|
|
//QObject::connect(&_core->_qtFunc, &qtFunction::addCtData, front, &MainWindow::addCtData);
|
|
QObject::connect(&_core->_qtFunc, &qtFunction::sendInitString, front, &MainWindow::recvInitString);
|
|
QObject::connect(&_core->_qtFunc, &qtFunction::sendPixmapImageWidget, front, &MainWindow::recvPixmapImageWidget);
|
|
|
|
QObject::connect(&_core->_qtFunc, &qtFunction::sendInitFinished, front, &MainWindow::recvInitFinished);
|
|
//QObject::connect(&_core->_qtFunc, &qtFunction::addDashBoardData, front, &MainWindow::addDashBoardData);
|
|
QObject::connect(&_core->_qtFunc, &qtFunction::addCtData, front, &MainWindow::addCtData);
|
|
QObject::connect(&_core->_qtFunc, &qtFunction::addHistoryDataSignal, front, &MainWindow::addDetHistoryData);
|
|
//QObject::connect(&_core->_qtFunc, &qtFunction::switchStartBtnStatusSignal,
|
|
// front->_displayWidget->_switchProductWidget, &switchProductWidget::switchStartBtnStatus);
|
|
//QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleLocationMap_ResetToDefault,
|
|
// front->_displayWidget->_uiModuleLocationMap, &uiModuleLocationMap::resetToDefault);
|
|
//QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleLocationMap_SetProductSignStatus,
|
|
// front, &MainWindow::uiModuleLocationMapSetProductSignStatus);
|
|
//uiModuleImageDoubleCheckQdialog
|
|
QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleImageDoubleCheckQdialog_ShowWindows,
|
|
front, [=](QPixmap map) {front->_imageDoubleCheckQdialog->showAndSetImg(map); });
|
|
|
|
//uiModuleSummaryDataManager
|
|
//QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleSummaryDataManager_SetSummaryResultText,
|
|
// front, [=](QString text, Qt::GlobalColor color)
|
|
// {front->_displayWidget->_summaryDataManager->setSummaryResult(text, color); });
|
|
//QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleSummaryDataManager_Reset,
|
|
// front, [=]() {front->_displayWidget->_summaryDataManager->resetAllValue(); });
|
|
|
|
QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleBackContinueDetDialog_show,
|
|
front, [=]() {front->_backContinueDetDialog->show(); });
|
|
QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleBackContinueDetDialog_hide,
|
|
front, [=]() {front->_backContinueDetDialog->hide(); });
|
|
|
|
QObject::connect(&_core->_qtFunc, &qtFunction::uiModuleHistoryListWidget_reset,
|
|
front, [=]() {front->_displayWidget->historyImgs->reset(); });
|
|
|
|
QObject::connect(&_detProcess->_manualDetThread, &manualDetThread::finishImgReadSignal,
|
|
front->_manualDetWidget, &manualDetWidget::finishImgReadSlot);
|
|
|
|
QObject::connect(front->_manualDetWidget, &manualDetWidget::startManualDetSignal,
|
|
&_detProcess->_manualDetThread, &manualDetThread::startManualDetSlot);
|
|
|
|
QObject::connect(front, &MainWindow::reInitSignal,
|
|
_detProcess, [=]() {_detProcess->start(); });
|
|
QObject::connect(front->_loadingWidget.retryBtn, &QPushButton::clicked,
|
|
_detProcess, [=]() {_detProcess->start(); });
|
|
/* QObject::connect(front->_displayWidget->_switchProductWidget, &switchProductWidget::startArmProgramSignal,
|
|
front->_productDetDoubleCheck, &productDetDoubleCheck::showAndSetText);*/
|
|
|
|
}
|
|
|
|
appCore _core;
|
|
int main(int argc, char* argv[])
|
|
{
|
|
if (!isRunAsAdmin())
|
|
{
|
|
restartAsAdmin();
|
|
exit(0);
|
|
}
|
|
#if enableHideConsle
|
|
HWND hWnd = GetConsoleWindow();
|
|
if (hWnd) {
|
|
ShowWindow(hWnd, SW_HIDE);
|
|
}// 隐藏控制台窗口
|
|
#endif
|
|
QApplication a(argc, argv);
|
|
//检测是否已运行
|
|
if (appIsRuning() == false)
|
|
exit(0);
|
|
//////////
|
|
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_ERROR);
|
|
qRegisterMetaType<imgWidgetShowType>("imgWidgetShowType");
|
|
qRegisterMetaType<showImgPack>("showImgPack");
|
|
qRegisterMetaType<cv::Mat*>("matPtr");
|
|
qRegisterMetaType<cv::Mat>("mat");
|
|
qRegisterMetaType<std::string>("stdString");
|
|
qRegisterMetaType<historyPack>("historyPack");
|
|
qRegisterMetaType<Qt::GlobalColor>("QtGlobalColor");
|
|
//_core.initTimer();
|
|
MainWindow w;
|
|
w.show();
|
|
detProcess _detProcess;
|
|
connectSignalAndSlots(&w,&_core,&_detProcess);
|
|
_detProcess.start();
|
|
return a.exec();
|
|
}
|