diff --git a/src/lpBase/SystemStateInfo.h b/src/lpBase/SystemStateInfo.h new file mode 100644 index 0000000..69755ec --- /dev/null +++ b/src/lpBase/SystemStateInfo.h @@ -0,0 +1,19 @@ +#ifndef SYSTEMSTATEINFO +#define SYSTEMSTATEINFO + +#include +#include "lpdsgdefine.h" + +class SystemStateInfo +{ +public: + static bool bParamStateFlag; + static int rgb; + static QSettings setIni; +}; + + +#endif // SYSTEMSTATEINFO + + + diff --git a/src/lpBase/baseClass.h b/src/lpBase/baseClass.h new file mode 100644 index 0000000..6e0a372 --- /dev/null +++ b/src/lpBase/baseClass.h @@ -0,0 +1,35 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:baseClass.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/08 + History:8:4:2015 13:13 + *******************************************************************************/ +#ifndef __BASE_CLASS_H_20150408 +#define __BASE_CLASS_H_20150408 + +//#include "baseDefine.h" +//#include "ZkImage.h" +#include +namespace QZK { + class QAtomicIntAdder{ + public: + QAtomicIntAdder(QAtomicInt& ai) + : m_ai(ai) { + ++m_ai; + } + ~QAtomicIntAdder() { + --m_ai; + } + private: + QAtomicInt& m_ai; + }; +}; + +namespace CZK { + +} + +#endif \ No newline at end of file diff --git a/src/lpBase/baseConstant.h b/src/lpBase/baseConstant.h new file mode 100644 index 0000000..684394d --- /dev/null +++ b/src/lpBase/baseConstant.h @@ -0,0 +1,20 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:baseConstant.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/08 + History:8:4:2015 12:55 + *******************************************************************************/ +#ifndef __BASE_CONSTNAT_H_20150608 +#define __BASE_CONSTNAT_H_20150608 + +namespace TP_STR{ + const char cszJsonSuffix[] = ".json"; + const char cszDatSuffix[] = ".dat"; +// const char cszCfgFolder[] = "config\\"; +// const char cszMainCfg[] = "main"; +} + +#endif \ No newline at end of file diff --git a/src/lpBase/baseDefine.h b/src/lpBase/baseDefine.h new file mode 100644 index 0000000..550fbfe --- /dev/null +++ b/src/lpBase/baseDefine.h @@ -0,0 +1,72 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:baseDefine.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/07 + History:7:4:2015 9:13 + *******************************************************************************/ +#ifndef __BASE_DEFINE_H_20150407 +#define __BASE_DEFINE_H_20150407 + +#include "sysInclude.h" + +#ifndef BYTE +typedef unsigned char BYTE; +#endif +#ifndef WORD +typedef unsigned short WORD; +#endif +#ifndef DWORD +typedef unsigned long DWORD; +#endif +//#ifndef size_t +//typedef unsigned int size_t; +//#endif + +#define MAX(a, b) (a) > (b) ? (a) : (b) +#define MIN(a, b) (a) > (b) ? (b) : (a) +#define ABS(a) (a) < 0 ? (-(a)) : (a) +#define SELF_ABS(a) if( a < 0 ) a = -a + + +#define ZStringA QByteArray + +//#define USE_PIXMAP_AS_SHOW +#ifdef USE_PIXMAP_AS_SHOW +#define ZShowImage QPixmap +#else +#define ZShowImage QImage +#endif + + +//#define QT_NO_DEBUG_OUTPUT //open this remark to enable qDebug +#ifndef tpDebugOut +#define tpDebugOut(...) qDebug(__VA_ARGS__) +#endif + +enum emTpColorFormat{ + TP_COLOR_NONE = 0, + TP_COLOR_Y800 = 1,//"GRAY8" + TP_COLOR_RGB24 = 2,//"RGB24" + TP_COLOR_RGB32 = 3,//"RGB32" + TP_COLOR_Y16 = 4,//"GRAY16" + TP_COLOR_RGB48 = 5, + TP_COLOR_BGR24 = 11,//"BGR24" + TP_COLOR_BGR32 = 12,//"BGR32" + // UYVY = 5, +}; + +//#define _USE_SPIDER_LOG + +enum emTpWarningCode { + WARNING_NO, + WARNING_COMM_CLOSED, +}; + +#ifndef PI +#define PI 3.1415927 +#endif + +#endif \ No newline at end of file diff --git a/src/lpBase/baseFunction.h b/src/lpBase/baseFunction.h new file mode 100644 index 0000000..55c9317 --- /dev/null +++ b/src/lpBase/baseFunction.h @@ -0,0 +1,31 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:baseFunction.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/08 + History:8:4:2015 13:04 + *******************************************************************************/ +#ifndef __BASE_FUNCTION_H_20150408 +#define __BASE_FUNCTION_H_20150408 + +#include "sysInclude.h" + +namespace SYS_F { + int GetCpus() { +#if defined(Q_OS_WIN) || defined(WIN32) || defined(WIN64) + SYSTEM_INFO sysInfo; + GetSystemInfo(&sysInfo); + return sysInfo.dwNumberOfProcessors; +#else + return 0; +#endif + } +} + +namespace TP_F { + +} + +#endif \ No newline at end of file diff --git a/src/lpBase/baseInclude.h b/src/lpBase/baseInclude.h new file mode 100644 index 0000000..eeeeca5 --- /dev/null +++ b/src/lpBase/baseInclude.h @@ -0,0 +1,20 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:baseInclude.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/07 + History:7:4:2015 9:16 + *******************************************************************************/ +#ifndef __BASE_INCLUDE_H_20150407 +#define __BASE_INCLUDE_H_20150407 + +#include "sysInclude.h" +#include "baseDefine.h" + +#include "baseConstant.h" +#include "baseStruct.h" +#include "baseClass.h" + +#endif \ No newline at end of file diff --git a/src/lpBase/baseStruct.h b/src/lpBase/baseStruct.h new file mode 100644 index 0000000..8c5adce --- /dev/null +++ b/src/lpBase/baseStruct.h @@ -0,0 +1,474 @@ +/****************************************************************************** +Copyright(C):2015~2018 hzleaper +FileName:baseStruct.h +Author:zhikun wu +Email:zk.wu@hzleaper.com +Tools:vs2010 pc on company +Created:2015/04/09 +History:9:4:2015 10:33 +*******************************************************************************/ +#ifndef __BASE_STRUCT_H +#define __BASE_STRUCT_H + +#include "baseDefine.h" +#include "baseConstant.h" +#include "iAlgorithm.h" + +#define BASE_MAX_FILE_PATH 260 +#define BASE_MAX_FOLDER_NAME_SIZE 64 +#define BASE_MAX_FILE_NAME_SIZE 64 + +enum emTpFolderNameList { + TP_FOLDER_NAME_CONFIG = 0, + TP_FOLDER_NAME_PICTURE = 1, + TP_FOLDER_NAME_UI = 2, + TP_FOLDER_NAME_MAX_NUM = 32, +}; +typedef struct tagTP_GLOBAL_DATA{ + char tgdMainPath[BASE_MAX_FILE_PATH]; + char tgdUserPath[BASE_MAX_FILE_PATH]; + char tgdDllPath[BASE_MAX_FILE_PATH]; + char tgdFolderNames[TP_FOLDER_NAME_MAX_NUM][BASE_MAX_FOLDER_NAME_SIZE]; + // char tgdFileNames[TP_FILE_NAME_MAX_NUM][BASE_MAX_FILE_NAME_SIZE]; + void* tgdpDllPaths;//pointer to a stringlist +}TP_GLOBAL_DATA; + +inline ZStringA TPConfigFileWholePath(const TP_GLOBAL_DATA* pGlobal, const char* szFile) { + ZStringA szFileName(pGlobal->tgdMainPath); + szFileName.append(pGlobal->tgdFolderNames[TP_FOLDER_NAME_CONFIG]).append(szFile).append(TP_STR::cszJsonSuffix); + return szFileName; +} + +///////////////////////////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////////////////////////////// + +enum emTpImageShowType { + TP_IMAGE_SHOW_NO = 0, + TP_IMAGE_SHOW_EVERY = 1, + TP_IMAGE_SHOW_NEW = 2, +}; + +typedef struct tagTP_CORE_SETTING{ + int threadsCount; + int imageShowType; +}TP_CORE_SETTING; + +enum emTpDeviceType { + DEV_CAM_NONE = 0, + DEV_CAM_VIRTUAL = 100, + DEV_CAM_VIRTUAL_FOLDER = 100, + DEV_CAM_BITFLOW = 110, + DEV_CAM_BITFLOW_BI = 110, + DEV_CAM_GIGE = 120, + DEV_CAM_USB = 130, + DEV_CAM_HIK = 140, + DEV_CAM_VIMBA = 150, + DEV_CAM_BAUMER = 160, + DEV_CAM_ADLINK = 170, + DEV_CAM_DAHUA = 180, + DEV_CAM_BASLER = 190, + DEV_CAM_PTGRAY = 200, + DEV_CAM_EURESYS = 220, + DEV_CAM_DALSA = 230, +}; + +static const QMap gCameraNamesMap = { + { DEV_CAM_NONE, "Unknown(0)" }, + { DEV_CAM_VIRTUAL, "Virtual Camera(100)" }, + { DEV_CAM_VIRTUAL_FOLDER, "Virtual Camera(100)" }, + { DEV_CAM_BITFLOW, "BitFlow(110)" }, + { DEV_CAM_BITFLOW_BI, "BitFlow(110)" }, + { DEV_CAM_GIGE, "Gige(120)" }, + { DEV_CAM_USB, "USB Camera(130)" }, + { DEV_CAM_HIK, "HIK(140)" }, + { DEV_CAM_VIMBA, "Vimba(150)" }, + { DEV_CAM_BAUMER, "Baumer(160)" }, + { DEV_CAM_ADLINK, "AdLink(170)" }, + { DEV_CAM_DAHUA, "DaHua(180)" }, + { DEV_CAM_BASLER, "Basler(190)" }, + { DEV_CAM_PTGRAY, "PtGray(200)" }, + { DEV_CAM_EURESYS, "Euresys(220)" }, + { DEV_CAM_DALSA, "Dalsa(230)" } +}; + +#define TP_STRING_MAX_SIZE 256 + +enum emTpCameraStatus{ + TP_CAMERA_STATUS_UNINIT = 0, // 未初始化(刚从配置文件加载) + TP_CAMERA_STATUS_INITED = 1, // 已初始化(即加载DLL成功) + TP_CAMERA_STATUS_OPENED = 2, // 已打开 + TP_CAMERA_STATUS_STARTED = 3, // 运行中 + TP_CAMERA_STATUS_STOPPED = 4, // 暂停 + TP_CAMERA_STATUS_CLOSED = 5, // 已关闭 +}; + +static const QMap gCameraStatusMap = { + { TP_CAMERA_STATUS_UNINIT, "Uninitialized" }, + { TP_CAMERA_STATUS_INITED, "Initialized" }, + { TP_CAMERA_STATUS_OPENED, "Opened" }, + { TP_CAMERA_STATUS_STARTED, "Running" }, + { TP_CAMERA_STATUS_STOPPED, "Paused" }, + { TP_CAMERA_STATUS_CLOSED, "Closed" } +}; + +typedef struct tagTP_CAMERA_OPTION { + tagTP_CAMERA_OPTION() + :id(0), deviceType(0), save(0), loop(0), width(0), + height(0), zoom(0), format(TP_COLOR_NONE), algorithm(0), exposure(0), + boardType(0), boardNum(0), gain(0), bIgnoreImage(false), + bNeedRgbSwapped(false), bAutoOpen(true), bAutoPush(true), + status(TP_CAMERA_STATUS_UNINIT) + { } + int id; + int deviceType; + BYTE save; + BYTE loop;// + BYTE reserve[2]; + QString showName; + QString uniqueName; + int width; + int height; + int zoom; + emTpColorFormat format; + QString folder; + QString saveImgSuffix; + int algorithm; + QString relyOnCamera; + long exposure; + int boardType; + int boardNum; + long gain; + QString dllsuffix; + QString sBoardName; + QString sBoardConfigFile; + + // used inner + bool bIgnoreImage; + QStringList* pSerials; + bool bNeedRgbSwapped; + QString macAddress; + bool bAutoOpen; + QString cameraFilePath; + bool bAutoPush; // 默认一旦得到图片,就直接push进pool。 + + // camera status - used for app inside + emTpCameraStatus status; + + bool operator==(const tagTP_CAMERA_OPTION& rhs) + { + return (id == rhs.id) && (deviceType == rhs.deviceType) && + (save == rhs.save) && (loop == rhs.loop) && + (showName == rhs.showName) && + (uniqueName == rhs.uniqueName) && + (zoom == rhs.zoom) && (format == rhs.format) && + (folder == rhs.folder) && + (saveImgSuffix == rhs.saveImgSuffix) && + (algorithm == rhs.algorithm) && (relyOnCamera == rhs.relyOnCamera) && + (exposure == rhs.exposure) && (boardType == rhs.boardType) && + (boardNum == rhs.boardNum) && + (gain == rhs.gain) && + (dllsuffix == rhs.dllsuffix) && + (sBoardName == rhs.sBoardName) && + (sBoardConfigFile == rhs.sBoardConfigFile) && + (bAutoPush == rhs.bAutoPush) && + (bNeedRgbSwapped == rhs.bNeedRgbSwapped); + } +}TP_CAMERA_OPTION; + +enum emTpCommType { + TP_COMM_TYPE_NO = 0, + TP_COMM_TYPE_SERIAL = 1, + TP_COMM_TYPE_USB = 2, + TP_COMM_TYPE_TCP_CLIENT = 3, // 主机作为客户端 + TP_COMM_TYPE_TCP_SERVER = 4, // 主机作为服务端 + TP_COMM_TYPE_TCP_CLIENT_SESSION = 5, // 主机作为服务端,接受的客户端会话 +}; + +static const QMap gCommNamesMap = { + { TP_COMM_TYPE_NO, "Unknown" }, + { TP_COMM_TYPE_SERIAL, "Serial Port" }, + { TP_COMM_TYPE_USB, "USB Port" }, + { TP_COMM_TYPE_TCP_CLIENT, "TCP Client" }, + { TP_COMM_TYPE_TCP_SERVER, "TCP Server" }, + { TP_COMM_TYPE_TCP_CLIENT_SESSION, "TCP Client Session" } +}; + +enum emTpCommStatus{ + TP_COMM_STATUS_DISABLE = 0, // 禁用状态 + TP_COMM_STATUS_OPENNING = 1, // 打开中或者连接建立中 + TP_COMM_STATUS_CONNECTED = 2, // 已打开或者连接已建立 + TP_COMM_STATUS_CLOSED = 3, // 已关闭 + TP_COMM_STATUS_CLOSING = 4, // 正在关闭 +}; + +typedef struct tagTP_COMM_SETTING_NODE { + tagTP_COMM_SETTING_NODE() + :type(TP_COMM_TYPE_NO), enable(0), + bound(115200), triggerInterval(0), + usb_pid(0), usb_vid(0), heartBeatInterval(5000), + strHostAddress("127.0.0.1"), hostPort(9040), + strListenIp("*"), listenPort(9040), nMaxClients(0), + nClientPort(0), status(TP_COMM_STATUS_DISABLE) + {} + + emTpCommType type; + int enable; + QString strName; + + //used for serial port + int bound; + int triggerInterval; + int meterDecodeInterval; + int usb_pid; + int usb_vid; + int heartBeatInterval; + + // used for tcp client + QString strHostAddress; + int hostPort; + + // used for tcp server + QString strListenIp; + int listenPort; + int nMaxClients; + + // used for tcp server client session + int nClientPort; + + // node status - used for app inside + emTpCommStatus status; + + bool operator==(const tagTP_COMM_SETTING_NODE& rhs) + { + return (type == rhs.type) && (enable == rhs.enable) && + (strName == rhs.strName) && (bound == rhs.bound) && + (triggerInterval == rhs.triggerInterval) && + (meterDecodeInterval == rhs.meterDecodeInterval) && + (usb_pid == rhs.usb_pid) && (usb_vid == rhs.usb_vid) && + (heartBeatInterval == rhs.heartBeatInterval) && + (strHostAddress == rhs.strHostAddress) && + (hostPort == rhs.hostPort) && (strListenIp == rhs.strListenIp) && + (listenPort == rhs.listenPort) && (nMaxClients == rhs.nMaxClients) && + (nClientPort == rhs.nClientPort); + } + +}TP_COMM_SETTING_NODE; + +enum emTpDeviceTriggerMode { + DEV_TRIGGER_MODE_STOP = 0, + DEV_TRIGGER_MODE_OUT = 1, + DEV_TRIGGER_MODE_AUTO = 2, + DEV_TRIGGER_MODE_FIXED_AUTO = 3, + DEV_TRIGGER_MODE_SOFT = 4, + // DEV_TRIGGER_MODE_MANUAL = 3, +}; + +enum emTpTriggerDirection { + TRIGGER_DIRECT_FOREWARD = 0, + TRIGGER_DIRECT_BACKWARD = 1, + TRIGGER_DIRECT_REPEAT = 2, +}; + +typedef struct tagTP_CAMERAPOOL_OPTION { + emTpDeviceTriggerMode triggerMode; + emTpTriggerDirection triggerDirection; + int frameRate; + int fixedFrames; +}TP_CAMERAPOOL_OPTION; + +typedef struct tagTP_CAMERA_WIN { + tagTP_CAMERA_WIN() + :images(1), buffers(2), + bitsPerPixel(32), index(0), + bufferW(0), bufferH(0), mirror(0), + bCacheOriginImage(false), bNeedRgbSwapped(false) + {} + QString key;//widget name + QString device;//camera key + quint8 images; + quint8 buffers; + quint8 bitsPerPixel; + quint8 index; + int bufferW; + int bufferH; + int mirror;//0:no, 1:horizontal, 2:vertical, 3: both + bool bCacheOriginImage; + bool bNeedRgbSwapped; + + bool operator==(const tagTP_CAMERA_WIN& rhs) + { + return (key == rhs.key) && (device == rhs.device) && + (images == rhs.images) && (buffers == rhs.buffers) && + (bitsPerPixel == rhs.bitsPerPixel) && + (index == rhs.index) && + (bufferW == rhs.bufferW) && (bufferH == rhs.bufferH) && + (mirror == rhs.mirror) && + (bCacheOriginImage == rhs.bCacheOriginImage) && + (bNeedRgbSwapped == rhs.bNeedRgbSwapped); + } +}TP_CAMERA_WIN; + +enum emTpUiDataType { + TP_UI_DATA_FROM_CORECTRL = 0, + TP_UI_DATA_FROM_ALGORITHM = 0x10000, + TP_UI_DATA_FROM_CAMERA = 0x20000, + TP_UI_DATA_FROM_COMMUNICATE = 0x30000, +}; + +Q_DECLARE_METATYPE(emTpUiDataType) + +typedef struct tagTP_IO_OUT_CONTROL { + BYTE index; + BYTE state;//0 or 1 + WORD mSecToSwitch;//0 for no Switch; +}TP_IO_OUT_CONTROL; + +static const QMap gColorNameMap = { + { TP_COLOR_NONE, "None" }, + { TP_COLOR_Y800, "GRAY8" }, + { TP_COLOR_RGB24, "RGB24" }, + { TP_COLOR_RGB32, "RGB32" }, + { TP_COLOR_Y16, "GRAY16" }, + { TP_COLOR_RGB48, "RGB48" }, + { TP_COLOR_BGR24, "BGR24" }, + { TP_COLOR_BGR32, "BGR32" } +}; + +#define TP_LOG_TAIL " - " << __FUNCTION__ +#define TP_DEBUG(msg) qDebug() << msg << TP_LOG_TAIL; +#define TP_WARN(msg) qWarning() << msg << TP_LOG_TAIL; +#define TP_ERROR(msg) qCritical() << msg << TP_LOG_TAIL; + +//global functions +namespace TP_FUNCS +{ +#define F_INLINE inline + F_INLINE QString ImageFileName(DWORD nFrameNumber, const TP_CAMERA_OPTION* pCamOpt, const char* szSuffix) + { + QStringList invaldcha = (QStringList() << "\\" << "/" << "*" << "?" << "<" << ">" << "|" << ":"); + QDateTime dt = QDateTime::currentDateTime(); + QString strCamName = pCamOpt->uniqueName; + foreach(const QString &str, invaldcha) { + strCamName.remove(str); + } + QString strName = pCamOpt->folder + strCamName + + "_" + dt.toString("yyyy_MM_dd_hh_mm_ss_zzz") + "_" + + QString::number(nFrameNumber) + szSuffix/*".BMP"*/; + + return strName; + } + + F_INLINE QString ImageFileName(DWORD nFrameNumber, const TP_CAMERA_OPTION* pCamOpt) + { + QStringList invaldcha = (QStringList() << "\\" << "/" << "*" << "?" << "<" << ">" << "|" << ":"); + QDateTime dt = QDateTime::currentDateTime(); + QString strCamName = pCamOpt->uniqueName; + //foreach(const QString &str, invaldcha) { + // strCamName.remove(str); + //} + strCamName.remove(":"); + QString strName = pCamOpt->folder + strCamName + + "_" + dt.toString("yyyy_MM_dd_hh_mm_ss_zzz") + "_" + + QString::number(nFrameNumber) + pCamOpt->saveImgSuffix; + + return strName; + } + + F_INLINE emTpColorFormat FromQImageFormat(const QImage &image) + { + if (QImage::Format_RGB32 == image.format()) + { + return TP_COLOR_RGB32; + } + else if (QImage::Format_RGB888 == image.format()) + { + return TP_COLOR_RGB24; + } + else if (QImage::Format_Indexed8 == image.format()) + { + return TP_COLOR_Y800; + } + else if (QImage::Format_RGB16 == image.format()) + { + return TP_COLOR_Y16; + } + else if (QImage::Format_ARGB32 == image.format()) + { + return TP_COLOR_RGB48; + } + else + { + return TP_COLOR_NONE; + } + } + + F_INLINE QImage::Format ToQImageFormat(emTpColorFormat colorFormat) + { + if (TP_COLOR_RGB32 == colorFormat) + { + return QImage::Format_RGB32; + } + else if (TP_COLOR_RGB24 == colorFormat) + { + return QImage::Format_RGB888; + } + else if (TP_COLOR_Y800 == colorFormat) + { + return QImage::Format_Indexed8; + } + else if (TP_COLOR_Y16 == colorFormat) + { + return QImage::Format_RGB16; + } + else if (TP_COLOR_RGB48 == colorFormat) + { + return QImage::Format_ARGB32; + } + else + { + return QImage::Format_Invalid; + } + } + + F_INLINE int BitsPerPixels(emTpColorFormat colorFormat) + { + if (TP_COLOR_RGB32 == colorFormat) + { + return 32; + } + else if (TP_COLOR_RGB24 == colorFormat) + { + return 24; + } + else if (TP_COLOR_Y800 == colorFormat) + { + return 8; + } + else if (TP_COLOR_Y16 == colorFormat) + { + return 16; + } + else + { + return 0; + } + } + + F_INLINE bool isValidImgSuffix(const QString& str) + { + static QRegExp rx("(\\w*|\\w*\\*)\\.(?:bmp|jpeg|jpg|png)", Qt::CaseInsensitive); + return rx.exactMatch(str); + } + + // IPV4 only + F_INLINE bool isValidIPAddress(const QString& str) + { + // [0,255].[0,255].[0,255].[0,255] + static QRegExp rx("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?).){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"); + return rx.exactMatch(str); + } +} + +#endif \ No newline at end of file diff --git a/src/lpBase/iAlgorithm.h b/src/lpBase/iAlgorithm.h new file mode 100644 index 0000000..5e1c739 --- /dev/null +++ b/src/lpBase/iAlgorithm.h @@ -0,0 +1,185 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:tpAlgorithm.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/05/15 + History:15:5:2015 17:51 + *******************************************************************************/ +#ifndef __TP_ALGORITHM_H +#define __TP_ALGORITHM_H + +#include "baseDefine.h" +#include +#include +#include +#include +#include +//#include "baseStruct.h" + +#define ALG_SHARED_GLOBAL_KEY_APP_STATUS "app_status" +#define ALG_SHARED_GLOBAL_KEY_APP_CHECKED "app_checked_status" + +class IAlgorithmShared +{ +public: + enum emAppStatus { + APP_STATUS_DEFAULT = 0, + APP_STATUS_SAMPLING = 1, + }; + IAlgorithmShared() {} + virtual ~IAlgorithmShared() {} + virtual UINT64 ILastUpdateTime() = 0; + virtual QStringList IGetStringList(const QString& key) = 0; + virtual int IGetInt(const QString& key, int nDef = 0) = 0; +}; + + +///////////////////////////////////////////////////////////////////////////////////////////// + +#define ALG_OPTION_GLOBAL_KEY_SAMPLING_OBJECT "sampling_object" +class IAlgorithmOption +{ +public: + IAlgorithmOption() {} + virtual ~IAlgorithmOption() {} + virtual int GetIntValue(const QString& skey, int nDefault) = 0; + virtual void SetIntValue(const QString& skey, int value) = 0; + virtual QString GetStringValue(const QString& skey, const QString& default = "") = 0; + virtual void SetStringValue(const QString& skey, const QString& value) = 0; + virtual bool Save(bool bWait = true) = 0; + virtual QVariantMap VariantMap() = 0; + virtual bool DbSetValue(const QString& key, int type, const QByteArray& data) = 0; + virtual bool DbGetValue(const QString& key, int type, QByteArray& data) = 0; + virtual bool DbDelValue(const QString& key) = 0; + virtual QStringList DbGetKeysByType(int type) = 0; + virtual QVariant GetValue(const QString& skey, const QVariant& def) = 0; + virtual void SetValue(const QString& skey, const QVariant& value) = 0; +}; + +typedef struct tagTP_ALGORITHM_OPTION { + int algorithm; + class IAlgorithmOption* pImagProcCb; +} TP_ALGORITHM_OPTION; +//////////////////////////////////////////////////////////////////////////////////////////// + +enum emTpCameraProperty{ + TP_CAM_PROPERTY_NONE = 0, + TP_CAM_PROPERTY_EXPOSURE = 1, + TP_CAM_PROPERTY_BALANCE_RATIO_RED = 2, + TP_CAM_PROPERTY_BALANCE_RATIO_GREEN = 3, + TP_CAM_PROPERTY_BALANCE_RATIO_BLUE = 4, + TP_CAM_PROPERTY_FOLDER_NAME = 50, + TP_CAM_BITFLOW_BASE = 110, + TP_CAM_BITFLOE_SAVE_CFG = TP_CAM_BITFLOW_BASE, + TP_CAM_BITFLOW_ROW_RATE = TP_CAM_BITFLOW_BASE + 1, + TP_CAM_BITFLOW_COMMAND = TP_CAM_BITFLOW_BASE + 9, + TP_CAM_PROPERTY_FINISH = 0xFFFF +}; +#define TP_MAX_STRING_SIZE 260 +typedef struct tagTP_CAMERA_PROPERTY { + emTpCameraProperty property; + long value; + char szProperty[TP_MAX_STRING_SIZE]; + int nErrorCode;//return by camera +} TP_CAMERA_PROPERTY; + + +class IImageObject +{ +public: + IImageObject() { } + virtual ~IImageObject() { } + + virtual emTpColorFormat IColorFormat() = 0; + //@nOutBytesPerLine: 0 means there is no valid value + virtual BYTE* IImageData(int& nOutW, int& nOutH, int& nOutBitsPerPixel, int& nOutBytesPerLine) = 0; + virtual int IGetId() = 0; + virtual int IGetAlgorithm() = 0; + virtual int IGetFrameNum() = 0; + virtual int IGetTriggerCount() = 0; + virtual void ISetCameroProperty(TP_CAMERA_PROPERTY& property) = 0; + virtual void ISendDataToUI(void* pData) = 0; + ////////////////////////////////////////////////////////// + typedef void(*Comm_Callback_Func)(int cmd, BYTE* pData, int nDataLen, void* pContext); + typedef struct tagDATA_TO_COMM_HEAD { + char* commNames; + int cmd; + Comm_Callback_Func pfCallback; + void* pContext; + tagDATA_TO_COMM_HEAD() { + commNames = NULL; + cmd = 0; + pfCallback = NULL; + pContext = NULL; + } + }DATA_TO_COMM_HEAD; + virtual void IDataToComm(DATA_TO_COMM_HEAD& head, char* pData, int nLen) = 0; + enum emTpDefectType { + TP_DEF_CLEAN, + TP_DEF_RECT_F,//double for float, pData is Left, Top, Width, Height;nDataLen = sizeof(double) * 4; + TP_DEF_LINE_F, + TP_DEF_CIRCLE_F, + TP_DEF_ELLIPSE_F, + TP_DEF_POLYGON_F, + TP_DEF_POLYLINE_I, + }; + virtual void IDrawDefect(const char* szWinName, emTpDefectType defectType, BYTE* pData, int nDataLen) = 0; + virtual void IDrawDefectOrg(emTpDefectType defectType, BYTE* pData, int nDataLen) = 0; + virtual void ISafeDataToUI(void* pData, int nDataLen) = 0; + virtual void ISafeDataToUI(WORD type, void* pData, int nDataLen) = 0; + virtual INT64 IMeterCode() = 0; + virtual const char* IGetImageUtf8String() = 0; + virtual void IDrawImage(QImage& image = QImage(), const char* szWinName = NULL) = 0; + virtual QImage IImage() = 0; + virtual const ZStringA& IDllSuffix() = 0; + virtual void ISetResult(const QString& key, QVariant& val) = 0; + virtual void IAccumulateResult(const QString& key, QVariant& val) = 0; + virtual void IMoveToFolder(const QString& szFolder) = 0; + virtual IAlgorithmShared* IGetShared() = 0; + virtual void IVariantMapToUI(const QVariantMap& vMap) = 0; + virtual const ZStringA& ICameraSerial() = 0; + virtual const QVariant& IVarFromUI() = 0; + virtual quint64 ITimeStamp() = 0; +}; +//pColor is ARGB, eg 0xFF010101 +inline void simple_draw_image_8(IImageObject* pImgObj, uint *pColor, int nNum) { + //pImgObj->IDrawImage(QImage(pBuffer, w, h, QImage::Format_ARGB32).copy()); + QImage image = pImgObj->IImage(); + if (QImage::Format_Indexed8 == image.format() && NULL != pColor) { + QVector corFmt; + for (int i = 0; i < nNum; ++i) { + corFmt.append(pColor[i]); + } + image.setColorTable(corFmt); + } + pImgObj->IDrawImage(image); +} + +class IAlgorithm +{ +public: + IAlgorithm() {} + virtual ~IAlgorithm() {} + + virtual int IImageAnalysis(class IImageObject* pImgObj, TP_ALGORITHM_OPTION* pOpt, class IDetectorEngine* pDE) = 0; +protected: +}; + +//#define _LOAD_ALGORITHM_DLL_STATIC + +#ifdef ALGORITHM_EXPORTS +#define ALGORITHM_API extern "C" __declspec(dllexport) +#else +#ifndef _LOAD_ALGORITHM_DLL_STATIC +#define ALGORITHM_API extern "C" +#else +#define ALGORITHM_API extern "C" __declspec(dllimport) +#endif +#endif + +ALGORITHM_API IAlgorithm* Algorithm_Create(class IDetectorEngine*); +ALGORITHM_API void Algorithm_Delete(IAlgorithm* pAlg); + +#endif \ No newline at end of file diff --git a/src/lpBase/iCoreCtrl.h b/src/lpBase/iCoreCtrl.h new file mode 100644 index 0000000..e3bd826 --- /dev/null +++ b/src/lpBase/iCoreCtrl.h @@ -0,0 +1,244 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:iCoreCtrl.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/23 + History:23:3:2015 15:35 + *******************************************************************************/ +#ifndef __I_CORE_CTRL_H +#define __I_CORE_CTRL_H + +//#include "icamera.h" +#include "baseStruct.h" +#include +#include +//the parameter for the CoreCtrl module +typedef struct tagCORE_CTRL_IN_PARAM +{ + class IGuiCallback* pGuiCb; + TP_GLOBAL_DATA* pGlobalData; + TP_CORE_SETTING* pCoreSetting; +}CORE_CTRL_IN_PARAM; + +/**/ +class IAlgorithmResult +{ +public: + IAlgorithmResult(){} + virtual ~IAlgorithmResult(){} + virtual QVariantMap ToVariantMap() = 0; +}; + +//interface for gui +class ICoreCtrl +{ +public: + ICoreCtrl() {} + virtual ~ICoreCtrl() {} + virtual QList ICameraKeys() = 0; + virtual QList ICameraKeysOrderByIds() = 0; + virtual bool ICameraOption(const QString& strSerial, TP_CAMERA_OPTION& camOpt) = 0; + virtual bool ICameraOptionByKey(const QString& strSerial, TP_CAMERA_OPTION& camOpt) = 0; + virtual QList IEnumAvailableCameras(emTpDeviceType camType) = 0; + virtual void ISetTriggerMode(emTpDeviceTriggerMode triggerMode, long nFrameRate) = 0; + virtual emTpDeviceTriggerMode IGetTriggerMode() = 0; + virtual void IManualTrigger(emTpTriggerDirection direct) = 0; + virtual void ISnapImage(const QStringList& camKeys) = 0; + virtual void ISendSoftTrigger(const QStringList& camKeys) = 0; + virtual void IDrawImage(const QString& sKey, QPainter& painter, QRect& rt) = 0; + virtual QImage IShowImage(const QString& sWinId, int& nFrameNum, QString& szExShow) = 0; + virtual QMap IGetCamShowNames() = 0; + virtual IAlgorithmOption* IGetAlgorithmOption(int nAlgorithm) = 0; + virtual bool ISetCameraOption(const QString& strSerial, const TP_CAMERA_OPTION& camOpt) = 0; + virtual bool IReopenCameraes() = 0; + virtual void ISetVirtualImages(const QString& camera, const QStringList& szImages) = 0; + virtual QImage IOriginImage(const QString& sShowId) = 0; + virtual void ISetCameraProperty(const QString& camera, TP_CAMERA_PROPERTY& property) = 0; + virtual void ISetAlgorithmShared(const QString& key, const QVariant& value) = 0; + virtual void IWriteIo(const TP_IO_OUT_CONTROL& state) = 0; + virtual void ISetResult(const QString& key, QVariant& val) = 0; + + + //operate camera + virtual bool ICreateCamera(const QString& strSerial, int nType) = 0; + virtual bool IOpenCamera(const QString& strSerial) = 0; + virtual bool ICloseCamera(const QString& strSerial) = 0; + virtual bool IStartCamera(const QString& strSerial) = 0; + virtual bool IStopCamera(const QString& strSerial) = 0; + virtual bool IDeleteCamera(const QString& strSerial) = 0; + virtual bool IAddCamera(const QString& strName, const TP_CAMERA_OPTION& camOpt, bool bNew, bool bAutoRun = false) = 0; + + //operate camera window + virtual QList ICamWinKeys() = 0; + virtual bool ICamWinOptionByKey(const QString& strKey, TP_CAMERA_WIN& camwinOpt) = 0; + virtual bool IAddCamWin(const QString& strKey, const TP_CAMERA_WIN& camwinOpt, bool bNew) = 0; + virtual bool IDelCamWin(const QString& strKey) = 0; + + //更新json配置文件 + virtual bool updateCommJson(const QString& sJsonPath) = 0; + virtual bool updateCamJson(const QString& sJsonPath) = 0; + + virtual bool ICamsStartPush() = 0; + virtual bool ICamsPausePush() = 0; + +public://private: //use private when the old main is discarded; + virtual int IInitCore(class IDetectorEngine* pDE = NULL) = 0; + virtual void IFreeCore() = 0; + + virtual void IStartImageProcess() = 0; + virtual void IEndImageProcess() = 0; + + friend class QTpMain; +}; + +//callback interface from gui +class IGuiCallback +{ +public: + IGuiCallback() {} + virtual ~IGuiCallback() {} + virtual void IOnReady() {} + virtual void IUpdateShow(const QString& skey) = 0; + virtual void INewCameraImage(const QVariantMap& vMap) = 0; + virtual void IAddWindows(const QString& sWinName, const QString& sShowId) {}; + virtual void ISendDataToUI(emTpUiDataType dataType, const QString& camKey, void* pData) {}//弃用,用IVariantMapToUI()替代 + virtual void ICameraTrigger(bool bStartOrStop) = 0;//弃用,用ICommInterval()替代 + virtual void IDrawDefectToScene(const QString& szWinName, IImageObject::emTpDefectType defectType, QByteArray& data) = 0; + virtual void ISafeDataToUI(emTpUiDataType dataType, const QString& camKey, const QByteArray& data) = 0; + virtual void IWarning(int nWarningCode, void* data, int nDataLen) = 0; + virtual void ICommInterval(const char* szCom, int nCmd, BYTE* pData, int nDataLen) = 0; + virtual void IAlgorithmResult(const QVariantMap& varMap) = 0; + virtual void IVariantMapToUI(emTpUiDataType dataType, const QString& camKey, const QVariantMap& vMap) = 0; + virtual QVariant IGetVariantById(int id) = 0; + virtual void IIoStatesChanged(int nOldState, int nNewState) = 0; + virtual void ICommAchieved(const char* szCom, int nCmd, BYTE* pData, int nDataLen) = 0; + virtual WORD IGetWorkState() = 0;//心跳包中发送的用来控制是否触发的值,返回0不触发,返回1触发 +}; + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#define TP_SIGNALS \ + Q_SIGNALS:\ + void sgAddWindows(const QString sWinName, const QString sShowId); \ + void sgUpdateShow(const QString skey); \ + void sgNewCameraImage(const QVariantMap& vMap); \ + void sgSendDataToUI(emTpUiDataType dataType, const QString camKey, void* pData); \ + void sgCameraTrigger(bool bStartOrStop); \ + void sgDrawDefectToScene(const QString szWinName, IImageObject::emTpDefectType defectType, QByteArray data); \ + void sgSafeDataToUI(emTpUiDataType dataType, const QString camKey, const QByteArray data); \ + void sgWarning(int nWarningCode, const QByteArray data); \ + void sgCommIntervale(const QString szCom, int nCmd, const QByteArray data); \ + void sgAlgorithmResult(const QVariantMap varMap); \ + void sgVariantMapToUI(emTpUiDataType dataType, const QString camKey, const QVariantMap vMap); \ + void sgIoStatesChanged(int nOldState, int nNewState); \ + void sgCommAchieved(const QString szCom, int nCmd, const QByteArray data);\ + +#define TP_SLOTS \ + public Q_SLOTS: \ + virtual void UpdateShow(const QString skey); \ + virtual void NewCameraImage(const QVariantMap& vMap); \ + virtual void AddWindows(const QString sWinName, const QString sShowId); \ + virtual void SendDataToUI(emTpUiDataType dataType, const QString camKey, void* pData); \ + virtual void CameraTrigger(bool bStartOrStop); \ + virtual void DrawDefectToScene(const QString szWinName, IImageObject::emTpDefectType defectType, QByteArray data); \ + virtual void SafeDataToUI(emTpUiDataType dataType, const QString camKey, const QByteArray data); \ + virtual void Warning(int nWarningCode, const QByteArray data); \ + virtual void CommIntervale(const QString szCom, int nCmd, const QByteArray data); \ + virtual void AlgorithmResult(const QVariantMap varMap); \ + virtual void VariantMapToUI(emTpUiDataType dataType, const QString camKey, const QVariantMap vMap); \ + virtual void IoStatesChanged(int nOldState, int nNewState); \ + virtual void CommAchieved(const QString szCom, int nCmd, const QByteArray data);\ + + +#define TP_CONSTRUCTOR \ + connectSignals(); + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#define TP_CALLBACKS_H \ + virtual void IAddWindows(const QString& sWinName, const QString& sShowId); \ + virtual void IUpdateShow(const QString& skey); \ + virtual void INewCameraImage(const QVariantMap& vMap); \ + virtual void ISendDataToUI(emTpUiDataType dataType, const QString& camKey, void* pData); \ + virtual void ICameraTrigger(bool bStartOrStop); \ + virtual void IDrawDefectToScene(const QString& szWinName, IImageObject::emTpDefectType defectType, QByteArray& data); \ + virtual void ISafeDataToUI(emTpUiDataType dataType, const QString& camKey, const QByteArray& data); \ + virtual void IWarning(int nWarningCode, void* data, int nDataLen); \ + virtual void ICommInterval(const char* szCom, int nCmd, BYTE* pData, int nDataLen); \ + virtual void IAlgorithmResult(const QVariantMap& varMap); \ + virtual void IVariantMapToUI(emTpUiDataType dataType, const QString& camKey, const QVariantMap& vMap); \ + virtual QVariant IGetVariantById(int id); \ + virtual void IIoStatesChanged(int nOldState, int nNewState); \ + virtual void ICommAchieved(const char* szCom, int nCmd, BYTE* pData, int nDataLen); \ + virtual WORD IGetWorkState(); \ + void connectSignals(); +/// +#define TP_CALLBACKS_CPP(cName) \ + void cName##::IUpdateShow(const QString& skey) { \ + emit sgUpdateShow(skey); \ + } \ + void cName##::INewCameraImage(const QVariantMap& vMap) { \ + emit sgNewCameraImage(vMap); \ + } \ + void cName##::IAddWindows(const QString& sWinName, const QString& sShowId) { \ + emit sgAddWindows(sWinName, sShowId); \ + } \ + void cName##::ISendDataToUI(emTpUiDataType dataType, const QString& camKey, void* pData) { \ + emit sgSendDataToUI(dataType, camKey, pData); \ + } \ + void cName##::ICameraTrigger(bool bStartOrStop) { \ + emit sgCameraTrigger(bStartOrStop); \ + } \ + void cName##::IDrawDefectToScene(const QString& szWinName, IImageObject::emTpDefectType defectType, QByteArray& data) { \ + emit sgDrawDefectToScene(szWinName, defectType, data); \ + } \ + void cName##::ISafeDataToUI(emTpUiDataType dataType, const QString& camKey, const QByteArray& data) { \ + emit sgSafeDataToUI(dataType, camKey, data); \ + } \ + void cName##::IWarning(int nWarningCode, void* data, int nDataLen) { \ + emit sgWarning(nWarningCode, QByteArray((char*)data, nDataLen)); \ + }\ + void cName##::ICommInterval(const char* szCom, int nCmd, BYTE* pData, int nDataLen) { \ + emit sgCommIntervale(QString(szCom), nCmd, QByteArray((char*)pData, nDataLen)); \ + } \ + void cName##::IAlgorithmResult(const QVariantMap& varMap) { \ + emit sgAlgorithmResult(varMap); \ + } \ + void cName##::IVariantMapToUI(emTpUiDataType dataType, const QString& camKey, const QVariantMap& vMap) { \ + emit sgVariantMapToUI(dataType, camKey, vMap); \ + } \ + void cName##::IIoStatesChanged(int nOldState, int nNewState) { \ + emit sgIoStatesChanged(nOldState, nNewState); \ + } \ + void cName##::ICommAchieved(const char* szCom, int nCmd, BYTE* pData, int nDataLen) { \ + emit sgCommAchieved(QString(szCom), nCmd, QByteArray((char*)pData, nDataLen)); \ + } \ + QVariant cName##::IGetVariantById(int id) { return QVariant(); } \ + WORD cName##::IGetWorkState() { return 0; } \ + void cName##::connectSignals() { \ + QMetaObject::Connection error = connect(this, SIGNAL(sgAddWindows(const QString, const QString)) \ + , this, SLOT(AddWindows(const QString, const QString))); \ + error = connect(this, SIGNAL(sgUpdateShow(const QString)), this, SLOT(UpdateShow(const QString))); \ + error = connect(this, SIGNAL(sgNewCameraImage(const QVariantMap)), this, SLOT(NewCameraImage(const QVariantMap))); \ + qRegisterMetaType("emTpUiDataType"); \ + error = connect(this, SIGNAL(sgSendDataToUI(emTpUiDataType, const QString, void*)) \ + , this, SLOT(SendDataToUI(emTpUiDataType, const QString, void*))); \ + error = connect(this, SIGNAL(sgCameraTrigger(bool)), this, SLOT(CameraTrigger(bool))); \ + qRegisterMetaType("IImageObject::emTpDefectType"); \ + error = connect(this, SIGNAL(sgDrawDefectToScene(const QString, IImageObject::emTpDefectType, QByteArray)) \ + , this, SLOT(DrawDefectToScene(const QString, IImageObject::emTpDefectType, QByteArray))); \ + error = connect(this, SIGNAL(sgSafeDataToUI(emTpUiDataType, const QString, const QByteArray)) \ + , this, SLOT(SafeDataToUI(emTpUiDataType, const QString, const QByteArray))); \ + error = connect(this, SIGNAL(sgWarning(int, const QByteArray)), this, SLOT(Warning(int, const QByteArray))); \ + error = connect(this, SIGNAL(sgCommIntervale(const QString, int, const QByteArray)) \ + , this, SLOT(CommIntervale(const QString, int, const QByteArray))); \ + error = connect(this, SIGNAL(sgAlgorithmResult(const QVariantMap)),this, SLOT(AlgorithmResult(const QVariantMap))); \ + error = connect(this, SIGNAL(sgVariantMapToUI(emTpUiDataType, const QString, const QVariantMap)) \ + , this, SLOT(VariantMapToUI(emTpUiDataType, const QString, const QVariantMap)));\ + error = connect(this, SIGNAL(sgIoStatesChanged(int, int)), this, SLOT(IoStatesChanged(int, int))); \ + error = connect(this, SIGNAL(sgCommAchieved(const QString, int, const QByteArray)) \ + , this, SLOT(CommAchieved(const QString, int, const QByteArray))); \ + } \ + +#endif \ No newline at end of file diff --git a/src/lpBase/iImgProc.h b/src/lpBase/iImgProc.h new file mode 100644 index 0000000..aca89a7 --- /dev/null +++ b/src/lpBase/iImgProc.h @@ -0,0 +1,46 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:iImgProc.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/26 + History:26:3:2015 17:58 + *******************************************************************************/ +#ifndef __I_IMG_PROC_H_20150326 +#define __I_IMG_PROC_H_20150326 + +#include "baseDefine.h" +#include "baseStruct.h" + +typedef struct tagIMGPROC_IN_PARAM{ + TP_GLOBAL_DATA* pGlobalData; +}IMGPROC_IN_PARAM; + +class IImgProc +{ +public: + IImgProc() {} + virtual ~IImgProc() {} + virtual int IImageProcess(class IImageObject* pImgObj, class IDetectorEngine* pDE = NULL) = 0; + virtual class IAlgorithmOption* IGetAlgorithmOption(int nAlgorithm) = 0; +}; + +// class IImageObject +// { +// public: +// IImageObject() { } +// virtual ~IImageObject() { } +// +// virtual emTpColorFormat IColorFormat() = 0; +// //@nOutBytesPerLine: 0 means there is no valid value +// virtual BYTE* IImageData(int& nOutW, int& nOutH, int& nOutBitsPerPixel, int& nOutBytesPerLine) = 0; +// virtual int IGetId() = 0; +// virtual int IGetAlgorithm() = 0; +// virtual int IGetFrameNum() = 0; +// virtual int IGetTriggerCount() = 0; +// ////////////////////////////////////////////////////////// +// virtual void IAddOverlay() { } +// }; + +#endif \ No newline at end of file diff --git a/src/lpBase/iIoCtrl.h b/src/lpBase/iIoCtrl.h new file mode 100644 index 0000000..36a49e4 --- /dev/null +++ b/src/lpBase/iIoCtrl.h @@ -0,0 +1,63 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:$FILE_BASE$.$FILE_EXT$ + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:$DATE$ + History:$DAY$:$MONTH$:$YEAR$ $HOUR$:$MINUTE$ + *******************************************************************************/ + +#include "zdefines.h" +#include + +enum tpemIoType { + TP_IO_ADLINK = 1, +}; + +class IIoInterface +{ +public: + IIoInterface() {} + virtual ~IIoInterface() {} + virtual int IIint() = 0; + virtual int IFree() = 0; + virtual int IReadI(qint32& state) = 0; + virtual int IReadO(qint32& state) = 0; + virtual int IWriteO(qint32& state) = 0; +}; + +#define TP_IOCTRL_DLL "tpIoCtrl" +class QLoadIoCtrl : public QLibrary +{ +public: + typedef IIoInterface*(*func_io_create)(int); + typedef void(*func_io_delete)(IIoInterface*); + QLoadIoCtrl(const QString& path) +#ifdef _DEBUG + : QLibrary(path + TP_IOCTRL_DLL + "d") +#else + : QLibrary(path + TP_IOCTRL_DLL) +#endif + { + _ioCreate = (func_io_create)resolve("tp_io_create"); + _ioDelete = (func_io_delete)resolve("tp_io_delete"); + } + ~QLoadIoCtrl(){} + + IIoInterface* Create(int type) { + if (NULL == _ioCreate) { + return NULL; + } + return _ioCreate(type); + } + + void Delete(IIoInterface* pio) { + if (NULL != _ioDelete) { + _ioDelete(pio); + } + } +private: + func_io_create _ioCreate; + func_io_delete _ioDelete; +}; \ No newline at end of file diff --git a/src/lpBase/icamera.h b/src/lpBase/icamera.h new file mode 100644 index 0000000..d137774 --- /dev/null +++ b/src/lpBase/icamera.h @@ -0,0 +1,105 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:TpICamera.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/20 + History:20:3:2015 17:12 + *******************************************************************************/ +#ifndef __TP_I_CAMERA_H +#define __TP_I_CAMERA_H + +//#include +#include "baseInclude.h" +#include "ZkCameraImage.h" + +typedef struct tagCAMERA_IN_PARAM { + class ICameraCallback* pCallback; + TP_GLOBAL_DATA* pGlobalData; +}CAMERA_IN_PARAM; + + +class ICameraPool +{ +public: + ICameraPool() {} + virtual ~ICameraPool() {} +public: + // operation for camera.json + virtual QList ICameraKeys() = 0; + virtual QList ICameraKeysOrderByIds() = 0; + virtual bool ICameraOption(const QString& strSerial, TP_CAMERA_OPTION& camOpt) = 0; + virtual bool ICameraOptionByKey(const QString& strSerial, TP_CAMERA_OPTION& camOpt) = 0; + virtual bool ISetCameraOption(const QString& strSerial, const TP_CAMERA_OPTION& camOpt) = 0; + + // try to get available (connected to the computer) by camera type(manufacturer) + virtual QList IEnumAvailableCameras(emTpDeviceType camType) = 0; + + virtual int ICreateCameraes() = 0; + virtual void IDeleteDameraes() = 0; + virtual bool ICreateCamera(const QString&, int nType) = 0; + virtual bool IOpenCamera(const QString& strSerial, bool bReopen = true) = 0; + virtual bool ICloseCamera(const QString& strSerial) = 0; + virtual bool IStartCamera(const QString& strSerial) = 0; + virtual bool IStopCamera(const QString& strSerial) = 0; + virtual bool IDeleteCamera(const QString& strSerial) = 0; + virtual bool IAddCamera(const QString& strName, const TP_CAMERA_OPTION& camOpt, bool bNew, bool bAutoRun = false) = 0; + + virtual int IOpenDevices(bool bReopenAll = true) = 0; + virtual int IOpenDevicesEx(bool bReopenAll = true) = 0; //如果camera.json里面配置了auto_open 值为false,则调用该函数不会打开对应相机 + virtual void ICloseDevices() = 0; + + virtual void IStartDevices() = 0; + virtual void IStopDevices(const QString& sDef = NULL) = 0; + virtual void ISetTriggerMode(emTpDeviceTriggerMode mode, emTpTriggerDirection nDirection = TRIGGER_DIRECT_FOREWARD, long nFrameRate = 0) = 0; + virtual emTpDeviceTriggerMode IGetTriggerMode() = 0; + virtual void IManualTrigger( emTpTriggerDirection nDirection = TRIGGER_DIRECT_FOREWARD) = 0; + virtual void ISnapImage(const QStringList& camKeys) = 0; + virtual void ISendSoftTrigger(const QStringList& camKeys) = 0; + virtual CZkCameraImage* IPopCameraImage() = 0; + virtual void IFreeCameraImage(CZkCameraImage *pCamImg) = 0; + //@camera: NULL means setting every camera + virtual void ISetCameraProperty(const QString& camera, emTpCameraProperty property, long nValue) = 0; + virtual void ISetCameraProperty(const QString& camera, TP_CAMERA_PROPERTY& property) = 0; + virtual QList ICameraWins() = 0; + virtual QMap IGetCamShowNames() = 0; + virtual void ISetCameraEncode(INT64 code, INT64 rate) = 0; + virtual void ISetVirtualImages(const QString& camera, const QStringList& szImages) = 0; + + //operate camera window + virtual QList ICamWinKeys() = 0; + virtual bool ICamWinOptionByKey(const QString& strKey, TP_CAMERA_WIN& camwinOpt) = 0; + virtual bool IAddCamWin(const QString& strKey, const TP_CAMERA_WIN& camwinOpt, bool bNew) = 0; + virtual bool IDelCamWin(const QString& strKey) = 0; + + virtual bool ICamsStartPush() = 0; + virtual bool ICamsPausePush() = 0; +}; + +// class ICamera +// { +// public: +// ICamera() {} +// virtual ~ICamera() {} +// public: +// int m_nCameraCode; +// }; + +class ICameraCallback +{ +public: + ICameraCallback() {} + virtual ~ICameraCallback() {} + virtual QVariant IGetVariantById(int nId) = 0; + virtual void INewCameraImage(const QVariantMap& vmap) = 0; +}; + +// class CTpICamera +// { +// public: +// CTpICamera(void); +// virtual ~CTpICamera(void); +// }; + +#endif \ No newline at end of file diff --git a/src/lpBase/lpalgorithm.h b/src/lpBase/lpalgorithm.h new file mode 100644 index 0000000..bd549ec --- /dev/null +++ b/src/lpBase/lpalgorithm.h @@ -0,0 +1,50 @@ +#ifndef LPALGORITHM_H +#define LPALGORITHM_H + +#include "lpbengine.h" + +class IAlgo +{ +public: + IAlgo(){} + virtual ~IAlgo(){} + virtual bool RegisterFunc(IAlgorithmLib* pAlgoLib) { return true; }; + virtual bool Exec(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm) = 0; + virtual bool Init(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm) = 0; + virtual void SaveUserParamValue(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm, QString& strParamName) {}; + virtual void LoadUserParamValue(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm, QString& strParamName, QVariant& value) {}; + virtual bool HandleEvent(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm, QString& strParaName, int event) { return true; }; +}; + + +#define REGISTER_FUNCTION_IMPLEMENT(NAME, FUNC) \ + if (NULL != pAlgoLib) { \ + if (!pAlgoLib->RegisterFunc(#NAME, FUNC)) \ + return false; \ + } + +#define DEFINE_FUNCTION_PARAM_IMPLEMENT(FUNCNAME, PARAMNAME, TYPE, INITVAL, DIR) \ + if (NULL != pAlgoLib) { \ + LP_ALGORITHM_PARAM_DESC desc; \ + desc.strName = PARAMNAME; \ + desc.type = TYPE; \ + desc.InitVal = INITVAL; \ + desc.dir = DIR; \ + if (!pAlgoLib->DefFuncParam(#FUNCNAME, desc)) \ + return false; \ + } + +#ifdef ALGO_LIB +# define ALGO_EXPORT extern "C" __declspec(dllexport) +#else +# define ALGO_EXPORT extern "C" __declspec(dllimport) +#endif + +typedef void(*FnLpAlgoNewInstance)(IAlgo** lppAlgo); + +ALGO_EXPORT void LpAlgoNewInstance(IAlgo** lppAlgo); + +ALGO_EXPORT bool LpAlgoDeleteInstance(); + + +#endif // LPALGORITHM_H diff --git a/src/lpBase/lpbMetaTypeDefine.h b/src/lpBase/lpbMetaTypeDefine.h new file mode 100644 index 0000000..04b4c9a --- /dev/null +++ b/src/lpBase/lpbMetaTypeDefine.h @@ -0,0 +1,389 @@ +#ifndef __LPENGINE_METATYPE_DEFINE_H +#define __LPENGINE_METATYPE_DEFINE_H + +#ifndef LPENGINE_SMART_CAMERA +#include "lpbengine.h" +#else +#include "lpbdefine.h" +#endif + +namespace LpEngine +{ + void task_out_param_save(QDataStream & ds, const void * p) + { + LP_DETECTOR_ALGO_OUT_DATA* d = (LP_DETECTOR_ALGO_OUT_DATA*)p; + if (d) + { + ds << d->size(); + for (int i = 0; i < d->size(); i++) + { + LP_DETECTOR_TASK_OUT_PARAM param = d->at(i); + ds << param.name; + ds << param.type; + ds << param.value; + } + } + } + + void task_out_param_load(QDataStream & ds, void * p) + { + int nCount = 0; + ds >> nCount; + + LP_DETECTOR_ALGO_OUT_DATA* d = (LP_DETECTOR_ALGO_OUT_DATA*)p; + if (d) + { + for (int i = 0; i < nCount; i++) + { + LP_DETECTOR_TASK_OUT_PARAM param; + ds >> param.name; + int type = 0; + ds >> type; + param.type = (AlgoParamType)type; + ds >> param.value; + + d->append(param); + } + } + } + + void double_list_save(QDataStream & ds, const void * p) + { + Double_List* d = (Double_List*)p; + if (d) + { + ds << d->size(); + for (int i = 0; i < d->size(); i++) + { + ds << d->at(i); + } + } + } + + void double_list_load(QDataStream & ds, void * p) + { + int nCount = 0; + ds >> nCount; + + Double_List* d = (Double_List*)p; + if (d) + { + for (int i = 0; i < nCount; i++) + { + double dVal; + ds >> dVal; + + d->append(dVal); + } + } + } + + void linef_list_save(QDataStream & ds, const void * p) + { + LineF_List* d = (LineF_List*)p; + if (d) + { + ds << d->size(); + for (int i = 0; i < d->size(); i++) + { + ds << d->at(i); + } + } + } + + void linef_list_load(QDataStream & ds, void * p) + { + int nCount = 0; + ds >> nCount; + + LineF_List* d = (LineF_List*)p; + if (d) + { + for (int i = 0; i < nCount; i++) + { + QLineF dVal; + ds >> dVal; + + d->append(dVal); + } + } + } + + void line_list_save(QDataStream & ds, const void * p) + { + Line_List* d = (Line_List*)p; + if (d) + { + ds << d->size(); + for (int i = 0; i < d->size(); i++) + { + ds << d->at(i); + } + } + } + + void line_list_load(QDataStream & ds, void * p) + { + int nCount = 0; + ds >> nCount; + + Line_List* d = (Line_List*)p; + if (d) + { + for (int i = 0; i < nCount; i++) + { + QLine dVal; + ds >> dVal; + + d->append(dVal); + } + } + } + + void cv_mat_save(QDataStream & ds, const void * p) + { + cv::Mat* d = (cv::Mat*)p; + if (d) + { + int rows = d->rows; + int cols = d->cols; + int type = d->type(); + int step = d->step; + + ds << (int)rows; + ds << (int)cols; + ds << (int)type; + ds << (int)step; + ds.writeRawData((const char*)d->data, step*rows); + } + } + + void cv_mat_load(QDataStream & ds, void * p) + { + cv::Mat* d = (cv::Mat*)p; + if (d) + { + int rows, cols, type; + int step; + ds >> rows; + ds >> cols; + ds >> type; + ds >> step; + if (rows > 0 && step > 0) + { + uchar* pdata = new uchar[rows * step]; + ds.readRawData((char*)pdata, rows * step); + *d = cv::Mat(rows, cols, type, (void*)pdata, step); + } + } + } + + void point_list_save(QDataStream & ds, const void * p) + { + Point_List* d = (Point_List*)p; + if (d) + { + ds << d->size(); + for (int i = 0; i < d->size(); i++) + { + ds << d->at(i); + } + } + } + + void point_list_load(QDataStream & ds, void * p) + { + int nCount = 0; + ds >> nCount; + + Point_List* d = (Point_List*)p; + if (d) + { + for (int i = 0; i < nCount; i++) + { + QPoint dVal; + ds >> dVal; + + d->append(dVal); + } + } + } + + void pointf_list_save(QDataStream & ds, const void * p) + { + PointF_List* d = (PointF_List*)p; + if (d) + { + ds << d->size(); + for (int i = 0; i < d->size(); i++) + { + ds << d->at(i); + } + } + } + + void pointf_list_load(QDataStream & ds, void * p) + { + int nCount = 0; + ds >> nCount; + + PointF_List* d = (PointF_List*)p; + if (d) + { + for (int i = 0; i < nCount; i++) + { + QPointF dVal; + ds >> dVal; + + d->append(dVal); + } + } + } + + void ploygon_list_save(QDataStream & ds, const void * p) + { + Ploygon_List* d = (Ploygon_List*)p; + if (d) + { + ds << d->size(); + for (int i = 0; i < d->size(); i++) + { + ds << d->at(i); + } + } + } + + void ploygon_list_load(QDataStream & ds, void * p) + { + int nCount = 0; + ds >> nCount; + + Ploygon_List* d = (Ploygon_List*)p; + if (d) + { + for (int i = 0; i < nCount; i++) + { + QPolygon dVal; + ds >> dVal; + + d->append(dVal); + } + } + } + + void ploygonf_list_save(QDataStream & ds, const void * p) + { + PloygonF_List* d = (PloygonF_List*)p; + if (d) + { + ds << d->size(); + for (int i = 0; i < d->size(); i++) + { + ds << d->at(i); + } + } + } + + void ploygonf_list_load(QDataStream & ds, void * p) + { + int nCount = 0; + ds >> nCount; + + PloygonF_List* d = (PloygonF_List*)p; + if (d) + { + for (int i = 0; i < nCount; i++) + { + QPolygonF dVal; + ds >> dVal; + + d->append(dVal); + } + } + } + + void mat_polygonf_save(QDataStream & ds, const void * p) + { + MatEx* d = (MatEx*)p; + if (d) + { + QVariant var; + var.setValue(d->first); + ds << var; + ds << d->second; + } + } + + void mat_polygonf_load(QDataStream & ds, void * p) + { + MatEx* d = (MatEx*)p; + if (d) + { + QVariant var; + ds >> var; + d->first = var.value(); + ds >> d->second; + } + } + + void algo_exec_result_save(QDataStream & ds, const void * p) + { + AlgoExecResult* d = (AlgoExecResult*)p; + if (d) + { + ds << d->code; + ds << d->errMsg; + } + } + + void algo_exec_result_load(QDataStream & ds, void * p) + { + + AlgoExecResult* d = (AlgoExecResult*)p; + if (d) + { + ds >> d->code; + ds >> d->errMsg; + + } + } + + void initUserTypeDefine() + { + qRegisterMetaType("task_out_param"); + QMetaType::registerStreamOperators("task_out_param", task_out_param_save, task_out_param_load); + + qRegisterMetaType("double_list"); + QMetaType::registerStreamOperators("double_list", double_list_save, double_list_load); + + qRegisterMetaType("linef_list"); + QMetaType::registerStreamOperators("linef_list", linef_list_save, linef_list_load); + + qRegisterMetaType("line_list"); + QMetaType::registerStreamOperators("line_list", line_list_save, line_list_load); + + qRegisterMetaType("cv_mat"); + QMetaType::registerStreamOperators("cv_mat", cv_mat_save, cv_mat_load); + + qRegisterMetaType("ploygon_list"); + QMetaType::registerStreamOperators("ploygon_list", ploygon_list_save, ploygon_list_load); + + qRegisterMetaType("ploygonf_list"); + QMetaType::registerStreamOperators("ploygonf_list", ploygonf_list_save, ploygonf_list_load); + + qRegisterMetaType("point_list"); + QMetaType::registerStreamOperators("point_list", point_list_save, point_list_load); + + qRegisterMetaType("pointf_list"); + QMetaType::registerStreamOperators("pointf_list", pointf_list_save, pointf_list_load); + + qRegisterMetaType("mat_polygonf"); + QMetaType::registerStreamOperators("mat_polygonf", mat_polygonf_save, mat_polygonf_load); + + qRegisterMetaType("algo_exec_result"); + QMetaType::registerStreamOperators("algo_exec_result", algo_exec_result_save, algo_exec_result_load); + } +} + + +#endif // __LPENGINE_METATYPE_DEFINE_H \ No newline at end of file diff --git a/src/lpBase/lpbdefine.h b/src/lpBase/lpbdefine.h new file mode 100644 index 0000000..8283de0 --- /dev/null +++ b/src/lpBase/lpbdefine.h @@ -0,0 +1,184 @@ +#ifndef LPBDEFINE_H +#define LPBDEFINE_H + +#include "cv.h" +#include "highgui.h" +#include +#include +#include "QJsonDocument" +#include "QJsonArray" +#include "QJsonObject" +#include +#include + +#ifndef BYTE +typedef unsigned char BYTE; +#endif +#ifndef WORD +typedef unsigned short WORD; +#endif +#ifndef DWORD +typedef unsigned long DWORD; +#endif +//#ifndef size_t +//typedef unsigned int size_t; +//#endif +#ifndef LPWORD +typedef WORD *LPWORD; +#endif +#ifndef LPDWORD +typedef DWORD *LPDWORD; +#endif + +#define BASE_MAX_FOLDER_NAME_SIZE 64 +#define BASE_MAX_FILE_NAME_SIZE 64 + + +#define LP_DETECTOR_BUSSINESS_CONFIG_DIR "./config/" +#define LP_DETECTOR_BUSSINESS_IMAGE_DIR "./images/" +#define LP_DETECTOR_BUSSINESS_IN_PARAM_FILE_DIR "./paramfiles/" +#define LP_DETECTOR_BUSSINESS_CONFIG_SOLUTIONMGR_FILE "./config/solutionmgr.json" +#define LP_DETECTOR_BUSSINESS_CONFIG_DEVICEMGR_FILE "./config/devicemgr.json" +#define LP_DETECTOR_BUSSINESS_DB "info.db" +#define LP_DETECTOR_BUSSINESS_CONFIG_FILE_NAME "systemInfo.ini" +#define LP_DETECTOR_BUSSINESS_CONFIG_SOLUTIONMGR_INFO_FILE "./solutions/info.json" +#define LP_DETECTOR_BUSSINESS_CONFIG_SOLUTION_DIR "./solutions/" +#define LP_DETECTOR_BUSSINESS_CONFIG_ALGO_DIR "./algorithmLib/" +#define LP_DETECTOR_BUSSINESS_CONFIG_PARAMSHARE_FILE "./config/paramshare.json" + + + + +#define LP_DETECTOR_INVALID_ID 0xffffffff + +#define LP_DETECTOR_ALGO_PARAM_INPUT_ROI "roi" +#define LP_DETECTOR_ALGO_PARAM_RELY_COORDINATE "rely_coordinate" +#define LP_DETECTOR_ALGO_PARAM_RELATIVE_ROI "relative_roi" + +const DWORD LP_DETECTOR_DEVICE_SERIALPORT_BASE = 0x0210FFFF; + +namespace EngineBase +{ + static cv::Mat QImage2cvMat(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_Indexed8: + mat = cv::Mat(image.height(), image.width(), CV_8UC1, (void*)image.constBits(), image.bytesPerLine()); + break; + } + return mat; + } + + static QImage convMat2QImage(cv::Mat & mat) + { + //qDebug() << "ERROR: Mat could not be converted to QImage."; + // 8-bits unsigned, NO. OF CHANNELS = 1 + if (mat.type() == CV_8UC1) + { + QImage image(mat.cols, mat.rows, QImage::Format_Indexed8); + // Set the color table (used to translate colour indexes to qRgb values) + image.setColorCount(256); + for (int i = 0; i < 256; i++) + { + image.setColor(i, qRgb(i, i, i)); + } + // Copy input Mat + 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; + } + // 8-bits unsigned, NO. OF CHANNELS = 3 + else if (mat.type() == CV_8UC3) + { + // Copy input Mat + const uchar *pSrc = (const uchar*)mat.data; + // Create QImage with same dimensions as input Mat + QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_RGB888); + + return image.rgbSwapped(); + } + else if (mat.type() == CV_8UC4) + { + qDebug() << "CV_8UC4"; + // Copy input Mat + const uchar *pSrc = (const uchar*)mat.data; + // Create QImage with same dimensions as input Mat + 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 bool DeleteDir(const QString &dirName) + { + if (dirName.isEmpty()) + { + return false; + } + + QDir dir(dirName); + if (!dir.exists()) + { + return true; + } + + QString srcPath = QDir::toNativeSeparators(dirName); + if (!srcPath.endsWith(QDir::separator())) + srcPath += QDir::separator(); + + + QStringList fileNames = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden); + bool error = false; + for (QStringList::size_type i = 0; i != fileNames.size(); ++i) + { + QString filePath = srcPath + fileNames.at(i); + QFileInfo fileInfo(filePath); + if (fileInfo.isFile() || fileInfo.isSymLink()) + { + QFile::setPermissions(filePath, QFile::WriteOwner); + if (!QFile::remove(filePath)) + { + error = true; + } + } + else if (fileInfo.isDir()) + { + if (!DeleteDir(filePath)) + { + error = true; + } + } + } + + if (!dir.rmdir(QDir::toNativeSeparators(dir.path()))) + { + qWarning() << "remove dir" << dir.path() << " faild!"; + error = true; + } + + return !error; + } +} + +#endif // LPBDEFINE_H \ No newline at end of file diff --git a/src/lpBase/lpbengine.h b/src/lpBase/lpbengine.h new file mode 100644 index 0000000..e64942d Binary files /dev/null and b/src/lpBase/lpbengine.h differ diff --git a/src/lpBase/lpdesigner.h b/src/lpBase/lpdesigner.h new file mode 100644 index 0000000..f445d97 --- /dev/null +++ b/src/lpBase/lpdesigner.h @@ -0,0 +1,41 @@ +#ifndef LPDESIGNER_H +#define LPDESIGNER_H + +#include "lpdsgdefine.h" +#include "SystemStateInfo.h" +#include +//#include "vld.h" +class IDetectorEngine; +class IDetectorTask; + +class IDetectorUISink +{ +public: + virtual void OnManualTrigger() = 0; + virtual void ResetItem(QPoint pos, QRect size) = 0; + virtual void OnSetParam(IDetectorTask* pTask) = 0; +}; + +class IDetectorUI +{ +public: + virtual bool ShowDeviceMgrDlg() = 0; + virtual bool ShowSolutionMgrDlg() = 0; + virtual bool ShowMainFrame() = 0; + virtual bool ShowReportView(QMap statInfo) = 0; +}; + + +#ifdef LPDESIGNER_LIB +# define LPDESIGNER_EXPORT extern "C" __declspec(dllexport) +#else +# define LPDESIGNER_EXPORT extern "C" __declspec(dllimport) +#endif + +typedef void(*FnLpDesignerNewInstance)(IDetectorUI **lppDetectorUI, IDetectorEngine *lpDE, IDetectorUISink* lpSink); + +LPDESIGNER_EXPORT void LpDesignerNewInstance(IDetectorUI **lppDetectorUI, IDetectorEngine *lpDE, IDetectorUISink* lpSink); + +LPDESIGNER_EXPORT bool LpDesignerDeleteInstance(); + +#endif // LPDESIGNER_H diff --git a/src/lpBase/lpdsgdefine.h b/src/lpBase/lpdsgdefine.h new file mode 100644 index 0000000..ddddf29 --- /dev/null +++ b/src/lpBase/lpdsgdefine.h @@ -0,0 +1,9 @@ +#ifndef LPDSGDEFINE_H +#define LPDSGDEFINE_H + + +#define LP_DETECTOR_DSG_TASK_ITEM_LOAD "Load" +#define LP_DETECTOR_UI_CONFIG_FILE_NAME "set.ini" +#define LP_DETECTOR_UI_REPORT_FOLDER "./report/" + +#endif // LPDSGDEFINE_H \ No newline at end of file diff --git a/src/lpBase/sysInclude.h b/src/lpBase/sysInclude.h new file mode 100644 index 0000000..da7ce4c --- /dev/null +++ b/src/lpBase/sysInclude.h @@ -0,0 +1,26 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:sysInclude.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/08 + History:8:4:2015 13:36 + *******************************************************************************/ +#ifndef __SYS_INCLUDE_H_20150408 +#define __SYS_INCLUDE_H_20150408 + +#ifdef QT_CORE_LIB +#include +#include +#include +#include +#include +#include +#endif + +#if defined(Q_OS_WIN) || defined(WIN32) || defined(WIN64) +#include +#endif + +#endif \ No newline at end of file diff --git a/src/lpCoreCtrl/AlgorithmResult.cpp b/src/lpCoreCtrl/AlgorithmResult.cpp new file mode 100644 index 0000000..580b455 --- /dev/null +++ b/src/lpCoreCtrl/AlgorithmResult.cpp @@ -0,0 +1,48 @@ +#include "AlgorithmResult.h" + +CAlgorithmResult::CAlgorithmResult() +{ + +} + +CAlgorithmResult::~CAlgorithmResult() +{ + +} + +QVariantMap CAlgorithmResult::ToVariantMap() +{ + QReadLocker locker(&m_lock); + return m_json.toVariantMap(); +} + +void CAlgorithmResult::SetResult(const QString& key, QVariant& val) +{ + QWriteLocker locker(&m_lock); + m_json.insert(key, QJsonValue::fromVariant(val)); +} +bool CAlgorithmResult::AccumulateResult(const QString& key, QVariant& val) +{ + QWriteLocker locker(&m_lock); + QJsonValue jval = m_json.value(key); + if (jval.isUndefined()) + { + m_json.insert(key, QJsonValue::fromVariant(val)); + } + else + { + if (!jval.isDouble()) + { + return false; + } + bool bOk; + double fv = val.toDouble(&bOk); + if (!bOk) + { + return false; + } + fv += jval.toDouble(); + m_json.insert(key, fv); + } + return true; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/AlgorithmResult.h b/src/lpCoreCtrl/AlgorithmResult.h new file mode 100644 index 0000000..ea4c86c --- /dev/null +++ b/src/lpCoreCtrl/AlgorithmResult.h @@ -0,0 +1,22 @@ +#ifndef CALGORITHMRESULT_H +#define CALGORITHMRESULT_H + +#include "iCoreCtrl.h" +#include +#include + +class CAlgorithmResult : public IAlgorithmResult +{ +public: + CAlgorithmResult(); + virtual ~CAlgorithmResult(); + virtual QVariantMap ToVariantMap(); + void SetResult(const QString& key, QVariant& val); + bool AccumulateResult(const QString& key, QVariant& val); +private: + QJsonObject m_json; + QReadWriteLock m_lock; + //friend class CImageObject; +}; + +#endif // CALGORITHMRESULT_H diff --git a/src/lpCoreCtrl/AlgorithmShared.cpp b/src/lpCoreCtrl/AlgorithmShared.cpp new file mode 100644 index 0000000..4c0b1dd --- /dev/null +++ b/src/lpCoreCtrl/AlgorithmShared.cpp @@ -0,0 +1,45 @@ +#include "AlgorithmShared.h" + +CAlgorithmShared::CAlgorithmShared() + : m_stamp(0) +{ + SetValue(ALG_SHARED_GLOBAL_KEY_APP_STATUS, APP_STATUS_DEFAULT); +} + +CAlgorithmShared::~CAlgorithmShared() +{ + +} + +void CAlgorithmShared::SetValue(const QString& key, const QVariant& value) +{ + m_values.insert(key, value); + updateStamp(); +} + +QStringList CAlgorithmShared::IGetStringList(const QString& key) +{ + if (!m_values.contains(key)) + { + return QStringList(); + } + return m_values[key].toStringList(); +} + +int CAlgorithmShared::IGetInt(const QString& key, int nDef/* = 0*/) +{ + if (!m_values.contains(key)) + { + return nDef; + } + bool bOk; + int nRet = m_values[key].toInt(&bOk); + if (bOk) + { + return nRet; + } + else + { + return nDef; + } +} \ No newline at end of file diff --git a/src/lpCoreCtrl/AlgorithmShared.h b/src/lpCoreCtrl/AlgorithmShared.h new file mode 100644 index 0000000..eac4458 --- /dev/null +++ b/src/lpCoreCtrl/AlgorithmShared.h @@ -0,0 +1,29 @@ +#ifndef ALGORITHMSHARED_H +#define ALGORITHMSHARED_H + +#include "iAlgorithm.h" +#include +#include + +class CAlgorithmShared : public IAlgorithmShared +{ +public: + CAlgorithmShared(); + ~CAlgorithmShared(); + virtual UINT64 ILastUpdateTime() { + return m_stamp; + } + virtual QStringList IGetStringList(const QString& key); + virtual int IGetInt(const QString& key, int nDef = 0); + + void SetValue(const QString& key, const QVariant& value); +private: + void updateStamp() { + m_stamp = QDateTime::currentDateTime().toTime_t(); + } +private: + QVariantMap m_values; + uint m_stamp; +}; + +#endif // ALGORITHMSHARED_H diff --git a/src/lpCoreCtrl/CoreCtrl.cpp b/src/lpCoreCtrl/CoreCtrl.cpp new file mode 100644 index 0000000..c5ff44e --- /dev/null +++ b/src/lpCoreCtrl/CoreCtrl.cpp @@ -0,0 +1,479 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:CoreCtrl.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/24 + History:24:3:2015 17:22 + *******************************************************************************/ +#include "CoreCtrl.h" +#include "globalCoreCtrl.h" +#include "baseFunction.h" +#include "QZkJsonParser.h" +#include +#include + +CCoreCtrl::CCoreCtrl(void) +{ + +} + +CCoreCtrl::~CCoreCtrl(void) +{ + IFreeCore(); +} + +int CCoreCtrl::IInitCore(class IDetectorEngine* pDE /*= NULL*/) +{ + int nRet = 0; + nRet = createShowWindows();//根据camera.json中的"windows"创建显示窗口内存, + //create threads + int nCount = gCoreSetting.threadsCount; + if (nCount <= 0) + { + nCount = SYS_F::GetCpus();//获取系统cpu线程数量 + } + /*创建图片处理线程*/ + for (int i = 0; i < nCount; ++i) + { + QTpThreadImage *pThd = new QTpThreadImage(this, pDE); + if( NULL == pThd ) + { + break; + } + +// pThd->StartThread(); +// pThd->setPriority(QThread::TimeCriticalPriority); + m_imgThdPool.append(pThd); + ++nRet; + } + + // + IStartImageProcess(); + //create cameraes... + glpCameralPool->ICreateCameraes();//更加camera.json 创建相机对象 + glpCameralPool->IOpenDevicesEx();//打开相机 + glpCameralPool->ISetTriggerMode(DEV_TRIGGER_MODE_OUT);//设置默认的触发模式 + glpCameralPool->IStartDevices();//设置相机开始工作 + return nRet; +} + +void CCoreCtrl::IFreeCore() +{ + glpCameralPool->IStopDevices();//设置相机停止工作 + glpCameralPool->ICloseDevices();//关闭相机 + glpCameralPool->IDeleteDameraes();//删除相机 + //删除图片处理线程 + while( !m_imgThdPool.isEmpty() ) + { + QTpThreadImage* pThd = m_imgThdPool.takeLast(); + pThd->EndThread(); + delete pThd; + } + //m_showImages.clear(releaseShowImage); + m_showWindows.clear(releaseShowWindow);//删除用用图像显示窗口内存 + + // 这里等待所有线程完成工作,虽然用clear也可以, + // 但是程序在退出的时候会跳出来错误。不够友好 + QThreadPool::globalInstance()->waitForDone(); + //QThreadPool::globalInstance()->clear(); +} + +void CCoreCtrl::IStartImageProcess() +{ + for (int i = 0; i < m_imgThdPool.size(); i++) + { + m_imgThdPool.at(i)->StartThread(); + m_imgThdPool.at(i)->setPriority(QThread::TimeCriticalPriority); + } +} + +void CCoreCtrl::IEndImageProcess() +{ + for (int i = 0; i < m_imgThdPool.size(); i++) + { + m_imgThdPool.at(i)->EndThread(); + } +} + +//void CCoreCtrl::releaseShowImage(const QString& k, QZkShowImage*& v, void* pData) +//{ +// delete v; +//} + +bool CCoreCtrl::ShowCameraImage(const ZStringA& serial, UINT nFrameNum, QImage& image, INT64 nStamp, int nIndex/* = 0*/, const QString& szExtend /*= NULL*/) +{ + QVariantMap map; + map.clear(); + map.insert("camera", serial); + map.insert("frame", nFrameNum); + QVariant vimg; + vimg.setValue(image); + map.insert("image", vimg); + glpGuiCallback->INewCameraImage(map); + + QString sWinId = serial + "_" + QString::number(nIndex); + CShowWindow* pWin = m_showWindows.value(sWinId, NULL); + if (NULL != pWin && pWin->AddCameraImage(image, nFrameNum, nStamp, szExtend)/*pWin->SetCameraImage(pCamImage)*/) + { + glpGuiCallback->IUpdateShow(pWin->CameraWin().key); + return true; + } + else + { + return false; + } +} + +void CCoreCtrl::DrawDefectOrg(IImageObject::emTpDefectType defectType, BYTE* pData, int nDataLen, CZkCameraImage* pCamImage) +{ + QString sWinId = QString::fromUtf8(pCamImage->Serial()) + "_" + QString::number(0); + CShowWindow* pWin = m_showWindows.value(sWinId, NULL); + if (NULL != pWin && pWin->DrawDefect(defectType, pData, nDataLen, pCamImage)) + { + glpGuiCallback->IUpdateShow(pWin->CameraWin().key); + } +} + +void CCoreCtrl::DrawImageOrg(QImage& srcImg, CZkCameraImage* pCamImage) +{ + if (!ShowCameraImage(pCamImage->Serial(), pCamImage->FrameNumber(), srcImg, pCamImage->Stamp(), 1, QString::fromUtf8(pCamImage->FileName()))) + { + QString sWinId = QString::fromUtf8(pCamImage->Serial()) + "_" + QString::number(0); + CShowWindow* pWin = m_showWindows.value(sWinId, NULL); + if (NULL != pWin && pWin->DrawImage(srcImg, pCamImage->FrameNumber(), QString::fromUtf8(pCamImage->FileName()))) + { + glpGuiCallback->IUpdateShow(pWin->CameraWin().key); + } + } +} + +void CCoreCtrl::ISetResult(const QString& key, QVariant& val) +{ + m_algResult.SetResult(key, val); + //callback to ui + glpGuiCallback->IAlgorithmResult(m_algResult.ToVariantMap()); +} + +void CCoreCtrl::AccumulateResult(const QString& key, QVariant& val) +{ + if (m_algResult.AccumulateResult(key, val)) + { + glpGuiCallback->IAlgorithmResult(m_algResult.ToVariantMap()); + } +} + +/* +void CCoreCtrl::setShowWindow(CShowWindow*& pWin, void* pData) +{ + ; +} +*/ + +//void CCoreCtrl::setShowImage(const QString& k, QZkShowImage*& v, void* pData) +//{ +// v->SetShowImage((CZkCameraImage*)pData); +//} + +QList CCoreCtrl::ICameraKeys() +{ + return glpCameralPool->ICameraKeys(); +} + +QList CCoreCtrl::ICameraKeysOrderByIds() +{ + return glpCameralPool->ICameraKeysOrderByIds(); +} + +bool CCoreCtrl::ICameraOption(const QString& strSerial, TP_CAMERA_OPTION& camOpt) +{ + return glpCameralPool->ICameraOption(strSerial, camOpt); +} + +bool CCoreCtrl::ICameraOptionByKey(const QString& strSerial, TP_CAMERA_OPTION& camOpt) +{ + return glpCameralPool->ICameraOptionByKey(strSerial, camOpt); +} + +QList CCoreCtrl::IEnumAvailableCameras(emTpDeviceType camType) +{ + return glpCameralPool->IEnumAvailableCameras(camType); +} + +void CCoreCtrl::ISetTriggerMode(emTpDeviceTriggerMode triggerMode, long nFrameRate) +{ + glpCameralPool->ISetTriggerMode(triggerMode, TRIGGER_DIRECT_FOREWARD, nFrameRate); +} + +void CCoreCtrl::IManualTrigger(emTpTriggerDirection direct) +{ + glpCameralPool->IManualTrigger(direct); +} + +void CCoreCtrl::ISnapImage(const QStringList& camKeys) +{ + glpCameralPool->ISnapImage(camKeys); +} + +void CCoreCtrl::ISendSoftTrigger(const QStringList& camKeys) +{ + glpCameralPool->ISendSoftTrigger(camKeys); +} + +void CCoreCtrl::IDrawImage(const QString& sKey, QPainter& painter, QRect& rt) +{ + /* + tagDrawShowImageParam param; + param.painter = &painter; + param.rt = &rt; + m_showImages.valueCall(sKey, drawShowImage, ¶m);*/ +} + +//void CCoreCtrl::drawShowImage(const QString& key, QZkShowImage*& v, void* pData) +//{ +// tagDrawShowImageParam* param = (tagDrawShowImageParam*)pData; +// v->DrawToPainter(param->painter, param->rt); +//// param->painter->drawPixmap() +//} + +int CCoreCtrl::createShowWindows() +{ + int nCount = 0; +// QList camWins = glpCameralPool->ICameraWins(); +// for (int i = 0; i < camWins.size(); ++i) +// { +// CShowWindow* pShow = new CShowWindow(camWins[i]); +// if (NULL == pShow) +// { +// continue; +// } +// if (m_showWindows.contains(pShow->WindowId())) +// { +// delete pShow; +// continue; +// } +// m_showWindows.insert(pShow->WindowId(), pShow); +// gGuiCallback_FuncCall(IAddWindows, camWins[i]->key, pShow->WindowId()); +// ++nCount; +// } + return nCount; +} + +void CCoreCtrl::releaseShowWindow(CShowWindow*& pWin, void* pData) +{ + delete pWin; + pWin = NULL; +} + +bool CCoreCtrl::IAddCamWin(const QString& strKey, const TP_CAMERA_WIN& camwinOpt, bool bNew) +{ + if (glpCameralPool->IAddCamWin(strKey, camwinOpt, bNew)) + { + if (bNew){ + QList camWins = glpCameralPool->ICameraWins(); + for (int i = 0; i < camWins.size(); ++i) + { + if (camWins[i]->key.compare(strKey, Qt::CaseInsensitive) == 0){ + CShowWindow* pShow = new CShowWindow(camWins[i]); + if (!pShow) return false; + + if (m_showWindows.contains(pShow->WindowId())) + { + delete pShow; + return false; + } + m_showWindows.insert(pShow->WindowId(), pShow); + gGuiCallback_FuncCall(IAddWindows, camWins[i]->key, pShow->WindowId()); + return true; + } + } + } + return true; + } + + return false; +} + +bool CCoreCtrl::IDelCamWin(const QString& strKey) +{ + TP_CAMERA_WIN optCamWin; + if (ICamWinOptionByKey(strKey, optCamWin)){ + QString strWinId = QString(optCamWin.device) + "_" + QString::number(optCamWin.index); + CShowWindow* pShow = m_showWindows.value(strWinId); + if (pShow){ + m_showWindows.remove(strWinId); + delete pShow; + pShow = NULL; + } + } + + return glpCameralPool->IDelCamWin(strKey); +} + +QImage CCoreCtrl::IShowImage(const QString& sShowId, int& nFrameNum, QString& szExShow) +{ + CShowWindow* pWin = m_showWindows.value(sShowId, NULL); + if (NULL == pWin) + { + nFrameNum = -1; + return QImage(); + } + else + { + nFrameNum = pWin->FrameNum(); + szExShow = pWin->ExtendString(); + return pWin->ShowImage(); + } +} + +QMap CCoreCtrl::IGetCamShowNames() +{ + return glpCameralPool->IGetCamShowNames(); +} + +IAlgorithmOption* CCoreCtrl::IGetAlgorithmOption(int nAlgorithm) +{ + return glpImgProc->IGetAlgorithmOption(nAlgorithm); +} + +bool CCoreCtrl::ISetCameraOption(const QString& strSerial, const TP_CAMERA_OPTION& camOpt) +{ + return glpCameralPool->ISetCameraOption(strSerial, camOpt); +} + +bool CCoreCtrl::IReopenCameraes() +{ + return glpCameralPool->IOpenDevices(); +} + +void CCoreCtrl::ISetVirtualImages(const QString& camera, const QStringList& szImages) +{ + glpCameralPool->ISetVirtualImages(camera, szImages); +} + +QImage CCoreCtrl::IOriginImage(const QString& sShowId) +{ + CShowWindow* pWin = m_showWindows.value(sShowId, NULL); + if (NULL == pWin) + { + return QImage(); + } + else + { + return pWin->OriginImage(); + } +} +void CCoreCtrl::ISetCameraProperty(const QString& camera, TP_CAMERA_PROPERTY& property) +{ + return glpCameralPool->ISetCameraProperty(camera, property); +} + +void CCoreCtrl::ISetAlgorithmShared(const QString& key, const QVariant& value) +{ + m_algShared.SetValue(key, value); +} + +void CCoreCtrl::IWriteIo(const TP_IO_OUT_CONTROL& state) +{ + +} + +bool CCoreCtrl::updateCommJson(const QString& sJsonPath) +{ + return false; + +} + +bool CCoreCtrl::updateCamJson(const QString& sJsonPath) +{ + int nError; + QJsonObject originObjJson = QZkJsonParser::ReadJsonObject(sJsonPath, &nError); + + QJsonObject cameraRoot; + QJsonObject cameraDevs; + + QList cameralist = ICameraKeys(); + foreach(const QString& strCameraName, cameralist) + { + TP_CAMERA_OPTION camopt; + if (ICameraOptionByKey(strCameraName, camopt)) + { + QJsonObject camObj; + camObj["id"] = camopt.id; + camObj["type"] = camopt.deviceType; + camObj["showname"] = camopt.showName; + + camObj["format"] = "None"; + QMap::const_iterator iter = gColorNameMap.find(camopt.format); + if (iter != gColorNameMap.constEnd()) + { + camObj["format"] = iter.value(); + } + + camObj["folder"] = camopt.folder; + camObj["zoom"] = camopt.zoom; + camObj["save"] = camopt.save; + camObj["save_img_suffix"] = camopt.saveImgSuffix; + camObj["algorithm"] = camopt.algorithm; + camObj["rely_on_camera"] = camopt.relyOnCamera; + camObj["board_type"] = camopt.boardType; + camObj["board_num"] = camopt.boardNum; + camObj["loop"] = camopt.loop; + camObj["algorithm_dll"] = camopt.dllsuffix.toInt(); + camObj["exposure"] = camopt.exposure; + camObj["gain"] = camopt.gain; + camObj["savefile_rgb_swapped"] = camopt.bNeedRgbSwapped; + camObj["board_name"] = camopt.sBoardName; + camObj["board_config_file"] = camopt.sBoardConfigFile; + + cameraDevs[camopt.uniqueName] = camObj; + } + } + + cameraRoot["devices"] = cameraDevs; + cameraRoot["pool"] = originObjJson["pool"].toObject(); + + + QJsonObject cameraWins; + QList camwinlist = ICamWinKeys(); + foreach(const QString& strCamWinName, camwinlist) + { + TP_CAMERA_WIN camwinOpt; + if (ICamWinOptionByKey(strCamWinName, camwinOpt)) + { + QJsonObject camwinObj; + camwinObj["bitsperpixel"] = camwinOpt.bitsPerPixel; + camwinObj["buffer_h"] = camwinOpt.bufferH; + camwinObj["buffer_w"] = camwinOpt.bufferW; + camwinObj["buffers"] = camwinOpt.buffers; + camwinObj["cache_origin"] = camwinOpt.bCacheOriginImage; + camwinObj["device"] = camwinOpt.device; + camwinObj["images"] = camwinOpt.images; + camwinObj["index"] = camwinOpt.index; + camwinObj["mirror"] = camwinOpt.mirror; + camwinObj["rgb_swapped"] = camwinOpt.bNeedRgbSwapped; + + + cameraWins[camwinOpt.key] = camwinObj; + } + } + cameraRoot["windows"] = cameraWins; + + return saveJsonToFile(cameraRoot, sJsonPath); +} + +bool CCoreCtrl::saveJsonToFile(const QJsonObject& json, const QString& fileFullName) +{ + QFile saveFile(fileFullName); + if (!saveFile.open(QIODevice::WriteOnly)) { + qWarning() << "Couldn't open save file - " << fileFullName + << " - " << __FUNCTION__; + return false; + } + + QJsonDocument saveDoc(json); + saveFile.write(saveDoc.toJson()); + + return true; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/CoreCtrl.h b/src/lpCoreCtrl/CoreCtrl.h new file mode 100644 index 0000000..3361ba9 --- /dev/null +++ b/src/lpCoreCtrl/CoreCtrl.h @@ -0,0 +1,100 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:CoreCtrl.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/24 + History:24:3:2015 17:21 + *******************************************************************************/ +#ifndef __CORE_CTRL_H +#define __CORE_CTRL_H + +#include "iCoreCtrl.h" +#include "qtpthreadimage.h" +#include "QZkMutexMap.h" +//#include "QZkShowImage.h" +#include "ShowWindow.h" +#include "AlgorithmResult.h" +#include "AlgorithmShared.h" + +class CCoreCtrl : public ICoreCtrl +{ +public: + CCoreCtrl(void); + virtual ~CCoreCtrl(void); + //初始化CoreCtrl + virtual int IInitCore(class IDetectorEngine* pDE = NULL); + //释放CoreCtrl + virtual void IFreeCore(); + + //开始执行算法处理 + virtual void IStartImageProcess(); + virtual void IEndImageProcess(); + + bool ShowCameraImage(const ZStringA& serial, UINT nFrameNum, QImage& image, INT64 nStamp, int nIndex = 0, const QString& szExtend = NULL); + void DrawDefectOrg(IImageObject::emTpDefectType defectType, BYTE* pData, int nDataLen, CZkCameraImage* pCamImage); + void DrawImageOrg(QImage& srcImg, CZkCameraImage* pCamImage); + void AccumulateResult(const QString& key, QVariant& val); + virtual void ISetResult(const QString& key, QVariant& val); + + +private: + virtual QList ICameraKeys(); + virtual QList ICameraKeysOrderByIds(); + virtual bool ICameraOption(const QString& strSerial, TP_CAMERA_OPTION& camOpt); + virtual bool ICameraOptionByKey(const QString& strSerial, TP_CAMERA_OPTION& camOpt); + virtual QList IEnumAvailableCameras(emTpDeviceType camType); // try to get available (connected to the computer) by camera type(manufacturer) + virtual void ISetTriggerMode(emTpDeviceTriggerMode triggerMode, long nFrameRate); + virtual emTpDeviceTriggerMode IGetTriggerMode() { return glpCameralPool->IGetTriggerMode(); } + virtual void IManualTrigger(emTpTriggerDirection direct); + virtual void ISnapImage(const QStringList& camKeys); + virtual void ISendSoftTrigger(const QStringList& camKeys); + virtual void IDrawImage(const QString& sKey, QPainter& painter, QRect& rt); + virtual QImage IShowImage(const QString& sShowId, int& nFrameNum, QString& szExShow); + virtual QMap IGetCamShowNames(); + virtual IAlgorithmOption* IGetAlgorithmOption(int nAlgorithm); + virtual bool ISetCameraOption(const QString& strSerial, const TP_CAMERA_OPTION& camOpt); + virtual bool IReopenCameraes(); + virtual void ISetVirtualImages(const QString& camera, const QStringList& szImages); + virtual QImage IOriginImage(const QString& sShowId); + virtual void ISetCameraProperty(const QString& camera, TP_CAMERA_PROPERTY& property); + virtual void ISetAlgorithmShared(const QString& key, const QVariant& value); + virtual void IWriteIo(const TP_IO_OUT_CONTROL& state); + + //camera operate + virtual bool ICreateCamera(const QString& strSerial, int nType) { return glpCameralPool->ICreateCamera(strSerial, nType); } + virtual bool IOpenCamera(const QString& strSerial) { return glpCameralPool->IOpenCamera(strSerial); } + virtual bool ICloseCamera(const QString& strSerial) { return glpCameralPool->ICloseCamera(strSerial); } + virtual bool IStartCamera(const QString& strSerial) { return glpCameralPool->IStartCamera(strSerial); } + virtual bool IStopCamera(const QString& strSerial) { return glpCameralPool->IStopCamera(strSerial); } + virtual bool IDeleteCamera(const QString& strSerial) { return glpCameralPool->IDeleteCamera(strSerial); } + virtual bool IAddCamera(const QString& strName, const TP_CAMERA_OPTION& camOpt, bool bNew, bool bAutoRun = false) { return glpCameralPool->IAddCamera(strName, camOpt, bNew, bAutoRun); } + + //operate camera window + virtual QList ICamWinKeys() { return glpCameralPool->ICamWinKeys(); } + virtual bool ICamWinOptionByKey(const QString& strKey, TP_CAMERA_WIN& camwinOpt) { return glpCameralPool->ICamWinOptionByKey(strKey, camwinOpt); } + virtual bool IAddCamWin(const QString& strKey, const TP_CAMERA_WIN& camwinOpt, bool bNew); + virtual bool IDelCamWin(const QString& strKey); + + //更新json配置文件 + virtual bool updateCommJson(const QString& sJsonPath); + virtual bool updateCamJson(const QString& sJsonPath); + bool saveJsonToFile(const QJsonObject& json, const QString& fileFullName); + + virtual bool ICamsStartPush() { return glpCameralPool->ICamsStartPush(); } + virtual bool ICamsPausePush() { return glpCameralPool->ICamsPausePush(); } +private: + int createShowWindows(); + static void releaseShowWindow(CShowWindow*& pWin, void* pData); +private: + QList m_imgThdPool; + //QZkMutexMap m_showImages; + QZkMutexMap m_showWindows; + CAlgorithmResult m_algResult; + CAlgorithmShared m_algShared; + + int m_nCoreCount; + friend class CImageObject; +}; +#endif \ No newline at end of file diff --git a/src/lpCoreCtrl/GlobalDataBase.cpp b/src/lpCoreCtrl/GlobalDataBase.cpp new file mode 100644 index 0000000..8189be5 --- /dev/null +++ b/src/lpCoreCtrl/GlobalDataBase.cpp @@ -0,0 +1,53 @@ +#include "GlobalDataBase.h" + +CGlobalDataBase::CGlobalDataBase(char *szExePath) +{ + int i = 0; + if( NULL != szExePath ) + { + i = std::strlen(szExePath); + if( i >= BASE_MAX_FILE_PATH ) + { + i = BASE_MAX_FILE_PATH - 1; + } + } + --i; + while( i > 0 ) + { + if( szExePath[i] == '\\' ) + { + break; + } + --i; + } + if ( i >= 0 ) + { + std::strncpy(tgdMainPath, szExePath, i+1); + tgdMainPath[i+1] = '\0'; + } + else + { + std::strcpy(tgdMainPath, ".\\"); + } + std::strcpy(tgdUserPath, tgdMainPath); + std::strcpy(tgdFolderNames[TP_FOLDER_NAME_CONFIG], "config\\"); + std::strcpy(tgdFolderNames[TP_FOLDER_NAME_PICTURE], "pic\\"); + + std::memset(&m_coreSetting, 0, sizeof(m_coreSetting)); +} + +CGlobalDataBase::~CGlobalDataBase() +{ + +} + +bool CGlobalDataBase::CoreSettingFromJson(QJsonObject& jsonObj) +{ + if( jsonObj.isEmpty() ) + { + return false; + } + m_coreSetting.threadsCount = jsonObj.value("image_threads").toInt(0); + m_coreSetting.imageShowType = jsonObj.value("show_type").toInt(TP_IMAGE_SHOW_NEW); + return true; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/GlobalDataBase.h b/src/lpCoreCtrl/GlobalDataBase.h new file mode 100644 index 0000000..f44c5a0 --- /dev/null +++ b/src/lpCoreCtrl/GlobalDataBase.h @@ -0,0 +1,20 @@ +#ifndef GLOBALDATABASE_H +#define GLOBALDATABASE_H + +#include "baseInclude.h" +#include + +class CGlobalDataBase : public TP_GLOBAL_DATA +{ +public: + CGlobalDataBase(char *szExePath); + ~CGlobalDataBase(); + + bool CoreSettingFromJson(QJsonObject& jsonObj); +public: + tagTP_CORE_SETTING m_coreSetting; +private: + +}; + +#endif // GLOBALDATABASE_H diff --git a/src/lpCoreCtrl/ImageObject.cpp b/src/lpCoreCtrl/ImageObject.cpp new file mode 100644 index 0000000..2e88d45 --- /dev/null +++ b/src/lpCoreCtrl/ImageObject.cpp @@ -0,0 +1,249 @@ +#include "ImageObject.h" +#include "CoreCtrl.h" +#include "zfunctions.h" + +CImageObject::CImageObject(class CCoreCtrl* pCoreCtrl) + : m_pCoreCtrl(pCoreCtrl) +{ + m_pCamImg = NULL; +} + +CImageObject::~CImageObject() +{ + +} + +bool CImageObject::SetCameraImage(CZkCameraImage* pCamImage) +{ + m_pCamImg = pCamImage; + return true; +} + +emTpColorFormat CImageObject::IColorFormat() +{ + if( NULL == m_pCamImg ) + { + return TP_COLOR_NONE; + } + else + { + return m_pCamImg->ColorFormat(); + } +} + +BYTE* CImageObject::IImageData(int& nOutW, int& nOutH, int& nOutBitsPerPixel, int& nBytesPerLine) +{ + if( NULL == m_pCamImg ) + { + return NULL; + } + else + { + return m_pCamImg->ImageData(nOutW, nOutH, nOutBitsPerPixel, nBytesPerLine); + } +} + +int CImageObject::IGetId() +{ + if( NULL == m_pCamImg ) + { + return 0; + } + else + { + return m_pCamImg->GetId(); + } +} + +int CImageObject::IGetAlgorithm() +{ + if( NULL == m_pCamImg ) + { + return 0; + } + else + { + return m_pCamImg->Algorithm(); + } +} + +int CImageObject::IGetFrameNum() +{ + if( NULL == m_pCamImg ) + { + return 0; + } + else + { + return m_pCamImg->FrameNumber(); + } +} + +int CImageObject::IGetTriggerCount() +{ + if( NULL == m_pCamImg ) + { + return 0; + } + else + { + return m_pCamImg->TriggerCount(); + } +} + +void CImageObject::ISetCameroProperty(TP_CAMERA_PROPERTY& property) +{ + if( NULL != m_pCamImg ) + { + glpCameralPool->ISetCameraProperty(m_pCamImg->Serial(), property); + } +} + +void CImageObject::ISendDataToUI(void* pData) +{ + if (NULL != m_pCamImg) + { + gGuiCallback_FuncCall(ISendDataToUI, TP_UI_DATA_FROM_ALGORITHM, m_pCamImg->Serial(), pData); + } +} + +void CImageObject::ISafeDataToUI(void* pData, int nDataLen) +{ + QByteArray data((char*)pData, nDataLen); + if (NULL != m_pCamImg) + { + gGuiCallback_FuncCall(ISafeDataToUI, TP_UI_DATA_FROM_ALGORITHM, m_pCamImg->Serial(), data); + } + else + { + gGuiCallback_FuncCall(ISafeDataToUI, TP_UI_DATA_FROM_ALGORITHM, NULL, data); + } +} + +void CImageObject::ISafeDataToUI(WORD type, void* pData, int nDataLen) +{ + QByteArray data((char*)pData, nDataLen); + emTpUiDataType emType = (emTpUiDataType)(TP_UI_DATA_FROM_ALGORITHM | type); + if (NULL != m_pCamImg) + { + gGuiCallback_FuncCall(ISafeDataToUI, emType, m_pCamImg->Serial(), data); + } + else + { + gGuiCallback_FuncCall(ISafeDataToUI, emType, NULL, data); + } +} + +void CImageObject::IDrawDefect(const char* szWinName, emTpDefectType defectType, BYTE* pData, int nDataLen) +{ + QByteArray data((char*)pData, nDataLen); + gGuiCallback_FuncCall(IDrawDefectToScene, szWinName, defectType, data); +} +void CImageObject::IDrawDefectOrg(emTpDefectType defectType, BYTE* pData, int nDataLen) +{ + if (NULL != m_pCoreCtrl && NULL != m_pCamImg) + { + m_pCoreCtrl->DrawDefectOrg(defectType, pData, nDataLen, m_pCamImg); + } +} + +INT64 CImageObject::IMeterCode() +{ + if (NULL == m_pCamImg) + { + return 0; + } + return m_pCamImg->MeterCode(); +} +const char* CImageObject::IGetImageUtf8String() +{ + if (NULL == m_pCamImg) + { + return 0; + } + return m_pCamImg->FileName().data(); +} + +void CImageObject::IDrawImage(QImage& image/* = QImage()*/, const char* szWinName/* = NULL*/) +{ + if (NULL != m_pCoreCtrl && NULL != m_pCamImg) + { + if (image.isNull()) + { + image = m_pCamImg->ToQImage(); + } + m_pCoreCtrl->DrawImageOrg(image, m_pCamImg); + } +} + +QImage CImageObject::IImage() +{ + if (NULL == m_pCamImg) + { + return QImage(); + } + else + { + return m_pCamImg->ToQImage(); + } +} + +const ZStringA& CImageObject::IDllSuffix() +{ + return m_pCamImg->DllSuffix(); +} + +void CImageObject::ISetResult(const QString& key, QVariant& val) +{ + if (NULL != m_pCoreCtrl) + { + m_pCoreCtrl->ISetResult(key, val); + } +} + +void CImageObject::IAccumulateResult(const QString& key, QVariant& val) +{ + if (NULL != m_pCoreCtrl) + { + m_pCoreCtrl->AccumulateResult(key, val); + } +} + +void CImageObject::IMoveToFolder(const QString& szFolder) +{ + if (QFile::exists(QString::fromUtf8(IGetImageUtf8String()))) + { + ZKF::qtCopyFile(IGetImageUtf8String(), szFolder.toUtf8().data()); + } + else + { + if (NULL == m_pCamImg) + { + return; + } + } +} + +IAlgorithmShared* CImageObject::IGetShared() +{ + if (NULL == m_pCoreCtrl) + { + return NULL; + } + return &m_pCoreCtrl->m_algShared; +} + +void CImageObject::IVariantMapToUI(const QVariantMap& vMap) +{ + glpGuiCallback->IVariantMapToUI(TP_UI_DATA_FROM_ALGORITHM, m_pCamImg->Serial(), vMap); +} + +const ZStringA& CImageObject::ICameraSerial() +{ + return m_pCamImg->Serial(); +} + +const QVariant& CImageObject::IVarFromUI() +{ + return m_pCamImg->VarFromUI(); +} \ No newline at end of file diff --git a/src/lpCoreCtrl/ImageObject.h b/src/lpCoreCtrl/ImageObject.h new file mode 100644 index 0000000..cfe35bb --- /dev/null +++ b/src/lpCoreCtrl/ImageObject.h @@ -0,0 +1,51 @@ +#ifndef IMAGEOBJECT_H +#define IMAGEOBJECT_H + +#include "globalCoreCtrl.h" +#include +#include "iAlgorithm.h" + +class CImageObject : public IImageObject +{ +public: + CImageObject(class CCoreCtrl* pCoreCtrl); + ~CImageObject(); + bool SetCameraImage(CZkCameraImage* pCamImage); +private: +// virtual const TP_IMAGE_NODE& ImageNode() { return m_imgNode; } + virtual emTpColorFormat IColorFormat(); + //@nBytesPerLine: 0 means there is no valid value + virtual BYTE* IImageData(int& nOutW, int& nOutH, int& nOutBitsPerPixel, int& nBytesPerLine); + virtual int IGetId(); + virtual int IGetAlgorithm(); + virtual int IGetFrameNum(); + virtual int IGetTriggerCount(); + virtual void ISetCameroProperty(TP_CAMERA_PROPERTY& property); + virtual void ISendDataToUI(void* pData); + virtual void IDrawDefect(const char* szWinName, emTpDefectType defectType, BYTE* pData, int nDataLen); + virtual void IDrawDefectOrg(emTpDefectType defectType, BYTE* pData, int nDataLen); + virtual void ISafeDataToUI(void* pData, int nDataLen); + virtual void ISafeDataToUI(WORD type, void* pData, int nDataLen); + virtual INT64 IMeterCode(); + virtual const char* IGetImageUtf8String(); + virtual void IDrawImage(QImage& image = QImage(), const char* szWinName = NULL); + virtual QImage IImage(); + virtual const ZStringA& IDllSuffix(); + virtual void ISetResult(const QString& key, QVariant& val); + virtual void IAccumulateResult(const QString& key, QVariant& val); + virtual void IMoveToFolder(const QString& szFolder); + virtual IAlgorithmShared* IGetShared(); + virtual void IVariantMapToUI(const QVariantMap& vMap); + virtual const ZStringA& ICameraSerial(); + virtual const QVariant& IVarFromUI(); + virtual quint64 ITimeStamp() { + return m_pCamImg->Stamp(); + } + virtual void IDataToComm(DATA_TO_COMM_HEAD& head, char* pData, int nLen) {}; +private: +// TP_IMAGE_NODE m_imgNode; + CZkCameraImage* m_pCamImg; + class CCoreCtrl* m_pCoreCtrl; +}; + +#endif // IMAGEOBJECT_H diff --git a/src/lpCoreCtrl/LoadModule.cpp b/src/lpCoreCtrl/LoadModule.cpp new file mode 100644 index 0000000..ccd5220 --- /dev/null +++ b/src/lpCoreCtrl/LoadModule.cpp @@ -0,0 +1,55 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:LoadModule.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/23 + History:23:3:2015 17:48 + *******************************************************************************/ +#include "LoadModule.h" + +CLoadModule::CLoadModule(const char *szLibName, const char *szFuncInit, const char *szFuncFree, const char* szPath /* = NULL */) +// :m_lib(szLibName) +{ + QString dllFile; + if( NULL != szPath ) + { + dllFile = QString(szPath) + szLibName; + } + else + { + dllFile = szLibName; + } +#ifdef _DEBUG + dllFile.append('d'); +#endif + m_lib.setFileName(dllFile); + m_fpInit = (Func_Lib_Init)m_lib.resolve(szFuncInit); + m_fpFree = (Func_Lib_Free)m_lib.resolve(szFuncFree); +} + + +CLoadModule::~CLoadModule(void) +{ + ModuleFree(); +} + +void* CLoadModule::ModuleInit(void* inParam /* = NULL */) +{ + if( NULL == m_fpInit ) + { + return NULL; + } + return m_fpInit(inParam); +} + +void CLoadModule::ModuleFree() +{ + if( NULL != m_fpFree ) + { + m_fpFree(); + m_fpFree = NULL; + m_lib.unload(); + } +} \ No newline at end of file diff --git a/src/lpCoreCtrl/LoadModule.h b/src/lpCoreCtrl/LoadModule.h new file mode 100644 index 0000000..c247e9d --- /dev/null +++ b/src/lpCoreCtrl/LoadModule.h @@ -0,0 +1,32 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:LoadModule.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/23 + History:23:3:2015 17:48 + *******************************************************************************/ +#ifndef __LOAD_MODULE_H +#define __LOAD_MODULE_H + +#include + +typedef void* (*Func_Lib_Init)(void *); +typedef void (*Func_Lib_Free)(); + +class CLoadModule +{ +public: + CLoadModule(const char *szLibName, const char *szFuncInit, const char *szFuncFree, const char* szPath = NULL); + ~CLoadModule(void); + + void* ModuleInit(void* inParam = NULL); + void ModuleFree(); +private: + QLibrary m_lib; + Func_Lib_Init m_fpInit; + Func_Lib_Free m_fpFree; +}; + +#endif \ No newline at end of file diff --git a/src/lpCoreCtrl/ModulesManager.cpp b/src/lpCoreCtrl/ModulesManager.cpp new file mode 100644 index 0000000..6e172a2 --- /dev/null +++ b/src/lpCoreCtrl/ModulesManager.cpp @@ -0,0 +1,109 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ModulesManager.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/23 + History:23:3:2015 16:20 + *******************************************************************************/ +#include "ModulesManager.h" +#include "LoadModule.h" +#include "globalCoreCtrl.h" + +#define EXTERN_LIB_FUNC(lib_name) \ + extern "C" void* lib_name##_Init(void* inParam);\ + extern "C" void lib_name##_Free(); + +#ifndef MDL_CAMERA_USE_DLL + EXTERN_LIB_FUNC(Lib_Camera) +#endif + +#ifndef MDL_IMGPROC_USE_DLL + EXTERN_LIB_FUNC(Lib_ImgProc) +#endif + +#ifndef MDL_COMMUNICATE_USE_DLL + EXTERN_LIB_FUNC(Lib_Communicate) +#endif + +inline void* CModulesManager::getModule(const char* szLib, const char* szInit, const char* szFree, void* pInitParam /* = NULL */) +{ + delModule(szLib); + CLoadModule* pLib = new CLoadModule(szLib, szInit, szFree, gpGlobalData->tgdDllPath); + return pLib->ModuleInit(pInitParam); +} + +inline void CModulesManager::delModule(const char* szLib) +{ + CLoadModule* pLib = m_mapLibs.value(szLib, NULL); + if( NULL != pLib ) + { + pLib->ModuleFree(); + delete pLib; + m_mapLibs.remove(szLib); + } +} + +CModulesManager::CModulesManager(void) +{ +} + + +CModulesManager::~CModulesManager(void) +{ +} + +int CModulesManager::LoadModules() +{ + int nRet = 0; + //load "tpCamera" modules + void *pReturn = NULL; + //Load camera library + CAMERA_IN_PARAM camInParam; + camInParam.pCallback = gpCoreCtrlGlobal; + camInParam.pGlobalData = gpGlobalData; +#ifdef MDL_CAMERA_USE_DLL + pReturn = getModule("tpCamera", "Lib_Camera_Init", "Lib_Camera_Free", &camInParam); +#else + pReturn = Lib_Camera_Init(&camInParam); +#endif + if( NULL == pReturn ) + { + return (-nRet); + } + glpCameralPool = (ICameraPool*)pReturn; + ++nRet; + //Load imgproc library + IMGPROC_IN_PARAM imgprocInParam; + imgprocInParam.pGlobalData = gpGlobalData; +#ifdef MDL_IMGPROC_USE_DLL + pReturn = getModule("tpImgProc", "Lib_ImgProc_Init", "Lib_ImpProc_Free", &imgprocInParam); +#else + pReturn = Lib_ImgProc_Init(&imgprocInParam); +#endif + if( NULL == pReturn ) + { + return (-nRet); + } + glpImgProc = (IImgProc*)pReturn; + ++nRet; + //load communicate library + ++nRet; + // + return nRet; +} + +void CModulesManager::FreeModules() +{ +#ifdef MDL_IMGPROC_USE_DLL + delModule("tpImgProc"); +#else + Lib_ImgProc_Free(); +#endif +#ifdef MDL_CAMERA_USE_DLL + delModule("tpCamera"); +#else + Lib_Camera_Free(); +#endif +} \ No newline at end of file diff --git a/src/lpCoreCtrl/ModulesManager.h b/src/lpCoreCtrl/ModulesManager.h new file mode 100644 index 0000000..26e1251 --- /dev/null +++ b/src/lpCoreCtrl/ModulesManager.h @@ -0,0 +1,38 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ModulesManager.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/23 + History:23:3:2015 16:20 + *******************************************************************************/ +#ifndef __MODULES_MANAGER_H +#define __MODULES_MANAGER_H + +//modues controls +//#define MDL_CAMERA_USE_DLL //open it if using camera's module as a dll +//#define MDL_IMGPROC_USE_DLL +//#define MDL_COMMUNICATE_USE_DLL + +///////////////////////////////////////// +#include "icamera.h" +#include "iCoreCtrl.h" +#include + +class CModulesManager +{ +public: + CModulesManager(void); + ~CModulesManager(void); + int LoadModules(); + void FreeModules(); +private: + inline void* getModule(const char* szLib, const char* szInit, const char* szFree, void* pInitParam = NULL); + inline void delModule(const char* szLib); +private: + QMap m_mapLibs; + +}; + +#endif \ No newline at end of file diff --git a/src/lpCoreCtrl/QZkShowImage.cpp b/src/lpCoreCtrl/QZkShowImage.cpp new file mode 100644 index 0000000..82f80e1 --- /dev/null +++ b/src/lpCoreCtrl/QZkShowImage.cpp @@ -0,0 +1,40 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:QZkShowImage.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/17 + History:17:4:2015 15:10 + *******************************************************************************/ +#include "QZkShowImage.h" +#include "ZkCameraImage.h" + +QZkShowImage::QZkShowImage() +{ + +} + +QZkShowImage::~QZkShowImage() +{ + +} + +void QZkShowImage::SetShowImage(class CZkCameraImage* pImg) +{ + m_showImage = pImg->ToShowImage(); + //test +// int depts = m_showImage.depth(); + // + m_nFrameNum = pImg->FrameNumber(); +} + +void QZkShowImage::DrawToPainter(QPainter *painter, QRect* rt) +{ +#ifdef USE_PIXMAP_AS_SHOW + painter->drawPixmap(*rt, m_showImage); +#else ZShowImage == QImage + painter->drawImage(*rt, m_showImage); +#endif + painter->drawText(25, 25, QString::number(m_nFrameNum)); +} \ No newline at end of file diff --git a/src/lpCoreCtrl/QZkShowImage.h b/src/lpCoreCtrl/QZkShowImage.h new file mode 100644 index 0000000..bcc6c8e --- /dev/null +++ b/src/lpCoreCtrl/QZkShowImage.h @@ -0,0 +1,31 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:QZkShowImage.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/17 + History:17:4:2015 15:10 + *******************************************************************************/ +#ifndef QZKSHOWIMAGE_H +#define QZKSHOWIMAGE_H + +#include +#include +#include "baseDefine.h" + +class QZkShowImage +{ +public: + QZkShowImage(); + ~QZkShowImage(); + + void SetShowImage(class CZkCameraImage* pImg); + void DrawToPainter(QPainter *painter, QRect* rt); + +private: + ZShowImage m_showImage; + long m_nFrameNum; +}; + +#endif // QZKSHOWIMAGE_H diff --git a/src/lpCoreCtrl/ShowWindow.cpp b/src/lpCoreCtrl/ShowWindow.cpp new file mode 100644 index 0000000..a7ffa78 --- /dev/null +++ b/src/lpCoreCtrl/ShowWindow.cpp @@ -0,0 +1,332 @@ +#include "ShowWindow.h" +#include "qtpthreadimage.h" +#include + +CShowWindow::CShowWindow(const TP_CAMERA_WIN* pCamWin) + : m_nLastStamp(0) +{ + m_winId = QString(pCamWin->device) + "_" + QString::number(pCamWin->index); + m_camWin = *pCamWin; + if (m_camWin.buffers > SHOW_MAX_BUFFERS) + { + m_camWin.buffers = SHOW_MAX_BUFFERS; + } + if (m_camWin.images <= 0) + { + m_camWin.images = 1; + } + if (m_camWin.bitsPerPixel > 32) + { + m_camWin.bitsPerPixel = 32; + } + m_bytesPerPexel = (m_camWin.bitsPerPixel + 7) / 8; + m_oneBufferSize = m_bytesPerPexel * m_camWin.bufferW * m_camWin.bufferH; + for (int i = 0; i < m_camWin.buffers; ++i) + { + m_ppBuffers[i] = new BYTE[m_oneBufferSize]; + if (NULL == m_ppBuffers[i]) + { + m_camWin.buffers = i; + break; + } + // memset(m_ppBuffers[i], 0xFF, m_oneBufferSize); + QImage(m_ppBuffers[i], m_camWin.bufferW, m_camWin.bufferH, bufferFormat()).fill(QColor(0, 0, 0)); + } + m_nBuffIdxWrite = 0; + m_nBuffIdxShow = 0; +// m_nBuffIdxLashShow = 0; +// m_nWriteImages = 0; +// m_nLastFrameNum = 0; + //...2015.08.31 + m_lastFrameNum = 0; + m_firstFrameNum = 0; + m_nowFrames = 0; + m_lastFrameFirst = 0; +// m_nLastTriggers = 0; +} + +CShowWindow::~CShowWindow() +{ + for (int i = 0; i < m_camWin.buffers; ++i) + { + if (NULL != m_ppBuffers[i]) + { + delete m_ppBuffers[i]; + } + } +} + +bool CShowWindow::AddCameraImage(QImage srcImg, UINT nFrameNum, UINT nStamp/* = 0*/, const QString& szExtend/* = NULL*/) +{ + bool bUpdate = false; + //UINT nFrameNum = pCamImage->FrameNumber(); + if (nFrameNum < m_firstFrameNum || 0 == nFrameNum) + { + return bUpdate; + } + if (1 == nFrameNum) + { + bUpdate = switchBuffers(); + } + else if (nFrameNum > m_lastFrameNum + 1)//wait for the first Frames + { + int nW = 0; + while (nFrameNum > m_lastFrameNum + 1 && nW < SHOW_MAX_WAIT_TIMES)//保证显示的时候图片的顺序 + { + QThread::msleep(25); + ++nW; + } + } + QMutexLocker locker(&m_mutexWrite); + //cache image + if (m_camWin.bCacheOriginImage && m_nLastStamp < nStamp) + { + m_nLastStamp = nStamp; + if (srcImg.text(QIMAGE_FUNC_KEY) == QIMAGE_FUNC_VALUE) + { + m_imgCache = srcImg.copy(); + } + else + { + m_imgCache = srcImg.copy(); + } + } + //判断图像是否有新的一组到来 + if (nFrameNum >= m_firstFrameNum + m_camWin.images) + { + bUpdate |= switchBuffers(); + } + // + // + if (0 == m_nowFrames)//set the first Frame + { + if (1 == nFrameNum) + { + m_firstFrameNum = nFrameNum; + m_lastFrameNum = nFrameNum; + } + else + { + m_firstFrameNum = (nFrameNum - 1) / m_camWin.images * m_camWin.images + 1;// + } + bUpdate = true; + } + // + if (nFrameNum > m_lastFrameNum) + { + m_lastFrameNum = nFrameNum; + } + ++m_nowFrames; + int nIdx = nFrameNum - m_firstFrameNum; + BYTE* pBuffer = m_ppBuffers[m_nBuffIdxWrite]; + if (NULL == pBuffer) + { + return bUpdate; + } + int nImageH = m_camWin.bufferH / m_camWin.images; + pBuffer += nIdx * nImageH * m_camWin.bufferW * m_bytesPerPexel; + QImage imgDest(pBuffer, m_camWin.bufferW, nImageH, bufferFormat()); + QPainter painter(&imgDest); + //QImage srcImg = pCamImage->ToQImage(); + //scale to width + if (m_camWin.bufferW < srcImg.width()) + { + srcImg = srcImg.scaledToWidth(m_camWin.bufferW); + } + //mirror the picture + if (m_camWin.mirror) + { + srcImg = srcImg.mirrored(m_camWin.mirror & 1, m_camWin.mirror & 2); + } + //mirror + if (m_camWin.bNeedRgbSwapped) + { + srcImg = srcImg.rgbSwapped(); + } + painter.drawImage(QPoint(0, 0), srcImg); +// painter.setPen(QColor(0, 150, 10)); +// painter.drawText(5, 15, QString::number(nFrameNum)); + //keep for drawing defects + if (m_bufferFrameNum.contains(pBuffer)) + { + m_frameNumBuffer.remove(m_bufferFrameNum.value(pBuffer)); + } + m_bufferFrameNum.insert(pBuffer, nFrameNum); + m_frameNumBuffer.insert(nFrameNum, pBuffer); + + // + if (m_nowFrames == m_camWin.images) + { + bUpdate |= switchBuffers(); + } + m_szExtend = szExtend; + return bUpdate; +} + +QImage CShowWindow::ShowImage() +{ + return QImage(m_ppBuffers[m_nBuffIdxShow], m_camWin.bufferW, m_camWin.bufferH, bufferFormat()); +} + +QImage::Format CShowWindow::bufferFormat() +{ + if (1 == m_bytesPerPexel) + { + return QImage::Format_Indexed8; + } + else if (2 == m_bytesPerPexel) + { + return QImage::Format_RGB16; + } + else if (3 == m_bytesPerPexel) + { + return QImage::Format_RGB888; + } + else + { + return QImage::Format_ARGB32_Premultiplied; + } +} + +bool CShowWindow::DrawDefect(IImageObject::emTpDefectType defectType, BYTE* pData, int nDataLen, CZkCameraImage* pCamImage) +{ + if (NULL == pCamImage || NULL == pData) + { + return false; + } + UINT nFrameNum = pCamImage->FrameNumber(); + // + QMutexLocker locker(&m_mutexWrite); + BYTE* pBuffer = m_frameNumBuffer.value(nFrameNum, NULL); + if (NULL == pBuffer) + { + return false; + } + int nImageH = m_camWin.bufferH / m_camWin.images; + QImage image(pBuffer, m_camWin.bufferW, nImageH, bufferFormat()); + if (image.isNull()) + { + return false; + } + //scale + double xScale = image.width() * 1.0 / pCamImage->Width(); + double yScale = image.height() * 1.0 / pCamImage->Height(); + //test + //uchar* bits = image.bits(); + //test + QRectF rtf; + switch (defectType) + { + case IImageObject::TP_DEF_RECT_F: + case IImageObject::TP_DEF_ELLIPSE_F: + if (nDataLen < 32) + { + break; + } + else + { + qreal* pfData = (qreal*)pData; + rtf.setRect(pfData[0] * xScale, pfData[1] * yScale, pfData[2] * xScale, pfData[3] * yScale); + } + break; + case IImageObject::TP_DEF_CIRCLE_F: + if (nDataLen < 24) + { + break; + } + else + { + qreal* pfData = (qreal*)pData; + rtf.setRect(pfData[0] * xScale, pfData[1] * yScale, pfData[2] * xScale, pfData[2] * yScale); + } + break; + case IImageObject::TP_DEF_POLYLINE_I: + break; + default: + return false; + } + // + QPainter painter(&image); + QPen pen(QColor(200, 10, 10)); + pen.setWidth(2); + painter.setPen(pen); + switch (defectType) + { + case IImageObject::TP_DEF_RECT_F: + painter.drawRect(rtf); + break; + case IImageObject::TP_DEF_CIRCLE_F: + case IImageObject::TP_DEF_ELLIPSE_F: + painter.drawEllipse(rtf); + break; + case IImageObject::TP_DEF_POLYLINE_I: + if (nDataLen < 16) + { + return false; + } + else + { + QPolygon polygon(nDataLen); + polygon.setPoints(nDataLen / 8, (int*)pData); + painter.drawPolyline(polygon); + } + break; + default: + return false; + } + if (pBuffer >= m_ppBuffers[m_nBuffIdxShow] && pBuffer < m_ppBuffers[m_nBuffIdxShow] + m_oneBufferSize) + { + return true; + } + else + { + return false; + } +} + +bool CShowWindow::DrawImage(QImage& srcImg, UINT nFrameNum, const QString& szExtend/* = NULL*/) +{ +// QMutexLocker locker(&m_mutexWrite); + BYTE* pBuffer = m_frameNumBuffer.value(nFrameNum, NULL); + if (NULL == pBuffer) + { + return false; + } + int nImageH = m_camWin.bufferH / m_camWin.images; + QImage image(pBuffer, m_camWin.bufferW, nImageH, bufferFormat()); + if (image.isNull()) + { + return false; + } + //scale + if (m_camWin.bufferW < srcImg.width()) + { + srcImg = srcImg.scaledToWidth(m_camWin.bufferW); + } + //mirror the picture + if (m_camWin.mirror) + { + srcImg = srcImg.mirrored(m_camWin.mirror & 1, m_camWin.mirror & 2); + } + QPainter painter(&image); + painter.drawImage(QPoint(0, 0), srcImg); + m_szExtend = szExtend; + return true; +} + +bool CShowWindow::switchBuffers() +{ + if (m_nowFrames > 0) + { + m_nBuffIdxShow = m_nBuffIdxWrite; + m_nBuffIdxWrite = (m_nBuffIdxWrite + 1) % m_camWin.buffers; + m_lastFrameFirst = m_firstFrameNum; + m_firstFrameNum = 0; + m_nowFrames = 0; + return true; + } + else + { + return false; + } +} \ No newline at end of file diff --git a/src/lpCoreCtrl/ShowWindow.h b/src/lpCoreCtrl/ShowWindow.h new file mode 100644 index 0000000..2283fa6 --- /dev/null +++ b/src/lpCoreCtrl/ShowWindow.h @@ -0,0 +1,63 @@ +#ifndef SHOWWINDOW_H +#define SHOWWINDOW_H + +#include "globalCoreCtrl.h" +#include "ZkCameraImage.h" +#include +#include "QZkMutexMap.h" +//#include "iAlgorithm.h" + +#define SHOW_MAX_BUFFERS 2 +#define SHOW_MAX_WAIT_TIMES gCoreSetting.threadsCount//4 + +class CShowWindow +{ +public: + CShowWindow(const TP_CAMERA_WIN* pCamWin); + ~CShowWindow(); + const QString& WindowId() { + return m_winId; + } + const TP_CAMERA_WIN& CameraWin() { + return m_camWin; + } +// bool SetCameraImage(CZkCameraImage* pCamImage); + bool AddCameraImage(QImage srcImg, UINT nFrameNum, UINT nStamp = 0, const QString& szExtend = NULL); + QImage ShowImage(); + int FrameNum() { + return m_lastFrameNum; + } + bool DrawDefect(IImageObject::emTpDefectType defectType, BYTE* pData, int nDataLen, CZkCameraImage* pCamImage); + bool DrawImage(QImage& srcImg, UINT nFrameNum, const QString& szExtend = NULL); + QImage& OriginImage() { + return m_imgCache; + } + const QString ExtendString() { + return m_szExtend; + } +private: + QImage::Format bufferFormat(); + bool switchBuffers(); +private: + TP_CAMERA_WIN m_camWin; + QString m_winId; + int m_bytesPerPexel; + BYTE* m_ppBuffers[SHOW_MAX_BUFFERS]; + int m_oneBufferSize; + int m_nBuffIdxWrite; + int m_nBuffIdxShow; + QMutex m_mutexWrite; + // + QMap m_frameNumBuffer;//frame + QMap m_bufferFrameNum; + /*QAtomicInteger*/UINT m_lastFrameNum; + /*QAtomicInteger*/UINT m_firstFrameNum; + UINT m_lastFrameFirst; + QAtomicInteger m_nowFrames; + // + QImage m_imgCache; + INT64 m_nLastStamp; + QString m_szExtend; +}; + +#endif // SHOWWINDOW_H diff --git a/src/lpCoreCtrl/XmlConfigParser.cpp b/src/lpCoreCtrl/XmlConfigParser.cpp new file mode 100644 index 0000000..945675a --- /dev/null +++ b/src/lpCoreCtrl/XmlConfigParser.cpp @@ -0,0 +1,31 @@ +#include "XmlConfigParser.h" +#include +#include + + +CXmlConfigParser::CXmlConfigParser(void) +{ +} + + +CXmlConfigParser::~CXmlConfigParser(void) +{ +} + +QList CXmlConfigParser::Read2DList(const QString& sFileName, const QString& nameTag) +{ + QList retList; + QFile file(QDir::currentPath() + sFileName); + QXmlStreamReader xmlReader(&file); + xmlReader.readNext(); + bool bNameTag = false; + while( !xmlReader.atEnd() ) + { + if( xmlReader.isStartElement() && xmlReader.name() == nameTag )//find a tag + { + ;//.... + } + xmlReader.readNext(); + } + return retList; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/XmlConfigParser.h b/src/lpCoreCtrl/XmlConfigParser.h new file mode 100644 index 0000000..8e21ba4 --- /dev/null +++ b/src/lpCoreCtrl/XmlConfigParser.h @@ -0,0 +1,25 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:XmlConfigParser.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/25 + History:25:3:2015 13:23 + *******************************************************************************/ +#ifndef __XML_CONFIG_PARSER_H_20150325 +#define __XML_CONFIG_PARSER_H_20150325 + +#include +#include + +class CXmlConfigParser +{ +public: + CXmlConfigParser(void); + ~CXmlConfigParser(void); + //Qvariant is a QList, so the returned value is a 2-dimension list + QList Read2DList(const QString& sFileName, const QString& nameTag); +}; + +#endif diff --git a/src/lpCoreCtrl/ZkCameraImage.cpp b/src/lpCoreCtrl/ZkCameraImage.cpp new file mode 100644 index 0000000..bef8e0d --- /dev/null +++ b/src/lpCoreCtrl/ZkCameraImage.cpp @@ -0,0 +1,338 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ZkCameraImage.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/16 + History:16:4:2015 15:40 + *******************************************************************************/ +#include "ZkCameraImage.h" + +CZkCameraImage::CZkCameraImage() +{ + m_nId = 0; + m_nFrameNum = 0; + m_colorFormat = TP_COLOR_NONE; + m_nTriggerCount = 0; + m_pImage = NULL; + m_nCopiedLines = 0; + m_nMeterCode = 0; + m_nTimeStamp = QDateTime::currentDateTime().toMSecsSinceEpoch(); +} + +CZkCameraImage::~CZkCameraImage() +{ + if (NULL != m_pImage) + { + delete m_pImage; + } +} + +int CZkCameraImage::CopyCameraObject(ICameraObject* pCamObj) +{ + // SetColorFormat(pCamObj->ColorFormat()); + if (NULL == pCamObj || NULL == pCamObj->m_pCamOpt) + { + return -1; + } + // TP_CAMERA_OPTION* pOpt = pCamObj->CameraOption(); + //if (NULL == pOpt) + //{ + // return -1; + //} + if (NULL == m_pImage) + { + int nW = pCamObj->m_nImageWidth; + int nH = pCamObj->m_nImageHeight; + if (pCamObj->m_pCamOpt->height > 0) + { + nH = pCamObj->m_pCamOpt->height; + } + m_pImage = new QImage(nW, nH, ToQImageFormat(pCamObj->m_nColorFormat)); + if (NULL == m_pImage) + { + return -1; + } + m_nCopiedLines = 0; + copyOption(pCamObj); + //SetFrameNum(pCamObj->FrameNumber()); + //SetTriggerCount(pCamObj->StartCount()); + //SetSerial(pOpt->uniqueName.toUtf8().data()); + //SetId(pOpt->id); + //SetAlgorithm(pOpt->algorithm); + //SetDllSuffix(pOpt->dllsuffix.toUtf8()); + } + int nLines = m_pImage->height() - m_nCopiedLines; + if (nLines > pCamObj->m_nImageHeight) + { + nLines = pCamObj->m_nImageHeight; + } + int nSizes = nLines * pCamObj->m_nImageWidth*((pCamObj->m_nBitsPerPixel + 7) / 8); + memcpy(m_pImage->scanLine(m_nCopiedLines), pCamObj->m_pCameraData, nSizes); + m_nCopiedLines += nLines; + //SetFileName(pCamObj->Utf8FileName()); + if (m_nCopiedLines == m_pImage->height()) + { + return 1; + } + else + { + return 0; + } +} + +int CZkCameraImage::CopyCameraObject2(ICameraObject* pCamObj) +{ + if (NULL == pCamObj || NULL == pCamObj->m_pCamOpt) + { + return 0; + } + if (NULL == pCamObj->m_funcFreeBuffer) + { + m_pImage = new QImage(); + *m_pImage = QImage(pCamObj->m_pCameraData, pCamObj->m_nImageWidth, pCamObj->m_nImageHeight, ToQImageFormat(pCamObj->m_nColorFormat)).copy(); + //m_pImage = new QImage(pCamObj->m_nImageWidth, pCamObj->m_nImageHeight, ToQImageFormat(pCamObj->m_nColorFormat)); + } + else + { + m_pImage = new QImage(pCamObj->m_pCameraData, pCamObj->m_nImageWidth, pCamObj->m_nImageHeight, ToQImageFormat(pCamObj->m_nColorFormat) + , pCamObj->m_funcFreeBuffer, pCamObj->m_pCameraData); + m_pImage->setText(QIMAGE_FUNC_KEY, QIMAGE_FUNC_VALUE); + } + if (NULL == m_pImage) + { + return 0; + } + copyOption(pCamObj); + return 1; +} + +/* +bool CZkCameraImage::CopyImageData(const BYTE* pData, int nW, int nH, int nBits, emTpColorFormat nColorFormat) +{ + SetColorFormat(nColorFormat); + if( ZIMAGE == m_imageType ) + { + return m_image.zk->Copy(pData, nW, nH, nBits); + } + else + { + *(m_image.q) = QImage(pData, nW, nH, ToQImageFormat()).copy(); + if( m_image.q->isNull() ) + { + return false; + } + else + { + return true; + } + } +} + +bool CZkCameraImage::CopyQImage(const QImage& image) +{ + if( ZIMAGE == m_imageType ) + { + delete m_image.zk; + m_image.q = new QImage(); + m_imageType = QIMAGE; + } + *(m_image.q) = image;//no copy + m_colorFormat = FromQImageFormat(image); + return true; +} +*/ + +ZShowImage CZkCameraImage::ToShowImage(int nShowW /* = 0 */, int nShowH /* = 0 */) +{ + if (NULL == m_pImage) + { + return QImage(); + } +#ifdef USE_PIXMAP_AS_SHOW + if (ZIMAGE == m_imageType) + { + QImage image = QImage(m_zimage.bits(), m_zimage.width(), m_zimage.height(), ToQImageFormat()); + return QPixmap::fromImage(image).copy(); + } + else + { + return QPixmap::fromImage(*(m_image.q)).copy(); + } +#else + /* + QImage image; + if( ZIMAGE == m_imageType ) + { + image = QImage(m_image.zk->bits(), m_image.zk->width(), m_image.zk->height(), ToQImageFormat()); + } + else + { + image = *(m_image.q); + }*/ + if (QImage::Format_Indexed8 == m_pImage->format()) + { + // + QVector colorFmt; + for (int i = 0; i < 256; ++i) + { + QColor clr1(i, i, i); + colorFmt.append(clr1.rgb()); + } + m_pImage->setColorTable(colorFmt); + return m_pImage->convertToFormat(QImage::Format_RGB32); + } + else + { + return m_pImage->copy(); + } +#endif +} + +QImage CZkCameraImage::ToQImage() +{ + if (NULL == m_pImage) + { + return QImage(); + } + //... + QImage::Format fmt = m_pImage->format(); + if (QImage::Format_Indexed8 == m_pImage->format() && m_pImage->colorTable().isEmpty()) + { + QVector colorFmt; + for (int i = 0; i < 256; ++i) + { +QColor clr1(i, i, i); +colorFmt.append(clr1.rgb()); + } + m_pImage->setColorTable(colorFmt); + } + return *m_pImage; +} + +QImage::Format CZkCameraImage::ToQImageFormat(emTpColorFormat colorFormat) +{ + if (TP_COLOR_RGB32 == colorFormat || + TP_COLOR_BGR32 == colorFormat) + { + return QImage::Format_RGB32; + } + else if (TP_COLOR_RGB24 == colorFormat || + TP_COLOR_BGR24 == colorFormat) + { + return QImage::Format_RGB888; + } + else if (TP_COLOR_Y800 == colorFormat) + { + return QImage::Format_Indexed8; + } + else if (TP_COLOR_Y16 == colorFormat) + { + return QImage::Format_RGB555;// QImage::Format_RGB16; + } + else if (TP_COLOR_RGB48 == colorFormat) + { + return QImage::Format_ARGB32; + } + else + { + return QImage::Format_Invalid; + } +} + +emTpColorFormat CZkCameraImage::FromQImageFormat(const QImage &image) +{ + if (QImage::Format_RGB32 == image.format()) + { + return TP_COLOR_RGB32; + } + else if (QImage::Format_RGB888 == image.format()) + { + return TP_COLOR_RGB24; + } + else if (QImage::Format_Indexed8 == image.format()) + { + return TP_COLOR_Y800; + } + else if (QImage::Format_RGB16 == image.format()) + { + return TP_COLOR_Y16; + } + else + { + return TP_COLOR_NONE; + } +} + +emTpColorFormat CZkCameraImage::FromString(const QString& strColor) +{ + if ("RGB32" == strColor) + { + return TP_COLOR_RGB32; + } + else if ("RGB24" == strColor) + { + return TP_COLOR_RGB24; + } + else if ("GRAY8" == strColor) + { + return TP_COLOR_Y800; + } + else if ("GRAY16" == strColor) + { + return TP_COLOR_Y16; + } + else if ("BGR24" == strColor) + { + return TP_COLOR_BGR24; + } + else if ("BGR32" == strColor) + { + return TP_COLOR_BGR32; + } + else + { + return TP_COLOR_NONE; + } +} + + +BYTE* CZkCameraImage::ImageData(int& nOutW, int& nOutH, int& nOutBitsPerPixel, int& nOutBytesPerLine) +{ + if (!m_pImage || m_pImage->isNull()) { + return NULL; + } + + nOutW = m_pImage->width(); + nOutH = m_pImage->height(); + + if (nOutW <= 0) { + qWarning() << "Invalid image data. - " << __FUNCTION__; + return NULL; + } + + nOutBitsPerPixel = m_pImage->bytesPerLine() * 8 / nOutW; + nOutBytesPerLine = m_pImage->bytesPerLine(); + + return m_pImage->bits(); +} + +bool CZkCameraImage::SaveToFile() +{ + if (NULL != m_pImage) + { + if (QImage::Format_Indexed8 == m_pImage->format()) + { + QVector colorFmt; + for (int i = 0; i < 256; ++i) + { + QColor clr1(i, i, i); + colorFmt.append(clr1.rgb()); + } + m_pImage->setColorTable(colorFmt); + } + + } + return m_pImage->save(m_fileName, ".BMP"); +} \ No newline at end of file diff --git a/src/lpCoreCtrl/ZkCameraImage.h b/src/lpCoreCtrl/ZkCameraImage.h new file mode 100644 index 0000000..e14511c --- /dev/null +++ b/src/lpCoreCtrl/ZkCameraImage.h @@ -0,0 +1,148 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ZkCameraImage.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/16 + History:16:4:2015 15:39 + *******************************************************************************/ +#ifndef ZKCAMERAIMAGE_H +#define ZKCAMERAIMAGE_H + +#include "baseDefine.h" +#include "baseStruct.h" +#include "ZkImage.h" +#include "iCameraObject.h" + +#define QIMAGE_FUNC_KEY "bool_func" +#define QIMAGE_FUNC_VALUE "func_true" + +class CZkCameraImage +{ +public: + CZkCameraImage(); + ~CZkCameraImage(); + int CopyCameraObject(ICameraObject* pCamObj); + int CopyCameraObject2(ICameraObject* pCamObj);//no combine and maybe use QImage +// bool CopyImageData(const BYTE* pData, int nW, int nH, int nBits, emTpColorFormat nColorFormat); +// bool CopyQImage(const QImage& image); + //void SetSerial(const char* szSerial) { + // m_strSerial = szSerial; + //} + const ZStringA& Serial() { + return m_strSerial; + } + uint GetId() { + return m_nId; + } + //void SetId(long nId) { + // m_nId = nId; + //} + //void SetFrameNum(long nFrameNum) { + // m_nFrameNum = nFrameNum; + //} + ULONG FrameNumber() { + return m_nFrameNum; + } + //void SetColorFormat(emTpColorFormat nColorFormat) { + // m_colorFormat = nColorFormat; + //} + emTpColorFormat ColorFormat() { + return m_colorFormat; + } + //void SetTriggerCount(long nTriggers) { + // m_nTriggerCount = nTriggers; + //} + long TriggerCount() { + return m_nTriggerCount; + } + ZShowImage ToShowImage(int nShowW = 0, int nShowH = 0); + QImage ToQImage(); + QImage::Format ToQImageFormat(emTpColorFormat colorFormat); + static emTpColorFormat FromQImageFormat(const QImage &image); + static emTpColorFormat FromString(const QString& strColor); + bool SaveToFile(const QString& strFile); + bool SaveToFile(); + BYTE* ImageData(int& nOutW, int& nOutH, int& nOutBitsPerPixel, int& nOutBytesPerLine); + void SetAlgorithm(long nAlgorithm) { + m_nAlgorithm = nAlgorithm; + } + long Algorithm() { + return m_nAlgorithm; + } + //void SetFileName(const ZStringA& strName) { + // m_fileName = strName; + //} + const ZStringA& FileName() { + return m_fileName; + } + void SetMeterCode(INT64 code) { + m_nMeterCode = code; + } + INT64 MeterCode() { + return m_nMeterCode; + } + int Width() { + return m_pImage->width(); + } + int Height() { + return m_pImage->height(); + } + INT64 Stamp() { + return m_nTimeStamp; + } + //void SetDllSuffix(const ZStringA& strName) { + // m_dllSuffix = strName; + //} + const ZStringA& DllSuffix() { + return m_dllSuffix; + } + void SetVarFromUI(const QVariant& v){ + m_varFromUI = v; + } + const QVariant& VarFromUI() { + return m_varFromUI; + } + void Mirror(bool horizontally, bool vertically) + { + if (!m_pImage) + { + return; + } + if (m_pImage->isNull()) + { + return; + } + *m_pImage = m_pImage->mirrored( + horizontally, vertically); + } +private: + void copyOption(ICameraObject* pCamObj) { + m_nFrameNum = pCamObj->m_nFrameNum; + m_nTriggerCount = pCamObj->m_nStartCount; + m_strSerial = pCamObj->m_pCamOpt->uniqueName.toUtf8(); + m_nId = pCamObj->m_pCamOpt->id; + m_nAlgorithm = pCamObj->m_pCamOpt->algorithm; + m_dllSuffix = pCamObj->m_pCamOpt->dllsuffix.toUtf8(); + m_fileName = pCamObj->m_szFileName; + m_colorFormat = pCamObj->m_nColorFormat; + } +private: + QImage* m_pImage; + int m_nCopiedLines; + ////////////////////////////////////////////////// + ZStringA m_strSerial; + long m_nId; + long m_nAlgorithm; + emTpColorFormat m_colorFormat; + ZStringA m_fileName; + ULONG m_nFrameNum; + long m_nTriggerCount; + INT64 m_nMeterCode; + INT64 m_nTimeStamp; + ZStringA m_dllSuffix; + QVariant m_varFromUI; +}; + +#endif // ZKCAMERAIMAGE_H diff --git a/src/lpCoreCtrl/ZkImage.cpp b/src/lpCoreCtrl/ZkImage.cpp new file mode 100644 index 0000000..e8bf6d5 --- /dev/null +++ b/src/lpCoreCtrl/ZkImage.cpp @@ -0,0 +1,74 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ZkImage.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/16 + History:16:4:2015 11:06 + *******************************************************************************/ +#include "ZkImage.h" + +CZkImage::CZkImage() +{ + m_pColorBuffer = NULL; + m_nbuffLen = 0; + m_nWidth = 0; + m_nHeight = 0; +} + +CZkImage::CZkImage(int nW, int nH, int nBits) +{ + CZkImage(); + allocBuffer(nW, nH, nBits); +} + +CZkImage::~CZkImage() +{ + freeBuffer(); +} + +bool CZkImage::allocBuffer(int nW, int nH, int nBits) +{ + SELF_ABS(nW); + SELF_ABS(nH); + SELF_ABS(nBits); + int nLen = (nW * nH * nBits + 7) / 8; + if( 0 == nLen ) + { + return false; + } + if( NULL == m_pColorBuffer || nLen != m_nbuffLen ) + { + freeBuffer(); + m_pColorBuffer = new BYTE[nLen]; + if( NULL == m_pColorBuffer ) + { + return false; + } + m_nbuffLen = nLen; + } + m_nWidth = nW; + m_nHeight = nH; + m_nBitsPerPixel = nBits; + return true; +} + +void CZkImage::freeBuffer() +{ + if( NULL != m_pColorBuffer ) + { + delete m_pColorBuffer; + m_pColorBuffer = NULL; + } +} + +bool CZkImage::Copy(const BYTE* pData, int nW, int nH, int nBits) +{ + if( !allocBuffer(nW, nH, nBits) ) + { + return false; + } + std::memcpy(m_pColorBuffer, pData, m_nbuffLen); + return true; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/ZkImage.h b/src/lpCoreCtrl/ZkImage.h new file mode 100644 index 0000000..1ed84c9 --- /dev/null +++ b/src/lpCoreCtrl/ZkImage.h @@ -0,0 +1,42 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ZkImage.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/16 + History:16:4:2015 11:06 + *******************************************************************************/ +#ifndef ZKIMAGE_H +#define ZKIMAGE_H + +#include "baseDefine.h" + +class CZkImage +{ +public: + CZkImage(); + CZkImage(int nW, int nH, int nBits); + virtual ~CZkImage(); + + bool Copy(const BYTE* pData, int nW, int nH, int nBits); + int width() { return m_nWidth; } + int height() { return m_nHeight; } + int bitsPerPixle() { + return m_nBitsPerPixel; + } + BYTE* bits() { return m_pColorBuffer; } + int buffLen() { return m_nbuffLen; } +private: + bool allocBuffer(int nW, int nH, int nBits); + void freeBuffer(); + +private: + BYTE* m_pColorBuffer; + int m_nbuffLen; + int m_nWidth; + int m_nHeight; + int m_nBitsPerPixel; +}; + +#endif // ZKIMAGE_H diff --git a/src/lpCoreCtrl/globalCoreCtrl.cpp b/src/lpCoreCtrl/globalCoreCtrl.cpp new file mode 100644 index 0000000..8d9770a --- /dev/null +++ b/src/lpCoreCtrl/globalCoreCtrl.cpp @@ -0,0 +1,36 @@ +#include "globalCoreCtrl.h" +#include "QZkJsonParser.h" + +void CGlobalCoreCtrl::readCoreCtrlCfg() +{ + //read config from ".json" file + QString szFileName(m_pGlobalData->tgdMainPath); + szFileName.append(m_pGlobalData->tgdFolderNames[TP_FOLDER_NAME_CONFIG]).append("corectrl").append(TP_STR::cszJsonSuffix); + QJsonObject objJson = QZkJsonParser::ReadJsonObject(szFileName); + if (objJson.isEmpty()) + { + return; + } + //core_setting + QJsonObject objTmp = objJson["core_setting"].toObject(); + m_coreSetting.threadsCount = objTmp.value("image_threads").toInt(0); + m_coreSetting.imageShowType = objTmp.value("show_type").toInt(TP_IMAGE_SHOW_NO); +} + +QVariant CGlobalCoreCtrl::IGetVariantById(int nId) +{ + if (!m_pGuiCallback){ + qCritical("m_pGuiCallback is null in CGlobalCoreCtrl::IGetVariantById."); + return QVariant(); + } + return m_pGuiCallback->IGetVariantById(nId); +} + +void CGlobalCoreCtrl::INewCameraImage(const QVariantMap& vmap) +{ + if (!m_pGuiCallback){ + qCritical("m_pGuiCallback is null in CGlobalCoreCtrl::IGetVariantById."); + return; + } + m_pGuiCallback->INewCameraImage(vmap); +} \ No newline at end of file diff --git a/src/lpCoreCtrl/globalCoreCtrl.h b/src/lpCoreCtrl/globalCoreCtrl.h new file mode 100644 index 0000000..4d6c094 --- /dev/null +++ b/src/lpCoreCtrl/globalCoreCtrl.h @@ -0,0 +1,73 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:globalCoreCtrl.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/24 + History:24:3:2015 17:30 + *******************************************************************************/ +#ifndef __GLOBAL_CORE_CTRL_H +#define __GLOBAL_CORE_CTRL_H + +#include "baseInclude.h" +#include "icamera.h" +#include "iCoreCtrl.h" +#include "iImgProc.h" +#include "GlobalDataBase.h" + + +#ifdef _USE_SPIDER_LOG +#include "logSpider.h" +#define CORE_CTRL_INIT(a, b) SPIDER_LOG_INIT(a, b) +#define CORE_CTRL_LOG(value) SPIDER_LOG_STRING("corectrl", value) +#define CORE_CTRL_FREE() SPIDER_LOG_FREE() +#else +#define CORE_CTRL_INIT(a, b) +#define CORE_CTRL_LOG(value) tpDebugOut(value) +#define CORE_CTRL_FREE() +#endif + +class CGlobalCoreCtrl : public ICameraCallback +{ +public: + CGlobalCoreCtrl(const CORE_CTRL_IN_PARAM* pParam){ + m_pCameraPool = NULL; + m_pImageProc = NULL; + m_pGuiCallback = pParam->pGuiCb; + m_pGlobalData = pParam->pGlobalData; + // m_pCoreSetting = pParam->pCoreSetting; + readCoreCtrlCfg(); + } + ~CGlobalCoreCtrl() {} + void AddCameraPool(ICameraPool* pCameraPool) { m_pCameraPool = pCameraPool; } +private: + void readCoreCtrlCfg(); + virtual QVariant IGetVariantById(int nId); + virtual void INewCameraImage(const QVariantMap& vmap); +public: + TP_GLOBAL_DATA* m_pGlobalData; + TP_CORE_SETTING m_coreSetting; + ICameraPool* m_pCameraPool; + IGuiCallback* m_pGuiCallback; + IImgProc* m_pImageProc; +}; + +extern CGlobalCoreCtrl* gpData; + +#define gpCoreCtrlGlobal gpData + +#define gpGlobalData ((TP_GLOBAL_DATA*)(gpData->m_pGlobalData)) +#define gCoreSetting gpData->m_coreSetting +#define glpCameralPool gpData->m_pCameraPool +//#define glpMainPath NULL != gpData ? gpData->tgdMainPath : ".\\" +// #define gcallCameraPool(fc) if( NULL != glpCameralPool ) glpCameralPool->##fc##() +// #define gcallCameraPoolParam(fc, ...) if( NULL != glpCameralPool) glpCameralPool->##fc##(__VA_VRGS__) +#define glpGuiCallback gpData->m_pGuiCallback +#define gfcbGuiSetImage(...) if( NULL != glpGuiCallback ) glpGuiCallback->ISetCameraImage(__VA_ARGS__) +#define gGuiCallback_FuncCall(fun, ...) if( NULL != glpGuiCallback ) glpGuiCallback->##fun##(__VA_ARGS__) + +#define glpImgProc gpData->m_pImageProc + + +#endif \ No newline at end of file diff --git a/src/lpCoreCtrl/iCameraObject.cpp b/src/lpCoreCtrl/iCameraObject.cpp new file mode 100644 index 0000000..dc8c584 --- /dev/null +++ b/src/lpCoreCtrl/iCameraObject.cpp @@ -0,0 +1,11 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:iCameraObject.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/05/26 + History:26:5:2015 15:35 + *******************************************************************************/ +#include "iCameraObject.h" + diff --git a/src/lpCoreCtrl/iCameraObject.h b/src/lpCoreCtrl/iCameraObject.h new file mode 100644 index 0000000..860c619 --- /dev/null +++ b/src/lpCoreCtrl/iCameraObject.h @@ -0,0 +1,313 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:iCameraObject.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/05/25 + History:25:5:2015 15:52 + *******************************************************************************/ +#ifndef _I_CAMERA_OBJECT_H +#define _I_CAMERA_OBJECT_H + +#include +#include +#include +#include +#include "baseStruct.h" +#include "QZkMutexList.h" +#include +#include +//#define _USE_CAMERA_SERIAL_ENCRYPTO + +class CSaveImgTask : public QRunnable +{ +public: + CSaveImgTask(const QString& path, BYTE* pdata, int BitsPerPixel, long imgwd = 0, + long imght = 0, emTpColorFormat fmt = TP_COLOR_NONE, bool brgbswp = false) + : msPath(path) + , mpData(0) + , mnImageWidth(imgwd) + , mnImageHeight(imght) + , mColorFormat(fmt) + , mbNeedRgbSwapped(brgbswp) + { + qint64 nSizes = mnImageHeight*mnImageWidth*((BitsPerPixel + 7) / 8); + QFileInfo srcInfo(path); + QDir dstDir = srcInfo.dir(); + if (nSizes > 0 && dstDir.exists()){ + try + { + mpData = new BYTE[nSizes]; + memcpy(mpData, pdata, nSizes); + } + catch (const std::bad_alloc& e) + { + qCritical() << "alloc error:" << e.what(); + } + catch (const std::exception& e) + { + qCritical() << "other exception:" << e.what(); + } + } + } + + ~CSaveImgTask(){ + if (mpData){ + delete mpData; + mpData = 0; + } + } + + void run() + { + if (!mpData) return; + + QImage image(mpData, mnImageWidth, mnImageHeight, + TP_FUNCS::ToQImageFormat(mColorFormat)); + + if (image.isNull()){ + qWarning() << "Could save image in CSaveImgTask : " << msPath; + return; + } + + if (QImage::Format_Indexed8 == image.format()) { + QVector colorFmt; + for (int i = 0; i < 256; ++i) { + QColor clr1(i, i, i); + colorFmt.append(clr1.rgb()); + } + image.setColorTable(colorFmt); + } + + if (mbNeedRgbSwapped) + { + image = image.rgbSwapped(); + } + image.save(msPath); + } +private: + QString msPath; + BYTE* mpData; + long mnImageWidth; + long mnImageHeight; + emTpColorFormat mColorFormat; + bool mbNeedRgbSwapped; +}; + +typedef void(*func_free_image_buffer)(void*); + +class ICameraObject +{ +public: + ICameraObject(TP_CAMERA_OPTION* pCamOpt, class IPoolCallback* pCb) + : m_pCamOpt(pCamOpt) + , m_pCb(pCb) + , m_funcFreeBuffer(NULL) + , m_bEnableCallBack(true) { + m_bHasOpened = false; + m_bHasStarted = false; + m_nImageWidth = 0; + m_nImageHeight = 0; + m_nBitsPerPixel = TP_FUNCS::BitsPerPixels((emTpColorFormat)pCamOpt->format);// 0; + m_nImageSize = m_nImageWidth * m_nImageHeight * ((m_nBitsPerPixel + 7) / 8); + m_nColorFormat = TP_COLOR_NONE; + m_nFixedFrames = 0; + m_nFrameNum = 0; + m_nStartCount = 0; + m_oldTriggerMode = DEV_TRIGGER_MODE_STOP; + m_newTriggerMode = DEV_TRIGGER_MODE_OUT; + m_pRelyOnCam = NULL; + m_pCameraData = NULL; + m_bIsCallback = false; + } + virtual ~ICameraObject() { + } + + virtual int IOpenCamera() = 0; + virtual void ICloseCamera() = 0; + virtual int IStartCamera() = 0; + virtual void IStopCamera() = 0; + + virtual void IStartPush() = 0; + virtual void IPausePush() = 0; + + virtual QList IEnumAvailableCameras(){ + QList ret; + return ret; + } + + virtual int ISnapCamera(emTpTriggerDirection direct) { + if( !m_bHasStarted || NULL == m_pCamOpt || m_pCamOpt->bIgnoreImage) { + return 0; + } + if( DEV_TRIGGER_MODE_FIXED_AUTO == m_oldTriggerMode && m_nFrameNum >= m_nFixedFrames ) { + return 0; + } + return 1; + } + virtual int ISendSoftTrigger() { + return ISnapCamera(TRIGGER_DIRECT_FOREWARD); + } + virtual int IAutoCapture() { return 0; } + virtual void ISetProperty(TP_CAMERA_PROPERTY* pCamProperty) {} + virtual const char* Utf8FileName() { + return m_szFileName.data();//TP_FUNCS::ImageFileName(m_nFrameNum, m_pCamOpt).toUtf8().data(); + } + virtual void ISetVirtualImages(const QStringList& szImages) {} + ///////////////////////////////////////////////////////// + void SetTriggerMode(emTpDeviceTriggerMode mode) { + m_newTriggerMode = mode; + } + void SetFixedFrames(int nFrames) { + m_nFixedFrames = nFrames; + } + void SetRelyOnCamera(ICameraObject* pCam) { + m_pRelyOnCam = pCam; + } + void SetReliedByCamera(ICameraObject* pCam) { + m_listReliedBy.appendOnce(pCam); + } + void setCallback(bool b) { + m_bIsCallback = b; + } + void enableCallback(bool b) { + m_bEnableCallBack = b; + } + ICameraObject* RelyOnCamera() { + return m_pRelyOnCam; + } + //int DeviceType() { + // return m_pCamOpt->deviceType; + //} + bool IsCallback() { + return m_bIsCallback; + } + bool IsCallbackEnabled() { + return m_bEnableCallBack; + } + bool SaveToFile() { + if (DEV_CAM_VIRTUAL != m_pCamOpt->deviceType) { + m_szFileName = TP_FUNCS::ImageFileName(m_nFrameNum, m_pCamOpt).toUtf8(); + } + + if (1 != m_pCamOpt->save || DEV_CAM_VIRTUAL == m_pCamOpt->deviceType) { + return false; + } + + //int curTaskCnt = QThreadPool::globalInstance()->activeThreadCount(); + //if (curTaskCnt > 5){ + // return false; + //} + + //QString imgPath = TP_FUNCS::ImageFileName(m_nFrameNum, m_pCamOpt); + //CSaveImgTask *imgSavtsk = new CSaveImgTask(imgPath, m_pCameraData, m_nBitsPerPixel, m_nImageWidth, + // m_nImageHeight, m_nColorFormat); + + //QThreadPool::globalInstance()->start(imgSavtsk); + //return true; + + + QImage image(m_pCameraData, m_nImageWidth, m_nImageHeight, TP_FUNCS::ToQImageFormat(m_nColorFormat)); + if (QImage::Format_Indexed8 == image.format()) { + QVector colorFmt; + for (int i = 0; i < 256; ++i) { + QColor clr1(i, i, i); + colorFmt.append(clr1.rgb()); + } + image.setColorTable(colorFmt); + } + + if (m_pCamOpt->bNeedRgbSwapped) + { + image = image.rgbSwapped(); + } + //qDebug() << TP_FUNCS::ImageFileName(m_nFrameNum, m_pCamOpt).toUtf8(); + return image.save(TP_FUNCS::ImageFileName(m_nFrameNum, m_pCamOpt).toUtf8()); + } + bool NeedStopping() { + if (DEV_TRIGGER_MODE_FIXED_AUTO == m_oldTriggerMode && m_nFrameNum >= m_nFixedFrames) { + return true; + } + else { + return false; + } + } + + virtual int GetCameraStatus(int nType) + { + return 0; + } + +protected: + QString getSerial(const QString& serialNumber) { + if (NULL == m_pCamOpt || NULL == m_pCamOpt->pSerials) { + return NULL; + } + for (QStringList::iterator it = m_pCamOpt->pSerials->begin(); it != m_pCamOpt->pSerials->end(); ++it) { + if (serialNumber == *it) { + return *it; + } + } + return NULL; + } +public: + TP_CAMERA_OPTION* m_pCamOpt; +protected: + bool m_bHasOpened; + bool m_bHasStarted; + bool m_bEnableCallBack; + long m_nImageWidth; + long m_nImageHeight; + long m_nImageSize;//bytes of the images + int m_nBitsPerPixel; + emTpColorFormat m_nColorFormat; + int m_nFixedFrames; + UINT m_nFrameNum; + long m_nStartCount; + emTpDeviceTriggerMode m_oldTriggerMode; + emTpDeviceTriggerMode m_newTriggerMode; + //emCameraDataType m_dataType; + BYTE* m_pCameraData; + ZStringA m_szFileName; + class IPoolCallback* m_pCb; + func_free_image_buffer m_funcFreeBuffer; +private: + ICameraObject* m_pRelyOnCam; + QZkMutexList m_listReliedBy; + bool m_bIsCallback; + friend class CZkCameraImage; + friend class CCameraPool; + friend class CLibCameraes; +}; + +class IPoolCallback +{ +public: + IPoolCallback() {} + virtual ~IPoolCallback() {} + virtual int IPushCameraData(ICameraObject* pCamObj) = 0; + virtual int IPushCameraData2(ICameraObject* pCamObj) = 0; + virtual char* IGetMainPath() = 0; +}; + +#define _USE_CAMERA_DLL +#define _USE_BITFLOW +#define _USE_VIRTUAL +#define _USE_GIGE + +/*****************prefix list*************************** + # DEV_DLL_BITFLOW_BI Bitflow_ + # DEV_DLL_VIRTUAL_FOLDER Virtual_ + # DEV_DLL_GIGE Gige_ + */ + +#ifdef _USE_CAMERA_DLL +#define API_DLL_EXPORT extern "C" __declspec(dllexport) +#define API_NAME_PREFIX(pfix, fname) fname +#else +#defien API_DLL_EXPORT extern "C" +#define API_NAME_PREFIX(pfix, fname) pfix##fname +#endif + +#endif \ No newline at end of file diff --git a/src/lpCoreCtrl/qtpthreadbase.cpp b/src/lpCoreCtrl/qtpthreadbase.cpp new file mode 100644 index 0000000..73539c1 --- /dev/null +++ b/src/lpCoreCtrl/qtpthreadbase.cpp @@ -0,0 +1,56 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:qtpthreadbase.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/26 + History:26:3:2015 17:06 + *******************************************************************************/ +#include "qtpthreadbase.h" + +QTpThreadBase::QTpThreadBase(QObject *parent) + : QThread(parent) +{ + m_bIsRunning = false; + m_bRunSignal = false; +} + +QTpThreadBase::~QTpThreadBase() +{ + +} + + +void QTpThreadBase::StartThread() +{ + if( !m_bIsRunning ) + { + m_bRunSignal = true; + m_bIsRunning = true; + start(); + } +} + +void QTpThreadBase::EndThread() +{ + m_bRunSignal = false; + while(m_bIsRunning ) + { + QThread::msleep(25); + } +} + +void QTpThreadBase::run() +{ + m_bIsRunning = true; + while( m_bRunSignal ) + { + if( !loop() ) + { + break; + } + //... wait signal or condition + } + m_bIsRunning = false; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/qtpthreadbase.h b/src/lpCoreCtrl/qtpthreadbase.h new file mode 100644 index 0000000..2bbc6f3 --- /dev/null +++ b/src/lpCoreCtrl/qtpthreadbase.h @@ -0,0 +1,33 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:qtpthreadbase.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/26 + History:26:3:2015 17:06 + *******************************************************************************/ +#ifndef QTPTHREADBASE_H +#define QTPTHREADBASE_H + +#include "baseInclude.h" +#include + +class QTpThreadBase : public QThread +{ +public: + QTpThreadBase(QObject *parent); + ~QTpThreadBase(); + + void StartThread(); + void EndThread(); +protected: + virtual bool loop() { msleep(25); return false; } +private: + virtual void run(); +private: + bool m_bRunSignal; + bool m_bIsRunning; +}; + +#endif // QTPTHREADBASE_H diff --git a/src/lpCoreCtrl/qtpthreadimage.cpp b/src/lpCoreCtrl/qtpthreadimage.cpp new file mode 100644 index 0000000..2c78523 --- /dev/null +++ b/src/lpCoreCtrl/qtpthreadimage.cpp @@ -0,0 +1,77 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:qtpthreadimage.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/26 + History:26:3:2015 17:10 + *******************************************************************************/ +#include "qtpthreadimage.h" +#include "globalCoreCtrl.h" +#include "CoreCtrl.h" +#include + +QTpThreadImage::QTpThreadImage(class CCoreCtrl* pCtrl, class IDetectorEngine* pDE /*= NULL*/,QObject *parent /* = NULL */) + : QTpThreadBase(parent) + , m_pCoreCtrl(pCtrl) + , m_objImage(pCtrl) + , m_pDE(pDE) +{ +// LOG_SPIDER::InitLog("", "log.txt"); +} + +QTpThreadImage::~QTpThreadImage() +{ + LOG_SPIDER::FreeLog(); +} + +bool QTpThreadImage::loop() +{ + QTime timespan; + + timespan.start(); + CZkCameraImage* pCamImage = glpCameralPool->IPopCameraImage(); + int span = timespan.elapsed(); + if (span > 100) + { + qWarning() << "Pop image from poll cost " << span << " MSecs" + << " - " __FUNCTION__; + } + + if( NULL != pCamImage ) + { + { + // send image to UI + timespan.restart(); + m_pCoreCtrl->ShowCameraImage(pCamImage->Serial() + , pCamImage->FrameNumber() + , pCamImage->ToQImage() + , pCamImage->Stamp() + , 0 + , QString::fromUtf8(pCamImage->FileName()));//(pCamImage); + + qDebug() << "Show camera image to UI cost " << timespan.elapsed() << " MSecs" + << " - " __FUNCTION__; + } + + { + // Algorithm process image + timespan.restart(); + m_objImage.SetCameraImage(pCamImage); + glpImgProc->IImageProcess(&m_objImage, m_pDE); + qDebug() << "Process Image(ID:" << pCamImage->FrameNumber() + << ") cost " << timespan.elapsed() << " MSecs" + << " - " __FUNCTION__; + } + //release CameraImage + m_objImage.SetCameraImage(NULL); + glpCameralPool->IFreeCameraImage(pCamImage); + } + else + { + QTpThreadBase::loop(); + } + + return true; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/qtpthreadimage.h b/src/lpCoreCtrl/qtpthreadimage.h new file mode 100644 index 0000000..2334f35 --- /dev/null +++ b/src/lpCoreCtrl/qtpthreadimage.h @@ -0,0 +1,30 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:qtpthreadimage.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/26 + History:26:3:2015 17:10 + *******************************************************************************/ +#ifndef QTPTHREADIMAGE_H +#define QTPTHREADIMAGE_H + +#include "qtpthreadbase.h" +#include "ImageObject.h" +#include "LogBySpider.h" + +class QTpThreadImage : public QTpThreadBase +{ +public: + QTpThreadImage(class CCoreCtrl* pCtrl, class IDetectorEngine* pDE = NULL ,QObject *parent = NULL); + ~QTpThreadImage(); +private: + virtual bool loop(); +private: + class CCoreCtrl* m_pCoreCtrl; + class IDetectorEngine* m_pDE; + CImageObject m_objImage; +}; + +#endif // QTPTHREADIMAGE_H diff --git a/src/lpCoreCtrl/tadpoleGuiHeader.h b/src/lpCoreCtrl/tadpoleGuiHeader.h new file mode 100644 index 0000000..af784f8 --- /dev/null +++ b/src/lpCoreCtrl/tadpoleGuiHeader.h @@ -0,0 +1,57 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:$FILE_BASE$.$FILE_EXT$ + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:$DATE$ + History:$DAY$:$MONTH$:$YEAR$ $HOUR$:$MINUTE$ + *******************************************************************************/ +#ifndef __TADPOLE_GUI_HEADER_H +#define __TADPOLE_GUI_HEADER_H + +#define TP_OBJ_NAME_ACTION_START "tp_action_start"//开始自动触发的Action名称 +#define TP_OBJ_NAME_ACTION_STOP "tp_action_stop"//停止自动触发的Action名称 +#define TP_OBJ_NAME_ACTION_SHILFT "tp_action_shift"//开始/停止自动触发的Action名称 +#define TP_OBJ_NAME_ACTION_NEXT "tp_action_next"//手动获取一张图片的Action名称 +#define TP_OBJ_NAME_ACTION_LAST "tp_action_last" + +#define TP_OBJ_CUR_TRIGMODE_LBL "tp_cam_cur_trigger_mode_lbl" + +#define TP_OBJ_NAME_PUSHBUTTON_NEXT "tp_button_next" +#define TP_OBJ_NAME_PUSHBUTTON_LAST "tp_button_last" +#define TP_OBJ_NAME_PUSHBUTTON_SHIFT "tp_button_shift" +#define TP_OBJ_NAME_PUSHBUTTON_START "tp_button_start" +#define TP_OBJ_NAME_PUSHBUTTON_STOP "tp_button_stop" +#define TP_OBJ_NAME_PUSHBUTTON_GHOST_APP "tp_button_ghost_app" +#define TP_OBJ_NAME_PUSHBUTTON_SAVE_ALGORITHM "tp_button_save_algorithm" +#define TP_OBJ_NAME_PUSHBUTTON_SAVE_CAMERAES "tp_button_save_cameraes" +#define TP_OBJ_NAME_PUSHBUTTON_FIX_AUTO "tp_button_fix_auto" +#define TP_OBJ_NAME_PUSHBUTTON_INNER_TRIGGER_SHILFT "tp_button_inner_trigger_shilft" + +#define TP_OBJ_NAME_COMBOBOX_SELECT_CAMERAES "tp_combox_select_cameraes" +#define TP_OBJ_NAME_COMBOBOX_SELECT_ALGORITHMS "tp_combox_select_algorithms" +#define TP_OBJ_NAME_EDIT_CAM_OPT_FOLDER "tp_edit_cam_opt_folder" +#define TP_OBJ_NAME_EDIT_CAM_OPT_ALGORITHM "tp_edit_cam_opt_algorithm" +#define TP_OBJ_NAME_EDIT_CAM_OPT_BOARD_TYPE "tp_edit_cam_opt_board_type" +#define TP_OBJ_NAME_EDIT_CAM_OPT_BOARD_NUM "tp_edit_cam_opt_board_num" +#define TP_OBJ_NAME_CHECKBOX_CAM_OPT_SAVE "tp_checkbox_cam_opt_save" +#define TP_OBJ_NAME_EDIT_FIX_FRAMES "tp_edit_fix_frames" +#define TP_OBJ_NAME_EDIT_MSECPERFRAME "tp_edit_msecperframe" + +#define TP_OBJ_NAME_WIDGET_ALGORITHM "tp_widget_algorithm" +#define TP_OBJ_NAME_WIDGET_ALGORITHM_RESULT "tp_widget_algorithm_result" + +//#define TP_OBJ_WIDGET_DRAW_CURVE_ "tp_obj_widget_draw_curve_" +#define TP_PROP_BOOL_NEED_REPEAT_MANUL "tp_prop_bool_need_repeat_manul" +#define TP_OBJ_NAME_CHECKBOX_SHILT_IMAGES "tp_checkbox_shilt_images" + +#define TP_OBJ_NAME_CHECKBOX_TRIGGER_SOFT "tp_checkbox_trigger_soft" +#define TP_OBJ_NAME_CHECKBOX_TRIGGER_AUTO "tp_checkbox_trigger_auto" +#define TP_OBJ_NAME_EDIT_TRIGGER_INTERVAL "tp_edit_trigger_interval" +#define TP_OBJ_NAME_PUSHBUTTON_SEND_TRIGGER "tp_button_send_trigger" + +#define TP_OBJ_NAME_CHECKBOX_APP_STATUS "tp_app_checked_status" + + +#endif //__TADPOLE_GUI_HEADER_H \ No newline at end of file diff --git a/src/lpCoreCtrl/tpCamera/CameraPool.cpp b/src/lpCoreCtrl/tpCamera/CameraPool.cpp new file mode 100644 index 0000000..02ed05c --- /dev/null +++ b/src/lpCoreCtrl/tpCamera/CameraPool.cpp @@ -0,0 +1,883 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:CameraPool.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/25 + History:25:3:2015 11:28 + *******************************************************************************/ +#include "CameraPool.h" +#include + +CCameraPool::CCameraPool(void) + : m_thdTrigger(this) + , m_libs(gpGlobalData->tgdDllPath) +// :m_mutexImgQueue(QMutex::Recursive) +{ + m_nTriggerMode = DEV_TRIGGER_MODE_STOP; + m_nFrameRate = 0; + m_nCameraEncode = 0; +} + +CCameraPool::~CCameraPool(void) +{ + releaseImagesList(); +} + +int CCameraPool::InitPool() +{ + int nRet = 0;//IOpenDevices(true); + m_thdTrigger.StartTrigger(); + return nRet; +} + +void CCameraPool::FreePool() +{ + m_thdTrigger.EndTrigger(); + ICloseDevices(); + IDeleteDameraes(); +} + +int CCameraPool::ICreateCameraes() +{ + QList keys = gpGlobalCamera->CameraKeys();//cameraes.keys(); + for (int i = 0; i < keys.size(); ++i) + { + if (m_cameraes.contains(keys[i])) + { + continue; + } + ICameraObject* pObject = m_libs.Create(gpGlobalCamera->CameraOption(keys[i]), this); + if (NULL == pObject) + { + continue; + } + pObject->m_pCamOpt->status = TP_CAMERA_STATUS_INITED; + m_cameraes.insert(keys[i], pObject); + } + return m_cameraes.size(); +} + +bool CCameraPool::ICreateCamera(const QString& strSerial, int nType) +{ + if (m_cameraes.contains(strSerial)) + { + return false; + } + + TP_CAMERA_OPTION camOpt; + camOpt.deviceType = nType; + camOpt.uniqueName = strSerial; + + ICameraObject* pObject = m_libs.Create(&camOpt, this); + if (NULL == pObject) + { + return false; + } + + pObject->m_pCamOpt->status = TP_CAMERA_STATUS_INITED; + m_cameraes.insert(strSerial, pObject); + return true; +} + +bool CCameraPool::IOpenCamera(const QString& strSerial, bool bReopen) +{ + ICameraObject* pCamera = m_cameraes.value(strSerial); + if (!pCamera) + return false; + + //if (pCamera->m_pCamOpt->status != TP_CAMERA_STATUS_INITED && + // pCamera->m_pCamOpt->status != TP_CAMERA_STATUS_CLOSED){ + // return false; + //} + + if (bReopen) + { + pCamera->ICloseCamera(); + pCamera->m_pCamOpt->status = TP_CAMERA_STATUS_CLOSED; + } + + int nret = pCamera->IOpenCamera(); + if (nret == 1){ + pCamera->m_pCamOpt->status = TP_CAMERA_STATUS_OPENED; + return true; + } + return false; +} + +bool CCameraPool::ICloseCamera(const QString& strSerial) +{ + ICameraObject* pCamera = m_cameraes.value(strSerial); + if (!pCamera) + return false; + + pCamera->ICloseCamera(); + pCamera->m_pCamOpt->status = TP_CAMERA_STATUS_CLOSED; + return true; +} + +bool CCameraPool::IDeleteCamera(const QString& strSerial) +{ + ICameraObject* pCamera = m_cameraes.value(strSerial); + if (pCamera){ + pCamera->IStopCamera(); + pCamera->ICloseCamera(); + + pCamera->m_pCamOpt->status = TP_CAMERA_STATUS_UNINIT; + m_libs.Delete(pCamera); + } + m_cameraes.remove(strSerial); + gpGlobalCamera->delCameraOption(strSerial); + + return true; +} + +bool CCameraPool::IAddCamera(const QString& strName, const TP_CAMERA_OPTION& camOpt, bool bNew, bool bAutoRun/* = false */) +{ + bool bret = false; + if (!bNew){ + bret = ICloseCamera(strName); + if (!bret) return bret; + } + + gpGlobalCamera->updateCameraOption(strName, camOpt); + + if (bNew){ + ICameraObject* pCamObj = m_libs.Create(gpGlobalCamera->CameraOption(strName), this); + if (pCamObj) + { + pCamObj->m_pCamOpt->status = TP_CAMERA_STATUS_INITED; + m_cameraes.insert(strName, pCamObj); + } + else{ + return false; + } + } + + bret = IOpenCamera(strName, true); + if (!bret) return bret; + + if (bAutoRun){ + bret = IStartCamera(strName); + } + return bret; +} + +bool CCameraPool::IStartCamera(const QString& strSerial) +{ + ICameraObject* pCamera = m_cameraes.value(strSerial); + if (!pCamera) + return false; + + //if (pCamera->m_pCamOpt->status != TP_CAMERA_STATUS_OPENED && + // pCamera->m_pCamOpt->status != TP_CAMERA_STATUS_STOPPED ) + //{ + // return false; + //} + + int nret = pCamera->IStartCamera(); + if (nret == 1){ + pCamera->m_pCamOpt->status = TP_CAMERA_STATUS_STARTED; + return true; + } + return false; +} + +bool CCameraPool::IStopCamera(const QString& strSerial) +{ + ICameraObject* pCamera = m_cameraes.value(strSerial); + if (!pCamera) + return false; + + pCamera->IStopCamera(); + pCamera->m_pCamOpt->status = TP_CAMERA_STATUS_STOPPED; + return true; +} + +void CCameraPool::IDeleteDameraes() +{ + IStopDevices(); + ICloseDevices(); + m_cameraes.clear(cameraErased, &m_libs); +} + +void CCameraPool::cameraOpen(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + + if (pCam->IOpenCamera() == 1) + { + pCam->m_pCamOpt->status = TP_CAMERA_STATUS_OPENED; + } +} + +void CCameraPool::cameraOpenEx(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + if (pCam->m_pCamOpt->bAutoOpen) + { + if (pCam->IOpenCamera() == 1) + { + pCam->m_pCamOpt->status = TP_CAMERA_STATUS_OPENED; + } + } +} + +int CCameraPool::IOpenDevices(bool bReopenAll) +{ + if( bReopenAll ) + { + ICloseDevices(); + } + m_cameraes.iterateCall(cameraOpen, NULL); + m_cameraes.iterateCall(cameraCalRelyOn, &m_cameraes); + //calRelyOn(); + //ISetTriggerMode(DEV_TRIGGER_MODE_AUTO, TRIGGER_DIRECT_FOREWARD, gGlobalPoolOption.frameRate); + return 1; +} + +int CCameraPool::IOpenDevicesEx(bool bReopenAll) +{ + if (bReopenAll) + { + ICloseDevices(); + } + m_cameraes.iterateCall(cameraOpenEx, NULL); + m_cameraes.iterateCall(cameraCalRelyOnEx, &m_cameraes); + //calRelyOn(); + //ISetTriggerMode(DEV_TRIGGER_MODE_AUTO, TRIGGER_DIRECT_FOREWARD, gGlobalPoolOption.frameRate); + return 1; +} + +void CCameraPool::cameraClose(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + + pCam->ICloseCamera(); + pCam->m_pCamOpt->status = TP_CAMERA_STATUS_CLOSED; +} +void CCameraPool::ICloseDevices() +{ + m_cameraes.iterateCall(cameraClose, NULL); +// m_devVessel.Erase(NULL, deviceErased, false); + //m_cameraes.clear(cameraErased, &m_libs); +} + + +void CCameraPool::IStartDevices() +{ + + m_cameraes.iterateCall(cameraStartDevices, NULL); +} + +void CCameraPool::IStopDevices(const QString& sDef/* = NULL*/) +{ + if (sDef.isEmpty()) + { + m_cameraes.iterateCall(cameraStopDevices, NULL); + } + else + { + m_cameraes.valueCall(sDef, cameraStopDevices, NULL); + } +} + +bool CCameraPool::ICamsStartPush() +{ + m_cameraes.iterateCall(camerasStartPush, NULL); + return true; +} + +void CCameraPool::camerasStartPush(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + + //if (pCam->m_pCamOpt->deviceType != 110) return; + + pCam->IStartPush(); +} + +bool CCameraPool::ICamsPausePush() +{ + m_cameraes.iterateCall(camerasPausePush, NULL); + return true; +} + +void CCameraPool::camerasPausePush(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + + //if (pCam->m_pCamOpt->deviceType != 110) return; + + pCam->IPausePush(); +} + +void CCameraPool::fixedFramesStopCamera(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + if (pCam->NeedStopping()) + { + pCam->IStopCamera(); + pCam->m_pCamOpt->status = TP_CAMERA_STATUS_STOPPED; + } +} + + + +void CCameraPool::DeviceLost(const QString& strName) +{ + ICameraObject* pObj = m_cameraes.take(strName); + if (NULL != pObj) + { + m_libs.Delete(pObj); + } +// m_devVessel.Erase(strName, deviceErased, false); +// m_virVessel.Erase(strName, deviceErased, false); +} + +QList CCameraPool::ICameraKeys() +{ + return gpGlobalCamera->CameraKeys(); +} + +QList CCameraPool::ICameraKeysOrderByIds() +{ + return gpGlobalCamera->CameraKeysOrderByIds(); +} + +bool CCameraPool::ICameraOption(const QString& strSerial, TP_CAMERA_OPTION& camOpt) +{ + return gpGlobalCamera->CameraOption(strSerial, camOpt); +} + +bool CCameraPool::ICameraOptionByKey(const QString& strSerial, TP_CAMERA_OPTION& camOpt) +{ + return gpGlobalCamera->CameraOptionByKey(strSerial, camOpt); +} + +bool CCameraPool::ISetCameraOption(const QString& strSerial, const TP_CAMERA_OPTION& camOpt) +{ + bool bRet = gpGlobalCamera->SetCameraOption(strSerial, camOpt); + if (bRet) + { + ICameraObject* pCam = m_cameraes.value(strSerial, NULL); + if (NULL != pCam) + { + pCam->ISetProperty(NULL); + } + } + return bRet; +} + +QList CCameraPool::IEnumAvailableCameras(emTpDeviceType camType) +{ + QList ret; + + // if the camera dll has been loaded + QZkMutexMap::const_iterator iter = m_cameraes.constBegin(); + while (iter != m_cameraes.constEnd()) + { + ICameraObject* pCam = iter.value(); + if (pCam && pCam->m_pCamOpt->deviceType == camType){ + ret = pCam->IEnumAvailableCameras(); + return ret; + } + iter++; + } + + // the camera dll has not been loaded + TP_CAMERA_OPTION camOpt; + camOpt.deviceType = camType; + + ret = m_libs.enumAvailableCameras(&camOpt, this); + return ret; +} + +void CCameraPool::ISetTriggerMode(emTpDeviceTriggerMode mode, emTpTriggerDirection nDirection /* = TRIGGER_DIRECT_FOREWARD */, long nFrameRate /* = 0 */) +{ + gGlobalPoolOption.triggerMode = mode; + gGlobalPoolOption.triggerDirection = nDirection; + gGlobalPoolOption.frameRate = nFrameRate; + gGlobalPoolOption.fixedFrames = nFrameRate; + m_nTriggerMode = mode; + m_nFrameRate = nFrameRate; + //set every device's trigger + m_thdTrigger.LockWorked(); + m_cameraes.iterateCall(cameraSetTriggerMode, &gGlobalPoolOption); + IStartDevices(); + m_thdTrigger.UnlockWorked(); + //begin or end trigger's thread + if( DEV_TRIGGER_MODE_AUTO != mode && + DEV_TRIGGER_MODE_FIXED_AUTO != mode ) + { + //m_thdTrigger.EndThread(); + m_thdTrigger.SetAutoTrigger(false); + } + else + { + m_thdTrigger.SetFrame(nFrameRate); + //m_thdTrigger.StartTrigger(); + m_thdTrigger.SetAutoTrigger(true); + } +} + + +void CCameraPool::IManualTrigger(emTpTriggerDirection nDirection /* = TRIGGER_DIRECT_FOREWARD */) +{ + if( DEV_TRIGGER_MODE_OUT != m_nTriggerMode ) + { + ISetTriggerMode(DEV_TRIGGER_MODE_OUT); + } + tagCOMMIT_TRIGGER_PARAM prm; + prm.direct = nDirection; + prm.count = 0; + prm.bFromMenual = true; + m_cameraes.iterateCall(cameraSnaps, &prm); +// SnapImages(prm); +} + +void gfunc_snap_camera_image(const QString& key, class ICameraObject*& pCam, void* pData) +{ + if (!pCam) + return; + if (NULL != pCam->RelyOnCamera()) + { + return; + } + QStringList* pKeys = (QStringList*)pData; + if (!pKeys->contains(key)) + { + return; + } + pCam->ISnapCamera(TRIGGER_DIRECT_FOREWARD); +} + +void CCameraPool::ISnapImage(const QStringList& camKeys) +{ + m_cameraes.iterateCall2(gfunc_snap_camera_image, (void*)(&camKeys)); +} + +void gfunc_send_soft_trigger(const QString& key, class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + + if (NULL != pCam->RelyOnCamera()) + { + return; + } + if (NULL != pData) + { + QStringList* pKeys = (QStringList*)pData; + if (!pKeys->contains(key)) + { + return; + } + } + pCam->ISendSoftTrigger(); +} +void CCameraPool::ISendSoftTrigger(const QStringList& camKeys) +{ + if (camKeys.isEmpty()) + { + m_cameraes.iterateCall2(gfunc_send_soft_trigger, NULL); + } + else + { + m_cameraes.iterateCall2(gfunc_send_soft_trigger, (void*)(&camKeys)); + } +} + +void CCameraPool::IntervalCaptureImages(tagCOMMIT_TRIGGER_PARAM& prm) +{ + m_cameraes.iterateCall(cameraIntervalCaptures, &prm); + /////////////////////////////////////////////////////////////////////////////////////////////////////////////// +} + +//**difficult to understand** +//iterate the virtual camera's vessel and the device's vessel as the parameter +void CCameraPool::calRelyOn() +{ + m_cameraes.iterateCall(cameraCalRelyOn, &m_cameraes); +} + + +void CCameraPool::ISetCameraProperty(const QString& camera, emTpCameraProperty property, long nValue) +{ +} + +void CCameraPool::ISetCameraProperty(const QString& camera, TP_CAMERA_PROPERTY& property) +{ + if( camera.isNull() ) + { + m_cameraes.iterateCall(cameraSetProperty, &property); + } + else + { + m_cameraes.valueCall(camera, cameraSetProperty, &property); + } +} + + +void CCameraPool::cameraSetProperty(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + pCam->ISetProperty((TP_CAMERA_PROPERTY*)pData); +} + +//ICameraObject* CCameraPool::CreateCamera(TP_CAMERA_OPTION* pCamOpt) +//{ +// if( NULL == pCamOpt ) +// { +// return NULL; +// } +// ICameraObject* pObj = NULL; +// if( DEV_CAMERA == pCamOpt->deviceType ) +// { +// //pObj = new CGigeCamera(pCamOpt, this); +// } +// else if( DEV_VIRTUAL == pCamOpt->deviceType ) +// { +// //pObj = new CVirtualCamera(pCamOpt, this); +// } +// else if( DEV_BITFLOW == pCamOpt->deviceType ) +// { +// //pObj = new CBitflowCameraBi(pCamOpt, this); +// } +// return pObj; +//} + +QList CCameraPool::ICameraWins() +{ + return gpGlobalCamera->CameraWins(); +} + +CZkCameraImage* CCameraPool::IPopCameraImage() +{ + return m_imagesList.takeFirst(NULL); + /*CZkCameraImage *pCamImg = m_imagesList.takeFirst(NULL); + if (NULL != pCamImg) + { + + } + return pCamImg;*/ +} + +////////////////////////////////////////////////////////////////////////////////////////////// +int CCameraPool::createDeviceByOptiones() +{ + QList keys = gpGlobalCamera->CameraKeys();//cameraes.keys(); + for( int i = 0; i < keys.size(); ++i ) + { + if( m_cameraes.contains(keys[i]) ) + { + continue; + } + ICameraObject* pObject = m_libs.Create(gpGlobalCamera->CameraOption(keys[i]), this); + if( NULL == pObject ) + { + continue; + } + if( 0 == pObject->IOpenCamera() ) + { + m_libs.Delete(pObject); + continue; + } + pObject->m_pCamOpt->status = TP_CAMERA_STATUS_OPENED; + m_cameraes.insert(keys[i], pObject); + } + return m_cameraes.size(); +} + +void CCameraPool::cameraErased(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + CLibCameraes* pLibs = (CLibCameraes*)pData; + pCam->IStopCamera(); + pCam->ICloseCamera(); + + pCam->m_pCamOpt->status = TP_CAMERA_STATUS_UNINIT; + pLibs->Delete(pCam); +} + +void CCameraPool::cameraStartDevices(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + + //if (pCam->m_pCamOpt->status != TP_CAMERA_STATUS_OPENED && + // pCam->m_pCamOpt->status != TP_CAMERA_STATUS_STOPPED) + //{ + // return; + //} + + if (pCam->IStartCamera() == 1){ + pCam->m_pCamOpt->status = TP_CAMERA_STATUS_STARTED; + } +} + +void CCameraPool::cameraStopDevices(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + pCam->IStopCamera(); + pCam->m_pCamOpt->status = TP_CAMERA_STATUS_STOPPED; +} + +void CCameraPool::cameraSetTriggerMode(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + TP_CAMERAPOOL_OPTION* pOpt = (TP_CAMERAPOOL_OPTION*)pData; + pCam->SetFixedFrames(pOpt->fixedFrames); + pCam->SetTriggerMode(pOpt->triggerMode); +} + +void CCameraPool::cameraSnaps(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + tagCOMMIT_TRIGGER_PARAM* pParam = (tagCOMMIT_TRIGGER_PARAM*)pData; + if( NULL != pCam->RelyOnCamera() ) + { + return; + } + pCam->ISnapCamera(pParam->direct); +} + +void CCameraPool::cameraIntervalCaptures(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + //tagCOMMIT_TRIGGER_PARAM* pParam = (tagCOMMIT_TRIGGER_PARAM*)pData; + if (NULL != pCam->RelyOnCamera()) + { + return; + } + //pCam->ISnapCamera(pParam->direct); + pCam->IAutoCapture(); +} + +void CCameraPool::cameraCalRelyOn(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + QZkMutexMap* pCameraes = (QZkMutexMap*)pData; + TP_CAMERA_OPTION* pOpt = pCam->m_pCamOpt; + if( DEV_CAM_VIRTUAL_FOLDER == pOpt->deviceType && NULL == pCam->RelyOnCamera() && pCameraes->contains(pOpt->relyOnCamera) ) + { + ICameraObject* pCamRelyOn = pCameraes->value(pOpt->relyOnCamera, NULL); + if( NULL != pCamRelyOn ) + { + pCam->SetRelyOnCamera(pCamRelyOn); + pCamRelyOn->SetReliedByCamera(pCam); + } + } +} + +void CCameraPool::cameraCalRelyOnEx(class ICameraObject*& pCam, void* pData) +{ + if (!pCam) return; + QZkMutexMap* pCameraes = (QZkMutexMap*)pData; + TP_CAMERA_OPTION* pOpt = pCam->m_pCamOpt; + if (DEV_CAM_VIRTUAL_FOLDER == pOpt->deviceType && pOpt->bAutoOpen && NULL == pCam->RelyOnCamera() && pCameraes->contains(pOpt->relyOnCamera)) + { + ICameraObject* pCamRelyOn = pCameraes->value(pOpt->relyOnCamera, NULL); + if (NULL != pCamRelyOn) + { + pCam->SetRelyOnCamera(pCamRelyOn); + pCamRelyOn->SetReliedByCamera(pCam); + } + } +} + +int CCameraPool::IPushCameraData(ICameraObject* pCamObj) +{ + if (m_imagesList.size() >= 32) + { + qWarning("Cache OverFlow, Camera Image Count:%d", m_imagesList.size()); + if (pCamObj->m_nFrameNum > 0) + { + pCamObj->m_nFrameNum--; + } + return 0; + } + + if (NULL == pCamObj || NULL == pCamObj->m_pCamOpt ) + { + return 0; + } + if (pCamObj->m_pCamOpt->bIgnoreImage) + { + if (pCamObj->m_nFrameNum > 0) + { + pCamObj->m_nFrameNum--; + } + return 0; + } + // + pCamObj->SaveToFile(); + + CZkCameraImage *pImage = m_imagesMerging.value(pCamObj->m_pCamOpt->uniqueName, NULL); + if (NULL == pImage) + { + pImage = new CZkCameraImage(); + } + int nRet = 0; + if (NULL != pImage) + { + // + if (!gpGlobalCamCallback){ + delete pImage; + return 0; + } + try{ + pImage->SetVarFromUI(gpGlobalCamCallback->IGetVariantById(pCamObj->m_pCamOpt->id)); + + //QVariantMap map; + //map.clear(); + //map.insert("width", pCamObj->m_nImageWidth); + //map.insert("height", pCamObj->m_nImageHeight); + //map.insert("size", pCamObj->m_nImageSize); + //map.insert("frame", pCamObj->m_nFrameNum); + //qint64 nSizes = pCamObj->m_nImageHeight*pCamObj->m_nImageWidth*((pCamObj->m_nBitsPerPixel + 7) / 8); + ////QByteArray baimgdat = QByteArray::fromRawData((const char*)(pCamObj->m_pCameraData), nSizes); + //QByteArray baimgdat = QByteArray((const char*)(pCamObj->m_pCameraData)); + //map.insert("imgdata", baimgdat); + + //std::string imgb64 = base64_encode(pCamObj->m_pCameraData, nSizes); + //int b64len = imgb64.length(); + //QString qsimgb64(imgb64.c_str()); + //map.insert("imgb64", qsimgb64); + //gpGlobalCamCallback->INewCameraImage(map); + } + catch (...){ + qCritical() << "Critical error." << __FUNCTION__; + return 0; + } + // + int nRet = pImage->CopyCameraObject(pCamObj); + if (-1 == nRet) + { + delete pImage; + pImage = NULL; + } + else if (1 == nRet) + { + pImage->SetMeterCode(m_nCameraEncode); + m_imagesList.append(pImage); + pImage = NULL; + } + m_imagesMerging.insert(pCamObj->m_pCamOpt->uniqueName, pImage); + nRet = 1; + } + + //checks to stop trigger in fixed_auto + if (pCamObj->NeedStopping()) + { + //IStopDevices(pCamObj->CameraOption()->uniqueName);//不是好方法,如果正在SetTriggerStart,这里可能会立刻Stop这次Start + //pCamObj->IStopCamera();//不是好方法,如果正在SetTriggerStart,这里可能会立刻Stop这次Start + m_cameraes.valueCall(pCamObj->m_pCamOpt->uniqueName, fixedFramesStopCamera, NULL); + } + return nRet; +} + +//don't combine image +int CCameraPool::IPushCameraData2(ICameraObject* pCamObj) +{ + if (m_imagesList.size() >= 32) + { + qWarning("Cache OverFlow, Camera Image Count:%d", m_imagesList.size()); + } + + quint64 msec = QDateTime::currentMSecsSinceEpoch(); + if (NULL == pCamObj || NULL == pCamObj->m_pCamOpt) + { + return 0; + } + if (pCamObj->m_pCamOpt->bIgnoreImage) + { + if (pCamObj->m_nFrameNum > 0) + { + pCamObj->m_nFrameNum--; + } + return 0; + } + // + pCamObj->SaveToFile(); + // + CZkCameraImage* pImage = new CZkCameraImage(); + if (NULL == pImage) + { + return 0; + } + if (0 == pImage->CopyCameraObject2(pCamObj)) + { + delete pImage; + return 0; + } + + pImage->SetVarFromUI(gpGlobalCamCallback->IGetVariantById(pCamObj->m_pCamOpt->id)); + m_imagesList.append(pImage); + // + if (pCamObj->NeedStopping()) + { + m_cameraes.valueCall(pCamObj->m_pCamOpt->uniqueName, fixedFramesStopCamera, NULL); + } + return 1; +} + +char* CCameraPool::IGetMainPath() +{ + return gpGlobalCamera->m_pGlobalData->tgdMainPath; +} +void CCameraPool::IFreeCameraImage(CZkCameraImage *pCamImg) +{ + delete pCamImg; +} + +QMap CCameraPool::IGetCamShowNames() +{ + return gpGlobalCamera->GetCamShowNames(); +} + +void CCameraPool::ISetCameraEncode(INT64 code, INT64 rate) +{ + m_nCameraEncode = code; + m_nEncoderRate = rate; +} + +void CCameraPool::ISetVirtualImages(const QString& camera, const QStringList& szImages) +{ + if (camera.isEmpty()) + { + m_cameraes.iterateCall(cameraSetVirtuleImages, (void*)&szImages); + } + else + { + m_cameraes.valueCall(camera, cameraSetVirtuleImages, (void*)&szImages); + } +} +void CCameraPool::cameraSetVirtuleImages(class ICameraObject*& pCam, void* pData) +{ + QStringList* pszImages = (QStringList*)pData; + if (pCam->m_pCamOpt->deviceType / 10 == DEV_CAM_VIRTUAL / 10) + { + pCam->ISetVirtualImages(*pszImages); + } +} + +QList CCameraPool::ICamWinKeys() +{ + return gpGlobalCamera->camWinKeys(); +} + +bool CCameraPool::ICamWinOptionByKey(const QString& strKey, TP_CAMERA_WIN& camwinOpt) +{ + + return gpGlobalCamera->camWinByKey(strKey, camwinOpt); +} + +bool CCameraPool::IAddCamWin(const QString& strKey, const TP_CAMERA_WIN& camwinOpt, bool bNew) +{ + return gpGlobalCamera->addCamWin(strKey, camwinOpt, bNew); +} + +bool CCameraPool::IDelCamWin(const QString& strKey) +{ + return gpGlobalCamera->delCamWin(strKey); +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpCamera/CameraPool.h b/src/lpCoreCtrl/tpCamera/CameraPool.h new file mode 100644 index 0000000..4d5af2c --- /dev/null +++ b/src/lpCoreCtrl/tpCamera/CameraPool.h @@ -0,0 +1,150 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:CameraPool.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/25 + History:25:3:2015 11:26 + *******************************************************************************/ +#ifndef __CAMERA_POOL_H_20150325 +#define __CAMERA_POOL_H_20150325 + +#include "icamera.h" +#include +#include +//#include +#include +#include "triggerthread.h" +#include "QZkMutexList.h" +#include "QZkMutexMap.h" +#include "iCameraObject.h" +#include "LibCameraes.h" + + +class CCameraPool : public ICameraPool, public IPoolCallback +{ +public: + CCameraPool(void); + virtual ~CCameraPool(void); + + int InitPool(); + void FreePool(); + int ImagesSize() { + return m_imagesList.size(); + } + void DeviceLost(const QString& strName); + //called by "CTriggerThread" + struct tagCOMMIT_TRIGGER_PARAM{ + emTpTriggerDirection direct; + DWORD count; + bool bFromMenual; + }; + void IntervalCaptureImages(tagCOMMIT_TRIGGER_PARAM& prm); +private: + virtual QList ICameraKeys();//获取相机的keys,在camera.json中配置 + virtual QList ICameraKeysOrderByIds();//获取相机的keys,但根据id排序 + virtual bool ICameraOption(const QString& strSerial, TP_CAMERA_OPTION& camOpt);//根据相机key获取相机的配置属性 + virtual bool ICameraOptionByKey(const QString& strSerial, TP_CAMERA_OPTION& camOpt);//根据相机key获取相机的配置属性 + virtual bool ISetCameraOption(const QString& strSerial, const TP_CAMERA_OPTION& camOpt); + // + virtual int ICreateCameraes(); + virtual void IDeleteDameraes(); + + virtual QList IEnumAvailableCameras(emTpDeviceType camType); // try to get available (connected to the computer) by camera type(manufacturer) + + virtual bool ICreateCamera(const QString& strSerial, int nType); + virtual bool IOpenCamera(const QString& strSerial, bool bReopen); + virtual bool ICloseCamera(const QString& strSerial); + virtual bool IStartCamera(const QString& strSerial); + virtual bool IStopCamera(const QString& strSerial); + virtual bool IDeleteCamera(const QString& strSerial); + virtual bool IAddCamera(const QString& strName, const TP_CAMERA_OPTION& camOpt, bool bNew, bool bAutoRun = false); + + // + virtual int IOpenDevices(bool bReopenAll); + virtual int IOpenDevicesEx(bool bReopenAll); + virtual void ICloseDevices(); + virtual void IStartDevices(); + virtual void IStopDevices(const QString& sDef = NULL); + virtual void ISetTriggerMode(emTpDeviceTriggerMode mode, emTpTriggerDirection nDirection = TRIGGER_DIRECT_FOREWARD, long nFrameRate = 0); + virtual emTpDeviceTriggerMode IGetTriggerMode(){ + return m_nTriggerMode; + } + virtual void IManualTrigger( emTpTriggerDirection nDirection = TRIGGER_DIRECT_FOREWARD); + virtual void ISnapImage(const QStringList& camKeys); + virtual void ISendSoftTrigger(const QStringList& camKeys); + virtual QList ICameraWins(); + virtual CZkCameraImage* IPopCameraImage(); + virtual int ICameraImages() { + return m_imagesList.size(); + } + virtual void IFreeCameraImage(CZkCameraImage *pCamImg); + /////////////////////////////////////////////////////////////////////////////////////// + virtual void ISetCameraProperty(const QString& camera, emTpCameraProperty property, long nValue); + virtual void ISetCameraProperty(const QString& camera, TP_CAMERA_PROPERTY& property); + virtual QMap IGetCamShowNames(); + virtual void ISetCameraEncode(INT64 code, INT64 rate); + virtual void ISetVirtualImages(const QString& camera, const QStringList& szImages); + + //operate camera window + virtual QList ICamWinKeys(); + virtual bool ICamWinOptionByKey(const QString& strKey, TP_CAMERA_WIN& camwinOpt); + virtual bool IAddCamWin(const QString& strKey, const TP_CAMERA_WIN& camwinOpt, bool bNew); + virtual bool IDelCamWin(const QString& strKey); + + virtual bool ICamsStartPush(); + virtual bool ICamsPausePush(); + + /////////////////////////////////////////////////////////////////////////////////////////// +// ICameraObject* CreateCamera(TP_CAMERA_OPTION* pCamOpt); + void calRelyOn(); + /////////////////////////////////////////////////////////////////////////////////////////////// + void releaseImagesList() { + //m_imagesList.iterateCall(iterateCallImageErase, NULL); + m_imagesList.clear(iterateCallImageErase, NULL); + m_imagesMerging.clear(iterateCallImageErase, NULL); + //m_imagesCache.clear(iterateCallImageErase, NULL); + } + static void iterateCallImageErase(class CZkCameraImage*& pImage, void* pData) { + delete pImage; + } + //using class ICameraObject + int createDeviceByOptiones(); + static void cameraOpen(class ICameraObject*& pCam, void* pData); + static void cameraOpenEx(class ICameraObject*& pCam, void* pData); + static void cameraClose(class ICameraObject*& pCam, void* pData); + static void cameraErased(class ICameraObject*& pCam, void* pData); + static void cameraStartDevices(class ICameraObject*& pCam, void* pData); + static void cameraStopDevices(class ICameraObject*& pCam, void* pData); + static void cameraSetTriggerMode(class ICameraObject*& pCam, void* pData); + static void cameraSnaps(class ICameraObject*& pCam, void* pData); + static void cameraIntervalCaptures(class ICameraObject*& pCam, void* pData); + static void cameraCalRelyOn(class ICameraObject*& pCam, void* pData); + static void cameraCalRelyOnEx(class ICameraObject*& pCam, void* pData); + static void cameraSetProperty(class ICameraObject*& pCam, void* pData); + static void fixedFramesStopCamera(class ICameraObject*& pCam, void* pData); + static void cameraSetVirtuleImages(class ICameraObject*& pCam, void* pData); + //IPoolCallback interface + virtual int IPushCameraData(ICameraObject* pCamObj); + virtual int IPushCameraData2(ICameraObject* pCamObj); + virtual char* IGetMainPath(); + + static void camerasStartPush(class ICameraObject*& pCam, void* pData); + static void camerasPausePush(class ICameraObject*& pCam, void* pData); +private: + //**the key is unique name, not serial number** + QZkMutexMap m_imagesMerging; + QZkMutexList m_imagesList; + //QZkMutexMap m_imagesCache; + CTriggerThread m_thdTrigger; + emTpDeviceTriggerMode m_nTriggerMode; + long m_nFrameRate; + ////////////////////////////////////////////////////////////// + QZkMutexMap m_cameraes; + CLibCameraes m_libs; + INT64 m_nCameraEncode; + INT64 m_nEncoderRate; +}; + +#endif \ No newline at end of file diff --git a/src/lpCoreCtrl/tpCamera/LibCameraes.cpp b/src/lpCoreCtrl/tpCamera/LibCameraes.cpp new file mode 100644 index 0000000..7b1fa6d --- /dev/null +++ b/src/lpCoreCtrl/tpCamera/LibCameraes.cpp @@ -0,0 +1,203 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:LibCameraes.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/05/26 + History:26:5:2015 16:34 + *******************************************************************************/ +#include "LibCameraes.h" +#include +#include + +#define PREFIX_API(pfx) \ + extern "C" ICameraObject* pfx##Camera_Create(TP_CAMERA_OPTION* pCamOpt, IPoolCallback* pCb);\ + extern "C" void pfx##Camera_Delete(ICameraObject*); + +#ifndef _USE_CAMERA_DLL + +#ifdef _USE_BITFLOW +PREFIX_API(Bitflow_) +#endif + +#ifdef _USE_VIRTUAL +PREFIX(Virtual_) +#endif + +#ifdef _USE_GIGE +PREFIX(Gige_) +#endif + +#endif + +CLibCameraes::CLibCameraes(char* szPath) + : m_szPath(szPath) +{ + +} + +CLibCameraes::~CLibCameraes() +{ + m_camApiMap.clear(clearCall); +} + +ICameraObject* CLibCameraes::Create(TP_CAMERA_OPTION* pCamOpt, IPoolCallback* pCb) +{ + if( NULL == pCamOpt || NULL == pCb ) + { + return NULL; + } + if( !LoadCameraApi((emTpDeviceType)pCamOpt->deviceType) ) + { + return NULL; + } + CAMERA_API* pApi = m_camApiMap.value(pCamOpt->deviceType, NULL); + if( NULL == pApi || NULL == pApi->fpCreate ) + { + return NULL; + } + ICameraObject* pCam = pApi->fpCreate(pCamOpt, pCb); + if (NULL != pCam) + { + pApi->cameraes++; + } + return pCam; +} + +bool CLibCameraes::Delete(ICameraObject* pCam) +{ + if( NULL == pCam ) + { + return false; + } + int nKey = pCam->m_pCamOpt->deviceType; + CAMERA_API* pApi = m_camApiMap.value(nKey, NULL); + if( NULL == pApi || NULL == pApi->fpDelete ) + { + return false; + } + pApi->fpDelete(pCam); + pApi->cameraes--; + /* + if (0 == pApi->cameraes)//release the dll + { + clearCall(pApi, NULL); + m_camApiMap.remove(nKey); + } + */ + return true; +} + +bool CLibCameraes::LoadCameraApi(emTpDeviceType devType) +{ + if( m_camApiMap.contains(devType) ) + { + return true; + } + CAMERA_API* pApi = new CAMERA_API; + if( NULL == pApi ) + { + return false; + } +#ifdef _USE_CAMERA_DLL + QString fileName(m_szPath); +// if( !fileName.endsWith('\\') && !fileName.endsWith('/') ) +// { +// fileName.append('\\'); +// } + int nType = devType/10 * 10; + QString strAlias; + strAlias = "tpCam_" + QString::number(nType); + + fileName.append(strAlias); +#ifdef _DEBUG + fileName.append('d'); +#endif + // + pApi->pLib = new QLibrary(fileName); + if( NULL == pApi->pLib ) + { + delete pApi; + return false; + } + + pApi->fpCreate = (Func_Create)pApi->pLib->resolve("Camera_Create"); + pApi->fpDelete = (Func_Delete)pApi->pLib->resolve("Camera_Delete"); + if( NULL == pApi->fpCreate || NULL == pApi->fpDelete ) + { + QString strErr = QString("Failed to Load camera's dll: %1; ERROR: %2") + .arg(fileName.toLocal8Bit().data()) + .arg(pApi->pLib->errorString().toLocal8Bit().data()); + qCritical() << strErr << " - " << __FUNCTION__; + + delete pApi->pLib; + delete pApi; + return false; + } +#else + switch(devType) + { + case DEV_CAM_BITFLOW: + pApi->fpCreate = API_NAME_PREFIX(Bitflow_, Camera_Create); + pApi->fpDelete = API_NAME_PREFIX(Bitflow_, Camera_Delete); + break; + case DEV_CAM_VIRTUAL: + pApi->fpCreate = API_NAME_PREFIX(Virtual_, Camera_Create); + pApi->fpDelete = API_NAME_PREFIX(Virtual_, Camera_Delete); + break; + case DEV_CAM_GIGE: + pApi->fpCreate = API_NAME_PREFIX(Gige_, Camera_Create); + pApi->fpDelete = API_NAME_PREFIX(Gige_, Camera_Delete); + break; + case DEV_CAM_USB: + pApi->fpCreate = API_NAME_PREFIX(Usb_, Camera_Create); + pApi->fpDelete = API_NAME_PREFIX(Usb_, Camera_Delete); + break; + default: + delete pApi; + return false; + } +#endif + pApi->cameraes = 0; + m_camApiMap.insert(devType, pApi); + return true; +} + +void CLibCameraes::clearCall(CAMERA_API*& pCamApi, void* pData) +{ +#ifdef _USE_CAMERA_DLL + delete pCamApi->pLib; +#endif + delete pCamApi; +} + +QList CLibCameraes::enumAvailableCameras(TP_CAMERA_OPTION* pCamOpt, IPoolCallback* pCb) +{ + QList ret; + if (!LoadCameraApi((emTpDeviceType)pCamOpt->deviceType)) + { + return ret; + } + CAMERA_API* pApi = m_camApiMap.value(pCamOpt->deviceType, NULL); + if (NULL == pApi || NULL == pApi->fpCreate) + { + return ret; + } + ICameraObject* pCam = pApi->fpCreate(pCamOpt, pCb); + if (NULL != pCam) + { + ret = pCam->IEnumAvailableCameras(); + int nKey = pCam->m_pCamOpt->deviceType; + pApi->fpDelete(pCam); + + if (0 == pApi->cameraes)//release the dll + { + clearCall(pApi, NULL); + + m_camApiMap.remove(nKey); + } + } + + return ret; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpCamera/LibCameraes.h b/src/lpCoreCtrl/tpCamera/LibCameraes.h new file mode 100644 index 0000000..5e7ba68 --- /dev/null +++ b/src/lpCoreCtrl/tpCamera/LibCameraes.h @@ -0,0 +1,54 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:LibCameraes.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/05/26 + History:26:5:2015 16:34 + *******************************************************************************/ +#ifndef LIBCAMERAES_H +#define LIBCAMERAES_H + +#include "iCameraObject.h" +#include "QZkMutexMap.h" +#include +#include + +class CLibCameraes +{ +public: + CLibCameraes(char* szPath); + ~CLibCameraes(); + ICameraObject* Create(TP_CAMERA_OPTION* pCamOpt, IPoolCallback* pCb); + bool Delete(ICameraObject* pCam); + + QList enumAvailableCameras(TP_CAMERA_OPTION* pCamOpt, IPoolCallback* pCb); +private: + typedef ICameraObject*(*Func_Create)(TP_CAMERA_OPTION* pCamOpt, IPoolCallback* pCb); + typedef void(*Func_Delete)(ICameraObject* pCam); + typedef struct tagCAMERA_API { + Func_Create fpCreate; + Func_Delete fpDelete; +#ifdef _USE_CAMERA_DLL + QLibrary* pLib; +#endif + int cameraes; + } CAMERA_API; + bool LoadCameraApi(emTpDeviceType devType); + static void clearCall(CAMERA_API*& pCamApi, void* pData); +private: + QZkMutexMap m_camApiMap; + char* m_szPath; +}; + +inline bool is_dll_library(const QString& name) +{ +#ifdef _DEBUG + return QFile::exists(name + "d.dll"); +#else + return QFile::exists(name + ".dll"); +#endif +} + +#endif // LIBCAMERAES_H diff --git a/src/lpCoreCtrl/tpCamera/globalCamera.cpp b/src/lpCoreCtrl/tpCamera/globalCamera.cpp new file mode 100644 index 0000000..c3867e8 --- /dev/null +++ b/src/lpCoreCtrl/tpCamera/globalCamera.cpp @@ -0,0 +1,460 @@ +/****************************************************************************** +Copyright(C):2015~2018 hzleaper +FileName:globalCamera.cpp +Author:zhikun wu +Email:zk.wu@hzleaper.com +Tools:vs2010 pc on company +Created:2015/04/09 +History:9:4:2015 13:23 +*******************************************************************************/ +#include +#include "globalCamera.h" +#include "ZkCameraImage.h" +#include +#include + +#ifdef _USE_CAMERA_SERIAL_ENCRYPTO +#include "QZkSerialNumbers.h" +#endif + +const char CGlobalCamera::cs_szCfgName[] = "camera"; + +CGlobalCamera::CGlobalCamera(const CAMERA_IN_PARAM* pInParam) + :m_mtxCam(QMutex::Recursive) +{ + m_pCallback = pInParam->pCallback; + m_pGlobalData = pInParam->pGlobalData; + readConfig(); + readSerials(); +} +CGlobalCamera::~CGlobalCamera() +{ + releaseConfig(); +} +bool CGlobalCamera::CameraOption(const QString& serials, TP_CAMERA_OPTION& camOpt) +{ + // camOpt.serials = serials; + return m_cameraesOption.iterateCall(copyCameraOptionBySerial, &camOpt); +} +bool CGlobalCamera::copyCameraOptionBySerial(const QString& key, TP_CAMERA_OPTION*& pCamOpt, void* pData) +{ + TP_CAMERA_OPTION* pDes = (TP_CAMERA_OPTION*)pData; + if (pCamOpt->uniqueName == pDes->uniqueName) + { + *pDes = *pCamOpt; + return true; + } + return false; +} + +bool CGlobalCamera::CameraOptionByKey(const QString& sKey, TP_CAMERA_OPTION& camOpt) +{ + return m_cameraesOption.valueCall(sKey, copyCameraOptionByKey, &camOpt); +} + +void CGlobalCamera::copyCameraOptionByKey(const QString& key, TP_CAMERA_OPTION*& pCamOpt, void* pData) +{ + TP_CAMERA_OPTION* pDes = (TP_CAMERA_OPTION*)pData; + *pDes = *pCamOpt; +} + +bool CGlobalCamera::SetCameraOption(const QString& sKey, const TP_CAMERA_OPTION& camOpt) +{ + TP_CAMERA_OPTION* pOpt = m_cameraesOption.value(sKey, NULL); + if (NULL == pOpt) + { + return false; + } + pOpt->save = camOpt.save; + pOpt->algorithm = camOpt.algorithm; + pOpt->exposure = camOpt.exposure; + pOpt->folder = camOpt.folder; + checkFolder(pOpt->folder); + + pOpt->gain = camOpt.gain; + pOpt->bIgnoreImage = camOpt.bIgnoreImage; + // m_jsonCamera.value("devices").toObject().value(pOpt->uniqueName) + return true; +} + +bool CGlobalCamera::SaveCameraOption(const TP_CAMERA_OPTION& camOpt) +{ + QJsonObject jsonDevices = m_jsonCamera.value("devices").toObject(); + if (jsonDevices.isEmpty()) + { + return false; + } + //TODO:... here + QJsonObject jsonCam = jsonDevices.value(camOpt.uniqueName).toObject(); + if (jsonCam.isEmpty()) + { + return false; + } + jsonCam.insert("folder", camOpt.folder); + + jsonDevices.insert(camOpt.uniqueName, jsonCam); + m_jsonCamera.insert("devices", jsonDevices); + return true; +} + +void CGlobalCamera::readConfig() +{ + int nError; + //read config from ".json" file + QString szFileName(m_pGlobalData->tgdMainPath); + szFileName.append(m_pGlobalData->tgdFolderNames[TP_FOLDER_NAME_CONFIG]).append(cs_szCfgName).append(TP_STR::cszJsonSuffix); + // szFileName.append(TP_STR::cszCfgFolder) + QMutexLocker locker(&m_mtxCam); + QJsonObject objJson = m_jsonCamera = QZkJsonParser::ReadJsonObject(szFileName, &nError); + tpDebugOut("camera.json paths: %s", szFileName.toLocal8Bit().data()); + tpDebugOut("read camera.json result: %d", nError); + if (objJson.isEmpty()) + { + tpDebugOut("fail to read camera.json"); + return; + } + QJsonObject objTmp = objJson["pool"].toObject(); + m_optPool.triggerMode = (emTpDeviceTriggerMode)objTmp.value("triggermode").toInt(0); + m_optPool.triggerDirection = (emTpTriggerDirection)objTmp.value("triggerdirection").toInt(0); + m_optPool.frameRate = objTmp.value("framerate").toInt(0); + m_optPool.fixedFrames = objTmp.value("fixedframes").toInt(0); + // + QJsonValue value = objJson["devices"]; + + QJsonObject userJson = getAppJsonUser(); + QJsonArray objEnableCameras = userJson["enable_cameras"].toArray(); + QStringList enableCamList; + for (int i = 0; i < objEnableCameras.size(); ++i) + { + enableCamList.append(objEnableCameras[i].toString()); + } + if (!value.isUndefined() && value.isObject()) + { + QJsonObject objDevices = value.toObject(); + for (QJsonObject::Iterator it = objDevices.begin(); it != objDevices.end(); ++it) + { + tpDebugOut("Camera key:%s", it.key().toLocal8Bit().data()); + if (!it.value().isObject() || + m_cameraesOption.contains(it.key())) + { + continue; + } + QJsonObject objCam = it.value().toObject(); + TP_CAMERA_OPTION* pCamOpt = new TP_CAMERA_OPTION; + if (NULL == pCamOpt) + { + continue; + } + //inner + pCamOpt->bIgnoreImage = false; + pCamOpt->pSerials = &m_serialsList; + // + pCamOpt->uniqueName = it.key(); + pCamOpt->id = objCam.value("id").toInt(0); + pCamOpt->deviceType = objCam.value("type").toInt(0); + pCamOpt->showName = objCam.value("showname").toString(""); + pCamOpt->width = objCam.value("width").toInt(0); + pCamOpt->height = objCam.value("height").toInt(0); + QJsonValue tempV = objCam.value("format"); + if (tempV.isString()) + { + pCamOpt->format = CZkCameraImage::FromString(tempV.toString()); + } + else + { + pCamOpt->format = TP_COLOR_NONE; + } + pCamOpt->zoom = objCam.value("zoom").toInt(0); + + pCamOpt->folder = objCam.value("folder").toString(".\\"); + ////check if folder valid + //QDir camDir(pCamOpt->folder); + //if (!camDir.exists()) + //{ + // // maybe a relative path, try add app path + // QString strCamFolder = QString(m_pGlobalData->tgdMainPath) + "/" + pCamOpt->folder; + // camDir.setPath(strCamFolder); + // if (camDir.exists()) + // { + // pCamOpt->folder = camDir.absolutePath() + "/"; + // } + //} + + pCamOpt->save = objCam.value("save").toInt(0); + + pCamOpt->saveImgSuffix = objCam.value("save_img_suffix").toString(".BMP"); + if (!TP_FUNCS::isValidImgSuffix(pCamOpt->saveImgSuffix)) + { + pCamOpt->saveImgSuffix = ".BMP"; + } + + pCamOpt->algorithm = objCam.value("algorithm").toInt(pCamOpt->id); + pCamOpt->relyOnCamera = objCam.value("rely_on_camera").toString(); + pCamOpt->exposure = objCam.value("exposure").toInt(0); + pCamOpt->boardType = objCam.value("board_type").toInt(64); + pCamOpt->boardNum = objCam.value("board_num").toInt(0); + pCamOpt->sBoardName = objCam.value("board_name").toString(); + pCamOpt->sBoardConfigFile = objCam.value("board_config_file").toString(); + pCamOpt->gain = objCam.value("gain").toInt(0); + pCamOpt->loop = objCam.value("loop").toInt(0); + pCamOpt->bNeedRgbSwapped = objCam.value("savefile_rgb_swapped").toInt(0); + pCamOpt->macAddress = objCam.value("mac_address").toString(); + pCamOpt->bAutoPush = objCam.value("auto_push").toInt(1); + pCamOpt->bAutoOpen = objCam.value("auto_open").toBool(true); + if (!enableCamList.contains(it.key())){ + pCamOpt->bAutoOpen = false; + } + + pCamOpt->cameraFilePath = objCam.value("camera_file").toString(); + if (objCam.value("algorithm_dll").toDouble()) + { + pCamOpt->dllsuffix = QString::number(objCam.value("algorithm_dll").toInt(pCamOpt->algorithm)); + } + else + { + pCamOpt->dllsuffix = objCam.value("algorithm_dll").toString(QString::number(pCamOpt->algorithm)); + } + //m_cfgCameraes[pCamOpt->uniqueName] = pCamOpt; + checkFolder(pCamOpt->folder); + pCamOpt->status = TP_CAMERA_STATUS_UNINIT; + m_cameraesOption.insert(pCamOpt->uniqueName, pCamOpt); + } + } + objTmp = objJson["windows"].toObject(); + if (!objTmp.isEmpty()) + { + for (QJsonObject::Iterator it = objTmp.begin(); it != objTmp.end(); ++it) + { + QJsonObject objWin = it.value().toObject(); + if (objWin.isEmpty()) + { + continue; + } + TP_CAMERA_WIN* pWin = new TP_CAMERA_WIN; + if (NULL == pWin) + { + continue; + } + pWin->key = it.key(); + pWin->device = objWin.value("device").toString(); + pWin->images = objWin.value("images").toInt(1); + pWin->buffers = objWin.value("buffers").toInt(2); + pWin->bitsPerPixel = objWin.value("bitsperpixel").toInt(32); + pWin->index = objWin.value("index").toInt(0); + pWin->bufferW = objWin.value("buffer_w").toInt(0); + pWin->bufferH = objWin.value("buffer_h").toInt(0); + pWin->mirror = objWin.value("mirror").toInt(0); + pWin->bCacheOriginImage = objWin.value("cache_origin").toBool(); + pWin->bNeedRgbSwapped = objWin.value("rgb_swapped").toBool(); + m_cameraWins.append(pWin); + } + } +} + +void CGlobalCamera::checkFolder(QString& sFolder) +{ + if (sFolder.startsWith(".\\")) + { + sFolder.replace(".\\", m_pGlobalData->tgdMainPath); + } + if (!sFolder.endsWith('\\')) + { + sFolder.append('\\'); + } +} + +void CGlobalCamera::releaseConfig(const QString& key /* = NULL */) +{ + m_cameraesOption.clear(releaseCameraOption); + m_cameraWins.clear(releaseCameraWin, NULL); +} + +void CGlobalCamera::releaseCameraOption(const QString& key, TP_CAMERA_OPTION*& pCamOpt, void* pData) +{ + delete pCamOpt; +} + +void CGlobalCamera::releaseCameraWin(tagTP_CAMERA_WIN*& pWin, void* pData) +{ + delete pWin; +} + +QList CGlobalCamera::CameraKeysOrderByIds() +{ + QList options = m_cameraesOption.values(); + qSort(options.begin(), options.end(), optionCompare); + QList strList; + for (QList::Iterator it = options.begin(); it != options.end(); ++it) + { + strList.append((*it)->uniqueName); + } + return strList; +} + +bool CGlobalCamera::optionCompare(TP_CAMERA_OPTION* op1, TP_CAMERA_OPTION* op2) +{ + return (op1->id < op2->id); +} + +QMap CGlobalCamera::GetCamShowNames() +{ + QMap knMap; + for (QZkMutexMap::iterator it = m_cameraesOption.begin(); it != m_cameraesOption.end(); ++it) + { + knMap.insert(it.key(), it.value()->showName); + } + //for (QZkMutexList::Iterator it = m_cameraWins.begin(); it != m_cameraWins.end(); ++it) + //{ + // if (0 == (*it)->index && m_cameraesOption.contains((*it)->device)) + // { + // knMap.insert((*it)->device, (*it)->key); + // } + //} + return knMap; +} + +void CGlobalCamera::readSerials() +{ +#ifdef _USE_CAMERA_SERIAL_ENCRYPTO + QString szFileName(m_pGlobalData->tgdMainPath); + szFileName.append("serials.dat"); + QZkSerialNumbers serials; + QList bytes = serials.AddFileName(szFileName); + for (QList::iterator it = bytes.begin(); it != bytes.end(); ++it) + { + m_serialsList.append(QString::fromUtf8(*it)); + } +#endif +} + +void CGlobalCamera::delCameraOption(const QString& serials) +{ + QMutexLocker locker(&m_mtxCam); + + TP_CAMERA_OPTION* pcamOpt = m_cameraesOption.value(serials); + if (pcamOpt){ + m_cameraesOption.remove(serials); + delete pcamOpt; + pcamOpt = NULL; + } +} + +void CGlobalCamera::updateCameraOption(const QString& serials, const TP_CAMERA_OPTION& camOpt) +{ + QMutexLocker locker(&m_mtxCam); + + // update if exist, otherwise new one. + if (m_cameraesOption.contains(serials)) + { + TP_CAMERA_OPTION* pCamOpt = m_cameraesOption.value(serials); + emTpCameraStatus oldStatus = pCamOpt->status; + *pCamOpt = camOpt; + pCamOpt->status = oldStatus; + pCamOpt->pSerials = &m_serialsList; + return; + } + + TP_CAMERA_OPTION* pCamOpt = new TP_CAMERA_OPTION; + if (NULL == pCamOpt) return; + + *pCamOpt = camOpt; + pCamOpt->pSerials = &m_serialsList; + m_cameraesOption.insert(pCamOpt->uniqueName, pCamOpt); +} + +QList CGlobalCamera::camWinKeys() +{ + QMutexLocker locker(&m_mtxCam); + + QList ret; + QZkMutexList::const_iterator it = m_cameraWins.constBegin(); + for (; it != m_cameraWins.constEnd(); ++it) + { + ret.append((*it)->key); + } + return ret; +} + +bool CGlobalCamera::camWinByKey(const QString& strKey, TP_CAMERA_WIN& camwinOpt) +{ + QMutexLocker locker(&m_mtxCam); + QZkMutexList::const_iterator it = m_cameraWins.constBegin(); + for (; it != m_cameraWins.constEnd(); ++it) + { + TP_CAMERA_WIN* pOpt = *it; + if (pOpt->key.compare(strKey, Qt::CaseInsensitive) == 0){ + camwinOpt = *pOpt; + return true; + } + } + return false; +} + +bool CGlobalCamera::addCamWin(const QString& strKey, const TP_CAMERA_WIN& camwinOpt, bool bNew) +{ + QMutexLocker locker(&m_mtxCam); + + // update if exist, otherwise new one. + QZkMutexList::iterator it = m_cameraWins.begin(); + for (; it != m_cameraWins.end(); ++it) + { + TP_CAMERA_WIN* pOpt = *it; + if (pOpt->key.compare(strKey, Qt::CaseInsensitive) == 0){ + *pOpt = camwinOpt; + return true; + } + } + + TP_CAMERA_WIN* pOpt = new TP_CAMERA_WIN; + if (NULL == pOpt) return false; + + *pOpt = camwinOpt; + m_cameraWins.append(pOpt); + + return true; +} + +bool CGlobalCamera::delCamWin(const QString& strKey) +{ + QMutexLocker locker(&m_mtxCam); + QZkMutexList::iterator it = m_cameraWins.begin(); + for (; it != m_cameraWins.end(); ++it) + { + TP_CAMERA_WIN* pOpt = *it; + if (pOpt->key.compare(strKey, Qt::CaseInsensitive) == 0){ + m_cameraWins.removeOne(pOpt); + delete pOpt; + pOpt = NULL; + return true; + } + } + return true; +} + +QJsonObject CGlobalCamera::getAppJsonUser() +{ + QJsonObject userJson; + + QString strUiPath(m_pGlobalData->tgdMainPath); + strUiPath.append(m_pGlobalData->tgdFolderNames[TP_FOLDER_NAME_UI]); + + QString strAppJsonPath(strUiPath); + strAppJsonPath.append(QCoreApplication::applicationName()); +#ifdef _DEBUG + if (strAppJsonPath.endsWith('d')) + { + strAppJsonPath.chop(1); + } +#endif + strAppJsonPath.append(".json"); + if (!QFile::exists(strAppJsonPath)) + { + strAppJsonPath = strUiPath + "app.json"; + } + + int nerr; + QJsonObject objJson = QZkJsonParser::ReadJsonObject(strAppJsonPath, &nerr); + + userJson = objJson["user"].toObject(); + return userJson; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpCamera/globalCamera.h b/src/lpCoreCtrl/tpCamera/globalCamera.h new file mode 100644 index 0000000..6effc86 --- /dev/null +++ b/src/lpCoreCtrl/tpCamera/globalCamera.h @@ -0,0 +1,97 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:globalCamera.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/07 + History:7:4:2015 8:53 + *******************************************************************************/ +#ifndef __GLOBAL_CAMERA_H_20150407 +#define __GLOBAL_CAMERA_H_20150407 + +#include "icamera.h" +#include "iCameraObject.h" +#include "QZkJsonParser.h" +#include +#include +#include +#include "QZkMutexMap.h" +#include "QZkMutexList.h" + + + +class CGlobalCamera +{ +public: + CGlobalCamera(const CAMERA_IN_PARAM* pInParam); + ~CGlobalCamera(); + bool CameraOption(const QString& serials, TP_CAMERA_OPTION& camOpt); + bool CameraOptionByKey(const QString& sKey, TP_CAMERA_OPTION& camOpt); + bool SetCameraOption(const QString& sKey, const TP_CAMERA_OPTION& camOpt); + TP_CAMERA_OPTION* CameraOption(const QString& serials) { + return m_cameraesOption.value(serials, NULL); + } + QList CameraKeys() { + return m_cameraesOption.keys(); + } + QList CameraKeysOrderByIds(); + QList CameraWins() { + return m_cameraWins; + } + QMap GetCamShowNames(); + bool SaveCameraOption(const TP_CAMERA_OPTION& camOpt); + void delCameraOption(const QString& serials); + void updateCameraOption(const QString& serials, const TP_CAMERA_OPTION& camOpt); + + QList camWinKeys(); + bool camWinByKey(const QString& strKey, TP_CAMERA_WIN& camwinOpt); + bool addCamWin(const QString& strKey, const TP_CAMERA_WIN& camwinOpt, bool bNew); + bool delCamWin(const QString& strKey); + +public: + TP_GLOBAL_DATA* m_pGlobalData; + ICameraCallback* m_pCallback; +// QHash m_cfgCameraes; + TP_CAMERAPOOL_OPTION m_optPool; +private: + void readConfig(); + void releaseConfig(const QString& key = NULL); + void checkFolder(QString& sFolder); + void readSerials(); + QJsonObject getAppJsonUser(); + + static void releaseCameraOption(const QString& key, TP_CAMERA_OPTION*& pCamOpt, void* pData); + static bool copyCameraOptionBySerial(const QString& key, TP_CAMERA_OPTION*& pCamOpt, void* pData); + static void copyCameraOptionByKey(const QString& key, TP_CAMERA_OPTION*& pCamOpt, void* pData); + static bool optionCompare(TP_CAMERA_OPTION* op1, TP_CAMERA_OPTION* op2); + static void releaseCameraWin(tagTP_CAMERA_WIN*& pWin, void* pData); +private: + QMutex m_mtxCam; + const static char cs_szCfgName[]; + QZkMutexMap m_cameraesOption; + QZkMutexList m_cameraWins; + QJsonObject m_jsonCamera; + QStringList m_serialsList; +}; +//const char CGlobalCamera::m_szCfgFile[] = "camera"; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +//***inline functions*** + + + +extern class CGlobalCamera* gpGlobalCameraZZZ; + +#define gpGlobalCamera gpGlobalCameraZZZ + +//#define gpMainPath gpGlobalCamera->m_pszMainPath +#define gpGlobalData gpGlobalCamera->m_pGlobalData +#define gpGlobalCamCallback gpGlobalCamera->m_pCallback +#define callCamCallback(fc, defaultReturn, ...) (NULL != gpGlobalCamCallback) ? gpGlobalCamCallback->##fc##(__VA_ARGS__) : defaultReturn +// #define callGlobalCamera(fc, dValue, ...) (NULL != gpGlobalCamera ) ? gpGlobalCamera->##fc##(__VA_ARGS__) : dValue +// #define callGlobalCameraNoP(fc, dValue) (NULL != gpGlobalCamera ) ? gpGlobalCamera->##fc##() : dValue +//#define gpCameraesHash() (NULL != gpGlobalCamera) ? gpGlobalCamera->m_cfgCameraes : QHash() +#define gGlobalPoolOption gpGlobalCamera->m_optPool + +#endif \ No newline at end of file diff --git a/src/lpCoreCtrl/tpCamera/tpCamera.cpp b/src/lpCoreCtrl/tpCamera/tpCamera.cpp new file mode 100644 index 0000000..23d6822 --- /dev/null +++ b/src/lpCoreCtrl/tpCamera/tpCamera.cpp @@ -0,0 +1,60 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:tpCamera.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/23 + History:23:3:2015 16:31 + *******************************************************************************/ +#include "CameraPool.h" +#include "globalCamera.h" + +#ifdef TPCAMERA_EXPORTS +#define TPCAMERA_API extern "C" __declspec(dllexport) +#else +#define TPCAMERA_API extern "C" +#endif + +CGlobalCamera* gpGlobalCameraZZZ = NULL; +CCameraPool *gpCameraPool = NULL; + + +//don't change the names of these global functions +TPCAMERA_API void* Lib_Camera_Init(void* inParam) +{ + CAMERA_IN_PARAM cinParam = {0}; + if( NULL != inParam ) + { + std::memcpy(&cinParam, inParam, sizeof(CAMERA_IN_PARAM)); + } + if( NULL == gpGlobalCamera ) + { + gpGlobalCamera = new CGlobalCamera(&cinParam); + } + // + if( NULL == gpCameraPool ) + { + gpCameraPool = new CCameraPool(); + } + if( NULL != gpCameraPool ) + { + gpCameraPool->InitPool(); + } + return gpCameraPool; +} + +TPCAMERA_API void Lib_Camera_Free() +{ + if( NULL != gpCameraPool ) + { + gpCameraPool->FreePool(); + delete gpCameraPool; + gpCameraPool = NULL; + } + if( NULL != gpGlobalCamera ) + { + delete gpGlobalCamera; + gpGlobalCamera = NULL; + } +} diff --git a/src/lpCoreCtrl/tpCamera/triggerthread.cpp b/src/lpCoreCtrl/tpCamera/triggerthread.cpp new file mode 100644 index 0000000..ba61f0f --- /dev/null +++ b/src/lpCoreCtrl/tpCamera/triggerthread.cpp @@ -0,0 +1,61 @@ +#include "triggerthread.h" +#include "CameraPool.h" +#include "globalCamera.h" + +CTriggerThread::CTriggerThread(class CCameraPool* pPool, QObject *parent /* = NULL */) + : QTpThreadBase(parent) + , m_pPool(pPool) +{ + m_msecOfInterval = 0; + m_nTriggerCount = 0; + m_bAutoTrigger = false; +} + +CTriggerThread::~CTriggerThread() +{ + EndTrigger(); +} + +void CTriggerThread::SetFrame(long nFrameRate) +{ + if( nFrameRate <= 0 ) + { + m_msecOfInterval = 0; + } + else + { + m_msecOfInterval = 1000 / nFrameRate; + } +} +void CTriggerThread::StartTrigger() +{ + EndThread(); + m_LastTriggerTime = QTime::currentTime(); + StartThread(); +} + +void CTriggerThread::EndTrigger() +{ + EndThread(); +} + +bool CTriggerThread::loop() +{ + if( m_bAutoTrigger && m_pPool->ImagesSize() < 32) + { + QMutexLocker locker(&m_mutexWorked); + QTime nowTime = QTime::currentTime(); + int nIntervals = m_LastTriggerTime.msecsTo(nowTime); + if (nIntervals >= m_msecOfInterval) + { + CCameraPool::tagCOMMIT_TRIGGER_PARAM prm; + prm.direct = gGlobalPoolOption.triggerDirection; + prm.count = ++m_nTriggerCount; + prm.bFromMenual = false; + m_pPool->IntervalCaptureImages(prm); + m_LastTriggerTime = nowTime; + } + } + msleep(5); + return true; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpCamera/triggerthread.h b/src/lpCoreCtrl/tpCamera/triggerthread.h new file mode 100644 index 0000000..a6b4768 --- /dev/null +++ b/src/lpCoreCtrl/tpCamera/triggerthread.h @@ -0,0 +1,37 @@ +#ifndef TRIGGERTHREAD_H +#define TRIGGERTHREAD_H + +#include "qtpthreadbase.h" +#include +#include +#include "globalCamera.h" + +class CTriggerThread : public QTpThreadBase +{ +public: + CTriggerThread(class CCameraPool* pPool, QObject *parent = NULL); + ~CTriggerThread(); + void SetFrame(long nFrameRate); + void StartTrigger(); + void EndTrigger(); + void LockWorked() { + m_mutexWorked.lock(); + } + void UnlockWorked() { + m_mutexWorked.unlock(); + } + void SetAutoTrigger(bool bAuto) { + m_bAutoTrigger = bAuto; + } +private: + virtual bool loop(); +private: + class CCameraPool* m_pPool; + DWORD m_msecOfInterval; + QTime m_LastTriggerTime; + DWORD m_nTriggerCount; + QMutex m_mutexWorked; + bool m_bAutoTrigger; +}; + +#endif // TRIGGERTHREAD_H diff --git a/src/lpCoreCtrl/tpCoreCtrl.cpp b/src/lpCoreCtrl/tpCoreCtrl.cpp new file mode 100644 index 0000000..d415292 --- /dev/null +++ b/src/lpCoreCtrl/tpCoreCtrl.cpp @@ -0,0 +1,75 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:tpCoreCtrl.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/24 + History:24:3:2015 12:46 + *******************************************************************************/ +#include "CoreCtrl.h" + +#ifdef TPCORECTRL_EXPORTS +#define TPCORECTRL_API extern "C" __declspec(dllexport) +#else +#define TPCORECTRL_API extern "C" +#endif + +#include "ModulesManager.h" +#include "globalCoreCtrl.h" +#include + +CModulesManager gMdlesMgr; +CGlobalCoreCtrl* gpData = NULL; + +class CCoreCtrl* gpCoreCtrl = NULL; + +TPCORECTRL_API void* Lib_CoreCtrl_Init(void* inParam) +{ + CORE_CTRL_LOG("Lib_CoreCtrl_Init start!"); + //create and initialize the global data(class CGlobalCoreCtrl's object) + CORE_CTRL_IN_PARAM* pCciParam = (CORE_CTRL_IN_PARAM*)inParam; + gpData = new CGlobalCoreCtrl(pCciParam); + if( NULL == gpData ) + { + return NULL; + } + // + CORE_CTRL_INIT(gpGlobalData->tgdMainPath, gpGlobalData->tgdMainPath); + // + if( gMdlesMgr.LoadModules() <= 0 ) + { + return NULL; + } + ////////////////////////////////////////////////////////////////// + if( NULL == gpCoreCtrl ) + { + gpCoreCtrl = new CCoreCtrl(); + } + /* + if( NULL != gpCoreCtrl ) + { + gpCoreCtrl->IInitCore(); + } + */ + CORE_CTRL_LOG("Lib_CoreCtrl_Init finished!"); + return gpCoreCtrl; +} + +TPCORECTRL_API void Lib_CoreCtrl_Free() +{ + if( NULL != gpCoreCtrl ) + { + gpCoreCtrl->IFreeCore(); + delete gpCoreCtrl; + gpCoreCtrl = NULL; + } + ///////////////////////////////////////////////// + gMdlesMgr.FreeModules(); + CORE_CTRL_FREE(); + if( NULL != gpData ) + { + delete gpData; + gpData = NULL; + } +} diff --git a/src/lpCoreCtrl/tpImgProc/AlgorithmOption.cpp b/src/lpCoreCtrl/tpImgProc/AlgorithmOption.cpp new file mode 100644 index 0000000..5329c92 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/AlgorithmOption.cpp @@ -0,0 +1,178 @@ +#include "AlgorithmOption.h" +#include "baseConstant.h" + +const char CAlgorithmOption::cs_szSuffix[] = ".dat"; + +CAlgorithmOption::CAlgorithmOption(const QString& strFile, int nAlgorithm, QSqliteAlgorithm* pDbAlg) + : m_pDbAlg(pDbAlg) +{ + m_fileName = strFile; + m_nAlgorithm = nAlgorithm; + QString szFileName = strFile + "_" + QString::number(nAlgorithm); + szFileName.append(TP_STR::cszJsonSuffix).append(cs_szSuffix); + int error = -1; + m_objJson = QZkJsonParser::ReadJsonObject(szFileName, &error); + if (0 != error) + { + szFileName = strFile + "_" + QString::number(nAlgorithm); + szFileName.append(TP_STR::cszJsonSuffix); + m_objJson = QZkJsonParser::ReadJsonObject(szFileName, &error); + } + m_bNeedSave = false; + m_nAlgorithmsUsings = 0; + m_pDbAlg->CreateTable(nAlgorithm); +} + +CAlgorithmOption::~CAlgorithmOption() +{ + +} + +int CAlgorithmOption::GetIntValue(const QString& skey, int nDefault) +{ + QJsonValue v = m_objJson.value(skey); + if (v.isUndefined() || !v.isDouble()) + { + Insert(skey, QJsonValue(nDefault)); + return nDefault; + } + else + { + return v.toInt(nDefault); + } +} + +void CAlgorithmOption::SetIntValue(const QString& skey, int value) +{ + Insert(skey, QJsonValue(value)); +} + +QString CAlgorithmOption::GetStringValue(const QString& skey, const QString& default/* = ""*/) +{ + QJsonValue v = m_objJson.value(skey); + if (v.isUndefined() || !v.isString()) + { + Insert(skey, QJsonValue(default)); + return default; + } + else + { + return v.toString(); + } +} + +void CAlgorithmOption::SetStringValue(const QString& skey, const QString& value) +{ + Insert(skey, QJsonValue(value)); +} + +QJsonObject CAlgorithmOption::GetObjectValue(const QString& skey) +{ + QJsonValue v = m_objJson.value(skey); + if (v.isUndefined() || !v.isString()) + { + return QJsonObject(); + } + else + { + return v.toObject(); + } +} + +bool CAlgorithmOption::Save(bool bWait/* = true*/) +{ + if (!m_bNeedSave) + { + return true; + } + if (!bWait) + { + if (!m_wLock.tryLockForWrite()) + { + return false; + } + } + else + { + m_wLock.lockForWrite(); + } + //if (!m_bNeedSave || !m_wLock.tryLockForWrite()) + //{ + // return; + //} + QString szFileName = m_fileName + "_" + QString::number(m_nAlgorithm); + szFileName.append(TP_STR::cszJsonSuffix).append(cs_szSuffix); + bool b = QZkJsonParser::WriteJsonObject(szFileName, m_objJson); + m_bNeedSave = !b; + m_wLock.unlock(); + return b; +} + +QVariantMap CAlgorithmOption::VariantMap() +{ + return m_objJson.toVariantMap(); +} + +bool CAlgorithmOption::DbSetValue(const QString& key, int type, const QBuffer& data) +{ + if (NULL == m_pDbAlg) + { + return false; + } + return m_pDbAlg->ReplaceRecord(m_nAlgorithm, key, type, data.buffer()); +} + +bool CAlgorithmOption::DbSetValue(const QString& key, int type, const QByteArray& data) +{ + if (NULL == m_pDbAlg) + { + return false; + } + return m_pDbAlg->ReplaceRecord(m_nAlgorithm, key, type, data); +} + +bool CAlgorithmOption::DbDelValue(const QString& key) +{ + if (NULL == m_pDbAlg) + { + return false; + } + return m_pDbAlg->DeleteRecord(m_nAlgorithm, key); +} + +bool CAlgorithmOption::DbGetValue(const QString& key, int type, QByteArray& data) +{ + if (NULL == m_pDbAlg) + { + return false; + } + return m_pDbAlg->ReadRecord(m_nAlgorithm, key, type, data); + //m_pDbAlg->ReplaceRecord(m_nAlgorithm, key, type, data); +} + +QStringList CAlgorithmOption::DbGetKeysByType(int type) +{ + if (NULL == m_pDbAlg) + { + return QStringList(); + } + return m_pDbAlg->KeysByType(m_nAlgorithm, type); +} + +QVariant CAlgorithmOption::GetValue(const QString& skey, const QVariant& def) +{ + QJsonValue v = m_objJson.value(skey); + if (v.isUndefined()) + { + Insert(skey, QJsonValue::fromVariant(def)); + return def; + } + else + { + return v.toVariant(); + } +} +void CAlgorithmOption::SetValue(const QString& skey, const QVariant& value) +{ + Insert(skey, QJsonValue::fromVariant(value)); +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpImgProc/AlgorithmOption.h b/src/lpCoreCtrl/tpImgProc/AlgorithmOption.h new file mode 100644 index 0000000..b3e1003 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/AlgorithmOption.h @@ -0,0 +1,47 @@ +#ifndef CALGORITHMOPTION_H +#define CALGORITHMOPTION_H + +#include "iAlgorithm.h" +#include +#include "QZkJsonParser.h" +#include +#include "QSqliteAlgorithm.h" + +class CAlgorithmOption : public IAlgorithmOption +{ +public: + CAlgorithmOption(const QString& strFile, int nAlgorithm, QSqliteAlgorithm* pDbAlg); + ~CAlgorithmOption(); + virtual int GetIntValue(const QString& skey, int nDefault); + virtual void SetIntValue(const QString& skey, int value); + virtual QString GetStringValue(const QString& skey, const QString& default = ""); + virtual void SetStringValue(const QString& skey, const QString& value); + virtual QJsonObject GetObjectValue(const QString& skey); + virtual bool Save(bool bWait = true); + virtual QVariantMap VariantMap(); + virtual bool DbSetValue(const QString& key, int type, const QBuffer& data); + virtual bool DbSetValue(const QString& key, int type, const QByteArray& data); + virtual bool DbDelValue(const QString& key); + virtual bool DbGetValue(const QString& key, int type, QByteArray& data); + virtual QStringList DbGetKeysByType(int type); + virtual QVariant GetValue(const QString& skey, const QVariant& def); + virtual void SetValue(const QString& skey, const QVariant& value); +private: + void Insert(const QString& skey, const QJsonValue& v) { + QWriteLocker locker(&m_wLock); + m_objJson.insert(skey, v); + m_bNeedSave = true; + tpDebugOut("Insert value in algorithm_%d.json;key=%s, value=%s", m_nAlgorithm, skey.toLocal8Bit().data(), v.toString("NULL").toLocal8Bit().data()); + } +private: + QJsonObject m_objJson; + int m_nAlgorithm; + QString m_fileName; + int m_nAlgorithmsUsings; + bool m_bNeedSave; + QReadWriteLock m_wLock; + const static char cs_szSuffix[]; + QSqliteAlgorithm* m_pDbAlg; +}; + +#endif // CALGORITHMOPTION_H diff --git a/src/lpCoreCtrl/tpImgProc/IImageAlgorithm.cpp b/src/lpCoreCtrl/tpImgProc/IImageAlgorithm.cpp new file mode 100644 index 0000000..987e906 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/IImageAlgorithm.cpp @@ -0,0 +1,28 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:IImageAlgorithm.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/22 + History:22:4:2015 13:34 + *******************************************************************************/ +#include "IImageAlgorithm.h" +#include "ImgProc.h" + +IImageAlgorithm::IImageAlgorithm(class CImgProc* pImgProc) + : m_pImgProc(pImgProc) +{ + +} + +IImageAlgorithm::~IImageAlgorithm() +{ + +} + +int IImageAlgorithm::ImageAnalysis(class IImageObject* pImgObj, TP_ALGORITHM_OPTION* pOpt) +{ + int nRet = IaImageAnalysis(pImgObj, pOpt); + return nRet; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpImgProc/IImageAlgorithm.h b/src/lpCoreCtrl/tpImgProc/IImageAlgorithm.h new file mode 100644 index 0000000..6c13bcc --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/IImageAlgorithm.h @@ -0,0 +1,30 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:IImageAlgorithm.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/22 + History:22:4:2015 13:34 + *******************************************************************************/ +#ifndef IIMAGEALGORITHM_H +#define IIMAGEALGORITHM_H + +#include "iImgProc.h" + +class IImageAlgorithm +{ +public: + IImageAlgorithm(class CImgProc* pImgProc); + virtual ~IImageAlgorithm(); + + virtual int ImageAnalysis(class IImageObject* pImgObj, TP_ALGORITHM_OPTION* pOpt); +protected: +private: + virtual int IaImageAnalysis(class IImageObject* pImgObj, const TP_ALGORITHM_OPTION* pAlgOpt) = 0; +private: + class CImgProc* m_pImgProc; +}; + + +#endif // IIMAGEALGORITHM_H diff --git a/src/lpCoreCtrl/tpImgProc/ImageAlgorithm.cpp b/src/lpCoreCtrl/tpImgProc/ImageAlgorithm.cpp new file mode 100644 index 0000000..35f36b1 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/ImageAlgorithm.cpp @@ -0,0 +1,23 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ImageAlgorithm.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/21 + History:21:4:2015 9:58 + *******************************************************************************/ +#include "ImageAlgorithm.h" + +// CImageAlgorithm::CImageAlgorithm(class CImgProc* pImgProc) +// : IImageAlgorithm(pImgProc) +// , m_pThis(this) +// { +// m_pSelfData = new tagIMAGE_DATA;//NULL; +// std::memset(m_pSelfData, 0, sizeof(tagIMAGE_DATA)); +// } +// +// CImageAlgorithm::~CImageAlgorithm() +// { +// delete m_pSelfData; +// } diff --git a/src/lpCoreCtrl/tpImgProc/ImageAlgorithm.h b/src/lpCoreCtrl/tpImgProc/ImageAlgorithm.h new file mode 100644 index 0000000..787aa39 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/ImageAlgorithm.h @@ -0,0 +1,34 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ImageAlgorithm.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/04/21 + History:21:4:2015 9:58 + *******************************************************************************/ +#ifndef IMAGEALGORITHM_H +#define IMAGEALGORITHM_H + +#include "baseDefine.h" +#include "baseStruct.h" +#include "iImgProc.h" + +#include "IImageAlgorithm.h" + +#define THIS (class IImageAlgorithm*) + + +class CImageAlgorithm : public IImageAlgorithm +{ +public: + CImageAlgorithm(class CImgProc* pImgProc); + virtual ~CImageAlgorithm(); + +private: + virtual int IaImageAnalysis(class IImageObject* pImgObj, const TP_ALGORITHM_OPTION* pAlgOpt); + void* m_pSelfData; + class IImageAlgorithm* m_pThis; +}; + +#endif // IMAGEALGORITHM_H diff --git a/src/lpCoreCtrl/tpImgProc/ImgProc.cpp b/src/lpCoreCtrl/tpImgProc/ImgProc.cpp new file mode 100644 index 0000000..d81ce34 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/ImgProc.cpp @@ -0,0 +1,217 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ImgProc.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/26 + History:26:3:2015 18:03 + *******************************************************************************/ +#include "ImgProc.h" +#include "baseConstant.h" +#include +#include +#include "QZkJsonParser.h" +#include "zfunctions.h" + +/////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +const char CImgProc::cs_strCfgName[] = "algorithm"; +TP_GLOBAL_DATA* CImgProc::s_pGlobalData = NULL; + +CImgProc::CImgProc(IMGPROC_IN_PARAM* pParam) + : m_dbAlg(pParam->pGlobalData->tgdUserPath) +{ + s_pGlobalData = pParam->pGlobalData; + m_bIsInited = false; + m_nAlgorithmsUsings = 0; + m_pDefAlgorithmDll = NULL; +} + +CImgProc::~CImgProc(void) +{ + FreeProc(); +} + +int CImgProc::InitProc() +{ + m_pDefAlgorithmDll = createAlgorithmDll("0", NULL); + //if (NULL == m_pDefAlgorithmDll) + //{ + // return 0; + //} + m_bIsInited = true; + return 1; +} + +void CImgProc::FreeProc() +{ + m_bIsInited = false; + while( m_nAlgorithmsUsings > 0 ) + { + QThread::msleep(25); + } + // m_algorithms.clear(releaseAlgorithm); + m_threadAlgorithms.clear(releaseAlgorithmApis); + m_algorithmOptions.clear(releaseAlgorithmOption); + m_algorithmDlls.clear(releaseAlgorithmDlls); + if (NULL != m_pDefAlgorithmDll) + { + delete m_pDefAlgorithmDll; + m_pDefAlgorithmDll = NULL; + } +} + +void CImgProc::releaseAlgorithm(const Qt::HANDLE& k, IAlgorithm*& v, void* pData) +{ + //Algorithm_Delete(v); + //FREE_ALGORITHM(v); +} + +void CImgProc::releaseAlgorithmOption(const int& k, CAlgorithmOption*& v, void* pData) +{ + delete v; +} + +CAlgorithmOption* CImgProc::createAlgorithmOption(const int& k, void* pData) +{ + CImgProc* pThis = (CImgProc*)pData; + QString szFileName(s_pGlobalData->tgdMainPath); + szFileName.append(s_pGlobalData->tgdFolderNames[TP_FOLDER_NAME_CONFIG]).append(cs_strCfgName); + CAlgorithmOption* pv = new CAlgorithmOption(szFileName, k, &pThis->m_dbAlg); + return pv; +} + +int CImgProc::IImageProcess(class IImageObject* pImgObj, class IDetectorEngine* pDE /*= NULL*/) +{ + if (NULL == pImgObj || !m_bIsInited) + { + return 0; + } + QZK::QAtomicIntAdder adder(m_nAlgorithmsUsings);//Img退出,删除AlgorithmOption有用,需要等所有的算法都用完了才可以删除 + //获取算法相关的参数 + TP_ALGORITHM_OPTION algOption; + algOption.algorithm = pImgObj->IGetAlgorithm();//获取算法数值,camera.json中的设置 + CAlgorithmOption* pAlgOpt = m_algorithmOptions.value2(algOption.algorithm, createAlgorithmOption, this);//列表中不包含相关参数就创建一个参数相关的Option对象 + algOption.pImagProcCb = pAlgOpt; + ///////////////////////////////////////////////////////////////////////// + Qt::HANDLE h = QThread::currentThreadId();//或取当前线程的ID + QString dllSuffix = QString::fromUtf8(pImgObj->IDllSuffix()); + // + tagALGORITHM_API* pApiNode = m_threadAlgorithms[h].value(dllSuffix);//获取当前线程的算法对象, + if (NULL == pApiNode)//若获取算法对象不成功,则需要创建一个 + { + CLoadAlgorithm* pDll = NULL; + if (0 == algOption.algorithm || (pDll = m_algorithmDlls.value2(dllSuffix, createAlgorithmDll, NULL)) == NULL)//根据算法库的后缀加载相应的tpAlgorithm_*.dll + { + pDll = m_pDefAlgorithmDll;//如果带后缀的算法库加载失败,则用默认的tpAlgorithm.dll算法库 + } + if (NULL == pDll) + { + //qWarning() << "Failed to " + return 0; + } + pApiNode = new tagALGORITHM_API; + if (NULL == pApiNode) + { + return 0; + } + pApiNode->pApi = pDll->m_fAlgCreata(pDE);//获取算法库中的类对象 + if (NULL == pApiNode->pApi) + { + delete pApiNode; + return 0; + } + pApiNode->pDll = pDll; + m_threadAlgorithms[h].insert(dllSuffix, pApiNode);//存储当前线程用到的类对象 + } + + //qWarning() << "ImageAnalysis Start: " << QDateTime::currentMSecsSinceEpoch() + // << " Image ID : " << pImgObj->IGetFrameNum() + // << " Thread ID : " << QThread::currentThreadId() + // << endl; + + int nRet = pApiNode->pApi->IImageAnalysis(pImgObj, &algOption, pDE); + try + { + // nRet = pApiNode->pApi->IImageAnalysis(pImgObj, &algOption, pDE); + } + catch (...) + { + qWarning() << "ERROR: Algorithm Crash!!! " + << "Image URL:" + << QString(pImgObj->IGetImageUtf8String()) + << endl; + QVariantMap vMap; + vMap.insert("ui_error", "ERROR: Algorithm Crash!!! Image URL:" + QString(pImgObj->IGetImageUtf8String())); + pImgObj->IVariantMapToUI(vMap); + } + + //qWarning() << "ImageAnalysis Over: " << QDateTime::currentMSecsSinceEpoch() + // << " Image ID : " << pImgObj->IGetFrameNum() + // << " Thread ID : " << QThread::currentThreadId() + // << endl; + + pAlgOpt->Save(); + return nRet; +} + +class IAlgorithmOption* CImgProc::IGetAlgorithmOption(int nAlgorithm) +{ + return m_algorithmOptions.value2(nAlgorithm, createAlgorithmOption, this); +} + +CLoadAlgorithm* CImgProc::createAlgorithmDll(const QString& k, void* pData) +{ + CLoadAlgorithm *pAlgDll = new CLoadAlgorithm(); + if (NULL == pAlgDll) + { + return NULL; + } + //TP_ALGORITHM_OPTION* pAlgOpt = (TP_ALGORITHM_OPTION*)pData; + QString dllFileName; +#ifdef _DEBUG + dllFileName.append("tpAlgorithmd"); +#else + dllFileName.append("tpAlgorithm"); +#endif + if (k != "0") + { + dllFileName.append("_").append(k); + } + QString dllPath(s_pGlobalData->tgdDllPath); + if (!ZKF::qtDllExit(dllPath, dllFileName)) + { + dllPath = s_pGlobalData->tgdMainPath; + } + dllFileName = dllPath + dllFileName; + if (!pAlgDll->LoadAlg(dllFileName)) + { + delete pAlgDll; + return NULL; + } + return pAlgDll; +} + +void CImgProc::releaseAlgorithmApis(QMap& v, void* pData) +{ + for (QMap::Iterator it = v.begin(); it != v.end(); ++it) + { + tagALGORITHM_API* pNode = it.value(); + if (NULL != pNode) + { + if (NULL != pNode->pApi && NULL != pNode->pDll) + { + pNode->pDll->m_fAlgDelete(pNode->pApi); + } + delete pNode; + } + } + v.clear(); +} + +void CImgProc::releaseAlgorithmDlls(CLoadAlgorithm*& v, void* pData) +{ + delete v; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpImgProc/ImgProc.h b/src/lpCoreCtrl/tpImgProc/ImgProc.h new file mode 100644 index 0000000..5dfbce8 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/ImgProc.h @@ -0,0 +1,56 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:ImgProc.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/26 + History:26:3:2015 18:03 + *******************************************************************************/ +#include "iImgProc.h" +/*#include "ImageAlgorithm.h"*/ +#include "QZkMutexMap.h" +#include "baseClass.h" +#include +#include +#include "LoadAlgorithm.h" +#include "AlgorithmOption.h" +#include "LoadAlgorithm.h" + +class CImgProc : public IImgProc +{ +public: + CImgProc(IMGPROC_IN_PARAM* pParam); + virtual ~CImgProc(void); + + int InitProc(); + void FreeProc(); +private: + virtual int IImageProcess(class IImageObject* pImgObj, class IDetectorEngine* pDE = NULL); + virtual class IAlgorithmOption* IGetAlgorithmOption(int nAlgorithm); +private: + static CAlgorithmOption* createAlgorithmOption(const int& k, void* pData); + static void releaseAlgorithm(const Qt::HANDLE& k, class IAlgorithm*& v, void* pData); + static void releaseAlgorithmOption(const int& k, CAlgorithmOption*& v, void* pData); + //class IImageProc* m_pImgProc; +public: + static TP_GLOBAL_DATA* s_pGlobalData; + const static char cs_strCfgName[]; +private: + bool m_bIsInited; + QSqliteAlgorithm m_dbAlg; + //QZkMutexMap m_algorithms; + QAtomicInt m_nAlgorithmsUsings; + QZkMutexMap m_algorithmOptions; + //class CLoadAlgorithm* m_pLibAlgorithm; + QZkMutexMap m_algorithmDlls; + CLoadAlgorithm* m_pDefAlgorithmDll;//nAlgorithm = 0; tpAlgorithm.dll + struct tagALGORITHM_API{ + class IAlgorithm* pApi; + class CLoadAlgorithm* pDll; + }; + QZkMutexMap> m_threadAlgorithms; + static CLoadAlgorithm* createAlgorithmDll(const QString& k, void* pData); + static void releaseAlgorithmApis(QMap& v, void* pData); + static void releaseAlgorithmDlls(CLoadAlgorithm*& v, void* pData); +}; diff --git a/src/lpCoreCtrl/tpImgProc/LoadAlgorithm.cpp b/src/lpCoreCtrl/tpImgProc/LoadAlgorithm.cpp new file mode 100644 index 0000000..e2dcfc3 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/LoadAlgorithm.cpp @@ -0,0 +1,72 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:LoadAlgorithm.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/05/21 + History:21:5:2015 14:33 + *******************************************************************************/ +#include "LoadAlgorithm.h" +#include + +//CLoadAlgorithm::Func_Alg_Create CLoadAlgorithm::sf_AlgCreata = NULL; +//CLoadAlgorithm::Func_Alg_Delete CLoadAlgorithm::sf_AlgDelete = NULL; +//class QLibrary* CLoadAlgorithm::s_pLib = NULL; + +CLoadAlgorithm::CLoadAlgorithm() +{ + m_pLib = NULL; + m_fAlgCreata = NULL; + m_fAlgDelete = NULL; +} + +CLoadAlgorithm::~CLoadAlgorithm() +{ + FreeAlg(); +} + +bool CLoadAlgorithm::LoadAlg(const QString &szDllName) +{ +#ifdef _USE_ALGORITHM_STATIC + m_fAlgCreata = Algorithm_Create; + m_fAlgDelete = Algorithm_Delete; +#else + if (NULL == m_pLib) + { + m_pLib = new QLibrary(szDllName); + if (NULL == m_pLib) + { + return false; + } + } + if (!m_pLib->load()) + { + tpDebugOut("Failed to Load dll: %s", szDllName.toLocal8Bit().data()); + return false; + } + m_fAlgCreata = (Func_Alg_Create)m_pLib->resolve("Algorithm_Create"); + m_fAlgDelete = (Func_Alg_Delete)m_pLib->resolve("Algorithm_Delete"); +#endif + if (NULL == m_fAlgCreata || NULL == m_fAlgDelete) + { + tpDebugOut("Failed to get functions from %s", szDllName.toLocal8Bit().data()); + return false; + } + return true; +} + +void CLoadAlgorithm::FreeAlg() +{ + m_fAlgCreata = NULL; + m_fAlgDelete = NULL; +#ifdef _USE_ALGORITHM_STATIC + +#else + if (NULL != m_pLib) + { + delete m_pLib; + m_pLib = NULL; + } +#endif +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpImgProc/LoadAlgorithm.h b/src/lpCoreCtrl/tpImgProc/LoadAlgorithm.h new file mode 100644 index 0000000..9546ea3 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/LoadAlgorithm.h @@ -0,0 +1,35 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:LoadAlgorithm.h + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/05/21 + History:21:5:2015 14:33 + *******************************************************************************/ +#ifndef LOADALGORITHM_H +#define LOADALGORITHM_H + +#include "iAlgorithm.h" + +class CLoadAlgorithm +{ +public: + CLoadAlgorithm(); + ~CLoadAlgorithm(); +public: + bool LoadAlg(const QString &szDllName); + void FreeAlg(); +public: + typedef IAlgorithm* (*Func_Alg_Create)(class IDetectorEngine* pDE); + typedef void(*Func_Alg_Delete)(IAlgorithm*); + Func_Alg_Create m_fAlgCreata; + Func_Alg_Delete m_fAlgDelete; +private: + class QLibrary* m_pLib; +}; + +//#define ALLOC_ALGORITHM() (NULL == CLoadAlgorithm::sf_AlgCreata) ? NULL : CLoadAlgorithm::sf_AlgCreata() +//#define FREE_ALGORITHM(obj) if ( NULL != CLoadAlgorithm::sf_AlgDelete) CLoadAlgorithm::sf_AlgDelete(obj) + +#endif // LOADALGORITHM_H diff --git a/src/lpCoreCtrl/tpImgProc/QSqliteAlgorithm.cpp b/src/lpCoreCtrl/tpImgProc/QSqliteAlgorithm.cpp new file mode 100644 index 0000000..bfd73d3 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/QSqliteAlgorithm.cpp @@ -0,0 +1,95 @@ +#include "QSqliteAlgorithm.h" + +#define _TP_SQLITE_ALGORITHM_DB "algorithm.db" + +#define _TP_SQLITE_CRETAE_ALGORITHM \ +"CREATE TABLE IF NOT EXISTS e_algorithm_%1(alg_key VARCHAR(255) \ +, alg_type INT(32) \ +, alg_data BLOB \ +, alg_stamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP \ +, PRIMARY KEY(alg_key, alg_type))" + +#define _TP_SQLITE_REPLACE_ALGORITHM \ + "REPLACE INTO e_algorithm_%1(alg_key, alg_type, alg_data) VALUES('%2', '%3', :data_buffer)" +#define _TP_SQLITE_SELECT_RECORD_DATA \ + "SELECT alg_key, alg_type, alg_data FROM e_algorithm_%1 WHERE alg_key='%2' AND alg_type='%3'" +#define _TP_SQLITE_SELECT_KEYS_BY_TYPE \ + "SELECT alg_key, alg_type FROM e_algorithm_%1 WHERE alg_type = '%2'" +#define _TP_SQLITE_DELETE_RECORD \ + "DELETE FROM e_algorithm_%1 WHERE alg_key='%2'" + +QSqliteAlgorithm::QSqliteAlgorithm(const QString& dbPath) + : QZkDbSqlite(dbPath+_TP_SQLITE_ALGORITHM_DB) +{ + +} + +QSqliteAlgorithm::~QSqliteAlgorithm() +{ + +} + +bool QSqliteAlgorithm::CreateTable(int nAlgorithm) +{ + if (!isOpen() && !open()) + { + return false; + } + QString strSql = QString(_TP_SQLITE_CRETAE_ALGORITHM).arg(QString::number(nAlgorithm)); + QSqlQuery sql = exec(strSql); + if (QSqlError::NoError != lastError().type()) + { + return false; + } + return true; +} + +bool QSqliteAlgorithm::ReplaceRecord(int nAlgorithm, const QString& key, int type, const QByteArray& data) +{ + QString strCmd(_TP_SQLITE_REPLACE_ALGORITHM); + strCmd = strCmd.arg(QString::number(nAlgorithm), key, QString::number(type)); + QSqlQuery sql(*this); + sql.prepare(strCmd); + sql.bindValue(":data_buffer", data, QSql::In); + return sql.exec(); +} + +bool QSqliteAlgorithm::DeleteRecord(int nAlgorithm, const QString& key) +{ + QString strCmd = QString(_TP_SQLITE_DELETE_RECORD).arg(QString::number(nAlgorithm), key); + QSqlQuery sql = exec(strCmd); + if (QSqlError::NoError != sql.lastError().type()) + { + return false; + } + return true; +} + +bool QSqliteAlgorithm::ReadRecord(int nAlgorithm, const QString& key, int type, QByteArray& data) +{ + QString strCmd = QString(_TP_SQLITE_SELECT_RECORD_DATA).arg(QString::number(nAlgorithm), key, QString::number(type)); + QSqlQuery sql = exec(strCmd); + if (QSqlError::NoError != lastError().type()) + { + return false; + } + if (!sql.next()) + { + return false; + } + QSqlRecord record = sql.record(); + data = record.value("alg_data").toByteArray(); + return true; +} + +QStringList QSqliteAlgorithm::KeysByType(int nAlgorithm, int type) +{ + QStringList strList; + QString strCmd = QString(_TP_SQLITE_SELECT_KEYS_BY_TYPE).arg(QString::number(nAlgorithm), QString::number(type)); + QSqlQuery sql = exec(strCmd); + while (sql.next()) + { + strList.append(sql.record().value("alg_key").toString()); + } + return strList; +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpImgProc/QSqliteAlgorithm.h b/src/lpCoreCtrl/tpImgProc/QSqliteAlgorithm.h new file mode 100644 index 0000000..7a2cb17 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/QSqliteAlgorithm.h @@ -0,0 +1,21 @@ +#ifndef QSQLITEALGORITHM_H +#define QSQLITEALGORITHM_H + +#include "QZkDbSqlite.h" + +class QSqliteAlgorithm : public QZkDbSqlite +{ +public: + QSqliteAlgorithm(const QString& dbPath); + ~QSqliteAlgorithm(); + + bool CreateTable(int nAlgorithm); + bool ReplaceRecord(int nAlgorithm, const QString& key, int type, const QByteArray& data); + bool DeleteRecord(int nAlgorithm, const QString& key); + bool ReadRecord(int nAlgorithm, const QString& key, int type, QByteArray& data); + QStringList KeysByType(int nAlgorithm, int type); +private: + +}; + +#endif // QSQLITEALGORITHM_H diff --git a/src/lpCoreCtrl/tpImgProc/tpImgProc.cpp b/src/lpCoreCtrl/tpImgProc/tpImgProc.cpp new file mode 100644 index 0000000..ae29644 --- /dev/null +++ b/src/lpCoreCtrl/tpImgProc/tpImgProc.cpp @@ -0,0 +1,54 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:tpImgProc.cpp + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:2015/03/26 + History:26:3:2015 17:56 + *******************************************************************************/ +#include "ImgProc.h" +#include "LoadAlgorithm.h" + +#ifdef TPIMGPROC_EXPORTS +#define TPIMGPROC_API extern "C" __declspec(dllexport) +#else +#define TPIMGPROC_API extern "C" +#endif + +CImgProc* gpImgProc = NULL; + +TPIMGPROC_API void* Lib_ImgProc_Init(void* inParam) +{ + IMGPROC_IN_PARAM* pParam = (IMGPROC_IN_PARAM*)inParam; + /* + char szDllName[260]; + strcpy(szDllName, pParam->pGlobalData->tgdDllPath); +#ifdef _DEBUG + strcat(szDllName, "tpAlgorithmd"); +#else + strcat(szDllName, "tpAlgorithm"); +#endif + CLoadAlgorithm::LoadAlg(szDllName); + */ + if( NULL == gpImgProc ) + { + gpImgProc = new CImgProc((IMGPROC_IN_PARAM*)pParam); + if( NULL != gpImgProc ) + { + gpImgProc->InitProc(); + } + } + return gpImgProc; +} + +TPIMGPROC_API void Lib_ImgProc_Free() +{ + if( NULL != gpImgProc ) + { + gpImgProc->FreeProc(); + delete gpImgProc; + gpImgProc = NULL; + } + //CLoadAlgorithm::FreeAlg(); +} \ No newline at end of file diff --git a/src/lpCoreCtrl/tpJsonConfig.h b/src/lpCoreCtrl/tpJsonConfig.h new file mode 100644 index 0000000..c66a429 --- /dev/null +++ b/src/lpCoreCtrl/tpJsonConfig.h @@ -0,0 +1,29 @@ +/****************************************************************************** + Copyright(C):2015~2018 hzleaper + FileName:$FILE_BASE$.$FILE_EXT$ + Author:zhikun wu + Email:zk.wu@hzleaper.com + Tools:vs2010 pc on company + Created:$DATE$ + History:$DAY$:$MONTH$:$YEAR$ $HOUR$:$MINUTE$ + *******************************************************************************/ +#ifndef __TP_JSON_CONFIG_H +#define __TP_JSON_CONFIG_H + +namespace CAMERA_JSON //camera.json +{ + namespace DEVICES //"devices" + { + + } + namespace POOL //"pool" + { + + } + namespace WINDOWS //"windows" + { + + } +} + +#endif//__TP_JSON_CONFIG_H diff --git a/src/lpMain/AutoTrigger.cpp b/src/lpMain/AutoTrigger.cpp new file mode 100644 index 0000000..8a7390e --- /dev/null +++ b/src/lpMain/AutoTrigger.cpp @@ -0,0 +1,29 @@ +#include "AutoTrigger.h" +#include "qtimer.h" + + +AutoTrigger::AutoTrigger() +{ + m_pTimer = new QTimer(this); + connect(m_pTimer, SIGNAL(timeout()), this, SIGNAL(sgTrig())); +} + + +AutoTrigger::~AutoTrigger() +{ + stop(); + delete m_pTimer; +} + +bool AutoTrigger::start(int nInterval) +{ + m_pTimer->stop(); + m_pTimer->start(nInterval); + return true; +} + +bool AutoTrigger::stop() +{ + m_pTimer->stop(); + return true; +} diff --git a/src/lpMain/AutoTrigger.h b/src/lpMain/AutoTrigger.h new file mode 100644 index 0000000..55a92df --- /dev/null +++ b/src/lpMain/AutoTrigger.h @@ -0,0 +1,21 @@ +#ifndef _AUTOTRIGGER_H_ +#define _AUTOTRIGGER_H_ + +#include + +class AutoTrigger : public QObject +{ + Q_OBJECT +public: + AutoTrigger(); + ~AutoTrigger(); + + bool start(int nInterval = 1000); + bool stop(); +signals : + void sgTrig(); +private: + class QTimer *m_pTimer{ nullptr }; +}; + +#endif \ No newline at end of file diff --git a/src/lpMain/CoreCtrl/CDllCoreCtrl.cpp b/src/lpMain/CoreCtrl/CDllCoreCtrl.cpp new file mode 100644 index 0000000..b529d3f --- /dev/null +++ b/src/lpMain/CoreCtrl/CDllCoreCtrl.cpp @@ -0,0 +1,79 @@ +#include "CDllCoreCtrl.h" + +#define _USE_LIB_CORECTRL_DLL +#ifdef _USE_LIB_CORECTRL_DLL +#include "DllLoader.h" +#else +extern "C" void* Lib_CoreCtrl_Init(void* inParam); +extern "C" void Lib_CoreCtrl_Free(); +#endif +#include "QZkJsonParser.h" + +CDllCoreCtrl::CDllCoreCtrl(const ZStringList& szDllPaths, IGuiCallback* pGuiCb,class IDetectorEngine* pDE /*= NULL*/) +{ + m_szDllPaths = szDllPaths; + memset(&m_tpGlobal, 0, sizeof(m_tpGlobal)); + m_tpGlobal.tgdpDllPaths = &m_szDllPaths; + if (m_szDllPaths.size() > 0) + { + strncpy(m_tpGlobal.tgdMainPath, m_szDllPaths.last().toUtf8().data(), BASE_MAX_FILE_PATH - 1); + strncpy(m_tpGlobal.tgdUserPath, m_szDllPaths.first().toUtf8().data(), BASE_MAX_FILE_PATH - 1); + strcpy(m_tpGlobal.tgdDllPath, m_tpGlobal.tgdMainPath); + } + QJsonObject jsonUser; + int nerr; + QJsonObject rootBoj = QZkJsonParser::ReadJsonObject(".\\ui\\app.json", &nerr); + QString folderStr = jsonUser.value("config").toString("config\\"); + strcpy(m_tpGlobal.tgdFolderNames[TP_FOLDER_NAME_CONFIG], folderStr.toUtf8().data()); + folderStr = jsonUser.value("pic").toString("pic\\"); + strcpy(m_tpGlobal.tgdFolderNames[TP_FOLDER_NAME_PICTURE], folderStr.toUtf8().data()); + strcpy(m_tpGlobal.tgdFolderNames[TP_FOLDER_NAME_UI], "ui\\"); + CORE_CTRL_IN_PARAM inParam; + inParam.pGlobalData = &m_tpGlobal; + inParam.pCoreSetting = NULL; + inParam.pGuiCb = pGuiCb; +#ifdef _USE_LIB_CORECTRL_DLL + m_pLibCoreCtrl = new CDllLoaderM("lpCoreCtrl", "Lib_CoreCtrl_Init", "Lib_CoreCtrl_Free", m_szDllPaths); + if (NULL != m_pLibCoreCtrl) + { + m_pCoreCtrl = (ICoreCtrl*)m_pLibCoreCtrl->ModuleInit(&inParam); + if (NULL != m_pCoreCtrl) + { + m_pCoreCtrl->IInitCore(pDE); + } + else + { + tpDebugOut("failed to get instance from tpCoreCtrl.dll"); + } + } + else + { + tpDebugOut("failed to load tpCoreCtrl.dll"); + } +#else + m_pLibCoreCtrl = NULL; + m_pCoreCtrl = (ICoreCtrl*)Lib_CoreCtrl_Init(&inParam); +#endif +} + +CDllCoreCtrl::~CDllCoreCtrl() +{ + if (NULL != m_pCoreCtrl) + { + m_pCoreCtrl->IFreeCore(); +#ifdef _USE_LIB_CORECTRL_DLL + if (NULL != m_pLibCoreCtrl) + { + m_pLibCoreCtrl->ModuleFree(); + } +#else + Lib_CoreCtrl_Free(); +#endif + m_pCoreCtrl = NULL; + } + if (NULL != m_pLibCoreCtrl) + { + delete m_pLibCoreCtrl; + m_pLibCoreCtrl = NULL; + } +} diff --git a/src/lpMain/CoreCtrl/CDllCoreCtrl.h b/src/lpMain/CoreCtrl/CDllCoreCtrl.h new file mode 100644 index 0000000..b6a0b8a --- /dev/null +++ b/src/lpMain/CoreCtrl/CDllCoreCtrl.h @@ -0,0 +1,21 @@ +#ifndef CDLLCORECTRL_H +#define CDLLCORECTRL_H + +#include "iCoreCtrl.h" +#include "zclasses.h" + +class CDllCoreCtrl +{ +public: + CDllCoreCtrl(const ZStringList& szDllPaths, IGuiCallback* pGuiCb, class IDetectorEngine* pDE /*= NULL*/); + ~CDllCoreCtrl(); +public: + TP_GLOBAL_DATA m_tpGlobal; + class CDllLoaderM* m_pLibCoreCtrl; + ICoreCtrl* m_pCoreCtrl; + ZStringList m_szDllPaths; + + +}; + +#endif // CDLLCORECTRL_H diff --git a/src/lpMain/CoreCtrl/CDllDetectorEngine.cpp b/src/lpMain/CoreCtrl/CDllDetectorEngine.cpp new file mode 100644 index 0000000..cf06805 --- /dev/null +++ b/src/lpMain/CoreCtrl/CDllDetectorEngine.cpp @@ -0,0 +1,79 @@ +#include "CDllDetectorEngine.h" +#include "iCoreCtrl.h" + +CDllDetectorEngine::CDllDetectorEngine() +{ + m_pDE = NULL; +#ifdef _DEBUG + m_lib.setFileName("lpbengined.dll"); +#else + m_lib.setFileName("lpbengine.dll"); +#endif + + if (!m_lib.load()) + { + qWarning("failed to load lpbengine"); + } + + FnLpNewEngineInstance pfnLpNewInstance = (FnLpNewEngineInstance)m_lib.resolve("LpNewEngineInstance"); + if (pfnLpNewInstance) + pfnLpNewInstance(&m_pDE, NULL); + + if (!m_pDE) + { + qWarning("failed to get instance from lpbengine"); + } + +} + +CDllDetectorEngine::~CDllDetectorEngine() +{ + Quit(); +} + +bool CDllDetectorEngine::Initialize(class ICoreCtrl* pCoreCtrl) +{ + if (m_pDE && pCoreCtrl) + { + void* p = NULL; + m_pDE->GetDataInterface(DEVICEMGR, &p); + IDetectorDeviceMgr* pDeviceMgr = (IDetectorDeviceMgr*)p; + if (pDeviceMgr) + { + pDeviceMgr->RegisterCoreCtrl(pCoreCtrl); + QList strCameraKeys = pCoreCtrl->ICameraKeys(); + for (int i = 0; i < strCameraKeys.size(); i++) + { + + IDetectorCameraDevice* pCamera = (IDetectorCameraDevice*)pDeviceMgr->AddDevice(CAMERA); + if (pCamera) + { + TP_CAMERA_OPTION option; + pCoreCtrl->ICameraOptionByKey(strCameraKeys.at(i), option); + pCamera->SetName(strCameraKeys.at(i)); + pCamera->SetID(option.id); + } + } + } + + m_pDE->GetDataInterface(SHAREAPARAM, &p); + IAlgorithmShare* pAlgoShare = (IAlgorithmShare*)p; + if (pAlgoShare) + { + pAlgoShare->RegisterCoreCtrl(pCoreCtrl); + } + + return true; + } + return false; +} + +void CDllDetectorEngine::Quit() +{ + FnLpDeleteEngineInstance pfnLpDeleteInstance = (FnLpDeleteEngineInstance)m_lib.resolve("LpDeleteEngineInstance"); + if (pfnLpDeleteInstance) + pfnLpDeleteInstance(); + + if (m_lib.isLoaded()) + m_lib.unload(); +} \ No newline at end of file diff --git a/src/lpMain/CoreCtrl/CDllDetectorEngine.h b/src/lpMain/CoreCtrl/CDllDetectorEngine.h new file mode 100644 index 0000000..bd2150c --- /dev/null +++ b/src/lpMain/CoreCtrl/CDllDetectorEngine.h @@ -0,0 +1,19 @@ +#ifndef CDLLDETECTORENGINE_H +#define CDLLDETECTORENGINE_H + +#include "lpbengine.h" + +class CDllDetectorEngine +{ +public: + CDllDetectorEngine(); + ~CDllDetectorEngine(); +public: + bool Initialize(class ICoreCtrl* pCoreCtrl); + void Quit(); + IDetectorEngine *m_pDE; +private: + QLibrary m_lib; +}; + +#endif // CDLLDETECTORENGINE_H diff --git a/src/lpMain/CoreCtrl/QDetectorDesignerMgr.cpp b/src/lpMain/CoreCtrl/QDetectorDesignerMgr.cpp new file mode 100644 index 0000000..b94fa2b --- /dev/null +++ b/src/lpMain/CoreCtrl/QDetectorDesignerMgr.cpp @@ -0,0 +1,64 @@ +#include "QDetectorDesignerMgr.h" + +QDetectorDesignerMgr::QDetectorDesignerMgr() +{ + m_pDesigner = NULL; + m_pDE = NULL; +} + +QDetectorDesignerMgr::~QDetectorDesignerMgr() +{ +// Quit(); +} + +bool QDetectorDesignerMgr::Initialize(IDetectorEngine* lpDE) +{ + if (!lpDE) + return false; + m_pDE = lpDE; + +#ifdef _DEBUG + m_lib.setFileName("lpdesignerd.dll"); +#else + m_lib.setFileName("lpdesigner.dll"); +#endif + if (!m_lib.load()) { + qDebug() << "lpdesigner lib load failed"; + return false; + } + qDebug() << "lib load ok"; + FnLpDesignerNewInstance pfnLpNewInstance = (FnLpDesignerNewInstance)m_lib.resolve("LpDesignerNewInstance"); + if (pfnLpNewInstance) + pfnLpNewInstance(&m_pDesigner, m_pDE, this); + + if (!m_pDesigner) + return false; + + return true; +} + +IDetectorUI* QDetectorDesignerMgr::GetDesignerInterface() const +{ + return m_pDesigner; +} + +void QDetectorDesignerMgr::Quit() +{ + if (m_lib.isLoaded()) + m_lib.unload(); + if (m_pDesigner) + { + delete m_pDesigner; + m_pDesigner = NULL; + } +} + +void QDetectorDesignerMgr::OnManualTrigger() +{ + emit sgCloseWindow(); +} + +void QDetectorDesignerMgr::OnSetParam(IDetectorTask* pTask) +{ + //return m_pApp->SetParam(pTask); +} diff --git a/src/lpMain/CoreCtrl/QDetectorDesignerMgr.h b/src/lpMain/CoreCtrl/QDetectorDesignerMgr.h new file mode 100644 index 0000000..c1931ed --- /dev/null +++ b/src/lpMain/CoreCtrl/QDetectorDesignerMgr.h @@ -0,0 +1,31 @@ +#ifndef QDETECTORDESIGNERMGR_H +#define QDETECTORDESIGNERMGR_H + +#include ".\lpbengine.h" +#include ".\lpdesigner.h" +#include "qobject.h" + +class QDetectorDesignerMgr : public QObject, public IDetectorUISink +{ + Q_OBJECT +public: + QDetectorDesignerMgr(); + virtual ~QDetectorDesignerMgr(); + bool Initialize(IDetectorEngine* lpDE); + void Quit(); + IDetectorUI * GetDesignerInterface() const; + virtual void OnManualTrigger(); + virtual void ResetItem(QPoint pos, QRect size){} + virtual void OnSetParam(IDetectorTask* pTask); + +signals: + void sgCloseWindow(); +private: + +private: + QLibrary m_lib; + IDetectorUI *m_pDesigner; + IDetectorEngine *m_pDE; +}; + +#endif // QDETECTORDESIGNERMGR_H \ No newline at end of file diff --git a/src/lpMain/IStation.h b/src/lpMain/IStation.h new file mode 100644 index 0000000..9c066d5 --- /dev/null +++ b/src/lpMain/IStation.h @@ -0,0 +1,56 @@ +#ifndef _ISTATION_H_ +#define _ISTATION_H_ + +#include +#include +#include "Serialport_global.h" +#define _WF_UNIQUE_SPLIT "_-_" + +enum EM_WIDGET_TYPE { + emListModel, emLableImageShow, emLabelStationName +}; +class WfModel; +class IStation : public QObject +{ + Q_OBJECT +public: + IStation(){}; + virtual ~IStation(){}; + virtual int stationId() = 0; + virtual QString stationKey() = 0; + virtual QString stationShowName() = 0; + virtual void setCamInfo(int nId, int alg, QString uniqueName, QString showName) = 0; + virtual void setComInfo(QString strName, int nCmd) = 0; + virtual QVariant getVariant(){ return QVariant(); } + virtual void revResult() = 0; + virtual bool trigImage(const QString folder = QString()) = 0; + virtual bool isWorkingOk() = 0; + + virtual QString currentRunningModel() const = 0; + virtual void setCurrentModel(QString strModel) = 0; + virtual void setCurrentModel(int index) = 0; + virtual QString currentSelectModel() = 0; + virtual int modelCount() { return 0; } + virtual QStringList modelList() { return QStringList(); } + virtual QString model(int index) { return QString(); } + virtual QString modelByPlcCmd(int nIndex) { return QString(); } + virtual WfModel *wfModel(QString) = 0; + virtual bool addModel(QString strModel) = 0; + virtual bool delModel(QString strModel) = 0; + virtual QString uniqueModel(const QString &model){ return QString(); } + + virtual bool sendResult(double ) = 0; + virtual bool setWidget(QString str, QWidget *pWgt) = 0; + + virtual bool startBatchTest(QString) = 0; + virtual bool IStandard(QString) = 0; + void setSerialPortPtr(ISerialPortTool *ptr){ m_pPort = ptr; } +signals: + void sgPrint2Window(QString &); + void sgUpdateLable(); + void sgShowImage(const QImage &img); +protected: + ISerialPortTool *m_pPort{ nullptr }; +}; + +#endif \ No newline at end of file diff --git a/src/lpMain/IWfCtrl.h b/src/lpMain/IWfCtrl.h new file mode 100644 index 0000000..a412430 --- /dev/null +++ b/src/lpMain/IWfCtrl.h @@ -0,0 +1,36 @@ +#ifndef _IWFCTRL_H_ +#define _IWFCTRL_H_ + +#include +#include +class IStation; +class WfModel; +class IWfCtrl :public QObject +{ + Q_OBJECT +public: + IWfCtrl(){}; + virtual~IWfCtrl(){}; + + virtual bool IOnlineMode() { return false; } + virtual void ISetOnlineModel(bool) {}; + virtual bool IBatchModel() = 0; + virtual bool IConnectStatus() = 0; + virtual QString IGetCommName() = 0; + virtual QString IGetCurrentRuningModel(int) = 0; + virtual void ISetUserInfo(QString& user, int& level)=0; + virtual bool IGetUserInfo(QString& user, int& level) = 0; + virtual void registerConnect() =0; + virtual QStringList IGetStationKeys() = 0; + virtual IStation* IGetStationById(int) = 0; + virtual IStation* IGetStationByKey(QString) = 0; + virtual WfModel *IGetModelInfo(int, QString) = 0; + virtual bool IUpdateModelInfo() = 0; + virtual QMap IGetModelInfos() = 0; + virtual bool IAddModel(int, QString) = 0; + virtual bool IDeleteModel(int, QString) = 0; + virtual bool ISelModel(int, QString) = 0; + virtual void ISetModifyModel(bool) = 0; + virtual bool IStandard(int nIndex ,QString strModel)=0; +}; +#endif diff --git a/src/lpMain/ModelTable.cpp b/src/lpMain/ModelTable.cpp new file mode 100644 index 0000000..226a3cf --- /dev/null +++ b/src/lpMain/ModelTable.cpp @@ -0,0 +1,122 @@ +#include "ModelTable.h" +#include "IStation.h" +#include "QDebug" +#include "qtableview.h" +#include "qabstractitemview.h" +#include "WfModel.h" +#pragma execution_character_set("utf-8") + +QVariant ModelModel::data(const QModelIndex &index, int role /*= Qt::DisplayRole*/) const +{ + if (role == Qt::DisplayRole) { + int nCol = index.column(); + int nRow = index.row(); + //qDebug() << index.row(); + if (0 == nCol) { + if (nRow != 0) { + int a = 1; + } + return m_pStation->model(nRow); + } + else if (1== nCol) { + return m_pStation->wfModel(m_pStation->model(nRow))->nIndex; + } + else if (2==nCol) { + //return m_pStation->wfModel(m_pStation->model(nRow))->bCaliState == true ? "已标定" : "未标定"; + return m_pStation->IStandard(m_pStation->model(nRow)) == true ? QObject::tr("已标定") : QObject::tr("未标定"); + } + } + else if (role == Qt::BackgroundRole) { + QString str1 = m_pStation->currentRunningModel(); + QString str2 = m_pStation->model(index.row()); + if (str1 == str2) { + return QColor(255, 0, 0); + } + else { + return QColor(255, 255, 255); + } + +// int nCol = index.column(); +// int nRow = index.row(); +// if (2 == nCol) { +// return m_pStation->IStandard(m_pStation->model(nRow)) == true ? QColor(255, 255, 255) : QColor(255, 0, 255); +// } + } + return QVariant(); +} + +int ModelModel::columnCount(const QModelIndex &parent /*= QModelIndex()*/) const +{ + return 3; +} + +int ModelModel::rowCount(const QModelIndex &parent /*= QModelIndex()*/) const +{ + return m_pStation->modelCount(); +} + +QVariant ModelModel::headerData(int section, Qt::Orientation orientation, int role /*= Qt::DisplayRole*/) const +{ + if (Qt::DisplayRole == role ) { + if (Qt::Horizontal == orientation) { + if (section < m_lstHeader.size()) { + return m_lstHeader.at(section); + } + else { + return QVariant(); + } + } + else { + return section + 1; + } + + } + return QVariant(); +} + +ModelModel::ModelModel(IStation *pStation) + : m_pStation(pStation) +{ + m_lstHeader = QStringList() << QObject::tr("模型号") << QObject::tr("PLC索引值") << QObject::tr("标定情况"); +} + +void ModelModel::resetModel() +{ + beginResetModel(); + endResetModel(); +} + +ModelView::ModelView(QTableView *pView, IStation *pStation) +{ + m_pView = pView; + m_pView->setSelectionBehavior(QAbstractItemView::SelectRows); + //QObject::connect(pView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onSelectItem(const QModelIndex&))); + m_pModel = new ModelModel(pStation); + m_pView->setModel(m_pModel); +} + +ModelView::~ModelView() +{ + delete m_pModel; + delete m_pView; + m_pView = NULL; + m_pModel = NULL; +} + +void ModelView::resetModel() +{ + m_pModel->resetModel(); +} + +void ModelView::scroll2Bottom() +{ + m_pView->scrollToBottom(); +} + +int ModelView::currentRow() +{ + if (m_pView) { + return m_pView->currentIndex().row(); + } + return -1; +} diff --git a/src/lpMain/ModelTable.h b/src/lpMain/ModelTable.h new file mode 100644 index 0000000..d88be5d --- /dev/null +++ b/src/lpMain/ModelTable.h @@ -0,0 +1,37 @@ +#pragma once +#include "qabstractitemmodel.h" +#include "qtableview.h" +#include "qmap.h" +#include "qstring.h" +#include "qobject.h" + +class IStation; +class ModelModel : public QAbstractTableModel +{ +public: + ModelModel(IStation *); + + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + virtual QVariant headerData(int section, Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + void resetModel(); +private: + IStation *m_pStation; + QStringList m_lstHeader; +}; + +class ModelView : public QObject +{ + Q_OBJECT +public: + ModelView(QTableView *, IStation *); + ~ModelView(); + void resetModel(); + void scroll2Bottom(); + int currentRow(); + ModelModel *m_pModel; + QTableView * m_pView; +}; diff --git a/src/lpMain/QDiskCleanThread/QDiskCleanThread.cpp b/src/lpMain/QDiskCleanThread/QDiskCleanThread.cpp new file mode 100644 index 0000000..30dc4d6 --- /dev/null +++ b/src/lpMain/QDiskCleanThread/QDiskCleanThread.cpp @@ -0,0 +1,184 @@ +#include +#include +#include +#include "QDiskCleanThread.h" +#include "solarCellHelper.h" + + +bool compareFileCreatTime(const QFileInfo &fileInfo1, const QFileInfo &fileInfo2) +{ + if (fileInfo1.created() < fileInfo2.created()) + { + return true; + } + + return false; +} + + +QDiskCleanThread::QDiskCleanThread(QObject * parent) + : QThread(parent) + , m_bExit(false) + , m_strImgStorageFolder(QString()) + , isUse(false) + , m_nDay(7) + , m_DelFile(false) + , nMiniSize(10) +{ + bModel = CleanFile; + nSleepTime = 300; +} + +QDiskCleanThread::~QDiskCleanThread() +{ + ExitThread(); +} + +void QDiskCleanThread::run() +{ + while (!m_bExit) + { + qWarning() << "Start Scan Disk ..."; + QString strDisk = m_strImgStorageFolder.left(2); + int space = solarCell::SolarCellHelper::GetDiskFreeSpace(strDisk); + if (space < 1024 * 10) + { + isUse = true; + m_nDay = 3; + + } + + + qWarning() << "spacesize =" << space; + if (bModel == CleanFile)//清空图片数据的操作 + { + if (isUse) + { + QFileInfoList fileInfoList; + fileInfoList.clear(); + solarCell::SolarCellHelper::GetFileInfoList(fileInfoList, m_strImgStorageFolder); + QDateTime timedate = QDateTime::currentDateTime(); + //timedate.setTime(QTime(0, 0, 0));//以零点时间为准 开始比较时间 + int nDay = 0; + if (m_nDay <= 0) + nDay = 3;//限制天数 不能低于3天 + else + nDay = m_nDay; + + timedate = timedate.addDays(-nDay); + GetFileListByTime(fileInfoList, timedate); + if (fileInfoList.size() > 10 && + !m_strImgStorageFolder.isEmpty()) + { + for (int nIndex = 0; nIndex < fileInfoList.size(); nIndex++) + { + QFileInfo qFileInfo = fileInfoList.at(nIndex); + qFileInfo.dir().remove(qFileInfo.fileName()); + } + } + space = solarCell::SolarCellHelper::GetDiskFreeSpace(strDisk); + qWarning() << "Delete Imgs ..."; + } + + + if (space < 1024 * nMiniSize) + { + m_DelFile = true; + } + + if (m_DelFile) + { + QFileInfoList fileInfoList; + fileInfoList.clear(); + solarCell::SolarCellHelper::GetFileInfoList(fileInfoList, m_strImgStorageFolder); + qSort(fileInfoList.begin(), fileInfoList.end(), compareFileCreatTime); + //删除时间最老的300张图片 + int delNum = 600; + if (delNum > fileInfoList.size()) + { + delNum = fileInfoList.size(); + } + for (int i = 0; i < delNum; i++) + { + QString filePath = fileInfoList.at(i).absolutePath(); + QString fileName = fileInfoList.at(i).fileName(); + QString createTIme = fileInfoList.at(i).created().toString("yyyy-MM-dd hh:mm:ss zzz"); + if (fileName.right(4).toLower() == ".jpg" || + fileName.right(4).toLower() == ".bmp" || + fileName.right(4).toLower() == ".png") + { + QFile::remove(fileInfoList.at(i).absolutePath() + "/" + fileInfoList.at(i).fileName()); + } + } + m_DelFile = false; + qWarning() << "Delete Imgs Finish..."; + } + } + else if (bModel == CleanDir)//清空图片文件夹测操作 + { + if (isUse) + { + QFileInfoList fileInfoList; + fileInfoList.clear(); + solarCell::SolarCellHelper::GetDirInfoList_root(fileInfoList, m_strImgStorageFolder); + QDateTime timedate = QDateTime::currentDateTime(); + if (m_nDay <= 0) + m_nDay = 3;//限制天数 不能低于3天 + timedate = timedate.addDays(-m_nDay); + GetDirListByTime(fileInfoList, timedate); + if (fileInfoList.size() > 0 && + !m_strImgStorageFolder.isEmpty()) + { + for (int nIndex = 0; nIndex < fileInfoList.size(); nIndex++) + solarCell::SolarCellHelper::DelDiretory(fileInfoList.at(nIndex).absoluteFilePath()); + } + } + } + qWarning() << "End Scan Disk ..."; + //三十秒判断一次 + if (nSleepTime <= 2) + nSleepTime = 2; + int sleeptime = nSleepTime * 1000; + msleep(10); + } +} + +void QDiskCleanThread::ExitThread() +{ + m_bExit = true; +} + +void QDiskCleanThread::SetImgStorageFolder(QString strFolder) +{ + m_strImgStorageFolder = strFolder; +} + +void QDiskCleanThread::GetDirListByTime(QFileInfoList &qDirList, QDateTime &qDateTime) +{ + QFileInfoList tmpList; + tmpList.clear(); + for (int nIndex = 0; nIndex < qDirList.size(); nIndex++){ + QFileInfo nFileInfo = qDirList.at(nIndex); + if (nFileInfo.fileName() == "." || nFileInfo.fileName() == "..") + continue; + if (nFileInfo.created() +#include +enum CleanModel +{ + CleanFile = 0, + CleanDir +}; +class QDiskCleanThread : public QThread +{ + Q_OBJECT; + +public: + QDiskCleanThread(QObject * parent = 0); + virtual ~QDiskCleanThread(); + + void setModel(CleanModel nModel = CleanFile){ bModel = nModel; }; + void setSleepS(int nTime){ nSleepTime = nTime; }; + void setUseFlag(bool bFalg = false){//是否开启轮询监控 + isUse = bFalg; + }; + void setMiniSize(int minsize){ + nMiniSize = minsize; + if (nMiniSize <= 0) + nMiniSize = 0; + }; + void setDays(int nday = 7){ m_nDay = nday; };//超期天数 + void ExitThread(); + void SetImgStorageFolder(QString strFolder); + void GetDirListByTime(QFileInfoList &qDirList, QDateTime &qDateTime); + void GetFileListByTime(QFileInfoList &qFileList, QDateTime &qDateTime); + +protected: + void run(); + +signals: + void sgDiskSpace(int nSpace, bool nFlag); +private: + bool m_bExit{ false }; + QString m_strImgStorageFolder;//监控的文件夹 + bool isUse{ false }; + int m_nDay{ 30 }; + bool m_DelFile{ false };//重复删除标志位 用于判断硬盘数据是否是过大 如果过大 会删除两次 + int nMiniSize{ 10 };//监控硬盘最小的内存大小 G单位计算 小于该数量 删除数据 + CleanModel bModel{ CleanFile };//线程工作模式选择 + int nSleepTime{ 30 };//线程挂起时间 单位 秒 +}; +#endif//_QDISK_CLEAN_THREAD_H__ diff --git a/src/lpMain/QDiskCleanThread/WorkChecker.cpp b/src/lpMain/QDiskCleanThread/WorkChecker.cpp new file mode 100644 index 0000000..07b9e81 --- /dev/null +++ b/src/lpMain/QDiskCleanThread/WorkChecker.cpp @@ -0,0 +1,51 @@ +#include "WorkChecker.h" +#include +#include + + +WorkChecker::WorkChecker() +{ + m_bWorking = true; + m_lLastTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); + m_nCheckInterval = 300; + m_pTimer = new QTimer(this); + connect(m_pTimer, SIGNAL(timeout()), this, SLOT(onChecker())); + start(); +} + + +WorkChecker::~WorkChecker() +{ +} + +void WorkChecker::registerWorking() +{ + m_lLastTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); + m_bWorking = true; +} + +bool WorkChecker::isWorking() const +{ + return m_bWorking; +} + +void WorkChecker::onChecker() +{ + long long l = QDateTime::currentDateTime().toMSecsSinceEpoch(); + long long l1 = l - m_lLastTime; + //m_lLastTime = l; + if (l1 > 3000) { + m_bWorking = false; + } +} + +void WorkChecker::start() +{ + stop(); + m_pTimer->start(m_nCheckInterval); +} + +void WorkChecker::stop() +{ + m_pTimer->stop(); +} diff --git a/src/lpMain/QDiskCleanThread/WorkChecker.h b/src/lpMain/QDiskCleanThread/WorkChecker.h new file mode 100644 index 0000000..a5cc0d4 --- /dev/null +++ b/src/lpMain/QDiskCleanThread/WorkChecker.h @@ -0,0 +1,23 @@ +#ifndef _WORKCHECKER_H_ +#define _WORKCHECKER_H_ +#include +class WorkChecker : public QObject +{ + Q_OBJECT +public: + WorkChecker(); + ~WorkChecker(); + void registerWorking(); + bool isWorking() const ; + + void start(); + void stop(); +public slots: + void onChecker(); +private: + class QTimer *m_pTimer{ nullptr }; + int m_nCheckInterval{ 300 }; + bool m_bWorking{ true }; + long long m_lLastTime{ 0 }; +}; +#endif diff --git a/src/lpMain/QDiskCleanThread/solarCellHelper.h b/src/lpMain/QDiskCleanThread/solarCellHelper.h new file mode 100644 index 0000000..b434b36 --- /dev/null +++ b/src/lpMain/QDiskCleanThread/solarCellHelper.h @@ -0,0 +1,90 @@ +#ifndef _SOLAR_CELL_HELPER_H__ +#define _SOLAR_CELL_HELPER_H__ + +#include +#include +#include +#include +#include +#include + + +namespace solarCell +{ + class SolarCellHelper + { + public: + static inline qint64 GetDiskFreeSpace(QString strDriver) + { + LPCWSTR lpcwstrDriver = (LPCWSTR)strDriver.utf16(); + + ULARGE_INTEGER liFreeBytesAvailable, liTotalBytes, liTotalFreeBytes; + + if (!GetDiskFreeSpaceEx(lpcwstrDriver, &liFreeBytesAvailable, &liTotalBytes, &liTotalFreeBytes)) + { + qWarning() << "ERROR: Call to GetDiskFreeSpaceEx() failed."; + return 0; + } + + //返回MB + return (quint64)liTotalFreeBytes.QuadPart / 1024 / 1024; + } + static inline void GetFileInfoList(QFileInfoList& fileInfoList, QString strFolder) + { + QDir qDir(strFolder); + QFileInfoList filesListTmp = qDir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot, QDir::Time); + fileInfoList += filesListTmp; + + QStringList dirList = qDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); + for (int i = 0; i < dirList.size(); i++) + { + GetFileInfoList(fileInfoList, strFolder + "/" + dirList.at(i)); + } + } + + static inline void GetDirInfoList_child(QFileInfoList& dirInfoList, QString strFolder) + { + QDir qDir(strFolder); + QFileInfoList filesListTmp = qDir.entryInfoList(QDir::Dirs, QDir::Time); + dirInfoList += filesListTmp; + + QStringList dirList = qDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); + for (int i = 0; i < dirList.size(); i++) + { + GetDirInfoList_child(dirInfoList, strFolder + "/" + dirList.at(i)); + } + } + + static inline void GetDirInfoList_root(QFileInfoList& dirInfoList, QString strFolder) + { + QDir qDir(strFolder); + QFileInfoList filesListTmp = qDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time); + dirInfoList += filesListTmp; + } + + static inline bool DelDiretory(const QString &dirPath) + { + if (dirPath.isEmpty()) + return false; + QDir qDir(dirPath); + if (!qDir.exists()) + return true; + qDir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); + QFileInfoList qFileList = qDir.entryInfoList(); + foreach(QFileInfo qFileInfo, qFileList) + { + if (qFileInfo.isFile()) + qFileInfo.dir().remove(qFileInfo.fileName()); + else + DelDiretory(qFileInfo.absoluteFilePath()); + } + return qDir.rmpath(qDir.absolutePath()); + } + + + };//Class SolarCellHelper + +} +#endif//_SOLAR_CELL_HELPER_H__ + + diff --git a/src/lpMain/Resource/app.png b/src/lpMain/Resource/app.png new file mode 100644 index 0000000..b2bc426 Binary files /dev/null and b/src/lpMain/Resource/app.png differ diff --git a/src/lpMain/Resource/app2.png b/src/lpMain/Resource/app2.png new file mode 100644 index 0000000..d47d80d Binary files /dev/null and b/src/lpMain/Resource/app2.png differ diff --git a/src/lpMain/Resource/toolBar/administrator.png b/src/lpMain/Resource/toolBar/administrator.png new file mode 100644 index 0000000..eb8e3ac Binary files /dev/null and b/src/lpMain/Resource/toolBar/administrator.png differ diff --git a/src/lpMain/Resource/toolBar/background.png b/src/lpMain/Resource/toolBar/background.png new file mode 100644 index 0000000..135493e Binary files /dev/null and b/src/lpMain/Resource/toolBar/background.png differ diff --git a/src/lpMain/Resource/toolBar/cali.png b/src/lpMain/Resource/toolBar/cali.png new file mode 100644 index 0000000..a327c91 Binary files /dev/null and b/src/lpMain/Resource/toolBar/cali.png differ diff --git a/src/lpMain/Resource/toolBar/education24.png b/src/lpMain/Resource/toolBar/education24.png new file mode 100644 index 0000000..e40e584 Binary files /dev/null and b/src/lpMain/Resource/toolBar/education24.png differ diff --git a/src/lpMain/Resource/toolBar/help.png b/src/lpMain/Resource/toolBar/help.png new file mode 100644 index 0000000..f781626 Binary files /dev/null and b/src/lpMain/Resource/toolBar/help.png differ diff --git a/src/lpMain/Resource/toolBar/messenger.png b/src/lpMain/Resource/toolBar/messenger.png new file mode 100644 index 0000000..bd0dffb Binary files /dev/null and b/src/lpMain/Resource/toolBar/messenger.png differ diff --git a/src/lpMain/Resource/toolBar/model.png b/src/lpMain/Resource/toolBar/model.png new file mode 100644 index 0000000..873279e Binary files /dev/null and b/src/lpMain/Resource/toolBar/model.png differ diff --git a/src/lpMain/Resource/toolBar/save.png b/src/lpMain/Resource/toolBar/save.png new file mode 100644 index 0000000..ce706e4 Binary files /dev/null and b/src/lpMain/Resource/toolBar/save.png differ diff --git a/src/lpMain/Resource/toolBar/setting.png b/src/lpMain/Resource/toolBar/setting.png new file mode 100644 index 0000000..75ca02c Binary files /dev/null and b/src/lpMain/Resource/toolBar/setting.png differ diff --git a/src/lpMain/Resource/toolBar/test.png b/src/lpMain/Resource/toolBar/test.png new file mode 100644 index 0000000..96758f8 Binary files /dev/null and b/src/lpMain/Resource/toolBar/test.png differ diff --git a/src/lpMain/Resource/wanfeng.png b/src/lpMain/Resource/wanfeng.png new file mode 100644 index 0000000..c4532ad Binary files /dev/null and b/src/lpMain/Resource/wanfeng.png differ diff --git a/src/lpMain/Resource/wanfeng2.png b/src/lpMain/Resource/wanfeng2.png new file mode 100644 index 0000000..b6660de Binary files /dev/null and b/src/lpMain/Resource/wanfeng2.png differ diff --git a/src/lpMain/Station.cpp b/src/lpMain/Station.cpp new file mode 100644 index 0000000..e059a69 --- /dev/null +++ b/src/lpMain/Station.cpp @@ -0,0 +1,601 @@ +#include "Station.h" +#include "qobject.h" +#include "iCoreCtrl.h" +#include "TrigDetector.h" +#include "QDebug" +#include "QSqliteWheelHubWf.h" +#include "ModelTable.h" +#include "IWfCtrl.h" +#include "WfModel.h" +#include +#include "lpSysLog.h" + +#pragma execution_character_set("utf-8") + +int Station::s_nTrigWaitTimes = 5; + +Station::Station(QSqliteWheelHubWf *p1, ICoreCtrl *p2, IWfCtrl * p3) + : m_pView(NULL), m_pLblImage(NULL), m_pLblStationName(NULL), + m_pDbWf(p1) +{ + m_pResultTextShow = NULL; + m_pCoreCtrl = p2; + m_pWfCtrl = p3; + m_pTrigDetector = new CTrigDetector; + connect(m_pTrigDetector, SIGNAL(sgErrorTrig(int)), this, SLOT(onErrTrig(int))); + connect(this, SIGNAL(sgPrint2Window(QString &)), this, SLOT(onAddResult2TextEdit(QString &))); + connect(this, SIGNAL(sgShowImage(const QImage&)), this, SLOT(showImage(const QImage&))); + connect(this, SIGNAL(sgUpdateLable()), this, SLOT(updateAll())); + connect(this, SIGNAL(sgaddTrigCount(int)), m_pTrigDetector, SLOT(addTrigCount(int))); + connect(this, SIGNAL(sgaddRevCount(int)), m_pTrigDetector, SLOT(addRevCount(int))); + m_pTrigDetector->start(); +} + + +Station::~Station() +{ + if (m_pTrigDetector) + { + m_pTrigDetector->stop(); + delete m_pTrigDetector; + } + if (m_pView) { + delete m_pView; + } +} + +void Station::setCamInfo(int nId, int alg, QString uniqueName, QString showName) +{ + this->nId = nId; + this->nAlgorithm = alg; + this->szCamKey = uniqueName; + this->szShow = showName; +} + +QString genCurrentTime(QString strFormat = "yyyy-MM-dd hh:mm::ss") { + QDateTime qTime = QDateTime::currentDateTime(); + QString strTime = qTime.toString(strFormat); + return strTime; +} + +bool Station::addModel(QString strModel) +{ + if (m_models.contains(strModel)) { + return false; + } + m_models.append(strModel); + if (m_pView) { + m_pView->resetModel(); + m_pView->scroll2Bottom(); + } + qDebug() << "add model :" << strModel; + return true; +} + + +bool Station::delModel(QString strModel) +{ + m_models.removeOne(strModel); + if (m_models.size() == 0) { + setCurrentModel(QString()); + } + if (m_pView) { + m_pView->resetModel(); + } + qDebug() << "del model" << strModel; + return true; +} + +int Station::modelCount() { + return m_models.size(); +} + +QString Station::getModelUnique(const QString &model) +{ + return QString::number(nId) + _WF_UNIQUE_SPLIT + szCamKey + _WF_UNIQUE_SPLIT + model; +} + +bool Station::updateCurrentModel() +{ + //update currrent model + if (!m_models.contains(m_strCurrentModel)) { + m_strCurrentModel = ""; + } + + if (m_strCurrentModel.isEmpty() && modelCount() != 0) { + m_strCurrentModel = m_models.first(); + } + return true; +} + + +unsigned short Station::swapBigEndian(unsigned short &data) +{ + data = ((data & 0x00FF) << 8) + ((data & 0xFF00) >> 8); + return data; +} + +void Station::setCurrentModel(QString strModel) +{ + if (strModel.isEmpty()) { + qDebug() << "setCurrentModel, model is empty"; + return; + } + else { + m_strCurrentModel = strModel; + } + if (m_pView && !m_strCurrentModel.isEmpty()) { + m_pView->resetModel(); + } + + updateAll(); +} + +void Station::setCurrentModel(int modelIndex) +{ + if (modelCount() != 0 && modelCount() > modelIndex && modelIndex >= 0) { + setCurrentModel(m_models[modelIndex]); + } +} + +bool Station::initCurrentModel() +{ + if (modelCount() <= 1) { + if (modelCount() == 1) { + setCurrentModel(m_models[0]); + } + else if (modelCount() == 0) { + setCurrentModel(""); + } + return true; + } + + return false; +} + +bool Station::updateCurrentModel2Label() +{ + if (m_pLblStationName) { + bool bCali = false; + WfModel *pModel = wfModel(m_strCurrentModel); + if (pModel) { + //bCali = pModel->bCaliState; + bCali = IStandard(m_strCurrentModel); + } + + QString strText = "

%2%3 __ %4 __%5< / span>< / p>< / body>< / html>"; + strText = strText.arg("color:#ff0000;").arg(QObject::tr("工位")) + .arg(nId).arg(m_strCurrentModel == "" ? "?" : m_strCurrentModel) + .arg(bCali == true ? QObject::tr("已标定") : QObject::tr("未标定")); + + m_pLblStationName->setText(strText); + } + + return true; +} + +bool Station::updateAll() +{ + updateCurrentModel(); + updateCurrentModel2Label(); + return true; +} + +bool Station::onAddResult2TextEdit(QString &str) +{ + if (!m_pResultTextShow) { + return false; + } + m_pResultTextShow->append(str); + return true; +} + +QVariant Station::getVariant() +{ + QVariantMap vMap; + vMap.insert("current_model", getModelUnique(m_strCurrentModel)); + return vMap; +} + +void Station::onErrTrig(int nErrCount) +{ + if (nErrCount > s_nTrigWaitTimes * 4) { + qWarning() << "stationid = " << nId << ", error count is bigger than xxx"; + } + else if (s_nTrigWaitTimes * 3 == nErrCount) { + qWarning() << "stationid =" << nId << ",nErrCount = " << nErrCount; + QString str = genTimerInfo() + "camera disconnect!"; + onAddResult2TextEdit(str); + str = genTimerInfo() + "camera count reset, but not trig again!"; + onAddResult2TextEdit(str); + m_pTrigDetector->correct(); + str = genTimerInfo() + "try reopen camera!"; + onAddResult2TextEdit(str); + m_pCoreCtrl->IStopCamera(szCamKey); + m_pCoreCtrl->ICloseCamera(szCamKey); + if (m_pWfCtrl->IBatchModel()) { + changeImageFolder(""); + } + bool bb = m_pCoreCtrl->IOpenCamera(szCamKey); + str = QString("reopen_%1").arg(bb); + onAddResult2TextEdit(str); + bool b = m_pCoreCtrl->IStartCamera(szCamKey); + if (b) { + str = genTimerInfo() + "try reopen successful!"; + m_pCoreCtrl->ISnapImage(QStringList()<IBatchModel()) { + trigImage(); + } + + qDebug() << "stationid = " << nId << ", " << str; + } + else if (s_nTrigWaitTimes == nErrCount || s_nTrigWaitTimes * 2 == nErrCount) { + qWarning() << "camera trig failed!"; + QString str = genTimerInfo() + "camera trig failed!"; + onAddResult2TextEdit(str); + str = genTimerInfo() + "try to trig again!"; + onAddResult2TextEdit(str); + + QStringList strList = m_pCoreCtrl->ICameraKeys(); + if (strList.contains(szCamKey)) + m_pCoreCtrl->ISnapImage(QStringList() << szCamKey); + qWarning() << str; + } + else { + qDebug() << "stationid = " << nId << ", wait for image result " << nErrCount; + } +} + +int Station::stationId() +{ + return nId; +} + +QString Station::model(int index) +{ + if (index >= 0 && index < m_models.size()) { + return m_models.at(index); + } + return QString(); +} + +QStringList Station::modelList() +{ + return m_models; +} + +void Station::revResult() +{ + emit(sgaddRevCount(1)); + //m_pTrigDetector->addRevCount(); + if (m_pWfCtrl->IBatchModel()) { + + } +} + +bool Station::trigImage(const QString folder/* = QString()*/) +{ + if (!folder.isEmpty()) { + m_pCoreCtrl->IStopCamera(szCamKey); + m_pCoreCtrl->ICloseCamera(szCamKey); + changeImageFolder(folder); + + TP_CAMERA_OPTION optCam; + m_pCoreCtrl->ICameraOptionByKey(szCamKey, optCam); + if (optCam.status != TP_CAMERA_STATUS_OPENED && + optCam.status != TP_CAMERA_STATUS_STARTED){ + if (m_pCoreCtrl->IOpenCamera(szCamKey)) + { + bool b = m_pCoreCtrl->IStartCamera(szCamKey); + } + } + } + else { + if (m_pWfCtrl->IBatchModel()) { + + } + } + TP_CAMERA_OPTION optCam; + m_pCoreCtrl->ICameraOptionByKey(szCamKey, optCam); + if (optCam.status != TP_CAMERA_STATUS_OPENED && + optCam.status != TP_CAMERA_STATUS_STARTED){ + if (m_pCoreCtrl->IOpenCamera(szCamKey)) + { + bool b = m_pCoreCtrl->IStartCamera(szCamKey); + } + } + + //filter + if (!m_pTrigDetector->filterTrig()) { + return false; + } + // check + if (!m_pTrigDetector->isWaitForTrig()) { + return false; + } + + QString str = genTimerInfo(); + //m_pTrigDetector->addTrigCount(); + emit(sgaddTrigCount(1)); + str += "trig succussful: " + QString::number(m_pTrigDetector->getTrigCount()); + emit sgPrint2Window(str); + qDebug() << str; + QStringList strList = m_pCoreCtrl->ICameraKeys(); + if (strList.contains(szCamKey)) + { + m_pCoreCtrl->ISnapImage(QStringList() << szCamKey); + SYSLOG_STATUS << QString("●工位%1:相机触发拍照,型号为[%2],型号索引ID为[%3],时间:%4") + .arg(stationId()) + .arg(m_strCurrentModel) + .arg(m_CurrentPLCIndex) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + } + return true; +} + +bool Station::setWidget(QString str, QWidget *pWgt) +{ +// if (str.startsWith(_WF_CAM_LISTWIDGET_PREFIX)) { + m_pView = new ModelView(qobject_cast(pWgt), this); +// } +// else if (str.startsWith(_WF_LABEL_IMAGE_SHOW_PREFIX)) { +// m_pLblImage = qobject_cast(pWgt); +// } +// else if (str.startsWith(_WF_LABEL_STATION_NAME_PREFIX)) { +// m_pLblStationName = qobject_cast(pWgt); +// updateCurrentModel2Label(); +// } +// else if (str.startsWith(_WF_TEXT_EDIT_RESULT_PREFIX)) { +// m_pResultTextShow = qobject_cast(pWgt); +// if (m_pResultTextShow) { +// m_pResultTextShow->clear(); +// QTextDocument *pDoc = m_pResultTextShow->document(); +// pDoc->setMaximumBlockCount(200); +// m_pResultTextShow->append(Station::genTimerInfo() + "start successful"); +// } +// } +// else { +// return false; +// } + + return true; +} + +bool Station::IStandard(QString strModel) +{ + if (!m_pWfCtrl) + return false; + return m_pWfCtrl->IStandard(stationId(), strModel); +} + +bool Station::sendResult(double angleValue) +{ + if (m_pPort) + { + const int c_nDataNum = 8; + const double c_dMaxAngle = 360.0; + if (angleValue < 0) { + angleValue += c_dMaxAngle; + } + + unsigned short data[c_nDataNum] = { 0 }; + data[2] = int(angleValue); + double tmp = angleValue - int(angleValue); + tmp *= 1000.0; + data[3] = int(tmp); + SComFrame sendFram; + sendFram.cmd = m_nCmd; + sendFram.data1 = data[0]; + sendFram.data2 = data[1]; + sendFram.data3 = data[2]; + sendFram.data4 = data[3]; + sendFram.data5 = data[4]; + sendFram.data6 = data[5]; + sendFram.data7 = data[6]; + sendFram.data8 = data[7]; + m_pPort->enquequeData(sendFram); + + if (angleValue >= c_dMaxAngle) { + IImageObject::DATA_TO_COMM_HEAD head2; + unsigned short data2[c_nDataNum] = { 0 }; + data2[0] = 6 + nId - 1; + data2[1] = 50; +// for (int i = 0; i < c_nDataNum; i++) { +// swapBigEndian(data2[i]); +// } + SComFrame sendFram2; + sendFram2.cmd = 0x48; + sendFram2.data1 = data2[0]; + sendFram2.data2 = data2[1]; + sendFram2.data3 = data2[2]; + sendFram2.data4 = data2[3]; + sendFram2.data5 = data2[4]; + sendFram2.data6 = data2[5]; + sendFram2.data7 = data2[6]; + sendFram2.data8 = data2[7]; + m_pPort->enquequeData(sendFram2); + } + + } + else + { + const int c_nDataNum = 8; + const double c_dMaxAngle = 360.0; + if (angleValue < 0) { + angleValue += c_dMaxAngle; + } + + unsigned short data[c_nDataNum] = { 0 }; + data[2] = int(angleValue); + double tmp = angleValue - int(angleValue); + tmp *= 1000.0; + data[3] = int(tmp); +// QString strPrint = "data1 = %1, data2 = %2"; +// strPrint = strPrint.arg(data[2]).arg(data[3]); + for (int i = 0; i < c_nDataNum; i++) { + swapBigEndian(data[i]); + } + IImageObject::DATA_TO_COMM_HEAD head; + head.cmd = m_nCmd; + QByteArray comArray = m_strComName.toLatin1(); + head.commNames = comArray.data(); + head.pfCallback = NULL; + head.pContext = this; + if (!m_pCoreCtrl) { + qWarning() << "send result, core ctrl is null"; + return false; + } + //m_pCoreCtrl->IDataToComm(head, (char*)data, c_nDataNum * 2); + + // send io ctrl + if (angleValue >= c_dMaxAngle) { + IImageObject::DATA_TO_COMM_HEAD head2; + unsigned short data2[c_nDataNum] = { 0 }; + head2.cmd = m_nCmd; + head2.commNames = comArray.data(); + head2.pContext = NULL; + head2.pfCallback = NULL; + head2.cmd = 0x48; + data2[0] = 6 + nId - 1; + data2[1] = 50; + for (int i = 0; i < c_nDataNum; i++) { + swapBigEndian(data2[i]); + } + //m_pCoreCtrl->IDataToComm(head2, (char*)data2, c_nDataNum * 2); + qDebug() << "send result, angle is bigger than 360"; + } + } + return true; +} + +void Station::setComInfo(QString strName, int nCmd) +{ + m_strComName = strName; + m_nCmd = nCmd; +} + +Q_SLOT void Station::showImage(const QImage &img) +{ +// if (m_pImgViewer) +// { +// QImage imgShow = img; +// m_pImgViewer->setImg(imgShow); +// return; +// } + + if (!m_pLblImage) { + qDebug() << "label image is null"; + return; + } + qDebug() << "show image"; + //QRect rt = m_pLblImage->rect(); + if (img.isNull()) + { + QString str = QObject::tr("检测到错误: 模型与图像尺寸不匹配,请重新标定模型!!!"); + m_pLblImage->setText(str); + } + else + { + QRect rt = m_pLblImage->rect(); + int h = img.height(); + int w = img.width(); + float d = w*1.0 / h; + if (d > 0) + { + int h2 = rt.width() / d; + rt.setHeight(h2); + } + QImage imgShow = img.scaled(QSize(rt.size())); + m_pLblImage->setPixmap(QPixmap::fromImage(imgShow)); + } + +} + +QString Station::currentSelectModel() +{ + if (m_pView) { + int row = m_pView->currentRow(); + if (modelCount() > row) { + return model(row); + } + } + return QString(); +} + +QString Station::genTimerInfo(QString strPre /*= ""*/, QString strFormat /*= ""*/, QString strEnd /*= ": "*/) +{ + QTime dTime = QTime::currentTime(); + QString strTime = dTime.toString() + ":" + QString::number(dTime.msec()) + strEnd; + return strTime; +} + +QString Station::stationKey() +{ + return szCamKey; +} + +QString Station::stationShowName() +{ + return szShow; +} + +WfModel * Station::wfModel(QString str) +{ + return m_pWfCtrl->IGetModelInfo(nId, str); + +} + +bool Station::isWorkingOk() +{ + return true; +} + +QString Station::modelByPlcCmd(int nIndex) +{ + //qWarning() << "modelByPlcCmd, nIndex is :" << nIndex; + for (int i = 0; i < m_models.size(); i++) { + WfModel *pModel = wfModel(m_models.at(i)); + if (pModel && pModel->nIndex == nIndex) { + QString strModel =m_models.at(i); + if (currentRunningModel() == strModel) + { + m_CurrentPLCIndex = nIndex; + return strModel; + } + m_CurrentPLCIndex = nIndex; + return strModel; + } + } + m_CurrentPLCIndex = 0; + qWarning() << "modelByPlcCmd, nIndex is invalid; index = " << nIndex; + return QString(); +} + +bool Station::startBatchTest(QString strBasePath) +{ + if (m_pWfCtrl->IBatchModel()) { + + return true; + } + + return false; +} + +bool Station::changeImageFolder(const QString str) +{ + TP_CAMERA_OPTION camOpt; + camOpt.uniqueName = szCamKey; + m_pCoreCtrl->ICameraOption(szCamKey, camOpt); + camOpt.folder = str; + m_pCoreCtrl->ISetCameraOption(szCamKey, camOpt); + if (m_pWfCtrl->IBatchModel()) { + } + + return true; +} diff --git a/src/lpMain/Station.h b/src/lpMain/Station.h new file mode 100644 index 0000000..211bb89 --- /dev/null +++ b/src/lpMain/Station.h @@ -0,0 +1,96 @@ +#pragma once +#include "qlist.h" +#include "qstring.h" +#include "qstringlist.h" +#include "qlabel.h" +#include "qtextedit.h" +#include "IStation.h" +enum EM_ADD_DELETE_OPERATION { + emADD = 0, emDELETE = 1 +}; + + + +#define _WF_LIST_SPLIT "_-_" +#define _WF_CURRENT_OBJECT_PREFIX "current_object_" +#define _WF_READ_FROM_PLC_STATE "read_from_plc_state" +#define _WF_CALI_STATE_STATION_PREFIX "cali_state_station_" + +class ICoreCtrl; +class QSqliteWheelHubWf; +class IWfCtrl; +class Station : public IStation +{ + Q_OBJECT +public: + Station(QSqliteWheelHubWf *p1, ICoreCtrl *p2, IWfCtrl * p3); + virtual ~Station(); + virtual int stationId(); + virtual QString stationKey(); + virtual QString stationShowName(); + virtual void setCamInfo(int nId, int alg, QString uniqueName, QString showName); + virtual void setComInfo(QString strName, int nCmd); + virtual QVariant getVariant(); + virtual void revResult(); + virtual bool trigImage(const QString folder = QString()); + virtual bool isWorkingOk(); + + virtual QString currentRunningModel() const { return m_strCurrentModel; } + virtual QString currentSelectModel(); + virtual void setCurrentModel(QString strModel); + virtual void setCurrentModel(int index); + virtual int modelCount(); + virtual QStringList modelList(); + virtual QString model(int index); + virtual QString modelByPlcCmd(int nIndex); + virtual WfModel *wfModel(QString); + virtual bool addModel(QString strModel); + virtual bool delModel(QString strModel); + + virtual bool sendResult(double); + virtual bool setWidget(QString str, QWidget *pWgt); + virtual bool IStandard(QString strModel); + + Q_SLOT void showImage(const QImage &img); + Q_SLOT bool onAddResult2TextEdit(QString &str); + Q_SLOT void onErrTrig(int); + + virtual bool startBatchTest(QString strBasePath); + bool changeImageFolder(const QString); + + static unsigned short swapBigEndian(unsigned short &data); + static QString genTimerInfo(QString strPre = "", QString strFormat = "", QString strEnd = ": "); +private: + class CTrigDetector *m_pTrigDetector; + class ModelView *m_pView; + QLabel *m_pLblImage{ NULL }; + QLabel *m_pLblStationName; + QTextEdit *m_pResultTextShow; + int nId; + int nAlgorithm; + QString szShow; + QString szCamKey; + + QString m_strComName; + int m_nCmd; + + static int s_nTrigWaitTimes; + QStringList m_models; + QString m_strCurrentModel; + int m_CurrentPLCIndex{ 0 }; + + QSqliteWheelHubWf *m_pDbWf; + ICoreCtrl *m_pCoreCtrl; + IWfCtrl *m_pWfCtrl; + class LabelManTest4Ui *m_pBatchTest; +public: + QString getModelUnique(const QString &model); + bool updateCurrentModel2Label(); + bool initCurrentModel(); + Q_SLOT bool updateAll(); + bool updateCurrentModel(); +signals: + void sgaddTrigCount(int ); + void sgaddRevCount(int); +}; + diff --git a/src/lpMain/TrigDetector.cpp b/src/lpMain/TrigDetector.cpp new file mode 100644 index 0000000..688a164 --- /dev/null +++ b/src/lpMain/TrigDetector.cpp @@ -0,0 +1,184 @@ +#include "TrigDetector.h" +#include "QDebug" +#include "qtimer.h" +#include "qdatetime.h" + + +CTrigDetector::CTrigDetector(QObject *parent) :QObject(parent) ,m_nMaxErrorCount(20), nTickCount(10) +{ + lastTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); + nCount = 0; + m_nTrigCount = m_nReceiveCount = 0; + m_nMaxTrigRecDiff = 1; + m_nCheckInterval = 4000; + m_nErrorTime = 2000; + m_nTimerID = -1; + m_pTimer = new QTimer(this); + m_setting = new QSettings(".\\user\\systemfile.ini", QSettings::IniFormat); + readSettingFile(); + connect(m_pTimer, SIGNAL(timeout()), this, SLOT(onChecker())); +} + + +CTrigDetector::~CTrigDetector() +{ + writeSettingFile(); + stop(); + delete m_pTimer; + if (m_setting){ + delete m_setting; + m_setting = NULL; + } +} + +void CTrigDetector::addTrigCount(int n /*= 1*/) +{ + if (m_nTrigCount - m_nReceiveCount >= m_nMaxTrigRecDiff) { + //error + qWarning() << "add trig count error, trig:" << m_nTrigCount << ", rev:" << m_nReceiveCount; + } + else { + m_nTrigCount++; + } +} + +bool CTrigDetector::start() +{ + stop(); + m_pTimer->start(m_nCheckInterval); + return true; +} + +// bool CTrigDetector::restart(int nInterval /*= -1*/) +// { +// if (nInterval > 0) { +// m_nCheckInterval = nInterval; +// } +// qDebug() << "reset trig count"; +// m_nReceiveCount = m_nTrigCount; +// start(); +// return true; +// } + +void CTrigDetector::onChecker() +{ + if (m_nTrigCount < m_nReceiveCount) { + qDebug() << "trig < rece"; + m_nReceiveCount = m_nTrigCount; + qDebug() << "m_nReceiveCount = m_nTrigCoun";// .... + } + else if (m_nReceiveCount < m_nTrigCount) { + m_nTmpErrorCount++; + emit(sgErrorTrig(m_nTmpErrorCount)); + } + else { + m_nTmpErrorCount = 0; + } +} + +bool CTrigDetector::isRunOk() +{ + if (m_nTrigCount == m_nReceiveCount || m_nReceiveCount + 1 == m_nTrigCount) { + return true; + } + return false; +} + +void CTrigDetector::addRevCount(int n /*= 1*/) +{ + m_nReceiveCount++; + m_nTmpErrorCount = 0; + + if (m_nReceiveCount > m_nTrigCount) { + //error + qWarning() << "addRevCount, rev bigger than trig"; + } + qDebug() << "rev result, count = " << m_nReceiveCount; +} + +bool CTrigDetector::stop() +{ + m_pTimer->stop(); + return true; +} + +bool CTrigDetector::isWaitForTrig() +{ + if (m_nReceiveCount == m_nTrigCount) { + qDebug() << "trig successful, trig count:" << m_nTrigCount; + return true; + } + qWarning() << "trig failed, trig count:" << m_nTrigCount << "; rev count:" << m_nReceiveCount; + return false; +} + +bool CTrigDetector::correct() +{ + qDebug() << "correct trig and rev"; + m_nReceiveCount = m_nTrigCount; + m_nTmpErrorCount = 0; + return true; +} + +bool CTrigDetector::filterTrig() +{ + /*static QMap s_mpLastTime; + long long dTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); + if (s_mpLastTime.contains(this)) { + long long lastTime = s_mpLastTime.value(this); + s_mpLastTime.take(this); + s_mpLastTime.insert(this, dTime); + long int interval = dTime - lastTime; + + if (interval < 350) { + qWarning() << "trig less than interval"; + if (nCount++ > nTickCount) + { + qWarning() << "correct"; + nCount = 0; + correct(); + return true; + } + return false; + } + } + s_mpLastTime.insert(this, dTime); + nCount = 0; + return true;*/ + + long long dTime = QDateTime::currentDateTime().toMSecsSinceEpoch(); + long int interval = dTime - lastTime; + lastTime = dTime; + if (interval < 0) + return true; + if (interval < 350) { + qWarning() << "trig less than interval"; + if (nCount++ > nTickCount) + { + qWarning() << "correct"; + nCount = 0; + correct(); + return true; + } + return false; + } + nCount = 0; + return true; +} + +void CTrigDetector::readSettingFile() +{ + if (m_setting){ + QString m_str = "/TrigDetector/"; + nTickCount = m_setting->value(m_str + "nTickFilter", 10).toInt(); + } +} + +void CTrigDetector::writeSettingFile() +{ + if (m_setting){ + QString m_str = "/TrigDetector/"; + m_setting->setValue(m_str + "nTickFilter", nTickCount); + } +} + diff --git a/src/lpMain/TrigDetector.h b/src/lpMain/TrigDetector.h new file mode 100644 index 0000000..71c48e8 --- /dev/null +++ b/src/lpMain/TrigDetector.h @@ -0,0 +1,69 @@ +#ifndef _TRIGDETECTOR_H_ +#define _TRIGDETECTOR_H_ + +#include +#include + +class CTrigDetector : public QObject +{ + Q_OBJECT +public: + CTrigDetector(QObject *parent =0); + ~CTrigDetector(); + + + void setCheckInterval(int nInterval) { + m_nCheckInterval = nInterval; + } + void setErrorTime(int nTime) { + m_nErrorTime = nTime; + } + int getCheckInterval() const { + return m_nCheckInterval; + } + int getErrorTime() const { + return m_nErrorTime; + } + int getCheckErrorCount() const { + return m_nTmpErrorCount; + } + int getTrigCount() const { + return m_nTrigCount; + } + int getRevCount() const { + return m_nReceiveCount; + } + bool correct(); + bool start(); + bool stop(); + bool isRunOk(); + bool isWaitForTrig(); + bool filterTrig(); + void readSettingFile(); + void writeSettingFile(); +signals: + void sgErrorTrig(int); + void sgSnapImage(); +public slots: + void onChecker(); + void addTrigCount(int n = 1); + void addRevCount(int n = 1); +private: + int m_nCheckInterval{0}; + int m_nErrorTime{0}; + int m_nTrigCount{0}; + int m_nReceiveCount{0}; + const int m_nMaxErrorCount; + int m_nTmpErrorCount{0}; + int m_nMaxTrigRecDiff{0}; + int m_nTimerID{0}; + class QTimer *m_pTimer{ nullptr }; + + QSettings *m_setting{ nullptr }; + int nTickCount{0}; + + int nCount{0}; + long long lastTime{0}; +}; + +#endif \ No newline at end of file diff --git a/src/lpMain/WfColossus.cpp b/src/lpMain/WfColossus.cpp new file mode 100644 index 0000000..68f0cb5 --- /dev/null +++ b/src/lpMain/WfColossus.cpp @@ -0,0 +1,380 @@ +#include "WfColossus.h" +#include "lpbengine.h" +#include "WfModel.h" +#include "lpbengine.h" + +#define WF_MODEL_TEMPLATE_NAME "TEMPLATE" +#pragma execution_character_set("utf-8") +WfColossus::WfColossus(IDetectorEngine*p) :m_IsModify(false) +{ + m_pDetEngine = p; + + QSettings setTaskInfo("TaskInfo.ini", QSettings::IniFormat); + int size = setTaskInfo.value("StationNum").toInt(); + for (int nIndex = 1; nIndex <= size; nIndex++){ + QString strKey = QString("Station_%1").arg(nIndex); + QString strModel = setTaskInfo.value(strKey).toString(); + if (!strModel.isEmpty()){ + m_CurRunTaskName[nIndex] = strModel; + } + } +} + + +WfColossus::~WfColossus() +{ +} + +bool WfColossus::addModel(int nIndex, QString strModel) +{ + IDetectorSolution* pSolutions = ptrRunSolution(); + if (!pSolutions) { + qWarning() << "add colossus, all solution is null"; + return false; + } + + bool bCreate = false; + QString strName = QString("%1##%2").arg(nIndex).arg(WF_MODEL_TEMPLATE_NAME); + IDetectorTask* pTask = pSolutions->GetTask(strName); + if (pTask) + { + IDetectorTask *pNew = pSolutions->AddAndCopyTask(pTask); + PLP_DETECTOR_TASK tTsk = pNew->GetTaskInfo(); + tTsk->strName = combineWithSymbol(QString::number(nIndex), strModel); + tTsk->bIsRun = false; + pNew->SetTaskInfo(tTsk); + bCreate = true; + } + + if (!bCreate) { + LP_DETECTOR_TASK tTsk; + tTsk.strName = combineWithSymbol(QString::number(nIndex), strModel); + IDetectorTask *pTaskNew = pSolutions->AddTask(&tTsk); + pTaskNew->LoadFile(""); + bCreate = true; + } + + m_IsModify = true; + return bCreate; +} + +bool WfColossus::delModel(int nIndex, QString strModel) +{ + IDetectorSolution* pSolutions = ptrRunSolution(); + QString strName = QString("%1##%2").arg(nIndex).arg(strModel); + if (pSolutions) + { + return pSolutions->DeleteTask(strName); + } + + return false; +} + +QMap WfColossus::allTask() +{ + QMap lstDst; + IDetectorSolution* pSolutions = ptrRunSolution(); + if (!pSolutions) { + qWarning() << "allTask, all solution is null"; + return lstDst; + } + + QStringList strKeys = pSolutions->GetAllTaskNames(); + + for (int i = 0; i < strKeys.size(); i++) { + IDetectorTask* pTask = pSolutions->GetTask(strKeys[i]); + if (!pTask) + continue; + PLP_DETECTOR_TASK tInfo = pTask->GetTaskInfo(); + QStringList l = splitBySymbol(tInfo->strName); + if (l.size() != 2) { + continue; + } + if (l.last() == WF_MODEL_TEMPLATE_NAME) { + continue; + } + WfModel *pInfo = new WfModel; + QVariantMap vMap = tInfo->property.toMap(); + pInfo->bCaliState = vMap.value("model_cali").toBool(); + pInfo->nCount = vMap.value("model_count").toInt();; + pInfo->nIndex = vMap.value("model_plc").toInt();; + pInfo->strCreateTime = vMap.value("model_time").toString();; + lstDst.insert(tInfo->strName, pInfo); + } + return lstDst; +} + +QStringList WfColossus::allRunningTask() +{ + QStringList lstDst; + IDetectorSolution* pSolutions = ptrRunSolution(); + if (!pSolutions) { + qDebug() << "allRunningTask pSolutions is null"; + return lstDst; + } + QMap m = pSolutions->GetRunningTask(); + for (QMap::iterator it = m.begin(); it != m.end(); ++it){ + if (*it) + { + lstDst.append((*it)->GetTaskInfo()->strName); + } + } + if (lstDst.size() <= 0) + { + for (QMap::iterator it = m_CurRunTaskName.begin(); it != m_CurRunTaskName.end(); ++it){ + QString nerName = QString("%1##%2").arg(it.key()).arg(*it); + lstDst.append(nerName); + } + } + return lstDst; +} + +bool WfColossus::selModel(int nIndex, QString strModel) +{ + QString strName = combineWithSymbol(QString::number(nIndex), strModel); + IDetectorSolution* pSolutions = ptrRunSolution(); + if (!pSolutions) { + return false; + } + + m_CurRunTaskName[nIndex] = strModel; + + pSolutions->SetRunTask(nIndex, strName); + + + QSettings setTaskInfo("TaskInfo.ini", QSettings::IniFormat); + setTaskInfo.setValue("StationNum", m_CurRunTaskName.size()); + for (QMap::iterator it = m_CurRunTaskName.begin(); it != m_CurRunTaskName.end(); ++it){ + + setTaskInfo.setValue(QString("Station_%1").arg(it.key()), *it); + } + emit sgSetModel(nIndex, strModel); + +// IDetectorTask *pTasks[c_nMaxTask]; +// int n = pSolutions->EnumTask(pTasks, c_nMaxTask); +// //qDebug() << "all task count = " << n; +// bool bChanged = false; +// for (int i = 0; i < n; i++) { +// IDetectorTask* pTask = pTasks[i]; +// PLP_DETECTOR_TASK tInfo = pTask->GetTaskInfo(); +// QString str = tInfo->strName; +// QStringList l = splitBySymbol(str); +// if (l.size() != 2) { +// continue; +// } +// if (l.first().toInt() == nIndex) { +// if (tInfo->bIsRun == true && tInfo->strName != strName) { +// bChanged = true; +// } +// pTask->GetTaskInfo()->bIsRun = false; +// if (l.last() == strModel) { +// pTask->GetTaskInfo()->bIsRun = true; +// } +// } +// } +// if (bChanged == true) { +// int a = 0; +// int nID = ptrSolMgr()->GetRunSolution()->GetID(); +// if (nID == 2) +// int b = 0; +// qDebug() << " change models ID:" << nID; +// ptrSolMgr()->SetRunSolution(nID); +// } + //if () + /*m_IsModify = true;*/ + return true; +} + +bool WfColossus::modModel(int nIndex, QString strNewName,QString strOldName) +{ + IDetectorSolution* pSolutions = ptrRunSolution(); + if (!pSolutions) { + qWarning() << "mod colossus, all solution is null"; + return false; + } +// IDetectorTask *pTasks[c_nMaxTask]; +// int n = pSolutions->EnumTask(pTasks, c_nMaxTask); + bool bModify = false; +// for (int i = 0; i < n; i++) { +// IDetectorTask *pTask = pTasks[i]; +// QString str = pTask->GetTaskInfo()->strName; +// QStringList l = str.split("##"); +// if (l.size() != 2) { +// continue; +// } +// if (l.first().toInt() == nIndex && l.last() == strOldName) { +// IDetectorTask *pNew = pSolutions->AddAndCopyTask(pTask); +// PLP_DETECTOR_TASK tTsk = pNew->GetTaskInfo(); +// tTsk->strName = combineWithSymbol(QString::number(nIndex), strNewName); +// tTsk->bIsRun = false; +// pNew->SetTaskInfo(tTsk); +// bModify = true; +// break; +// } +// } + +// if (!bModify) { +// LP_DETECTOR_TASK tTsk; +// tTsk.strName = combineWithSymbol(QString::number(nIndex), strNewName); +// IDetectorTask *pTaskNew = pSolutions->AddTask(&tTsk); +// bModify = true; +// } + delModel(nIndex, strOldName); + m_IsModify = true; + return bModify; +} + +bool WfColossus::bStandard(int nIndex ,QString strModel) +{ + IDetectorSolution* pSolutions = ptrRunSolution(); + if (pSolutions) + { + QString strName = QString("%1##%2").arg(nIndex).arg(strModel); + IDetectorTask* pTask = pSolutions->GetTask(strName); + if (pTask) + { + bool b = pTask->GetTaskInfo()->templateImg.data == NULL; + if (b == true) + return false; + else + return true; + } + } + return false; +} + +bool WfColossus::saveTask(QMap infos) +{ + IDetectorSolution* pSolutions = ptrRunSolution(); + if (!pSolutions) { + qWarning() << "running solution is null "; + return false; + } + for (QMap::iterator it = infos.begin(); it != infos.end(); it++) + { + QString strName = it.key(); + IDetectorTask *pTask = pSolutions->GetTask(strName); + if (pTask) + { + PLP_DETECTOR_TASK tInfo = pTask->GetTaskInfo(); + QVariantMap vMap = tInfo->property.toMap(); + vMap.insert("model_plc", (*it)->nIndex); + vMap.insert("model_count", (*it)->nCount); + vMap.insert("model_time", (*it)->strCreateTime); + tInfo->property = vMap; + pTask->SetTaskInfo(tInfo); + } + } + ptrSolMgr()->Save(); + return true; +} + +QStringList WfColossus::getStationModels(int nIndex) +{ + IDetectorSolution* pSolutions = ptrRunSolution(); + if (!pSolutions) { + return QStringList(); + } + QStringList strList; +// IDetectorTask *pTasks[c_nMaxTask]; +// int n = pSolutions->EnumTask(pTasks, c_nMaxTask); +// bool bModify = false; +// for (int i = 0; i < n; i++) { +// IDetectorTask *pTask = pTasks[i]; +// QString str = pTask->GetTaskInfo()->strName; +// QStringList l = str.split("##"); +// if (l.size() != 2) { +// continue; +// } +// if (l.first().toInt() == nIndex) { +// strList.append(l.last()); +// } +// } + return strList; +} + +QStringList WfColossus::splitBySymbol(QString str) +{ + return str.split("##"); +} + +QString WfColossus::combineWithSymbol(QString s1, QString s2) +{ + return s1 + "##" + s2; +} + +class IDetectorSolutionMgr * WfColossus::ptrSolMgr() const +{ + void * p; + m_pDetEngine->GetDataInterface(SOLUTIONMGR, &p); + return (IDetectorSolutionMgr*)p; +} + +class IDetectorSolution * WfColossus::ptrRunSolution() const +{ + IDetectorSolutionMgr*pMgr = ptrSolMgr(); + if (pMgr) { + return pMgr->GetRunSolution(); + } + qWarning() << "solution mgr is null"; + return NULL; +} + +// bool WfColossus::getOnlineModel() const +// { +// IDetectorSystemInfo * p; +// m_pDetEngine->GetDataInterface(SYSTEMINFO, (void**)&p); +// if (p) { +// return p->GetValue("OnlineMode").toBool(); +// } +// return false; +// } +// +// void WfColossus::setOnlineModel(bool b) +// { +// IDetectorSystemInfo * p; +// m_pDetEngine->GetDataInterface(SYSTEMINFO, (void**)&p); +// if (p) { +// p->SetValue("OnlineMode", b); +// } +// } + +bool WfColossus::getBatchModel() const +{ + IDetectorSystemInfo * p; + m_pDetEngine->GetDataInterface(SYSTEMINFO, (void**)&p); + if (p) { + return p->GetValue("wf_batch_test", false).toBool(); + } + return false; +} + +bool WfColossus::updateModelInfo(QMap &infos) +{ + IDetectorSolution* pSolutions = ptrRunSolution(); + if (!pSolutions) { + qWarning() << "updateModelInfo solution is null "; + return false; + } +// IDetectorTask *pTasks[c_nMaxTask]; +// int n = pSolutions->EnumTask(pTasks, c_nMaxTask); +// for (int i = 0; i < n; i++) { +// IDetectorTask *pTask = pTasks[i]; +// if (!pTask) { +// qWarning() << "updateModelInfo, task is null " << i; +// continue; +// } +// QString str = pTask->GetTaskInfo()->strName; +// WfModel *pModel = infos.value(str); +// if (!pModel) { +// continue; +// } +// PLP_DETECTOR_TASK tInfo = pTask->GetTaskInfo(); +// QVariantMap vMap = tInfo->property.toMap(); +// pModel->bCaliState = vMap.value("model_cali").toBool(); +// } + + return true; +} + + diff --git a/src/lpMain/WfColossus.h b/src/lpMain/WfColossus.h new file mode 100644 index 0000000..9ee07cc --- /dev/null +++ b/src/lpMain/WfColossus.h @@ -0,0 +1,46 @@ +#ifndef _WFCOLOSSUS_H_ +#define _WFCOLOSSUS_H_ +#include +#include +#include +class IDetectorEngine; +class WfColossus:public QObject +{ + Q_OBJECT +public: + WfColossus(IDetectorEngine* p); + ~WfColossus(); + bool addModel(int, QString); + bool delModel(int, QString); + bool selModel(int, QString); + bool modModel(int nIndex, QString strNewName, QString strOldName); + bool bStandard(int ,QString); + class IDetectorSolutionMgr *ptrSolMgr() const; + class IDetectorSolution *ptrRunSolution() const; + QMap allTask(); + + bool updateModelInfo(QMap &info); +// bool getOnlineModel() const; +// void setOnlineModel(bool b); + bool getBatchModel() const; + QStringList allRunningTask(); + bool saveTask(QMap); + + void setModifyState(bool bFlag){ m_IsModify = bFlag; }; + bool getModifyState() const{ return m_IsModify; }; + void ReSetModifyState() { m_IsModify = false; }; + + QStringList getStationModels(int nIndex); +signals: + void sgSetModel(int, QString); +private: + QStringList splitBySymbol(QString); + QString combineWithSymbol(QString, QString); + + bool m_IsModify{ false };//Ƿ޸ ʾǷҪ +private: + IDetectorEngine *m_pDetEngine{ nullptr }; + QMap m_CurRunTaskName; +}; + +#endif \ No newline at end of file diff --git a/src/lpMain/WfCtrl.cpp b/src/lpMain/WfCtrl.cpp new file mode 100644 index 0000000..dd55a8b --- /dev/null +++ b/src/lpMain/WfCtrl.cpp @@ -0,0 +1,395 @@ +#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//"); + initGolbal(); + initStation(); + initModel(); + initCurrentModel(); + 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); + delete m_pConnectChecker; + delete m_pWfDb; + 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::initGolbal() +{ + //m_nOnlineMode = m_pColossus->getOnlineModel(); + + // get comm name +// QString strConfig = m_pMainBack->IJsonUser().value("config").toString(); +// QString strPath = m_pMainBack->IDllPaths().size() == 0 ? ".\\" : m_pMainBack->IDllPaths().first(); +// QJsonObject objJson = QZkJsonParser::ReadJsonObject(strPath + "\\" + strConfig + "\\communicate.json"); +// if (!objJson.empty()) { +// QJsonValue jValue = objJson["COM"]; +// if (jValue.isArray()) { +// QJsonArray jArray = jValue.toArray(); +// for (int i = 0; i < jArray.size(); ++i) { +// if (!jArray[i].isObject()) { +// continue; +// } +// QJsonObject objTmp = jArray[i].toObject(); +// m_strCommName = objTmp.value("name").toString(); +// qDebug() << "comm name is " << m_strCommName; +// break; +// } +// } +// } +// else { +// qWarning() << "can not find communicate.json"; +// } +} + +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() +{ + QStringList camKeys = m_pCoreCtrl->ICameraKeys(); + QString strCom = "COM3"; + 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); + pStation->setComInfo(strCom, 0x46 + camOpt.id - 1); + 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); + } + m_mpModels.insert(genModelName(nStation, strModel), new WfModel); + 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::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 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); + } +} + diff --git a/src/lpMain/WfCtrl.h b/src/lpMain/WfCtrl.h new file mode 100644 index 0000000..38c6aae --- /dev/null +++ b/src/lpMain/WfCtrl.h @@ -0,0 +1,69 @@ +#ifndef _WFCTRL_H_ +#define _WFCTRL_H_ + +#include +#include +#include +#include "IWfCtrl.h" +#include "QDiskCleanThread.h" + +class ICoreCtrl; +class IMainCallback; +class WfColossus; +class CWfCtrl : public IWfCtrl +{ + Q_OBJECT +public: + CWfCtrl(ICoreCtrl *, WfColossus*); + virtual~CWfCtrl(); + virtual bool IOnlineMode(); + virtual void ISetOnlineModel(bool); + virtual bool IBatchModel(); + virtual bool IConnectStatus(); + virtual QString IGetCommName(); + virtual void ISetUserInfo(QString& user, int& level); + virtual bool IGetUserInfo(QString& user, int& level); + virtual void registerConnect(); + virtual QStringList IGetStationKeys(); + virtual IStation* IGetStationById(int); + virtual IStation* IGetStationByKey(QString); + virtual WfModel *IGetModelInfo(int, QString); + virtual bool IUpdateModelInfo(); + virtual QMapIGetModelInfos(); + virtual bool IStandard(int,QString strModel); + + virtual bool IAddModel(int, QString); + virtual bool IDeleteModel(int, QString); + virtual bool ISelModel(int, QString); + virtual void ISetModifyModel(bool bflag); + virtual QString IGetCurrentRuningModel(int); +private: + void initGolbal(); + bool initStation(); + bool initModel(); + bool initCurrentModel(); + static QString genModelName(int nIndex, QString strModel); + void readSettingFile(); + void writeSettingFile(); +private: + bool m_nOnlineMode{ false }; + //QString m_strCommName; + class WorkChecker *m_pConnectChecker{ nullptr }; + QMap m_pStationMap; + QMap m_mpModels; + ICoreCtrl *m_pCoreCtrl{ nullptr }; + IMainCallback *m_pMainBack{ nullptr }; + WfColossus *m_pColossus{ nullptr }; + class QSqliteWheelHubWf *m_pWfDb{ nullptr }; + + QList m_pDCThreadList; + QSettings *m_setting{ nullptr }; + int nCheckImgFileDays;//ⱣͼƬʱ䣨bmpʽͼƬ 㷨Զģ2~5MС + int nCheckDirDays;//ⱣͼƬļгʱ䣨ͼ 100kСͼƬ + bool nCheckThreadEable; + int nMinSpaceSize; + + QString m_strUserName; + int m_nLevel{ 0 }; +}; +#endif diff --git a/src/lpMain/WfModel.h b/src/lpMain/WfModel.h new file mode 100644 index 0000000..c2d4b44 --- /dev/null +++ b/src/lpMain/WfModel.h @@ -0,0 +1,16 @@ +#ifndef _WFMODEL_H_ +#define _WFMODEL_H_ + +#include +class WfModel +{ +public: + WfModel() { nCount = 0; bCaliState = false; nIndex = 100; }; + + int nCount; + QString strCreateTime; + bool bCaliState; + int nIndex; +}; + +#endif diff --git a/src/lpMain/algela/QTipWidget.cpp b/src/lpMain/algela/QTipWidget.cpp new file mode 100644 index 0000000..e477dbc --- /dev/null +++ b/src/lpMain/algela/QTipWidget.cpp @@ -0,0 +1,118 @@ +#include "QTipWidget.h" + +int ShowMessage(QString text) +{ + QTipWidget::showTips(QString(text), TIPS_SHORT); + return 0; +} + +void ShowMessagems(QString text, int time) +{ + QTipWidget::showTips(QString(text), time); +} +QTipWidget::QTipWidget(QWidget *parent) : + QDockWidget(parent) +{ + initGui(); +} + +void QTipWidget::initGui() +{ + this->setFeatures(QDockWidget::NoDockWidgetFeatures); + this->setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint | Qt::Tool | Qt::WindowStaysOnTopHint); + this->setAllowedAreas(Qt::NoDockWidgetArea); + this->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + this->setWindowOpacity(0.75); + setCursor(Qt::WaitCursor); + + mainFrame = new QFrame(this); + this->setWidget(mainFrame); + mainFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain); + mainFrame->setLineWidth(2); + mainFrame->setMidLineWidth(1); + + mainLayout = new QHBoxLayout(); + mainLayout->setSpacing(12); + mainLayout->setMargin(12); + mainFrame->setLayout(mainLayout); + + //iconLbl = new QLabel(this); + //iconLbl->setText(""); + //mainLayout->addWidget(iconLbl); + tipsLbl = new QLabel(this); + tipsLbl->setWordWrap(false); + tipsLbl->setAlignment(Qt::AlignCenter); + mainLayout->addWidget(tipsLbl); + QFont font = tipsLbl->font(); + font.setPointSize(14); + font.setBold(true); + tipsLbl->setFont(font); + + iconMovie = NULL; + + this->setStyleSheet("QWidget{ color:#FFFFFF;} QFrame { background-color : #515C63;}");//color:lightgray; +} + +void QTipWidget::setIcon(const QString& iconUrl) +{ + if (!iconUrl.isEmpty()) + { + if (NULL != iconMovie) + { + delete iconMovie; + } + iconMovie = new QMovie(this); + iconMovie->setFileName(iconUrl); + iconLbl->setMovie(iconMovie); + iconMovie->start(); + } +} + +void QTipWidget::setText(const QString& txt) +{ + tipsLbl->setText(txt); +} + +void QTipWidget::showTips(const QString& txt, int seconds) +{ + QTipWidget* tips = new QTipWidget(); + tips->setText(txt); + + QTimer::singleShot(seconds * 500, tips, SLOT(close())); + QTimer::singleShot(seconds * 501, tips, SLOT(deleteLater()));//延迟自动删除内存 + + tips->show(); + + QDesktopWidget dw; + QRect rect = dw.availableGeometry(); + int posX = (rect.width() - tips->width()) / 2; + int posY = (rect.height() - tips->height()) / 2; + tips->move(posX, posY); + QApplication::setActiveWindow(tips); + tips->raise(); +} + +QTipWidget* QTipWidget::showWaitingTips(const QString& iconUrl, const QString& txt) +{ + QTipWidget* tips = new QTipWidget(); + tips->setIcon(iconUrl); + tips->setText(txt); + + tips->show(); + + QDesktopWidget dw; + QRect rect = dw.availableGeometry(); + int posX = (rect.width() - tips->width()) / 2; + int posY = (rect.height() - tips->height()) / 2; + tips->move(posX, posY); + QApplication::setActiveWindow(tips); + tips->raise(); + + return tips; +} + +void QTipWidget::enterEvent(QEvent* event) +{ + this->raise(); + this->setFocus(Qt::MouseFocusReason); +} diff --git a/src/lpMain/algela/QTipWidget.h b/src/lpMain/algela/QTipWidget.h new file mode 100644 index 0000000..4e41cd2 --- /dev/null +++ b/src/lpMain/algela/QTipWidget.h @@ -0,0 +1,42 @@ +#ifndef YTIPSWIDGET_H +#define YTIPSWIDGET_H + + +#include +#include + +#define TIPS_LONG (5) +#define TIPS_SHORT (3) + +/* + *ϢʾؼԶʱϢ + * +*/ +int ShowMessage(QString text); +void ShowMessagems(QString text, int time); +class QTipWidget : public QDockWidget +{ + Q_OBJECT +public: + explicit QTipWidget(QWidget *parent = 0); + + void setIcon(const QString& iconUrl); + void setText(const QString& txt); + static void showTips(const QString& txt, int seconds);//ⲿҪú룺ʾϢʾʱ + static QTipWidget* showWaitingTips(const QString& iconUrl, const QString& txt); + +public slots: + +protected: + virtual void enterEvent(QEvent* event); + +private: + void initGui(); + QFrame* mainFrame; + QHBoxLayout* mainLayout; + QLabel* iconLbl; + QLabel* tipsLbl; + QMovie* iconMovie; +}; + +#endif // YTIPSWIDGET_H diff --git a/src/lpMain/algela/RoiImgViewer.cpp b/src/lpMain/algela/RoiImgViewer.cpp new file mode 100644 index 0000000..35d1508 --- /dev/null +++ b/src/lpMain/algela/RoiImgViewer.cpp @@ -0,0 +1,670 @@ +#include "RoiImgViewer.h" +#include +//#include "qtUtils.h" +#include +#include + + + //#define DEBUG_PRINT + + RoiImgViewer::RoiImgViewer(QWidget* parent /*= 0*/) + : lpImgViewer(parent) + , mMouseCaptureStatus(MouseCaptureNone) + , mDrawStatus(DrawNone) + , mMouseCaptureDistance(10) + , mpDrawingLineItem(NULL) + , mpDrawingRectItem(NULL) + , mpSelectedRoiNode(NULL) + { + connect(scene(), SIGNAL(selectionChanged()), this, SLOT(updateSelectedRoiNode())); + } + + QGraphicsPixmapItem* RoiImgViewer::setImg(QImage& img) + { + if (lpImgViewer::setImg(img)) + { + mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); + return mpImgItem; + } + else + { + return NULL; + } + } + + QGraphicsItem* RoiImgViewer::firstSelectedItem() + { + auto selectedItemList = scene()->selectedItems(); + if (selectedItemList.size()) + { + return selectedItemList.front(); + } + else + { + return NULL; + } + } + + void RoiImgViewer::setDrawStatus(DrawStatus s) + { + + mDrawStatus = s; + // if(mpImgItem){ + // if(DrawNone == s){ + // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, true); + // printf("RoiImgViewer::setDrawStatus true\n"); + // } + // else{ + // mpImgItem->setFlag(QGraphicsItem::ItemIsMovable, false); + // printf("RoiImgViewer::setDrawStatus false\n"); + // } + // } + } + + void RoiImgViewer::clearRois(int type /*= -1*/) + { + QGraphicsScene* pScene = scene(); + if (type < 0) + { + foreach(auto itemList, mRoiItemMap) + { + foreach(auto pItem, itemList) + { + pScene->removeItem(pItem); + delete pItem; + } + } + mRoiItemMap.clear(); + } + else + { + auto iterItem = mRoiItemMap.find(type); + if (iterItem != mRoiItemMap.end()) + { + foreach(auto pItem, mRoiItemMap[type]) + { + pScene->removeItem(pItem); + delete pItem; + } + mRoiItemMap.erase(iterItem); + } + } + + if (type < 0 || type == QGraphicsRectItem::Type) + { + mRoiNodeList.clear(); + mpSelectedRoiNode = NULL; + } + + rejectDrawingItem(); + } + + void RoiImgViewer::clearExistRois() + { + QGraphicsScene* pScene = scene(); + + foreach(auto itemList, mRoiItemMap) + { + foreach(auto pItem, itemList) + { + pScene->removeItem(pItem); + delete pItem; + } + } + mRoiItemMap.clear(); + mRoiNodeList.clear(); + mpSelectedRoiNode = NULL; + } + + void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate /*= true*/, QColor nonTmplColor /*= Qt::yellow*/) + { + DrawStatus backupDrawStatus = mDrawStatus; + QString backupChannelName = getChannel(); + + setChannel(channelName); + setDrawStatus(DrawRect); + mDrawingRect = rect; + createDrawingItem(); + + qreal backupFixedSizeScale = fixedSizeScale(); + setFixedSizeScale(scale); + acceptDrawingItem(); + lastRectRoi()->id = id; + lastRectRoi()->isTemplate = isTemplate; + if (!isTemplate) + { + //setPenColor(lastRectRoi()->pItem, nonTmplColor); + QPen pen = lastRectRoi()->pItem->pen(); + pen.setColor(nonTmplColor); + lastRectRoi()->pItem->setPen(pen); + } + setFixedSizeScale(backupFixedSizeScale); + + mDrawStatus = backupDrawStatus; + setChannel(backupChannelName); + } + + void RoiImgViewer::addRoiRect(QRectF rect, qreal scale, QString id) + { + setDrawStatus(DrawRect); + // QPolygonF qrect = mapToScene(rect.toRect()); + // mDrawingRect = qrect.boundingRect(); + mDrawingRect = rect; + createDrawingItem(); + updateDrawingItem(); + //setFixedSizeScale(scale); + acceptDrawingItem(); + lastRectRoi()->id = id; + } + + void RoiImgViewer::addRoiLine(QLineF line, QString id) + { + setDrawStatus(DrawLine); + mDrawingLine = line; + createDrawingItem(); + updateDrawingItem(); + acceptDrawingItem(); + //lastRectRoi()->id = id; + setDrawStatus(DrawNone); + } + + LP_ROI_NODE* RoiImgViewer::lastRectRoi() + { + if (mRoiNodeList.size()) + { + return &mRoiNodeList.last(); + } + else + { + return NULL; + } + } + + void RoiImgViewer::mousePressEvent(QMouseEvent *event) + { + QGraphicsItem* pItem = firstSelectedItem(); + if (!pItem) + { + lpImgViewer::mousePressEvent(event); + pItem = firstSelectedItem(); + } + + QPoint mousePos = event->pos(); + QPointF scenePos = mapToScene(mousePos); + + if (event->button() == Qt::LeftButton) + { + + if (!pItem) + { + // nothing is selected, start drawing + switch (mDrawStatus) + { + case DrawLine: + mDrawingLine.setP1(scenePos); + mDrawingLine.setP2(scenePos); + break; + case DrawRect: + mDrawingRect.setTopLeft(scenePos); + mDrawingRect.setBottomRight(scenePos); + break; + default: + break; + } + createDrawingItem(); + return; + } + else + { + // something is selected + + // map pos to selected item's local coordinates + QPointF itemMousePos = pItem->mapFromScene(scenePos); +#ifdef DEBUG_PRINT + printf("viewer mouse press pos %d %d\n", mousePos.x(), mousePos.y()); + printf("scene mouse press pos %f %f\n", scenePos.x(), scenePos.y()); + printf("item mouse press pos %f %f\n", itemMousePos.x(), itemMousePos.y()); +#endif + QGraphicsRectItem* pRectItem = dynamic_cast(pItem); + if (pRectItem) + { + QRectF r = pRectItem->rect(); +#ifdef DEBUG_PRINT + printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); +#endif + mMouseCaptureStatus = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); + + if (mMouseCaptureStatus != MouseCaptureNone) + { + pRectItem->setFlag(QGraphicsItem::ItemIsMovable, false); + return; + } + } + QGraphicsLineItem* pLineItem = dynamic_cast(pItem); + if (pLineItem) + { + QLineF l = pLineItem->line(); + + mMouseCaptureStatus = decideMouseCaptureStatus(l, itemMousePos, mMouseCaptureDistance); + + if (mMouseCaptureStatus != MouseCaptureNone) + { + pLineItem->setFlag(QGraphicsItem::ItemIsMovable, false); + return; + } + } + } + } + + lpImgViewer::mousePressEvent(event); + } + + void RoiImgViewer::mouseMoveEvent(QMouseEvent *evt) + { + lpImgViewer::mouseMoveEvent(evt); + + QGraphicsItem* pItem = dynamic_cast( + firstSelectedItem()); + + QPoint mousePos = evt->pos(); + QPointF scenePos = mapToScene(mousePos); + + if (!pItem) + { + if (evt->buttons() == Qt::LeftButton) + { + switch (mDrawStatus) + { + case DrawLine: + mDrawingLine.setP2(scenePos); + break; + case DrawRect: + mDrawingRect.setBottomRight(scenePos); + break; + default: + break; + } + updateDrawingItem(); + } + } + else + { + QPointF itemMousePos = pItem->mapFromScene(scenePos); + + if (pItem->type() == QGraphicsRectItem().type()) + { + QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); + // map pos to selected item's local coordinates + + QRectF r = pRectItem->rect(); +#ifdef DEBUG_PRINT + printf("item rect %f %f %f %f\n", r.x(), r.y(), r.width(), r.height()); + printf("viewer mouse move pos %d %d\n", evt->pos().x(), evt->pos().y()); + printf("scene mouse move pos %f %f\n", scenePos.x(), scenePos.y()); + printf("item mouse move pos %f %f\n", itemMousePos.x(), itemMousePos.y()); + printf("mouse capture status %d\n", mMouseCaptureStatus); +#endif + if (evt->buttons() == Qt::LeftButton) + { + QRectF oriRect = r; + switch (mMouseCaptureStatus) + { + case MouseCaptureLeft: + r.setLeft(itemMousePos.x()); + r.setWidth(oriRect.right() - r.left()); + break; + case MouseCaptureRight: + r.setRight(itemMousePos.x()); + r.setWidth(r.right() - oriRect.left()); + break; + case MouseCaptureTop: + r.setTop(itemMousePos.y()); + r.setHeight(oriRect.bottom() - r.top()); + break; + case MouseCaptureBottom: + r.setBottom(itemMousePos.y()); + r.setHeight(r.bottom() - oriRect.top()); + break; + default: + case MouseCaptureNone: + break; + } + pRectItem->setRect(r); + } + + MouseCaptureStatus s = decideMouseCaptureStatus(r, itemMousePos, mMouseCaptureDistance); +#ifdef DEBUG_PRINT + printf("cur mouse status %d\n", s); +#endif + if (s == MouseCaptureLeft || s == MouseCaptureRight) + { + setCursor(Qt::SizeHorCursor); + } + else if (s == MouseCaptureTop || s == MouseCaptureBottom) + { + setCursor(Qt::SizeVerCursor); + } + else + { + setCursor(Qt::ArrowCursor); + } + } + else if (pItem->type() == QGraphicsLineItem().type()) + { + QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); + + } + } + + } + + void RoiImgViewer::mouseReleaseEvent(QMouseEvent *event) + { + if (event->button() == Qt::LeftButton) + { + mMouseCaptureStatus = MouseCaptureNone; + + QGraphicsItem* pItem = firstSelectedItem(); + if (!pItem) + { + // draw + switch (mDrawStatus) + { + case DrawLine: + if (mpDrawingLineItem) + { + emit roiAdded(mpDrawingLineItem); + } + break; + case DrawRect: + if (mpDrawingRectItem) + { + emit roiAdded(mpDrawingRectItem); + } + break; + default: + break; + } + acceptDrawingItem(); + } + else + { + // edit + pItem->setFlag(QGraphicsItem::ItemIsMovable, true); + + int itemType = pItem->type(); + if (itemType == QGraphicsRectItem().type()) + { + QGraphicsRectItem* pRectItem = qgraphicsitem_cast(pItem); + } + else if (itemType == QGraphicsLineItem().type()) + { + QGraphicsLineItem* pLineItem = qgraphicsitem_cast(pItem); + } + + emit roiChanged(pItem); + } + } + lpImgViewer::mouseReleaseEvent(event); + } + + void RoiImgViewer::wheelEvent(QWheelEvent *evt) + { + lpImgViewer::wheelEvent(evt); + + if (!mpSelectedRoiNode) + { + return; + } + + mpSelectedRoiNode->fScale = mFixedSizeScale; + } + + void RoiImgViewer::keyPressEvent(QKeyEvent *event) + { + if (mpSelectedRoiNode && Qt::Key_Delete == event->key()) { + QGraphicsScene* pScene = scene(); + + foreach(auto itemList, mRoiItemMap) + { + foreach(auto pItem, itemList) + { + if (pItem == mpSelectedRoiNode->pItem) { + pScene->removeItem(pItem); + + auto i1 = std::find_if(itemList.begin(), itemList.end(), [&](QGraphicsItem* pi) + { + return pi == pItem; + }); + itemList.erase(i1); + + auto i2 = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) + { + return roiNode.pItem == pItem; + }); + mRoiNodeList.erase(i2); + + delete pItem; + mpSelectedRoiNode = NULL; + return; + } + } + } + } + } + + QRectF extRect(const QRectF& r, float w) + { + return QRectF(r.x() - w, r.y() - w, r.width() + 2.0 * w, r.height() + 2.0*w); + } + + RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QRectF r, QPointF p, float capDis /*= 10*/) + { + MouseCaptureStatus ret = MouseCaptureNone; + + QRectF validRect = extRect(r, capDis); + if (!validRect.contains(p)) + { + return ret; + } + + if (abs(p.x() - r.left()) < capDis) + { + ret = MouseCaptureLeft; + } + else if (abs(p.x() - r.right()) < capDis) + { + ret = MouseCaptureRight; + } + else if (abs(p.y() - r.top()) < capDis) + { + ret = MouseCaptureTop; + } + else if (abs(p.y() - r.bottom()) < capDis) + { + ret = MouseCaptureBottom; + } + + return ret; + } + + RoiImgViewer::MouseCaptureStatus RoiImgViewer::decideMouseCaptureStatus(const QLineF l, QPointF p, float capDis /*= 10*/) + { + return MouseCaptureNone; + } + + void RoiImgViewer::updateSelectedRoiNode() + { + QGraphicsItem* pItem = firstSelectedItem(); + + LP_ROI_NODE *pRoiNode = findRoiNode(pItem); + if (pRoiNode != mpSelectedRoiNode) + { + mpSelectedRoiNode = pRoiNode; + emit roiSelectionChanged(mpSelectedRoiNode); + } + } + + void RoiImgViewer::updateDrawingItem() + { + switch (mDrawStatus) + { + case DrawLine: + if (mpDrawingLineItem) + { + QPen pen = mpDrawingLineItem->pen(); + pen.setColor(Qt::yellow); + pen.setWidth(5); + mpDrawingLineItem->setPen(pen); + mpDrawingLineItem->setLine(mDrawingLine); + } + else + { + qWarning() << tr("line item is not created"); + } + break; + case DrawRect: + if (mpDrawingRectItem) + { + QPen pen = mpDrawingRectItem->pen(); + pen.setColor(Qt::yellow); + pen.setWidth(5); + mpDrawingRectItem->setPen(pen); + mpDrawingRectItem->setRect(mDrawingRect); + } + else + { + qWarning() << tr("line item is not created"); + } + break; + default: + break; + } + } + + void RoiImgViewer::createDrawingItem() + { + switch (mDrawStatus) + { + case DrawLine: + if (!mpDrawingLineItem) + { + mpDrawingLineItem = scene()->addLine(mDrawingLine); + mpDrawingLineItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + } + else + { + qWarning() << tr("line item is already created"); + } + break; + case DrawRect: + if (!mpDrawingRectItem) + { + mpDrawingRectItem = scene()->addRect(mDrawingRect); + mpDrawingRectItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable); + } + else + { + qWarning() << tr("rect item is already created"); + } + break; + default: + break; + } + } + + void RoiImgViewer::acceptDrawingItem() + { + //clearExistRois(); + switch (mDrawStatus) + { + case DrawLine: + if (mpDrawingLineItem) + { + acceptRoiItem(mpDrawingLineItem); + mpDrawingLineItem = NULL; + } + break; + case DrawRect: + if (mpDrawingRectItem) + { + acceptRoiItem(mpDrawingRectItem); + mpDrawingRectItem = NULL; + } + break; + default: + break; + } + } + + void RoiImgViewer::rejectDrawingItem() + { + switch (mDrawStatus) + { + case DrawLine: + scene()->removeItem(mpDrawingLineItem); + mpDrawingLineItem = NULL; + break; + case DrawRect: + scene()->removeItem(mpDrawingRectItem); + mpDrawingRectItem = NULL; + break; + default: + break; + } + } + + void RoiImgViewer::resetAllDrawingItems() + { + mpDrawingLineItem = NULL; + mpDrawingRectItem = NULL; + } + + void RoiImgViewer::acceptRoiItem(QGraphicsItem* pItem) + { + int type = pItem->type(); + if (mRoiItemMap.contains(type)) + { + mRoiItemMap[type].append(pItem); + } + else + { + QList itemList; + itemList << pItem; + mRoiItemMap.insert(type, itemList); + } + + if (type == QGraphicsRectItem::Type) + { + LP_ROI_NODE roi_node; + roi_node.fScale = fixedSizeScale(); + roi_node.szChannel = getChannel(); + roi_node.pItem = qgraphicsitem_cast(pItem); + + //roi_node.id = uniqueTimeID(); + qint64 msecs = QDateTime::currentMSecsSinceEpoch(); + roi_node.id = QString::number(msecs, 16); + + roi_node.isTemplate = true; + mRoiNodeList.append(roi_node); + } + + } + + LP_ROI_NODE* RoiImgViewer::findRoiNode(QGraphicsItem* pItem) + { + auto i = std::find_if(mRoiNodeList.begin(), mRoiNodeList.end(), [&](LP_ROI_NODE& roiNode) + { + return roiNode.pItem == pItem; + }); + if (i == mRoiNodeList.end()) + { + return NULL; + } + else + { + return &(*i); + } + } + + diff --git a/src/lpMain/algela/RoiImgViewer.h b/src/lpMain/algela/RoiImgViewer.h new file mode 100644 index 0000000..c21ddca --- /dev/null +++ b/src/lpMain/algela/RoiImgViewer.h @@ -0,0 +1,109 @@ +#pragma once + +#include "lpImgViewer.h" +#include + +typedef struct tagLP_ROI_NODE { + QString id; + qreal fScale; + QString szChannel; + QGraphicsRectItem* pItem; + bool isTemplate; +}LP_ROI_NODE, *P_LP_ROI_NODE; +Q_DECLARE_METATYPE(LP_ROI_NODE*) + + + typedef QMap > RoiItemMap; + + class RoiImgViewer : public lpImgViewer + { + Q_OBJECT + + public: + enum MouseCaptureStatus + { + MouseCaptureLeft, + MouseCaptureRight, + MouseCaptureTop, + MouseCaptureBottom, + MouseCaptureNone + }; + + enum DrawStatus + { + DrawLine, + DrawRect, + DrawNone + }; + + public: + RoiImgViewer(QWidget* parent = 0); + ~RoiImgViewer() {}; + + virtual void wheelEvent(QWheelEvent *evt); + + QGraphicsPixmapItem* setImg(QImage& img); + + QGraphicsItem* firstSelectedItem(); + + void setDrawStatus(DrawStatus s); + + void clearRois(int type = -1); + void clearExistRois(); + + float getMouseCaptureDistance() const { return mMouseCaptureDistance; } + void setMouseCaptureDistance(float val) { mMouseCaptureDistance = val; } + + void addRoiRect(QRectF rect, qreal scale, QString channelName, QString id, bool isTemplate = true, QColor nonTmplColor = Qt::yellow); + void addRoiRect(QRectF rect, qreal scale, QString id); + + void addRoiLine(QLineF line, QString id); + + QList getRectROIs() const { return mRoiNodeList; } + LP_ROI_NODE* lastRectRoi(); + + protected: + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *evt); + void mouseReleaseEvent(QMouseEvent *event); + void keyPressEvent(QKeyEvent *event); + + MouseCaptureStatus decideMouseCaptureStatus(const QRectF r, + QPointF p, float capDis = 10); + MouseCaptureStatus decideMouseCaptureStatus(const QLineF l, + QPointF p, float capDis = 10); + + protected slots: + void updateSelectedRoiNode(); + + protected: + float mMouseCaptureDistance; + + MouseCaptureStatus mMouseCaptureStatus; + + DrawStatus mDrawStatus; + QLineF mDrawingLine; + QRectF mDrawingRect; + QGraphicsLineItem* mpDrawingLineItem; + QGraphicsRectItem* mpDrawingRectItem; + void updateDrawingItem(); + void createDrawingItem(); + void acceptDrawingItem(); + void rejectDrawingItem(); + void resetAllDrawingItems(); + + void acceptRoiItem(QGraphicsItem* pItem); + LP_ROI_NODE* findRoiNode(QGraphicsItem* pItem); + RoiItemMap mRoiItemMap; + QList mRoiNodeList; + LP_ROI_NODE* mpSelectedRoiNode; + + signals: + void roiChanged(QGraphicsItem* pItem); + void roiAdded(QGraphicsItem* pItem); + void roiSelectionChanged(LP_ROI_NODE* pSelectedRoiNode); + + private: + + }; + diff --git a/src/lpMain/algela/lpImgViewer.cpp b/src/lpMain/algela/lpImgViewer.cpp new file mode 100644 index 0000000..0832500 --- /dev/null +++ b/src/lpMain/algela/lpImgViewer.cpp @@ -0,0 +1,235 @@ +#include "lpImgViewer.h" +#include +#include +#include +#include +#include + + + + lpImgViewer::lpImgViewer(QWidget* parent /*= 0*/) + : QGraphicsView(parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), mMinScaleThre(0.01), + mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false) + { + QGraphicsScene* lpScene = new QGraphicsScene; + setScene(lpScene); + setResizeAnchor(QGraphicsView::AnchorUnderMouse); + setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + } + + lpImgViewer::lpImgViewer(QGraphicsScene *scene, QWidget *parent /*= 0*/) + : QGraphicsView(scene, parent), mpImgItem(NULL), mpInfoLabel(NULL), mpImg(NULL), m_scale(1.0), + mIsFixedSizeScale(false), mFixedSizeScale(1.0), mImgScaleFunc(NULL), mIsAutoResetTransform(false) + { + setResizeAnchor(QGraphicsView::AnchorUnderMouse); + setTransformationAnchor(QGraphicsView::AnchorUnderMouse); + } + + + void lpImgViewer::setInitScale(qreal val) + { + scaleImg2(val); + } + + + + + + QGraphicsPixmapItem* lpImgViewer::setImg(QImage& img) + { + if (mpImg) + delete mpImg; + mpImg = new QImage(img); + + if (!mpImgItem) + mpImgItem = scene()->addPixmap(QPixmap::fromImage(img, Qt::NoFormatConversion)); + else + mpImgItem->setPixmap(QPixmap::fromImage(img, Qt::NoFormatConversion)); + + mpImgItem->setOffset(-img.width() / 2.0, -img.height() / 2.0); + + mImgOriSize = img.size(); + mMinScaleThre = 1.0 / std::min(mImgOriSize.width(), mImgOriSize.height()); + //qreal scale = std::min((qreal)size().width() / img.width(), (qreal)size().height() / img.height()); + + if (isAutoResetTransform()) + { + mpImgItem->setPos(0, 0); + qreal scale = 1.0f; + scaleImg2(scale); + this->centerOn(0, 0); + } + mpImgItem->setFlags(QGraphicsItem::ItemIsMovable); + + return mpImgItem; + } + + void lpImgViewer::wheelEvent(QWheelEvent *evt) + { + if (mpImgItem) + { + qreal numDegrees = evt->angleDelta().y() / 120; + + if (!isFixedSizeScale()) + { + qreal newScale = transform().m11(); + if (numDegrees > 0) + newScale *= std::pow(1.1, numDegrees); + else if (numDegrees < 0) + newScale *= std::pow(0.9, -numDegrees); + + mpImgItem->setTransformOriginPoint(0, 0); + scaleImg2(newScale); + } + else + { + qreal newScale = fixedSizeScale(); + if (numDegrees > 0) + newScale *= std::pow(1.2, numDegrees); + else if (numDegrees < 0) + newScale *= std::pow(0.8, -numDegrees); + + if (newScale > 1.0) newScale = 1.0; + if (newScale < mMinScaleThre) newScale = mMinScaleThre; + + setFixedSizeScale(newScale); + + scaleImageWithFixedViewSize(); + } + } + } + + void lpImgViewer::mouseMoveEvent(QMouseEvent *evt) + { + if (mpImgItem) + { + QPoint curpos = (mpImgItem->mapFromScene(this->mapToScene(evt->pos())) + + QPointF(mImgOriSize.width() / 2.0, mImgOriSize.height() / 2.0) + QPointF(-0.5, -0.5)).toPoint(); + + if (mpInfoLabel) + selectPixel(curpos); + else + emit pixelSelected(curpos); + } + + if (mpImgItem && mpImgItem->isSelected()) + { + QPointF pos = mpImgItem->scenePos(); + qDebug() << pos; + emit imgMoved(pos); + } + + QGraphicsView::mouseMoveEvent(evt); + } + + void lpImgViewer::resizeEvent(QResizeEvent* evt) + { + QGraphicsView::resizeEvent(evt); + } + + void lpImgViewer::mouseReleaseEvent(QMouseEvent *evt) + { + QGraphicsView::mouseReleaseEvent(evt); + if (mpImgItem) + mpImgItem->setSelected(false); + } + + void lpImgViewer::closeEvent(QCloseEvent *evt) + { + deleteLater(); + } + + void lpImgViewer::moveImg(QPointF pos) + { + if (mpImgItem) + mpImgItem->setPos(pos); + } + + QString lpImgViewer::pixelInfoStr(QPoint pos, QRgb _rgb) + { + QColor rgb(_rgb); + QColor hsv = rgb.toHsv(); + QString infoStr("Position:[%1, %2] Color(RGB):[%3, %4, %5] (HSV):[%6, %7, %8]"); + infoStr = infoStr.arg(pos.x()).arg(pos.y()) + .arg(rgb.red()).arg(rgb.green()).arg(rgb.blue()) + .arg(hsv.hue() / 2).arg(hsv.saturation()).arg(hsv.value()); + return infoStr; + } + + void lpImgViewer::selectPixel(QPoint pos) + { + if (pos.x() < 0 || pos.y() < 0 || pos.x() > mImgOriSize.width() || pos.y() > mImgOriSize.height()) + { + mpInfoLabel->setText(QString("out of image...")); + return; + } + + if (!mpImgItem) + { + return; + } + + QImage img = mpImgItem->pixmap().toImage(); + QRgb pixel = img.pixel(pos); + + mpInfoLabel->setText(pixelInfoStr(pos, pixel)); + } + + void lpImgViewer::scaleImageWithFixedViewSize() + { + if (!mpImg) + { + return; + } + QImage scaledImage; + if (!imgScaleFunc()) + { + scaledImage = mpImg->scaled(mpImg->width()*mFixedSizeScale, mpImg->height()*mFixedSizeScale, + Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + mpImgItem->setPixmap(QPixmap::fromImage(scaledImage.scaled(mpImg->width(), + mpImg->height()), Qt::NoFormatConversion)); + } + else + { + scaledImage = mImgScaleFunc(*mpImg, mFixedSizeScale, Qt::SmoothTransformation); + mpImgItem->setPixmap(QPixmap::fromImage(mImgScaleFunc(scaledImage, + 1.0 / mFixedSizeScale, Qt::FastTransformation), Qt::NoFormatConversion)); + } + + emit imgScaledWithFixedSize(fixedSizeScale()); + } + + void lpImgViewer::scaleImg(QTransform tf, QPointF center) + { + this->resetTransform(); + this->setTransform(tf); + this->centerOn(center); + } + + void lpImgViewer::scaleImg2(qreal scale) + { + m_scale = scale; + QTransform t; + t.scale(scale, scale); + this->setTransform(t); + + QPointF center = this->mapToScene(width() / 2, height() / 2); + + emit imgScaled(this->transform(), center); + } + + void lpImgViewer::clear() + { + m_scale = 1.0f; + m_channel = ""; + scene()->clear(); + mpImgItem = NULL; + + if (mpImg) + { + delete mpImg; + mpImg = NULL; + } + } + + diff --git a/src/lpMain/algela/lpImgViewer.h b/src/lpMain/algela/lpImgViewer.h new file mode 100644 index 0000000..ab63cec --- /dev/null +++ b/src/lpMain/algela/lpImgViewer.h @@ -0,0 +1,81 @@ +#pragma once + +#include +#include +#include +#include + +typedef QImage (*ImageScaleFun)(QImage, double, int); + +class lpImgViewer : public QGraphicsView +{ + Q_OBJECT +public: + static QString pixelInfoStr(QPoint pos, QRgb rgb); + +public: + lpImgViewer(QGraphicsScene *scene, QWidget *parent = 0); + lpImgViewer(QWidget* parent = 0); + virtual ~lpImgViewer(){ + if (mpImg) + delete mpImg; + } + + virtual QGraphicsPixmapItem* setImg(QImage& img); + void setInfoLabel(QLabel* ipLabel){ mpInfoLabel = ipLabel; } + const QImage* img() { return mpImg; } + QGraphicsPixmapItem* imgItem() { return mpImgItem; } + + virtual void wheelEvent(QWheelEvent *evt); + virtual void mouseMoveEvent(QMouseEvent *evt); + virtual void resizeEvent(QResizeEvent* evt); + virtual void mouseReleaseEvent(QMouseEvent *evt); + virtual void closeEvent(QCloseEvent *evt); + virtual void clear(); + + virtual const qreal getScale(void) const { return m_scale; }; + virtual void setChannel(const QString& channel) { m_channel = channel; } + virtual QString getChannel() const { return m_channel; } + bool isFixedSizeScale() const { return mIsFixedSizeScale; } + void setIsFixedSizeScale(bool val) { mIsFixedSizeScale = val; } + qreal fixedSizeScale() const { return mFixedSizeScale; } + void setFixedSizeScale(qreal val) { mFixedSizeScale = val; } + ImageScaleFun imgScaleFunc() const { return mImgScaleFunc; } + void setImgScaleFunc(ImageScaleFun val) { mImgScaleFunc = val; } + void setInitScale(qreal val); + + bool isAutoResetTransform() const { return mIsAutoResetTransform; } + void setIsAutoResetTransform(bool val) { mIsAutoResetTransform = val; } + bool isAutoResetToWindowSize() const { return mIsAutoResetToWindowSize; } + void setIsAutoResetToWindowSize(bool val) { mIsAutoResetToWindowSize = val; } + +signals: + void imgScaled(QTransform tf, QPointF center); + void imgMoved(QPointF pos); + void pixelSelected(QPoint pos); + void imgScaledWithFixedSize(qreal scale); + +public slots: + void scaleImg(QTransform tf, QPointF center); + void moveImg(QPointF pos); + void selectPixel(QPoint pos); + void scaleImageWithFixedViewSize(); + +protected: + QGraphicsPixmapItem* mpImgItem; + QSize mImgOriSize; + qreal mMinScaleThre; + QLabel* mpInfoLabel; + QImage* mpImg; + + void scaleImg2(qreal scale); + qreal m_scale; + QString m_channel; + + bool mIsFixedSizeScale; + qreal mFixedSizeScale; + bool mIsAutoResetTransform; + bool mIsAutoResetToWindowSize; + + ImageScaleFun mImgScaleFunc; +}; diff --git a/src/lpMain/lpMain.qrc b/src/lpMain/lpMain.qrc new file mode 100644 index 0000000..f619ec9 --- /dev/null +++ b/src/lpMain/lpMain.qrc @@ -0,0 +1,22 @@ + + + Resource/wanfeng.png + Resource/wanfeng2.png + + + Resource/toolBar/administrator.png + Resource/toolBar/background.png + Resource/toolBar/cali.png + Resource/toolBar/education24.png + Resource/toolBar/help.png + Resource/toolBar/model.png + Resource/toolBar/save.png + Resource/toolBar/setting.png + Resource/toolBar/test.png + Resource/toolBar/messenger.png + + + Resource/app.png + Resource/app2.png + + diff --git a/src/lpMain/sqliteDB/DetectDataDB.cpp b/src/lpMain/sqliteDB/DetectDataDB.cpp new file mode 100644 index 0000000..8f1aee3 --- /dev/null +++ b/src/lpMain/sqliteDB/DetectDataDB.cpp @@ -0,0 +1,399 @@ +#include "DetectDataDB.h" +#include "InfoFile.h" +#include "gensql.h" + +#define _MD_WARNINGTABLE "warningtable" +/*myself */ +#define _MD_PRIMARY_KEY "uid" +#define _MD_TABLE_FORMS_MANE "wftable" //数据表名称 + +#define _MD_MODEL "model" //model 模型名称 +#define _MD_DIAMETER "diameter" //直径 +#define _MD_HIGHT "hight" //高度 +#define _MD_CORRELATE "correlate" //相似度 +#define _MD_CHANNEL "channel" //通道 +#define _MD_PICPATH "picpath" //图片路径 +#define _MD_ROTATE "rotate"//辐条个数 +#define _MD_UPDATE_TIME "time" //最后更新的时间 +#define _MD_PIC "pic" //图片 + + +#define _MD_TIMETABLE "wftimetable" +#define _MD_TYPE "type" +#define _MD_STARTTIME "starttime" +#define _MD_ENDTIME "endtime" + +#define _MD_WARNINGTABLE "warningtable" +#define _MD_MESSAGE "message" +#define _MD_CLASS "class" +#define _INDEX_FORTABLE "CREATE INDEX idx_wftable ON wftable (time COLLATE BINARY ASC); " +DetectDataDB::DetectDataDB(const QString& dbName,const QString &dbType) :DataBaseSql(dbName,dbType) +{ +// db = QSqlDatabase::addDatabase("QSQLITE"); +// db.setDatabaseName(dbName); +// if (!dbUser.isEmpty()){ +// db.setUserName(dbUser); +// db.setPassword(dbPwb); +// } +} + +DetectDataDB::~DetectDataDB() +{ + +} +//m_value.insert("time1", "");//起始时间 +//m_value.insert("time2", "");//结束时间 +//m_value.insert("name", "");//模型名字 +//m_value.insert("Type", "");//查询类型 +QString DataBaseSql::genCheckStr(QVariantMap m_value) +{ + int nType = m_value.value(_CHECK_TYPE_).toInt(); + QString select_sql; + switch (nType) + { + case EMT_CHECK_BY_TIME: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString strFifter = QString(" where time ='%1'").arg(time1); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount==1) + select_sql = QString("select count(*) from ") + _MD_TABLE_FORMS_MANE + strFifter; + else + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_NAME: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString modelname = m_value.value(_CHECK_NAME_).toString(); + QString strFifter = QString(" where time >'%1' and time < '%2' and model='%3'").arg(time1).arg(time2).arg(modelname); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount == 1) + select_sql = QString("select count(*) from ") + _MD_TABLE_FORMS_MANE + strFifter; + else + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_SAE: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString checktypeStr = m_value.value("CheckType").toString(); + QString strFifter = QString(" where time >'%1' and time < '%2'").arg(time1).arg(time2); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount == 1) + select_sql = QString("select count(*) from ") + _MD_TABLE_FORMS_MANE + strFifter; + else{ + if (checktypeStr == "Count") + select_sql = QString("select %1 from ").arg(_MD_MODEL) + _MD_TABLE_FORMS_MANE + strFifter; + else + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + } + break; + case EMT_CHECK_BY_LOG: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + int logType = m_value.value(_CHECK_LOGTYPE).toInt(); + QString strFifter = QString(" where time >'%1' and time < '%2' and class = '%3' order by time desc ").arg(time1).arg(time2).arg(logType); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount == 1) + select_sql = QString("select count(*) from ") + _MD_WARNINGTABLE + strFifter; + else + select_sql = QString("select * from ") + _MD_WARNINGTABLE + strFifter; + } + break; + case EMT_CHECK_BY_COUNT: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString checktypeStr = m_value.value("CheckType").toString(); + QString strFifter = QString(" where time >'%1' and time < '%2'").arg(time1).arg(time2); + int IsCount = m_value.value(_CHECK_COUNT_).toInt(0); + if (IsCount == 1) + select_sql = QString("select count(*) from ") + _MD_TABLE_FORMS_MANE + strFifter; + else{ + QString strGroup = QString(" GROUP BY %1 ORDER BY %2").arg(_MD_MODEL).arg(_MD_MODEL); + if (checktypeStr == "Count") + select_sql = QString("select %1 from ").arg(_MD_MODEL).arg(_MD_MODEL) + _MD_TABLE_FORMS_MANE + strFifter;// +strGroup; + else + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + } + break; + default: + break; + } + return select_sql; +} + +bool DetectDataDB::checkoutData(QVariantMap m_value, QSqlQuery &sql) +{ + int nType = m_value.value(_CHECK_TYPE_).toInt(); + QString select_sql; + switch (nType) + { + case EMT_CHECK_BY_TIME: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString strFifter = QString(" where time ='%1'").arg(time1); + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_NAME: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString modelname = m_value.value(_CHECK_NAME_).toString(); + QString strFifter = QString(" where time >'%1' and time < '%2' and model='%3'").arg(time1).arg(time2).arg(modelname); + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_SAE: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + QString strFifter = QString(" where time >'%1' and time < '%2'").arg(time1).arg(time2); + select_sql = QString("select * from ") + _MD_TABLE_FORMS_MANE + strFifter; + } + break; + case EMT_CHECK_BY_LOG: + { + QString time1 = m_value.value(_CHECK_TIME1_).toString(); + QString time2 = m_value.value(_CHECK_TIME2_).toString(); + int logType = m_value.value(_CHECK_LOGTYPE).toInt(); + QString strFifter = QString(" where time >'%1' and time < '%2' and class = '%3' order by time desc ").arg(time1).arg(time2).arg(logType); + select_sql = QString("select * from ") + _MD_WARNINGTABLE + strFifter; + } + break; + default: + break; + } + + sql = db->exec(select_sql); + return true; +} + +bool DetectDataDB::checkoutData(QString selectStr, QSqlQuery &sql) +{ + sql = db->exec(selectStr); + return true; +} + +bool DetectDataDB::DelDatasByTime(QString minTime) +{ + QString StrTime = QString("time <'%1'").arg(minTime); + QString select_sql = QString("DELETE FROM %1 WHERE %2").arg(_MD_TABLE_FORMS_MANE).arg(StrTime); + db->exec(select_sql); + return true; +} + +bool DetectDataDB::DelAllDatas() +{ + QString strSqll = QString("delete from %1 ").arg(_MD_TABLE_FORMS_MANE); + db->exec(strSqll); + strSqll = QString("delete from %1 ").arg("warningtable"); + db->exec(strSqll); + return true; +} + +bool DetectDataDB::DelWarnDataByCount(int model /*=1*/, int nCount/*=100000*/) +{ + QString strLimit1 = QString("select count(uid) from %1 where class = '%3'").arg("warningtable").arg(model); + QString strLimit2 = QString("uid in(select uid from %1 where class = '%2' order by time desc limit(select count(uid) from %3 where class = '%4') offset %5)").arg("warningtable").arg(model).arg("warningtable").arg(model).arg(nCount); + QString strSqll = QString("delete from %1 where (%2)>%3 and %4").arg("warningtable").arg(strLimit1).arg(nCount).arg(strLimit2); + QSqlQuery sql = db->exec(strSqll); + return true; +} + +bool DetectDataDB::InitDatabase() +{ + if (!openDB()) + { + return false; + } + + QString strCheckTable = QString("select name from sqlite_master where type='table' order by name;"); + QSqlQuery sql = db->exec(strCheckTable);//查询数据库中所有的数据表 + QStringList tablenamelist; + while (sql.next()) + { + QString strname = sql.value(0).toString(); + tablenamelist.append(strname); + } + if (!tablenamelist.contains(_MD_TABLE_FORMS_MANE))//是否包含 table 否则创建新表 + { + QVariantMap vDataMap; + vDataMap.insert(_MD_MODEL, "VARCHAR(32)"); + vDataMap.insert(_MD_DIAMETER, "INT(100)");//直径 + vDataMap.insert(_MD_HIGHT, "INT(100)");//高度 + vDataMap.insert(_MD_CORRELATE, "INT(100)");//相似度 + vDataMap.insert(_MD_CHANNEL, "INT(100)"); + vDataMap.insert("detecttime", "VARCHAR(32)"); + vDataMap.insert(_MD_UPDATE_TIME, "DATETIME(32)"); + vDataMap.insert(_MD_PIC, "BLOB"); + if (!CreatTable(_MD_TABLE_FORMS_MANE, _MD_PRIMARY_KEY, vDataMap)) + { + //return false; + } + else + { + QString strIndex = QString("CREATE INDEX idx_wftable ON wftable (time COLLATE BINARY ASC); "); + db->exec(strIndex);//创建索引 + } + } + + if (!tablenamelist.contains(_MD_TIMETABLE)) + { + QVariantMap vTimeMap;//保存班次时间 + vTimeMap.insert(_MD_TYPE, "VARCHAR(32)"); + vTimeMap.insert(_MD_STARTTIME, "VARCHAR(32)"); + vTimeMap.insert(_MD_ENDTIME, "VARCHAR(32)"); + if (!CreatTable(_MD_TIMETABLE, _MD_PRIMARY_KEY, vTimeMap)) + { + //return false; + } + else{ + + } + } + + if (!tablenamelist.contains(_MD_WARNINGTABLE)) + { + QVariantMap vWarningMap;//报警信息 + vWarningMap.insert(_MD_MESSAGE, "VARCHAR(256)"); + vWarningMap.insert(_MD_CLASS, "VARCHAR(32)"); + vWarningMap.insert(_MD_UPDATE_TIME, "DATETIME(32)"); + if (!CreatTable(_MD_WARNINGTABLE, _MD_PRIMARY_KEY, vWarningMap)) + { + //return false; + + } + else{ + QString strIndex = QString("CREATE INDEX idx_warningtable ON warningtable (time COLLATE BINARY ASC); "); + db->exec(strIndex); + } + } + + return true; +} + +bool DetectDataDB::ReadOutTimeData(QMap &m_MapTimeMatch) +{ + QString select_sql = QString("select * from ") + _MD_TIMETABLE; + QSqlQuery sql = db->exec(select_sql); + QSqlError err = sql.lastError(); + int t = err.type(); + if (t != QSqlError::NoError) + { + return false; + } + while (sql.next()) + { + int nIndex = sql.value("uid").toInt(); + QString type = sql.value(_MD_TYPE).toString(); + QTime start = sql.value(_MD_STARTTIME).toTime(); + QTime end = sql.value(_MD_ENDTIME).toTime(); + TimeStruct m_timeStruct; + m_timeStruct.m_Index = nIndex; + m_timeStruct.m_name = type; + m_timeStruct.m_startTime = start; + m_timeStruct.m_endTime = end; + m_MapTimeMatch.insert(type, m_timeStruct); + } + return true; +} + +bool DetectDataDB::AddOneWarningMessage(WarnMessage m_messageInfo) +{ + QVariantMap m_map; + m_map.insert(_MD_MESSAGE, m_messageInfo.m_Message); + m_map.insert(_MD_UPDATE_TIME, m_messageInfo.m_Date); + m_map.insert(_MD_CLASS, m_messageInfo.m_class); + return InsertOneData(_MD_WARNINGTABLE, m_map); +} +bool DetectDataDB::AddOneTime(TimeStruct &m_timestruct) +{ + QVariantMap m_map; + m_map.insert(_MD_TYPE, m_timestruct.m_name); + m_map.insert(_MD_STARTTIME, m_timestruct.m_startTime); + m_map.insert(_MD_ENDTIME, m_timestruct.m_endTime); + return InsertOneData(_MD_TIMETABLE, m_map); +} +bool DetectDataDB::DelOneTime(TimeStruct &m_timestruct) +{ + QString m_map = gensql::genClass(_MD_TYPE, m_timestruct.m_name);//!>生成where条件语句 + QString strSql = gensql::genDeleteData(_MD_TIMETABLE, m_map); + db->exec(strSql); + if (db->lastError().isValid()) + { + return false; + } + return true; +} + +bool DetectDataDB::AddOneData(QVariantMap m_map) +{ + /*该部分数据是保存检测结果+结果图片*/ + + QString strInsert = "INSERT INTO %1(%2) VALUES(%3)"; + QString strHeader;// + QString strValue;// + + QStringList strKeys = m_map.keys(); + for (int i = 0; i < strKeys.size(); i++) { + strHeader += strKeys[i]; + if (i + 1 < strKeys.size()) + strHeader += ","; + strValue += ":" + strKeys[i] + ""; + + if (i + 1 < strKeys.size()) + strValue += ","; + } + strInsert = strInsert.arg(_MD_TABLE_FORMS_MANE, strHeader, strValue); + //return strInsert; + QSqlQuery query = db->exec(); + query.prepare(strInsert); + for (int i = 0; i < strKeys.size(); i++) + { + QString m_keys = strKeys.at(i); + QString str = ":" + m_keys; + query.bindValue(str, m_map.value(m_keys)); + } + query.exec(); + return true; +} + +bool DetectDataDB::AddOneData(QVariantMap m_map,QString strTableName) +{ + /*该部分数据是保存检测结果+结果图片*/ + + QString strInsert = "INSERT INTO %1(%2) VALUES(%3)"; + QString strHeader;// + QString strValue;// + + QStringList strKeys = m_map.keys(); + for (int i = 0; i < strKeys.size(); i++) { + strHeader += strKeys[i]; + if (i + 1 < strKeys.size()) + strHeader += ","; + strValue += ":" + strKeys[i] + ""; + + if (i + 1 < strKeys.size()) + strValue += ","; + } + strInsert = strInsert.arg(strTableName, strHeader, strValue); + QSqlQuery query = db->exec(); + query.prepare(strInsert); + for (int i = 0; i < strKeys.size(); i++) + { + QString m_keys = strKeys.at(i); + QString str = ":" + m_keys; + query.bindValue(str, m_map.value(m_keys)); + } + query.exec(); + return true; +} + diff --git a/src/lpMain/sqliteDB/DetectDataDB.h b/src/lpMain/sqliteDB/DetectDataDB.h new file mode 100644 index 0000000..ae393d4 --- /dev/null +++ b/src/lpMain/sqliteDB/DetectDataDB.h @@ -0,0 +1,34 @@ +#ifndef DETECTDATA_H +#define DETECTDATA_H +#include "databasesql.h" +#include +#include "InfoFile.h" +#include "QMutex" +/*DetectDataDB 用于记录检测数据 便于查询和插入*/ +class DetectDataDB : public DataBaseSql +{ + Q_OBJECT + +public: + DetectDataDB(const QString& dbName, const QString &dbType = QString("QSQLITE")); + ~DetectDataDB(); + virtual bool InitDatabase(); + + virtual bool checkoutData(QVariantMap m_value, QSqlQuery &sql); + virtual bool checkoutData(QString selectStr, QSqlQuery &sql); + virtual bool DelDatasByTime(QString minTime); + virtual bool DelAllDatas(); + virtual bool DelWarnDataByCount(int model /*=1*/, int nCount/*=100000*/); + bool AddOneWarningMessage(WarnMessage m_messageInfo); + + /*班次时间管理*/ + bool ReadOutTimeData(QMap &m_MapTimeMatch); + bool DelOneTime(TimeStruct &m_timestruct); + bool AddOneTime(TimeStruct &m_timestruct); + bool AddOneData(QVariantMap m_map); + bool AddOneData(QVariantMap m_map, QString strTableName); +private: + +}; + +#endif // DETECTDATA_H diff --git a/src/lpMain/sqliteDB/InfoFile.h b/src/lpMain/sqliteDB/InfoFile.h new file mode 100644 index 0000000..2d30418 --- /dev/null +++ b/src/lpMain/sqliteDB/InfoFile.h @@ -0,0 +1,53 @@ +#ifndef _INFOFILE_H_ +#define _INFOFILE_H_ +#include +#include +#include "qstringlist.h" +#define WS_PICSIZE 129 //!>缩放大小 +#define WS_PICSIZELIST 120 + +#define WF_HUBMODEL_ID "hubID" +#define WF_HUBMODEL_DIAMETER "diameter"//轮毂直径 +#define WF_HUBMODEL_HEIGHT "height"//轮毂厚度 +#define WF_HUBMODEL_CHANNELS "channels" +#define WF_HUBMODEL_FILEPATH "filepath" + +#define WF_LIFHT "Light" +#define WF_PLCPARA "PlcPara" +#define WF_PARASET "paraSetting"//PLC参数设置 +struct TimeStruct +{ + int m_Index; + QString m_name; + QTime m_startTime; + QTime m_endTime; +}; +struct WarnMessage +{ + QString m_Message; + QString m_Date; + QString m_class; +}; + +struct ChannelInfo +{ + QString m_ChannelName; + QString m_AboutName; + int m_value; + QStringList m_strModels; +}; +enum EM_LOG_TYPE{ + emTypeWaring = 1, + emTypeCameraState, + emTypeNetState, + emTypeRunState, + emTypeUseState +}; +enum emTypeBee{ + LIGHT_REDBEE = 0, + LIGHT_GREENBEE, + LIGHT_YELLOWBEE, + LIGHT_BEE +}; + +#endif diff --git a/src/lpMain/sqliteDB/QSqliteGeneral.cpp b/src/lpMain/sqliteDB/QSqliteGeneral.cpp new file mode 100644 index 0000000..ba55195 --- /dev/null +++ b/src/lpMain/sqliteDB/QSqliteGeneral.cpp @@ -0,0 +1,133 @@ +#include "QSqliteGeneral.h" + + +QSqliteGeneral::QSqliteGeneral(const QString& dbPath) + : QZkDbSqlite(dbPath) +{ +} + + +QSqliteGeneral::~QSqliteGeneral() +{ +} + +QString QSqliteGeneral::genInsertData(const QString & strTableName, const QString &strUniqueKey, const QString & strUniqueValue, const QVariantMap &vMap) +{ + QString strInsert = "INSERT INTO %1(%2) VALUES(%3)"; + QString strHeader = strUniqueKey; + QString strValue = "'" + strUniqueValue + "'"; + + QStringList strKeys = vMap.keys(); + for (int i = 0; i < strKeys.size(); i++) { + strHeader += ", " + strKeys[i]; + strValue += ", '" + vMap[strKeys[i]].toString() + "'"; + } + strInsert = strInsert.arg(strTableName, strHeader, strValue); + return strInsert; +} + +QString QSqliteGeneral::genSelect(const QString & strTableName, QStringList strSelectList, QString strClass) +{ + QString strDstSelect; + if (strClass.isEmpty()) { + strDstSelect = "SELECT %1 FROM %2"; + } + else { + strDstSelect = "SELECT %1 FROM %2 WHERE " + strClass; + } + + if (0 == strSelectList.size()) { + strDstSelect = strDstSelect.arg("*").arg(strTableName); + } + else { + QString strSeletTmp = strSelectList[0]; + for (int i = 1; i < strSelectList.size(); i++) { + strSeletTmp += "," + strSelectList[i]; + } + strDstSelect = strDstSelect.arg(strSeletTmp, strTableName); + } + + return strDstSelect; +} + +QString QSqliteGeneral::genClass(QString strName, QString strValue) +{ + QString strDst = ""; + strDst += strName + " = '" + strValue + "'"; + return strDst; +} + +QString QSqliteGeneral::genUpdate(const QString & strTableName, QVariantMap &vMap, QString strClass) +{ + //#define _WF_SQL_UPDATE_INFO_MODEL "UPDATE e_wh_models SET %1 = '%2' WHERE md_unique = '%3'" + QString strDst = "";// + if (strClass.isEmpty()) { + strDst = "UPDATE %1 SET %2"; + } + else { + strDst = "UPDATE %1 SET %2 WHERE %3"; + } + QString strUpdateTmp = ""; + if (vMap.size() != 0) { + QStringList strList = vMap.keys(); + strUpdateTmp += genClass(strList[0], vMap[strList[0]].toString()); + for (int i = 1; i < strList.size(); i++) { + strUpdateTmp += "," + genClass(strList[i], vMap[strList[i]].toString()); + } + } + + strDst = strDst.arg(strTableName, strUpdateTmp, strClass); + return strDst; +} + +QString QSqliteGeneral::genDeleteData(const QString & strTableName, QString strClass) +{ + //#define _WF_SQL_DELETE_MODEL "DELETE FROM e_wh_models WHERE md_unique = '%1'" + QString strDst; + if (strClass.isEmpty()) { + strDst = "DELETE FROM %1"; + } + else { + strDst = "DELETE FROM %1 WHERE %2"; + } + + strDst = strDst.arg(strTableName, strClass); + return strDst; +} + +QString QSqliteGeneral::genInsertColumn(const QString & strTableName, QString strName, QString strType) +{ + QString strDst = "ALTER TABLE %1 ADD COLUMN %2 %3"; + strDst = strDst.arg(strTableName).arg(strName).arg(strType); + + return strDst; +} + +QString QSqliteGeneral::genDeleteColumn(const QString & strTableName, QString strColumnName) +{ + QString strDst = "ALTER TABLE %1 DROP %2"; + strDst = strDst.arg(strTableName, strColumnName); + return strDst; +} + +QString QSqliteGeneral::genCreateTabel(const QString strTable, QString strPrimary, QString strType, QVariantMap &vMap) +{ + QString strDst = "CREATE TABLE IF NOT EXISTS %1 (%2)"; + QString strColumn = strPrimary + " " + strType; + QStringList strList = vMap.keys(); + for (int i = 0; i < strList.size(); i++) { + strColumn += ", " + strList[i] + " " + vMap[strList[i]].toString(); + } + strDst = strDst.arg(strTable, strColumn); + return strDst; +// +// "CREATE TABLE IF NOT EXISTS e_wh_models(md_unique VARCHAR(60) PRIMARY KEY \ +// , md_id VARCHAR(2) \ +// , md_index INT(100) \ +// , md_camKey VARCHAR(32) \ +// , md_model VARCHAR(20) \ +// , md_cali INT(1) DEFAULT '0' \ +// , md_stamp VARCHAR(32) \ +// , md_count INT(1) DEFAULT '0' \ +// , md_text TEXT)" +} \ No newline at end of file diff --git a/src/lpMain/sqliteDB/QSqliteGeneral.h b/src/lpMain/sqliteDB/QSqliteGeneral.h new file mode 100644 index 0000000..0649bd4 --- /dev/null +++ b/src/lpMain/sqliteDB/QSqliteGeneral.h @@ -0,0 +1,18 @@ +#pragma once +#include "QZkDbSqlite.h" +#include "QVariantMap" +class QSqliteGeneral : public QZkDbSqlite +{ +public: + QSqliteGeneral(const QString& dbPath); + ~QSqliteGeneral(); + QString genInsertData(const QString & strTableName, const QString &strUniqueKey, const QString & strUniqueValue, const QVariantMap &vMap); + QString genInsertColumn(const QString & strTableName, QString strName, QString strType); + QString genClass(QString strName, QString strValue); + QString genSelect(const QString & strTableName, QStringList strSelect = QStringList(), QString strClass = QString()); + QString genUpdate(const QString & strTableName, QVariantMap &vMap, QString strClass); + QString genDeleteData(const QString & strTableName, QString strClass = QString()); + QString genDeleteColumn(const QString & strTableName, QString strColumnName); + QString genCreateTabel(const QString strTable, QString strPrimary, QString strType, QVariantMap &vMap); +}; + diff --git a/src/lpMain/sqliteDB/QSqliteWheelHubWf.cpp b/src/lpMain/sqliteDB/QSqliteWheelHubWf.cpp new file mode 100644 index 0000000..269f11e --- /dev/null +++ b/src/lpMain/sqliteDB/QSqliteWheelHubWf.cpp @@ -0,0 +1,343 @@ +#include "QSqliteWheelHubWf.h" +#include "qmutex.h" + +#define _QSQLITE_WHEELHUBWF_NAME "wheelhubwf.db" + +#define _QSQLITE_CREATE_WHEELHUBWF_MODELS \ +"CREATE TABLE IF NOT EXISTS e_wh_models(md_unique VARCHAR(60) PRIMARY KEY \ +, md_id VARCHAR(2) \ +, md_index INT(100) \ +, md_camKey VARCHAR(32) \ +, md_model VARCHAR(20) \ +, md_cali INT(1) DEFAULT '0' \ +, md_stamp VARCHAR(32) \ +, md_count INT(1) DEFAULT '0' \ +, md_text TEXT)" + +#define _QSQLITE_CRETAE_WHEELHUBWF_R_MODEL_CAMERA \ +"CREATE TABLE IF NOT EXISTS r_wh_model_camera(model_id VARCHAR(16) \ +, camera_id INT(32) \ +, camera_key VARCHAR(255) \ +, add_stamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP \ +, mark_data BLOB \ +, PRIMARY KEY(model_id, camera_key))" +//#define _WF_SQL_SELECT_MODEL "SELECT * FROM e_wh_models WHERE md_unique = '%1'" +//#define _WF_SQL_SELECT_MODELS_ALL "SELECT md_id, md_stamp FROM e_wh_models ORDER BY md_stamp" +//#define _WF_SQL_INSERT_MODEL "INSERT INTO e_wh_models(md_unique, md_id, md_camKey, md_model, md_stamp) VALUES('%1', '%2', '%3', '%4', '%5')" +//#define _WF_SQL_INSERT_MODEL_PREFIX "INSERT INTO e_wh_models" +//#define _WF_SQL_DELETE_MODEL "DELETE FROM e_wh_models WHERE md_unique = '%1'" +//#define _WF_SQL_SELECT_INFO_MODEL "SELECT %1 FROM e_wh_models WHERE md_unique = '%2'" +// #define _WF_SQL_UPDATE_INFO_MODEL "UPDATE e_wh_models SET %1 = '%2' WHERE md_unique = '%3'" +//#define _WF_SQL_DELETE_HEADER "alter table e_wh_models drop %1" +// #define _WF_SQL_ADD_HEADER "alter table e_wh_models add column %1 %2" + + +/* +ijλϱ궨乤λ++ͺΨһġ +*/ + +QSqliteWheelHubWf::QSqliteWheelHubWf(const QString& dbPath) + : QSqliteGeneral(dbPath + _QSQLITE_WHEELHUBWF_NAME), m_mxLock(QMutex::Recursive) +{ + +} + +QSqliteWheelHubWf::~QSqliteWheelHubWf() +{ + +} + +bool QSqliteWheelHubWf::InitDatabase() +{ + if (!isOpen() && !open()) + { + return false; + } + //cerate default tables; + QVariantMap vMap; + vMap.insert(_WF_DB_MD_ID, "VARCHAR(2)"); + vMap.insert(_WF_DB_MD_INDEX, "INT(100)"); + vMap.insert(_WF_DB_MD_CAMKEY, "VARCHAR(32)"); + vMap.insert(_WF_DB_MD_MODEL, "VARCHAR(20)"); + vMap.insert(_WF_DB_MD_CALI, "INT(1) DEFAULT '0'"); + vMap.insert(_WF_DB_MD_STAMP, "VARCHAR(32)"); + vMap.insert(_WF_DB_MD_COUNT, "INT(1) DEFAULT '0'"); + vMap.insert(_WF_DB_MD_TEXT, "TEXT"); + + QString strSql = genCreateTabel(_WF_DB_MD_TABLE_NAME, _WF_DB_MD_PRIMARY_KEY, "VARCHAR(60) PRIMARY KEY", vMap); + QSqlQuery sql = exec(strSql); + QSqlError err = sql.lastError(); + int t = err.type(); + if (t != QSqlError::NoError) + { + return false; + } + + //sql = exec(_QSQLITE_CRETAE_WHEELHUBWF_R_MODEL_CAMERA); + //err = sql.lastError(); + //t = err.type(); + // if (t != QSqlError::NoError) + // { + // return false; + // } + return true; +} +void QSqliteWheelHubWf::FreeDatabase() +{ + +} + + + +QStringList QSqliteWheelHubWf::GetModelsByCamera(const QString& camKey) +{ + QStringList modelsList; + QSqlQuery sql = exec(QString("SELECT model_id, camera_id, camera_key FROM r_wh_model_camera WHERE camera_key = '%1'").arg(camKey)); + while (sql.next()) + { + QSqlRecord record = sql.record(); + modelsList.append(record.value("model_id").toString()); + } + return modelsList; +} + +QList QSqliteWheelHubWf::GetCamsOfModel(const QString& model) +{ + QList rmcList; + tagR_MODEL_CAMERA rmc; + bool bOk; + QSqlQuery sql = exec(QString("SELECT model_id, camera_id, camera_key FROM r_wh_model_camera WHERE model_id = '%1'").arg(model)); + while (sql.next()) + { + QSqlRecord record = sql.record(); + rmc.cameraId = record.value("camera_id").toInt(&bOk); + if (!bOk) + { + continue; + } + rmc.cameraKey = record.value("camera_key").toString(); + rmcList.append(rmc); + } + return rmcList; +} + +QStringList QSqliteWheelHubWf::getModelsByCamKey(const QString &camKey) +{ + QStringList modelsList; + + QString strClass = genClass(_WF_DB_MD_CAMKEY, camKey); + QString strSql = genSelect(_WF_DB_MD_TABLE_NAME, QStringList(_WF_DB_MD_MODEL), strClass); + QSqlQuery sql = exec(strSql); + + while (sql.next()) { + QSqlRecord record = sql.record(); + modelsList.append(record.value(_WF_DB_MD_MODEL).toString()); + } + return modelsList; +} + +// bool QSqliteWheelHubWf::addModel(const QString & strUnique, const QString & id, const QString &cam, const QString &model, QString &strTime) +// { +// if (cam.isEmpty() && model.isEmpty()) { +// return false; +// } +// +// QString strSql = QString(_WF_SQL_SELECT_MODEL).arg(strUnique); +// QSqlQuery sql = exec(strSql); +// if (sql.size() > 0) { +// return false; +// } +// strSql = QString(_WF_SQL_INSERT_MODEL).arg(strUnique, id, cam, model, strTime); +// exec(strSql); +// if (lastError().isValid()) +// { +// return false; +// } +// return true; +// } + + +bool QSqliteWheelHubWf::addModel(const QString & strUnique, QVariantMap &vMap) +{ + if (strUnique.isEmpty() || vMap.empty()) { + return false; + } + + QString strClass = genClass(_WF_DB_MD_PRIMARY_KEY, strUnique); + QString strSql = genSelect(_WF_DB_MD_TABLE_NAME, QStringList(), strClass); + + QSqlQuery sql = exec(strSql); + if (sql.size() > 0) { + return false; + } + + strSql = genInsertData(_WF_DB_MD_TABLE_NAME, _WF_DB_MD_PRIMARY_KEY, strUnique, vMap); + + exec(strSql); + if (lastError().isValid()) + { + return false; + } + return true; +} +bool QSqliteWheelHubWf::delModelByUnique(const QString &strUnique) +{ + //QString str = QString(_WF_SQL_DELETE_MODEL).arg(strUnique); + QString str = genDeleteData(_WF_DB_MD_TABLE_NAME, genClass(_WF_DB_MD_PRIMARY_KEY, strUnique));// QString(_WF_SQL_DELETE_MODEL).arg(strUnique); + + QSqlQuery sql = exec(str); + if (sql.size() == 0) { + return false; + } + + return true; +} + +bool QSqliteWheelHubWf::getModelInfoByUnique(const QString &strUnique, const QString & strContent, QVariant &result) +{ + //QString strSql = QString(_WF_SQL_SELECT_INFO_MODEL).arg(strContent).arg(strUnique); + QString strClass = genClass(_WF_DB_MD_PRIMARY_KEY, strUnique);// _WF_DB_PRIMARY_KEY + QString("=") + strUnique; + QString strSql = genSelect(_WF_DB_MD_TABLE_NAME, QStringList(strContent), strClass); + QSqlQuery sql = exec(strSql); + if (sql.size() == 0) { + return false; + } + + if (lastError().isValid()) { + return false; + } + while (sql.next()) + { + QSqlRecord records = sql.record(); + result = records.value(strContent); + return true; + } + + return false; +} + + +bool QSqliteWheelHubWf::setModelInfoByUnique(const QString &strUnique, const QString & strContent, QVariant v, int type) +{ + QMutexLocker locker(&m_mxLock); + QString strSql; + if (type == 0) { + QVariantMap vMap; + vMap.insert(strContent, v); + QString strClass = genClass(_WF_DB_MD_PRIMARY_KEY, strUnique); + strSql = genUpdate(_WF_DB_MD_TABLE_NAME, vMap, strClass); + } + + QSqlQuery sql = exec(strSql); + if (sql.size() == 0) { + return false; + } + + if (lastError().isValid()) { + return false; + } + + return true; +} + +bool QSqliteWheelHubWf::getRecordByUnique(const QString &strUnique, QSqlRecord &result) +{ + //QString strSql = QString(_WF_SQL_SELECT_MODEL).arg(strUnique); + QString strSql = genSelect(_WF_DB_MD_TABLE_NAME, QStringList(), genClass(_WF_DB_MD_PRIMARY_KEY, strUnique));// QString(_WF_SQL_SELECT_MODEL).arg(strUnique); + + QSqlQuery sql = exec(strSql); + if (sql.size() == 0) { + return false; + } + + if (lastError().isValid()) { + return false; + } + while (sql.next()) + { + QSqlRecord records = sql.record(); + result = records; + return true; + } + + return false; +} + +bool QSqliteWheelHubWf::addHeader(QString strColumnName, QString strColumnType) +{ + QString strSql = genSelect(_WF_DB_MD_TABLE_NAME);// QString("SELECT * FROM e_wh_models"); + QSqlQuery sql = exec(strSql); + if (sql.size() == 0) { + return false; + } + + if (lastError().isValid()) { + return false; + } + + while (sql.next()) { + QSqlRecord records = sql.record(); + int bExist = records.contains(strColumnName); + if (!bExist) { + //QString strSql = QString(_WF_SQL_ADD_HEADER).arg(strColumnName).arg(strColumnType); + QString strSql = genInsertColumn(_WF_DB_MD_TABLE_NAME, strColumnName, strColumnType); + QSqlQuery sql = exec(strSql); + + if (sql.size() == 0) { + return false; + } + + if (lastError().isValid()) { + return false; + } + } + return true; + } + + return true; +} + +bool QSqliteWheelHubWf::deleteHeader(QString strColumnName) +{ + QString strSql = genDeleteColumn(_WF_DB_MD_TABLE_NAME, strColumnName);// QString(_WF_SQL_DELETE_HEADER).arg(strColumnName); + QSqlQuery sql = exec(strSql); + + if (sql.size() == 0) { + return false; + } + + if (lastError().isValid()) { + return false; + } + return true; +} + +bool QSqliteWheelHubWf::increaseJob(QString strModel, QString strKey, QString strValue, QVariantMap &vMap) +{ + QString strTable = _WF_DB_MF_TABLE_PRIFIX + strModel; + { + QVariantMap vMapCreate; + QStringList strList = vMap.keys(); + for (int i = 0; i < strList.size(); i++) { + vMapCreate.insert(strList[i], "VARCHAR(20)"); + } + + QString strSql = genCreateTabel(strTable, _WF_DB_MF_PRIMARY_KEY, "VARCHAR(90) PRIMARY KEY", vMapCreate); + QSqlQuery sql = exec(strSql); + + QSqlError err = sql.lastError(); + int t = err.type(); + if (t != QSqlError::NoError) + { + return false; + } + } + + QString strInsert = genInsertData(strTable, strKey, strValue, vMap); + QSqlQuery sql = exec(strInsert); + + if (lastError().isValid()) { + return false; + } + return true; +} \ No newline at end of file diff --git a/src/lpMain/sqliteDB/QSqliteWheelHubWf.h b/src/lpMain/sqliteDB/QSqliteWheelHubWf.h new file mode 100644 index 0000000..6a7e64a --- /dev/null +++ b/src/lpMain/sqliteDB/QSqliteWheelHubWf.h @@ -0,0 +1,64 @@ +#ifndef QSQLITEWHEELHUBWF_H +#define QSQLITEWHEELHUBWF_H + +#include +#include +#include "QSqliteGeneral.h" +#include "qmutex" + +#define _WF_DB_MD_TABLE_NAME "e_wh_models" +#define _WF_DB_MD_PRIMARY_KEY "md_unique" +#define _WF_DB_MD_CAMKEY "md_camKey" +#define _WF_DB_MD_INDEX "md_index" +#define _WF_DB_MD_CALI "md_cali" +#define _WF_DB_MD_COUNT "md_count" +#define _WF_DB_MD_MODEL "md_model" +#define _WF_DB_MD_ID "md_id" +#define _WF_DB_MD_TEXT "md_text" +#define _WF_DB_MD_STAMP "md_stamp" + +#define _WF_DB_MF_TABLE_PRIFIX "e_wf_model_info" +#define _WF_DB_MF_PRIMARY_KEY "mf_time" +#define _WF_DB_MF_MODEL "mf_model" +#define _WF_DB_MF_UNIQUE "mf_unique" +#define _WF_DB_MF_ERROR_TYPE "mf_error" +#define _WF_DB_MF_ANGLE "md_angle" + +#define _WF_UNIQUE_SPLIT "_-_" +#define _WF_PRIMARY_SPLIT "__" + + + + +class QSqliteWheelHubWf : public QSqliteGeneral +{ +public: + struct tagR_MODEL_CAMERA{ + int cameraId; + QString cameraKey; + }; + QSqliteWheelHubWf(const QString& dbPath); + ~QSqliteWheelHubWf(); + + bool InitDatabase(); + void FreeDatabase(); + + QStringList GetModelsByCamera(const QString& camKey); + QList GetCamsOfModel(const QString& model); + + bool addModel(const QString & strUnique, const QString & id, + const QString &cam, const QString &model, QString &strTime); + bool addModel(const QString & strUnique, QVariantMap &vMap); + QStringList getModelsByCamKey(const QString &cam); + bool delModelByUnique(const QString &strUnique); + bool getModelInfoByUnique(const QString &strUnique, const QString & strContent, QVariant &result); + bool getRecordByUnique(const QString &strUnique, QSqlRecord &result); + bool setModelInfoByUnique(const QString &strUnique, const QString & strContent, QVariant result, int type = 0); + bool addHeader(QString strColumnName, QString strColumnType); + bool deleteHeader(QString strColumnName); + bool increaseJob(QString strModel, QString strKey, QString strValue, QVariantMap &vMap); +private: + QMutex m_mxLock; +}; + +#endif // QSQLITEWHEELHUBWF_H diff --git a/src/lpMain/sqliteDB/databasesql.cpp b/src/lpMain/sqliteDB/databasesql.cpp new file mode 100644 index 0000000..dd0f6a5 --- /dev/null +++ b/src/lpMain/sqliteDB/databasesql.cpp @@ -0,0 +1,165 @@ +#include "databasesql.h" +#include "gensql.h" +#define _MD_PRIMARY_KEY "uid" +#define _QMYSQL_ "QMYSQL" +#define _SQLITE_ "QSQLITE" + +DataBaseSql::DataBaseSql(const QString& dbName, const QString &dbType) +{ + m_DBType = dbType; + if (dbType == "QSQLITE") + { + db = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", dbName)); + db->setDatabaseName(dbName); + //qry = QSqlQuery::QSqlQuery(db); + } + else if (dbType == "QMYSQL") + { + //if (!QSqlDatabase::contains(m_DBType)) + db = new QSqlDatabase(QSqlDatabase::addDatabase("QMYSQL", dbName)); + //db.setDatabaseName(dbName); + } +} + +DataBaseSql::~DataBaseSql() +{ + if (db->isOpen()) + { + db->close(); + } + delete db; + db = NULL; +} + +bool DataBaseSql::openDB() +{ + return db->open(); +} + +void DataBaseSql::closeDB() +{ + db->close(); +} + +bool DataBaseSql::InitDatabase() +{ + if (!db->open() && db->open()) + { + return false; + } + + return true; +} + +bool DataBaseSql::CreatTable(QString m_tableName, QString m_primaty, QVariantMap m_map) +{ + QString strSql; + if (m_DBType == _SQLITE_) + strSql = gensql::genCreateTabel(m_tableName, m_primaty, "INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL", m_map); + else if (m_DBType == _QMYSQL_) + strSql = QString("CREATE TABLE `testtable2` (`id` int(11) NOT NULL,`name` varchar(60) DEFAULT NULL,`age` int(11) DEFAULT NULL,PRIMARY KEY(`id`)) ENGINE = InnoDB DEFAULT CHARSET = utf8; "); + QSqlQuery sql = db->exec(strSql); + + QSqlError err = sql.lastError(); + int nType = err.type(); + if (nType != QSqlError::NoError) + return false; + return true; +} + +bool DataBaseSql::InsertOneData(QString m_tableName, QVariantMap m_map) +{ + + if (m_tableName.isEmpty() || m_map.empty()) { + return false; + } + QString strSql; + strSql = gensql::genInsertData(m_tableName, m_map); + qry = db->exec(strSql); + QSqlError bflags = qry.lastError(); + int nType = bflags.type(); + QString str = db->databaseName(); + if (db->lastError().isValid()) + { + return false; + } + return true; +} + +bool DataBaseSql::ModefyOneData(QString m_tableName, QVariantMap m_map) +{ + if (m_tableName.isEmpty() || m_map.empty()) { + return false; + } + int max_id = 0; + QString select_max_sql = "select max(md_unique) from e_report_forms"; + QSqlQuery sql = db->exec(select_max_sql); + if (db->lastError().isValid()) + { + return false; + } + else + { + while (sql.next()) + { + max_id = sql.value(0).toInt(); + } + } + QString m = gensql::genClass(_MD_PRIMARY_KEY, "0"); + QString strSql = gensql::genUpdate(m_tableName, m_map, m); + + db->exec(strSql); + if (db->lastError().isValid()) + { + return false; + } + return true; +} + +bool DataBaseSql::DeleteOneData(QString m_tableName, QString m_map) +{ + if (m_tableName.isEmpty() || m_map.isEmpty()) { + return false; + } + int max_id = 0; + QString select_max_sql = "select max(" + QString(_MD_PRIMARY_KEY) + ") from " + m_tableName; + QSqlQuery sql = db->exec(select_max_sql); + if (db->lastError().isValid()) + { + return false; + } + else + { + while (sql.next()) + { + max_id = sql.value(0).toInt(); + } + } + QString m;// = genClass(_MD_PRIMARY_KEY, "0"); + QString strSql = gensql::genDeleteData(m_tableName, m); + + db->exec(strSql); + if (db->lastError().isValid()) + { + return false; + } + return true; +} + +void DataBaseSql::SetDatabaseName(QString dbName) +{ + db->setDatabaseName(dbName); +} + +void DataBaseSql::SetDBPort(QString nAddr /*= QString("localhost")*/, int nPort /*= 3306*/) +{ + db->setHostName(nAddr); + db->setPort(nPort); +} + +void DataBaseSql::SetDBUser(QString dbUser /*= QString("root")*/, QString dbPwd /*= QString("hzleaper")*/) +{ + db->setUserName(dbUser); + db->setPassword(dbPwd); +} + diff --git a/src/lpMain/sqliteDB/databasesql.h b/src/lpMain/sqliteDB/databasesql.h new file mode 100644 index 0000000..1d82024 --- /dev/null +++ b/src/lpMain/sqliteDB/databasesql.h @@ -0,0 +1,73 @@ +#ifndef DATABASESQL_H +#define DATABASESQL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "QMutex" + +#define _CHECK_TIME1_ "time1" +#define _CHECK_TIME2_ "time2" +#define _CHECK_NAME_ "name" +#define _CHECK_TYPE_ "Type" +#define _CHECK_COUNT_ "Count" +#define _CHECK_LOGTYPE "logType" +enum EMTYPE_CHECKTYPE{ + EMT_CHECK_BY_TIME = 0,//只按时间查询 + EMT_CHECK_BY_NAME,//按照模型名查询 + EMT_CHECK_BY_SAE,//按照起始结束时间查询 + EMT_CHECK_BY_LOG, + EMT_CHECK_BY_COUNT +}; +class DataBaseSql : public QObject +{ + Q_OBJECT + +public: + DataBaseSql( const QString& dbName ,const QString &dbType = QString("QSQLITE")); + ~DataBaseSql(); + bool openDB(); + void closeDB(); + void SetDatabaseName(QString dbName); + void SetDBPort(QString nAddr = QString("localhost"), int nPort = 3306); + void SetDBUser(QString dbUser = QString("root"), QString dbPwd = QString("hzleaper")); + virtual bool InitDatabase(); + bool CreatTable(QString m_tableName, QString m_primaty, QVariantMap m_map); + + virtual bool InsertOneData(QString m_tableName, QVariantMap m_map); + virtual bool ModefyOneData(QString m_tableName, QVariantMap m_map); + virtual bool DeleteOneData(QString m_tableName, QString m_map); + /* + m_value.insert("time1","");//起始时间 + m_value.insert("time2","");//结束时间 + m_value.insert("name","");//模型名字 + m_value.insert("Type","");//查询类型 + m_value.insert("logType","");//报警信息查询 + */ + virtual bool AddOneData(QVariantMap m_map, QString strTableName)=0; + virtual bool checkoutData(QVariantMap m_value, QSqlQuery &sql) = 0; + virtual bool checkoutData(QString selectStr, QSqlQuery &sql) = 0; + virtual bool AddOneWarningMessage(struct WarnMessage m_messageInfo) = 0; + virtual bool DelWarnDataByCount(int model = 1, int nCount = 100000) = 0; + virtual bool DelAllDatas() = 0; + virtual bool DelDatasByTime(QString minTime) = 0; + virtual QString genCheckStr(QVariantMap m_value);//通过value数据生成查询语句 实现与checkoutdata相同 +public: + +protected: + QSqlDatabase *db; + QSqlQuery qry; + QString m_DBType; + +}; + +#endif // DATABASESQL_H diff --git a/src/lpMain/sqliteDB/gensql.cpp b/src/lpMain/sqliteDB/gensql.cpp new file mode 100644 index 0000000..fe955ad --- /dev/null +++ b/src/lpMain/sqliteDB/gensql.cpp @@ -0,0 +1,116 @@ +#include "gensql.h" +#include +#include "QStringList" + +QString gensql::genInsertData(const QString & strTableName, const QVariantMap &vMap) +{ + QString strInsert = "INSERT INTO %1(%2) VALUES(%3)"; + QString strHeader;// + QString strValue;// + + QStringList strKeys = vMap.keys(); + for (int i = 0; i < strKeys.size(); i++) { + strHeader += strKeys[i]; + if (i + 1 < strKeys.size()) + strHeader += ","; + strValue += "'" + vMap[strKeys[i]].toString() + "'"; + if (i + 1 < strKeys.size()) + strValue += ","; + } + strInsert = strInsert.arg(strTableName, strHeader, strValue); + return strInsert; +} + +QString gensql::genSelect(const QString & strTableName, QStringList strSelectList, QString strClass) +{ + QString strDstSelect; + if (strClass.isEmpty()) { + strDstSelect = "SELECT %1 FROM %2"; + } + else { + strDstSelect = "SELECT %1 FROM %2 WHERE " + strClass; + } + + if (0 == strSelectList.size()) { + strDstSelect = strDstSelect.arg("*").arg(strTableName); + } + else { + QString strSeletTmp = strSelectList[0]; + for (int i = 1; i < strSelectList.size(); i++) { + strSeletTmp += "," + strSelectList[i]; + } + strDstSelect = strDstSelect.arg(strSeletTmp, strTableName); + } + + return strDstSelect; +} + +QString gensql::genClass(QString strName, QString strValue) +{ + QString strDst = ""; + strDst += strName + " = '" + strValue + "'"; + return strDst; +} + +QString gensql::genUpdate(const QString & strTableName, QVariantMap &vMap, QString strClass) +{ + QString strDst = "";// + if (strClass.isEmpty()) { + strDst = "UPDATE %1 SET %2";//全部修改 + } + else { + strDst = "UPDATE %1 SET %2 WHERE %3";//指定修改 + } + QString strUpdateTmp = ""; + if (vMap.size() != 0) { + QStringList strList = vMap.keys(); + strUpdateTmp += gensql::genClass(strList[0], vMap[strList[0]].toString()); + for (int i = 1; i < strList.size(); i++) { + strUpdateTmp += "," + gensql::genClass(strList[i], vMap[strList[i]].toString()); + } + } + + strDst = strDst.arg(strTableName, strUpdateTmp, strClass); + return strDst; +} + +QString gensql::genDeleteData(const QString & strTableName, QString strClass) +{ + QString strDst; + if (strClass.isEmpty()) { + strDst = "DELETE FROM %1";//全部删除 + } + else { + strDst = "DELETE FROM %1 WHERE %2";//指定删除 + } + + strDst = strDst.arg(strTableName, strClass); + return strDst; +} + +QString gensql::genInsertColumn(const QString & strTableName, QString strName, QString strType) +{ + QString strDst = "ALTER TABLE %1 ADD COLUMN %2 %3"; + strDst = strDst.arg(strTableName).arg(strName).arg(strType); + + return strDst; +} + +QString gensql::genDeleteColumn(const QString & strTableName, QString strColumnName) +{ + QString strDst = "ALTER TABLE %1 DROP %2"; + strDst = strDst.arg(strTableName, strColumnName); + return strDst; +} + +QString gensql::genCreateTabel(const QString strTable, QString strPrimary, QString strType, QVariantMap &vMap) +{ + QString strDst = "CREATE TABLE IF NOT EXISTS %1 (%2)"; + QString strColumn = strPrimary + " " + strType; + QStringList strList = vMap.keys(); + for (int i = 0; i < strList.size(); i++) { + strColumn += ", " + strList[i] + " " + vMap[strList[i]].toString(); + } + strDst = strDst.arg(strTable, strColumn); + return strDst; +} diff --git a/src/lpMain/sqliteDB/gensql.h b/src/lpMain/sqliteDB/gensql.h new file mode 100644 index 0000000..0a72be0 --- /dev/null +++ b/src/lpMain/sqliteDB/gensql.h @@ -0,0 +1,15 @@ +#ifndef _GENSQL_H_ +#define _GENSQL_H_ +#include "QMetaType" +#include "QString" +namespace gensql{ + QString genInsertData(const QString & strTableName, const QVariantMap &vMap); + QString genSelect(const QString & strTableName, QStringList strSelectList, QString strClass); + QString genClass(QString strName, QString strValue); + QString genUpdate(const QString & strTableName, QVariantMap &vMap, QString strClass); + QString genDeleteData(const QString & strTableName, QString strClass); + QString genInsertColumn(const QString & strTableName, QString strName, QString strType); + QString genDeleteColumn(const QString & strTableName, QString strColumnName); + QString genCreateTabel(const QString strTable, QString strPrimary, QString strType, QVariantMap &vMap); +} +#endif diff --git a/src/lpMain/sqliteDB/qcheckdatadlg.cpp b/src/lpMain/sqliteDB/qcheckdatadlg.cpp new file mode 100644 index 0000000..7ba34b9 --- /dev/null +++ b/src/lpMain/sqliteDB/qcheckdatadlg.cpp @@ -0,0 +1,372 @@ +#include "qcheckdatadlg.h" +#include "qstandarditemmodel.h" +#include "qmessagebox.h" +#include "qfontmetrics.h" +#pragma execution_character_set("utf-8") +QCheckDataDlg::QCheckDataDlg(QWidget *parent) + : QDialog(parent), m_db(NULL), nPrevNum(0), nTotlaNumber(0) +{ + ui.setupUi(this); + m_ViewImg = new QTpGraphView; + connect(ui.m_pbCheck, SIGNAL(clicked()), this, SLOT(onCheckOutData())); + connect(ui.Prev_checkShengchang, SIGNAL(clicked()), this, SLOT(onChenckButton())); + connect(ui.Next_checkShengchang, SIGNAL(clicked()), this, SLOT(onChenckButton())); + connect(ui.m_pbCount, SIGNAL(clicked()), this, SLOT(onChenckButton())); + setWindowIcon(QIcon(":/leaper/app.png")); + pShowName_label = ui.check_fileName; + pShowName_label->clear(); + + check_showImg_label = ui.check_showImg_label; + check_showImg_label->clear(); + QGridLayout *pGrid = new QGridLayout(this); + pGrid->addWidget(m_ViewImg); + check_showImg_label->setLayout(pGrid); + + m_tableModel = new QStandardItemModel; + tableView = ui.tableView; + connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTBUI_ItemClick(const QModelIndex &))); + tableView->setModel(m_tableModel); + textBrowser = ui.textBrowser; + + pStartTimeEdit = ui.dateTimeEdit_start; + pEndTimeEdit = ui.dateTimeEdit_end; + QDateTime nDateTime = QDateTime::currentDateTime(); + nDateTime.setTime(QTime(0, 0, 0)); + pStartTimeEdit->setDateTime(nDateTime); + pEndTimeEdit->setDateTime(QDateTime::currentDateTime()); + Qt::WindowFlags flags = Qt::Dialog; + flags |= Qt::WindowMinMaxButtonsHint; + flags |= Qt::WindowCloseButtonHint; + setWindowFlags(flags); + setPageShow(0, 0); +} + +QCheckDataDlg::~QCheckDataDlg() +{ + if (m_tableModel) + { + delete m_tableModel; + m_tableModel = NULL; + } + if (m_ViewImg){ + delete m_ViewImg; + m_ViewImg = NULL; + } +} + +void QCheckDataDlg::createHeader() +{ + QStringList listStr; + listStr.append(QObject::tr("时间")); + listStr.append(QObject::tr("型号")); + listStr.append(QObject::tr("matchScore")); + listStr.append(QObject::tr("BenchMark")); + listStr.append(QObject::tr("Angle")); + listStr.append(QObject::tr("errorType")); + listStr.append(QObject::tr("resultTip")); + listStr.append(QObject::tr("工位")); + m_tableModel->setHorizontalHeaderLabels(listStr); +} + +void QCheckDataDlg::updateModelShowLog(QSqlQuery &sql) +{ + m_tableModel->clear(); + m_strMap.clear(); + createHeader(); + tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); + tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);//自适应行宽 + int nIndex = 0; + while (sql.next()) + { + /*这里下面是统计查询到的通道对应的产品总数*/ + QString time = sql.value("time").toString(); + QString dAngle = sql.value("dAngle").toString(); + QString matchScore = sql.value("matchScore").toString().left(5); + QString errorType = sql.value("errorType").toString(); + QString resultTip = sql.value("resultTip").toString(); + QString threshBenchMark = sql.value("threshBenchMark").toString(); + QString stationName = sql.value("stationName").toString(); + QString strFilename = sql.value("value1").toString();//取出保存图片的路径名 + //QByteArray picByte = sql.value("image").toByteArray(); + QString strModelName = sql.value("value2").toString(); + //QImage img = QImage::fromData(picByte); + + m_tableModel->setItem(nIndex, 0, new QStandardItem(time)); + m_tableModel->setItem(nIndex, 1, new QStandardItem(strModelName)); + m_tableModel->setItem(nIndex, 2, new QStandardItem(matchScore)); + m_tableModel->setItem(nIndex, 3, new QStandardItem(threshBenchMark)); + m_tableModel->setItem(nIndex, 4, new QStandardItem(dAngle)); + m_tableModel->setItem(nIndex, 5, new QStandardItem(errorType)); + m_tableModel->setItem(nIndex, 6, new QStandardItem(resultTip)); + m_tableModel->setItem(nIndex, 7, new QStandardItem(stationName)); + m_strMap.insert(time, strFilename); + pShowName_label->setText(strFilename); + nIndex++; + } + + ui.showNum_Label_Checkdata->setText(QString(QObject::tr("共显示%1条记录")).arg(nIndex)); + tableView->setModel(m_tableModel); + + int page = nPrevNum / getLimitNumber(); + int totalPage = nTotlaNumber / getLimitNumber(); + setPageShow(page+1, totalPage+1); +} + +int QCheckDataDlg::getLimitNumber() +{ + int num = ui.LineNumber_checkShengchang->text().toInt(); + if (num > 1) + return num; + else + { + ui.LineNumber_checkShengchang->setText("50"); + return 50; + } + +} +int QCheckDataDlg::getTotalNumber() +{ + QString startTime = pStartTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz"); + QString endTime = pEndTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz"); + QString stationName = getStationName(); + int errorType = getErrorType(); + QString strSql = QString(); + if (stationName == QObject::tr("全部")&&errorType == 0) + strSql = QString("select count(uid) from RltTable where time >'%1' and time <'%2' ").arg(startTime).arg(endTime); + else if (stationName == QObject::tr("全部") && errorType == 1) + strSql = QString("select count(uid) from RltTable where time >'%1' and time <'%2' and errorType != '%3'").arg(startTime).arg(endTime).arg(0); + else if (stationName != QObject::tr("全部") && errorType == 1) + strSql = QString("select count(uid) from RltTable where time >'%1' and time <'%2' and errorType != '%3' and stationName == '%4' ").arg(startTime).arg(endTime).arg(0).arg(stationName); + else + strSql = QString("select count(uid) from RltTable where time >'%1' and time <'%2' and stationName == '%3'").arg(startTime).arg(endTime).arg(stationName); + + QSqlQuery sqlquery; + m_db->checkoutData(strSql, sqlquery); + int totalNumber =0; + while (sqlquery.next()) + { + QSqlRecord record = sqlquery.record(); + QString fieldName = record.fieldName(0); + QString num = sqlquery.value(0).toString(); + totalNumber = num.toInt(); + // /*这里下面是统计查询到的通道对应的产品总数*/ + } + return totalNumber; +} +Q_SLOT void QCheckDataDlg::onCheckOutData() +{ + nTotlaNumber = 0; + nPrevNum = 0; + int limitNum = getLimitNumber(); + nTotlaNumber = getTotalNumber(); + + onCheckOutData(limitNum, nPrevNum); +} + +void QCheckDataDlg::onCheckOutData(int nLimitNum, int nPrenum) +{ + QString startTime = pStartTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz"); + QString endTime = pEndTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz"); + QString stationName = getStationName(); + int errorType = getErrorType(); + QString strSql = QString(); + if (stationName == QObject::tr("全部")&&errorType == 0) + strSql=QString("select * from RltTable where time >'%1' and time <'%2' LIMIT %3 OFFSET %4 ").arg(startTime).arg(endTime).arg(nLimitNum).arg(nPrenum); + else if (stationName == QObject::tr("全部") && errorType == 1) + strSql = QString("select * from RltTable where time >'%1' and time <'%2' and errorType != '%3' LIMIT %4 OFFSET %5 ").arg(startTime).arg(endTime).arg(0).arg(nLimitNum).arg(nPrenum); + else if (stationName != QObject::tr("全部") && errorType == 1) + strSql = QString("select * from RltTable where time >'%1' and time <'%2' and errorType != '%3' and stationName == '%4' LIMIT %5 OFFSET %6 ").arg(startTime).arg(endTime).arg(0).arg(stationName).arg(nLimitNum).arg(nPrenum); + else + strSql = QString("select * from RltTable where time >'%1' and time <'%2' and stationName == '%3' LIMIT %4 OFFSET %5 ").arg(startTime).arg(endTime).arg(stationName).arg(nLimitNum).arg(nPrenum); + QSqlQuery sqlquery; + m_db->checkoutData(strSql, sqlquery); + updateModelShowLog(sqlquery); +} + +Q_SLOT void QCheckDataDlg::onChenckButton() +{ + QString strObjName = sender()->objectName(); + if (strObjName == "Next_checkShengchang") + { + if (nTotlaNumber <= 0) + return; + if (nPrevNum > nTotlaNumber) + return; + nPrevNum += getLimitNumber(); + if (nPrevNum > nTotlaNumber) + { + nPrevNum -= getLimitNumber(); + QMessageBox infobox(QMessageBox::Information, QObject::tr("提醒"), QObject::tr("已经是最后一页了"), QMessageBox::Ok, NULL); + infobox.setWindowIcon(QIcon(":/leaper/app.png")); + infobox.setButtonText(QMessageBox::Ok, QString(QObject::tr("确认"))); + infobox.exec(); + return; + } + onCheckOutData(getLimitNumber(), nPrevNum); + } + else if (strObjName == "Prev_checkShengchang") + { + if (nTotlaNumber <= 0) + return; + if (nPrevNum < 0) + return; + nPrevNum -= getLimitNumber(); + if (nPrevNum < 0) + { + nPrevNum = 0; + QMessageBox infobox(QMessageBox::Information, QObject::tr("提醒"), QObject::tr("已经是第一页了"), QMessageBox::Ok, NULL); + infobox.setWindowIcon(QIcon(":/leaper/app.png")); + infobox.setButtonText(QMessageBox::Ok, QString(QObject::tr("确认"))); + infobox.exec(); + return; + } + onCheckOutData(getLimitNumber(), nPrevNum); + } + else if (strObjName == "m_pbCount") + { + QString startTime = pStartTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz"); + QString endTime = pEndTimeEdit->dateTime().toString("yyyy-MM-dd hh:mm:ss zzz"); + QString stationName = getStationName(); + QString strSql = QString(); + if (stationName == QObject::tr("全部")) + strSql = QString("select errorType,count(uid) from RltTable where time >'%1' and time <'%2' group by errorType order by errorType").arg(startTime).arg(endTime); + else + strSql = QString("select errorType,count(uid) from RltTable where time >'%1' and time <'%2' and stationName == '%3' group by errorType order by errorType").arg(startTime).arg(endTime).arg(stationName); + + QSqlQuery sqlquery; + m_db->checkoutData(strSql, sqlquery); + QMap nCountMap; + + while (sqlquery.next()) + { + QSqlRecord record = sqlquery.record(); + QString fieldName = record.fieldName(0); + QString nType = sqlquery.value(0).toString(); + int count = sqlquery.value(1).toInt(); + nCountMap.insert(nType, count); + } + int TotalNumber = 0; + int ErrorNumber = 0; + textBrowser->clear(); + for (QMap::iterator its = nCountMap.begin(); its != nCountMap.end();++its) + { + QString strKey = its.key(); + int nValue = nCountMap.value(strKey); + QString str; + if (strKey != "0") + str = QString("errorType:%1 Sum:%2;").arg(strKey).arg(nValue); + else + str = QString("goodType Sum:%2;").arg(nValue); + TotalNumber += nValue; + if (strKey != "0") + { + ErrorNumber += nValue; + } + textBrowser->append(str); + } + QString strEnd = QString("ErrorNumber:%1\nTotalNumber:%2").arg(ErrorNumber).arg(TotalNumber); + textBrowser->append(strEnd); + } +} + +void QCheckDataDlg::setStationNames(QStringList listNames) +{ + ui.comboBox_station->addItems(listNames); +} + +QString QCheckDataDlg::getStationName() +{ + return ui.comboBox_station->currentText(); +} + +int QCheckDataDlg::getErrorType() +{ + QString str = ui.comboBox_errorType->currentText(); + if (str == QObject::tr("全部")) + return 0; + else + return 1; +} + +void QCheckDataDlg::setPageShow(int page,int totalPage) +{ + QString str = QString(QObject::tr("第%1页 共%2页")).arg(page).arg(totalPage); + ui.showPage_Label_Checkdata->setText(str); +} + +Q_SLOT void QCheckDataDlg::onTBUI_ItemClick(const QModelIndex & index) +{ + QModelIndex nindex = m_tableModel->index(index.row(), 0); + QString str = nindex.data().toString(); + if (m_strMap.size() > 0) + { + QString strFileName = m_strMap.value(str); + + if (check_showImg_label) + { + QPixmap npixmap; + QString appPath = QApplication::applicationDirPath(); + npixmap.load(appPath+strFileName); + m_ViewImg->setImg(npixmap); + if (!npixmap.isNull()){ + if (pShowName_label) + { + QFontMetrics fontMetrics(this->font()); + int fontSize = fontMetrics.width(strFileName); + QString str = strFileName; + if (fontSize > pShowName_label->width()) + { + str = fontMetrics.elidedText(strFileName, Qt::ElideRight, pShowName_label->width()); + } + pShowName_label->setText(str); + } + } + else{ + if (pShowName_label){ + pShowName_label->setText(QObject::tr("无图片(或图片已过期/已被删除)")); + } + } + } + } + + int i = 0; +} + +Q_SLOT void QCheckDataDlg::onSlowPixmap(QSqlQuery sql) +{ + static bool nFlag = false; + if (nFlag == true) + return; + nFlag = true; + + sql.next(); + double dHight = sql.value("hight").toDouble(); + QByteArray pic = sql.value("pic").toByteArray(); + QImage img = QImage::fromData(pic); + QSize s = img.size(); + QPixmap m_Pix = QPixmap::fromImage(img); + + { + int dhight = m_Pix.height(); + int dwidth = m_Pix.width(); + double nRate = m_Pix.width()*1.0 / m_Pix.height(); + int scarew = 150; + int scareh = 150 * 1.0 / nRate; + + if (scareh > 150) + { + scarew = 150; + scareh = 150 * 1.0 / nRate; + } + + if (check_showImg_label) + { + m_ViewImg->setImg(m_Pix); + } + } + //label_6->setPixmap(m_Pix.scaled(WHEEL_PIC_SIZE, WHEEL_PIC_SIZE)); + nFlag = false; +} + + diff --git a/src/lpMain/sqliteDB/qcheckdatadlg.h b/src/lpMain/sqliteDB/qcheckdatadlg.h new file mode 100644 index 0000000..9fdaf8a --- /dev/null +++ b/src/lpMain/sqliteDB/qcheckdatadlg.h @@ -0,0 +1,58 @@ +#ifndef QCHECKDATADLG_H +#define QCHECKDATADLG_H + +#include +#include "ui_qcheckdatadlg.h" +#include "stationdb.h" +#include "qsqlquery.h" +#include "qstandarditemmodel.h" +#include "qtableview.h" +#include "qdatetimeedit.h" +#include "QTextBrowser.h" +#include "cunstomgraphview.h" +class QCheckDataDlg : public QDialog +{ + Q_OBJECT + +public: + QCheckDataDlg(QWidget *parent = 0); + ~QCheckDataDlg(); + void setDbPtr(StationDB *pDb){ m_db = pDb; }; + void setStationNames(QStringList listNames); + +private: + Q_SLOT void onChenckButton(); + Q_SLOT void onCheckOutData(); + Q_SLOT void onTBUI_ItemClick(const QModelIndex & index); + Q_SLOT void onSlowPixmap(QSqlQuery sql); +private: + int getLimitNumber(); + int getTotalNumber(); + int getErrorType(); + + QString getStationName(); + + void createHeader(); + void updateModelShowLog(QSqlQuery &sql); + void onCheckOutData(int nLimitNum, int nPrenum); + void setPageShow(int page, int totalPage); +private: + Ui::QCheckDataDlg ui; + + QLabel *pShowName_label; + QLabel *check_showImg_label; + QTextBrowser *textBrowser; + StationDB *m_db; + QStandardItemModel *m_tableModel; + QTableView *tableView; + QDateTimeEdit *pStartTimeEdit; + QDateTimeEdit *pEndTimeEdit; + + QMap m_strMap; + int nPrevNum; + int nTotlaNumber; + + QTpGraphView *m_ViewImg; +}; + +#endif // QCHECKDATADLG_H diff --git a/src/lpMain/sqliteDB/qcheckdatadlg.ui b/src/lpMain/sqliteDB/qcheckdatadlg.ui new file mode 100644 index 0000000..35b6ac5 --- /dev/null +++ b/src/lpMain/sqliteDB/qcheckdatadlg.ui @@ -0,0 +1,386 @@ + + + QCheckDataDlg + + + + 0 + 0 + 902 + 598 + + + + 检测记录查询 + + + + + + Qt::Horizontal + + + + + 4 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 3 + 0 + + + + Qt::Vertical + + + true + + + 1 + + + true + + + + + 0 + 2 + + + + + + + + + + 查询操作 + + + + + + + 全部 + + + + + error + + + + + + + + 结束时间: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + 全部 + + + + + + + + 显示: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + 起始时间: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 工位: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + 查询 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 8 + + + + + + + + + + 显示数据数(条) + + + + + + + + 0 + 0 + + + + + 0 + 20 + + + + + 100 + 50 + + + + 50 + + + 4 + + + Qt::AlignCenter + + + + + + + 上一页 + + + + + + + TextLabel + + + + + + + 下一页 + + + + + + + Qt::Horizontal + + + + 151 + 20 + + + + + + + + TextLabel + + + + + + + + + + TextLabel + + + + + + + + + + + + + 6 + 0 + + + + + 250 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Qt::Vertical + + + + + 0 + 3 + + + + 统计 + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + 统计当前设置的查询时间记录总数 + + + 统计 + + + + + + + + + 0 + 6 + + + + + 300 + 300 + + + + + + + + + + + + + + + + + + diff --git a/src/lpMain/sqliteDB/stationdb.cpp b/src/lpMain/sqliteDB/stationdb.cpp new file mode 100644 index 0000000..9fea651 --- /dev/null +++ b/src/lpMain/sqliteDB/stationdb.cpp @@ -0,0 +1,94 @@ +#include "stationdb.h" +#define _TABLENAME_ "RltTable" +#define _PERITY_KEY_ "uid" +#define _ST_ANGLE_ "dAngle" +#define _ST_SCORE_ "matchScore" +#define _ST_ERRORTYPE_ "errorType" +#define _ST_RESULT_TIP_ "resultTip" +#define _ST_THREDBENCHMARK_ "threshBenchMark" +#define _ST_STATIONNAME_ "stationName" +#define _ST_VALUE1_ "value1" +#define _ST_VALUE2_ "value2" +#define _ST_VALUE3_ "value3" +#define _ST_TIME_ "time" +#define _ST_PIC_ "image" +#define _ST_NAME_ "modelName" +StationDB::StationDB(const QString& dbName, const QString &dbType /*= QString("QSQLITE")*/):DetectDataDB(dbName,dbType) +{ + +} + +StationDB::~StationDB() +{ + +} + +bool StationDB::InitDatabase() +{ + if (!openDB()) + { + return false; + } + QStringList strList = GetAllTableNamesByDB(); + if (!strList.contains(_TABLENAME_)) + { + QVariantMap vDataMap; + vDataMap.insert(_ST_ANGLE_, "INT(100)"); + vDataMap.insert(_ST_SCORE_, "INT(100)"); + vDataMap.insert(_ST_ERRORTYPE_, "INT(100)");//ƶ + vDataMap.insert(_ST_RESULT_TIP_, "VARCHAR(32)"); + vDataMap.insert(_ST_THREDBENCHMARK_, "VARCHAR(32)"); + vDataMap.insert(_ST_STATIONNAME_, "VARCHAR(32)"); + vDataMap.insert(_ST_VALUE1_, "VARCHAR(32)"); + vDataMap.insert(_ST_VALUE2_, "VARCHAR(32)"); + vDataMap.insert(_ST_VALUE3_, "VARCHAR(32)"); + vDataMap.insert(_ST_TIME_, "DATETIME(32)"); + //vDataMap.insert(_ST_PIC_, "BLOB"); + if (!CreatTable(_TABLENAME_, _PERITY_KEY_, vDataMap)) + { + //return false; + } + else + { + QString strIndex = QString("CREATE INDEX %1 ON %2 (time COLLATE BINARY ASC); ").arg(QString("idx_%1").arg(_TABLENAME_)).arg(_TABLENAME_); + db->exec(strIndex);// + } + } + return true; +} + + +QStringList StationDB::GetAllTableNamesByDB() +{ + QString strCheckTable = QString("select name from sqlite_master where type='table' order by name;"); + QSqlQuery sql = db->exec(strCheckTable);//ѯݿеݱ + QStringList tablenamelist; + while (sql.next()) + { + QString strname = sql.value(0).toString(); + tablenamelist.append(strname); + } + return tablenamelist; +} + +void StationDB::addData2DB(Struct2SaveData &data) +{ + QVariantMap m_map; + m_map.insert(_ST_ANGLE_, data.dAngle); + m_map.insert(_ST_SCORE_, data.matchScore); + m_map.insert(_ST_ERRORTYPE_, data.errorType); + m_map.insert(_ST_RESULT_TIP_, data.resultTip); + m_map.insert(_ST_THREDBENCHMARK_, data.threshBenchMark); + m_map.insert(_ST_STATIONNAME_, data.stationName); + m_map.insert(_ST_VALUE1_, data.value1); + m_map.insert(_ST_VALUE2_, data.value2); + m_map.insert(_ST_VALUE3_, data.value3); + m_map.insert(_ST_TIME_, QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss zzz")); + //QByteArray ad; + //QBuffer buffer(&ad); + //data.m_pixRlt.save(&buffer, "jpg", 20); + //m_map.insert(_ST_PIC_, ad); + AddOneData(m_map, _TABLENAME_); + +} + diff --git a/src/lpMain/sqliteDB/stationdb.h b/src/lpMain/sqliteDB/stationdb.h new file mode 100644 index 0000000..05b5cb1 --- /dev/null +++ b/src/lpMain/sqliteDB/stationdb.h @@ -0,0 +1,35 @@ +#ifndef STATIONDB_H +#define STATIONDB_H + +#include +#include "DetectDataDB.h" +#include "QPixmap" +struct Struct2SaveData +{ + double dAngle; + int errorType; + double matchScore; + QString resultTip; + QString threshBenchMark; + QString stationName; + QString value1; + QString value2; + QString value3; + QPixmap m_pixRlt; +}; + +class StationDB : public DetectDataDB +{ + Q_OBJECT + +public: + StationDB(const QString& dbName, const QString &dbType = QString("QSQLITE")); + ~StationDB(); + virtual bool InitDatabase(); + QStringList GetAllTableNamesByDB(); + void addData2DB(Struct2SaveData &data); +private: + +}; + +#endif // STATIONDB_H diff --git a/tpvs17/Enchanter/Enchanter.qrc b/tpvs17/Enchanter/Enchanter.qrc new file mode 100644 index 0000000..7c87735 --- /dev/null +++ b/tpvs17/Enchanter/Enchanter.qrc @@ -0,0 +1,4 @@ + + + + diff --git a/tpvs17/Enchanter/Enchanter.vcxproj b/tpvs17/Enchanter/Enchanter.vcxproj new file mode 100644 index 0000000..b1efa29 --- /dev/null +++ b/tpvs17/Enchanter/Enchanter.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {7B76D75A-0E01-451E-880E-FB9AC63A914B} + Qt4VSv1.0 + 10.0.17763.0 + + + + Application + v141 + + + Application + v141 + + + + $(MSBuildProjectDirectory)\QtMsBuild + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(ProjectName)d + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + + + + + + + + + + + + + + + + true + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;%(AdditionalIncludeDirectories) + Disabled + ProgramDatabase + MultiThreadedDebugDLL + true + + + Windows + $(SolutionDir)..\runner17\$(TargetName)$(TargetExt) + $(QTDIR)\lib;%(AdditionalLibraryDirectories) + true + qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;%(AdditionalDependencies) + + + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + Moc'ing %(Identity)... + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;%(AdditionalIncludeDirectories) + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions) + + + Uic'ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h + + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + + + + + true + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;%(AdditionalIncludeDirectories) + + MultiThreadedDLL + true + + + Windows + $(OutDir)\$(ProjectName).exe + $(QTDIR)\lib;%(AdditionalLibraryDirectories) + false + qtmain.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;%(AdditionalDependencies) + + + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + Moc'ing %(Identity)... + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;%(AdditionalIncludeDirectories) + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions) + + + Uic'ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h + + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + + + + + + + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tpvs17/Enchanter/Enchanter.vcxproj.filters b/tpvs17/Enchanter/Enchanter.vcxproj.filters new file mode 100644 index 0000000..0a7e78a --- /dev/null +++ b/tpvs17/Enchanter/Enchanter.vcxproj.filters @@ -0,0 +1,47 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} + qrc;* + false + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + + + {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} + qrc;* + false + + + {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} + moc;h;cpp + False + + + + + Source Files + + + + + Header Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/tpvs17/Enchanter/Enchanter.vcxproj.user b/tpvs17/Enchanter/Enchanter.vcxproj.user new file mode 100644 index 0000000..1cea243 --- /dev/null +++ b/tpvs17/Enchanter/Enchanter.vcxproj.user @@ -0,0 +1,15 @@ + + + + + D:\Qt\Qt5.9.4\5.9.4\msvc2017_64 + $(SolutionDir)..\runner17\$(TargetName)$(TargetExt) + $(SolutionDir)..\runner17\ + WindowsLocalDebugger + PATH=$(QTDIR)\bin%3b$(PATH) + + + D:\Qt\Qt5.9.4\5.9.4\msvc2017_64 + PATH=$(QTDIR)\bin%3b$(PATH) + + \ No newline at end of file diff --git a/tpvs17/Enchanter/IMainWidget.h b/tpvs17/Enchanter/IMainWidget.h new file mode 100644 index 0000000..f68415a --- /dev/null +++ b/tpvs17/Enchanter/IMainWidget.h @@ -0,0 +1,20 @@ +#ifndef _H_IMAINWIDGET_H_ +#define _H_IMAINWIDGET_H_ + +#include +#include +class IMainWidget : public QObject +{ + Q_OBJECT + +public: + IMainWidget(QObject *parent = nullptr) {}; + ~IMainWidget() {}; + virtual QWidget* getMainWidget() = 0; +}; + +#define IMAINWIDGET_API extern "C" __declspec(dllexport) +IMAINWIDGET_API IMainWidget* MainWidget_Create(); +IMAINWIDGET_API void MainWidget_Delete(IMainWidget* pwd); +typedef IMainWidget* (*_MainWidget_Create)(); +#endif diff --git a/tpvs17/Enchanter/main.cpp b/tpvs17/Enchanter/main.cpp new file mode 100644 index 0000000..847ad79 --- /dev/null +++ b/tpvs17/Enchanter/main.cpp @@ -0,0 +1,35 @@ +#include +#include +#include "IMainWidget.h" +#include + +#pragma execution_character_set("utf-8") +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication a(argc, argv); + IMainWidget* pMain = nullptr; + QWidget* pMainWid = nullptr; +#ifdef _DEBUG + QLibrary lib("lpMaind"); +#else + QLibrary lib("lpMain"); +#endif + _MainWidget_Create func = (_MainWidget_Create)lib.resolve("MainWidget_Create"); + if (func) + { + pMain = func(); + if (pMain) { + pMainWid = pMain->getMainWidget(); + } + } + if (pMainWid) + { + pMainWid->show(); + a.exec(); + } + else { + QMessageBox::information(0, "", QObject::tr("lpMainʧ")); + } + return 0; +} diff --git a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj new file mode 100644 index 0000000..a95df4b --- /dev/null +++ b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj @@ -0,0 +1,141 @@ + + + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {784071A9-BF94-4D27-B62E-588ACD7E0633} + Qt4VSv1.0 + 10.0.16299.0 + + + + DynamicLibrary + v141 + + + DynamicLibrary + v141 + + + + + + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(ProjectName)d + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + UNICODE;_UNICODE;WIN32;WIN64;QT_CORE_LIB;QT_GUI_LIB;QT_NETWORK_LIB;QT_SERIALPORT_LIB;QT_SQL_LIB;TPCORECTRL_LIB;TPCORECTRL_EXPORTS;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;..\..\src\lpCoreCtrl;..\..\src\lpCoreCtrl\tpCamera;..\..\src\lpCoreCtrl\tpImgProc;..\..\3part\libzkq\include;..\..\..\lpOpenssl\openssl-1.0.2n\vs13\include;..\..\src\lpBase;%(AdditionalIncludeDirectories) + Disabled + ProgramDatabase + MultiThreadedDebugDLL + true + + + Windows + $(SolutionDir)..\runner17\$(TargetName)$(TargetExt) + $(QTDIR)\lib;$(OutDir);..\..\..\lpOpenssl\openssl-1.0.2n\vs13\lib\x64;%(AdditionalLibraryDirectories) + true + qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Networkd.lib;Qt5SerialPortd.lib;Qt5Sqld.lib;tpBased.lib;libzkqd.lib;libeay32.lib;%(AdditionalDependencies) + + + + + UNICODE;_UNICODE;WIN32;WIN64;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_NETWORK_LIB;QT_SERIALPORT_LIB;QT_SQL_LIB;TPCORECTRL_LIB;TPCORECTRL_EXPORTS;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtNetwork;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;..\..\include;..\..\src\tpBase;..\..\src\tpCoreCtrl;..\..\src\tpCamera;..\..\src\tpCommunicate;..\..\src\tpImgProc;..\..\3dpart\modbus\include;..\..\..\spider\libZK;..\..\src\crypto;..\..\..\lpOpenssl\openssl-1.0.2n\vs13\include;%(AdditionalIncludeDirectories) + ProgramDatabase + MultiThreadedDLL + true + + + Windows + $(SolutionDir)..\runner17\$(TargetName)$(TargetExt) + $(QTDIR)\lib;$(OutDir);..\..\..\lpOpenssl\openssl-1.0.2n\vs13\lib\x64;%(AdditionalLibraryDirectories) + true + qtmain.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Network.lib;Qt5SerialPort.lib;Qt5Sql.lib;tpBase.lib;libzkq.lib;libeay32.lib;%(AdditionalDependencies) + + + + + + + + + + + \ No newline at end of file diff --git a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters new file mode 100644 index 0000000..43f9326 --- /dev/null +++ b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.filters @@ -0,0 +1,212 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} + qrc;* + false + + + {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} + qrc;* + false + + + {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} + moc;h;cpp + False + + + {98ba8cd6-7087-4a49-9a18-5b750011123a} + + + {17f92375-9526-49f4-8a95-2b5adfa2fb7e} + + + {2edd888e-9c88-49cf-a98d-e23d4409689d} + + + + + tpImgProc + + + tpImgProc + + + tpImgProc + + + tpImgProc + + + tpImgProc + + + tpImgProc + + + tpImgProc + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCamera + + + tpCamera + + + tpCamera + + + tpCamera + + + tpCamera + + + + + tpImgProc + + + tpImgProc + + + tpImgProc + + + tpImgProc + + + tpImgProc + + + tpImgProc + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCoreCtrl + + + tpCamera + + + tpCamera + + + tpCamera + + + tpCamera + + + \ No newline at end of file diff --git a/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.user b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.user new file mode 100644 index 0000000..4195e6b --- /dev/null +++ b/tpvs17/lpCoreCtrl/lpCoreCtrl.vcxproj.user @@ -0,0 +1,12 @@ + + + + + D:\Qt\Qt5.9.4\5.9.4\msvc2017_64 + PATH=$(QTDIR)\bin%3b$(PATH) + + + D:\Qt\Qt5.9.4\5.9.4\msvc2017_64 + PATH=$(QTDIR)\bin%3b$(PATH) + + \ No newline at end of file diff --git a/tpvs17/lpMain/CMainWin.cpp b/tpvs17/lpMain/CMainWin.cpp new file mode 100644 index 0000000..6321043 --- /dev/null +++ b/tpvs17/lpMain/CMainWin.cpp @@ -0,0 +1,951 @@ +#include "CMainWin.h" +#include +#include "lpSysLog.h" +#include "IStation.h" +#include +#include +#include "WfCtrl.h" +#include +#include "quserinfo_global.h" +#include "Serialport_global.h" +#include "qcheckdatadlg.h" +#include "QAboutUI.h" + +#define LEAPER_LOGO ":/leaper/app.png" +#define DELETE_POINTER(p) if (p) {delete p; p = NULL;} +#pragma execution_character_set("utf-8") +CMainWin::CMainWin(QWidget *parent) + : QMainWindow(parent) +{ + setWindowIcon(QIcon(":/leaper/Resource/app.png")); + onInitCoreCtrl(); + + ui.setupUi(this); + lpSysLog::instance()->Init(); + readConfig(); + SetLanguage(m_strCurLanguage); + + { + QString strPath = QCoreApplication::applicationDirPath(); + QString DBFilePath = strPath + "\\DBFiles"; + QDir dbDir; + dbDir.mkpath(DBFilePath); + m_db = new StationDB(DBFilePath + "\\AntMan.db"); + m_db->InitDatabase(); + QSettings setting(strPath + "\\user\\systemfile.ini", QSettings::IniFormat); + connect(this, SIGNAL(sgShowLog(int, QString)), this, SLOT(onShowLog(int, QString))); + SYSLOG_STATUS << "ϵͳ"; + } + + m_pCameraTrig = new AutoTrigger; + connect(m_pCameraTrig, SIGNAL(sgTrig()), this, SLOT(onTrigImage())); + onInitStatus(); + + if (!m_DesignerMgr.Initialize(m_pDetectorEngine)) { + qWarning() << "Initialize is false"; + + } + connect(&m_DesignerMgr, SIGNAL(sgCloseWindow()), this, SLOT(onMainFrameClose())); + connect(&m_testWid, SIGNAL(sgTestMode(int)), this, SLOT(onTestMode(int))); + + m_pColossus = new WfColossus(m_pDetectorEngine); + m_pWfCtrl = new CWfCtrl(m_pCoreCtrl, m_pColossus); + + connect(m_pColossus, SIGNAL(sgSetModel(int, QString)), this, SLOT(onShowName(int, QString))); + m_mangeWid.onInitModelList(m_pWfCtrl); + + {//ûģ +#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))); + } + } + + {//豸 +#ifdef _DEBUG + QLibrary lib("SerialPortToold");//ļ +#else + QLibrary lib("SerialPortTool");//ļ +#endif + _SerialPortCreate func = (_SerialPortCreate)lib.resolve("SerialPortCreate"); + if (func) + m_pSerialPort = func(); + + //load seriport dll + if (m_pSerialPort)//ļ ʹԶĴ + { + m_pSerialPort->loadAnalysefunc(this, &CMainWin::onAppanalysis); + + //رտܵĴʹ + QString strDefaultPort = "COM6"; + + bool bOpen = m_pSerialPort->OpenCom(strDefaultPort, QString::number(115200)); + if (bOpen == false) + { + QMessageBox infobox(QMessageBox::Information, QString(QObject::tr("ʾ")), QString("error %1 %2 ").arg(strDefaultPort).arg(115200), QMessageBox::Yes | QMessageBox::No, NULL); + infobox.setWindowIcon(QIcon(":/image/leaper")); + infobox.exec(); + } + connect(&m_HeartBit, SIGNAL(timeout()), this, SLOT(onHeardBit())); + m_HeartBit.start(300); + } + } + + connect(ui.actionSetting, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.actionManage, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.actionTest, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.actionHelp, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.action_Check, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.action, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.main_Login_action, SIGNAL(triggered()), this, SLOT(onActionClicked())); + connect(ui.main_action_userManager, SIGNAL(triggered()), this, SLOT(onActionClicked())); + + connect(this, SIGNAL(sgShowImg(int, QImage)), this, SLOT(onShowImage(int, QImage))); + connect(this, SIGNAL(sgSelModel(int, QString)), this, SLOT(onSelModel(int, QString))); + m_TimerID_Status = startTimer(1000); + + ui.main_action_userManager->setVisible(false); + ui.action->setVisible(false); + + QTextDocument *pDoc = ui.wf_text_edit_result_1->document(); + pDoc->setMaximumBlockCount(200); + pDoc = ui.wf_text_edit_result_2->document(); + pDoc->setMaximumBlockCount(200); +} + +CMainWin::~CMainWin() +{ + if (m_pStatus) { + DELETE_POINTER(m_pStatusTrig); + DELETE_POINTER(m_pStatus); + } + DELETE_POINTER(m_pVersion); + DELETE_POINTER(m_pCameraTrig); + DELETE_POINTER(m_pWfCtrl); + DELETE_POINTER(m_pColossus); + if (m_db) + { + delete m_db; + m_db = NULL; + } + if (m_pUserCtrl) { + delete m_pUserCtrl; + m_pUserCtrl = NULL; + } + if (m_pSerialPort) { + m_HeartBit.stop(); + m_pSerialPort->CloseCom(); + delete m_pSerialPort; + m_pSerialPort = NULL; + } + rmTranslator(); + lpSysLog::uninstance(); +} + +void CMainWin::IVariantMapToUI(emTpUiDataType dataType, const QString& camKey, const QVariantMap& vMap) +{ + qDebug() << "variant 2 ui, start"; + if (!m_pWfCtrl) { + qWarning() << "VariantMapToUI, WFctrl is null"; + return; + } + QVariantMap mMap = vMap.value("algoRlt").toMap(); + IStation *pStation = m_pWfCtrl->IGetStationByKey(camKey); + if (pStation) { + QImage image = vMap.value("image").value(); + int nSize = image.height(); + if (!vMap.contains("angle")) { + qWarning() << "no angle result"; + } + double dAngle = vMap.contains("angle") ? vMap.value("angle").toDouble() : 365; + int errorType = vMap.contains("error") ? vMap.value("error").toInt() : 16; + double matchScore = vMap.value("score").toDouble() * 100; + + QString str = vMap.value("resultTip").toString(); + QStringList strList = str.split("/"); + QString strRusltTip = strList.first(); + QString threshBenchMark = strList.last(); + //QString strImgPath = vMap.value("imageName").toString(); + + QString strResult = QTime::currentTime().toString("hh:mm:ss zzz:") + strList.first(); + strResult += "angle result : " + QString::number(dAngle, 'f', 3); + pStation->setSerialPortPtr(m_pSerialPort); + if (dAngle >= 361) + dAngle = 361.0; + pStation->sendResult(dAngle); + if (image.isNull()) + int b = 0; + SYSLOG_STATUS << QString("λ%1յ㷨,ǰͺΪ[%2],ͽǶΪ:%3").arg(pStation->stationId()).arg(pStation->currentRunningModel()).arg(dAngle); + emit sgShowImg(pStation->stationId(),image); + emit sgShowLog(pStation->stationId(), strResult); + //emit pStation->sgPrint2Window(strResult); + pStation->revResult(); + + QString str2 = pStation->currentRunningModel(); + int ID = pStation->stationId(); + QString strModelName = QString("%1_%2").arg(ID).arg(str2); + QString strImgPath;// = genSavePath(strModelName, image); + Struct2SaveData nStructData; + nStructData.dAngle = dAngle; + nStructData.errorType = errorType; + nStructData.matchScore = matchScore; + nStructData.threshBenchMark = threshBenchMark; + nStructData.resultTip = strRusltTip; + nStructData.stationName = pStation->stationShowName(); + nStructData.value1 = strImgPath; + nStructData.value2 = str2; + qWarning() << "Add Result to DB,cam=" << camKey; + m_db->addData2DB(nStructData); + } + else { + qWarning() << "can not find station key=" << camKey; + qWarning() << "framework, camera kyes:" << m_pCoreCtrl->ICameraKeys(); + qWarning() << "wf ctrl, camera kyes:" << m_pWfCtrl->IGetStationKeys(); + } + qDebug() << "variant 2 ui, end"; +} + +QVariant CMainWin::IGetVariantById(int id) +{ + IStation *pStation = m_pWfCtrl->IGetStationById(id); + if (pStation) { + return pStation->getVariant(); + } + return QVariant(); +} + +QString CMainWin::genSavePath(QString modelName, QImage &img) +{ + QString strApp = QApplication::applicationDirPath(); + QString targetPath = "/DBFiles/Images"; + QString strData = QDateTime::currentDateTime().toString("yyyyMMdd"); + QString strFileName = QDateTime::currentDateTime().toString("yyyy_MM_dd_hhmmsszzz") + ".jpg"; + targetPath = targetPath + "/" + strData + "/" + modelName; + QDir dir; + dir.mkpath(strApp + targetPath); + targetPath = targetPath + "/" + strFileName; + + if (!img.isNull()) { + QString strImg = strApp + targetPath; + img.save(strImg, "jpg", 5); + } + return targetPath; +} + +Q_SLOT void CMainWin::onAppanalysis(SComFrame frame) +{ + //ݽ + int nCmd = frame.cmd; + if (0x43 == nCmd) + { + onHeartComm(frame); + return; + } + else if (0x50 == nCmd) { + int nCameraID = -1; + if (5 == frame.data1) { + nCameraID = 1; + } + else if (6 == frame.data1) { + nCameraID = 2; + } + + if (!m_pWfCtrl) { + qDebug() << "CommAchieved m_pWfCtrl is null"; + return; + } + IStation *pStation = m_pWfCtrl->IGetStationById(nCameraID); + if (!pStation) { + return; + } + if (m_pWfCtrl->IOnlineMode() == true) + { + if (nCameraID == 1) + { + if (m_StationInfo_1.m_bRunEnable == true) + { + pStation->trigImage(); + } + else { + QString strMsg = QString("%1:ͺID:%2ģͿвڣգ").arg(QTime::currentTime().toString("hh:mm:ss zzz:")).arg(m_StationInfo_1.m_PLCID); + emit sgShowLog(1, strMsg); + if (m_StationInfo_1.m_PLCID > 0) { + pStation->setSerialPortPtr(m_pSerialPort); + pStation->sendResult(999); + SYSLOG_STATUS << QString("λ%1:յź,Ϸû,999Ƕ,ͺΪ[%2],ͺIDΪ[%3],ʱ:%4") + .arg(nCameraID) + .arg(m_StationInfo_1.strModelName.isEmpty() == true ? "" : m_StationInfo_1.strModelName) + .arg(m_StationInfo_1.m_PLCID) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + } + else { + SYSLOG_STATUS << QString("λ%1:յź,Ϸû,ͺΪ[%2],ͺIDΪ[%3],ʱ:%4") + .arg(nCameraID) + .arg(m_StationInfo_1.strModelName.isEmpty() == true ? "" : m_StationInfo_1.strModelName) + .arg(m_StationInfo_1.m_PLCID) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + } + } + } + else if (nCameraID == 2) + { + if (m_StationInfo_2.m_bRunEnable == true) + { + pStation->trigImage(); + } + else + { + QString strMsg = QString("%1:ͺID:%2ģͿвڣգ").arg(QTime::currentTime().toString("hh:mm:ss zzz:")).arg(m_StationInfo_2.m_PLCID); + emit sgShowLog(2, strMsg); + if (m_StationInfo_2.m_PLCID > 0) { + pStation->setSerialPortPtr(m_pSerialPort); + pStation->sendResult(999); + SYSLOG_STATUS << QString("λ%1:յź,Ϸû,999Ƕ,ͺΪ[%2],ͺIDΪ[%3],ʱ:%4") + .arg(nCameraID) + .arg(m_StationInfo_2.strModelName.isEmpty() == true ? "" : m_StationInfo_2.strModelName) + .arg(m_StationInfo_2.m_PLCID) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + + } + else { + SYSLOG_STATUS << QString("λ%1:յź,Ϸû,ͺΪ[%2],ͺIDΪ[%3],ʱ:%4") + .arg(nCameraID) + .arg(m_StationInfo_2.strModelName.isEmpty() == true ? "" : m_StationInfo_2.strModelName) + .arg(m_StationInfo_2.m_PLCID) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + } + } + } + } + else + pStation->trigImage(); + } + else if (0xf1 == nCmd) + {//յλرд ػ + qApp->closeAllWindows(); + //shutDown(); + } +} + +void CMainWin::onHeartComm(SComFrame &frame) +{ + static int nS1 = -1; + static int nS2 = -1; + + if (m_pWfCtrl) + m_pWfCtrl->registerConnect(); + else + return; + + if (m_pWfCtrl->IOnlineMode() == true) + { + int nSta1 = frame.data1; + int nSta2 = frame.data2; + if (nS1 != nSta1 || nS2 != nSta2) + { + nS1 = nSta1; + nS2 = nSta2; + } + else + return; + + QStringList lstKeys = m_pWfCtrl->IGetStationKeys(); + for each (QString var in lstKeys) + { + IStation *pStation = m_pWfCtrl->IGetStationByKey(var); + if (!pStation) { + continue; + } + int nId = pStation->stationId(); + if (nId <= 0 || nId > 8) { + //error + qWarning() << "error, id is beyong"; + continue; + } + + int mmCmd = 0; + if (nId == 1) + mmCmd = frame.data1; + if (nId == 2) + mmCmd = frame.data2; + if (nId == 3) + mmCmd = frame.data3; + if (nId == 4) + mmCmd = frame.data4; + if (nId == 5) + mmCmd = frame.data5; + if (nId == 6) + mmCmd = frame.data6; + if (nId == 7) + mmCmd = frame.data7; + if (nId == 8) + mmCmd = frame.data8; + QString strModel = pStation->modelByPlcCmd(mmCmd); + if (!strModel.isEmpty()) + { + emit(sgSelModel(nId, strModel)); + if (nId == 1) + { + if (m_StationInfo_1.m_PLCID != mmCmd) + { + m_StationInfo_1.m_PLCID = mmCmd; + m_StationInfo_1.strModelName = strModel; + SYSLOG_STATUS << QString("﹤λ%1:лͺΪ[%2],ͺIDΪ[%3],ʱ:%4") + .arg(nId) + .arg(strModel) + .arg(mmCmd) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + } + m_StationInfo_1.m_bRunEnable = true; + } + else if (nId == 2) + { + if (m_StationInfo_2.m_PLCID != mmCmd) { + m_StationInfo_2.m_PLCID = mmCmd; + m_StationInfo_2.strModelName = strModel; + SYSLOG_STATUS << QString("﹤λ%1:лͺΪ[%2],ͺIDΪ[%3],ʱ:%4") + .arg(nId) + .arg(strModel) + .arg(mmCmd) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + } + m_StationInfo_2.m_bRunEnable = true; + } + } + else { + if (nId == 1) + { + if (m_StationInfo_1.m_PLCID != mmCmd) { + m_StationInfo_1.m_PLCID = mmCmd; + m_StationInfo_1.strModelName = strModel; + if (mmCmd <= 0) + SYSLOG_STATUS << QString("﹤λ%1:ͺ,ͺIDΪ[%2],ʱ:%3") + .arg(nId) + .arg(mmCmd) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + else + SYSLOG_STATUS << QString("﹤λ%1:ͺлʧ,Ӧ,ͺIDΪ[%2],ʱ:%3") + .arg(nId) + .arg(mmCmd) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + } + + m_StationInfo_1.m_bRunEnable = false; + if (mmCmd > 0) + { + QString strMsg = QString("%1:ͺʧ,ģͿв%2").arg(QTime::currentTime().toString("hh:mm:ss zzz:")).arg(mmCmd); + emit sgShowLog(1, strMsg); + } + } + else if (nId == 2) + { + if (m_StationInfo_2.m_PLCID != mmCmd) { + m_StationInfo_2.m_PLCID = mmCmd; + m_StationInfo_2.strModelName = strModel; + if (mmCmd <= 0) + SYSLOG_STATUS << QString("﹤λ%1:ͺ,ͺIDΪ[%2],ʱ:%3") + .arg(nId) + .arg(mmCmd) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + else + SYSLOG_STATUS << QString("﹤λ%1:ͺлʧ,Ӧ,ͺIDΪ[%2],ʱ:%3") + .arg(nId) + .arg(mmCmd) + .arg(QDateTime::currentDateTime().toString("hh:mm:ss zzz")); + } + m_StationInfo_2.m_bRunEnable = false; + + if (mmCmd > 0) { + QString strMsg = QString("%1:ͺʧܣģͿв%2").arg(QTime::currentTime().toString("hh:mm:ss zzz:")).arg(mmCmd); + emit sgShowLog(2, strMsg); + } + } + } + } + } +} + +Q_SLOT void CMainWin::onHeardBit() +{ + if (m_pSerialPort) { + SComFrame frame; + memset(&frame, 0, sizeof(SComFrame)); + frame.cmd = 0x43; + frame.data7 = 200; + frame.data8 = 0x50; + m_pSerialPort->enquequeData(frame); + } +} + +Q_SLOT void CMainWin::onActionClicked() +{ + QString strObj = sender()->objectName(); + if ("actionSetting" == strObj) {//궨 + IDetectorUI* pDetectorUI = GetDesignerInterface(); + if (pDetectorUI) { + pDetectorUI->ShowMainFrame(); + } + } + else if ("actionManage" == strObj) {//ģ + m_mangeWid.setParent(this); + m_mangeWid.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + m_mangeWid.setWindowModality(Qt::ApplicationModal); + m_mangeWid.setAttribute(Qt::WA_ShowModal, true); + m_mangeWid.show(); + } + else if ("actionTest" == strObj) {// + m_testWid.setParent(this); + m_testWid.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + m_testWid.setWindowModality(Qt::ApplicationModal); + m_testWid.setAttribute(Qt::WA_ShowModal, true); + m_testWid.show(); + } + else if ("actionHelp" == strObj) {// + QAboutUI dlg(this); + dlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + dlg.setWindowModality(Qt::ApplicationModal); + dlg.setAttribute(Qt::WA_ShowModal, true); + dlg.show(); + } + else if ("action_Check" == strObj) {//ʷ¼ѯ + QCheckDataDlg dlg(this); + dlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + dlg.setDbPtr(m_db); + QStringList strList = m_pWfCtrl->IGetStationKeys(); + QStringList pList; + for (int nIndex = 0; nIndex < strList.size(); nIndex++) + { + IStation *pStation = m_pWfCtrl->IGetStationByKey(strList.at(nIndex)); + pList.append(pStation->stationShowName()); + } + dlg.setStationNames(pList); + dlg.exec(); + } + else if ("action" == strObj) {//ϵͳ + + } + else if ("main_Login_action" == strObj) {//û½ + if (m_pUserCtrl) { + if (m_pUserCtrl->getLoginState() == EM_LOGIN) + { + QMessageBox infobox(QMessageBox::Information, QString(QObject::tr("ʾ")), QString(QObject::tr("ȷҪע%1 ?")).arg(m_pUserCtrl->CurUser()), QMessageBox::Yes | QMessageBox::No, NULL); + infobox.setWindowIcon(QIcon(":/image/leaper")); + infobox.setButtonText(QMessageBox::Yes, QString("ȷ")); + infobox.setButtonText(QMessageBox::No, QString("ȡ")); + if (infobox.exec() == QMessageBox::Yes) { + m_pUserCtrl->LogOutUser(); + } + } + else + m_pUserCtrl->CheckLogin(); + } + else + { + QMessageBox infobox(QMessageBox::Information, QString(QObject::tr("ʾ")), QString(QObject::tr("ùδ.")), QMessageBox::Yes, NULL); + infobox.setWindowIcon(QIcon(":/image/leaper")); + infobox.setButtonText(QMessageBox::Yes, QString(QObject::tr("ȷ"))); + infobox.exec(); + } + } + else if ("main_action_userManager" == strObj) {//û + if (m_pUserCtrl) { + m_pUserCtrl->ShowUserMgrDlg(); + } + else + { + QMessageBox infobox(QMessageBox::Information, QString(QObject::tr("ʾ")), QString(QObject::tr("ùδ.")), QMessageBox::Yes, NULL); + infobox.setWindowIcon(QIcon(":/image/leaper")); + infobox.setButtonText(QMessageBox::Yes, QString(QObject::tr("ȷ"))); + infobox.exec(); + } + } +} + +void CMainWin::timerEvent(QTimerEvent *event) +{ + if (m_TimerID_Status == event->timerId()) + { + onUpdateStatus(); + } +} + +void CMainWin::closeEvent(QCloseEvent *event) +{ + QMessageBox info(this); + info.setWindowIcon(QIcon(LEAPER_LOGO)); + info.setWindowTitle(QObject::tr("")); + info.setText(QObject::tr("ϵͳУҪرգ")); + info.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + info.setButtonText(QMessageBox::Ok, QObject::tr("ȷ")); + info.setButtonText(QMessageBox::Cancel, QObject::tr("ȡ")); + if (info.exec() != QMessageBox::Ok) + { + event->ignore(); + } + else + event->accept(); +} + +//ʼ״̬ +void CMainWin::onInitStatus() +{ + const int c_nWidth = 170; + m_pLbCurrentTime = new QLabel(QObject::tr("ϵͳʱ")); + m_pLbCurrentTime->setMinimumHeight(40); + m_pLbCurrentTime->setMinimumWidth(c_nWidth); + + m_pLbOnLine = new class QLabel(QObject::tr("ģʽ:")); + m_pLbOnLine->setMinimumWidth(c_nWidth); + + m_pLbUser = new class QLabel(QObject::tr("û:")); + m_pLbUser->setMinimumWidth(c_nWidth); + + m_pLbConnect = new class QLabel(QObject::tr("״̬:")); + m_pLbConnect->setMinimumWidth(c_nWidth); + + m_pLbDiskSpace = new class QLabel(QObject::tr("Ӳʣռ:xxx.xG")); + m_pLbDiskSpace->setMinimumWidth(c_nWidth); + + ui.statusBar->addWidget(m_pLbOnLine); + ui.statusBar->addWidget(m_pLbConnect); + ui.statusBar->addWidget(m_pLbUser); + ui.statusBar->addWidget(m_pLbCurrentTime); + ui.statusBar->addWidget(m_pLbDiskSpace); +} + +void CMainWin::onUpdateStatus() +{ + if (m_pLbCurrentTime) { + QString m_currentTimerString = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); + m_pLbCurrentTime->setText(QObject::tr("ϵͳʱ: ") + m_currentTimerString + " "); + //m_pLbCurrentTime->setStyleSheet("font: 14px;"); + } + +// if (m_pLbOnLine && m_pCtrl) { +// QString strOnlineState = QString(QObject::tr("ģʽ")) +// + (m_pCtrl->IOnlineMode() == true ? QObject::tr("ģʽ") : QObject::tr("ģʽ")); +// m_pLbOnLine->setText(strOnlineState); +// // m_pLbOnLine->setStyleSheet("font: bold 14px;"); +// } + + if (m_pLbConnect) { + QString strOnlineState = QString(QObject::tr("״̬")) + + (true == true ? QObject::tr("") : QObject::tr("쳣")); + m_pLbConnect->setText(strOnlineState); + } + + if (m_pLbUser) { + QString strUser; + m_pLbUser->setText(QObject::tr("û ") + strUser); + } + if (m_pLbDiskSpace) + { + QString strDiskSpace = QString(QObject::tr("Ӳʣռ:%1G")).arg(100 / 1024.0); + m_pLbDiskSpace->setText(strDiskSpace); + } +} + +bool CMainWin::onInitCoreCtrl() +{ + //load engine + if (NULL == m_pDllDetectorEngine) + { + m_pDllDetectorEngine = new CDllDetectorEngine(); + if (NULL == m_pDllDetectorEngine) + { + return false; + } + m_pDetectorEngine = m_pDllDetectorEngine->m_pDE; + } + //load coretrl + if (NULL == m_pDllCoreCtrl) + { + m_pDllCoreCtrl = new CDllCoreCtrl(QStringList(), this, m_pDetectorEngine); + if (NULL == m_pDllCoreCtrl) + { + return false; + } + m_pCoreCtrl = m_pDllCoreCtrl->m_pCoreCtrl; + } + + m_pDllDetectorEngine->Initialize(m_pCoreCtrl); + return true; +} + +bool CMainWin::onInitDevice() +{ + QStringList strCamKeys = m_pCoreCtrl->ICameraKeys(); + for (int nIndex = 0; nIndex < strCamKeys.size(); nIndex++) + { + QString camKey = strCamKeys.at(nIndex); + m_pCoreCtrl->IOpenCamera(camKey); + m_pCoreCtrl->IStartCamera(camKey); + } + return true; +} +//======ϵͳ +void CMainWin::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 CMainWin::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 CMainWin::SetLanguage(QString strLangage) +{ + QString strDirPath = QString(QCoreApplication::applicationDirPath() + "/language/"); + QString translatorFileName = strLangage; + if (!translatorFileName.isEmpty()) + { + rmTranslator(); + QLocale::setDefault(QLocale(translatorFileName)); + + QString transDir = strDirPath + translatorFileName; + SearchQmFile(transDir); + } +} + +void CMainWin::rmTranslator() +{ + if (m_VecTranPtr.size() > 0) + { + while (m_VecTranPtr.size()) + { + QTranslator *pVa = m_VecTranPtr.takeFirst(); + qApp->removeTranslator(pVa); + delete pVa; + pVa = NULL; + } + } +} + +void CMainWin::readConfig() +{ + QSettings setting("language.ini", QSettings::IniFormat); + m_strCurLanguage = setting.value("language", "Chinese").toString(); +} + +void CMainWin::writeConfig() +{ + QSettings setting("language.ini", QSettings::IniFormat); + setting.setValue("language", m_strCurLanguage); +} +//====== + +IDetectorUI* CMainWin::GetDesignerInterface() const +{ + return m_DesignerMgr.GetDesignerInterface(); +} + +void CMainWin::saveSolution() +{ + qDebug() << "start save solution"; + if (m_pColossus && m_pWfCtrl) { + m_pColossus->saveTask(m_pWfCtrl->IGetModelInfos()); + } + qDebug() << "finish save solution"; +} + +Q_SLOT void CMainWin::onMainFrameClose() +{ + if (m_pWfCtrl) { + m_pWfCtrl->IUpdateModelInfo(); + } +} + +Q_SLOT void CMainWin::onSnapImage(int nCamera /*= -1*/) +{ + if (!m_pWfCtrl) + return; + IStation *pStation = m_pWfCtrl->IGetStationById(nCamera); + if (!pStation) { + return; + } + else { + pStation->trigImage(); + } +} + +Q_SLOT void CMainWin::onTrigImage() +{ + onSnapImage(1); + onSnapImage(2); +} + +Q_SLOT void CMainWin::onSelModel(int nId, QString strModel) +{ + if (m_pWfCtrl) { + m_pWfCtrl->ISelModel(nId, strModel); + } +} + +Q_SLOT void CMainWin::onChangeUI(QString strUsr, int nLevel) +{ + switch (nLevel) { + case 9: + case 8: + case 7: + case 6: + ui.main_action_userManager->setVisible(true); + ui.action->setEnabled(true); + ui.actionTest->setEnabled(true); + break; + case 5: + ui.main_action_userManager->setVisible(true); + ui.action->setEnabled(true); + ui.actionTest->setEnabled(true); + break; + case 4: + case 3: + case 2: + case 1: + case 0: + ui.main_action_userManager->setVisible(false); + ui.action->setEnabled(false); + ui.actionTest->setEnabled(false); + break; + default: + break; + } +} +Q_SLOT void CMainWin::onLogInOut(QString strName, int level, int state) +{ + if (m_pWfCtrl) { + m_pWfCtrl->ISetUserInfo(strName, level); + onChangeUI(strName, level); + } + + if (state == 0) { + ui.main_Login_action->setText(QObject::tr("ע ")); + } + else + { + ui.main_Login_action->setText(QObject::tr(" ¼")); + } +} + +Q_SLOT void CMainWin::onTestMode(int val) +{ + if (val == 0) { + m_pCameraTrig->start(1000); + } + else if(val ==1){ + m_pCameraTrig->stop(); + } + else if (val == 2) { + onSnapImage(1); + } + else if (val == 3) { + onSnapImage(2); + } +} +//չʾͼƬ +Q_SLOT void CMainWin::onShowImage(int ID, QImage img) +{ + auto ShowImg=[&](QLabel* pLab ,QImage& img) { + if (!pLab) { + qDebug() << "label image is null"; + return; + } + if (img.isNull()) + { + QString str = QObject::tr("⵽: ģͼߴ粻ƥ䣬±궨ģ!!!"); + pLab->setText(str); + } + else + { + QRect rt = ui.wf_lb_image_show_1->rect(); + int h = img.height(); + int w = img.width(); + float d = w * 1.0 / h; + if (d > 0) + { + int h2 = rt.width() / d; + rt.setHeight(h2); + } + QImage imgShow = img.scaled(QSize(rt.size())); + pLab->setPixmap(QPixmap::fromImage(imgShow)); + } + }; + if (ID == 1) + { + ShowImg(ui.wf_lb_image_show_1,img); + } + else if (ID == 2) + { + ShowImg(ui.wf_lb_image_show_2, img); + } +} +//չʾڼͺ +Q_SLOT void CMainWin::onShowName(int ID, QString strName) +{ + if (ID == 1) { + ui.wf_lb_station_name_1->setText(strName); + } + else if (ID == 2) { + ui.wf_lb_station_name_2->setText(strName); + } +} +//չʾlog +Q_SLOT void CMainWin::onShowLog(int nID, QString strMsg) +{ + if (nID == 1) { + ui.wf_text_edit_result_1->append(strMsg); + } + else if (nID == 2) { + ui.wf_text_edit_result_2->append(strMsg); + } +} \ No newline at end of file diff --git a/tpvs17/lpMain/CMainWin.h b/tpvs17/lpMain/CMainWin.h new file mode 100644 index 0000000..4e86ecd --- /dev/null +++ b/tpvs17/lpMain/CMainWin.h @@ -0,0 +1,135 @@ +#ifndef _H_CMAINWIN_H_ +#define _H_CMAINWIN_H_ + +#include +#include "ui_CMainWin.h" +#include "QUserBase.h" +#include "BaseSerialport.h" +#include +#include +#include "CDllCoreCtrl.h" +#include "CDllDetectorEngine.h" +#include "stationdb.h" +#include "IWfCtrl.h" +#include "WfColossus.h" +#include "AutoTrigger.h" +#include "QDetectorDesignerMgr.h" +#include "QTestModeWid.h" +#include "iCoreCtrl.h" +#include "QModelMangerUI.h" + +struct StationInfo +{ + int m_PLCID{ 0 }; + bool m_bRunEnable{ false }; + QString strModelName; +}; +class CMainWin : public QMainWindow, public IGuiCallback +{ + Q_OBJECT + +public: + CMainWin(QWidget *parent = Q_NULLPTR); + ~CMainWin(); + + virtual void IOnReady() {} + virtual void IUpdateShow(const QString& skey) {}; + virtual void INewCameraImage(const QVariantMap& vMap) {}; + virtual void IAddWindows(const QString& sWinName, const QString& sShowId) {}; + virtual void ISendDataToUI(emTpUiDataType dataType, const QString& camKey, void* pData) {}//ãIVariantMapToUI() + virtual void ICameraTrigger(bool bStartOrStop) {};//ãICommInterval() + virtual void IDrawDefectToScene(const QString& szWinName, IImageObject::emTpDefectType defectType, QByteArray& data) {}; + virtual void ISafeDataToUI(emTpUiDataType dataType, const QString& camKey, const QByteArray& data) {}; + virtual void IWarning(int nWarningCode, void* data, int nDataLen) {}; + virtual void ICommInterval(const char* szCom, int nCmd, BYTE* pData, int nDataLen) {}; + virtual void IAlgorithmResult(const QVariantMap& varMap) {}; + virtual void IVariantMapToUI(emTpUiDataType dataType, const QString& camKey, const QVariantMap& vMap); + virtual QVariant IGetVariantById(int id); + virtual void IIoStatesChanged(int nOldState, int nNewState) {}; + virtual void ICommAchieved(const char* szCom, int nCmd, BYTE* pData, int nDataLen) {}; + virtual WORD IGetWorkState() { return 0; };//з͵Ƿ񴥷ֵ01 +public: + Q_SLOT void onAppanalysis(SComFrame frame); + void onHeartComm(SComFrame &frame); + Q_SLOT void onHeardBit(); + Q_SLOT void onShowLog(int nID, QString strMsg); + Q_SLOT void onActionClicked(); + QString genSavePath(QString modelName, QImage &img); +protected: + virtual void timerEvent(QTimerEvent *event); + virtual void closeEvent(QCloseEvent *event); +protected: + void onInitStatus(); + void onUpdateStatus(); + + bool onInitCoreCtrl(); + bool onInitDevice(); +signals: + void sgSelModel(int, QString); + void sgSendChangeUI(QString, QString); + void sgShowLog(int, QString); + void sgShowImg(int, QImage); +private://Ӣ + void SearchQmFile(const QString & strDir); + void SetTranslator(const QString strPath); + void SetLanguage(QString strLangage); + void rmTranslator(); + void readConfig(); + void writeConfig(); + +private: + IDetectorUI* GetDesignerInterface() const; + QDetectorDesignerMgr m_DesignerMgr; + 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); + Q_SLOT void onShowImage(int ID, QImage img); + Q_SLOT void onShowName(int ID, QString strName); +private: + Ui::CMainWin ui; + + IUserCtrl *m_pUserCtrl{ nullptr }; + ISerialPortTool *m_pSerialPort{ nullptr }; + QTimer m_HeartBit; + + QVector m_VecTranPtr; + QString m_strCurLanguage{ "Chinese" }; + + StationInfo m_StationInfo_1; + StationInfo m_StationInfo_2; + + //status ״̬ + int m_TimerID_Status{ 0 }; + class QLabel *m_pLbCurrentTime; + class QLabel *m_pLbOnLine; + class QLabel *m_pLbConnect; + class QLabel *m_pLbUser; + class QLabel *m_pLbDiskSpace; +private: + CDllCoreCtrl* m_pDllCoreCtrl{nullptr}; + CDllDetectorEngine* m_pDllDetectorEngine{nullptr}; + + ICoreCtrl* m_pCoreCtrl{nullptr}; + IDetectorEngine* m_pDetectorEngine{nullptr}; + + StationDB *m_db{nullptr}; + class AutoTrigger *m_pCameraTrig; + class AutoTrigger *m_pStatusTrig; + class ModelLists *m_pModelList; + class IWfCtrl *m_pWfCtrl; + class WfColossus *m_pColossus; + class WfStatus *m_pStatus; + class CVersion *m_pVersion; + + QTestModeWid m_testWid; + QModelMangerUI m_mangeWid; +}; + +#endif diff --git a/tpvs17/lpMain/CMainWin.ui b/tpvs17/lpMain/CMainWin.ui new file mode 100644 index 0000000..a8d0aea --- /dev/null +++ b/tpvs17/lpMain/CMainWin.ui @@ -0,0 +1,386 @@ + + + CMainWin + + + + 0 + 0 + 1028 + 686 + + + + CMainWin + + + + + + + + 0 + 0 + + + + + 0 + 80 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + 20 + 20 + + + + + 240 + 80 + + + + + + + :/wanfengLogo/Resource/wanfeng2.png + + + true + + + false + + + + + + + + 宋体 + 22 + + + + 浙江万丰科技开发股份有限公司 + + + Qt::AutoText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + QFrame::Box + + + QFrame::Raised + + + + 3 + + + 3 + + + + + + + + 0 + 40 + + + + + 55555 + 40 + + + + + 微软雅黑 + 10 + + + + <html><head/><body><p><span style=" font-size:11pt; color:#ff0000;">工位1</span></p></body></html> + + + + + + + + 492 + 372 + + + + + 492 + 372 + + + + QFrame::Panel + + + image + + + Qt::AlignCenter + + + + + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + 40 + + + + + 16777215 + 40 + + + + + 微软雅黑 + 10 + + + + <html><head/><body><p><span style=" font-size:11pt; color:#ff0000;">工位2</span></p></body></html> + + + + + + + + 492 + 372 + + + + + 492 + 372 + + + + QFrame::Panel + + + image + + + Qt::AlignCenter + + + + + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + 12 + + + + Qt::ToolButtonTextUnderIcon + + + TopToolBarArea + + + false + + + + + + + + + + + + + + + :/toolbar/Resource/toolBar/cali.png:/toolbar/Resource/toolBar/cali.png + + + 标定 + + + + + + :/toolbar/Resource/toolBar/model.png:/toolbar/Resource/toolBar/model.png + + + 模型管理 + + + + + + :/toolbar/Resource/toolBar/test.png:/toolbar/Resource/toolBar/test.png + + + 测试 + + + + + + :/toolbar/Resource/toolBar/help.png:/toolbar/Resource/toolBar/help.png + + + 帮助 + + + + + + :/toolbar/Resource/toolBar/education24.png:/toolbar/Resource/toolBar/education24.png + + + 查询记录 + + + + + + :/toolbar/Resource/toolBar/setting.png:/toolbar/Resource/toolBar/setting.png + + + 工位配置 + + + + + + :/toolbar/Resource/toolBar/administrator.png:/toolbar/Resource/toolBar/administrator.png + + + 登 录 + + + + + + :/toolbar/Resource/toolBar/messenger.png:/toolbar/Resource/toolBar/messenger.png + + + 用户管理 + + + + + + + + + diff --git a/tpvs17/lpMain/IMainWidget.h b/tpvs17/lpMain/IMainWidget.h new file mode 100644 index 0000000..f68415a --- /dev/null +++ b/tpvs17/lpMain/IMainWidget.h @@ -0,0 +1,20 @@ +#ifndef _H_IMAINWIDGET_H_ +#define _H_IMAINWIDGET_H_ + +#include +#include +class IMainWidget : public QObject +{ + Q_OBJECT + +public: + IMainWidget(QObject *parent = nullptr) {}; + ~IMainWidget() {}; + virtual QWidget* getMainWidget() = 0; +}; + +#define IMAINWIDGET_API extern "C" __declspec(dllexport) +IMAINWIDGET_API IMainWidget* MainWidget_Create(); +IMAINWIDGET_API void MainWidget_Delete(IMainWidget* pwd); +typedef IMainWidget* (*_MainWidget_Create)(); +#endif diff --git a/tpvs17/lpMain/QAboutUI.cpp b/tpvs17/lpMain/QAboutUI.cpp new file mode 100644 index 0000000..01a6519 --- /dev/null +++ b/tpvs17/lpMain/QAboutUI.cpp @@ -0,0 +1,12 @@ +#include "QAboutUI.h" +#pragma execution_character_set("utf-8") +QAboutUI::QAboutUI(QWidget *parent) + : QWidget(parent) +{ + ui.setupUi(this); + +} + +QAboutUI::~QAboutUI() +{ +} diff --git a/tpvs17/lpMain/QAboutUI.h b/tpvs17/lpMain/QAboutUI.h new file mode 100644 index 0000000..a48c100 --- /dev/null +++ b/tpvs17/lpMain/QAboutUI.h @@ -0,0 +1,19 @@ +#ifndef _H_QABOUTUI_H_ +#define _H_QABOUTUI_H_ + +#include +#include "ui_QAboutUI.h" + +class QAboutUI : public QWidget +{ + Q_OBJECT + +public: + QAboutUI(QWidget *parent = Q_NULLPTR); + ~QAboutUI(); + +private: + Ui::QAboutUI ui; +}; + +#endif diff --git a/tpvs17/lpMain/QAboutUI.ui b/tpvs17/lpMain/QAboutUI.ui new file mode 100644 index 0000000..ad828bd --- /dev/null +++ b/tpvs17/lpMain/QAboutUI.ui @@ -0,0 +1,34 @@ + + + QAboutUI + + + + 0 + 0 + 436 + 284 + + + + 关于 + + + + + + + 11 + + + + <html><head/><body><p>Main Version: 1.5.0228</p><p>Tadpole Version: 2.0.99</p><p>Baumer Driver: v2.8</p><p>Final update date:20200228 11:00:00</p><p>Final Test data:11</p><p>单工位汽轮定位型号判别</p><p>CopyRight (C) 2016-2022 HangZhou Leaper </p><p>摩汽配件产品部</p><p><br/></p></body></html> + + + + + + + + + diff --git a/tpvs17/lpMain/QModelMangerUI.cpp b/tpvs17/lpMain/QModelMangerUI.cpp new file mode 100644 index 0000000..a269fb2 --- /dev/null +++ b/tpvs17/lpMain/QModelMangerUI.cpp @@ -0,0 +1,203 @@ +#include "QModelMangerUI.h" +#include +#include +#include +#include +#include "QPLCIndexUI.h" +#include "WfModel.h" + +#pragma execution_character_set("utf-8") +QModelMangerUI::QModelMangerUI(QWidget *parent) + : QWidget(parent) +{ + ui.setupUi(this); + connect(ui.wf_model_select_button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.wf_model_add_button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.wf_model_mod_button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.wf_model_delete_button, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + QRegExp regx("[a-zA-Z0-9]+$"); + QSharedPointer validator = QSharedPointer(new QRegExpValidator(regx)); + ui.wf_model_input_edit->setValidator(validator.data()); + + connect(ui.wf_chkbox_read_mode_from_plc, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxChange(int))); +} + + +QModelMangerUI::~QModelMangerUI() +{ +} + +Q_SLOT void QModelMangerUI::onButtonClicked() +{ + QString strObj = sender()->objectName(); + if ("wf_model_select_button" == strObj) { + if (!m_pCtrl->IOnlineMode()) { + IStation *pStation = getStation(); + if (pStation) { + QString strModel = pStation->currentSelectModel(); + if (!strModel.isEmpty()) { + m_pCtrl->ISelModel(currentTab(), strModel); + ui.mLblModelState->setText(tr("current %1 OK!").arg(strModel)); + m_pCtrl->ISetModifyModel(true); + } + } + } + } + else if ("wf_model_add_button" == strObj) { + QString strModel = ui.wf_model_input_edit->text(); + if (!strModel.isEmpty() && !strModel.contains(_WF_UNIQUE_SPLIT) && !strModel.contains("##") + && strModel.size() >= 3 && strModel.size() <= 20 && !strModel.contains(" ")) { + int nIndex = currentTab(); + bool bFlag = m_pCtrl->IAddModel(nIndex, strModel); + if (bFlag) { + ui.mLblModelState->setText(tr("add %1 successful!").arg(strModel)); + ui.wf_model_input_edit->setText(""); + } + else { + ui.mLblModelState->setText(tr("add %1 failed!").arg(strModel)); + } + } + else { + ui.mLblModelState->setText(QObject::tr("ģͺвַܰոַ320֮!")); + } + QTimer::singleShot(5000, [&]() { + ui.mLblModelState->setText(""); + }); + } + else if ("wf_model_mod_button" == strObj) { + + } + else if ("wf_model_delete_button" == strObj) { + IStation *pStation = getStation(); + if (pStation) { + QString strModel = pStation->currentRunningModel(); + if (!strModel.isEmpty()) { + QString strName = m_pCtrl->IGetCurrentRuningModel(currentTab()); + if (strModel == strName) + { + QMessageBox msgWarning(QMessageBox::Warning, QObject::tr("󾯸"), strModel + QObject::tr(" ʹãܱɾ"), QMessageBox::Yes); + msgWarning.setWindowIcon(QIcon(":/leaper/app.png")); + msgWarning.setButtonText(QMessageBox::Yes, QObject::tr("ȷ")); + msgWarning.exec(); + return ; + } + QMessageBox msgBox(QMessageBox::Warning, QObject::tr("ͺɾ"), QObject::tr("ɾ") + strModel + "?", QMessageBox::Yes | QMessageBox::No); + msgBox.setWindowIcon(QIcon(":/leaper/app.png")); + if (QMessageBox::Yes == msgBox.exec()) { + bool b = m_pCtrl->IDeleteModel(currentTab(), strModel); + if (!b) { + ui.mLblModelState->setText(tr("delete %1 failed!").arg(strModel)); + } + else { + ui.mLblModelState->setText(tr("delete %1 successful!").arg(strModel)); + } + } + } + } + } +} +int QModelMangerUI::lastNum(QString str) +{ + return str.right(1).toInt(); +} +Q_SLOT bool QModelMangerUI::OnCellDoubleClicked(const QModelIndex &index) +{ + QString strListName = sender()->objectName(); + if (1 != index.column()) { + return false; + } + int stationID = lastNum(strListName); + IStation *pStation = getStation(stationID); + if (pStation) { + QString strModel = pStation->model(index.row()); + QString strName = QObject::tr("ģͺ:") + strModel; + WfModel *pModel = pStation->wfModel(strModel); + if (!pModel) { + return false; + } + QPLCIndexUI dlg(this); + dlg.setModelName(strName); + dlg.setModelIndex(pModel->nIndex); + if (dlg.exec() == QDialog::Accepted) + { + int nIndex = dlg.getModelIndex(); + pModel->nIndex = nIndex; + } + } + + return true; +} + +Q_SLOT void QModelMangerUI::onCheckBoxChange(int state) +{ + if (state > 0) + { + ui.wf_model_select_button->setDisabled(true); + if (m_pCtrl) + m_pCtrl->ISetOnlineModel(true); + } + else { + ui.wf_model_select_button->setDisabled(false); + if (m_pCtrl) + m_pCtrl->ISetOnlineModel(false); + } +} + +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) { + if (m_pCtrl->IOnlineMode() == true) + { + ui.wf_chkbox_read_mode_from_plc->setChecked(true); + } + else { + ui.wf_chkbox_read_mode_from_plc->setChecked(false); + } + } +} + +void QModelMangerUI::closeEvent(QCloseEvent *event) +{ + +} + + +void QModelMangerUI::onInitModelList(IWfCtrl *pCtrl) +{ + m_pCtrl = pCtrl; + if (m_pCtrl) + { + ui.tabWidgetStation->clear(); + QStringList lst = m_pCtrl->IGetStationKeys(); + for (int i = 0; i < lst.size(); i++) { + QTableView *pW = new QTableView(ui.tabWidgetStation); + IStation *pStation = m_pCtrl->IGetStationByKey(lst.at(i)); + QString strName = "wf_cam_listwidget_" + QString::number(pStation->stationId()); + pW->setObjectName(strName); + int nIndex = pStation->stationId()-1; + ui.tabWidgetStation->insertTab(nIndex, (QWidget*)pW, pStation->stationShowName()); + pStation->setWidget(strName, pW); + connect(pW, SIGNAL(doubleClicked(const QModelIndex &)),this, SLOT(OnCellDoubleClicked(const QModelIndex &))); + } + } +} + +int QModelMangerUI::currentTab() +{ + QWidget *pWidget = ui.tabWidgetStation->currentWidget(); + if (pWidget) { + return lastNum(pWidget->objectName()); + } + return -1; +} \ No newline at end of file diff --git a/tpvs17/lpMain/QModelMangerUI.h b/tpvs17/lpMain/QModelMangerUI.h new file mode 100644 index 0000000..f6997e6 --- /dev/null +++ b/tpvs17/lpMain/QModelMangerUI.h @@ -0,0 +1,34 @@ +#ifndef _H_QMODELMANGERUI_H_ +#define _H_QMODELMANGERUI_H_ + +#include +#include "ui_QModelMangerUI.h" +#include "IWfCtrl.h" +#include "IStation.h" + +class QModelMangerUI : public QWidget +{ + Q_OBJECT + +public: + QModelMangerUI(QWidget *parent = Q_NULLPTR); + ~QModelMangerUI(); + + void onInitModelList(IWfCtrl *pCtrl); + int currentTab(); + Q_SLOT void onButtonClicked(); + int lastNum(QString str); + Q_SLOT bool OnCellDoubleClicked(const QModelIndex &index); + Q_SLOT void onCheckBoxChange(int state); +private: + IStation * getStation(int nIndex = -1); +protected: + virtual void showEvent(QShowEvent *event); + virtual void closeEvent(QCloseEvent *event); + +private: + Ui::QModelMangerUI ui; + IWfCtrl *m_pCtrl{ nullptr }; +}; + +#endif diff --git a/tpvs17/lpMain/QModelMangerUI.ui b/tpvs17/lpMain/QModelMangerUI.ui new file mode 100644 index 0000000..aa89ac8 --- /dev/null +++ b/tpvs17/lpMain/QModelMangerUI.ui @@ -0,0 +1,199 @@ + + + QModelMangerUI + + + + 0 + 0 + 671 + 450 + + + + QModelMangerUI + + + + + + + 0 + 0 + + + + + 0 + 23 + + + + + 16777215 + 44444 + + + + + 微软雅黑 + 10 + + + + QTabWidget::North + + + QTabWidget::Rounded + + + -1 + + + + + + + + 16777215 + 50 + + + + QFrame::Box + + + QFrame::Raised + + + 2 + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 微软雅黑 + 10 + + + + 模型号: + + + + + + + + 0 + 25 + + + + + + + + + 0 + 25 + + + + 添加 + + + + + + + + 0 + 25 + + + + 修改 + + + + + + + + 0 + 25 + + + + 删除 + + + + + + + + 0 + 25 + + + + 设置为当前运行模型 + + + + + + + + 0 + 25 + + + + + 微软雅黑 + 10 + + + + 从PLC获取当前模型 + + + + + + + + + + + 16777215 + 25 + + + + + + + + + + + + + diff --git a/tpvs17/lpMain/QPLCIndexUI.cpp b/tpvs17/lpMain/QPLCIndexUI.cpp new file mode 100644 index 0000000..973ef80 --- /dev/null +++ b/tpvs17/lpMain/QPLCIndexUI.cpp @@ -0,0 +1,40 @@ +#include "QPLCIndexUI.h" +#pragma execution_character_set("utf-8") +QPLCIndexUI::QPLCIndexUI(QWidget *parent) + : QDialog(parent) +{ + ui.setupUi(this); + connect(ui.BtnPCLIndexOK, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.BtnPCLIndexCancel, SIGNAL(clicked()), this, SLOT(onButtonClicked())); +} + +QPLCIndexUI::~QPLCIndexUI() +{ +} + +void QPLCIndexUI::setModelName(QString strName) +{ + +} + +void QPLCIndexUI::setModelIndex(int val) +{ + ui.spBxPLCEdit->setValue(val); +} + +int QPLCIndexUI::getModelIndex() +{ + int ret = ui.spBxPLCEdit->value(); + return ret; +} + +Q_SLOT void QPLCIndexUI::onButtonClicked() +{ + QString strObj = sender()->objectName(); + if ("BtnPCLIndexOK" == strObj) { + QDialog::accept(); + } + else if ("BtnPCLIndexCancel" == strObj) { + QDialog::reject(); + } +} diff --git a/tpvs17/lpMain/QPLCIndexUI.h b/tpvs17/lpMain/QPLCIndexUI.h new file mode 100644 index 0000000..31f14c6 --- /dev/null +++ b/tpvs17/lpMain/QPLCIndexUI.h @@ -0,0 +1,23 @@ +#ifndef _H_QPLCINDEXUI_H_ +#define _H_QPLCINDEXUI_H_ + +#include +#include "ui_QPLCIndexUI.h" + +class QPLCIndexUI : public QDialog +{ + Q_OBJECT + +public: + QPLCIndexUI(QWidget *parent = Q_NULLPTR); + ~QPLCIndexUI(); + + void setModelName(QString strName); + void setModelIndex(int val); + int getModelIndex(); + Q_SLOT void onButtonClicked(); +private: + Ui::QPLCIndexUI ui; +}; + +#endif diff --git a/tpvs17/lpMain/QPLCIndexUI.ui b/tpvs17/lpMain/QPLCIndexUI.ui new file mode 100644 index 0000000..ef562a5 --- /dev/null +++ b/tpvs17/lpMain/QPLCIndexUI.ui @@ -0,0 +1,109 @@ + + + QPLCIndexUI + + + + 0 + 0 + 230 + 91 + + + + + 11 + + + + QPLCIndexUI + + + + + + + 0 + 0 + + + + + 11 + + + + 确认 + + + + + + + + 0 + 0 + + + + + 11 + + + + 取消 + + + + + + + + 11 + + + + PLC索引号设置 + + + + + + + + + + 11 + + + + PLC索引值 + + + + + + + + 0 + 0 + + + + + 11 + + + + 100 + + + + + + + + + + + diff --git a/tpvs17/lpMain/QTestModeWid.cpp b/tpvs17/lpMain/QTestModeWid.cpp new file mode 100644 index 0000000..6a346b8 --- /dev/null +++ b/tpvs17/lpMain/QTestModeWid.cpp @@ -0,0 +1,33 @@ +#include "QTestModeWid.h" +#pragma execution_character_set("utf-8") +QTestModeWid::QTestModeWid(QWidget *parent) + : QWidget(parent) +{ + ui.setupUi(this); + + connect(ui.wf_test_btn_start, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.wf_test_btn_stop, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.wf_test_btn_snap_cam1, SIGNAL(clicked()), this, SLOT(onButtonClicked())); + connect(ui.wf_test_btn_snap_cam2, SIGNAL(clicked()), this, SLOT(onButtonClicked())); +} + +QTestModeWid::~QTestModeWid() +{ +} + +Q_SLOT void QTestModeWid::onButtonClicked() +{ + QString strObj = sender()->objectName(); + if ("wf_test_btn_start" == strObj) { + emit sgTestMode(EM_START); + } + else if("wf_test_btn_stop" == strObj) { + emit sgTestMode(EM_STOP); + } + else if ("wf_test_btn_snap_cam1" == strObj) { + emit sgTestMode(EM_CAM1_Trig); + } + else if ("wf_test_btn_snap_cam2" == strObj) { + emit sgTestMode(EM_CAM2_Trig); + } +} diff --git a/tpvs17/lpMain/QTestModeWid.h b/tpvs17/lpMain/QTestModeWid.h new file mode 100644 index 0000000..089f4c5 --- /dev/null +++ b/tpvs17/lpMain/QTestModeWid.h @@ -0,0 +1,28 @@ +#ifndef _H_QTESTMODEWID_H_ +#define _H_QTESTMODEWID_H_ + +#include +#include "ui_QTestModeWid.h" +enum EM_TestMode { + EM_START = 0, + EM_STOP = 1, + EM_CAM1_Trig = 2, + EM_CAM2_Trig = 3 +}; +class QTestModeWid : public QWidget +{ + Q_OBJECT + +public: + QTestModeWid(QWidget *parent = Q_NULLPTR); + ~QTestModeWid(); + + Q_SLOT void onButtonClicked(); +signals: + void sgTestMode(int); +private: + Ui::QTestModeWid ui; + +}; + +#endif diff --git a/tpvs17/lpMain/QTestModeWid.ui b/tpvs17/lpMain/QTestModeWid.ui new file mode 100644 index 0000000..4e4cff0 --- /dev/null +++ b/tpvs17/lpMain/QTestModeWid.ui @@ -0,0 +1,110 @@ + + + QTestModeWid + + + + 0 + 0 + 250 + 103 + + + + QTestModeWid + + + + + + + 0 + 30 + + + + + 11 + + + + 模拟运行 + + + 1001 + + + + + + + + 0 + 30 + + + + + 11 + + + + 相机2捕获 + + + + + + + + 0 + 30 + + + + + 11 + + + + 相机1捕获 + + + + + + + + 0 + 30 + + + + + 11 + + + + 停止 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + diff --git a/tpvs17/lpMain/lpMain.cpp b/tpvs17/lpMain/lpMain.cpp new file mode 100644 index 0000000..63a9a6e --- /dev/null +++ b/tpvs17/lpMain/lpMain.cpp @@ -0,0 +1,29 @@ +#include "lpMain.h" +#pragma execution_character_set("utf-8") + +IMAINWIDGET_API IMainWidget* MainWidget_Create() +{ + return new lpMain(); +} +IMAINWIDGET_API void MainWidget_Delete(IMainWidget* pwd) +{ + if (pwd) { + delete pwd; + pwd = nullptr; + } +} + +lpMain::lpMain(QObject *parent /*= nullptr*/) +{ + +} + +lpMain::~lpMain() +{ + +} + +QWidget * lpMain::getMainWidget() +{ + return &m_wid; +} diff --git a/tpvs17/lpMain/lpMain.h b/tpvs17/lpMain/lpMain.h new file mode 100644 index 0000000..0e2a140 --- /dev/null +++ b/tpvs17/lpMain/lpMain.h @@ -0,0 +1,18 @@ +#ifndef _H_LPMAIN_H_ +#define _H_LPMAIN_H_ + +#include "IMainWidget.h" +#include "CMainWin.h" +class lpMain :public IMainWidget +{ + Q_OBJECT +public: + lpMain(QObject *parent = nullptr); + ~lpMain(); + virtual QWidget *getMainWidget(); + +public: + CMainWin m_wid; +}; + +#endif diff --git a/tpvs17/lpMain/lpMain.vcxproj b/tpvs17/lpMain/lpMain.vcxproj new file mode 100644 index 0000000..c836e7e --- /dev/null +++ b/tpvs17/lpMain/lpMain.vcxproj @@ -0,0 +1,326 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {783A56EA-8A72-4BC9-B8DF-23B76D4FE0E0} + Qt4VSv1.0 + 10.0.17763.0 + + + + DynamicLibrary + v141 + + + DynamicLibrary + v141 + + + + $(MSBuildProjectDirectory)\QtMsBuild + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(ProjectName)d + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + + + + + + + + + + + + + + + + true + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;LPMAIN_LIB;QT_WIDGETS_LIB;QT_SERIALBUS_LIB;QT_SERIALPORT_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;..\..\3part\SerialPortTool\include;..\..\src\lpMain;..\..\src\lpMain\algela;..\..\src\lpMain\QDiskCleanThread;..\..\src\lpMain\sqliteDB;..\..\src\lpMain\UI;..\..\3part\opencv3.4.1\include;..\..\3part\opencv3.4.1\include\opencv;..\..\3part\opencv3.4.1\include\opencv2;..\..\3part\libzkq\include;..\..\3part\lpSyslog\inc;..\..\3part\customgui\include;..\..\src\userCtrl;..\..\src\lpMain\CoreCtrl;..\..\src\lpBase;%(AdditionalIncludeDirectories) + Disabled + ProgramDatabase + MultiThreadedDebugDLL + true + + + Windows + $(SolutionDir)..\runner17\$(TargetName)$(TargetExt) + $(QTDIR)\lib;..\..\3part\opencv3.4.1\x64\vc15\lib;..\..\3part\lpSyslog\lib;..\..\3part\customgui\lib_x64;..\..\3part\libzkq\lib;%(AdditionalLibraryDirectories) + true + qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;Qt5SerialBusd.lib;Qt5SerialPortd.lib;Qt5Sqld.lib;customguid.lib;opencv_world341d.lib;lpSyslogd.lib;libzkqd.lib;%(AdditionalDependencies) + + + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;LPMAIN_LIB;QT_WIDGETS_LIB;QT_SERIALBUS_LIB;QT_SERIALPORT_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;..\..\3part\SerialPortTool\include;..\..\src\lpMain;..\..\src\lpMain\algela;..\..\src\lpMain\QDiskCleanThread;..\..\src\lpMain\sqliteDB;..\..\src\lpMain\UI;..\..\3part\opencv3.4.1\include;..\..\3part\opencv3.4.1\include\opencv;..\..\3part\opencv3.4.1\include\opencv2;..\..\3part\libzkq\include;..\..\3part\lpSyslog\inc;..\..\3part\customgui\include;..\..\src\userCtrl;..\..\src\lpMain\CoreCtrl;..\..\src\lpBase;%(AdditionalIncludeDirectories) + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + Moc'ing %(Identity)... + + + Uic'ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h + + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + + + + + true + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;LPMAIN_LIB;QT_WIDGETS_LIB;QT_SERIALBUS_LIB;QT_SERIALPORT_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) + + MultiThreadedDLL + true + + + Windows + $(OutDir)\$(ProjectName).dll + $(QTDIR)\lib;%(AdditionalLibraryDirectories) + false + qtmain.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;Qt5SerialBus.lib;Qt5SerialPort.lib;Qt5Sql.lib;%(AdditionalDependencies) + + + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;LPMAIN_LIB;QT_WIDGETS_LIB;QT_SERIALBUS_LIB;QT_SERIALPORT_LIB;QT_SQL_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;%(AdditionalIncludeDirectories) + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + Moc'ing %(Identity)... + + + Uic'ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h + + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + + + + + + + + + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl;.\..\..\src\lpBase + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql;.\..\..\3part\SerialPortTool\include;.\..\..\src\lpMain;.\..\..\src\lpMain\algela;.\..\..\src\lpMain\QDiskCleanThread;.\..\..\src\lpMain\sqliteDB;.\..\..\src\lpMain\UI;.\..\..\3part\opencv3.4.1\include;.\..\..\3part\opencv3.4.1\include\opencv;.\..\..\3part\opencv3.4.1\include\opencv2;.\..\..\3part\libzkq\include;.\..\..\3part\lpSyslog\inc;.\..\..\3part\customgui\include;.\..\..\src\userCtrl;.\..\..\src\lpMain\CoreCtrl + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;$(QTDIR)\include\QtSerialBus;$(QTDIR)\include\QtSerialPort;$(QTDIR)\include\QtSql + + + + + + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + true + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tpvs17/lpMain/lpMain.vcxproj.filters b/tpvs17/lpMain/lpMain.vcxproj.filters new file mode 100644 index 0000000..227fd3c --- /dev/null +++ b/tpvs17/lpMain/lpMain.vcxproj.filters @@ -0,0 +1,300 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} + qrc;* + false + + + {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} + qrc;* + false + + + {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} + moc;h;cpp + False + + + {99349809-55BA-4b9d-BF79-8FDBB0286EB3} + ui + true + + + {b8a7fc0f-77f9-4dfc-ab46-43a76501dc86} + + + {dc879e95-c05e-4810-b5cc-f05b2d5ae753} + + + {788788e3-dd4d-4754-9097-7ab652d7049b} + + + {d4ee84cc-3ae8-4d69-b15a-24ed868a2f7a} + + + {aeffe6ee-5f98-4bbf-b0fc-bada2f76bf5d} + + + {460a87f9-e992-4ca0-8545-eea6c2194b2b} + + + + + Source Files + + + CoreCtrl + + + CoreCtrl + + + Source Files + + + CoreCtrl + + + lpMain\algela + + + lpMain\algela + + + lpMain\diskclean + + + lpMain\diskclean + + + lpMain\db + + + lpMain\db + + + lpMain\db + + + lpMain\db + + + lpMain\db + + + lpMain\db + + + lpMain\algela + + + lpMain + + + lpMain + + + lpMain + + + lpMain + + + lpMain\db + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + CoreCtrl + + + lpMain\algela + + + lpMain\algela + + + lpMain\diskclean + + + lpMain\diskclean + + + lpMain\db + + + lpMain\db + + + lpMain\db + + + lpMain\algela + + + lpMain + + + lpMain + + + lpMain + + + lpMain + + + lpMain + + + lpMain\db + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Form Files + + + lpMain\db + + + Form Files + + + Form Files + + + Form Files + + + Form Files + + + + + CoreCtrl + + + CoreCtrl + + + lpMain\diskclean + + + lpMain\db + + + lpMain\db + + + lpMain\db + + + lpMain\db + + + lpMain + + + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + Resource Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/tpvs17/lpMain/lpMain.vcxproj.user b/tpvs17/lpMain/lpMain.vcxproj.user new file mode 100644 index 0000000..60c58f5 --- /dev/null +++ b/tpvs17/lpMain/lpMain.vcxproj.user @@ -0,0 +1,15 @@ + + + + + D:\Qt\Qt5.9.4\5.9.4\msvc2017_64 + $(SolutionDir)..\runner17\ + WindowsLocalDebugger + $(SolutionDir)..\runner17\Enchanterd.exe + PATH=$(QTDIR)\bin%3b$(PATH) + + + D:\Qt\Qt5.9.4\5.9.4\msvc2017_64 + PATH=$(QTDIR)\bin%3b$(PATH) + + \ No newline at end of file diff --git a/tpvs17/tpMain/toolBar/messenger.png b/tpvs17/tpMain/toolBar/messenger.png new file mode 100644 index 0000000..bd0dffb Binary files /dev/null and b/tpvs17/tpMain/toolBar/messenger.png differ