CCollimatorDlg.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. // CCollimatorDlg.cpp: 实现文件
  2. //
  3. #include "pch.h"
  4. #include "resource.h" // 主符号
  5. #include "CCollimatorDlg.h"
  6. #include "afxdialogex.h"
  7. #include "CConfigDlg.h"
  8. #include "CColmImageDlg.h"
  9. CallFunGetImageData FunGetImageData = NULL;
  10. CallFunBeginTransImage FunBeginTransImage = NULL;
  11. CallFunEndTransImage FunEndTransImage = NULL;
  12. // CCollimatorDlg 对话框
  13. IMPLEMENT_DYNAMIC(CCollimatorDlg, CDiosBasicDlg)
  14. CCollimatorDlg::CCollimatorDlg(CWnd* pParent /*=nullptr*/)
  15. : CDiosBasicDlg(Dev_Collimator, IDD_DIALOG3, pParent)
  16. {
  17. }
  18. CCollimatorDlg::~CCollimatorDlg()
  19. {
  20. }
  21. void CCollimatorDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialogEx::DoDataExchange(pDX);
  24. DDX_Control(pDX, IDC_EDIT1, m_Edit_XSize);
  25. DDX_Control(pDX, IDC_EDIT2, m_Edit_YSize);
  26. DDX_Control(pDX, IDC_EDIT3, m_Edit_SID);
  27. DDX_Control(pDX, IDC_EDIT4, m_Edit_Angle);
  28. DDX_Control(pDX, IDC_EDIT5, m_Edit_Filter);
  29. DDX_Control(pDX, IDC_EDIT6, m_Edit_Mode);
  30. }
  31. BEGIN_MESSAGE_MAP(CCollimatorDlg, CDialogEx)
  32. ON_BN_CLICKED(IDCANCEL, &CCollimatorDlg::OnBnClickedCancel)
  33. ON_BN_CLICKED(IDC_BUTTON3, &CCollimatorDlg::OnBnClickedButton3)
  34. ON_BN_CLICKED(IDC_BUTTON1, &CCollimatorDlg::OnBnClickedButton1)
  35. ON_BN_CLICKED(IDC_BUTTON2, &CCollimatorDlg::OnBnClickedButton2)
  36. ON_BN_CLICKED(IDC_BUTTON4, &CCollimatorDlg::OnBnClickedButton4)
  37. ON_BN_CLICKED(IDC_BUTTON5, &CCollimatorDlg::OnBnClickedButton5)
  38. ON_BN_CLICKED(IDC_BUTTON6, &CCollimatorDlg::OnBnClickedButton6)
  39. ON_BN_CLICKED(IDC_BUTTON7, &CCollimatorDlg::OnBnClickedButton7)
  40. ON_BN_CLICKED(IDC_BUTTON8, &CCollimatorDlg::OnBnClickedButton8)
  41. ON_BN_CLICKED(IDC_BUTTON9, &CCollimatorDlg::OnBnClickedButton9)
  42. ON_BN_CLICKED(IDC_BUTTON10, &CCollimatorDlg::OnBnClickedButton10)
  43. ON_BN_CLICKED(IDC_BUTTON11, &CCollimatorDlg::OnBnClickedButton11)
  44. ON_EN_KILLFOCUS(IDC_EDIT1, &CCollimatorDlg::OnEnKillfocusEdit1)
  45. ON_EN_KILLFOCUS(IDC_EDIT2, &CCollimatorDlg::OnEnKillfocusEdit2)
  46. ON_EN_KILLFOCUS(IDC_EDIT3, &CCollimatorDlg::OnEnKillfocusEdit3)
  47. ON_EN_KILLFOCUS(IDC_EDIT4, &CCollimatorDlg::OnEnKillfocusEdit4)
  48. ON_EN_KILLFOCUS(IDC_EDIT5, &CCollimatorDlg::OnEnKillfocusEdit5)
  49. ON_EN_KILLFOCUS(IDC_EDIT6, &CCollimatorDlg::OnEnKillfocusEdit6)
  50. END_MESSAGE_MAP()
  51. // CCollimatorDlg 消息处理程序
  52. //初始化配置
  53. BOOL CCollimatorDlg::OnInitDialog()
  54. {
  55. CDiosBasicDlg::OnInitDialog();
  56. return TRUE;
  57. }
  58. //设备初始化
  59. bool CCollimatorDlg::AppInitial(bool act)
  60. {
  61. CString log;
  62. return CreatMode(act);
  63. }
  64. //获取初始值
  65. bool CCollimatorDlg::GetInitData()
  66. {
  67. CString log;
  68. CString tempStr;
  69. string strTempValue;
  70. if (m_pDevice != nullptr)
  71. {
  72. m_nXsize = atoi(DevGetValue(nsCOLL::AttrKey::XSIZE).c_str());
  73. tempStr.Format("%d", m_nXsize);
  74. m_Edit_XSize.SetWindowText(tempStr);
  75. m_nYsize = atof(DevGetValue(nsCOLL::AttrKey::YSIZE).c_str());
  76. tempStr.Format("%.2f", m_nYsize);
  77. m_Edit_YSize.SetWindowText(tempStr);
  78. m_nSID = atof(DevGetValue(nsCOLL::AttrKey::FILTER).c_str());
  79. tempStr.Format("%.2f", m_nSID);
  80. m_Edit_SID.SetWindowText(tempStr);
  81. m_nAngle = atof(DevGetValue(nsCOLL::AttrKey::SID).c_str());
  82. tempStr.Format("%.2f", m_nAngle);
  83. m_Edit_Angle.SetWindowText(tempStr);
  84. m_nFilter = atoi(DevGetValue(nsCOLL::AttrKey::ANGLE).c_str());
  85. tempStr.Format("%d", m_nFilter);
  86. m_Edit_Filter.SetWindowText(tempStr);
  87. int Mode = atoi(DevGetValue(nsCOLL::AttrKey::MODE).c_str());
  88. tempStr.Format("%d", Mode);
  89. m_Edit_Mode.SetWindowText(tempStr);
  90. m_bLight = atoi(DevGetValue(nsCOLL::AttrKey::LIGHT).c_str());
  91. if (m_bLight)
  92. {
  93. GetDlgItem(IDC_BUTTON10)->SetWindowText("LightOn");
  94. }
  95. else
  96. {
  97. GetDlgItem(IDC_BUTTON10)->SetWindowText("LightOff");
  98. }
  99. }
  100. return true;
  101. }
  102. //设置消息对照表
  103. void CCollimatorDlg::SetMagMap()
  104. {
  105. auto HW_UNKNOWN = [this](int NotifyCode, string key, string context)
  106. {
  107. CString strNotify;
  108. strNotify.Format("COLL can not deal with Attribute[%s] \n", key.c_str());
  109. ToolsDlgLog(strNotify);
  110. };
  111. auto HW_XSize = [this](int NotifyCode, string key, string context)//XSize
  112. {
  113. m_nXsize = atoi(context.c_str());
  114. m_Edit_XSize.SetWindowText(context.c_str());
  115. };
  116. auto HW_YSize = [this](int NotifyCode, string key, string context)//YSize
  117. {
  118. m_nYsize = atoi(context.c_str());
  119. m_Edit_YSize.SetWindowText(context.c_str());
  120. };
  121. auto HW_SID = [this](int NotifyCode, string key, string context)//SID
  122. {
  123. m_Edit_SID.SetWindowText(context.c_str());
  124. };
  125. auto HW_Angle = [this](int NotifyCode, string key, string context)//Angle
  126. {
  127. m_Edit_Angle.SetWindowText(context.c_str());
  128. };
  129. auto HW_CollimatorFilter = [this](int NotifyCode, string key, string context)//Filter
  130. {
  131. m_Edit_Filter.SetWindowText(context.c_str());
  132. };
  133. auto HW_Mode = [this](int NotifyCode, string key, string context)//Mode
  134. {
  135. m_Edit_Mode.SetWindowText(context.c_str());
  136. };
  137. //Collimator
  138. m_mapFrame["UnKnown"] = tFrameMapItem(HW_UNKNOWN);
  139. m_mapFrame[nsCOLL::AttrKey::XSIZE] = tFrameMapItem(HW_XSize);
  140. m_mapFrame[nsCOLL::AttrKey::YSIZE] = tFrameMapItem(HW_YSize);
  141. m_mapFrame[nsCOLL::AttrKey::SID] = tFrameMapItem(HW_SID);
  142. m_mapFrame[nsCOLL::AttrKey::ANGLE] = tFrameMapItem(HW_Angle);
  143. m_mapFrame[nsCOLL::AttrKey::FILTER] = tFrameMapItem(HW_CollimatorFilter);
  144. m_mapFrame[nsCOLL::AttrKey::MODE] = tFrameMapItem(HW_Mode);
  145. }
  146. void CCollimatorDlg::InitPageElements(bool act)
  147. {
  148. if (act)
  149. {
  150. ShowPageElements(FALSE, TRUE, FALSE, FALSE);
  151. SetMagMap();
  152. GetInitData();
  153. }
  154. else
  155. {
  156. ShowPageElements(TRUE, FALSE, TRUE, FALSE);
  157. }
  158. }
  159. //设置窗口元素显示
  160. void CCollimatorDlg::ShowPageElements(bool init, bool exit, bool cfg, bool general)
  161. {
  162. __super::ShowPageElements(init,exit,cfg,general);
  163. bool nomal = exit;
  164. //Size
  165. GetDlgItem(IDC_BUTTON4)->EnableWindow(nomal);
  166. GetDlgItem(IDC_EDIT1)->EnableWindow(nomal);
  167. //YSize
  168. GetDlgItem(IDC_BUTTON5)->EnableWindow(nomal);
  169. GetDlgItem(IDC_EDIT2)->EnableWindow(nomal);
  170. //SID
  171. GetDlgItem(IDC_BUTTON6)->EnableWindow(nomal);
  172. GetDlgItem(IDC_EDIT3)->EnableWindow(nomal);
  173. //Angle
  174. GetDlgItem(IDC_BUTTON7)->EnableWindow(nomal);
  175. GetDlgItem(IDC_EDIT4)->EnableWindow(nomal);
  176. //Filter
  177. GetDlgItem(IDC_BUTTON8)->EnableWindow(nomal);
  178. GetDlgItem(IDC_EDIT5)->EnableWindow(nomal);
  179. //Mode
  180. GetDlgItem(IDC_BUTTON9)->EnableWindow(general);
  181. GetDlgItem(IDC_EDIT6)->EnableWindow(general);
  182. //Light
  183. GetDlgItem(IDC_BUTTON10)->EnableWindow(nomal);
  184. //AI
  185. GetDlgItem(IDC_BUTTON11)->EnableWindow(nomal);
  186. }
  187. //统一修改接口
  188. void CCollimatorDlg::SetSize(int Xvalue, int Yvalue)
  189. {
  190. CString log;
  191. string rsp{ "error" };
  192. try {
  193. ResDataObject json;
  194. json.add("P0", Xvalue);
  195. json.add("P1", Yvalue);
  196. RET_STATUS rc0;
  197. {
  198. if (m_pDevice != nullptr)
  199. rc0 = m_pDevice->Action(nsCOLL::ActionKey::SetCollimatorSize, json.encode(), rsp);
  200. }
  201. if (rc0 == RET_STATUS::RET_SUCCEED)
  202. mLog::Debug("{$} [SetCollimatorSize] success", UnitTool_logKey_Col);
  203. else
  204. {
  205. log.Format("%s [SetCollimatorSize] fail", UnitTool_logKey_Col);
  206. mLog::Error(log);
  207. ToolsDlgLog(log);
  208. rsp.clear();
  209. }
  210. }
  211. catch (...)
  212. {
  213. log.Format("%s action[SetCollimatorSize] exe failed", UnitTool_logKey_Col);
  214. mLog::Error(log);
  215. ToolsDlgLog(log);
  216. }
  217. }
  218. void CCollimatorDlg::OnBnClickedCancel()
  219. {
  220. // TODO: 在此添加控件通知处理程序代码
  221. CDialogEx::OnCancel();
  222. }
  223. //选择配置
  224. void CCollimatorDlg::OnBnClickedButton3()
  225. {
  226. CString log;
  227. nsCFG::CConfigDlg dlgcfg(Dev_Collimator,
  228. m_strCfgLib,
  229. m_strCfgFile);
  230. dlgcfg.DoModal();
  231. if (m_strCfgFile.empty())
  232. {
  233. log.Format("%s COLL m_strCfgFile is empty", UnitTool_logKey_Col);
  234. mLog::Warn(log);
  235. ToolsDlgLog(log);
  236. }
  237. else
  238. {
  239. ShowPageElements(TRUE, FALSE, TRUE, FALSE);
  240. }
  241. }
  242. //初始化
  243. void CCollimatorDlg::OnBnClickedButton1()
  244. {
  245. CString log;
  246. if (m_pDriver == nullptr)
  247. if (!m_pDevice)
  248. {
  249. if (AppInitial(true))
  250. {
  251. ShowPageElements(FALSE, TRUE, FALSE, FALSE);
  252. SetMagMap();
  253. GetInitData();
  254. mLog::Debug("{$} COLL Initial success", UnitTool_logKey_Col);
  255. }
  256. else
  257. {
  258. log.Format("%s COLL Initial fail", UnitTool_logKey_Col);
  259. mLog::Error(log);
  260. ToolsDlgLog(log);
  261. }
  262. }
  263. else
  264. {
  265. log.Format("%s m_pDevice not empty", UnitTool_logKey_Col);
  266. mLog::Warn(log);
  267. ToolsDlgLog(log);
  268. }
  269. else
  270. {
  271. log.Format("%s m_pDriver not empty", UnitTool_logKey_Col);
  272. mLog::Warn(log);
  273. ToolsDlgLog(log);
  274. }
  275. }
  276. //退出
  277. void CCollimatorDlg::OnBnClickedButton2()
  278. {
  279. if (AppInitial(false))
  280. {
  281. ShowPageElements(TRUE, FALSE, TRUE, FALSE);
  282. }
  283. }
  284. //XSize
  285. void CCollimatorDlg::OnBnClickedButton4()
  286. {
  287. SetSize(m_nXsize, m_nYsize);
  288. }
  289. //YSize
  290. void CCollimatorDlg::OnBnClickedButton5()
  291. {
  292. SetSize(m_nXsize, m_nYsize);
  293. }
  294. //SID
  295. void CCollimatorDlg::OnBnClickedButton6()
  296. {
  297. DevActionValue(nsCOLL::ActionKey::SetCollimatorSID, { to_string(m_nSID) });
  298. }
  299. //Angle
  300. void CCollimatorDlg::OnBnClickedButton7()
  301. {
  302. DevActionValue(nsCOLL::ActionKey::SetCollimatorAngle, { to_string(m_nAngle) });
  303. }
  304. //Filter
  305. void CCollimatorDlg::OnBnClickedButton8()
  306. {
  307. DevActionValue(nsCOLL::ActionKey::SetCollimatorFilter, { to_string(m_nFilter) });
  308. }
  309. //Mode
  310. void CCollimatorDlg::OnBnClickedButton9()
  311. {
  312. //DevActionValue(nsCOLL::ActionKey::SetCollimatorMode, { m_nMode });
  313. }
  314. //Light?
  315. void CCollimatorDlg::OnBnClickedButton10()
  316. {
  317. if (m_bLight)
  318. {
  319. GetDlgItem(IDC_BUTTON10)->SetWindowText("LightOff");
  320. m_bLight = false;
  321. DevActionValue(nsCOLL::ActionKey::SetCollimatorLight, { to_string(m_bLight) });
  322. }
  323. else
  324. {
  325. m_bLight = true;
  326. GetDlgItem(IDC_BUTTON10)->SetWindowText("Lighton");
  327. DevActionValue(nsCOLL::ActionKey::SetCollimatorLight, { to_string(m_bLight) });
  328. }
  329. }
  330. //AI Video
  331. void CCollimatorDlg::OnBnClickedButton11()
  332. {
  333. DevActionValue("OpenSaveImage", { to_string(1) });
  334. CColmImageDlg ColmTest;
  335. ColmTest.DoModal();
  336. DevActionValue("OpenSaveImage", { to_string(0) });
  337. }
  338. //XSize_Value
  339. void CCollimatorDlg::OnEnKillfocusEdit1()
  340. {
  341. CString tempStr;
  342. m_Edit_XSize.GetWindowText(tempStr);
  343. m_nXsize = atoi(tempStr);
  344. }
  345. //YSize_Value
  346. void CCollimatorDlg::OnEnKillfocusEdit2()
  347. {
  348. CString tempStr;
  349. m_Edit_YSize.GetWindowText(tempStr);
  350. m_nYsize = atoi(tempStr);
  351. }
  352. //SID_Value
  353. void CCollimatorDlg::OnEnKillfocusEdit3()
  354. {
  355. CString tempStr;
  356. m_Edit_SID.GetWindowText(tempStr);
  357. m_nSID = atoi(tempStr);
  358. }
  359. //Angle_Value
  360. void CCollimatorDlg::OnEnKillfocusEdit4()
  361. {
  362. CString tempStr;
  363. m_Edit_Angle.GetWindowText(tempStr);
  364. m_nAngle = atoi(tempStr);
  365. }
  366. //Filter_Value
  367. void CCollimatorDlg::OnEnKillfocusEdit5()
  368. {
  369. CString tempStr;
  370. m_Edit_Filter.GetWindowText(tempStr);
  371. m_nFilter = atoi(tempStr);
  372. }
  373. //Mode_Value
  374. void CCollimatorDlg::OnEnKillfocusEdit6()
  375. {
  376. CString tempStr;
  377. m_Edit_Mode.GetWindowText(tempStr);
  378. m_nMode = atoi(tempStr);
  379. }
  380. void CCollimatorDlg::CreateCareRaySmartSys()
  381. {
  382. //智光器特殊逻辑
  383. FunGetImageData = (CallFunGetImageData)GetProcAddress(m_hDevLib, "COLM_GET_IMAGE_DATA");
  384. if (FunGetImageData == NULL)
  385. {
  386. ToolsDlgLog("CollimatorDevice:error FunGetImageData is null");
  387. }
  388. FunBeginTransImage = (CallFunBeginTransImage)GetProcAddress(m_hDevLib, "COLM_BEGIN_TRANS_IMAGE");
  389. if (FunBeginTransImage == NULL)
  390. {
  391. ToolsDlgLog("CollimatorDevice:error FunBeginTransImage is null");
  392. }
  393. FunEndTransImage = (CallFunEndTransImage)GetProcAddress(m_hDevLib, "COLM_END_TRANS_IMAGE");
  394. if (FunEndTransImage == NULL)
  395. {
  396. ToolsDlgLog("CollimatorDevice:error FunEndTransImage is null");
  397. }
  398. }