DataStructure.cpp 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993
  1. 
  2. #include "DataStructure.h"
  3. #include "Utility.h"
  4. #include "DllToolCommon.h"
  5. ////========================================================
  6. ////
  7. //// VALUE
  8. ////
  9. ////========================================================
  10. VALUE::VALUE()
  11. {
  12. type = VALUE_TYPE::Type_Unknown;
  13. passMode = VALUE_PASS_MODE::PASS_BY_VALUE;
  14. Ptr = nullptr;
  15. }
  16. /// <summary>
  17. /// 重载 =
  18. /// </summary>
  19. /// <param name="v"></param>
  20. /// <returns></returns>
  21. VALUE& VALUE::operator = (const VALUE& v)
  22. {
  23. if (this != &v)
  24. {
  25. this->type = v.type;
  26. this->passMode = v.passMode;
  27. this->Ptr = v.Ptr;
  28. // this->strValueString = v.strValueString;
  29. }
  30. return *this;
  31. }
  32. /// <summary>
  33. /// 重载 ==
  34. /// </summary>
  35. /// <param name="other"></param>
  36. /// <returns></returns>
  37. bool VALUE::operator == (const VALUE& other) const
  38. {
  39. return (
  40. this->type == other.type
  41. && this->toString() == other.toString()
  42. );
  43. }
  44. /// <summary>
  45. /// 是否是基础数据类型(目前只支持5种)
  46. /// </summary>
  47. /// <returns></returns>
  48. bool VALUE::isBaseType() const
  49. {
  50. if (this->type == VALUE_TYPE::Type_Int
  51. || this->type == VALUE_TYPE::Type_String
  52. || this->type == VALUE_TYPE::Type_Bool
  53. || this->type == VALUE_TYPE::Type_Float
  54. || this->type == VALUE_TYPE::Type_Double
  55. // || this->Type == VALUE_TYPE::Type_CharP
  56. // || this->Type == VALUE_TYPE::Type_StdString
  57. )
  58. {
  59. return true;
  60. }
  61. return false;
  62. }
  63. /// <summary>
  64. /// 是否是基础的数值类型(int float double)
  65. /// </summary>
  66. /// <returns></returns>
  67. bool VALUE::isBaseValueType() const
  68. {
  69. if (this->type == VALUE_TYPE::Type_Int
  70. || this->type == VALUE_TYPE::Type_Float
  71. || this->type == VALUE_TYPE::Type_Double
  72. )
  73. {
  74. return true;
  75. }
  76. return false;
  77. }
  78. /// <summary>
  79. /// 设置数值(按类型字符串)
  80. /// </summary>
  81. /// <param name="strValue"></param>
  82. void VALUE::setValue(const QString& strValue)
  83. {
  84. // Value
  85. if (this->type == VALUE_TYPE::Type_Int)
  86. {
  87. this->setValue<int>(strValue.toInt());
  88. }
  89. else if (this->type == VALUE_TYPE::Type_String)
  90. {
  91. this->setValue<QString>(strValue);
  92. }
  93. else if (this->type == VALUE_TYPE::Type_Bool)
  94. {
  95. if (strValue == "true" || strValue == "1")
  96. {
  97. this->setValue<bool>(true);
  98. }
  99. else
  100. {
  101. this->setValue<bool>(false);
  102. }
  103. }
  104. else if (this->type == VALUE_TYPE::Type_Float)
  105. {
  106. this->setValue<float>(strValue.toFloat());
  107. }
  108. else if (this->type == VALUE_TYPE::Type_Double)
  109. {
  110. this->setValue<double>(strValue.toDouble());
  111. }
  112. else if (this->type == VALUE_TYPE::Type_String)
  113. {
  114. QString value;
  115. this->setValue<QString>(value);
  116. }
  117. else if (this->type == VALUE_TYPE::Type_StdString)
  118. {
  119. std::string value;
  120. this->setValue<std::string>(value);
  121. }
  122. else if (this->type == VALUE_TYPE::Type_QImage)
  123. {
  124. QImage value;
  125. this->setValue<QImage>(value);
  126. }
  127. else if (this->type == VALUE_TYPE::Type_Mat)
  128. {
  129. Mat value;
  130. this->setValue<Mat>(value);
  131. }
  132. else if (this->type == VALUE_TYPE::Type_HTuple)
  133. {
  134. HTuple value;
  135. this->setValue<HTuple>(value);
  136. }
  137. else if (this->type == VALUE_TYPE::Type_HObject)
  138. {
  139. HObject value;
  140. this->setValue<HObject>(value);
  141. }
  142. else if (this->type == VALUE_TYPE::Type_HImage)
  143. {
  144. HImage value;
  145. this->setValue<HImage>(value);
  146. }
  147. else if (this->type == VALUE_TYPE::Type_ST_Pos)
  148. {
  149. ST_POS value;
  150. this->setValue<ST_POS>(value);
  151. }
  152. else if (this->type == VALUE_TYPE::Type_ST_HomMat2D)
  153. {
  154. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_HomMat2D >";
  155. }
  156. else if (this->type == VALUE_TYPE::Type_ST_Point)
  157. {
  158. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Point >";
  159. }
  160. else if (this->type == VALUE_TYPE::Type_ST_Line)
  161. {
  162. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Line >";
  163. }
  164. else if (this->type == VALUE_TYPE::Type_ST_Circle)
  165. {
  166. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Circle >";
  167. }
  168. else if (this->type == VALUE_TYPE::Type_ST_Disp)
  169. {
  170. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Disp >";
  171. }
  172. else if (this->type == VALUE_TYPE::Type_ST_Window)
  173. {
  174. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Window >";
  175. }
  176. else if (this->type == VALUE_TYPE::Type_ST_Ncc_Modle)
  177. {
  178. qWarning() << "setValue Type not supported " << static_cast<short>(this->type);
  179. }
  180. else if (this->type == VALUE_TYPE::Type_ST_Shape_Modle)
  181. {
  182. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Shape_Modle >";
  183. }
  184. else if (this->type == VALUE_TYPE::Type_ST_Calibration)
  185. {
  186. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_Calibration >";
  187. }
  188. else if (this->type == VALUE_TYPE::Type_ST_CamParam_PoseCalib)
  189. {
  190. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_ST_CamParam_PoseCalib >";
  191. }
  192. else if (this->type == VALUE_TYPE::Type_pIBaseCamera)
  193. {
  194. IBaseCamera* value = nullptr;
  195. this->setValue<IBaseCamera* >(value);
  196. }
  197. else if (this->type == VALUE_TYPE::Type_pIpImage)
  198. {
  199. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pIpImage >";
  200. }
  201. else if (this->type == VALUE_TYPE::Type_pISocket)
  202. {
  203. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pISocket >";
  204. }
  205. else if (this->type == VALUE_TYPE::Type_pArrayIn)
  206. {
  207. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pArrayIn >";
  208. }
  209. else if (this->type == VALUE_TYPE::Type_pArrayOut)
  210. {
  211. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pArrayOut >";
  212. }
  213. else if (this->type == VALUE_TYPE::Type_pArrayRobotPos)
  214. {
  215. qWarning() << "setValue Type not supported < VALUE_TYPE::Type_pArrayRobotPos >";
  216. }
  217. else
  218. {
  219. qWarning() << "setValue Type not supported " << static_cast<short>(this->type);
  220. }
  221. // 继续补充其他类型
  222. }
  223. /// <summary>
  224. /// 2022-2-23 重置数值(根据不同类型分别处理)
  225. /// </summary>
  226. void VALUE::resetValue()
  227. {
  228. this->setValue("");
  229. }
  230. /// <summary>
  231. /// 2022-3-25 清空Value
  232. /// </summary>
  233. void VALUE::clear()
  234. {
  235. this->passMode = VALUE_PASS_MODE::PASS_BY_VALUE;
  236. this->type = VALUE_TYPE::Type_Unknown;
  237. this->Ptr = nullptr;
  238. }
  239. /// <summary>
  240. /// 转换至 QString 类型
  241. /// </summary>
  242. /// <returns></returns>
  243. QString VALUE::toString() const
  244. {
  245. QString strRet;
  246. if (this->type == VALUE_TYPE::Type_Int)
  247. {
  248. strRet = QString::number(*(int*)this->Ptr);
  249. }
  250. else if (this->type == VALUE_TYPE::Type_Float)
  251. {
  252. strRet = QString("%1").arg(*(float*)this->Ptr);
  253. }
  254. else if (this->type == VALUE_TYPE::Type_Double)
  255. {
  256. strRet = QString("%1").arg(*(double*)this->Ptr);
  257. }
  258. else if (this->type == VALUE_TYPE::Type_Bool)
  259. {
  260. // strRet = QString("%1").arg(*(bool*)this->Ptr);
  261. // 2022-9-25 修改了bool变量显示的值字符串
  262. if (*(bool*)this->Ptr == true)
  263. {
  264. strRet = "true";
  265. }
  266. else
  267. {
  268. strRet = "false";
  269. }
  270. }
  271. else if (this->type == VALUE_TYPE::Type_String)
  272. {
  273. return (*(QString*)this->Ptr);
  274. }
  275. return strRet;
  276. }
  277. /// <summary>
  278. /// 转换至 int 类型
  279. /// </summary>
  280. /// <returns></returns>
  281. int VALUE::toInt() const
  282. {
  283. int nRet = 0;
  284. if (this->type == VALUE_TYPE::Type_Int)
  285. {
  286. return (*(int*)this->Ptr);
  287. }
  288. else if (this->type == VALUE_TYPE::Type_Float)
  289. {
  290. nRet = static_cast<int>(*(float*)this->Ptr);
  291. }
  292. else if (this->type == VALUE_TYPE::Type_Double)
  293. {
  294. nRet = static_cast<int>(*(double*)this->Ptr);
  295. }
  296. else if (this->type == VALUE_TYPE::Type_Bool)
  297. {
  298. nRet = static_cast<int>(*(bool*)this->Ptr);
  299. }
  300. else if (this->type == VALUE_TYPE::Type_String)
  301. {
  302. nRet = (*(QString*)this->Ptr).toInt();
  303. }
  304. return nRet;
  305. }
  306. /// <summary>
  307. /// 转换至 float 类型
  308. /// </summary>
  309. /// <returns></returns>
  310. float VALUE::toFloat() const
  311. {
  312. float fRet = 0.0;
  313. if (this->type == VALUE_TYPE::Type_Int)
  314. {
  315. fRet = static_cast<float>(*(int*)this->Ptr);
  316. }
  317. else if (this->type == VALUE_TYPE::Type_Float)
  318. {
  319. return (*(float*)this->Ptr);
  320. }
  321. else if (this->type == VALUE_TYPE::Type_Double)
  322. {
  323. fRet = static_cast<float>(*(double*)this->Ptr);
  324. }
  325. else if (this->type == VALUE_TYPE::Type_Bool)
  326. {
  327. fRet = static_cast<float>(*(bool*)this->Ptr);
  328. }
  329. else if (this->type == VALUE_TYPE::Type_String)
  330. {
  331. fRet = (*(QString*)this->Ptr).toFloat();
  332. }
  333. return fRet;
  334. }
  335. /// <summary>
  336. /// 转换至 double 类型
  337. /// </summary>
  338. /// <returns></returns>
  339. double VALUE::toDouble() const
  340. {
  341. double dRet = 0.0;
  342. if (this->type == VALUE_TYPE::Type_Int)
  343. {
  344. dRet = static_cast<float>(*(int*)this->Ptr);
  345. }
  346. else if (this->type == VALUE_TYPE::Type_Float)
  347. {
  348. dRet = static_cast<double>(*(float*)this->Ptr);
  349. }
  350. else if (this->type == VALUE_TYPE::Type_Double)
  351. {
  352. return (*(double*)this->Ptr);
  353. }
  354. else if (this->type == VALUE_TYPE::Type_Bool)
  355. {
  356. dRet = static_cast<double>(*(bool*)this->Ptr);
  357. }
  358. else if (this->type == VALUE_TYPE::Type_String)
  359. {
  360. dRet = (*(QString*)this->Ptr).toDouble();
  361. }
  362. return dRet;
  363. }
  364. /// <summary>
  365. /// 转换至 bool 类型
  366. /// </summary>
  367. /// <returns></returns>
  368. bool VALUE::toBool() const
  369. {
  370. bool bRet = false;
  371. if (this->type == VALUE_TYPE::Type_Int)
  372. {
  373. bRet = static_cast<bool>(*(int*)this->Ptr);
  374. }
  375. else if (this->type == VALUE_TYPE::Type_Float)
  376. {
  377. bRet = static_cast<bool>(*(float*)this->Ptr);
  378. }
  379. else if (this->type == VALUE_TYPE::Type_Double)
  380. {
  381. bRet = static_cast<bool>(*(double*)this->Ptr);
  382. }
  383. else if (this->type == VALUE_TYPE::Type_Bool)
  384. {
  385. return (*(bool*)this->Ptr);
  386. }
  387. else if (this->type == VALUE_TYPE::Type_String)
  388. {
  389. QString strValue = (*(QString*)this->Ptr);
  390. if (strValue == "true" || strValue == "1")
  391. {
  392. bRet = true;
  393. }
  394. else
  395. {
  396. bRet = false;
  397. }
  398. }
  399. return bRet;
  400. }
  401. /// <summary>
  402. /// VALUE序列化
  403. /// </summary>
  404. /// <param name="out"></param>
  405. /// <param name="w"></param>
  406. /// <returns></returns>
  407. QDataStream& operator<<(QDataStream& out, const VALUE& v)
  408. {
  409. out << v.passMode;
  410. out << v.type;
  411. // 2022-9-27 加入了对Ptr为nullptr时的处理
  412. if (v.Ptr == nullptr)
  413. {
  414. out << 0;
  415. return out;
  416. }
  417. else
  418. {
  419. out << 1;
  420. }
  421. // 根据不同类型写入不同的值
  422. if (v.type == VALUE_TYPE::Type_Int)
  423. {
  424. out << *(int*)v.Ptr;
  425. }
  426. else if (v.type == VALUE_TYPE::Type_String)
  427. {
  428. out << *((QString*)v.Ptr);
  429. }
  430. else if (v.type == VALUE_TYPE::Type_Bool)
  431. {
  432. out << *(bool*)v.Ptr;
  433. }
  434. else if (v.type == VALUE_TYPE::Type_Float)
  435. {
  436. out << *(float*)v.Ptr;
  437. }
  438. else if (v.type == VALUE_TYPE::Type_Double)
  439. {
  440. out << *(double*)v.Ptr;
  441. }
  442. //else if (v.Type == VALUE_TYPE::Type_CharP)
  443. //{
  444. // out << QString(*(char*)v.Ptr);
  445. //}
  446. else
  447. {
  448. }
  449. return out;
  450. }
  451. /// <summary>
  452. /// VALUE反序列化
  453. /// </summary>
  454. /// <param name="in"></param>
  455. /// <param name="w"></param>
  456. /// <returns></returns>
  457. QDataStream& operator>>(QDataStream& in, VALUE& v)
  458. {
  459. in >> v.passMode;
  460. in >> v.type;
  461. // 2022-9-27,读取是否有值的标志
  462. int nValueExist = 0;
  463. in >> nValueExist;
  464. if (nValueExist == 0)
  465. {
  466. v.Ptr = nullptr;
  467. return in;
  468. }
  469. // 根据不同类型读入不同的值
  470. if (v.type == VALUE_TYPE::Type_Int)
  471. {
  472. int newValue = 0;
  473. in >> newValue;
  474. v.setValue<int>(newValue);
  475. }
  476. else if (v.type == VALUE_TYPE::Type_String)
  477. {
  478. QString newValue;
  479. in >> newValue;
  480. v.setValue<QString>(newValue);
  481. }
  482. else if (v.type == VALUE_TYPE::Type_Bool)
  483. {
  484. bool newValue;
  485. in >> newValue;
  486. v.setValue<bool>(newValue);
  487. }
  488. else if (v.type == VALUE_TYPE::Type_Float)
  489. {
  490. float newValue;
  491. in >> newValue;
  492. v.setValue<float>(newValue);
  493. }
  494. else if (v.type == VALUE_TYPE::Type_Double)
  495. {
  496. double newValue;
  497. in >> newValue;
  498. v.setValue<double>(newValue);
  499. }
  500. //else if (v.Type == VALUE_TYPE::Type_CharP)
  501. //{
  502. // out << QString(*(char*)v.Ptr);
  503. //}
  504. else
  505. {
  506. }
  507. return in;
  508. }
  509. //========================================================
  510. //
  511. // _INTERFACE
  512. //
  513. //========================================================
  514. _INTERFACE::_INTERFACE(TOOL* pParent, INF_TYPE type)
  515. {
  516. this->Type = type;
  517. pParentTool = pParent;
  518. // pOriginalTool = pParent;
  519. pUpLinkInterface = nullptr;
  520. pBindInterface = nullptr;
  521. bWatch = false;
  522. bSerialized = true;
  523. bDataLink = false;
  524. bComplexLinkIndex = false;
  525. accessMode = VPEnum::GVL_ACCESS_MODE::All;
  526. bShow = true;
  527. eventTrigger = nullptr;
  528. nRefCount = 0;
  529. // 如果本接口属于ToolStart接口,那么把数值类型也同时设置为 Tool 类型
  530. if (type == INF_TYPE::INF_TYPE_TOOL)
  531. {
  532. this->value.type = VALUE_TYPE::Type_Tool;
  533. this->bShowName = false; // ToolStart接口不显示名字
  534. //// TODO:如果以后要改成Tool之间直接连接的话,此处方向不能是输入了
  535. //this->Direction = INF_DIRECTION::INF_DIR_IN; // 输入接口
  536. }
  537. }
  538. /// <summary>
  539. /// 根据用户的输入构造一个变量(仅变量类型接口专用)
  540. /// </summary>
  541. /// <param name="bSerialized"></param>
  542. /// <param name="strName"></param>
  543. /// <param name="strType"></param>
  544. /// <param name="strValue"></param>
  545. /// <param name="strComment"></param>
  546. _INTERFACE::_INTERFACE(
  547. const QString& strGroup,
  548. bool bSerialized,
  549. const QString& strName,
  550. const QString& strType,
  551. const QString& strValue,
  552. const QString& strComment,
  553. int nIndex,
  554. bool bShow,
  555. bool bTrigger /* = false */,
  556. const QString& strCommAddress /* = "" */,
  557. VPEnum::GVL_ACCESS_MODE mode /* = GVL_ACCESS_MODE::All*/
  558. )
  559. {
  560. // this->setValue(strGroup, bSerialized, strName, strType, strValue, strComment);
  561. // 赋值Value属性
  562. this->value.type = Utility::getTypeByString(strType);
  563. this->value.setValue(strValue);
  564. this->value.passMode = VALUE_PASS_MODE::PASS_BY_ADDRESS;
  565. // 赋值接口属性
  566. this->bSerialized = bSerialized;
  567. this->bShow = bShow;
  568. this->strName = strName;
  569. this->strFullName = strGroup + "." + strName;
  570. this->strComment = strComment;
  571. this->strNameWithType = this->strName + " <" + Utility::getTypeString(this->value.type) + ">";
  572. // 所有的变量类型都是双向接口
  573. this->Direction = INF_DIRECTION::INF_DIR_BOTH;
  574. this->Type = INF_TYPE::INF_TYPE_VALUE;
  575. this->nIndex = nIndex;
  576. this->bEnable = true;
  577. pParentTool = nullptr;
  578. // pOriginalTool = nullptr;
  579. pUpLinkInterface = nullptr;
  580. pBindInterface = nullptr;
  581. bWatch = false;
  582. bDataLink = false;
  583. bComplexLinkIndex = false;
  584. nRefCount = 0;
  585. this->strCommAddress = strCommAddress;
  586. accessMode = mode;
  587. // 2022-9-1增加,如果支持变量触发,则创建一个触发事件
  588. if (bTrigger)
  589. {
  590. eventTrigger = new ToolEvent(strGroup, this->strName, TOOL_EVENT_TYPE::TASK_TRIGGER);
  591. }
  592. else
  593. {
  594. eventTrigger = nullptr;
  595. }
  596. }
  597. ///// <summary>
  598. ///// 构造一个空的接口
  599. ///// </summary>
  600. //_INTERFACE::_INTERFACE()
  601. //{
  602. // // 所有的变量类型都是双向接口
  603. // this->Direction = INF_DIRECTION::INF_DIR_BOTH;
  604. // this->Type = INF_TYPE::INF_TYPE_VALUE;
  605. // this->nIndex = 0;
  606. // this->bEnable = true;
  607. //
  608. // pParentTool = nullptr;
  609. // pOriginalTool = nullptr;
  610. // pUpLinkInterface = nullptr;
  611. //
  612. // bWatch = false;
  613. // bDataLink = false;
  614. // bComplexLinkIndex = false;
  615. // nRefCount = 0;
  616. //}
  617. /// <summary>
  618. /// 从基础接口信息中扩展运行时信息
  619. /// </summary>
  620. /// <param name="inf"></param>
  621. void _INTERFACE::basedFrom(const STATIC_INTERFACE& inf)
  622. {
  623. this->strName = inf.strName;
  624. this->Direction = inf.Direction;
  625. // 2022-6-10 复制接口的是否废弃的状态
  626. this->Discard = inf.Discard;
  627. this->Type = inf.Type;
  628. this->value = inf.value;
  629. this->nIndex = inf.nIndex;
  630. this->bEnable = inf.bEnable;
  631. this->strNameWithType = this->strName + " <" + Utility::getTypeString(this->value.type) + ">";
  632. // 2022-3-12 复制动态接口状态
  633. this->bDynamic = inf.bDynamic;
  634. // 2022-4-8 复制接口名字显示设置
  635. this->bShowName = inf.bShowName;
  636. //// 2022-9-19,如果是Event类型接口,要把eventTrigger复制进来
  637. //this->eventTrigger = (ToolEvent*)inf.value.Ptr;
  638. }
  639. ///// <summary>
  640. ///// 从Dll的接口中拷贝
  641. ///// </summary>
  642. ///// <param name="dllInf"></param>
  643. //void _INTERFACE::copyFrom(const DLL_INF& dllInf)
  644. //{
  645. // this->strName = dllInf.strName;
  646. // this->Direction = dllInf.Direction;
  647. // this->Type = dllInf.Type;
  648. // this->value = dllInf.value;
  649. // this->bEnable = dllInf.bEnable;
  650. // this->strNameWithType = this->strName + " <" + Utility::getTypeString(this->value.type) + ">";
  651. //}
  652. /// <summary>
  653. /// 是否和指定的接口方向相同
  654. /// </summary>
  655. /// <param name="pInf"></param>
  656. /// <returns></returns>
  657. bool _INTERFACE::isSameDirectionTo(const _INTERFACE* pInf) const
  658. {
  659. return this->Direction == pInf->Direction;
  660. }
  661. /// <summary>
  662. /// 是否和指定的接口方向相反
  663. /// </summary>
  664. /// <param name="pInf"></param>
  665. /// <returns></returns>
  666. bool _INTERFACE::isRevDirectionTo(const _INTERFACE* pInf) const
  667. {
  668. if (this->Direction == INF_DIRECTION::INF_DIR_IN
  669. && pInf->Direction == INF_DIRECTION::INF_DIR_OUT
  670. )
  671. {
  672. return true;
  673. }
  674. if (this->Direction == INF_DIRECTION::INF_DIR_OUT
  675. && pInf->Direction == INF_DIRECTION::INF_DIR_IN
  676. )
  677. {
  678. return true;
  679. }
  680. return false;
  681. }
  682. /// <summary>
  683. /// 是否是相同类型(2021-8-24修改,加入了基础数据类型判断)
  684. /// </summary>
  685. /// <param name="pInf"></param>
  686. /// <param name="ignoreBaseType">是否忽略基础类型(基础类型统一算作是相同类型)</param>
  687. /// <returns></returns>
  688. bool _INTERFACE::isSameTypeTo(const _INTERFACE* pInf, bool ignoreBaseType) const
  689. {
  690. // 2021-8-24 增加,基础类型算作是相同类型(为了进行接口的强制转换)
  691. if (ignoreBaseType
  692. && (this->value.isBaseType() && pInf->value.isBaseType())
  693. )
  694. {
  695. return true;
  696. }
  697. return (this->value.type == pInf->value.type);
  698. }
  699. /// <summary>
  700. /// 2022-6-7,父工具是否是相同类型(用于检查ToolInterface之间的连接)
  701. /// </summary>
  702. /// <param name="pInf"></param>
  703. /// <returns></returns>
  704. bool _INTERFACE::isParentSameTypeTo(const _INTERFACE* pInf) const
  705. {
  706. if (this->parent() == nullptr || pInf->parent() == nullptr)
  707. {
  708. return false;
  709. }
  710. return (this->parent()->Type == pInf->parent()->Type);
  711. }
  712. /// <summary>
  713. /// 是否是基础类型(目前只支持5种)
  714. /// </summary>
  715. /// <returns></returns>
  716. bool _INTERFACE::isBaseType() const
  717. {
  718. return this->value.isBaseType();
  719. }
  720. /// <summary>
  721. /// 是否是基础的数值类型(int float double)
  722. /// </summary>
  723. /// <returns></returns>
  724. bool _INTERFACE::isBaseValueType() const
  725. {
  726. return this->value.isBaseValueType();
  727. }
  728. /// <summary>
  729. /// 是否是输入接口(包括输入和双向两种)
  730. /// </summary>
  731. /// <returns></returns>
  732. bool _INTERFACE::isDirInput() const
  733. {
  734. return (
  735. this->Direction == INF_DIRECTION::INF_DIR_IN
  736. || this->Direction == INF_DIRECTION::INF_DIR_BOTH
  737. );
  738. }
  739. /// <summary>
  740. /// 是否是输出接口(包括输出和双向两种)
  741. /// </summary>
  742. /// <returns></returns>
  743. bool _INTERFACE::isDirOutput() const
  744. {
  745. return (
  746. this->Direction == INF_DIRECTION::INF_DIR_OUT
  747. || this->Direction == INF_DIRECTION::INF_DIR_BOTH
  748. );
  749. }
  750. /// <summary>
  751. /// 本接口是否被绑定(Goto或者Port工具等等)
  752. /// </summary>
  753. /// <returns></returns>
  754. bool _INTERFACE::isBinded() const
  755. {
  756. // return (this->pOriginalTool != this->pParentTool);
  757. return (this->pBindInterface != nullptr);
  758. }
  759. /// <summary>
  760. /// 是否是Goto的ToolEnd接口
  761. /// </summary>
  762. /// <returns></returns>
  763. bool _INTERFACE::isGotoToolEnd() const
  764. {
  765. return (
  766. this->pParentTool != nullptr
  767. && this->pParentTool->isGotoTool()
  768. && this->Direction == INF_DIRECTION::INF_DIR_OUT
  769. && this->Type == INF_TYPE::INF_TYPE_TOOL
  770. );
  771. }
  772. /// <summary>
  773. /// 是否是Parallel的ToolStart接口
  774. /// </summary>
  775. /// <returns></returns>
  776. bool _INTERFACE::isParallelToolStart() const
  777. {
  778. return (
  779. this->pParentTool != nullptr
  780. && this->pParentTool->isParallelTool()
  781. && this->Direction == INF_DIRECTION::INF_DIR_IN
  782. && this->Type == INF_TYPE::INF_TYPE_TOOL
  783. );
  784. }
  785. /// <summary>
  786. /// 是否是Parallel的ToolEnd接口
  787. /// </summary>
  788. /// <returns></returns>
  789. bool _INTERFACE::isParallelToolEnd() const
  790. {
  791. return (
  792. this->pParentTool != nullptr
  793. && this->pParentTool->isParallelTool()
  794. && this->Direction == INF_DIRECTION::INF_DIR_OUT
  795. && this->Type == INF_TYPE::INF_TYPE_TOOL
  796. );
  797. }
  798. /// <summary>
  799. /// 是否是ForLoop的ToolEnd接口
  800. /// </summary>
  801. /// <returns></returns>
  802. bool _INTERFACE::isForLoopToolEnd() const
  803. {
  804. return (
  805. this->pParentTool != nullptr
  806. && this->pParentTool->isForloopTool()
  807. && this->Direction == INF_DIRECTION::INF_DIR_OUT
  808. && this->Type == INF_TYPE::INF_TYPE_TOOL
  809. );
  810. }
  811. /// <summary>
  812. /// 是否是标注标准工具的ToolStart接口
  813. /// </summary>
  814. /// <returns></returns>
  815. bool _INTERFACE::isStandardToolStart() const
  816. {
  817. return (
  818. this->pParentTool != nullptr
  819. && this->pParentTool->Type == TOOL_TYPE::TOOL_TYPE_STANDARD
  820. && this->Direction == INF_DIRECTION::INF_DIR_IN
  821. && this->Type == INF_TYPE::INF_TYPE_TOOL
  822. );
  823. }
  824. /// <summary>
  825. /// 是否是Tool类型的输入接口(ToolStart)
  826. /// </summary>
  827. /// <returns></returns>
  828. bool _INTERFACE::isToolStart() const
  829. {
  830. return (
  831. this->Direction == INF_DIRECTION::INF_DIR_IN
  832. && this->Type == INF_TYPE::INF_TYPE_TOOL
  833. );
  834. }
  835. /// <summary>
  836. /// 是否是Tool类型的输出接口(ToolEnd)
  837. /// </summary>
  838. /// <returns></returns>
  839. bool _INTERFACE::isToolEnd() const
  840. {
  841. return (
  842. this->Direction == INF_DIRECTION::INF_DIR_OUT
  843. && this->Type == INF_TYPE::INF_TYPE_TOOL
  844. );
  845. }
  846. /// <summary>
  847. /// 是否是ToolInterface(Start、End)
  848. /// </summary>
  849. /// <returns></returns>
  850. bool _INTERFACE::isToolInterface() const
  851. {
  852. return (
  853. (this->Direction == INF_DIRECTION::INF_DIR_IN
  854. || this->Direction == INF_DIRECTION::INF_DIR_OUT
  855. ) && this->Type == INF_TYPE::INF_TYPE_TOOL
  856. );
  857. }
  858. /// <summary>
  859. /// 获取绑定接口的Parent(而非自身Parent)
  860. /// </summary>
  861. /// <returns></returns>
  862. TOOL* _INTERFACE::bindedParent() const
  863. {
  864. if (this->pBindInterface != nullptr)
  865. {
  866. return (this->pBindInterface->pParentTool);
  867. }
  868. return nullptr;
  869. }
  870. /// <summary>
  871. /// 设置Parent
  872. /// </summary>
  873. /// <param name="pParent"></param>
  874. void _INTERFACE::setParent(TOOL* pParent)
  875. {
  876. this->pParentTool = pParent;
  877. }
  878. /// <summary>
  879. /// 设置数值(按类型字符串,模板特化)
  880. /// </summary>
  881. /// <param name="strValue"></param>
  882. void _INTERFACE::setValue(const QString& strValue)
  883. {
  884. this->value.setValue(strValue);
  885. }
  886. /// <summary>
  887. /// 获取Dll中的Value指针(因为exe本身不保存dll工具的值、仅保存全局和局部变量的)
  888. /// </summary>
  889. /// <returns></returns>
  890. void** _INTERFACE::getValuePtr() const
  891. {
  892. // -- 如果是变量或者全局变量数值类型
  893. if (this->value.Ptr != nullptr)
  894. {
  895. return this->value.Ptr;
  896. }
  897. // -- 如果是dll中的数值类型
  898. if (pParentTool == nullptr || pParentTool->pDllPtr == nullptr || this->nIndex == -1)
  899. {
  900. return nullptr;
  901. }
  902. if (pParentTool->pDllPtr->GetInterfaceSize() <= this->nIndex)
  903. {
  904. return nullptr;
  905. }
  906. return pParentTool->pDllPtr->Interface(this->nIndex).value.Ptr;
  907. }
  908. /// <summary>
  909. /// 设置数值对应的字符串
  910. /// </summary>
  911. void _INTERFACE::setValueString(const QString& strValue)
  912. {
  913. this->valueString = strValue;
  914. }
  915. // 获取数值对应的字符串(For debug)
  916. QString _INTERFACE::getValueString() const
  917. {
  918. // 2022-8-24 增加,如果是Tool接口的话,直接返回Tool相关字符串
  919. if (this->Type == INF_TYPE::INF_TYPE_TOOL)
  920. {
  921. if (this->Direction == INF_DIRECTION::INF_DIR_IN)
  922. {
  923. return "Tool.Start";
  924. }
  925. else
  926. {
  927. return "Tool.End";
  928. }
  929. }
  930. // -- 如果是变量或者全局变量数值类型
  931. if (this->value.Ptr != nullptr)
  932. {
  933. return Utility::getValueString(this->value.Ptr, value.type);
  934. }
  935. // -- 如果是dll中的数值类型
  936. if (pParentTool == nullptr || pParentTool->pDllPtr == nullptr)
  937. {
  938. return "nullptr";
  939. }
  940. if (pParentTool->GetInterfaceSize() <= this->nIndex)
  941. {
  942. return "InterfaceSize Error";
  943. }
  944. if (pParentTool->pDllPtr->GetInterfaceSize() <= this->nIndex)
  945. {
  946. return "Dll InterfaceSize Error";
  947. }
  948. if (pParentTool->Interfaces[nIndex]->Discard != INF_DISCARD::INF_DEFAULT)
  949. {
  950. QString str;
  951. switch (pParentTool->Interfaces[nIndex]->Discard)
  952. {
  953. case INF_DISCARD::INF_MARK_DELETE:
  954. str = "Error Inf is Delete";
  955. break;
  956. case INF_DISCARD::INF_MARK_CHANGE:
  957. str = "Error Inf is Change";
  958. break;
  959. case INF_DISCARD::INF_MARK_DISCARD:
  960. str = "Error Inf is Discard";
  961. break;
  962. default:
  963. str = "Error";
  964. break;
  965. }
  966. return str;
  967. }
  968. if (pParentTool->Interfaces[nIndex]->strName == pParentTool->pDllPtr->Interface(this->nIndex).strName
  969. && pParentTool->Interfaces[nIndex]->value.type == pParentTool->pDllPtr->Interface(this->nIndex).value.type
  970. )
  971. {
  972. void** pDllValue = pParentTool->pDllPtr->Interface(this->nIndex).value.Ptr;
  973. if (*pDllValue != nullptr)
  974. {
  975. QString strValue = "";
  976. strValue = Utility::getValueString(pDllValue, value.type);
  977. return strValue;
  978. }
  979. else
  980. {
  981. return "nullptr";
  982. }
  983. }
  984. return "Interface Error";
  985. }
  986. /// <summary>
  987. /// 2022-3-23 获取真实的ParentTool(因为Port绑定的关系,接口的Parent需要转换一下)
  988. /// </summary>
  989. /// <returns></returns>
  990. TOOL* _INTERFACE::realParent() const
  991. {
  992. if (!this->isBinded())
  993. {
  994. return this->pParentTool;
  995. }
  996. else
  997. {
  998. return this->pBindInterface->pParentTool;
  999. }
  1000. }
  1001. /// <summary>
  1002. /// 获取本身的parent
  1003. /// </summary>
  1004. /// <returns></returns>
  1005. TOOL* _INTERFACE::parent() const
  1006. {
  1007. return this->pParentTool;
  1008. }
  1009. ////========================================================
  1010. ////
  1011. //// TOOL_BASE_INFO
  1012. ////
  1013. ////========================================================
  1014. TOOL_BASE_INFO::TOOL_BASE_INFO()
  1015. {
  1016. Type = TOOL_TYPE::TOOL_TYPE_UNKNOWN;
  1017. }
  1018. TOOL_BASE_INFO::TOOL_BASE_INFO(
  1019. TOOL_TYPE type,
  1020. QString name,
  1021. QString aliasName,
  1022. QString instanceName,
  1023. QString category,
  1024. QString version,
  1025. QString info,
  1026. QString comment
  1027. )
  1028. {
  1029. this->Type = type;
  1030. this->strName = name;
  1031. this->strAliasName = aliasName;
  1032. this->strInstanceName = instanceName;
  1033. this->strCategory = category;
  1034. this->strVersion = version;
  1035. this->strInfo = info;
  1036. this->strComment = comment;
  1037. }
  1038. /// <summary>
  1039. /// 是否是Standard类型工具
  1040. /// </summary>
  1041. /// <returns></returns>
  1042. bool TOOL_BASE_INFO::isStandardTool() const
  1043. {
  1044. return (this->Type == TOOL_TYPE::TOOL_TYPE_STANDARD);
  1045. }
  1046. /// <summary>
  1047. /// 是否是Port类型的工具
  1048. /// </summary>
  1049. /// <returns></returns>
  1050. bool TOOL_BASE_INFO::isPortTool() const
  1051. {
  1052. return (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
  1053. || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT
  1054. );
  1055. }
  1056. /// <summary>
  1057. /// 是否是硬件类型的工具
  1058. /// </summary>
  1059. /// <returns></returns>
  1060. bool TOOL_BASE_INFO::isHardwareTool() const
  1061. {
  1062. return (this->strPouName == GROUP_NAME_HARDWARE);
  1063. }
  1064. /// <summary>
  1065. /// 是否是Goto类型的工具
  1066. /// </summary>
  1067. /// <returns></returns>
  1068. bool TOOL_BASE_INFO::isGotoTool() const
  1069. {
  1070. return (this->Type == TOOL_TYPE::TOOL_TYPE_GOTO);
  1071. }
  1072. /// <summary>
  1073. /// 是否是Comment类型的工具
  1074. /// </summary>
  1075. /// <returns></returns>
  1076. bool TOOL_BASE_INFO::isCommentTool() const
  1077. {
  1078. return (this->Type == TOOL_TYPE::TOOL_TYPE_COMMENT);
  1079. }
  1080. /// <summary>
  1081. /// 是否是Parallel并行工具组
  1082. /// </summary>
  1083. /// <returns></returns>
  1084. bool TOOL_BASE_INFO::isParallelTool() const
  1085. {
  1086. return (this->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL);
  1087. }
  1088. /// <summary>
  1089. /// 是否是For循环工具
  1090. /// </summary>
  1091. /// <returns></returns>
  1092. bool TOOL_BASE_INFO::isForloopTool() const
  1093. {
  1094. return (this->Type == TOOL_TYPE::TOOL_TYPE_FORLOOP);
  1095. }
  1096. /// <summary>
  1097. /// 2022-9-2 是否是Wait工具
  1098. /// </summary>
  1099. /// <returns></returns>
  1100. bool TOOL_BASE_INFO::isWaitTool() const
  1101. {
  1102. return (this->Type == TOOL_TYPE::TOOL_TYPE_WAIT);
  1103. }
  1104. /// <summary>
  1105. /// 2022-8-21 是否是具备Tool接口的工具(例如标准工具、Parallel工具、For工具等等)
  1106. /// </summary>
  1107. /// <returns></returns>
  1108. bool TOOL_BASE_INFO::isHaveToolInterfaces() const
  1109. {
  1110. return (
  1111. this->Type == TOOL_TYPE::TOOL_TYPE_STANDARD
  1112. || this->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL
  1113. || this->Type == TOOL_TYPE::TOOL_TYPE_FORLOOP
  1114. || this->Type == TOOL_TYPE::TOOL_TYPE_WAIT
  1115. );
  1116. }
  1117. /// <summary>
  1118. /// 2022-8-25 是否是具备索引序号的工具
  1119. /// </summary>
  1120. /// <returns></returns>
  1121. bool TOOL_BASE_INFO::isIndexedTool() const
  1122. {
  1123. return (
  1124. this->Type == TOOL_TYPE::TOOL_TYPE_STANDARD
  1125. || this->Type == TOOL_TYPE::TOOL_TYPE_GOTO
  1126. || this->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL
  1127. || this->Type == TOOL_TYPE::TOOL_TYPE_FORLOOP
  1128. || this->Type == TOOL_TYPE::TOOL_TYPE_WAIT
  1129. );
  1130. }
  1131. /// <summary>
  1132. /// 2022-3-8 是否是默认值变量组
  1133. /// </summary>
  1134. /// <returns></returns>
  1135. bool TOOL_BASE_INFO::isDefaultValueGroup() const
  1136. {
  1137. return (this->strPouName == GROUP_NAME_DEFAULVALUE);
  1138. }
  1139. ///// <summary>
  1140. ///// 生成基础类型信息
  1141. ///// </summary>
  1142. ///// <returns></returns>
  1143. //TOOL_BASE_INFO TOOL_BASE_INFO::baseInfo() const
  1144. //{
  1145. // return TOOL_BASE_INFO(
  1146. // this->Type,
  1147. // this->strName,
  1148. // this->strAliasName,
  1149. // this->strInstanceName,
  1150. // this->strCategory,
  1151. // this->strVersion,
  1152. // this->strInfo
  1153. // );
  1154. //}
  1155. /// <summary>
  1156. /// 重载 =
  1157. /// </summary>
  1158. /// <param name="v"></param>
  1159. /// <returns></returns>
  1160. TOOL_BASE_INFO& TOOL_BASE_INFO::operator =(const TOOL_BASE_INFO& v)
  1161. {
  1162. if (this != &v)
  1163. {
  1164. this->Type = v.Type;
  1165. this->strName = v.strName;
  1166. this->strAliasName = v.strAliasName;
  1167. this->strInstanceName = v.strInstanceName;
  1168. this->strCategory = v.strCategory;
  1169. this->strVersion = v.strVersion;
  1170. this->strInfo = v.strInfo;
  1171. this->strPouName = v.strPouName;
  1172. this->strComment = v.strComment;
  1173. }
  1174. return *this;
  1175. }
  1176. ///// <summary>
  1177. ///// 2022-10-1,编写拷贝构造函数,完成工具原始信息的深度拷贝(目前用于Undo结构中)
  1178. ///// </summary>
  1179. ///// <param name="toolInfo"></param>
  1180. //STATIC_TOOL::STATIC_TOOL(const STATIC_TOOL& toolInfo)
  1181. //{
  1182. // vDebug() << "STATIC_TOOL copy constructor()";
  1183. //}
  1184. //
  1185. //
  1186. //
  1187. //STATIC_TOOL& STATIC_TOOL::operator=(const STATIC_TOOL& toolInfo)
  1188. //{
  1189. // vDebug() << "STATIC_TOOL::operator=";
  1190. //
  1191. // return *this;
  1192. //}
  1193. /// <summary>
  1194. /// 2022-10-14,从TOOL中提取基础信息生成STATIC_TOOL(目前用于Undo体系中记录工具原始信息)
  1195. /// </summary>
  1196. STATIC_TOOL::STATIC_TOOL(const TOOL* tool)
  1197. {
  1198. this->Type = tool->Type;
  1199. this->strName = tool->strName;
  1200. this->strAliasName = tool->strAliasName;
  1201. this->strInstanceName = tool->strInstanceName;
  1202. this->strCategory = tool->strCategory;
  1203. this->strVersion = tool->strVersion;
  1204. this->strInfo = tool->strInfo;
  1205. this->strPouName = tool->strPouName;
  1206. this->strComment = tool->strComment;
  1207. // 如果是标准工具,需要复制DllPath信息
  1208. if (tool->isStandardTool())
  1209. {
  1210. this->strDllPath = tool->pDllPtr->m_strFullPath;
  1211. }
  1212. // 复制接口信息
  1213. for (int i = 0; i < tool->Interfaces.size(); i++)
  1214. {
  1215. const _INTERFACE* toolInf = tool->Interfaces[i];
  1216. STATIC_INTERFACE newStaticInf;
  1217. newStaticInf.strName = toolInf->strName;
  1218. newStaticInf.Direction = toolInf->Direction;
  1219. newStaticInf.Discard = toolInf->Discard;
  1220. newStaticInf.Type = toolInf->Type;
  1221. newStaticInf.value.passMode = toolInf->value.passMode;
  1222. newStaticInf.value.type = toolInf->value.type;
  1223. newStaticInf.nIndex = toolInf->nIndex;
  1224. newStaticInf.bEnable = toolInf->bEnable;
  1225. newStaticInf.bDynamic = toolInf->bDynamic;
  1226. newStaticInf.bShowName = toolInf->bShowName;
  1227. this->staticInterfaces.push_back(newStaticInf);
  1228. }
  1229. }
  1230. ////========================================================
  1231. ////
  1232. //// TOOL
  1233. ////
  1234. ////========================================================
  1235. // 为了GVL增加的构造函数
  1236. TOOL::TOOL(const QString& strName, TOOL_TYPE varType, GVL_MODE gvlMode)
  1237. {
  1238. // 设置为变量类型
  1239. this->Type = varType;
  1240. this->strName = strName;
  1241. // 2021-8-24 增加,修正了port绑定了变量状态下序列化出现的错误
  1242. this->strPouName = strName;
  1243. // 2022-3-2 增加了 GVL的模式
  1244. this->gvlMode = gvlMode;
  1245. bEnable = true;
  1246. bEnableBreakPoint = false;
  1247. // bParallelized = false;
  1248. nIndex = 0;
  1249. parentTool = nullptr;
  1250. pDllPtr = nullptr;
  1251. // 如果是标准类型、Parallel类型、For类型的工具,则需要初始化Tool接口(但是这里是GVL的构造函数,应该不会执行到这里)
  1252. if (this->isHaveToolInterfaces())
  1253. {
  1254. //this->startInterface = new _INTERFACE(this, INF_TYPE::INF_TYPE_TOOLSTART);
  1255. //this->endInterface = new _INTERFACE(this, INF_TYPE::INF_TYPE_TOOLEND);
  1256. for (int i = 0; i < (int)TOOL_INTERFACE_COUNT; i++)
  1257. {
  1258. _INTERFACE* newInf = new _INTERFACE(this, INF_TYPE::INF_TYPE_TOOL);
  1259. this->ToolInterfaces.push_back(newInf);
  1260. }
  1261. this->ToolInterfaces[INF_START]->Direction = INF_DIRECTION::INF_DIR_IN;
  1262. this->ToolInterfaces[INF_END]->Direction = INF_DIRECTION::INF_DIR_OUT;
  1263. }
  1264. //else
  1265. //{
  1266. // this->startInterface = nullptr;
  1267. // this->endInterface = nullptr;
  1268. //}
  1269. }
  1270. TOOL::TOOL(const STATIC_TOOL* pTool)
  1271. {
  1272. this->basedFrom(pTool);
  1273. parentTool = nullptr;
  1274. pDllPtr = nullptr;
  1275. bEnable = true;
  1276. bEnableBreakPoint = false;
  1277. // bParallelized = false;
  1278. nIndex = 0;
  1279. gvlMode = GVL_MODE::GVL_BASIC;
  1280. // 如果是标准类型、Parallel类型、For类型的工具,则需要初始化Tool接口
  1281. if (this->isHaveToolInterfaces())
  1282. {
  1283. for (int i = 0; i < (int)TOOL_INTERFACE_COUNT; i++)
  1284. {
  1285. _INTERFACE* newInf = new _INTERFACE(this, INF_TYPE::INF_TYPE_TOOL);
  1286. this->ToolInterfaces.push_back(newInf);
  1287. }
  1288. this->ToolInterfaces[INF_START]->Direction = INF_DIRECTION::INF_DIR_IN;
  1289. this->ToolInterfaces[INF_END]->Direction = INF_DIRECTION::INF_DIR_OUT;
  1290. }
  1291. //else
  1292. //{
  1293. // this->startInterface = nullptr;
  1294. // this->endInterface = nullptr;
  1295. //}
  1296. }
  1297. /// <summary>
  1298. /// 构造一个空的工具(用于反序列化写入)
  1299. /// </summary>
  1300. TOOL::TOOL()
  1301. {
  1302. this->Type = TOOL_TYPE::TOOL_TYPE_STANDARD;
  1303. parentTool = nullptr;
  1304. pDllPtr = nullptr;
  1305. bEnable = true;
  1306. bEnableBreakPoint = false;
  1307. // bParallelized = false;
  1308. nIndex = 0;
  1309. gvlMode = GVL_MODE::GVL_BASIC;
  1310. //// 直接置空,用于反序列化后写入
  1311. //this->startInterface = nullptr;
  1312. //this->endInterface = nullptr;
  1313. }
  1314. ///// <summary>
  1315. ///// 2022-10-1,编写拷贝构造函数,完成Tool的深度拷贝
  1316. ///// </summary>
  1317. ///// <param name="tool"></param>
  1318. //TOOL::TOOL(const TOOL& tool)
  1319. //{
  1320. // vDebug() << "Tool copy constructor";
  1321. //}
  1322. /// <summary>
  1323. /// 从指定的静态Tool信息中扩展
  1324. /// </summary>
  1325. void TOOL::basedFrom(const STATIC_TOOL* pTool)
  1326. {
  1327. this->Type = pTool->Type;
  1328. this->strName = pTool->strName;
  1329. this->strAliasName = pTool->strAliasName;
  1330. //this->strInstanceName = pTool->strName;
  1331. this->strCategory = pTool->strCategory;
  1332. this->strVersion = pTool->strVersion;
  1333. // this->strDllPath = pTool->strDllPath;
  1334. this->strInfo = pTool->strInfo;
  1335. this->strComment = pTool->strComment;
  1336. for (const STATIC_INTERFACE& pStaticInf : pTool->staticInterfaces)
  1337. {
  1338. _INTERFACE* newInf = new _INTERFACE(this);
  1339. newInf->basedFrom(pStaticInf);
  1340. // newInf->strFullName = this->strInstanceName + "." + newInf->strName;
  1341. this->Interfaces.push_back(newInf);
  1342. }
  1343. }
  1344. /// <summary>
  1345. /// 更新实例名字
  1346. /// </summary>
  1347. void TOOL::updateInstanceName(const QString& strInsName)
  1348. {
  1349. if (this->strInstanceName.isEmpty())
  1350. {
  1351. this->strInstanceName = strInsName;
  1352. }
  1353. for (_INTERFACE* pInf : Interfaces)
  1354. {
  1355. pInf->strFullName = this->strInstanceName + "." + pInf->strName;
  1356. }
  1357. }
  1358. /// <summary>
  1359. /// 根据名字获取指定接口
  1360. /// </summary>
  1361. /// <param name="strInfName"></param>
  1362. /// <returns></returns>
  1363. _INTERFACE* TOOL::getInterfaceByName(const QString& strInfName)
  1364. {
  1365. for (_INTERFACE* pInf : this->Interfaces)
  1366. {
  1367. if (pInf->strName == strInfName)
  1368. {
  1369. return pInf;
  1370. }
  1371. }
  1372. return nullptr;
  1373. }
  1374. /// <summary>
  1375. /// 动态增加接口
  1376. /// </summary>
  1377. /// <param name="newInf"></param>
  1378. /// <returns></returns>
  1379. void TOOL::addInterface(_INTERFACE* newInf)
  1380. {
  1381. Interfaces.push_back(newInf);
  1382. }
  1383. /// <summary>
  1384. /// 根据名字动态删除接口
  1385. /// (因为接口一般动态接口都加在后面,所有从后往前找效率比较高)
  1386. /// </summary>
  1387. /// <param name="strName"></param>
  1388. /// <returns></returns>
  1389. bool TOOL::delInterfaceByName(const QString& strName)
  1390. {
  1391. QVector<_INTERFACE*>::iterator itr = Interfaces.begin();
  1392. for (; itr != Interfaces.end();)
  1393. {
  1394. if ((*itr)->strName == strName)
  1395. {
  1396. itr = Interfaces.erase(itr);
  1397. return true;
  1398. }
  1399. else
  1400. {
  1401. itr++;
  1402. }
  1403. }
  1404. return false;
  1405. }
  1406. /// <summary>
  1407. /// 检查是否已经存在此接口了(按名称)
  1408. /// </summary>
  1409. /// <param name="strName"></param>
  1410. /// <returns></returns>
  1411. bool TOOL::contains(const QString& strName)
  1412. {
  1413. for (_INTERFACE* pInf : this->Interfaces)
  1414. {
  1415. if (pInf->strName == strName)
  1416. {
  1417. return true;
  1418. }
  1419. }
  1420. return false;
  1421. }
  1422. /// <summary>
  1423. /// 2022-3-2 根据全名获取指定接口
  1424. /// </summary>
  1425. /// <param name="strInfFullName"></param>
  1426. /// <returns></returns>
  1427. _INTERFACE* TOOL::getInterfaceByFullName(const QString& strInfFullName)
  1428. {
  1429. for (_INTERFACE* pInf : this->Interfaces)
  1430. {
  1431. if (pInf->strFullName == strInfFullName)
  1432. {
  1433. return pInf;
  1434. }
  1435. }
  1436. return nullptr;
  1437. }
  1438. /// <summary>
  1439. /// 2022-3-23 绑定一个Port接口(仅Port工具使用)
  1440. /// </summary>
  1441. /// <param name="pSourceInf"></param>
  1442. void TOOL::bindPortInterface(_INTERFACE* pSourceInf)
  1443. {
  1444. this->Interfaces[0]->pBindInterface = pSourceInf;
  1445. }
  1446. /// <summary>
  1447. /// 2022-3-23 获取本Port工具绑定的源接口(仅Port工具使用)
  1448. /// </summary>
  1449. /// <returns></returns>
  1450. _INTERFACE* TOOL::bindedInterface()
  1451. {
  1452. if (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
  1453. || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT)
  1454. {
  1455. // Port工具目前只用到了0号接口
  1456. return this->Interfaces[0]->pBindInterface;
  1457. }
  1458. return nullptr;
  1459. }
  1460. /// <summary>
  1461. /// 本Port工具是否绑定了接口(仅Port工具使用)
  1462. /// </summary>
  1463. /// <returns></returns>
  1464. bool TOOL::isBinded() const
  1465. {
  1466. if (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
  1467. || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT)
  1468. {
  1469. return (this->Interfaces[0]->pBindInterface != nullptr);
  1470. }
  1471. return false;
  1472. }
  1473. /// <summary>
  1474. /// 重置本Port工具状态(仅Port工具使用)
  1475. /// </summary>
  1476. void TOOL::resetPort()
  1477. {
  1478. if (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
  1479. || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT)
  1480. {
  1481. _INTERFACE* inf = this->Interfaces[0];
  1482. inf->pBindInterface = nullptr;
  1483. inf->nRefCount = 0;
  1484. inf->strFullName.clear();
  1485. inf->strName.clear();
  1486. inf->Direction = INF_DIRECTION::INF_DIR_OUT;
  1487. inf->Type = INF_TYPE::INF_TYPE_UNKNOWN;
  1488. inf->value.clear();
  1489. }
  1490. }
  1491. /// <summary>
  1492. /// 设置本Port工具状态(仅Port工具使用)
  1493. /// </summary>
  1494. void TOOL::setPortError()
  1495. {
  1496. if (this->Type == TOOL_TYPE::TOOL_TYPE_PORT_INPUT
  1497. || this->Type == TOOL_TYPE::TOOL_TYPE_PORT_OUTPUT)
  1498. {
  1499. this->execParams.nRetValue = VPEnum::RETURN_VALUE::Error;
  1500. }
  1501. }
  1502. /// <summary>
  1503. /// 获取ToolStart接口绑定的上级工具
  1504. /// </summary>
  1505. /// <returns></returns>
  1506. TOOL* TOOL::toolStartUpTool()
  1507. {
  1508. // pStardardBlock->m_toolInfo->TopInterface->pUpLinkInterface->parent();
  1509. if (this->ToolInterfaces.size() <= 0
  1510. || this->ToolInterfaces[INF_START]->pUpLinkInterface == nullptr)
  1511. {
  1512. return nullptr;
  1513. }
  1514. return this->ToolInterfaces[INF_START]->pUpLinkInterface->parent();
  1515. }
  1516. /// <summary>
  1517. /// 2022-8-28 本工具是否加入了并行组(判定规则为ToolStart的上级工具是否为并行工具)
  1518. /// </summary>
  1519. /// <returns></returns>
  1520. bool TOOL::isParallelSubTool()
  1521. {
  1522. TOOL* pUpTool = this->toolStartUpTool();
  1523. if (pUpTool != nullptr && pUpTool->isParallelTool())
  1524. {
  1525. return true;
  1526. }
  1527. return false;
  1528. }
  1529. /// <summary>
  1530. /// 2022-8-28 本工具是否加入了For循环
  1531. /// </summary>
  1532. /// <returns></returns>
  1533. bool TOOL::isForloopSubTool()
  1534. {
  1535. TOOL* pUpTool = this->toolStartUpTool();
  1536. if (pUpTool != nullptr && pUpTool->isForloopTool())
  1537. {
  1538. return true;
  1539. }
  1540. return false;
  1541. }
  1542. /// <summary>
  1543. /// 获取接口的数量
  1544. /// </summary>
  1545. /// <returns></returns>
  1546. int TOOL::GetInterfaceSize()
  1547. {
  1548. return Interfaces.size();
  1549. }
  1550. /// <summary>
  1551. /// 2022-9-5 工具等待触发执行
  1552. /// </summary>
  1553. /// <returns></returns>
  1554. VPEnum::RETURN_VALUE TOOL::waitForExecution(unsigned long timeOut /* = ULONG_MAX */)
  1555. {
  1556. this->mutex.lock();
  1557. if (this->activator.wait(&this->mutex, timeOut) == false)
  1558. {
  1559. this->mutex.unlock();
  1560. return VPEnum::RETURN_VALUE::Error;
  1561. }
  1562. this->mutex.unlock();
  1563. return VPEnum::RETURN_VALUE::Success;
  1564. }
  1565. ///// <summary>
  1566. ///// 2022-4-30 本工具是否并行化(加入了并行组)
  1567. ///// </summary>
  1568. ///// <returns></returns>
  1569. //bool TOOL::isParallelized()
  1570. //{
  1571. // // 2022-5-4 注释,此处的判断虽然正确,但是无法用于反序列化的场景,所以暂时不用了
  1572. // //return (
  1573. // // this->TopInterface != nullptr
  1574. // // && this->TopInterface->pUpLinkInterface != nullptr
  1575. // // && this->TopInterface->pUpLinkInterface->parent()->Type == TOOL_TYPE::TOOL_TYPE_PARALLEL
  1576. // // );
  1577. //}
  1578. ///// <summary>
  1579. ///// 2022-4-27 ToolStart接口是否已连接
  1580. ///// </summary>
  1581. ///// <returns></returns>
  1582. //bool TOOL::isTopLinked() const
  1583. //{
  1584. // return (
  1585. // this->TopInterface != nullptr
  1586. // && this->TopInterface->pUpLinkInterface != nullptr
  1587. // );
  1588. //}
  1589. ///// <summary>
  1590. ///// TOOL序列化
  1591. ///// </summary>
  1592. ///// <param name="out"></param>
  1593. ///// <param name="w"></param>
  1594. ///// <returns></returns>
  1595. //QDataStream& operator<<(QDataStream& out, const TOOL& tool)
  1596. //{
  1597. //
  1598. // int nParanum = 11;//参数数量
  1599. // out << nParanum;//先保存参数数量
  1600. //
  1601. // out << (int)1 << tool.Type;
  1602. // out << (int)2 << tool.strPouName;
  1603. // out << (int)3 << tool.strName;
  1604. // out << (int)4 << tool.strAliasName;
  1605. // out << (int)5 << tool.strInstanceName;
  1606. // out << (int)6 << tool.strInfo;
  1607. // out << (int)7 << tool.strVersion;
  1608. // out << (int)8 << tool.bEnable;
  1609. // out << (int)9 << tool.nIndex;
  1610. // out << (int)10 << tool.strComment;
  1611. // out << (int)11 << tool.bParallelized;
  1612. //
  1613. // // 写入接口数量
  1614. // out << tool.Interfaces.size();
  1615. // // 继续遍历接口
  1616. // for (_INTERFACE* pInf : tool.Interfaces)
  1617. // {
  1618. // out << *pInf;
  1619. // }
  1620. //
  1621. // // 如果是具备ToolStart接口的,还需要额外保存一下ToolStart接口信息
  1622. // if (tool.TopInterface != nullptr)
  1623. // {
  1624. // out << *tool.TopInterface;
  1625. // }
  1626. //
  1627. // return out;
  1628. //}
  1629. ///// <summary>
  1630. ///// TOOL反序列化(暂未使用)
  1631. ///// </summary>
  1632. ///// <param name="in"></param>
  1633. ///// <param name="w"></param>
  1634. ///// <returns></returns>
  1635. //QDataStream& operator>>(QDataStream& in, TOOL& tool)
  1636. //{
  1637. // Q_UNUSED(tool);
  1638. //
  1639. // return in;
  1640. //}
  1641. ////========================================================
  1642. ////
  1643. //// PORT
  1644. ////
  1645. ////========================================================
  1646. PORT::PORT(const STATIC_TOOL* pTool)
  1647. {
  1648. pBindInterface = nullptr;
  1649. // Interface = nullptr;
  1650. this->basedFrom(pTool);
  1651. }
  1652. /// <summary>
  1653. /// 从指定的静态Tool信息中扩展
  1654. /// </summary>
  1655. /// <param name="pTool"></param>
  1656. void PORT::basedFrom(const STATIC_TOOL* pTool)
  1657. {
  1658. this->Type = pTool->Type;
  1659. this->strName = pTool->strName;
  1660. this->strAliasName = pTool->strAliasName;
  1661. this->strInfo = pTool->strInfo;
  1662. this->strVersion = pTool->strVersion;
  1663. _INTERFACE* newInf = new _INTERFACE((TOOL*)this);
  1664. newInf->basedFrom(pTool->staticInterfaces[0]);
  1665. newInf->strFullName = this->strName + "." + newInf->strName;
  1666. Interfaces.push_back(newInf);
  1667. }
  1668. //============================================================
  1669. //
  1670. // Other
  1671. //
  1672. //============================================================
  1673. QEvent::Type SyncControlEvent::m_EventType = QEvent::None;
  1674. QEvent::Type SyncValueEvent::m_EventType = QEvent::None;
  1675. QEvent::Type SyncHdValueEvent::m_EventType = QEvent::None;
  1676. QEvent::Type SyncInterfaceEvent::m_EventType = QEvent::None;