DllToolCommon.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. #pragma once
  2. #include <afx.h>
  3. #include <vector>
  4. #include <functional>
  5. #include "Logger/LoggerModule.h"
  6. #pragma comment(lib, "../lib/Logger/Win64/Logger.lib")
  7. using namespace std;
  8. /////////////////////////////////////////////////////////////////
  9. enum /*class*/ VAR_TYPE
  10. {
  11. ALL_Var,
  12. Bool_Var, //bool
  13. Int_Var, // int
  14. float_Var, //float
  15. Doublel_Var, //double
  16. CharP_Var, //char*
  17. String_Var, //string
  18. CString_Var, //CString
  19. IpImageP_Var, //lpImage*
  20. Mat_Var, //Mat
  21. HTuple_Var, //HTuple
  22. HObject_Vat, //HObject
  23. HImage_Var, //HImage
  24. ISocketP_Var, //ISocket*
  25. ArrayInP_Var, //ArrayIn*
  26. ArrayOutP_Var, //ArrayOut*
  27. ArrayRobotPos_Vat, //ArrayRobotPos*
  28. HTuple_Pos_Var, //HTuple_Pos
  29. HTuple_HomMat2D_Var, //HTuple_HomMat2D
  30. HTuple_Point_Var, //HTuple_Point
  31. HTuple_Line_Var, //HTuple_Line
  32. HTuple_Circle_Var, //HTuple_Circle
  33. HTuple_Disp_Var, //HTuple_Disp
  34. HTuple_Window_Var, //HTuple_Window
  35. HTuple_Ncc_Modle_Var, //HTuple_Ncc_Modle
  36. HTuple_Shape_Modle_Var, //HTuple_Shape_Modle
  37. QHalconWindow_Var, //QHalconWindow
  38. HTuple_Calibration_Var, //HTuple_Calibration
  39. HTuple_CamParam_PoseCalib_Var, //HTuple_CamParam_PoseCalib
  40. //////////////////////////////////////////////////////////////////////////
  41. Control_Base,
  42. Control_ComboBox,
  43. Control_Button,
  44. Control_Radiobutton,
  45. Control_CheckBox,
  46. Control_ListCtrl,
  47. Control_Groupbox,
  48. Control_Static,
  49. Control_Listbox,
  50. Control_EditBox,
  51. Control_Text,
  52. Control_Image,
  53. //////////////////////////////////////////////////////////////////////////
  54. Tool,
  55. };
  56. typedef struct _tagArray
  57. {
  58. int nValidData = 100;
  59. float mData[512] = { 0 };
  60. } Array1;
  61. typedef struct _tagEven
  62. {
  63. int nEvenTime = INFINITE; //超时时间
  64. HANDLE hEvenHandle = NULL;// 事件句柄
  65. } EVEN;
  66. typedef struct _tagHPos
  67. {
  68. HTuple hv_Row;
  69. HTuple hv_Column;
  70. HTuple hv_Angle;
  71. HTuple hv_HomMat2D;
  72. _tagHPos()
  73. {
  74. Clear();
  75. }
  76. void Clear()
  77. {
  78. hv_Row.Clear();
  79. hv_Column.Clear();
  80. hv_Angle.Clear();
  81. hv_HomMat2D.Clear();
  82. }
  83. } HPOS;
  84. typedef struct _tagHCalibration
  85. {
  86. HTuple hv_HomMat2D;
  87. HTuple hv_Center_x;//旋转中心坐标(图像坐标系)
  88. HTuple hv_Center_y;//旋转中心坐标(图像坐标系)
  89. double nToolMark_X;//设定的中心点坐标(机器人坐标系)
  90. double nToolMark_Y;//设定的中心点坐标(机器人坐标系)
  91. double nToolMark_A;//设定的基准角度(机器人坐标系)
  92. bool b_IsAngleCalibration;//是否启用了旋转标定
  93. _tagHCalibration()
  94. {
  95. Clear();
  96. }
  97. void Clear()
  98. {
  99. hv_HomMat2D.Clear();
  100. hv_Center_x.Clear();
  101. hv_Center_y.Clear();
  102. nToolMark_X = 0;
  103. nToolMark_Y = 0;
  104. nToolMark_A = 0;
  105. b_IsAngleCalibration = false;
  106. }
  107. } HCALIBRATION;
  108. typedef struct _tagHCamParam_PoseCalib
  109. {
  110. HTuple hv_CamParam;
  111. HTuple hv_PoseCalib;
  112. _tagHCamParam_PoseCalib()
  113. {
  114. Clear();
  115. }
  116. void Clear()
  117. {
  118. hv_CamParam.Clear();
  119. hv_PoseCalib.Clear();
  120. }
  121. }HCAMPARAM_POSECALIB;
  122. typedef struct _tagHHCCModle
  123. {
  124. HObject hv_ROI;
  125. HObject ho_ModelRegion;
  126. HNCCModel hv_ModelID;
  127. HTuple hv_SubPixel;
  128. int m_nAngleStart2;
  129. int m_nAngleExtent2;
  130. int m_nMinScore;
  131. int m_nNumMatches;
  132. int m_nMaxOverlap;
  133. int m_nNumLevels;
  134. _tagHHCCModle()
  135. {
  136. Clear();
  137. }
  138. void Clear()
  139. {
  140. hv_ROI.Clear();
  141. ho_ModelRegion.Clear();
  142. hv_ModelID.Clear();
  143. hv_SubPixel.Clear();
  144. m_nAngleStart2 = 0;
  145. m_nAngleExtent2 = 0;
  146. m_nMinScore = 0;
  147. m_nNumMatches = 0;
  148. m_nMaxOverlap = 0;
  149. m_nNumLevels = 0;
  150. }
  151. } HNCCMODLE;
  152. typedef struct _tagShapeModel
  153. {
  154. HObject hv_ROI;
  155. HObject ho_ModelRegion;
  156. HShapeModel hv_ModelID;
  157. HTuple hv_SubPixel;
  158. int m_nAngleStart2;
  159. int m_nAngleExtent2;
  160. int m_nMinScore;
  161. int m_nNumMatches;
  162. int m_nMaxOverlap;
  163. int m_nNumLevels;
  164. _tagShapeModel()
  165. {
  166. Clear();
  167. }
  168. void Clear()
  169. {
  170. hv_ROI.Clear();
  171. ho_ModelRegion.Clear();
  172. hv_ModelID.Clear();
  173. hv_SubPixel.Clear();
  174. m_nAngleStart2 = 0;
  175. m_nAngleExtent2 = 0;
  176. m_nMinScore = 0;
  177. m_nNumMatches = 0;
  178. m_nMaxOverlap = 0;
  179. m_nNumLevels = 0;
  180. }
  181. } HSHAPEMODLE;
  182. typedef struct _tagHMessage
  183. {
  184. HTuple hv_Row;
  185. HTuple hv_Column;
  186. HTuple hv_Msg;
  187. HTuple hv_MsgSize;
  188. HTuple hv_MsgColor;
  189. _tagHMessage()
  190. {
  191. Clear();
  192. }
  193. void addMsg(HTuple hvMsg, HTuple hvRow, HTuple hvColumn, HTuple hvMsgSize = 10, HTuple hvMsgColor = "green")
  194. {
  195. int nCon = hv_Row.TupleLength();
  196. hv_Msg[nCon] = hvMsg;
  197. hv_Row[nCon] = hvRow;
  198. hv_Column[nCon] = hvColumn;
  199. hv_MsgSize[nCon] = hvMsgSize;
  200. hv_MsgColor[nCon] = hvMsgColor;
  201. }
  202. void Clear()
  203. {
  204. hv_Row = HTuple();
  205. hv_Column = HTuple();
  206. hv_Msg = HTuple();
  207. hv_MsgSize = HTuple();
  208. hv_MsgSize = HTuple();
  209. hv_MsgColor = HTuple();
  210. // hv_MsgSize = 10;
  211. // hv_MsgColor = "green";
  212. }
  213. } HMESSAGE;
  214. typedef struct _tagHDISP
  215. {
  216. HObject ho_DispObj;
  217. HMESSAGE hv_Message;
  218. _tagHDISP()
  219. {
  220. Clear();
  221. }
  222. void addMsg(HTuple hvMsg, HTuple hvRow, HTuple hvColumn, HTuple hvMsgSize = 10, HTuple hvMsgColor = "green")
  223. {
  224. hv_Message.addMsg(hvMsg, hvRow, hvColumn, hvMsgSize, hvMsgColor);
  225. }
  226. void AddObj(HObject hoObj)
  227. {
  228. ConcatObj(ho_DispObj, hoObj, &ho_DispObj);
  229. }
  230. void Clear()
  231. {
  232. GenEmptyObj(&ho_DispObj);
  233. hv_Message.Clear();
  234. }
  235. } HDISP;
  236. typedef struct _tagHIMAGE
  237. {
  238. HObject ho_Image;
  239. } HIMAGE;
  240. typedef struct _tagHWINDOW
  241. {
  242. HTuple hv_Window;
  243. _tagHWINDOW()
  244. {
  245. Clear();
  246. }
  247. void Clear()
  248. {
  249. hv_Window.Clear();
  250. }
  251. } HWINDOW;
  252. typedef struct _tagHLine
  253. {
  254. void Clear()
  255. {
  256. hv_Row1.Clear();
  257. hv_Column1.Clear();
  258. hv_Row2.Clear();
  259. hv_Column2.Clear();
  260. }
  261. HTuple hv_Row1;
  262. HTuple hv_Column1;
  263. HTuple hv_Row2;
  264. HTuple hv_Column2;
  265. } HLine;
  266. typedef struct _tagHCircle
  267. {
  268. void Clear()
  269. {
  270. hv_Row.Clear();
  271. hv_Column.Clear();
  272. hv_Radius.Clear();
  273. }
  274. HTuple hv_Row;
  275. HTuple hv_Column;
  276. HTuple hv_Radius;
  277. } HCircle;
  278. typedef struct _tagHPoint
  279. {
  280. void Clear()
  281. {
  282. hv_Row.Clear();
  283. hv_Column.Clear();
  284. }
  285. HTuple hv_Row;
  286. HTuple hv_Column;
  287. } HPoint;
  288. //////////////////////////////////////////////////////////////////////////
  289. //////////////////////////////////////////////////////////////////////////
  290. #define FUNCTION_GETGLOBALFILEID ("GetGlobalFileID")
  291. #define FUNCTION_DESCRIPTION ("Description")
  292. #define FUNCTION_GETTOOLPTR ("GetToolPtr")
  293. #define FUNCTION_RELEASE ("Release")
  294. // Diagram的控件类型
  295. #define CONTROL_BASE _T("Base")
  296. #define CONTROL_COMBOBOX _T("ComboBox")
  297. #define CONTROL_BUTTON _T("Button")
  298. #define CONTROL_RADIOBUTTON _T("Radiobutton")
  299. #define CONTROL_CHECKBOX _T("CheckBox")
  300. #define CONTROL_LISTCTRL _T("ListCtrl")
  301. #define CONTROL_GROUPBOX _T("Groupbox")
  302. #define CONTROL_STATIC _T("Static")
  303. #define CONTROL_LISTBOX _T("Listbox")
  304. #define CONTROL_EDITBOX _T("EditBox")
  305. #define CONTROL_TEXT _T("Text") // 同EditBox
  306. #define CONTROL_IMAGE _T("Image") // 同Edit
  307. //////////////////////////////////////////////////////////////////////////
  308. // Dll 工作状态
  309. #define TOOL_ERROR -1
  310. #define TOOL_SUCCESS 0
  311. #define TOOl_BUSY 1
  312. #define TOOL_DONE 2
  313. // Dll执行的返回值
  314. #define RT_INVALID -2 // 工具无效 或被禁用
  315. #define RT_NONE -1 // 工具尚未执行
  316. #define RT_SUCCESS 0 // 工具执行成功
  317. #define RT_ERROR 1
  318. #define RT_TIMEOUT 2
  319. #define RT_GOTO 3 // 返回跳转信号
  320. // 接口相关错误码
  321. // 接口已存在
  322. #define RT_ERR_ALREADY_EXIST 0x2000
  323. // 接口信息无效
  324. #define RT_ERR_INVALID_INFO 0x2001
  325. // 各种控件需要同步的消息
  326. typedef enum _tagSyncMsg
  327. {
  328. SYNC_COMBO_SELCHANGE,
  329. SYNC_EDIT_CHANGE,
  330. SYNC_LIST_CHANGE,
  331. } SYNC_MSG;
  332. // 输入输出类型
  333. typedef enum _tagInfDirection
  334. {
  335. INF_IN = 1, // 输入接口
  336. INF_OUT = 2, // 输出接口
  337. INF_INOUT = 3,
  338. INF_NONE = 5,
  339. } INF_DIRECTION;
  340. // 接口类型(值或控件)
  341. typedef enum _tagInfType
  342. {
  343. INF_VALUE_1 = 1, // 基础变量值类型
  344. INF_VALUE_2 = 2, // 图像变量值类型
  345. INF_VALUE_3 = 3, // 句柄、对象类型
  346. INF_VALUE_4 = 4, // 地址类型
  347. INF_CONTROL = 4, // 控件类型
  348. INF_TOOL = 5, // 工具(跳转用)
  349. INF_TYPE_NONE = 6 // 未定义
  350. } INF_TYPE;
  351. // 参数传递类型(传值或者传引用)
  352. typedef enum _tagInfWay
  353. {
  354. INF_BY_VALUE, // 传值
  355. INF_BY_ADDRESS, // 传地址
  356. INF_BY_NONE
  357. } INF_WAY;
  358. // 工具类型(工具或控件)
  359. typedef enum _tagToolType
  360. {
  361. TOOL_BY_TOOL, // 工具
  362. TOOL_BY_PROT, // 端口
  363. TOOL_BY_GOTO, // 跳转
  364. TOOL_BY_NONE
  365. } TOOL_TYPE;
  366. //////////////////////////////////////////////
  367. // Dll工具的接口描述信息
  368. typedef struct _tagDllInterface
  369. {
  370. CString strName; // 接口名字
  371. CString strAliasName; // 工具别名(通常为曾用名或者中文名)
  372. CString strInfo; // 接口的描述信息
  373. VAR_TYPE VarType; // 接口的值类型
  374. LPVOID* pValue; // 接口的值指针
  375. INF_DIRECTION InfDirection; // 输入还是输出
  376. INF_TYPE InfType; // 控件类型还是值类型
  377. INF_WAY InfWay; // 传值还是传引用(2019-5-3增加)
  378. bool bShow; // 2019-3-26 是否隐藏此接口
  379. bool bSmartLink; // 智能链接(添加工具到任务栏的时候,工具的输入接口自动向上搜素可用的输出端口.序列化的时候该功能不适用)
  380. _tagDllInterface()
  381. {
  382. Reset();
  383. }
  384. void Reset()
  385. {
  386. strInfo = _T("Prot Info !");
  387. InfDirection = INF_NONE;
  388. InfType = INF_TYPE_NONE;//INF_VALUE_1
  389. InfWay = INF_BY_VALUE;
  390. bShow = true;
  391. bSmartLink = false;
  392. pValue = NULL;
  393. }
  394. // 重载 =
  395. _tagDllInterface& operator =(const _tagDllInterface& inf)
  396. {
  397. if (this != &inf)
  398. {
  399. this->strName = inf.strName;
  400. this->strAliasName = inf.strAliasName;
  401. this->strInfo = inf.strInfo;
  402. this->VarType = inf.VarType;
  403. this->InfDirection = inf.InfDirection;
  404. this->InfType = inf.InfType;
  405. this->InfWay = inf.InfWay;
  406. this->bShow = inf.bShow;
  407. }
  408. return *this;
  409. }
  410. ~_tagDllInterface()
  411. {
  412. }
  413. } DLL_INF, *LPDLL_INF;
  414. //////////////////////////////////////////////
  415. // Dll工具的描述信息
  416. typedef struct _tagDllToolDescription
  417. {
  418. TOOL_TYPE Type; // 工具的类型(工具、控件、跳转指令)
  419. CString strCategory; // 工具的分组
  420. CString strName; // 工具名字
  421. CString strAliasName; // 工具别名(通常为曾用名或者中文名)
  422. CString strVersion; // 工具版本
  423. CString strInfo; // 描述信息
  424. _tagDllToolDescription()
  425. {
  426. Type = TOOL_TYPE::TOOL_BY_TOOL;
  427. }
  428. } DLL_TOOL_DESC, *LPDLL_TOOL_DESC;
  429. typedef struct _tagDEUBGOBJ
  430. {
  431. HImage mImage;
  432. HObject mObj;
  433. _tagDEUBGOBJ()
  434. {
  435. mImage.Clear();
  436. mObj.Clear();
  437. }
  438. } DEUBGOBJ;
  439. // 接口类型
  440. typedef enum _tagMsgType
  441. {
  442. _WARNING, // 警告
  443. _ERROR, // 错误
  444. _INFO, // 信息
  445. _MSG, // Message
  446. } MSG_WAY;
  447. /// 工具状态
  448. typedef void(__stdcall* receToolStateCallBack) (CString strToolName, int nState, long long userParam);
  449. /// Log
  450. typedef void(__stdcall* receLogCallBack) (CString strToolName, MSG_WAY nType, CString strMassage, long long userParam);
  451. /// OnExecute
  452. typedef void(__stdcall* receOnExecutegCallBack) (CString strToolName, long long userParam);
  453. /// ToolBusy
  454. typedef void(__stdcall* receToolBusyCallBack) (CString strToolName, int nState, CString strMassage, long long userParam);
  455. // dll操作向exe同步的回调函数
  456. // CWnd:触发的控件指针
  457. // nMSG:触发的消息
  458. typedef std::function<void(CWnd* pWnd, UINT nMSG)> CONTROL_CALLBACK;
  459. class CDllTool
  460. {
  461. public:
  462. CDllTool()
  463. {
  464. //ControlCallback = NULL;
  465. m_Even.hEvenHandle = NULL;
  466. m_Even.nEvenTime = 0;
  467. }
  468. virtual ~CDllTool()
  469. {
  470. }
  471. public:
  472. virtual int InitTool(CWnd * pWnd, CString strTaskName, CString strToolName) { return 0; };
  473. virtual void ShowDialog(CString strTaskName, CString strToolName) {};
  474. virtual DEUBGOBJ GetDeubgDispObj() { DEUBGOBJ obj; return obj; };
  475. virtual int Execute() { return 0; };
  476. DLL_INF& Interface(const int nIndex) { return m_Interfaces[nIndex]; }
  477. UINT GetInterfaceSize() { return (UINT)m_Interfaces.size(); }
  478. void AddInterface(const DLL_INF dll_inf) { m_Interfaces.push_back(dll_inf); };
  479. void InterfaceClear() { m_Interfaces.clear(); };
  480. template<typename T>
  481. T& Value(const int nIndex) { return *(T*)m_Interfaces[nIndex].pValue; }
  482. template<typename T>
  483. void SetValue(const int nIndex, T& t, INF_WAY way = INF_BY_VALUE)
  484. {
  485. if (way == INF_BY_VALUE)
  486. {
  487. *(T*)m_Interfaces[nIndex].pValue = t;
  488. }
  489. else
  490. {
  491. *m_Interfaces[nIndex].pValue = &t;
  492. }
  493. }
  494. virtual void Trigger(bool bMode = false) { };
  495. virtual void Running(bool bRun) {};
  496. virtual void Serialize(CArchive& ar, const int nExeVersion, const int nDocVersion) {};
  497. //设置接收 工具状态 数据回调函数
  498. virtual void setReceToolStateCallBack(receToolStateCallBack callBack, long long userParam) {};
  499. ///设置接收 LOG 数据回调函数
  500. virtual void setReceLogCallBack(receLogCallBack callBack, long long userParam) {};
  501. ///设置接收 OnExecute 回调函数
  502. virtual void setOnExecuteCallBack(receOnExecutegCallBack callBack, long long userParam) {};
  503. ///设置接收 ToolBusy 回调函数
  504. virtual void setToolBusyCallBack(receToolBusyCallBack callBack, long long userParam) {};
  505. EVEN m_Even;
  506. CONTROL_CALLBACK ControlCallback; // 控件用于双向同步的回调函数
  507. protected:
  508. virtual void InitDefaultInterfaces() {};
  509. protected:
  510. vector<DLL_INF> m_Interfaces;
  511. };
  512. ////////////////////////
  513. /// 网络套接字
  514. class ISocket
  515. {
  516. public:
  517. virtual ~ISocket() { }
  518. public:
  519. /// IP
  520. virtual CString ip(void) = 0;
  521. /// 端口号
  522. virtual UINT port(void) = 0;
  523. /// 获取已经接收的消息数据大小
  524. virtual BOOL msgSize(long &size) = 0;
  525. /// 接收消息
  526. virtual BOOL receMsg(void** msg, long size) = 0;
  527. /// 发送消息
  528. virtual BOOL sendMsg(const CString msg) = 0;
  529. /// 发送消息
  530. virtual BOOL sendMsg(const void* msg, long size) = 0;
  531. };
  532. //TRACE