pch.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // pch.h: 这是预编译标头文件。
  2. // 下方列出的文件仅编译一次,提高了将来生成的生成性能。
  3. // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。
  4. // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。
  5. // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。
  6. #ifndef PCH_H
  7. #define PCH_H
  8. // 添加要在此处预编译的标头
  9. #include "framework.h"
  10. // Windows 头文件
  11. #include <windows.h>
  12. #include <assert.h>
  13. #include <string>
  14. #include <atomic>
  15. #include <thread>
  16. #include <map>
  17. #include "Log4CPP.Logger.hpp"
  18. #include "Log4CPP.TLSLog.Tracing.hpp"
  19. #include "mLog.Log4CPP.hpp"
  20. #include "ResDataObject.h"
  21. #include "DIOS.Dev.IODevice.hpp"
  22. //#include "CConfigDlg.h"
  23. //全局消息定义
  24. #define MSG_Dios_Notify_ModeInit (WM_USER+100)
  25. //主窗口句柄
  26. extern HWND gal_hTopWnd;
  27. //输出日志:可供下层模块调用
  28. using logFun = function <void(CString strlog)>;
  29. using msgFun = function <void(CString strKey, CString strText)>;
  30. extern logFun gal_pLogFun;
  31. extern msgFun gal_pMSGFun;
  32. void ToolsDlgLog(CString strlog);
  33. void ToolsDlgMSG(CString strKey, CString strText);
  34. //********************************属性定义********************************
  35. namespace nsDEV = DIOS::Dev;
  36. #define UnitTool_GenGUID "{123492D6-A546-4ACF-8EF1-2CCAA9EA974E}"
  37. #define UnitTool_Mech1GUID "{0C99B70A-F788-48E1-9728-403BFF6DF982}"
  38. #define UnitTool_Mech2GUID "{A6C288B9-8C4F-3A6C-9C5F-12345A0F7284}"
  39. #define UnitTool_Mech3GUID "{9A02D2A7-523D-4FE3-8EA0-C711AE7CA6C3}"
  40. #define UnitTool_Col1GUID "{566EC9F1-CE5A-4B31-9D2A-E9E80B4CA0CC}"
  41. #define UnitTool_Col2GUID "{DD98BBEB-0850-4BE7-997B-8DDECA6BD654}"
  42. #define UnitTool_SynGUID "{D1AF818B-72D0-400E-B780-DF58E2EF23D4}"
  43. #define UnitTool_FPDGUID "{A209866C-A049-4A17-B5C9-421974E59D68}"
  44. #define UnitTool_LogPath "\\DevToolConf\\Log4CPP.Config.Tool.xml"
  45. #define UnitTool_LogName "Tool.DiosUnit"
  46. #define UnitTool_configPath "\\DevToolConf\\UnitToolconfig.xml"
  47. #define UnitTool_UseJson 0
  48. #define UnitTool_PlatformModule "PlatformModule"
  49. #define UnitTool_DevErrorList "ErrorList"
  50. #define UnitTool_logKey_Null "(null)- "
  51. #define UnitTool_DevType_Null "null"
  52. #define UnitTool_logKey_UI "(DiosUnit)- "
  53. #define UnitTool_DevType_UI "DiosUnit"
  54. #define UnitTool_logKey_Gen "(GEN)- "
  55. #define UnitTool_DevType_Gen "Generator"
  56. #define UnitTool_logKey_Mech "(MECH)- "
  57. #define UnitTool_DevType_Mech "Mechanical"
  58. #define UnitTool_logKey_Col "(COLL)- "
  59. #define UnitTool_DevType_Col "Collimator"
  60. #define UnitTool_logKey_Syn "(SYN)- "
  61. #define UnitTool_DevType_Syn "SynBox"
  62. #define UnitTool_logKey_FPD "(FPD)- "
  63. #define UnitTool_DevType_FPD "Detector"
  64. #define UnitTool_logKey_SM "(SMachine)- "
  65. #define UnitTool_DevType_SM "SMachine"
  66. #define UnitTool_LogFileName "LogFileName"
  67. #define UnitTool_CONFIGURATION "CONFIGURATION"
  68. #define UnitTool_DriverConfigPath "DriverConfig"
  69. #define UnitTool_MajorID "MajorID"
  70. #define UnitTool_VendorID "VendorID"
  71. #define UnitTool_ProductID "ProductID"
  72. #define UnitTool_SerialID "SerialID"
  73. #define UnitTool_oemdriver "oemdriver"
  74. #define UnitTool_DeviceNumber "DeviceNumber"
  75. #define UnitTool_GenFileName "GenFileName"
  76. #define UnitTool_GenLibDLL "GenLibDLL"
  77. #define UnitTool_MechFileName "MechFileName"
  78. #define UnitTool_MechLibDLL "MechLibDLL"
  79. #define UnitTool_ColFileName "ColFileName"
  80. #define UnitTool_ColLibDLL "ColLibDLL"
  81. #define UnitTool_SynFileName "SynFileName"
  82. #define UnitTool_SynLibDLL "SynLibDLL"
  83. #define UnitTool_FPDFileName "FPDFileName"
  84. #define UnitTool_FPDLibDLL "FPDLibDLL"
  85. #define UnitTool_SMFileName "SMFileName"
  86. #define UnitTool_SMLibDLL "SMLibDLL"
  87. //逻辑设备类型
  88. enum Dev_Type {
  89. Dev_TypeNULL = -1,
  90. Dev_Generator,
  91. Dev_Mechanical,
  92. Dev_Collimator,
  93. Dev_SynBox,
  94. Dev_Detector,
  95. Dev_SMachine,
  96. Dev_TypeALL
  97. };
  98. //逻辑设备状态
  99. enum Dev_Status {
  100. Dev_StatusNULL = -1,
  101. Dev_Init = 0,
  102. Dev_OnLine = 1,
  103. Dev_OutLine = 2,
  104. Dev_Error = 3,
  105. Dev_StatusALL
  106. };
  107. //********************************公共方法定义********************************
  108. //获取进程路径
  109. string GetProcessDirectory(bool withPlatformModule = false);
  110. //获取模块版本
  111. bool GetVersion(string& version);
  112. //获取时间
  113. CString GetTimeStr();
  114. //读取文件夹下的所有文件路径
  115. void GetAllCFGFiles(string path, vector<string>& files);
  116. void GetAllLibrary(string path, vector<string>& dlls, string nameKey = "");
  117. //设置、删除临时环境变量
  118. bool AddEnvPath(const char* pPath);
  119. bool DelEnvPath(const char* pPath);
  120. //********************************指令查找表********************************
  121. using cmdFun = function <void(int NotifyCode, string key, string context)>;
  122. struct tFrameMapItem
  123. {
  124. cmdFun m_fFun; //处理函数
  125. tFrameMapItem();
  126. tFrameMapItem(cmdFun f);
  127. tFrameMapItem& operator =(const tFrameMapItem& value);
  128. };
  129. //********************************通用模块类********************************
  130. class Device
  131. {
  132. public:
  133. //通用
  134. Device(Dev_Type type = Dev_TypeNULL);
  135. //设备创建
  136. virtual bool CreatMode(bool act); //初始化设备模块
  137. virtual void SetMagMap(); //设置消息查找表
  138. //设备调用方法
  139. string DevActionValue(string action, initializer_list<string> args);//参数:方法名,数值列表
  140. string DevActionKeyValue(string action, map<string, string>& args, bool withP0 = false);//参数:方法名,字段-数值列表,外层是否带有P0层
  141. string DevAction(string action);//参数:方法名
  142. string DevGetValue(string action);//参数:方法名
  143. //设备返回通知
  144. void OnDiosNotify(int& NotifyCode, string& key, string& context);
  145. //获取配置文件及dll的绝对路径
  146. bool OpenCFGAndGetDllPath(string& CFGPath, string& DLLPath);
  147. //属性
  148. Dev_Type m_enuType{ Dev_TypeNULL }; //模块类型
  149. string m_strName{ UnitTool_DevType_Null }; //模块名称
  150. string m_strLogTitle{ UnitTool_logKey_Null }; //日志标题
  151. string m_strLibTitle{ "nullLibDLL" }; //DLL库标题
  152. string m_strCfgLib{ "dll" }; //DLL库名称(带后缀),仅用于显示
  153. string m_strFileTitle{ "nullFileName" }; //配置文件标题
  154. string m_strCfgFile{ "xml" }; //配置文件名称(带后缀)
  155. ResDataObject m_DeviceConfig; //配置文件结构体
  156. shared_ptr<nsDEV::IODriver> m_pDriver{ nullptr }; //驱动指针
  157. unique_ptr<nsDEV::IODevice> m_pDevice{ nullptr }; //设备指针
  158. Dev_Type m_BelongToOtherDriver{ Dev_TypeNULL }; //设备是否属于其它驱动
  159. HMODULE m_hDevLib{ NULL }; //LoadLibrary返回的DLL加载后的句柄
  160. map <string, tFrameMapItem> m_mapFrame; //指令消息动作映射表
  161. };
  162. //********************************通用对话框基类********************************
  163. class CDiosBasicDlg : public CDialogEx, public Device
  164. {
  165. public:
  166. CDiosBasicDlg(Dev_Type type, UINT nIDTemplate, CWnd* pParent = nullptr) :CDialogEx(nIDTemplate, pParent), Device(type){}; // 标准构造函数
  167. // 生成的消息映射函数
  168. virtual BOOL OnInitDialog() override;
  169. virtual void InitPageElements(bool act); //若模块已存在则直接初始化页面元素
  170. virtual void ShowPageElements(bool init = FALSE, bool exit = FALSE, bool cfg = FALSE,
  171. bool general = FALSE); //设置窗口元素显示
  172. //窗口滚动条:最好只修改窗口的高,窗口的宽不要动
  173. virtual void OnOK() override; //
  174. virtual void OnCancel() override; //
  175. afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); //
  176. afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); //
  177. afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); //
  178. void UpdateScrollInfo(int nWidthNeed, int nLengthNeed); //
  179. //悬停提示
  180. virtual BOOL PreTranslateMessage(MSG* pMsg) override;//悬停触发
  181. virtual void SetToolTipsMsgMap(); //悬停提示信息设置
  182. //关联模块
  183. //unique_ptr<Device> m_pDevice{ nullptr }; //窗口指针
  184. protected:
  185. //类属性
  186. CToolTipCtrl m_Ttc;//悬停提示
  187. };
  188. //********************************模块集合类********************************
  189. typedef map<Dev_Type, unique_ptr<CDiosBasicDlg>> _DeviceMape;
  190. class CDeviceSET
  191. {
  192. private:
  193. CDeviceSET() {}//该类不能在外被构造
  194. ~CDeviceSET() {}//该类不能在外被析构
  195. CDeviceSET(const CDeviceSET&) = delete;//该类不能在外被拷贝
  196. CDeviceSET& operator=(const CDeviceSET&) = delete;//该类不能在外被赋值
  197. static CDeviceSET glo_CDeviceSET;//该进程下唯一Singleton对象,即单例
  198. public:
  199. static CDeviceSET* GetInstance();//外部只能通过调用该函数拿到data
  200. //根据GUID确定设备类型
  201. Dev_Type CheckDeviceType(string GUID);
  202. //设置工具默认参数
  203. static void SetToolDefaultConfig();
  204. //获取工具默认参数
  205. static void GetToolDefaultConfig();
  206. static _DeviceMape m_CDeviceMap; //设备列表
  207. };
  208. //********************************康众智光器********************************
  209. #define COLL_CareRaySmartSys_Flag 1
  210. #if COLL_CareRaySmartSys_Flag
  211. using tDataPredate = std::function <int(const char* RecData, const int dataLength)>;
  212. typedef bool(*CallFunGetImageData)(char* imageData, int& imageSize);
  213. typedef bool(*CallFunBeginTransImage)(tDataPredate callback);
  214. typedef bool(*CallFunEndTransImage)();
  215. extern CallFunGetImageData FunGetImageData;
  216. extern CallFunBeginTransImage FunBeginTransImage;
  217. extern CallFunEndTransImage FunEndTransImage;
  218. #endif
  219. #endif //PCH_H