pch.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. // pch.cpp: 与预编译标头对应的源文件
  2. #include "pch.h"
  3. #include "resource.h" // 主符号
  4. // 当使用预编译的头时,需要使用此源文件,编译才能成功。
  5. //主窗口句柄
  6. HWND gal_hTopWnd = nullptr;
  7. //输出日志:可供下层模块调用(下发至各个窗口)
  8. Log4CPP::Logger* mLog::gLogger = nullptr;
  9. //输出日志:可供下层模块调用
  10. logFun gal_pLogFun = nullptr;
  11. void ToolsDlgLog(CString strlog)
  12. {
  13. if (gal_pLogFun != nullptr)
  14. {
  15. gal_pLogFun(strlog);
  16. }
  17. }
  18. //输出消息:可供下层模块调用
  19. msgFun gal_pMSGFun = nullptr;
  20. void ToolsDlgMSG(CString strKey, CString strText)
  21. {
  22. if (gal_pMSGFun != nullptr)
  23. {
  24. gal_pMSGFun(strKey, strText);
  25. }
  26. }
  27. //全局设备集合对象
  28. CDeviceSET CDeviceSET::glo_CDeviceSET;
  29. _DeviceMape CDeviceSET::m_CDeviceMap;
  30. //********************************公共方法定义********************************
  31. //获取进程路径
  32. string GetProcessDirectory(bool withPlatformModule)
  33. {
  34. string ret = "";
  35. char szFilename[MAX_PATH] = { 0 };
  36. DWORD res = GetModuleFileNameA(0, szFilename, MAX_PATH);
  37. if (res == 0)
  38. {
  39. return ret;
  40. }
  41. string fullpath = szFilename;
  42. if (withPlatformModule)
  43. {
  44. string::size_type firstHit = fullpath.find_last_of('\\');
  45. if (firstHit != string::npos && firstHit != 0)
  46. {
  47. ret = fullpath.substr(0, firstHit);//kick last
  48. }
  49. }
  50. else
  51. {
  52. string V3_1_Key("\\");
  53. V3_1_Key += UnitTool_PlatformModule;
  54. string::size_type firstHit = fullpath.find(V3_1_Key);
  55. if (firstHit != string::npos)
  56. {
  57. ret = fullpath.substr(0, firstHit);
  58. }
  59. else
  60. {
  61. firstHit = fullpath.find_last_of('\\');
  62. if (firstHit != string::npos && firstHit != 0)
  63. {
  64. ret = fullpath.substr(0, firstHit);//kick last
  65. }
  66. }
  67. }
  68. //mLog::Info("get device ProcessDirectory:{$}\n", ret.c_str());
  69. return ret;
  70. }
  71. //获取模块版本
  72. bool GetVersion(string& version)
  73. {
  74. try {
  75. char filename[MAX_PATH + 1] = { 0 };
  76. if (GetModuleFileName(nullptr, filename, MAX_PATH) == 0)
  77. {
  78. return false;
  79. }
  80. printf("get Generator path:%s\n", filename);
  81. mLog::Info("get device path:{$}\n", filename);
  82. DWORD dummy;
  83. DWORD size = GetFileVersionInfoSize(filename, &dummy);
  84. if (size == 0)
  85. {
  86. return false;
  87. }
  88. auto data = make_unique<BYTE[]>(size);
  89. if (!GetFileVersionInfo(filename, 0, size, &data[0]))
  90. {
  91. return false;
  92. }
  93. UINT32 len = 0;
  94. VS_FIXEDFILEINFO* fixed_file_info = 0;
  95. if (!VerQueryValue(&data[0], TEXT("\\"), reinterpret_cast<void**>(&fixed_file_info), &len))
  96. {
  97. return false;
  98. }
  99. // version 为版本号
  100. UINT32 vBitNumber = 0;
  101. vBitNumber = HIWORD(fixed_file_info->dwProductVersionMS);
  102. version += to_string(vBitNumber);
  103. version += ".";
  104. vBitNumber = LOWORD(fixed_file_info->dwProductVersionMS);
  105. version += to_string(vBitNumber);
  106. version += ".";
  107. vBitNumber = HIWORD(fixed_file_info->dwProductVersionLS);
  108. version += to_string(vBitNumber);
  109. version += ".";
  110. vBitNumber = LOWORD(fixed_file_info->dwProductVersionLS);
  111. version += to_string(vBitNumber);
  112. return true;
  113. }
  114. catch (...)
  115. {
  116. printf("get Generator Mould version failed");
  117. mLog::Error("get device Mould version failed");
  118. }
  119. return false;
  120. }
  121. //获取时间
  122. CString GetTimeStr()
  123. {
  124. CTime tm = CTime::GetCurrentTime();
  125. SYSTEMTIME st;
  126. GetSystemTime(&st);
  127. CString strTime;
  128. strTime.Format("[%02d:%02d:%02d,%03d]", tm.GetHour(), tm.GetMinute(), tm.GetSecond(), st.wMilliseconds);
  129. return strTime;
  130. }
  131. //读取文件夹下的所有文件路径
  132. void GetAllCFGFiles(string path, vector<string>& files)
  133. {
  134. CFileFind find;
  135. BOOL IsFind = find.FindFile(CString(path.c_str()) + _T("/*.xml"));
  136. while (IsFind)
  137. {
  138. IsFind = find.FindNextFile();
  139. if (find.IsDots())
  140. {
  141. continue;
  142. }
  143. else
  144. {
  145. files.push_back(string(find.GetFileName()));
  146. }
  147. }
  148. IsFind = find.FindFile(CString(path.c_str()) + _T("/*.json"));
  149. while (IsFind)
  150. {
  151. IsFind = find.FindNextFile();
  152. if (find.IsDots())
  153. {
  154. continue;
  155. }
  156. else
  157. {
  158. files.push_back(string(find.GetFileName()));
  159. }
  160. }
  161. }
  162. void GetAllLibrary(string path, vector<string>& dlls, string nameKey)
  163. {
  164. CFileFind find;
  165. BOOL IsFind = find.FindFile(CString(path.c_str()) + _T("/*.dll"));
  166. while (IsFind)
  167. {
  168. IsFind = find.FindNextFile();
  169. if (find.IsDots())
  170. {
  171. continue;
  172. }
  173. else
  174. {
  175. string itemName = find.GetFileName();
  176. if(!nameKey.empty() && itemName.find(nameKey) != string::npos)
  177. dlls.push_back(itemName);
  178. }
  179. }
  180. }
  181. //设置、删除临时环境变量
  182. bool AddEnvPath(const char* pPath)
  183. {
  184. DWORD PathLen = 32768;
  185. char* pszPath = new char[PathLen];
  186. DWORD Len = GetEnvironmentVariable("Path", pszPath, PathLen);
  187. if (Len > PathLen)
  188. {
  189. mLog::Error("AddEnvPath:EnvironmentVariable too long[{$}]", (int)Len);
  190. delete[]pszPath;
  191. return false;
  192. }
  193. string::size_type pos = 0;
  194. string EnvPath = pszPath;
  195. delete[]pszPath;
  196. //EnvPath.find(pPath, 0);
  197. string NewPath;
  198. if ((pos = EnvPath.find(pPath, pos)) == string::npos)
  199. {
  200. NewPath = EnvPath;
  201. NewPath += ";";
  202. NewPath += pPath;
  203. if (SetEnvironmentVariable("Path", NewPath.c_str()) == FALSE)
  204. {
  205. mLog::Error("AddEnvPath:SetEnvironmentVariable failed");
  206. return false;
  207. }
  208. }
  209. mLog::Debug("AddEnvPath:SetEnvironmentVariable[{$}]successed", NewPath.c_str());
  210. return true;
  211. }
  212. bool DelEnvPath(const char* pPath)
  213. {
  214. DWORD PathLen = 32768;
  215. char* pszPath = new char[PathLen];
  216. DWORD Len = GetEnvironmentVariable("Path", pszPath, PathLen);
  217. if (Len > PathLen)
  218. {
  219. delete[]pszPath;
  220. return false;
  221. }
  222. string::size_type pos = 0;
  223. string EnvPath = pszPath;
  224. delete[]pszPath;
  225. //EnvPath.find(pPath, 0);
  226. if ((pos = EnvPath.find(pPath, pos)) > 0)
  227. {
  228. string NewPath = EnvPath;
  229. //NewPath += ";";
  230. //NewPath += pPath;
  231. NewPath.erase(pos, pos + strlen(pPath) + 1);
  232. if (SetEnvironmentVariable("Path", NewPath.c_str()) == FALSE)
  233. {
  234. return false;
  235. }
  236. }
  237. return true;
  238. }
  239. //********************************指令查找表********************************
  240. tFrameMapItem::tFrameMapItem()
  241. {
  242. m_fFun = NULL;
  243. }
  244. tFrameMapItem::tFrameMapItem(cmdFun f)
  245. {
  246. m_fFun = f;
  247. }
  248. tFrameMapItem& tFrameMapItem::operator =(const tFrameMapItem& value)
  249. {
  250. m_fFun = value.m_fFun;
  251. return *this;
  252. }
  253. //********************************通用模块类********************************
  254. Device::Device(Dev_Type type)
  255. {
  256. CString log;
  257. string name = UnitTool_DevType_Null;
  258. string logTitle = UnitTool_logKey_Null;
  259. string cfgLib;
  260. string cfgFile;
  261. switch (type)
  262. {
  263. case Dev_Generator:
  264. {
  265. logTitle = UnitTool_logKey_Gen;
  266. name = UnitTool_DevType_Gen;
  267. cfgLib = UnitTool_GenLibDLL;
  268. cfgFile = UnitTool_GenFileName;
  269. }break;
  270. case Dev_Mechanical:
  271. {
  272. logTitle = UnitTool_logKey_Mech;
  273. name = UnitTool_DevType_Mech;
  274. cfgLib = UnitTool_MechLibDLL;
  275. cfgFile = UnitTool_MechFileName;
  276. }break;
  277. case Dev_Collimator:
  278. {
  279. logTitle = UnitTool_logKey_Col;
  280. name = UnitTool_DevType_Col;
  281. cfgLib = UnitTool_ColLibDLL;
  282. cfgFile = UnitTool_ColFileName;
  283. }break;
  284. case Dev_SynBox:
  285. {
  286. logTitle = UnitTool_logKey_Syn;
  287. name = UnitTool_DevType_Syn;
  288. cfgLib = UnitTool_SynLibDLL;
  289. cfgFile = UnitTool_SynFileName;
  290. }break;
  291. case Dev_Detector:
  292. {
  293. logTitle = UnitTool_logKey_FPD;
  294. name = UnitTool_DevType_FPD;
  295. cfgLib = UnitTool_FPDLibDLL;
  296. cfgFile = UnitTool_FPDFileName;
  297. }break;
  298. case Dev_SMachine:
  299. {
  300. logTitle = UnitTool_logKey_SM;
  301. name = UnitTool_DevType_SM;
  302. cfgLib = UnitTool_SMLibDLL;
  303. cfgFile = UnitTool_SMFileName;
  304. }break;
  305. case Dev_TypeALL:
  306. {
  307. logTitle = UnitTool_logKey_UI;
  308. name = UnitTool_DevType_UI;
  309. }break;
  310. default:
  311. log.Format("unknown DevType[%d]", (int)type);
  312. ToolsDlgLog(log);
  313. break;
  314. }
  315. m_enuType = type;
  316. m_strName = name;
  317. m_strLogTitle = logTitle;
  318. m_strLibTitle = cfgLib;
  319. m_strFileTitle = cfgFile;
  320. }
  321. bool Device::CreatMode(bool act)
  322. {
  323. CString log;
  324. try
  325. {
  326. if (act)
  327. {
  328. if (m_pDevice)
  329. {
  330. mLog::Debug("CreatModel: Device type[{$}] aiready create", (int)m_enuType);
  331. return true;
  332. }
  333. mLog::Debug("{$}AppInitial:Initial", m_strLogTitle.c_str());
  334. string strCFGPath("");
  335. string strDLLPath("");
  336. if (!OpenCFGAndGetDllPath(strCFGPath, strDLLPath))
  337. {
  338. log.Format("%s OpenCFGAndGetDllPath failed", m_strLogTitle.c_str());
  339. mLog::Error(log);
  340. ToolsDlgLog(log);
  341. return false;
  342. }
  343. if (m_hDevLib != NULL)
  344. {
  345. FreeLibrary(m_hDevLib);
  346. m_hDevLib = NULL;
  347. }
  348. #if true //优先加载DLL所在目录
  349. m_hDevLib = LoadLibraryEx(strDLLPath.c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
  350. #else
  351. m_hDevLib = LoadLibrary(strDLLPath.c_str());
  352. #endif // 1
  353. if (m_hDevLib == NULL)
  354. {
  355. DWORD ret = GetLastError();
  356. log.Format("%s Failed to load library ret = %d", m_strLogTitle.c_str(), ret);
  357. mLog::Error(log);
  358. ToolsDlgLog(log);
  359. return false;
  360. }
  361. Sleep(100);
  362. mLog::Debug("{$}get module entry function", m_strLogTitle.c_str());
  363. auto inletFun = GetProcAddress(m_hDevLib, "CreateIODriver");//GetIODriver
  364. if (!inletFun)
  365. {
  366. log.Format("%s entry function get failed", m_strLogTitle.c_str());
  367. mLog::Error(log);
  368. ToolsDlgLog(log);
  369. return false;
  370. }
  371. shared_ptr<nsDEV::IODriver> tempDriver(reinterpret_cast <nsDEV::IODriver*> (inletFun()));
  372. if (!tempDriver)
  373. {
  374. log.Format("%s entry function conversion failed", m_strLogTitle.c_str());
  375. mLog::Error(log);
  376. ToolsDlgLog(log);
  377. return false;
  378. }
  379. Sleep(100);
  380. mLog::Debug("{$}Module driver execution DriverEntry", m_strLogTitle.c_str());
  381. tempDriver->DriverEntry(strCFGPath);
  382. Sleep(100);
  383. mLog::Debug("{$}Module driver execution Prepare", m_strLogTitle.c_str());
  384. tempDriver->Prepare();
  385. Sleep(100);
  386. mLog::Debug("{$}Module driver execution Connect", m_strLogTitle.c_str());
  387. tempDriver->Connect();
  388. auto bConnected = tempDriver->isConnected();
  389. if (!bConnected)
  390. {
  391. log.Format("%s Module failed to connect to device", m_strLogTitle.c_str());
  392. mLog::Error(log);
  393. ToolsDlgLog(log);
  394. return false;
  395. }
  396. bConnected = tempDriver->isConnected();
  397. Sleep(100);
  398. //bConnected = tempDriver->isConnected();
  399. int devNumber = 1;
  400. if (m_DeviceConfig[UnitTool_CONFIGURATION].GetKeyCount(UnitTool_DeviceNumber) > 0)
  401. {
  402. devNumber = m_DeviceConfig[UnitTool_CONFIGURATION][UnitTool_DeviceNumber];
  403. }
  404. mLog::Debug("{$}Module Driver Create [{$}]Logical Device Object", m_strLogTitle.c_str(), devNumber);
  405. for (int i = 0; i < devNumber; i++)
  406. {
  407. unique_ptr<nsDEV::IODevice> tempDevice = tempDriver->CreateDevice(i);
  408. if (tempDevice->Prepare())
  409. {
  410. Dev_Type tempDevType = CDeviceSET::GetInstance()->CheckDeviceType(tempDevice->GetGUID());
  411. mLog::Debug("{$}Logical Device type[{$}]execute Prepare", m_strLogTitle.c_str(), (int)tempDevType);
  412. auto findItem = CDeviceSET::GetInstance()->m_CDeviceMap.find(tempDevType);
  413. if (findItem != CDeviceSET::GetInstance()->m_CDeviceMap.end())
  414. {
  415. findItem->second->m_pDriver = tempDriver;
  416. findItem->second->m_BelongToOtherDriver = m_enuType;
  417. findItem->second->m_pDevice = std::move(tempDevice);
  418. findItem->second->m_pDevice->EventCenter->OnNotify.Push([this](int NotifyCode, string key, string context) { OnDiosNotify(NotifyCode, key, context); });
  419. mLog::Debug("{$}Device[{$}:{$}] Create success", m_strLogTitle.c_str(), i, findItem->second->m_strName.c_str());
  420. if (gal_hTopWnd && tempDevType != m_enuType)
  421. {
  422. ::PostMessage(gal_hTopWnd, MSG_Dios_Notify_ModeInit, tempDevType, 1);
  423. }
  424. }
  425. else
  426. {
  427. log.Format("%s Unknow Device type[%d]", m_strLogTitle.c_str(), (int)tempDevType);
  428. mLog::Error(log);
  429. ToolsDlgLog(log);
  430. }
  431. }
  432. else
  433. {
  434. log.Format("%s Logical Device num[%d]execute Prepare failed", m_strLogTitle.c_str(), i);
  435. mLog::Error(log);
  436. ToolsDlgLog(log);
  437. }
  438. }
  439. Sleep(100);
  440. }
  441. else
  442. {
  443. if (!m_pDevice)
  444. {
  445. mLog::Debug("CreatModel: Device type[{$}] already Delete", (int)m_enuType);
  446. return true;
  447. }
  448. shared_ptr<nsDEV::IODriver> tempDriver = m_pDriver;
  449. for (auto findDevcie = CDeviceSET::GetInstance()->m_CDeviceMap.begin(); findDevcie != CDeviceSET::GetInstance()->m_CDeviceMap.end(); findDevcie++)
  450. {
  451. if (findDevcie->second->m_BelongToOtherDriver == m_enuType)
  452. {
  453. mLog::Debug("{$}AppInitial:Exit[{$}]", m_strLogTitle.c_str(), findDevcie->second->m_strName.c_str());
  454. if (gal_hTopWnd && findDevcie->second->m_enuType != m_enuType)
  455. {
  456. ::SendMessage(gal_hTopWnd, MSG_Dios_Notify_ModeInit, findDevcie->second->m_enuType, 0);
  457. Sleep(100);
  458. }
  459. if (nullptr != findDevcie->second->m_pDevice)
  460. {
  461. findDevcie->second->m_pDevice.reset();
  462. }
  463. if (nullptr != findDevcie->second->m_pDriver)
  464. {
  465. findDevcie->second->m_pDriver.reset();
  466. }
  467. }
  468. }
  469. if (tempDriver != nullptr)
  470. {
  471. tempDriver->Disconnect();
  472. mLog::Debug("{$}try release dirver[{$}] count[{$}]", m_strLogTitle.c_str(), m_strName.c_str(), tempDriver.use_count()-1);
  473. tempDriver.reset();
  474. if (m_hDevLib != NULL)
  475. {
  476. FreeLibrary(m_hDevLib);
  477. m_hDevLib = NULL;
  478. }
  479. }
  480. mLog::Debug("{$}exit success", m_strLogTitle.c_str());
  481. }
  482. }
  483. catch (const ResDataObjectExption&)
  484. {
  485. log.Format("%s open file failed", m_strLogTitle.c_str());
  486. mLog::Error(log);
  487. ToolsDlgLog(log);
  488. return false;
  489. }
  490. catch (...)
  491. {
  492. log.Format("%s AppInitial failed", m_strLogTitle.c_str());
  493. mLog::Error(log);
  494. ToolsDlgLog(log);
  495. return false;
  496. }
  497. return true;
  498. }
  499. void Device::SetMagMap()
  500. {}
  501. string Device::DevActionValue(string action, initializer_list<string> args)
  502. {
  503. CString log;
  504. string rsp{ "error" };
  505. try {
  506. ResDataObject json;
  507. if (0 == args.size())
  508. {
  509. return rsp;
  510. }
  511. char key[8]{ 0 };
  512. int num{ 0 };
  513. for (auto item : args)
  514. {
  515. sprintf(key,"P%1d", num);
  516. json.add(key, item.c_str());
  517. num++;
  518. }
  519. //mLog::Debug("act[{$}],param[{$}]", action.c_str(), json.encode());
  520. RET_STATUS rc0;
  521. if (m_pDevice != nullptr)
  522. rc0 = m_pDevice->Action(action, json.encode(), rsp);
  523. if (rc0 == RET_STATUS::RET_SUCCEED)
  524. {
  525. mLog::Debug("{$}[{$}] success", m_strLogTitle.c_str(), action.c_str());
  526. }
  527. else
  528. {
  529. log.Format("%s[%s] fail", m_strLogTitle.c_str(), action.c_str());
  530. mLog::Error(log);
  531. ToolsDlgLog(log);
  532. rsp.clear();
  533. }
  534. }
  535. catch (...)
  536. {
  537. log.Format("%s action[%s] exe failed", m_strLogTitle.c_str(), action.c_str());
  538. mLog::Error(log);
  539. ToolsDlgLog(log);
  540. }
  541. return rsp;
  542. }
  543. string Device::DevActionKeyValue(string action, map<string, string>& args, bool withP0)
  544. {
  545. CString log;
  546. string rsp{ "error" };
  547. try {
  548. ResDataObject json;
  549. if (0 == args.size())
  550. {
  551. return rsp;
  552. }
  553. ResDataObject tempParam;
  554. for (auto& item : args)
  555. {
  556. tempParam.add(item.first.c_str(), item.second.c_str());
  557. }
  558. if (withP0)
  559. {
  560. json.add("P0", tempParam);
  561. }
  562. else
  563. {
  564. json = tempParam;
  565. }
  566. //mLog::Debug("act[{$}],param[{$}]", action.c_str(), json.encode());
  567. RET_STATUS rc0;
  568. if (m_pDevice != nullptr)
  569. rc0 = m_pDevice->Action(action, json.encode(), rsp);
  570. if (rc0 == RET_STATUS::RET_SUCCEED)
  571. {
  572. mLog::Debug("{$}[{$}] success", m_strLogTitle.c_str(), action.c_str());
  573. }
  574. else
  575. {
  576. log.Format("%s[%s] fail", m_strLogTitle.c_str(), action.c_str());
  577. mLog::Error(log);
  578. ToolsDlgLog(log);
  579. rsp.clear();
  580. }
  581. }
  582. catch (...)
  583. {
  584. log.Format("%s action[%s] exe failed", m_strLogTitle.c_str(), action.c_str());
  585. mLog::Error(log);
  586. ToolsDlgLog(log);
  587. }
  588. return rsp;
  589. }
  590. string Device::DevAction(string action)
  591. {
  592. CString log;
  593. string strLogKey = UnitTool_logKey_Null;
  594. string rsp;
  595. RET_STATUS rc0;
  596. if (m_pDevice != nullptr)
  597. rc0 = m_pDevice->Action(action, "", rsp);
  598. if (rc0 == RET_STATUS::RET_SUCCEED)
  599. {
  600. mLog::Debug("{$}[{$}] success", m_strLogTitle.c_str(), action.c_str());
  601. }
  602. else
  603. {
  604. log.Format("%s[%s] fail", m_strLogTitle.c_str(), action.c_str());
  605. mLog::Error(log);
  606. ToolsDlgLog(log);
  607. rsp.clear();
  608. }
  609. return rsp;
  610. }
  611. string Device::DevGetValue(string action)
  612. {
  613. CString log;
  614. string strLogKey = UnitTool_logKey_Null;
  615. string rsp{ "error" };
  616. try {
  617. RET_STATUS rc0;
  618. if (m_pDevice != nullptr)
  619. rc0 = m_pDevice->Get(action, rsp);
  620. if (rc0 == RET_STATUS::RET_SUCCEED)
  621. {
  622. mLog::Debug("{$}[{$}] success", m_strLogTitle.c_str(), action.c_str());
  623. }
  624. else
  625. {
  626. log.Format("%s[%s] fail", m_strLogTitle.c_str(), action.c_str());
  627. mLog::Error(log);
  628. ToolsDlgLog(log);
  629. rsp.clear();
  630. }
  631. }
  632. catch (...)
  633. {
  634. log.Format("%s action[%s] exe failed", m_strLogTitle.c_str(), action.c_str());
  635. mLog::Error(log);
  636. ToolsDlgLog(log);
  637. }
  638. return rsp;
  639. }
  640. void Device::OnDiosNotify(int& NotifyCode, string& key, string& context)
  641. {
  642. CString strNotify;
  643. mLog::Debug("OnNotify: code[{$}] key[{$}] text[{$}]", NotifyCode, key.c_str(), context.c_str());
  644. auto found = m_mapFrame.find(key);//此处pr用来在arFrame中找到对于的包头
  645. if (found == m_mapFrame.end())
  646. {
  647. mLog::Warn("OnNotify: UnKnown key");
  648. }
  649. else
  650. {
  651. found->second.m_fFun(NotifyCode, key, context);
  652. }
  653. }
  654. bool Device::OpenCFGAndGetDllPath(string& CFGPath, string& DLLPath)
  655. {
  656. CString log;
  657. switch (m_enuType)
  658. {
  659. case Dev_Generator:
  660. case Dev_Mechanical:
  661. case Dev_Collimator:
  662. case Dev_SynBox:
  663. case Dev_Detector:
  664. {
  665. string procdir = GetProcessDirectory();
  666. if (!m_strCfgFile.empty())
  667. {
  668. CFGPath = procdir + "\\" + UnitTool_DriverConfigPath + "\\" + m_strCfgFile;
  669. mLog::Debug("{$}Read module config file:{$}", m_strLogTitle.c_str(), CFGPath.c_str());
  670. if (!(m_DeviceConfig.loadFile(CFGPath.c_str())))
  671. {
  672. log.Format("%s Load reading module config file[%s]failed", m_strLogTitle.c_str(), CFGPath.c_str());
  673. mLog::Error(log);
  674. ToolsDlgLog(log);
  675. return false;
  676. }
  677. if (m_DeviceConfig[UnitTool_CONFIGURATION].GetKeyCount(UnitTool_oemdriver) > 0)
  678. {
  679. DLLPath = (string)m_DeviceConfig[UnitTool_CONFIGURATION][UnitTool_oemdriver];
  680. }
  681. if (!(DLLPath.empty()))
  682. {
  683. string oemdrvpath = DLLPath;
  684. {
  685. string keystr = "%ROOT%";
  686. string::size_type pos = 0;
  687. string::size_type keylen = keystr.size();
  688. string::size_type replen = procdir.size();
  689. while ((pos = oemdrvpath.find(keystr, pos)) != string::npos)
  690. {
  691. oemdrvpath.replace(pos, keylen, procdir);
  692. pos += replen;
  693. }
  694. }
  695. DLLPath = oemdrvpath;
  696. }
  697. }
  698. else
  699. {
  700. log.Format("%s Read module config file is null", m_strLogTitle.c_str());
  701. mLog::Error(log);
  702. ToolsDlgLog(log);
  703. return false;
  704. }
  705. }break;
  706. case Dev_SMachine:
  707. {
  708. string procdir = GetProcessDirectory(true);
  709. DLLPath = procdir + "\\" + m_strCfgLib;
  710. mLog::Debug("{$}get SMachine dll:{$}", m_strLogTitle.c_str(), DLLPath.c_str());
  711. CFGPath = m_strCfgFile;
  712. mLog::Debug("{$}Read module config file:{$}", m_strLogTitle.c_str(), CFGPath.c_str());
  713. }break;
  714. case Dev_TypeALL:
  715. {}break;
  716. default:
  717. log.Format("unknown DevType[%d]", (int)m_enuType);
  718. ToolsDlgLog(log);
  719. break;
  720. }
  721. #if UnitTool_UseJson
  722. string strMajorID, strVendorID, strProductID, strSerialID;
  723. if (m_DeviceConfig[UnitTool_CONFIGURATION].GetKeyCount(UnitTool_MajorID) > 0)
  724. {
  725. strMajorID = (string)m_DeviceConfig[UnitTool_CONFIGURATION][UnitTool_MajorID];
  726. }
  727. if (m_DeviceConfig[UnitTool_CONFIGURATION].GetKeyCount(UnitTool_VendorID) > 0)
  728. {
  729. strVendorID = (string)m_DeviceConfig[UnitTool_CONFIGURATION][UnitTool_VendorID];
  730. }
  731. if (m_DeviceConfig[UnitTool_CONFIGURATION].GetKeyCount(UnitTool_ProductID) > 0)
  732. {
  733. strProductID = (string)m_DeviceConfig[UnitTool_CONFIGURATION][UnitTool_ProductID];
  734. }
  735. if (m_DeviceConfig[UnitTool_CONFIGURATION].GetKeyCount(UnitTool_SerialID) > 0)
  736. {
  737. strSerialID = (string)m_DeviceConfig[UnitTool_CONFIGURATION][UnitTool_SerialID];
  738. }
  739. CFGPath = strMajorID + "_" + strVendorID + "_" + strProductID + "_" + strSerialID + ".json";
  740. #endif
  741. mLog::Debug("{$}Load cfgFile:{$}, library:{$}", m_strLogTitle.c_str(), CFGPath.c_str(), DLLPath.c_str());
  742. return true;
  743. }
  744. //********************************通用对话框基类********************************
  745. BOOL CDiosBasicDlg::OnInitDialog()
  746. {
  747. CDialogEx::OnInitDialog();
  748. //鼠标悬停
  749. m_Ttc.Create(this); //必需
  750. EnableToolTips(true); //设置是否启用提示
  751. m_Ttc.SetDelayTime(0); //设置延迟,如果为0则不等待
  752. m_Ttc.SetTipTextColor(RGB(0, 0, 255)); //设置提示文本的颜色
  753. m_Ttc.SetTipBkColor(RGB(255, 255, 255)); //设置提示框的背景颜色
  754. m_Ttc.SetMaxTipWidth(600);//设置提示文本框的最大宽度
  755. m_Ttc.Activate(TRUE); //设置是否启用提示
  756. SetToolTipsMsgMap();//封装的函数
  757. return TRUE;
  758. }
  759. void CDiosBasicDlg::InitPageElements(bool act)
  760. {}
  761. void CDiosBasicDlg::ShowPageElements(bool init, bool exit, bool cfg, bool general)
  762. {
  763. //init
  764. GetDlgItem(IDC_BUTTON1)->EnableWindow(init);
  765. //exit
  766. GetDlgItem(IDC_BUTTON2)->EnableWindow(exit);
  767. //config
  768. GetDlgItem(IDC_BUTTON3)->EnableWindow(cfg);
  769. }
  770. void CDiosBasicDlg::OnOK()
  771. {
  772. }
  773. void CDiosBasicDlg::OnCancel()
  774. {
  775. }
  776. BOOL CDiosBasicDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
  777. {
  778. if ((GetStyle() & WS_VSCROLL) == WS_VSCROLL)
  779. {
  780. SCROLLINFO scinfo = { 0 };
  781. scinfo.cbSize = sizeof(SCROLLINFO);
  782. GetScrollInfo(SB_VERT, &scinfo, SIF_ALL);
  783. // 滚动条最大滚动位置
  784. int nPosMax = scinfo.nMax - (int)scinfo.nPage;
  785. // 旧窗体位置(窗体尺寸及滚动位置根据 SCROLLINFO::nMax、nPage、nPos 反算,省去增加并维护相关成员变量的代码)
  786. int nWndPosOld = scinfo.nPos * scinfo.nMax / nPosMax;
  787. // 移动滚动条
  788. scinfo.fMask = SIF_POS;
  789. scinfo.nPos = min(max(scinfo.nPos - zDelta, 0), nPosMax);
  790. SetScrollInfo(SB_VERT, &scinfo);
  791. // 新窗体位置(窗体尺寸及滚动位置根据 SCROLLINFO::nMax、nPage、nPos 反算,省去增加并维护相关成员变量的代码)
  792. int nWndPosNew = scinfo.nPos * scinfo.nMax / nPosMax;
  793. // 滚动窗体
  794. ScrollWindow(0, nWndPosOld - nWndPosNew);
  795. }
  796. else if ((GetStyle() & WS_HSCROLL) == WS_HSCROLL)
  797. {
  798. SCROLLINFO scinfo = { 0 };
  799. scinfo.cbSize = sizeof(SCROLLINFO);
  800. GetScrollInfo(SB_HORZ, &scinfo, SIF_ALL);
  801. // 滚动条最大滚动位置
  802. int nPosMax = scinfo.nMax - (int)scinfo.nPage;
  803. // 旧窗体位置(窗体尺寸及滚动位置根据 SCROLLINFO::nMax、nPage、nPos 反算,省去增加并维护相关成员变量的代码)
  804. int nWndPosOld = scinfo.nPos * scinfo.nMax / nPosMax;
  805. // 移动滚动条
  806. scinfo.fMask = SIF_POS;
  807. scinfo.nPos = min(max(scinfo.nPos - zDelta, 0), nPosMax);
  808. SetScrollInfo(SB_HORZ, &scinfo);
  809. // 新窗体位置(窗体尺寸及滚动位置根据 SCROLLINFO::nMax、nPage、nPos 反算,省去增加并维护相关成员变量的代码)
  810. int nWndPosNew = scinfo.nPos * scinfo.nMax / nPosMax;
  811. // 滚动窗体
  812. ScrollWindow(nWndPosOld - nWndPosNew, 0);
  813. }
  814. return CDialogEx::OnMouseWheel(nFlags, zDelta, pt);
  815. }
  816. void CDiosBasicDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  817. {
  818. if ((GetStyle() & WS_VSCROLL) == WS_VSCROLL)
  819. {
  820. SCROLLINFO scinfo = { 0 };
  821. scinfo.cbSize = sizeof(SCROLLINFO);
  822. GetScrollInfo(SB_VERT, &scinfo, SIF_ALL);
  823. // 滚动条最大滚动位置
  824. int nPosMax = scinfo.nMax - (int)scinfo.nPage;
  825. // 旧窗体位置(窗体尺寸及滚动位置根据 SCROLLINFO::nMax、nPage、nPos 反算,省去增加并维护相关成员变量的代码)
  826. int nWndPosOld = scinfo.nPos * scinfo.nMax / nPosMax;
  827. switch (nSBCode)
  828. {
  829. case SB_TOP: scinfo.nPos = 0; break; // 滑块滚动到最顶部
  830. case SB_BOTTOM: scinfo.nPos = nPosMax; break; // 滑块滚动到最底部
  831. case SB_LINEUP: scinfo.nPos -= nPosMax / 10; break; // 单击上箭头(10 次结束,可视需求修改)
  832. case SB_LINEDOWN: scinfo.nPos += nPosMax / 10; break; // 单击下箭头(10 次结束,可视需求修改)
  833. case SB_PAGEUP: scinfo.nPos -= nPosMax / 2; break; // 单击滑块上方空白区域(2 次结束,可视需求修改)
  834. case SB_PAGEDOWN: scinfo.nPos += nPosMax / 2; break; // 单击滑块下方空白区域(2 次结束,可视需求修改)
  835. case SB_THUMBTRACK: scinfo.nPos = nPos; break; // 拖动滑块
  836. }
  837. // 移动滚动条
  838. scinfo.fMask = SIF_POS;
  839. scinfo.nPos = min(max(scinfo.nPos, 0), nPosMax);
  840. SetScrollInfo(SB_VERT, &scinfo);
  841. // 新窗体位置(窗体尺寸及滚动位置根据 SCROLLINFO::nMax、nPage、nPos 反算,省去增加并维护相关成员变量的代码)
  842. int nWndPosNew = scinfo.nPos * scinfo.nMax / nPosMax;
  843. // 滚动窗体
  844. ScrollWindow(0, nWndPosOld - nWndPosNew);
  845. }
  846. CDialogEx::OnVScroll(nSBCode, nPos, pScrollBar);
  847. }
  848. void CDiosBasicDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  849. {
  850. if ((GetStyle() & WS_HSCROLL) == WS_HSCROLL)
  851. {
  852. SCROLLINFO scinfo = { 0 };
  853. scinfo.cbSize = sizeof(SCROLLINFO);
  854. GetScrollInfo(SB_HORZ, &scinfo, SIF_ALL);
  855. // 滚动条最大滚动位置
  856. int nPosMax = scinfo.nMax - (int)scinfo.nPage;
  857. // 旧窗体位置(窗体尺寸及滚动位置根据 SCROLLINFO::nMax、nPage、nPos 反算,省去增加并维护相关成员变量的代码)
  858. int nWndPosOld = scinfo.nPos * scinfo.nMax / nPosMax;
  859. switch (nSBCode)
  860. {
  861. case SB_LEFT: scinfo.nPos = 0; break; // 滑块滚动到最左部
  862. case SB_RIGHT: scinfo.nPos = nPosMax; break; // 滑块滚动到最右部
  863. case SB_LINELEFT: scinfo.nPos -= nPosMax / 10; break; // 单击左箭头(10 次结束,可视需求修改)
  864. case SB_LINERIGHT: scinfo.nPos += nPosMax / 10; break; // 单击右箭头(10 次结束,可视需求修改)
  865. case SB_PAGELEFT: scinfo.nPos -= nPosMax / 2; break; // 单击滑块左空白区域(2 次结束,可视需求修改)
  866. case SB_PAGERIGHT: scinfo.nPos += nPosMax / 2; break; // 单击滑块右空白区域(2 次结束,可视需求修改)
  867. case SB_THUMBTRACK: scinfo.nPos = nPos; break; // 拖动滑块
  868. }
  869. // 移动滚动条
  870. scinfo.fMask = SIF_POS;
  871. scinfo.nPos = min(max(scinfo.nPos, 0), nPosMax);
  872. SetScrollInfo(SB_HORZ, &scinfo);
  873. // 新窗体位置(窗体尺寸及滚动位置根据 SCROLLINFO::nMax、nPage、nPos 反算,省去增加并维护相关成员变量的代码)
  874. int nWndPosNew = scinfo.nPos * scinfo.nMax / nPosMax;
  875. // 滚动窗体
  876. ScrollWindow(nWndPosOld - nWndPosNew, 0);
  877. }
  878. CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
  879. }
  880. void CDiosBasicDlg::UpdateScrollInfo(int nWidthNeed, int nLengthNeed)
  881. {
  882. //<summary>更新对话框滚动条(未改变原滚动位置)</summary>
  883. //<param name="nWidthNeed">需要滚动的区域宽度</param>
  884. //<param name="nHeightNeed">需要滚动的区域高度</param>
  885. //ASSERT(nWidthNeed > 0);
  886. //ASSERT(nLengthNeed > 0);
  887. int nCxVsCroll = ::GetSystemMetrics(SM_CXVSCROLL); // 系统垂直滚动条宽度
  888. int nCyHsCroll = ::GetSystemMetrics(SM_CYHSCROLL); // 系统水平滚动条高度
  889. // 可用客户区是去掉滚动条的客户区,计算滚动条参数时需要知道更新前和后滚动条是否存在,以在计算时减去或加上滚动条的尺寸
  890. // 当前客户区,这是不含滚动条的尺寸
  891. CRect rcClient;
  892. GetClientRect(rcClient);
  893. SCROLLINFO scinfo = { 0 };
  894. scinfo.cbSize = sizeof(SCROLLINFO);
  895. scinfo.fMask = SIF_RANGE | SIF_PAGE; // 不改变原滚动位置
  896. // 如果当前有垂直滚动条,则可用客户区宽度加上垂直滚动条宽度,计算结果是原始可用客户区
  897. if ((GetStyle() & WS_VSCROLL) == WS_VSCROLL) rcClient.right += nCxVsCroll;
  898. // 如果当前有水平滚动条,则可用客户区高度加上水平滚动条高度,计算结果是原始可用客户区
  899. if ((GetStyle() & WS_HSCROLL) == WS_HSCROLL) rcClient.bottom += nCyHsCroll;
  900. // 1、计算是否需要添加垂直滚动条
  901. BOOL bVsCrollAdd = nLengthNeed > rcClient.Height();
  902. // 2、计算是否需要添加水平滚动条
  903. BOOL bHsCrollAdd = nWidthNeed > rcClient.Width();
  904. // 3、如果需要水平滚动条并且前面计算不需要垂直滚动条,则由于可用客户区高度已变化,需要重新计算是否需要垂直滚动条
  905. if (bHsCrollAdd && !bVsCrollAdd)
  906. {
  907. bVsCrollAdd = nLengthNeed > rcClient.Height();
  908. // 如果需要垂直滚动条,客户区宽度减去垂直滚动条宽度
  909. if (bVsCrollAdd)
  910. rcClient.right -= nCxVsCroll;
  911. }
  912. // 如果需要垂直滚动条,客户区宽度减去垂直滚动条宽度
  913. if (bVsCrollAdd)
  914. {
  915. rcClient.right -= nCxVsCroll;
  916. // 更新垂直滚动条(不改变原滚动位置)
  917. scinfo.nMax = max(0, nLengthNeed - rcClient.Height()); // 垂直滚动最大值 = 需求高度 - 客户区高度
  918. scinfo.nPage = scinfo.nMax * rcClient.Height() / nLengthNeed; // 垂直滚动条内的滚动块高度
  919. SetScrollInfo(SB_VERT, &scinfo);
  920. }
  921. // 如果需要水平滚动条,客户区高度减去水平滚动条宽度
  922. if (bHsCrollAdd)
  923. {
  924. rcClient.bottom -= nCyHsCroll;
  925. // 更新水平滚动条(不改变原滚动位置)
  926. scinfo.nMax = max(0, nWidthNeed - rcClient.Width()); // 水平滚动最大值 = 需求宽度 - 客户区宽度
  927. scinfo.nPage = scinfo.nMax * rcClient.Width() / nWidthNeed; // 水平滚动条内的滚动块长度
  928. SetScrollInfo(SB_HORZ, &scinfo);
  929. }
  930. }
  931. BOOL CDiosBasicDlg::PreTranslateMessage(MSG* pMsg)
  932. {
  933. if (pMsg->message == WM_MOUSEMOVE)
  934. m_Ttc.RelayEvent(pMsg);
  935. return CDialog::PreTranslateMessage(pMsg);
  936. }
  937. void CDiosBasicDlg::SetToolTipsMsgMap()
  938. {
  939. //m_Ttc.AddTool(GetDlgItem(控件ID), _T("提示内容"));//绑定控件ID 显示提示内容
  940. }
  941. //********************************模块集合类********************************
  942. CDeviceSET* CDeviceSET::GetInstance()
  943. {
  944. return &glo_CDeviceSET;
  945. }
  946. Dev_Type CDeviceSET::CheckDeviceType(string GUID)
  947. {
  948. CString log;
  949. Dev_Type tempType = Dev_TypeNULL;
  950. if (GUID == UnitTool_GenGUID)//创建发生器
  951. {
  952. tempType = Dev_Generator;
  953. }
  954. else if (GUID == UnitTool_Mech1GUID ||
  955. GUID == UnitTool_Mech2GUID ||
  956. GUID == UnitTool_Mech3GUID)//创建机架
  957. {
  958. tempType = Dev_Mechanical;
  959. }
  960. else if (GUID == UnitTool_Col1GUID ||
  961. GUID == UnitTool_Col2GUID)//创建遮光器
  962. {
  963. tempType = Dev_Collimator;
  964. }
  965. else if (GUID == UnitTool_SynGUID)//创建同步盒
  966. {
  967. tempType = Dev_SynBox;
  968. }
  969. else if (GUID == UnitTool_FPDGUID)//创建探测器
  970. {
  971. tempType = Dev_Detector;
  972. }
  973. else
  974. {
  975. log.Format("can not deal with GUID[%s]", GUID.c_str());
  976. mLog::Error(log);
  977. ToolsDlgLog(log);
  978. }
  979. return tempType;
  980. }
  981. void CDeviceSET::SetToolDefaultConfig()
  982. {
  983. bool needSaveFlag = false;
  984. ResDataObject tempConfig;
  985. try
  986. {
  987. string strCFGPath = GetProcessDirectory() + UnitTool_configPath;
  988. if (tempConfig.loadFile(strCFGPath.c_str()))
  989. {
  990. for (int i = Dev_TypeNULL + 1; i < Dev_TypeALL; i++)
  991. {
  992. string FileName,cfgFile = CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strFileTitle;
  993. string Lib,cfgLib = CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strLibTitle;
  994. if (tempConfig[UnitTool_CONFIGURATION].GetKeyCount(cfgFile.c_str()) > 0)
  995. {
  996. FileName = (string)tempConfig[UnitTool_CONFIGURATION][cfgFile.c_str()];
  997. if (FileName != CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgFile)
  998. {
  999. tempConfig[UnitTool_CONFIGURATION][cfgFile.c_str()] = CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgFile.c_str();
  1000. needSaveFlag = true;
  1001. }
  1002. }
  1003. else
  1004. {
  1005. tempConfig[UnitTool_CONFIGURATION].add(cfgFile.c_str(), CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgFile.c_str());
  1006. needSaveFlag = true;
  1007. }
  1008. if (tempConfig[UnitTool_CONFIGURATION].GetKeyCount(cfgLib.c_str()) > 0)
  1009. {
  1010. Lib = (string)tempConfig[UnitTool_CONFIGURATION][cfgLib.c_str()];
  1011. if (Lib != CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgLib)
  1012. {
  1013. tempConfig[UnitTool_CONFIGURATION][cfgLib.c_str()] = CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgLib.c_str();
  1014. needSaveFlag = true;
  1015. }
  1016. }
  1017. else
  1018. {
  1019. tempConfig[UnitTool_CONFIGURATION].add(cfgLib.c_str(), CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgLib.c_str());
  1020. needSaveFlag = true;
  1021. }
  1022. }
  1023. if (needSaveFlag)
  1024. {
  1025. tempConfig.SaveFile(strCFGPath.c_str());
  1026. }
  1027. }
  1028. }
  1029. catch (...)
  1030. {
  1031. mLog::Error("open UnitToolconfig.xml catch");
  1032. return;
  1033. }
  1034. }
  1035. void CDeviceSET::GetToolDefaultConfig()
  1036. {
  1037. ResDataObject tempConfig;
  1038. try
  1039. {
  1040. string strCFGPath = GetProcessDirectory() + UnitTool_configPath;
  1041. if (tempConfig.loadFile(strCFGPath.c_str()))
  1042. {
  1043. for (int i = Dev_TypeNULL+1; i < Dev_TypeALL; i++)
  1044. {
  1045. bool isHasCfg{ false };
  1046. string cfgLib = CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strLibTitle;
  1047. string cfgFile = CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strFileTitle;
  1048. if (tempConfig[UnitTool_CONFIGURATION].GetKeyCount(cfgFile.c_str()) > 0)
  1049. {
  1050. CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgFile = (string)tempConfig[UnitTool_CONFIGURATION][cfgFile.c_str()];
  1051. if(!CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgFile.empty())
  1052. isHasCfg = true;
  1053. }
  1054. if (tempConfig[UnitTool_CONFIGURATION].GetKeyCount(cfgLib.c_str()) > 0)
  1055. {
  1056. CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgLib = (string)tempConfig[UnitTool_CONFIGURATION][cfgLib.c_str()];
  1057. if (!CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->m_strCfgLib.empty())
  1058. isHasCfg = true;
  1059. }
  1060. if (isHasCfg)
  1061. {
  1062. CDeviceSET::GetInstance()->m_CDeviceMap[(Dev_Type)i]->ShowPageElements(TRUE, FALSE, TRUE, FALSE);
  1063. }
  1064. }
  1065. }
  1066. }
  1067. catch (...)
  1068. {
  1069. mLog::Error("open UnitToolconfig.xml catch");
  1070. return;
  1071. }
  1072. }