|
|
|
|
|
#include "WfCtrl.h"
|
|
|
|
|
|
#include "Station.h"
|
|
|
|
|
|
#include "QSqliteWheelHubWf.h"
|
|
|
|
|
|
#include "iCoreCtrl.h"
|
|
|
|
|
|
#include "baseStruct.h"
|
|
|
|
|
|
#include "lpbengine.h"
|
|
|
|
|
|
#include "WfModel.h"
|
|
|
|
|
|
#include "WfColossus.h"
|
|
|
|
|
|
#include "WorkChecker.h"
|
|
|
|
|
|
#include "QZkJsonParser.h"
|
|
|
|
|
|
|
|
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
CWfCtrl::CWfCtrl(ICoreCtrl* p1, WfColossus* p3)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_nOnlineMode = false;
|
|
|
|
|
|
|
|
|
|
|
|
m_pConnectChecker = new WorkChecker;
|
|
|
|
|
|
m_pCoreCtrl = p1;
|
|
|
|
|
|
m_pColossus = p3;
|
|
|
|
|
|
m_setting = new QSettings(QCoreApplication::applicationDirPath()+"\\user\\systemfile.ini", QSettings::IniFormat);
|
|
|
|
|
|
readSettingFile();
|
|
|
|
|
|
QString path;
|
|
|
|
|
|
m_pWfDb = new QSqliteWheelHubWf(path + "//user//");
|
|
|
|
|
|
initStation();
|
|
|
|
|
|
QSettings systemIniFile("systemInfo.ini", QSettings::IniFormat);
|
|
|
|
|
|
m_nOnlineMode = systemIniFile.value("OnlineMode").toBool();
|
|
|
|
|
|
{
|
|
|
|
|
|
QString strErrorPath = QCoreApplication::applicationDirPath()+"/errorImage/";
|
|
|
|
|
|
// QDiskCleanThread *pDCleanThread = new QDiskCleanThread;
|
|
|
|
|
|
// pDCleanThread->setUseFlag(nCheckThreadEable);
|
|
|
|
|
|
// pDCleanThread->setDays(nCheckImgFileDays);
|
|
|
|
|
|
// pDCleanThread->SetImgStorageFolder(strErrorPath);
|
|
|
|
|
|
// pDCleanThread->setMiniSize(nMinSpaceSize);
|
|
|
|
|
|
// pDCleanThread->start();
|
|
|
|
|
|
// m_pDCThreadList.append(pDCleanThread);
|
|
|
|
|
|
//
|
|
|
|
|
|
//
|
|
|
|
|
|
// QString strRltImgPath = QCoreApplication::applicationDirPath() + "/DBFiles/Images/";
|
|
|
|
|
|
// QDiskCleanThread *pCleanDir = new QDiskCleanThread;
|
|
|
|
|
|
// pCleanDir->setModel(CleanDir);
|
|
|
|
|
|
// pCleanDir->setSleepS(3600);
|
|
|
|
|
|
// pCleanDir->setUseFlag(nCheckThreadEable);
|
|
|
|
|
|
// pCleanDir->setDays(nCheckDirDays);
|
|
|
|
|
|
// pCleanDir->SetImgStorageFolder(strRltImgPath);
|
|
|
|
|
|
// pCleanDir->setMiniSize(nMinSpaceSize);
|
|
|
|
|
|
// pCleanDir->start();
|
|
|
|
|
|
// m_pDCThreadList.append(pCleanDir);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CWfCtrl::~CWfCtrl()
|
|
|
|
|
|
{
|
|
|
|
|
|
writeSettingFile();
|
|
|
|
|
|
if (m_pDCThreadList.size() > 0){
|
|
|
|
|
|
for (int nIndex = 0; nIndex < m_pDCThreadList.size(); nIndex++)
|
|
|
|
|
|
{
|
|
|
|
|
|
QDiskCleanThread *pDCThread = m_pDCThreadList.at(nIndex);
|
|
|
|
|
|
if (pDCThread)
|
|
|
|
|
|
{
|
|
|
|
|
|
pDCThread->ExitThread();
|
|
|
|
|
|
pDCThread->quit();
|
|
|
|
|
|
pDCThread->wait();
|
|
|
|
|
|
delete pDCThread;
|
|
|
|
|
|
pDCThread = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
m_pDCThreadList.clear();
|
|
|
|
|
|
//m_pColossus->setOnlineModel(m_nOnlineMode);
|
|
|
|
|
|
if (m_pConnectChecker)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete m_pConnectChecker;
|
|
|
|
|
|
m_pConnectChecker = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pWfDb) {
|
|
|
|
|
|
delete m_pWfDb;
|
|
|
|
|
|
m_pWfDb = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
qDeleteAll(m_pStationMap);
|
|
|
|
|
|
m_pStationMap.clear();
|
|
|
|
|
|
qDeleteAll(m_mpModels);
|
|
|
|
|
|
m_mpModels.clear();
|
|
|
|
|
|
qDebug() << "~CWfCtrl";
|
|
|
|
|
|
if (m_setting){
|
|
|
|
|
|
delete m_setting;
|
|
|
|
|
|
m_setting = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CWfCtrl::ISetOnlineModel(bool b)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_nOnlineMode = b;
|
|
|
|
|
|
QSettings systemIniFile("systemInfo.ini", QSettings::IniFormat);
|
|
|
|
|
|
systemIniFile.setValue("OnlineMode", m_nOnlineMode);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CWfCtrl::onInit()
|
|
|
|
|
|
{
|
|
|
|
|
|
initModel();
|
|
|
|
|
|
initCurrentModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::IOnlineMode()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_nOnlineMode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IStation* CWfCtrl::IGetStationById(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
for each (IStation* var in m_pStationMap) {
|
|
|
|
|
|
if (var->stationId() == id) {
|
|
|
|
|
|
return var;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IStation* CWfCtrl::IGetStationByKey(QString key)
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pStationMap.value(key);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList CWfCtrl::IGetStationKeys()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pStationMap.keys();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::initModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_mpModels = m_pColossus->allTask();
|
|
|
|
|
|
QStringList lstModels = m_mpModels.keys();
|
|
|
|
|
|
for (int i = 0; i < lstModels.size(); i++) {
|
|
|
|
|
|
QStringList lst = lstModels.at(i).split("##");
|
|
|
|
|
|
if (lst.size() != 2) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
int nId = lst.first().toInt();
|
|
|
|
|
|
IStation* pStation = IGetStationById(nId);
|
|
|
|
|
|
if (pStation) {
|
|
|
|
|
|
pStation->addModel(lst.last());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::initStation()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!m_pCoreCtrl)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
QStringList camKeys = m_pCoreCtrl->ICameraKeys();
|
|
|
|
|
|
for (QStringList::iterator it = camKeys.begin(); it != camKeys.end(); ++it) {
|
|
|
|
|
|
TP_CAMERA_OPTION camOpt;
|
|
|
|
|
|
if (!m_pCoreCtrl->ICameraOptionByKey(*it, camOpt)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
IStation *pStation = new Station(m_pWfDb, m_pCoreCtrl, this);
|
|
|
|
|
|
pStation->setCamInfo(camOpt.id, camOpt.algorithm, camOpt.uniqueName, camOpt.showName);
|
|
|
|
|
|
m_pStationMap.insert(camOpt.uniqueName, pStation);
|
|
|
|
|
|
|
|
|
|
|
|
if (camOpt.deviceType != 100)//虚拟相机模式下不开启定时删除图像的模式
|
|
|
|
|
|
{
|
|
|
|
|
|
QDiskCleanThread *pDCleanThread = new QDiskCleanThread;
|
|
|
|
|
|
pDCleanThread->setUseFlag(nCheckThreadEable);
|
|
|
|
|
|
pDCleanThread->setDays(nCheckImgFileDays);
|
|
|
|
|
|
//QString strErrorPath = QCoreApplication::applicationDirPath() + "//errorImage//";
|
|
|
|
|
|
//pDCleanThread->SetImgStorageFolder(strErrorPath);
|
|
|
|
|
|
pDCleanThread->SetImgStorageFolder(camOpt.folder);
|
|
|
|
|
|
pDCleanThread->setMiniSize(nMinSpaceSize);
|
|
|
|
|
|
pDCleanThread->start();
|
|
|
|
|
|
m_pDCThreadList.append(pDCleanThread);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::initCurrentModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
QStringList lstModels = m_pColossus->allRunningTask();
|
|
|
|
|
|
for each (IStation* var in m_pStationMap) {
|
|
|
|
|
|
bool bFlag = false;
|
|
|
|
|
|
for (int i = 0; i < lstModels.size(); i++) {
|
|
|
|
|
|
QStringList lst = lstModels.at(i).split("##");
|
|
|
|
|
|
if (lst.size() != 2) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (lst.first().toInt() == var->stationId()) {
|
|
|
|
|
|
if (var->modelList().contains(lst.last())) {
|
|
|
|
|
|
var->setCurrentModel(lst.last());
|
|
|
|
|
|
m_pColossus->selModel(var->stationId(), lst.last());
|
|
|
|
|
|
bFlag = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!bFlag) {
|
|
|
|
|
|
QString strModel = var->modelCount() == 0 ? QString() : var->model(0);
|
|
|
|
|
|
var->setCurrentModel(strModel);
|
|
|
|
|
|
m_pColossus->selModel(var->stationId(), strModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
m_pColossus->ReSetModifyState();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::IAddModel(int nStation, QString strModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
IStation *pStation = IGetStationById(nStation);
|
|
|
|
|
|
if (!pStation) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
bool b = pStation->addModel(strModel);
|
|
|
|
|
|
if (!b) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_pColossus) {
|
|
|
|
|
|
m_pColossus->addModel(nStation, strModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
WfModel *pMode = new WfModel;
|
|
|
|
|
|
pMode->strName = genModelName(nStation, strModel);
|
|
|
|
|
|
m_mpModels.insert(pMode->strName, pMode);
|
|
|
|
|
|
qDebug() << "CWfCtrl::IAddModel:" << strModel;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::IDeleteModel(int nStation, QString strModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
IStation *pStation = IGetStationById(nStation);
|
|
|
|
|
|
if (!pStation) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
QString strNow = pStation->currentRunningModel();
|
|
|
|
|
|
if (strNow == strModel) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
pStation->delModel(strModel);
|
|
|
|
|
|
if (m_pColossus) {
|
|
|
|
|
|
m_pColossus->delModel(nStation, strModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
m_mpModels.remove(genModelName(nStation, strModel));
|
|
|
|
|
|
qDebug() << "CWfCtrl::IDeleteModel:" << strModel;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::ISaveModel(int ID, QString strName)
|
|
|
|
|
|
{
|
|
|
|
|
|
IStation *pStation = IGetStationById(ID);
|
|
|
|
|
|
if (m_pColossus && pStation)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pColossus->saveTask(pStation->wfModel(strName));
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::ISelModel(int nStation, QString strModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (strModel.isEmpty()) {
|
|
|
|
|
|
qDebug() << "station=" << nStation << ",model=" << strModel;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
IStation *pStation = IGetStationById(nStation);
|
|
|
|
|
|
if (pStation) {
|
|
|
|
|
|
pStation->setCurrentModel(strModel);
|
|
|
|
|
|
if (m_pColossus) {
|
|
|
|
|
|
//需要测试
|
|
|
|
|
|
m_pColossus->selModel(nStation, strModel/*pStation->currentRunningModel()*/);
|
|
|
|
|
|
//m_pColossus->ReSetModifyState();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CWfCtrl::ISetModifyModel(bool bflag)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_pColossus){
|
|
|
|
|
|
m_pColossus->setModifyState(bflag);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString CWfCtrl::IGetCurrentRuningModel(int nIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
IStation *pStation = IGetStationById(nIndex);
|
|
|
|
|
|
if (!pStation) {
|
|
|
|
|
|
return QString();
|
|
|
|
|
|
}
|
|
|
|
|
|
QString strNow = pStation->currentRunningModel();
|
|
|
|
|
|
return strNow;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WfModel * CWfCtrl::IGetModelInfo(int nIndex, QString strModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
// if (m_pColossus) {
|
|
|
|
|
|
// m_pColossus->selModel(nStation, pStation->currentRunningModel());
|
|
|
|
|
|
// }
|
|
|
|
|
|
return m_mpModels.value(genModelName(nIndex, strModel));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString CWfCtrl::genModelName(int nIndex, QString strModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
return QString::number(nIndex) + "##" + strModel;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QMap<QString, class WfModel*> CWfCtrl::IGetModelInfos()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_mpModels;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::IStandard(int nIndex,QString strModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pColossus->bStandard(nIndex,strModel);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::IConnectStatus()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_pConnectChecker) {
|
|
|
|
|
|
return m_pConnectChecker->isWorking();
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CWfCtrl::registerConnect()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_pConnectChecker) {
|
|
|
|
|
|
m_pConnectChecker->registerWorking();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::IBatchModel()
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_pColossus->getBatchModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::IUpdateModelInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
m_pColossus->updateModelInfo(m_mpModels);
|
|
|
|
|
|
for each (IStation* var in m_pStationMap) {
|
|
|
|
|
|
emit var->sgUpdateLable();
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString CWfCtrl::IGetCommName()
|
|
|
|
|
|
{
|
|
|
|
|
|
return "null com";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CWfCtrl::IGetUserInfo(QString& user, int& level)
|
|
|
|
|
|
{
|
|
|
|
|
|
// if (!m_pMainBack) {
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return m_pMainBack->IGetUserInfo(user, level);
|
|
|
|
|
|
|
|
|
|
|
|
if (m_strUserName.isEmpty())
|
|
|
|
|
|
user = QObject::tr("未登录");
|
|
|
|
|
|
else
|
|
|
|
|
|
user = m_strUserName;
|
|
|
|
|
|
level = m_nLevel;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CWfCtrl::ISetUserInfo(QString& user, int& level)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_strUserName = user;
|
|
|
|
|
|
m_nLevel = level;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CWfCtrl::readSettingFile()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_setting){
|
|
|
|
|
|
QString m_str = "/CheckThread/";
|
|
|
|
|
|
nCheckImgFileDays = m_setting->value(m_str + "days", 7).toInt();
|
|
|
|
|
|
nCheckDirDays = m_setting->value(m_str + "days_dir", 30).toInt();
|
|
|
|
|
|
nCheckThreadEable = m_setting->value(m_str + "IsUse", true).toBool();
|
|
|
|
|
|
nMinSpaceSize = m_setting->value(m_str + "spacesize", 10).toInt();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CWfCtrl::writeSettingFile()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_setting){
|
|
|
|
|
|
QString m_str = "/CheckThread/";
|
|
|
|
|
|
m_setting->setValue(m_str + "days", nCheckImgFileDays);
|
|
|
|
|
|
m_setting->setValue(m_str + "days_dir", nCheckDirDays);
|
|
|
|
|
|
m_setting->setValue(m_str + "IsUse", nCheckThreadEable);
|
|
|
|
|
|
m_setting->setValue(m_str + "spacesize", nMinSpaceSize);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|