DataStructure.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. 
  2. #pragma once
  3. #include <QString>
  4. #include <QVector>
  5. #include <QDebug>
  6. #include <QEvent>
  7. #include <QMutex>
  8. #include <QWaitCondition>
  9. #include <QThread>
  10. #include <QColor>
  11. #include <QImage>
  12. #include <QFileInfo>
  13. #include <QFileDialog>
  14. #include <QElapsedTimer>
  15. #include <QGridLayout>
  16. #include <QCloseEvent>
  17. #include <HalconCpp.h>
  18. using namespace HalconCpp;
  19. #include "opencv2/opencv.hpp"
  20. using namespace cv;
  21. class TOOL;
  22. class DllTool;
  23. // 默认的硬件组态页面名称
  24. #define GROUP_NAME_HARDWARE ("硬件组态")
  25. // 默认的TaskManager的页面名称
  26. #define GROUP_NAME_TASKMONITOR ("任务监控")
  27. // 默认的DebugView的页面名称
  28. #define GROUP_NAME_LOGVIEW ("日志信息")
  29. // 系统内置的Event的分组名称
  30. #define GROUP_NAME_SYSTEMEVENT ("SYSTEM_EVENT")
  31. // 内置的全局变量组名字
  32. #define GROUP_NAME_SYSTEM ("System")
  33. // 内置的默认变量组名字
  34. #define GROUP_NAME_DEFAULVALUE ("DefaultValue")
  35. // 硬件组态的工具分类
  36. #define CATEGORY_TOOL_HARDWARE ("硬件工具")
  37. ////========================================================
  38. ////
  39. //// ENUM
  40. ////
  41. ////========================================================
  42. /// <summary>
  43. /// 管理系统中所有的枚举类型(逐步添加中,方便使用Q_ENUM管理)
  44. /// </summary>
  45. class VPEnum : public QObject
  46. {
  47. Q_OBJECT
  48. public:
  49. /// <summary>
  50. /// 线程的优先级
  51. /// </summary>
  52. enum class PRIORITY : short
  53. {
  54. IdlePriority,
  55. LowestPriority,
  56. LowPriority,
  57. NormalPriority,
  58. HighPriority,
  59. HighestPriority,
  60. TimeCriticalPriority,
  61. InheritPriority
  62. };
  63. Q_ENUM(PRIORITY);
  64. /// <summary>
  65. /// Tool工作状态
  66. /// </summary>
  67. enum class EXEC_STATUS : short
  68. {
  69. Wait, // 等待事件中
  70. Busy, // 执行中
  71. Done, // 执行完毕
  72. StandBy // 就绪状态,表示工具尚未执行
  73. };
  74. Q_ENUM(EXEC_STATUS)
  75. /// <summary>
  76. /// Tool执行的返回值
  77. /// </summary>
  78. enum class RETURN_VALUE : short
  79. {
  80. Success = 0, // 工具执行成功
  81. Error, // 工具执行错误
  82. Invalid, // 工具无效 或被禁用
  83. Timeout, // 工具执行超时
  84. Goto, // 返回跳转信号
  85. Abort, // 2022-9-5 因为各种原因,放弃执行此工具
  86. None // 无状态,表示工具尚未执行
  87. };
  88. Q_ENUM(RETURN_VALUE)
  89. /// <summary>
  90. /// 全局变量的读写模式(仅DB模式使用)
  91. /// </summary>
  92. enum class GVL_ACCESS_MODE : short
  93. {
  94. All,
  95. ReadOnly,
  96. WriteOnly
  97. };
  98. Q_ENUM(GVL_ACCESS_MODE)
  99. };
  100. // 基础模式中包括的类型数量
  101. #define GVL_BASIC_TYPE_COUNT 5
  102. // 标准模式中包括的类型数量
  103. #define GVL_STANDARD_TYPE_COUNT 28
  104. /// <summary>
  105. /// 数据类型定义
  106. /// </summary>
  107. enum class VALUE_TYPE : short
  108. {
  109. Type_Bool = 0, //bool
  110. Type_Int, //int
  111. Type_Float, //float
  112. Type_Double, //double
  113. Type_String, //QString
  114. Type_StdString, //std::string
  115. Type_QImage, //QImage
  116. Type_Mat, //Mat
  117. Type_HTuple, //HTuple
  118. Type_HObject, //HObject
  119. Type_HImage, //HImage
  120. Type_ST_Pos, //HTuple_Pos
  121. Type_ST_HomMat2D, //HTuple_HomMat2D
  122. Type_ST_Point, //HTuple_Point
  123. Type_ST_Line, //HTuple_Line
  124. Type_ST_Circle, //HTuple_Circle
  125. Type_ST_Disp, //HTuple_Disp
  126. Type_ST_Window, //HTuple_Window
  127. Type_ST_Ncc_Modle, //HTuple_Ncc_Modle
  128. Type_ST_Shape_Modle, //HTuple_Shape_Modle
  129. Type_ST_Calibration, //HTuple_Calibration
  130. Type_ST_CamParam_PoseCalib, //HTuple_CamParam_PoseCalib
  131. Type_pIBaseCamera, //IBaseCamera*
  132. Type_pIpImage, //lpImage*
  133. Type_pISocket, //ISocket*
  134. Type_pArrayIn, //ArrayIn*
  135. Type_pArrayOut, //ArrayOut*
  136. Type_pArrayRobotPos, //ArrayRobotPos*
  137. Control_Base = 100,
  138. Control_Label,
  139. Control_Button,
  140. Control_CheckBox,
  141. Control_RadioBox,
  142. Control_Groupbox,
  143. Control_Image,
  144. Control_LineEdit,
  145. Control_Listbox,
  146. Control_ComboBox,
  147. Control_Value,
  148. Control_PieChart,
  149. Control_CustomPlot,
  150. Control_Table,
  151. Control_Result,
  152. Control_Widget,
  153. // Type_Event, // 2022-9-3 废弃,统一到接口的 INF_EVENT 类型中
  154. Type_Tool,
  155. Type_Unknown
  156. };
  157. /// <summary>
  158. /// 数据类型定义
  159. /// 此处对应DataStructure.h中的 VALUE_TYPE 顺序,要确保双方顺序同步
  160. /// </summary>
  161. const static QStringList valueString =
  162. {
  163. "bool", // 0
  164. "int", // 1
  165. "float", // 2
  166. "double", // 3
  167. "QString", // 4
  168. "std::string", // 5
  169. "QImage", // 6
  170. "Mat", // 7
  171. "HTuple", // 8
  172. "HObject", // 9
  173. "HImage", // 10
  174. "HPos", // 11
  175. "HTuple_HomMat2D", // 12
  176. "HTuple_Point", // 13
  177. "HTuple_Line", // 14
  178. "HTuple_Circle", // 15
  179. "HTuple_Disp", // 16
  180. "HTuple_Window", // 17
  181. "HTuple_Ncc_Modle", // 18
  182. "HTuple_Shape_Modle", // 19
  183. "HTuple_Calibration", // 20
  184. "HTuple_CamParam_PoseCalib", // 21
  185. "IBaseCamera*", // 22
  186. "lpImage*", // 23
  187. "ISocket*", // 24
  188. "ArrayIn*", // 25
  189. "ArrayOut*", // 26
  190. "ArrayRobotPos*", // 27
  191. // 28
  192. "ControlBase", // 100
  193. "QLabel", // 101
  194. "QPushButton", // 102
  195. "QCheckBox", // 103
  196. "QRadioButton", // 104
  197. "QGroupBox", // 105
  198. "QImage", // 106
  199. "QLineEdit", // 107
  200. "QListWidget", // 108
  201. "QComboBox", // 109
  202. "ValueControl", // 110
  203. "PieChart", // 111
  204. "WaveChart", // 112
  205. "TableControl", // 113
  206. "Result", // 114
  207. "QWidget", // 115
  208. "QEvent",
  209. "Tool",
  210. "Unknown"
  211. };
  212. /// <summary>
  213. /// 输入输出类型
  214. /// </summary>
  215. enum class INF_DIRECTION : short
  216. {
  217. INF_DIR_IN = 1, // 输入接口
  218. INF_DIR_OUT = 2, // 输出接口
  219. INF_DIR_BOTH = 3, // 双向接口(全局变量)
  220. INF_DIR_UNKNOWN,
  221. };
  222. /// <summary>
  223. /// 端口废弃类型
  224. /// </summary>
  225. enum class INF_DISCARD : short
  226. {
  227. INF_DEFAULT = 0, // 默认值(未废弃,正常使用的端口)
  228. INF_MARK_DELETE = 1, // 接口被删除
  229. INF_MARK_DISCARD = 2, // 接口被标记为废弃
  230. INF_MARK_CHANGE = 3 // 接口被修改(常因为端口的类型被修改)
  231. };
  232. /// <summary>
  233. /// 工具总体类型(工具、控件或者变量)
  234. /// </summary>
  235. enum class TOOL_TYPE : short
  236. {
  237. TOOL_TYPE_STANDARD, // 标准工具
  238. TOOL_TYPE_PORT_INPUT, // 输入端口工具
  239. TOOL_TYPE_PORT_OUTPUT, // 输出端口工具
  240. TOOL_TYPE_GLOBAL_VARIABLE, // 全局变量
  241. TOOL_TYPE_LOCAL_VARIABLE, // 局部变量
  242. TOOL_TYPE_GOTO, // 跳转工具
  243. TOOL_TYPE_COMMENT, // 2022-3-13,注释工具
  244. TOOL_TYPE_PARALLEL, // 2022-4-18,并行计算工具
  245. TOOL_TYPE_FORLOOP, // 2022-8-21,For循环工具
  246. TOOL_TYPE_WAIT, // 2022-9-2,Wait工具
  247. TOOL_TYPE_UNKNOWN
  248. };
  249. /// <summary>
  250. /// 接口总体类型
  251. /// </summary>
  252. enum class INF_TYPE : short
  253. {
  254. INF_TYPE_STANDARD, // 标准接口
  255. INF_TYPE_VALUE, // 数值接口(全局变量,局部变量)
  256. INF_TYPE_CONTROL, // 控件接口
  257. INF_TYPE_TOOL, // 2022-8-21 Tool接口,包括输入和输出两种
  258. INF_TYPE_EVENT, // 2021-7-27 增加,Event类型接口
  259. INF_TYPE_UNKNOWN
  260. };
  261. /// <summary>
  262. /// 值的传递方式
  263. /// </summary>
  264. enum class VALUE_PASS_MODE : short
  265. {
  266. PASS_BY_VALUE,
  267. PASS_BY_ADDRESS,
  268. PASS_BY_UNKNOWN
  269. };
  270. /// <summary>
  271. /// Tool的运行模式
  272. /// </summary>
  273. enum class TOOL_RUN_MODE : short
  274. {
  275. SINGLE_STEP, // 单步执行
  276. STANDALONE, // 独立运行(仅运行本工具)
  277. SEQUENTIAL, // 顺序执行(任务中,或者ExecuteAll执行)
  278. IN_PARALLEL, // 在并行工具中执行
  279. IN_FORLOOP // 在For工具中执行
  280. };
  281. /// <summary>
  282. /// Task的运行模式
  283. /// </summary>
  284. enum class TASK_RUN_MODE : short
  285. {
  286. RUN_LOOP, // 循环执行
  287. RUN_ONCE, // 单次执行
  288. RUN_STOP // 退出执行
  289. };
  290. // 更新值的工作模式
  291. enum class UPDATE_VALUE_MODE : short
  292. {
  293. MODE_FROM_TOOL, // 从Tool接口中更新
  294. MODE_FROM_VARIABLE, // 从变量中读取
  295. MODE_TO_VARIABLE // 写入到变量中
  296. };
  297. /// <summary>
  298. /// 2022-2-15增加,变量模式(局部变量统一为BASIC模式,全局变量分三种模式)
  299. /// </summary>
  300. enum class GVL_MODE : short
  301. {
  302. GVL_BASIC, // 基础模式(基础类型)
  303. GVL_STANDARD, // 标准模式(全类型)
  304. GVL_SYSTEM, // 系统类型(内置类型,不可编辑)
  305. GVL_DB, // 共享内存模式
  306. GVL_UNKNOWN // 无效的模式
  307. };
  308. /// <summary>
  309. /// 2022-2-15,各种变量分组类型在界面中显示的名称字符串
  310. /// </summary>
  311. const static QStringList gvlTypeString =
  312. {
  313. "基础类型",
  314. "标准类型",
  315. "系统变量",
  316. "DB类型"
  317. };
  318. /// <summary>
  319. /// Link连线的模式
  320. /// </summary>
  321. enum class LINK_MODE : short
  322. {
  323. LINK_NORMAL, // 正常功能块的连线模式(横向五段线)
  324. LINK_PARALLEL // 并行连线的模式(纵向二段线)
  325. };
  326. ///// <summary>
  327. ///// 2022-8-21,TOOL级别的接口定义,目前只有Start和End两种
  328. ///// </summary>
  329. //enum class TOOL_INTERFACE : short
  330. //{
  331. // INF_START,
  332. // INF_END,
  333. // TOOL_INTERFACE_COUNT
  334. //
  335. //};
  336. ////========================================================
  337. ////
  338. //// STRUCT
  339. ////
  340. ////========================================================
  341. /// <summary>
  342. /// Pou、Tool的运行参数
  343. /// </summary>
  344. typedef struct _tagExecutionParameters
  345. {
  346. int nExecTime; // 执行总时长(ms)
  347. int nExecCount; // 执行次数
  348. int nErrorCount; // 错误次数
  349. int nPreDelay; // 前延时(ms,仅Tool使用)
  350. int nPostDelay; // 后延时(ms)
  351. VPEnum::EXEC_STATUS nStatus; // 工具执行状态
  352. VPEnum::RETURN_VALUE nRetValue; // 工具的执行返回值(默认为未执行状态)
  353. _tagExecutionParameters()
  354. {
  355. this->reset();
  356. }
  357. void reset()
  358. {
  359. nExecTime = 0;
  360. nExecCount = 0;
  361. nErrorCount = 0;
  362. nPreDelay = 0;
  363. nPostDelay = 0;
  364. nRetValue = VPEnum::RETURN_VALUE::None;
  365. nStatus = VPEnum::EXEC_STATUS::StandBy;
  366. }
  367. // EXEC_PARAMS 序列化
  368. friend QDataStream& operator<<(QDataStream& out, const _tagExecutionParameters& ep);
  369. // EXEC_PARAMS 反序列化
  370. friend QDataStream& operator>>(QDataStream& in, _tagExecutionParameters& ep);
  371. } EXEC_PARAMS;
  372. /// <summary>
  373. /// Task 的运行参数
  374. /// </summary>
  375. typedef struct _tagTaskParameters : public EXEC_PARAMS
  376. {
  377. bool bWatchDog; // 是否启用看门狗(仅Task使用)
  378. int nWatchDog; // 看门狗的设置数值(ms, 仅Task使用)
  379. VPEnum::PRIORITY nPriority; // 优先级
  380. int nTriggerFailedCount; // 触发失败次数
  381. TASK_RUN_MODE runMode; // 运行模式
  382. _tagTaskParameters()
  383. {
  384. bWatchDog = true;
  385. nWatchDog = 200;
  386. nPriority = VPEnum::PRIORITY::NormalPriority;
  387. runMode = TASK_RUN_MODE::RUN_LOOP;
  388. nPostDelay = 200;
  389. nTriggerFailedCount = 0;
  390. }
  391. // TASK_PARAMS 序列化
  392. friend QDataStream& operator<<(QDataStream& out, const _tagTaskParameters& tp);
  393. // TASK_PARAMS 反序列化
  394. friend QDataStream& operator>>(QDataStream& in, _tagTaskParameters& tp);
  395. } TASK_PARAMS;
  396. //============================================================
  397. //
  398. // Value
  399. //
  400. //============================================================
  401. /// <summary>
  402. /// 接口的值信息
  403. /// </summary>
  404. class VALUE
  405. {
  406. public:
  407. VALUE();
  408. // 重载 =
  409. VALUE& operator =(const VALUE& v);
  410. // 重载 ==
  411. bool operator==(const VALUE& other) const;
  412. // 是否是基础类型(目前只支持5种)
  413. bool isBaseType() const;
  414. // 是否是基础的数值类型(int float double)
  415. bool isBaseValueType() const;
  416. // 值是否是nullptr
  417. bool isNullptr()
  418. {
  419. return (this->Ptr == nullptr);
  420. }
  421. // 直接设置Ptr值的地址
  422. void setValueByAddress(void** valuePtr)
  423. {
  424. this->Ptr = valuePtr;
  425. }
  426. // 根据传值或者传址设置不同的参数值
  427. template<class T>
  428. void setValue(T v, VALUE_PASS_MODE mode = VALUE_PASS_MODE::PASS_BY_VALUE)
  429. {
  430. if (mode == VALUE_PASS_MODE::PASS_BY_VALUE)
  431. {
  432. if (this->Ptr == nullptr)
  433. {
  434. T* newValue = new T;
  435. *newValue = v;
  436. this->Ptr = (void**)newValue;
  437. }
  438. else
  439. {
  440. *(T*)this->Ptr = v;
  441. }
  442. }
  443. // 按地址为全局变量赋值(将全局变量指向到指定的内存地址,暂未使用)
  444. // TODO: 此处代码是错误的,不能使用
  445. else if (mode == VALUE_PASS_MODE::PASS_BY_ADDRESS)
  446. {
  447. //if (this->value.Ptr == nullptr)
  448. //{
  449. this->Ptr = (void**)&v;
  450. //}
  451. //else
  452. //{
  453. // *this->value.Ptr = &v;
  454. //}
  455. }
  456. else
  457. {
  458. qWarning() << "[Value] [SetValue] Error: Invalid VALUE_PASS_MODE: " << (int)mode;
  459. }
  460. // this->value.strValueString = getValueByString();
  461. //T* newValue = new T;
  462. //*newValue = v;
  463. //this->value.Ptr = newValue;
  464. }
  465. // 设置数值(按类型字符串)
  466. void setValue(const QString& strValue);
  467. // 获取数值
  468. template<class T>
  469. T getValue()
  470. {
  471. return *((T*)this->Ptr);
  472. }
  473. // 2022-2-23 仅重置数值
  474. void resetValue();
  475. // 2022-3-25 清空Value
  476. void clear();
  477. // 转换至 QString 类型
  478. QString toString() const;
  479. // 转换至 int 类型
  480. int toInt() const;
  481. // 转换至 float 类型
  482. float toFloat() const;
  483. // 转换至 double 类型
  484. double toDouble() const;
  485. // 转换至 bool 类型
  486. bool toBool() const;
  487. // 序列化
  488. friend QDataStream& operator<<(QDataStream& out, const VALUE& v);
  489. // 反序列化
  490. friend QDataStream& operator>>(QDataStream& in, VALUE& v);
  491. public:
  492. VALUE_TYPE type; // 值类型
  493. VALUE_PASS_MODE passMode; // 值的传递方式
  494. void** Ptr; // 接口的值指针
  495. // QString strValueString; // 字符串形式的数值
  496. };
  497. //============================================================
  498. //
  499. // Interface
  500. //
  501. //============================================================
  502. /// <summary>
  503. /// // 用于存储工具库中的工具接口静态信息
  504. // (设计思路变更:让初始化加载的静态工具信息和加入POU执行的运行时工具信息分开)
  505. /// </summary>
  506. class STATIC_INTERFACE
  507. {
  508. public:
  509. STATIC_INTERFACE()
  510. {
  511. reset();
  512. }
  513. void reset()
  514. {
  515. strName.clear();
  516. Direction = INF_DIRECTION::INF_DIR_UNKNOWN;
  517. Discard = INF_DISCARD::INF_DEFAULT;
  518. Type = INF_TYPE::INF_TYPE_STANDARD;
  519. nIndex = -1;
  520. bEnable = true;
  521. bDynamic = false;
  522. bShowName = true;
  523. // eventTrigger = nullptr;
  524. value.clear();
  525. }
  526. public:
  527. QString strName; // 接口名称
  528. INF_TYPE Type; // 接口的类别
  529. INF_DIRECTION Direction; // 接口的输入输出类型
  530. INF_DISCARD Discard; // 该端口已经废弃的标志
  531. // (备注:指在dll已经删除的端口,但是为了向下兼容,旧版本依然会加载。功能上会用黑色的端口显示)
  532. VALUE value; // 接口的值信息
  533. // ToolEvent* eventTrigger; // 2022-9-19,为Event类型的接口保存触发事件
  534. int nIndex; // 接口的序号
  535. bool bEnable; // 是否启用此接口
  536. bool bDynamic; // 是否是动态接口
  537. bool bShowName; // 是否在界面中显示接口名称(Goto的输入接口,以及Start接口等,在界面中是不显示名称的)
  538. };
  539. using DLL_INF = class STATIC_INTERFACE;
  540. /// <summary>
  541. /// 用于存储接口的运行时信息
  542. // 2021-5-20调整,将TOOL和全局变量组整合到一起
  543. // 每一个变量数据就相当于是一个接口
  544. /// </summary>
  545. using GVL = class TOOL;
  546. class ToolEvent;
  547. class _INTERFACE : public STATIC_INTERFACE
  548. {
  549. public:
  550. // _INTERFACE();
  551. _INTERFACE(TOOL* pParent, INF_TYPE type = INF_TYPE::INF_TYPE_STANDARD);
  552. // 根据用户的输入构造一个变量
  553. // 2022-2-27,增加了DB变量需要的参数
  554. _INTERFACE(
  555. const QString& strGroup,
  556. bool bSerialized,
  557. const QString& strName,
  558. const QString& strType,
  559. const QString& strValue,
  560. const QString& strComment,
  561. int nIndex,
  562. bool bShow,
  563. bool bTrigger = false, // 2022-9-1 增加,是否支持触发
  564. const QString& strCommAddress = "",
  565. VPEnum::GVL_ACCESS_MODE mode = VPEnum::GVL_ACCESS_MODE::All
  566. );
  567. // 从基础接口信息中扩展运行时信息
  568. void basedFrom(const STATIC_INTERFACE& inf);
  569. //// 从Dll的接口中拷贝
  570. //void copyFrom(const DLL_INF& dllInf);
  571. // 是否和指定的接口方向相同
  572. bool isSameDirectionTo(const _INTERFACE* pInf) const;
  573. // 是否和指定的接口方向相反
  574. bool isRevDirectionTo(const _INTERFACE* pInf) const;
  575. // 是否是相同类型
  576. bool isSameTypeTo(const _INTERFACE* pInf, bool ignoreBaseType = false) const;
  577. // 2022-6-7,父工具是否是相同类型(用于检查Start接口之间的连接)
  578. bool isParentSameTypeTo(const _INTERFACE* pInf) const;
  579. // 是否是基础类型(目前只支持5种)
  580. bool isBaseType() const;
  581. // 是否是基础的数值类型(int float double)
  582. bool isBaseValueType() const;
  583. // 是否是输入接口(包括输入和双向两种)
  584. bool isDirInput() const;
  585. // 是否是输出接口(包括输出和双向两种)
  586. bool isDirOutput() const;
  587. // 本接口是否被Port绑定(Goto或者Port工具等等)
  588. bool isBinded() const;
  589. // 是否是Goto的ToolEnd接口
  590. bool isGotoToolEnd() const;
  591. // 是否是Parallel的ToolStart接口
  592. bool isParallelToolStart() const;
  593. // 是否是Parallel的ToolEnd接口
  594. bool isParallelToolEnd() const;
  595. // 是否是ForLoop的ToolEnd接口
  596. bool isForLoopToolEnd() const;
  597. // 是否是标准工具的ToolStart接口
  598. bool isStandardToolStart() const;
  599. // 是否是Tool类型的输入接口
  600. bool isToolStart() const;
  601. // 是否是Tool类型的输出接口
  602. bool isToolEnd() const;
  603. // 是否是ToolInterface(Start、End)
  604. bool isToolInterface() const;
  605. //// 20210520增加,按照Variable的方式初始化本接口
  606. //void setAsVariable(TOOL* pGroup, const QString& strGroup, const QString& strName);
  607. // 为接口中对应的dll数值赋值
  608. template<class T>
  609. void setValue(T v, VALUE_PASS_MODE mode)
  610. {
  611. this->value.setValue<T>(v, mode);
  612. //qDebug() << "[Interface][Value] Set " << this->strFullName
  613. // << " value to [" << Utility::getValueString(value.Ptr, value.Type) << "].";
  614. // this->value.strValueString = getValueByString();
  615. //T* newValue = new T;
  616. //*newValue = v;
  617. //this->value.Ptr = newValue;
  618. }
  619. // 为接口中对应的dll数值赋值
  620. template<class T>
  621. bool setValue(T v)
  622. {
  623. // dll变量
  624. if (this->value.Ptr == nullptr)
  625. {
  626. // 到dll中取值
  627. T& currentValue = (*(T*)this->pParentTool->pDllPtr->Interface(this->nIndex).value.Ptr);
  628. if (currentValue != v)
  629. {
  630. // 如果不相等就写入数值
  631. currentValue = v;
  632. return true;
  633. }
  634. }
  635. // 全局变量
  636. else
  637. {
  638. T& currentValue = (*(T*)this->value.Ptr);
  639. if (currentValue != v)
  640. {
  641. // 如果不相等就写入数值
  642. currentValue = v;
  643. return true;
  644. }
  645. }
  646. return false;
  647. }
  648. // 设置数值(按类型字符串,模板特化)
  649. void setValue(const QString& strValue);
  650. // 获取数值
  651. template<class T>
  652. T getValue()
  653. {
  654. return this->value.getValue<T>();
  655. }
  656. // 获取Dll中的Value指针(因为exe本身不保存dll工具的值)
  657. void** getValuePtr() const;
  658. // 是否Value是空值
  659. bool isValueNullptr()
  660. {
  661. return (this->value.Ptr == nullptr);
  662. }
  663. //// 2021-8-3增加,到dll中获取本接口的值(因为exe本身不保存dll工具的值)
  664. //void** getValuePtrFromDll();
  665. // 设置数值对应的字符串
  666. void setValueString(const QString& strValue);
  667. // 获取数值对应的字符串(For debug)
  668. QString getValueString() const;
  669. // 2022-3-23 获取真实的ParentTool(因为Port绑定的关系,接口的Parent需要转换一下)
  670. TOOL* realParent() const;
  671. // 获取本身的parent
  672. TOOL* parent() const;
  673. // 获取绑定接口的Parent(而非自身Parent)
  674. TOOL* bindedParent() const;
  675. // 设置Parent
  676. void setParent(TOOL* pParent);
  677. //// 序列化
  678. //friend QDataStream& operator<<(QDataStream& out, const _INTERFACE& inf);
  679. //// 反序列化
  680. //friend QDataStream& operator>>(QDataStream& in, _INTERFACE& inf);
  681. public:
  682. // TOOL* pOriginalTool; // 2021-6-13增加,接口原本的父工具(由于接口会被换绑到Port上,导致原本的父工具丢失)
  683. _INTERFACE* pUpLinkInterface; // 上联的Interface
  684. QVector<_INTERFACE*> pDownLinkInterfaces; // 下联的Interface(下联接口会有多个)
  685. _INTERFACE* pBindInterface; // 绑定的Interface(仅用于Port类型工具)
  686. QString strFullName; // 接口的全名(toolname.interfacename)
  687. QString strPropertyName; // 2022-1-18增加,变量在属性表中的属性名字(仅用于属性表)
  688. QString strNameWithType; // 2021-10-14增加,为了方便在界面中直接显示接口类型,加了一个以<type>为结尾的名字
  689. bool bWatch; // 是否启用变量监控,默认不启用,可在工具中配置默认状态
  690. QString strComment; // 2021-5-20增加,接口的注释信息(仅变量)
  691. bool bSerialized; // 2021-5-20增加,是否进行值序列化(仅变量)
  692. bool bShow; // 2022-2-15增加,是否显示数值(仅变量)
  693. int nRefCount; // 引用计数(接口/变量)
  694. bool bDataLink; // 2021-11-9,是否与Runtime做了数据链接
  695. QString valueString; // 2021-11-9,尝试性增加了本接口的数值字符串为了提高代码效率
  696. // 由于接口本身不应该存储任何数值(存储在dll中),所以此处有待考证
  697. bool bComplexLinkIndex; // 2021-12-14,是否被作为复杂控件的索引数值
  698. // (备注:当索引数值变动时,需要向Runtime推送当前索引所有数据的变动通知)
  699. VPEnum::GVL_ACCESS_MODE accessMode; // 2022-2-26,变量存取权限(仅DB模式全局变量会用到)
  700. QString strCommAddress; // 2022-2-26,通信地址(仅DB模式全局变量会用到)
  701. ToolEvent* eventTrigger; // 2022-9-1,增加变量数值的变动通知(因为增加了变量变动触发Task的动作)
  702. protected:
  703. // 2022-3-23,防止此指针的错误使用,设置为私有
  704. // 正确的用法应该是用 realParent() 获取真实的父工具(因为存在接口或者变量绑定到别的Tool中的情况)
  705. TOOL* pParentTool; // 从属的工具
  706. };
  707. // 增加一些同名名称
  708. using VARIABLE = class _INTERFACE;
  709. using EVENT = class _INTERFACE;
  710. using VARIABLES = QVector<_INTERFACE*>;
  711. //============================================================
  712. //
  713. // Tool
  714. //
  715. //============================================================
  716. ///////////////////////////////////////////////////////////
  717. // 工具基础信息
  718. class TOOL_BASE_INFO
  719. {
  720. public:
  721. TOOL_BASE_INFO();
  722. TOOL_BASE_INFO(
  723. TOOL_TYPE type,
  724. QString name,
  725. QString aliasName,
  726. QString instanceName,
  727. QString category,
  728. QString version,
  729. QString info,
  730. QString comment = ""
  731. );
  732. // 是否是Standard类型工具
  733. bool isStandardTool() const;
  734. // 是否是Port类型的工具
  735. bool isPortTool() const;
  736. // 是否是硬件类型的工具
  737. bool isHardwareTool() const;
  738. // 是否是Goto类型的工具
  739. bool isGotoTool() const;
  740. // 是否是Comment类型的工具
  741. bool isCommentTool() const;
  742. // 是否是Parallel并行工具
  743. bool isParallelTool() const;
  744. // 2022-8-21 是否是For循环工具
  745. bool isForloopTool() const;
  746. // 2022-9-2 是否是Wait工具
  747. bool isWaitTool() const;
  748. // 2022-8-21 是否是具备Tool接口的工具(例如标准工具、Parallel工具、For工具等等)
  749. bool isHaveToolInterfaces() const;
  750. // 2022-8-25 是否是具备索引序号的工具
  751. bool isIndexedTool() const;
  752. // 2022-3-8 是否是默认值变量组
  753. bool isDefaultValueGroup() const;
  754. //// 生成基础类型信息
  755. //TOOL_BASE_INFO baseInfo() const;
  756. // 重载 =
  757. TOOL_BASE_INFO& operator =(const TOOL_BASE_INFO& v);
  758. public:
  759. TOOL_TYPE Type; // 工具的类型
  760. QString strPouName; // 2021.7.4 增加,工具所属的Pou名字(Tool的分组,变量是所在的Gvl的名字)
  761. QString strName; // 工具名称
  762. QString strAliasName; // 曾用名或者别名
  763. QString strInstanceName; // 工具的实例名字
  764. QString strCategory; // 工具所在的集合
  765. QString strVersion; // 工具的版本
  766. QString strInfo; // 工具的Info
  767. QString strComment; // 工具的注释信息
  768. };
  769. ///////////////////////////////////////////////////////////
  770. // 用于存储工具库中的工具的静态信息
  771. class TOOL;
  772. class STATIC_TOOL : public TOOL_BASE_INFO
  773. {
  774. public:
  775. STATIC_TOOL()
  776. {
  777. Type = TOOL_TYPE::TOOL_TYPE_UNKNOWN;
  778. }
  779. // 2022-10-14,从TOOL中提取基础信息生成STATIC_TOOL(目前用于Undo体系中记录工具原始信息)
  780. STATIC_TOOL(const TOOL* tool);
  781. //// 2022-10-1,编写拷贝构造函数,完成工具原始信息的深度拷贝(目前用于Undo结构中)
  782. //STATIC_TOOL(const STATIC_TOOL& toolInfo);
  783. //// 2022-10-1,重载 = 运算符,完成工具原始信息的深度拷贝(目前用于Undo结构中)
  784. //STATIC_TOOL& operator = (const STATIC_TOOL& toolInfo);
  785. public:
  786. QString strDllPath; // 实现本工具的dll
  787. QVector<STATIC_INTERFACE> staticInterfaces; // 接口的静态信息
  788. };
  789. using ToolActivator = QWaitCondition;
  790. ///////////////////////////////////////////////////////////
  791. // 用于存储Tool的运行时信息
  792. class TOOL : public TOOL_BASE_INFO
  793. {
  794. public:
  795. // 为了GVL增加的构造函数(用于构造变量)
  796. TOOL(const QString& strName, TOOL_TYPE varType, GVL_MODE gvlMode);
  797. // 从工具箱中构造
  798. TOOL(const STATIC_TOOL* pTool);
  799. // 构造一个空的工具(用于反序列化写入)
  800. TOOL();
  801. //// 2022-10-1,编写拷贝构造函数,完成Tool的深度拷贝
  802. //TOOL(const TOOL& tool);
  803. // 从指定的静态Tool信息中扩展
  804. void basedFrom(const STATIC_TOOL* pTool);
  805. // 更新实例名字,并且通过实例名字更新接口的FullName
  806. void updateInstanceName(const QString& strInsName);
  807. // 根据名字获取指定接口
  808. _INTERFACE* getInterfaceByName(const QString& strInfName);
  809. // 动态增加接口
  810. void addInterface(_INTERFACE* newInf);
  811. // 根据名字动态删除接口
  812. bool delInterfaceByName(const QString& strName);
  813. // 检查是否已经存在此接口了(按名称)
  814. bool contains(const QString& strName);
  815. // 2022-3-2 根据全名获取指定接口
  816. _INTERFACE* getInterfaceByFullName(const QString& strInfFullName);
  817. // 2022-3-23 绑定一个Port接口(仅Port工具使用)
  818. void bindPortInterface(_INTERFACE* pSourceInf);
  819. // 获取本Port工具绑定的源接口(仅Port工具使用)
  820. _INTERFACE* bindedInterface();
  821. // 本Port工具是否绑定了接口(仅Port工具使用)
  822. bool isBinded() const;
  823. // 重置本Port工具状态(仅Port工具使用)
  824. void resetPort();
  825. // 设置本Port工具状态(仅Port工具使用)
  826. void setPortError();
  827. // 获取ToolStart接口绑定的上级工具
  828. TOOL* toolStartUpTool();
  829. // 2022-8-28 本工具是否加入了并行组
  830. bool isParallelSubTool();
  831. // 2022-8-28 本工具是否加入了For循环
  832. bool isForloopSubTool();
  833. int GetInterfaceSize();
  834. // 排序(用于在Pou中保持执行队列按index有序)
  835. static bool sort_by_index(const TOOL* t1, const TOOL* t2)
  836. {
  837. return t1->nIndex < t2->nIndex;
  838. }
  839. // 2022-9-5 工具等待触发执行
  840. VPEnum::RETURN_VALUE waitForExecution(unsigned long timeOut = ULONG_MAX);
  841. public:
  842. DllTool* pDllPtr; // 工具Dll运行的实例指针
  843. TOOL* parentTool; // 2022-4-18,本工具所属的工具组(目前只有并行工具组)
  844. QVector<_INTERFACE*> Interfaces; // Tool的标准接口
  845. //_INTERFACE* startInterface; // 2022-4-5增加,Tool级别的输入接口,2022-8-21,从Top重命名为Start
  846. // //(用于执行Goto跳转,及其他Tool直连的链接,仅标准工具使用)
  847. //_INTERFACE* endInterface; // 2022-8-21 增加,Tool界别的输出接口,用于执行与下级的Tool直接连接
  848. QVector<_INTERFACE*> ToolInterfaces; // 2022-8-21 改动,将Tool接口定义为了数组,方便扩展
  849. // 目前总共有两个Tool级别接口
  850. #define INF_START 0
  851. #define INF_END 1
  852. #define TOOL_INTERFACE_COUNT 2
  853. #define startInterface ToolInterfaces[INF_START]
  854. #define endInterface ToolInterfaces[INF_END]
  855. // _INTERFACE* pBindInterface; // Port绑定的源接口的指针(仅Port类型)
  856. #define Variables Interfaces // (仅变量类型使用)
  857. // 工具执行的相关参数
  858. bool bEnable; // 是否启用本工具
  859. int nIndex; // 工具的执行序号
  860. bool bEnableBreakPoint; // 启用断点
  861. EXEC_PARAMS execParams; // 执行参数
  862. GVL_MODE gvlMode; // 全局变量的模式(仅用于变量)
  863. // DllTool* pHdwDllPtr; // 2022-3-2,本DB数据绑定的硬件工具(仅用于DB模式变量)
  864. QString strHdwInstName; // 本DB数据绑定的硬件工具实例名称(仅用于DB模式变量)
  865. // bool bParallelized; // 2022-5-4,是否加入了并行组(2022-8-28去掉,改为运行时实时判定)
  866. // ToolEvent* eventTrigger; // 2022-9-3,Tool也加入了Event触发机制(用于给Wait工具使用)
  867. QMutex mutex; // Tool与Event对应的互斥量,用于等待事件触发
  868. ToolActivator activator; // 2022-9-3,TaskManager中用于触发Tool的事件(目前用于Wait工具)
  869. };
  870. // 变量组
  871. using GVLS = QMap<QString, GVL*>;
  872. ///////////////////////////////////////////////////////////
  873. //
  874. class PORT : public TOOL_BASE_INFO
  875. {
  876. public:
  877. PORT(const STATIC_TOOL* pTool);
  878. // 从指定的静态Tool信息中扩展
  879. void basedFrom(const STATIC_TOOL* pTool);
  880. public:
  881. QVector<_INTERFACE*> Interfaces; // 自带的接口(理论上Port有且仅有一个接口,输入/输出)
  882. _INTERFACE* pBindInterface; // Port绑定的源接口的指针
  883. };
  884. /// <summary>
  885. /// 用于存储工具库中的工具类别
  886. /// </summary>
  887. class TOOL_CATEGORY
  888. {
  889. public:
  890. TOOL_CATEGORY()
  891. {
  892. }
  893. public:
  894. QString strName; // 分类的名称
  895. QVector<STATIC_TOOL> staticTools; // 本分类下的所有工具的静态信息
  896. };
  897. //============================================================
  898. //
  899. // Task、Event
  900. //
  901. //============================================================
  902. /// <summary>
  903. /// ToolEvent中的执行方式
  904. /// </summary>
  905. enum class TOOL_EVENT_TYPE : short
  906. {
  907. TOOL_TRIGGER, // 触发执行某个工具
  908. TASK_TRIGGER, // 触发执行Task
  909. //TOOL_TRIGGER_BY_VALUE, // 按照等于某个值时触发工具
  910. //TASK_TRIGGER_BY_VALUE // 按照等于某个值时触发Task(暂未实现)
  911. };
  912. /// <summary>
  913. /// 工具中的事件接口类型
  914. /// </summary>
  915. class ToolEvent : public QEvent
  916. {
  917. public:
  918. ToolEvent() :
  919. // QEvent((QEvent::Type)QEvent::registerEventType(QEvent::User + genRandNumber(0, 60000)));
  920. // 此处似乎不需要随机生成ID,系统会从MaxUser开始自动往下分配
  921. QEvent((QEvent::Type)QEvent::registerEventType())
  922. {
  923. m_exType = TOOL_EVENT_TYPE::TASK_TRIGGER;
  924. }
  925. // QEvent((QEvent::Type)QEvent::registerEventType(QEvent::User + genRandNumber(0, 60000)));
  926. // 此处似乎不需要随机生成ID,系统会从MaxUser开始自动往下分配
  927. // 这个ID号是
  928. ToolEvent(const QString& strGroupName, const QString& strName, TOOL_EVENT_TYPE type) :
  929. QEvent((QEvent::Type)QEvent::registerEventType())
  930. {
  931. setName(strGroupName, strName);
  932. m_exType = type;
  933. }
  934. ~ToolEvent() {};
  935. // 设定Event的名字(Tool.Interface的全名以及GroupName)
  936. void setName(const QString& strGroupName, const QString& strName)
  937. {
  938. this->m_strGroupName = strGroupName;
  939. this->m_strEventName = strName;
  940. }
  941. // 设定Event的GroupName(默认都是 HARDWARE_GROUP_NAME,以防万一需要扩展,还是保存一下 )
  942. // 获取Event的名字
  943. QString name() const
  944. {
  945. return m_strEventName;
  946. }
  947. // 获取GroupName
  948. QString groupName() const
  949. {
  950. return m_strGroupName;
  951. }
  952. void setExType(TOOL_EVENT_TYPE type)
  953. {
  954. m_exType = type;
  955. }
  956. TOOL_EVENT_TYPE getExType() const
  957. {
  958. return m_exType;
  959. }
  960. // 2022-9-25 为了实现等于某个值的事件触发增加
  961. VALUE m_triggerValue;
  962. protected:
  963. QString m_strEventName;
  964. QString m_strGroupName;
  965. TOOL_EVENT_TYPE m_exType = TOOL_EVENT_TYPE::TASK_TRIGGER;
  966. public:
  967. // 事件携带的返回值
  968. VPEnum::RETURN_VALUE ret = VPEnum::RETURN_VALUE::Success;
  969. };
  970. // 设置别名
  971. using TaskActivator = QWaitCondition;
  972. using EVENT_ID = QEvent::Type;
  973. /// <summary>
  974. /// 用于UI、Runtime和Dll同步的消息
  975. /// </summary>
  976. enum class UI_SYNC_MSG : short
  977. {
  978. EDIT_TEXT_CHANGED,
  979. COMBO_SEL_CHANGED,
  980. LIST_SEL_CHANGED,
  981. CHECKBOX_CHANGED,
  982. RADIOBOX_CHANGED,
  983. VALUE_CHANGED,
  984. UNKNOWN_MSG
  985. };
  986. /// <summary>
  987. /// 控件到Runtime的同步事件(每次仅一个控件同步)
  988. /// </summary>
  989. #define CONTROL_EVENT_TYPEID QEvent::Type::User + 10
  990. class SyncControlEvent : public QEvent
  991. {
  992. public:
  993. SyncControlEvent() :
  994. QEvent(eventType())
  995. {
  996. }
  997. ~SyncControlEvent() {};
  998. static Type eventType()
  999. {
  1000. // 创建事件Type
  1001. if (m_EventType == QEvent::None)
  1002. {
  1003. m_EventType = (QEvent::Type)QEvent::registerEventType(CONTROL_EVENT_TYPEID);
  1004. }
  1005. return m_EventType;
  1006. }
  1007. // 待同步的控件句柄
  1008. QWidget* m_pSrcControl = nullptr;
  1009. // 待同步的控件事件类型
  1010. UI_SYNC_MSG m_SyncMsg = UI_SYNC_MSG::UNKNOWN_MSG;
  1011. private:
  1012. static Type m_EventType;
  1013. };
  1014. /// <summary>
  1015. /// 数值到Runtime的同步事件(WindowRuntime用)
  1016. /// 同时也作为动态接口到Pou的同步事件(UiManager用)
  1017. /// 同时也作为全局变量在表格中的变动通知(GvlManager用)
  1018. /// </summary>
  1019. #define VALUE_EVENT_TYPEID QEvent::Type::User + 11
  1020. class SyncValueEvent : public QEvent
  1021. {
  1022. public:
  1023. SyncValueEvent() :
  1024. QEvent(eventType())
  1025. {
  1026. }
  1027. ~SyncValueEvent() {};
  1028. static Type eventType()
  1029. {
  1030. // 创建事件Type
  1031. if (m_EventType == QEvent::None)
  1032. {
  1033. m_EventType = (QEvent::Type)QEvent::registerEventType(VALUE_EVENT_TYPEID);
  1034. }
  1035. return m_EventType;
  1036. }
  1037. // 待同步数据项
  1038. void addSyncValue(VARIABLE* val)
  1039. {
  1040. m_SyncValues.push_back(val);
  1041. }
  1042. QList<VARIABLE*> getSyncValues() const
  1043. {
  1044. return m_SyncValues;
  1045. }
  1046. void setSyncValues(const QList<VARIABLE*>& listInf)
  1047. {
  1048. m_SyncValues = listInf;
  1049. }
  1050. private:
  1051. static Type m_EventType;
  1052. // Value(一个或多个)
  1053. QList<VARIABLE*> m_SyncValues;
  1054. };
  1055. /// <summary>
  1056. /// 硬件数值接口到Runtime的同步事件
  1057. /// </summary>
  1058. #define HDVALUE_EVENT_TYPEID QEvent::Type::User + 12
  1059. class SyncHdValueEvent : public QEvent
  1060. {
  1061. public:
  1062. SyncHdValueEvent() :
  1063. QEvent(eventType())
  1064. {
  1065. }
  1066. ~SyncHdValueEvent() {};
  1067. // 设定Event的 GroupName
  1068. void setGroupName(const QString& strGroupName)
  1069. {
  1070. this->m_strGroupName = strGroupName;
  1071. }
  1072. // 获取GroupName
  1073. QString groupName() const
  1074. {
  1075. return m_strGroupName;
  1076. }
  1077. static Type eventType()
  1078. {
  1079. // 创建事件Type
  1080. if (m_EventType == QEvent::None)
  1081. {
  1082. m_EventType = (QEvent::Type)QEvent::registerEventType(HDVALUE_EVENT_TYPEID);
  1083. }
  1084. return m_EventType;
  1085. }
  1086. // 需要同步的硬件接口信息
  1087. // 第一种同步方式,按实例名和接口名同步
  1088. QString m_strInstanceName; // 实例名称
  1089. QString m_strInfName; // 接口名称
  1090. // 第二种同步方式:直接按数值指针同步
  1091. void* m_pSrcValue = nullptr; // 接口数值指针
  1092. protected:
  1093. QString m_strGroupName;
  1094. private:
  1095. static Type m_EventType;
  1096. };
  1097. /// <summary>
  1098. /// 动态接口到Pou的同步事件
  1099. /// </summary>
  1100. #define DLLINF_EVENT_TYPEID QEvent::Type::User + 13
  1101. class SyncInterfaceEvent : public QEvent
  1102. {
  1103. public:
  1104. SyncInterfaceEvent() :
  1105. QEvent(eventType())
  1106. {
  1107. }
  1108. ~SyncInterfaceEvent() {};
  1109. static Type eventType()
  1110. {
  1111. // 创建事件Type
  1112. if (m_EventType == QEvent::None)
  1113. {
  1114. m_EventType = (QEvent::Type)QEvent::registerEventType(DLLINF_EVENT_TYPEID);
  1115. }
  1116. return m_EventType;
  1117. }
  1118. // 待同步动态接口
  1119. void addSyncInterface(const DLL_INF val)
  1120. {
  1121. m_SyncDllInfs.push_back(val);
  1122. }
  1123. QList<DLL_INF> getSyncInterfaces() const
  1124. {
  1125. return m_SyncDllInfs;
  1126. }
  1127. void setSyncValues(const QList<DLL_INF> listInf)
  1128. {
  1129. m_SyncDllInfs = listInf;
  1130. }
  1131. // 待同步接口的工具实例名称
  1132. QString m_strInstanceName;
  1133. // true 是增加, false 是删除
  1134. bool m_bAdd = true;
  1135. // 执行结果
  1136. bool m_bSuccess = false;
  1137. // 原因(如果出错)
  1138. QString m_strReason;
  1139. private:
  1140. static Type m_EventType;
  1141. // Interface(一个或多个)
  1142. QList<DLL_INF> m_SyncDllInfs;
  1143. };
  1144. typedef struct _tagDisplay
  1145. {
  1146. public:
  1147. HObject ho_Obj;
  1148. QColor Color;
  1149. double fTransparency;
  1150. int nLinsWhite;
  1151. public:
  1152. _tagDisplay()
  1153. {
  1154. nLinsWhite = 0;
  1155. fTransparency = 0;
  1156. }
  1157. _tagDisplay(HObject obj, QColor color = qRgb(255, 0, 0), double fTransparency = 0.0, int nLinsWhite = 1)
  1158. {
  1159. this->ho_Obj = obj;
  1160. this->Color = color;
  1161. this->fTransparency = fTransparency;
  1162. this->nLinsWhite = nLinsWhite;
  1163. }
  1164. void setObject(HObject obj, QColor color = qRgb(255, 0, 0), double fTransparency = 0.0, int nLinsWhite = 1)
  1165. {
  1166. this->ho_Obj = obj;
  1167. this->Color = color;
  1168. this->fTransparency = fTransparency;
  1169. this->nLinsWhite = nLinsWhite;
  1170. }
  1171. void Clear()
  1172. {
  1173. this->ho_Obj.Clear();
  1174. this->Color = qRgb(255, 0, 0);
  1175. this->fTransparency = 0.0;
  1176. this->nLinsWhite = 1;
  1177. }
  1178. _tagDisplay& operator =(const _tagDisplay& disp)
  1179. {
  1180. if (this != &disp)
  1181. {
  1182. this->ho_Obj = disp.ho_Obj;
  1183. this->Color = disp.Color;
  1184. this->fTransparency = disp.fTransparency;
  1185. this->nLinsWhite = disp.nLinsWhite;
  1186. }
  1187. return *this;
  1188. }
  1189. } ST_Display;
  1190. typedef struct _tagMessage
  1191. {
  1192. public:
  1193. HTuple hv_Msg;
  1194. int nX;
  1195. int nY;
  1196. int nMsgSize;
  1197. QColor Color;
  1198. public:
  1199. _tagMessage()
  1200. {
  1201. Clear();
  1202. }
  1203. _tagMessage(HTuple hvMsg, QColor color = qRgb(255, 0, 0), int nX = 10, int nY = 10, int nMsgSize = 10)
  1204. {
  1205. this->hv_Msg = hvMsg;
  1206. this->Color = color;
  1207. this->nX = nX;
  1208. this->nY = nY;
  1209. this->nMsgSize = nMsgSize;
  1210. }
  1211. void setMsg(HTuple hvMsg, QColor color = qRgb(255, 0, 0), int nX = 10, int nY = 10, int nMsgSize = 10)
  1212. {
  1213. this->hv_Msg = hvMsg;
  1214. this->Color = color;
  1215. this->nX = nX;
  1216. this->nY = nY;
  1217. this->nMsgSize = nMsgSize;
  1218. }
  1219. void Clear()
  1220. {
  1221. hv_Msg.Clear();
  1222. this->Color = qRgb(255, 0, 0);
  1223. this->nX = 10;
  1224. this->nY = 10;
  1225. this->nMsgSize = 10;
  1226. }
  1227. _tagMessage& operator =(const _tagMessage& msg)
  1228. {
  1229. if (this != &msg)
  1230. {
  1231. this->hv_Msg = msg.hv_Msg;
  1232. this->Color = msg.Color;
  1233. this->nX = msg.nX;
  1234. this->nY = msg.nY;
  1235. this->nMsgSize = msg.nMsgSize;
  1236. }
  1237. return *this;
  1238. }
  1239. }ST_Message;
  1240. typedef struct _tagDebugLog
  1241. {
  1242. public:
  1243. QString strName;
  1244. QString strLog;
  1245. public:
  1246. _tagDebugLog()
  1247. {
  1248. Clear();
  1249. }
  1250. _tagDebugLog(QString strName, QString strLog)
  1251. {
  1252. this->strName = strName;
  1253. this->strLog = strLog;
  1254. }
  1255. void Clear()
  1256. {
  1257. this->strName = "";
  1258. this->strLog = "";
  1259. }
  1260. _tagDebugLog& operator =(const _tagDebugLog& log)
  1261. {
  1262. if (this != &log)
  1263. {
  1264. this->strName = log.strName;
  1265. this->strLog = log.strLog;
  1266. }
  1267. return *this;
  1268. }
  1269. }ST_DebugLog;
  1270. /// <summary>
  1271. /// 用于Debug输出的结构体
  1272. /// </summary>
  1273. typedef struct _tagDebugData
  1274. {
  1275. public:
  1276. _tagDebugData()
  1277. {
  1278. Clear();
  1279. }
  1280. void Clear()
  1281. {
  1282. listDisplay.clear();
  1283. listMessage.clear();
  1284. listDebugLog.clear();
  1285. }
  1286. void addImage(HImage img)
  1287. {
  1288. ho_Image = img;
  1289. }
  1290. void addObj(HObject obj, QColor color = qRgb(255, 0, 0), double fTransparency = 0.0, int nLinsWhite = 1)
  1291. {
  1292. ST_Display disp(obj, color, fTransparency, nLinsWhite);
  1293. listDisplay.push_back(disp);
  1294. }
  1295. void addMsg(HTuple hvMsg, QColor color = qRgb(255, 0, 0), int nX = 10, int nY = 10, int nMsgSize = 10)
  1296. {
  1297. ST_Message msg(hvMsg, color, nX, nY, nMsgSize);
  1298. listMessage.push_back(msg);
  1299. }
  1300. void addLog(QString strName = "NULL", QString strLog = "Log")
  1301. {
  1302. ST_DebugLog debuglog(strName, strLog);
  1303. listDebugLog.push_back(debuglog);
  1304. }
  1305. _tagDebugData& operator =(const _tagDebugData& data)
  1306. {
  1307. if (this != &data)
  1308. {
  1309. this->ho_Image = data.ho_Image;
  1310. this->listDisplay = data.listDisplay;
  1311. this->listMessage = data.listMessage;
  1312. this->listDebugLog = data.listDebugLog;
  1313. }
  1314. return *this;
  1315. }
  1316. HImage getImage()
  1317. {
  1318. return ho_Image;
  1319. }
  1320. ST_Display getDisplay(int index)
  1321. {
  1322. ST_Display disp;
  1323. if ((index >= 0) && (index < listDisplay.size()))
  1324. {
  1325. disp = listDisplay[index];
  1326. }
  1327. return disp;
  1328. }
  1329. ST_Message getMessage(int index)
  1330. {
  1331. ST_Message msg;
  1332. if ((index >= 0) && (index < listMessage.size()))
  1333. {
  1334. msg = listMessage[index];
  1335. }
  1336. return msg;
  1337. }
  1338. ST_DebugLog getDebugLog(int index)
  1339. {
  1340. ST_DebugLog log;
  1341. if ((index >= 0) && (index < listDebugLog.size()))
  1342. {
  1343. log = listDebugLog[index];
  1344. }
  1345. return log;
  1346. }
  1347. int getDisplaySize()
  1348. {
  1349. return listDisplay.size();
  1350. }
  1351. int getMessageSize()
  1352. {
  1353. return listMessage.size();
  1354. }
  1355. int getDebugLogSize()
  1356. {
  1357. return listDebugLog.size();
  1358. }
  1359. protected:
  1360. HImage ho_Image;
  1361. QList<ST_Display> listDisplay;
  1362. QList<ST_Message> listMessage;
  1363. QList<ST_DebugLog> listDebugLog;
  1364. } DebugData;
  1365. /// <summary>
  1366. /// 存储图片和窗口转储的数据结构
  1367. /// </summary>
  1368. typedef struct _tagSaveImg
  1369. {
  1370. HImage hoImage;
  1371. HImage hoDumpWindow;
  1372. QString strFileName;
  1373. QString strFilePath;
  1374. HTuple hvWindow;
  1375. // 0 == NULL , 1 == OK, 2 == NG
  1376. int nExecuteState;
  1377. bool bEnSaveImage;
  1378. bool bEnSaveDumpWindow;
  1379. bool bEnExecuteState;
  1380. int nSaveMode;
  1381. int nBufferSize;
  1382. int nFreeTime;
  1383. _tagSaveImg()
  1384. {
  1385. hoImage.Clear();
  1386. hoDumpWindow.Clear();
  1387. strFileName = "";
  1388. strFilePath = "";
  1389. nExecuteState = 0;
  1390. bEnSaveImage = false;
  1391. bEnSaveDumpWindow = false;
  1392. nSaveMode = 0;
  1393. nBufferSize = 100;
  1394. nFreeTime = 100;
  1395. }
  1396. }SAVE_IMG;
  1397. typedef struct _tagST_Pos
  1398. {
  1399. HTuple hv_Row;
  1400. HTuple hv_Column;
  1401. HTuple hv_Angle;
  1402. HTuple hv_HomMat2D;
  1403. _tagST_Pos()
  1404. {
  1405. Clear();
  1406. }
  1407. void Clear()
  1408. {
  1409. hv_Row.Clear();
  1410. hv_Column.Clear();
  1411. hv_Angle.Clear();
  1412. hv_HomMat2D.Clear();
  1413. }
  1414. } ST_POS;