ControllerSettingForm.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Xml;
  5. using System.IO;
  6. using System.Windows.Forms.DataVisualization.Charting;
  7. using System.Threading;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using OTSCLRINTERFACE;
  11. using OTSModelSharp.ServiceCenter;
  12. using System.Drawing.Drawing2D;
  13. namespace OTSSysMgrApp
  14. {
  15. public partial class ControllerSettingForm : Form
  16. {
  17. #region 全部变量声明
  18. RecommendedConfiguration recommendedConfiguration;
  19. //连接状态
  20. bool ConnectionState = false;
  21. static string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFilePath"].ConnectionString;
  22. //日志路径
  23. static string LogPath = System.Configuration.ConfigurationManager.ConnectionStrings["LogPath"].ConnectionString;
  24. static NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
  25. IEDSController m_EDSHardwareMgr = null;
  26. //图片
  27. Bitmap bitmap = null;
  28. //国际化
  29. Language lan;
  30. //国际化存储信息
  31. Hashtable table;
  32. #endregion
  33. public enum connectionEnumType
  34. {
  35. EDSOnlyPointXRay = 0,
  36. EDSMultiPointXRay = 1,
  37. EDSAreaXRay = 2,
  38. ScanImage = 3
  39. }
  40. #region 构造函数
  41. public ControllerSettingForm()
  42. {
  43. InitializeComponent();
  44. string deviceType = FileHelper.GetXMLInformations("EDSName");
  45. var semtype = FileHelper.GetXMLInformations("SemControllerName");
  46. m_EDSHardwareMgr = EDSController.GetEDSController(semtype, deviceType, Convert.ToInt32(tbRWidth.Text), Convert.ToInt32(tbRHeight.Text), 5000,true,"");
  47. lan = new Language(this);
  48. table = lan.GetNameTable(this.Name);
  49. }
  50. /// <summary>
  51. /// 连接电镜
  52. /// </summary>
  53. /// <param name="connectionType"></param>
  54. public bool ConnectionSem(connectionEnumType connectionType)
  55. {
  56. //连接电镜标识
  57. bool DisConnResult = false;
  58. //判断连接状态
  59. if (!ConnectionState)
  60. {
  61. //连接电镜设置
  62. DisConnResult = m_EDSHardwareMgr.Connect();
  63. }
  64. if (DisConnResult)
  65. {
  66. ConnectionState = true;
  67. }
  68. else
  69. {
  70. ConnectionState = false;
  71. }
  72. return DisConnResult;
  73. }
  74. /// <summary>
  75. /// EDS初始化
  76. /// </summary>
  77. public bool EDSInit()
  78. {
  79. bool initResult = false;
  80. //线程调用 加载
  81. initResult = m_EDSHardwareMgr.Connect();
  82. return initResult;
  83. }
  84. #endregion
  85. #region 窗体中控件事件汇总
  86. private void btnClearXRay_Click(object sender, EventArgs e)
  87. {
  88. chartXRay.Series.RemoveAt(0);
  89. }
  90. private void btnCollectionTime_Click(object sender, EventArgs e)
  91. {
  92. try
  93. {
  94. int CollectionTime = 0;
  95. //判断是否为空与类型
  96. if (!IsNull(tbCollectionTime))
  97. {
  98. tbCollectionTime.Focus();
  99. return;
  100. }
  101. if (!IsType(tbCollectionTime.Text, 1))
  102. {
  103. tbCollectionTime.Focus();
  104. return;
  105. }
  106. //获取参数与设置参数
  107. CollectionTime = Convert.ToInt32(tbCollectionTime.Text);
  108. bool result = false;
  109. if (result)
  110. {
  111. //配置结果提示
  112. ShowMessage(3);
  113. }
  114. else
  115. {
  116. ShowMessage(4);
  117. }
  118. }
  119. catch (Exception ex)
  120. {
  121. //记录日志信息(异常日志)
  122. log.Error(ex.Message.ToString());
  123. }
  124. }
  125. private void ControllerSettingForm_Load(object sender, EventArgs e)
  126. {
  127. //设置窗体图表
  128. Control.CheckForIllegalCrossThreadCalls = false;
  129. ddlDwellTime.SelectedIndex = 0;
  130. InitXRayData();
  131. int width = Convert.ToInt32(tbRWidth.Text);
  132. int height = Convert.ToInt32(tbRHeight.Text);
  133. string deviceType = FileHelper.GetXMLInformations("EDSName");
  134. var semtype = FileHelper.GetXMLInformations("SemControllerName");
  135. m_EDSHardwareMgr = EDSController.GetEDSController(semtype, deviceType, width, height, 5000,true,"");
  136. cb_Xdirection.Items.Add("LEFT_TOWARD");
  137. cb_Xdirection.Items.Add("RIGHT_TOWARD");
  138. cb_Ydirection.Items.Add("UP_TOWARD");
  139. cb_Ydirection.Items.Add("DOWN_TOWARD");
  140. tB_scanFieldSize100.Text = "1270";
  141. cb_imageresolution.Items.Add("1024*768");
  142. cb_imageresolution.Items.Add("1024*704");
  143. cb_imageresolution.Items.Add("1536*1024");
  144. string xmlpath = Application.StartupPath + @"\Config\SysData\OTSProgMgrParam.pmf";
  145. string xAxisDir = "";
  146. string yAxisDir = "";
  147. string scanFieldSize = "";
  148. ReadConfigXml(xmlpath, ref xAxisDir, ref yAxisDir, ref scanFieldSize);
  149. if (xAxisDir.Split(':')[1] == "LEFT_TOWARD")
  150. {
  151. cb_Xdirection.SelectedIndex = 0;
  152. }
  153. else
  154. {
  155. cb_Xdirection.SelectedIndex = 1;
  156. }
  157. if (yAxisDir.Split(':')[1] == "UP_TOWARD")
  158. {
  159. cb_Ydirection.SelectedIndex = 0;
  160. }
  161. else
  162. {
  163. cb_Ydirection.SelectedIndex = 1;
  164. }
  165. tB_scanFieldSize100.Text = scanFieldSize;
  166. cb_imageresolution.SelectedIndex = 0;
  167. InitEvent();
  168. }
  169. Thread ScanThread = null;
  170. private void btnDisplay_Click(object sender, EventArgs e)
  171. {
  172. GetBSEDisplay();
  173. }
  174. private bool GetScanImage(int iWidth, int iHeigh, string DwellTime, ref byte[] bImageData)
  175. {
  176. //电镜设置对象
  177. var scan = ScanController.GetScanController();
  178. int GetImgCount = 0;
  179. try
  180. {
  181. //连接电镜
  182. bool IsConnec = scan.Init();
  183. if (!IsConnec)
  184. {
  185. return false;
  186. }
  187. #region 设置图像分辨率
  188. //设置宽度
  189. if (!scan.SetImageSize(iWidth, iHeigh))
  190. {
  191. return false;
  192. }
  193. #endregion
  194. #region 采集时间
  195. //采集时间
  196. DwellTimeLevel nDwellTime=DwellTimeLevel.Low;
  197. switch (DwellTime)
  198. {
  199. case "Low":
  200. nDwellTime = DwellTimeLevel.Low;
  201. break;
  202. case "Medium":
  203. nDwellTime = DwellTimeLevel.Medium;
  204. break;
  205. case "High":
  206. nDwellTime = DwellTimeLevel.High;
  207. break;
  208. }
  209. //设置采集时间
  210. if (!scan.SetDwellTime(nDwellTime))
  211. {
  212. return false;
  213. }
  214. #endregion
  215. int resultCount = iWidth * iHeigh;
  216. var img = scan.AcquireBSEImage();
  217. bImageData = img.GetImageDataPtr();
  218. }
  219. catch (Exception ex)
  220. {
  221. NLog.LogManager.GetCurrentClassLogger().Error(ex.ToString());
  222. return false;
  223. }
  224. return true;
  225. }
  226. protected void GetBSEDisplay()
  227. {
  228. try
  229. {
  230. string str1 = table["str1"].ToString();
  231. btnDisplay.Text = str1;
  232. btnDisplay.Enabled = false;
  233. btnDisplay.Refresh();
  234. if (pbImage.Image != null)
  235. {
  236. pbImage.Image = null;
  237. pbImage.Refresh();
  238. }
  239. Thread.Sleep(100);
  240. //设置图像分辨率
  241. int width = 0;
  242. int height = 0;
  243. //获取宽度
  244. width = Convert.ToInt32(tbRWidth.Text);
  245. height = Convert.ToInt32(tbRHeight.Text);
  246. byte[] ImageByte = new byte[width * height];
  247. Bitmap bitmap = null;
  248. int iWidth = Convert.ToInt32(tbRWidth.Text);
  249. int iHeight = Convert.ToInt32(tbRHeight.Text);
  250. bool resultValue = GetScanImage(iWidth, iHeight, ddlDwellTime.Text, ref ImageByte);
  251. string str2 = table["str2"].ToString();
  252. if (resultValue )
  253. {
  254. if (ImageByte != null)
  255. {
  256. bitmap = CImageHandler.ToGrayBitmap(ImageByte, width, height);
  257. pbImage.Image = bitmap;
  258. btnSaveImage.Enabled = true;
  259. log.Info("Image capture success!\nImage resolution:" + tbRWidth.Text + "X" + tbRHeight.Text + ";");
  260. }
  261. else
  262. {
  263. MessageBox.Show(str2, "Tip");
  264. }
  265. }
  266. else
  267. {
  268. MessageBox.Show(str2, "Tip");
  269. }
  270. }
  271. catch (Exception ex)
  272. {
  273. log.Error("ControllerSettingForm_btnDisplay_Click--错误信息:" + ex.ToString());
  274. }
  275. finally
  276. {
  277. string str = table["btndisplay"].ToString();
  278. btnDisplay.Text = str;
  279. btnDisplay.Enabled = true;
  280. btnDisplay.Refresh();
  281. }
  282. }
  283. private void btnClear_Click(object sender, EventArgs e)
  284. {
  285. pbImage.BackgroundImage = null;
  286. }
  287. Thread EDSThread = null;
  288. private void btnDisplayXRay_Click(object sender, EventArgs e)
  289. {
  290. try
  291. {
  292. string str1 = table["str1"].ToString();
  293. btnDisplayXRay.Text = str1;
  294. btnDisplayXRay.Enabled = false;
  295. btnDisplayXRay.Refresh();
  296. btnPointXRay.Enabled = false;
  297. btnPointXRay.Refresh();
  298. btnAreaRay.Enabled = false;
  299. btnAreaRay.Refresh();
  300. btnClearData.Enabled = false;
  301. btnClearData.Refresh();
  302. InitXRayData();
  303. if (ConnectionSem(connectionEnumType.EDSOnlyPointXRay))
  304. {
  305. if (EDSInit())
  306. {
  307. //图像数据
  308. uint[] a_XrayData = new uint[2000];
  309. uint a_Milliseconds = 0;
  310. //采集时间
  311. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  312. //采集XRay数据
  313. bool result = m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData);
  314. if (!result)
  315. {
  316. log.Info("CollectSpectrum failed!");
  317. }
  318. int[] XData = new int[2000];
  319. uint nXrayCount = 0;
  320. for (int i = 1; i <= 2000; i++)
  321. {
  322. XData[i - 1] = i;
  323. nXrayCount += a_XrayData[i - 1];
  324. }
  325. //绑定数据源
  326. chartData(XData, a_XrayData);
  327. //显示Xray计数
  328. lbXrayCount.Text = nXrayCount.ToString();
  329. }
  330. }
  331. log.Info("Single point collection succeeded!");
  332. }
  333. catch (Exception ex)
  334. {
  335. //记录日志
  336. log.Error(ex.Message.ToString());
  337. }
  338. finally
  339. {
  340. string str = table["btndisplayxray"].ToString();
  341. btnDisplayXRay.Text = str;
  342. btnDisplayXRay.Enabled = true;
  343. btnDisplayXRay.Refresh();
  344. btnPointXRay.Enabled = true;
  345. btnPointXRay.Refresh();
  346. btnAreaRay.Enabled = true;
  347. btnAreaRay.Refresh();
  348. btnClearData.Enabled = true;
  349. btnClearData.Refresh();
  350. }
  351. }
  352. public void RunEDSThread()
  353. {
  354. try
  355. {
  356. //图像数据
  357. uint[] a_XrayData = new uint[2000];
  358. uint a_Milliseconds = 0;
  359. //采集时间
  360. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  361. //采集XRay数据
  362. m_EDSHardwareMgr.CollectSpectrum(a_Milliseconds, ref a_XrayData);
  363. int[] XData = new int[2000];
  364. for (int i = 1; i <= 2000; i++)
  365. {
  366. XData[i - 1] = i;
  367. }
  368. //绑定数据源
  369. chartData(XData, a_XrayData);
  370. }
  371. catch (Exception ex)
  372. {
  373. //记录日志
  374. log.Error(ex.Message.ToString());
  375. }
  376. }
  377. public void chartData(int[] XData, uint[] YData)
  378. {
  379. //chartXRay = new Chart();
  380. //背景
  381. if (chartXRay.ChartAreas.Count == 0)
  382. {
  383. chartXRay.ChartAreas.Add(new ChartArea() { Name = "" }); //背景框
  384. }
  385. chartXRay.ChartAreas[0].Axes[0].MajorGrid.Enabled = false; //X轴上网格
  386. chartXRay.ChartAreas[0].Axes[1].MajorGrid.Enabled = false; //y轴上网格
  387. chartXRay.ChartAreas[0].Axes[0].MajorGrid.LineDashStyle = ChartDashStyle.Dash; //网格类型 短横线
  388. chartXRay.ChartAreas[0].Axes[0].MajorGrid.LineColor = Color.Gray;
  389. chartXRay.ChartAreas[0].Axes[0].MajorTickMark.Enabled = false; // x轴上突出的小点
  390. chartXRay.ChartAreas[0].Axes[1].MajorTickMark.Enabled = false; //
  391. chartXRay.ChartAreas[0].Axes[1].MajorGrid.LineWidth = 1;
  392. //图表数据区,有多个重叠则循环添加
  393. if (chartXRay.Series.Count == 0)
  394. {
  395. chartXRay.Series.Add(new Series() { Name = "" });
  396. }
  397. chartXRay.Series[0].ChartType = SeriesChartType.Line; //图类型(折线)
  398. chartXRay.Series[0].Points.DataBindXY(XData, YData); //添加数据
  399. chartXRay.Series[0].Label = "";
  400. chartXRay.Series[0].LegendText = "";
  401. //折线段配置
  402. chartXRay.Series[0].Color = Color.Blue; //线条颜色
  403. chartXRay.Series[0].BorderWidth = 1; //线条粗细
  404. chartXRay.Series[0].MarkerBorderColor = Color.Red; //标记点边框颜色
  405. chartXRay.Series[0].MarkerBorderWidth = 1; //标记点边框大小
  406. chartXRay.Series[0].MarkerColor = Color.Red; //标记点中心颜色
  407. chartXRay.Series[0].MarkerSize = 0; //标记点大小
  408. //chartXRay.Series[0].BorderWidth = 500;
  409. //另外
  410. //饼图说明设置,这用来设置饼图每一块的信息显示在什么地方
  411. chartXRay.Series[0]["PieLabelStyle"] = "Outside";//将文字移到外侧
  412. chartXRay.Series[0]["PieLineColor"] = "Black";//绘制黑色的连线。
  413. //柱状图其他设置
  414. chartXRay.Series[0]["DrawingStyle"] = "Emboss"; //设置柱状平面形状
  415. chartXRay.Series[0]["PointWidth"] = "0.1"; //设置柱状大小
  416. }
  417. #endregion
  418. #region 设置按钮事件
  419. private void btnSetInfo_Click(object sender, EventArgs e)
  420. {
  421. if (!IsConnection())
  422. {
  423. //return;
  424. }
  425. //获取响应按钮
  426. Button btnTest = (Button)sender;
  427. try
  428. {
  429. //节点名称与节点参数值
  430. string Name = string.Empty;
  431. string Value = string.Empty;
  432. //判断本地中是否存在文件路径
  433. if (ExistsFile(xmlFilePath))
  434. {
  435. //遍历tabHardwareSet标签中所有的TextBox控件
  436. foreach (Control control in this.tabXRay.Controls)
  437. {
  438. //判断类型名称
  439. if (control is TextBox)
  440. {
  441. Name = (control as TextBox).Name.Substring(2);
  442. if (btnTest.Name.Contains(Name))
  443. {
  444. //判断是否为空与类型
  445. if (!IsNull(((TextBox)control)))
  446. {
  447. ((TextBox)control).Focus();
  448. return;
  449. }
  450. if (!IsType(((TextBox)control).Text, 1))
  451. {
  452. ((TextBox)control).Focus();
  453. return;
  454. }
  455. //获取节点名称与节点参数值
  456. Value = (control as TextBox).Text;
  457. SaveSetting(Name, Value);
  458. }
  459. }
  460. }
  461. //遍历tabHardwareSet标签中所有的TextBox控件
  462. foreach (Control control in this.tabImage.Controls)
  463. {
  464. //判断类型名称
  465. if (control is TextBox)
  466. {
  467. Name = (control as TextBox).Name.Substring(2);
  468. if (btnTest.Name.Contains(Name))
  469. {
  470. //判断是否为空与类型
  471. if (!IsNull(((TextBox)control)))
  472. {
  473. ((TextBox)control).Focus();
  474. return;
  475. }
  476. if (!IsType(((TextBox)control).Text, 1))
  477. {
  478. ((TextBox)control).Focus();
  479. return;
  480. }
  481. //获取节点名称与节点参数值
  482. Value = (control as TextBox).Text;
  483. SaveSetting(Name, Value);
  484. }
  485. }
  486. }
  487. }
  488. else
  489. {
  490. //如果文件不存在,则创建文件
  491. CreateFile(xmlFilePath);
  492. }
  493. }
  494. catch (Exception ex)
  495. {
  496. //记录日志信息
  497. log.Error(ex.Message.ToString());
  498. }
  499. }
  500. #endregion
  501. #region 保存设置
  502. /// <summary>
  503. /// 保存设置
  504. /// </summary>
  505. /// <param name="Name">节点名称</param>
  506. /// <param name="Value">节点参数值</param>
  507. public void SaveSetting(string Name, string Value)
  508. {
  509. try
  510. {
  511. //判断XML文件中是否存在
  512. if (!XMLOperationClass.ExistsXmlInfo(Name))
  513. {
  514. //调用添加XML节点功能
  515. XMLOperationClass.AddXmlInfo(Name, Value);
  516. }
  517. else
  518. {
  519. //调用修改XML节点功能
  520. XMLOperationClass.EditXmlInfo(Name, Value);
  521. }
  522. }
  523. catch (Exception ex)
  524. {
  525. //记录日志信息
  526. log.Error(ex.Message.ToString());
  527. }
  528. }
  529. #endregion
  530. #region 修改设置
  531. public void EditSetting(string Name, string Value)
  532. {
  533. try
  534. {
  535. //调用修改XML节点功能
  536. XMLOperationClass.EditXmlInfo(Name, Value);
  537. }
  538. catch (Exception ex)
  539. {
  540. //记录日志信息
  541. log.Error(ex.Message.ToString());
  542. }
  543. }
  544. #endregion
  545. #region 判断文件路径
  546. /// <summary>
  547. /// 判断文件路径
  548. /// </summary>
  549. /// <param name="path"></param>
  550. /// <returns></returns>
  551. public bool CreateFile(string path)
  552. {
  553. Directory.CreateDirectory(path);
  554. return false;
  555. }
  556. #endregion
  557. #region 判断文件是否存在
  558. /// <summary>
  559. /// 判断文件是否存在
  560. /// </summary>
  561. /// <param name="path">文件路径</param>
  562. /// <returns></returns>
  563. public bool ExistsFile(string path)
  564. {
  565. try
  566. {
  567. if (File.Exists(path))
  568. {
  569. return true;
  570. }
  571. return false;
  572. }
  573. catch (Exception ex)
  574. {
  575. //记录日志信息
  576. log.Error(ex.Message.ToString());
  577. return false;
  578. }
  579. }
  580. #endregion
  581. #region 获取窗体中所有参数
  582. /// <summary>
  583. /// 获取窗体中控件的所有参数
  584. /// </summary>
  585. public void GetWindowsControlValue()
  586. {
  587. try
  588. {
  589. XmlDocument doc = new XmlDocument();
  590. //加载Xml文件
  591. doc.Load(xmlFilePath);
  592. //获取根节点
  593. XmlElement root = doc.DocumentElement;
  594. //获取子节点集合
  595. XmlNodeList mainNodes = root.GetElementsByTagName("parameter");
  596. foreach (XmlNode node in mainNodes)
  597. {
  598. //获取Name属性值
  599. string text = ((XmlElement)node).GetAttribute("Name");
  600. string value = ((XmlElement)node).GetAttribute("Value");
  601. foreach (Control control in this.tabXRay.Controls)
  602. {
  603. //判断类型名称
  604. if (control.Name.Contains(text))
  605. {
  606. if (control is TextBox)
  607. {
  608. ((TextBox)control).Text = value;
  609. }
  610. else if (control is ComboBox)
  611. {
  612. ((ComboBox)control).SelectedValue = value;
  613. }
  614. else if (control is CheckBox)
  615. {
  616. ((CheckBox)control).Checked = text.Equals("1") ? true : false;
  617. }
  618. }
  619. }
  620. foreach (Control control in this.tabImage.Controls)
  621. {
  622. //判断类型名称
  623. if (control.Name.Contains(text))
  624. {
  625. if (control is TextBox)
  626. {
  627. ((TextBox)control).Text = value;
  628. }
  629. else if (control is ComboBox)
  630. {
  631. ((ComboBox)control).SelectedValue = value;
  632. }
  633. else if (control is CheckBox)
  634. {
  635. ((CheckBox)control).Checked = text.Equals("1") ? true : false;
  636. }
  637. }
  638. }
  639. }
  640. }
  641. catch (Exception ex)
  642. {
  643. //记录日志信息
  644. log.Error(ex.Message.ToString());
  645. }
  646. }
  647. #endregion
  648. #region 用户信息提示
  649. /// <summary>
  650. /// 提示
  651. /// </summary>
  652. /// <param name="Message"></param>
  653. private void ShowMessage(int MessageType)
  654. {
  655. string message1 = table["message1"].ToString();
  656. string message2 = table["message2"].ToString();
  657. string message3 = table["message3"].ToString();
  658. string message4 = table["message4"].ToString();
  659. string message5 = table["message5"].ToString();
  660. string message6 = table["message6"].ToString();
  661. string message7 = table["message7"].ToString();
  662. string message8 = table["message8"].ToString();
  663. string message9 = table["message9"].ToString();
  664. string message10 = table["message10"].ToString();
  665. string MessageInfo = string.Empty;
  666. switch (MessageType)
  667. {
  668. case 0:
  669. MessageInfo = message1;
  670. break;
  671. case 1:
  672. MessageInfo = message2;
  673. break;
  674. case 2:
  675. MessageInfo = message3;
  676. break;
  677. case 3:
  678. MessageInfo = message4;
  679. break;
  680. case 4:
  681. MessageInfo = message5;
  682. break;
  683. case 5:
  684. MessageInfo = message6;
  685. break;
  686. case 6:
  687. MessageInfo = message7;
  688. break;
  689. case 7:
  690. MessageInfo = message8;
  691. break;
  692. case 8:
  693. MessageInfo = message9;
  694. break;
  695. case 9:
  696. MessageInfo = message10;
  697. break;
  698. }
  699. MessageBox.Show(MessageInfo, "Tip");
  700. }
  701. #endregion
  702. #region 判断控制内容是否为空 与 判断输入的格式是否正确
  703. /// <summary>
  704. /// 判断控制内容是否为空
  705. /// </summary>
  706. /// <param name="tbContent"></param>
  707. /// <returns></returns>
  708. public bool IsNull(TextBox tbContent)
  709. {
  710. if (tbContent.Text.Trim().Equals(""))
  711. {
  712. //为空提示
  713. ShowMessage(0);
  714. //获取焦点
  715. tbContent.Focus();
  716. return false;
  717. }
  718. return true;
  719. }
  720. /// <summary>
  721. ///
  722. /// </summary>
  723. /// <param name="objValue"></param>
  724. /// <param name="objType"></param>
  725. /// <returns></returns>
  726. public bool IsType(object ObjValue, int ObjType)
  727. {
  728. try
  729. {
  730. switch (ObjType)
  731. {
  732. case 1:
  733. int intValue = Convert.ToInt32(ObjValue);
  734. break;
  735. case 2:
  736. double douValue = Convert.ToDouble(ObjValue);
  737. break;
  738. case 3:
  739. float floValue = Convert.ToSingle(ObjValue);
  740. break;
  741. }
  742. return true;
  743. }
  744. catch (Exception)
  745. {
  746. //为空提示
  747. ShowMessage(7);
  748. return false;
  749. }
  750. }
  751. /// <summary>
  752. /// 判断是否连接
  753. /// </summary>
  754. /// <returns></returns>
  755. public bool IsConnection()
  756. {
  757. if (ConnectionState)
  758. {
  759. return true;
  760. }
  761. return false;
  762. }
  763. #endregion
  764. private void ControllerSettingForm_FormClosing(object sender, FormClosingEventArgs e)
  765. {
  766. }
  767. private void tabSetting_SelectedIndexChanged(object sender, EventArgs e)
  768. {
  769. try
  770. {
  771. if (ScanThread != null)
  772. {
  773. ScanThread.Abort();
  774. }
  775. if (EDSThread != null)
  776. {
  777. EDSThread.Abort();
  778. }
  779. if (tabSetting.SelectedIndex == 0)
  780. {
  781. EDSInit();
  782. }
  783. }
  784. catch (Exception)
  785. {
  786. }
  787. }
  788. private void btnSaveImage_Click(object sender, EventArgs e)
  789. {
  790. if (bitmap != null)
  791. {
  792. string fileName = LogPath + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpeg";
  793. bitmap.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
  794. }
  795. }
  796. private void btnPointXRay_Click(object sender, EventArgs e)
  797. {
  798. GetPointXRay();
  799. }
  800. protected void GetPointXRay()
  801. {
  802. try
  803. {
  804. string str = table["str1"].ToString();
  805. btnDisplayXRay.Enabled = false;
  806. btnDisplayXRay.Refresh();
  807. btnPointXRay.Text = str;
  808. btnPointXRay.Enabled = false;
  809. btnPointXRay.Refresh();
  810. btnAreaRay.Enabled = false;
  811. btnAreaRay.Refresh();
  812. btnClearData.Enabled = false;
  813. btnClearData.Refresh();
  814. InitXRayData();
  815. if (ConnectionSem(connectionEnumType.EDSMultiPointXRay))
  816. {
  817. if (EDSInit())
  818. {
  819. //图像数据
  820. uint[] a_XrayData = new uint[2000];
  821. uint a_Milliseconds = 0;
  822. //采集时间
  823. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  824. //采集XRay数据
  825. List<COTSParticleClr> cOTSParticleClrs = new List<COTSParticleClr>();
  826. for (int i = 0; i < 5; i++)
  827. {
  828. COTSParticleClr cOTSParticle = new COTSParticleClr();
  829. CPosXrayClr cPosXray = new CPosXrayClr();
  830. cOTSParticle.SetXray(cPosXray);
  831. cOTSParticle.SetXRayPos(new Point(100 + i, 100 + i));
  832. cOTSParticleClrs.Add(cOTSParticle);
  833. }
  834. m_EDSHardwareMgr.SetResolution(int.Parse(tbRWidth.Text), int.Parse(tbRHeight.Text));
  835. bool result=m_EDSHardwareMgr.GetXRayByParts(cOTSParticleClrs, a_Milliseconds, false);
  836. if(!result)
  837. {
  838. log.Error("m_EDSHardwareMgr.GetXRayByPoints failed!");
  839. }
  840. int[] XData = new int[2000];
  841. uint nXrayCount = 0;
  842. for (int j = 0; j < 5; j++)
  843. {
  844. a_XrayData = cOTSParticleClrs[j].GetXray().GetXrayData();
  845. for (int i = 1; i <= 2000; i++)
  846. {
  847. XData[i - 1] = i;
  848. nXrayCount += a_XrayData[i - 1];
  849. }
  850. }
  851. //绑定数据源
  852. chartData(XData, a_XrayData);
  853. //显示Xray计数
  854. lbXrayCount.Text = nXrayCount.ToString();
  855. }
  856. }
  857. log.Info("Multipoint collection succeeded!");
  858. }
  859. catch (Exception ex)
  860. {
  861. //记录日志
  862. log.Error(ex.Message.ToString());
  863. }
  864. finally
  865. {
  866. string str = table["btnpointxray"].ToString();
  867. btnPointXRay.Text = str;
  868. btnPointXRay.Enabled = true;
  869. btnPointXRay.Refresh();
  870. btnDisplayXRay.Enabled = true;
  871. btnDisplayXRay.Refresh();
  872. btnAreaRay.Enabled = true;
  873. btnAreaRay.Refresh();
  874. btnClearData.Enabled = true;
  875. btnClearData.Refresh();
  876. }
  877. }
  878. private void btnAreaRay_Click(object sender, EventArgs e)
  879. {
  880. try
  881. {
  882. string str = table["str1"].ToString();
  883. btnDisplayXRay.Enabled = false;
  884. btnDisplayXRay.Refresh();
  885. btnPointXRay.Enabled = false;
  886. btnPointXRay.Refresh();
  887. btnAreaRay.Text = str;
  888. btnAreaRay.Enabled = false;
  889. btnAreaRay.Refresh();
  890. btnClearData.Enabled = false;
  891. btnClearData.Refresh();
  892. InitXRayData();
  893. if (ConnectionSem(connectionEnumType.EDSAreaXRay))
  894. {
  895. if (EDSInit())
  896. {
  897. //图像数据
  898. uint[] a_XrayData = new uint[2000];
  899. uint a_Milliseconds = 0;
  900. //采集时间
  901. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  902. //采集XRay数据
  903. var fea = new COTSFeatureClr();
  904. var segs = new List<COTSSegmentClr>();
  905. segs.Add(new COTSSegmentClr(5, 10, 12));
  906. segs.Add(new COTSSegmentClr(6, 10, 12));
  907. segs.Add(new COTSSegmentClr(7, 10, 12));
  908. fea.SetSegmentsList(segs, false);
  909. string ele = "";
  910. //设置图像分辨率
  911. int width = 0;
  912. int height = 0;
  913. //获取宽度
  914. //width = Convert.ToInt32(tbRWidth.Text);
  915. //height = Convert.ToInt32(tbRHeight.Text);
  916. //m_EDSHardwareMgr.SetResolution(width, height);
  917. bool isTrue = GetXRayBySingleFeature(a_Milliseconds, fea, ref a_XrayData,ref ele, false);
  918. int[] XData = new int[2000];
  919. uint nXrayCount = 0;
  920. for (int i = 1; i <= 2000; i++)
  921. {
  922. XData[i - 1] = i;
  923. nXrayCount += a_XrayData[i - 1];
  924. }
  925. //绑定数据源
  926. chartData(XData, a_XrayData);
  927. //显示Xray计数
  928. lbXrayCount.Text = nXrayCount.ToString();
  929. }
  930. }
  931. }
  932. catch (Exception ex)
  933. {
  934. //记录日志
  935. log.Error(ex.Message.ToString());
  936. }
  937. finally
  938. {
  939. string str = table["btnarearay"].ToString();
  940. btnPointXRay.Enabled = true;
  941. btnPointXRay.Refresh();
  942. btnDisplayXRay.Enabled = true;
  943. btnDisplayXRay.Refresh();
  944. btnAreaRay.Text = str;
  945. btnAreaRay.Enabled = true;
  946. btnAreaRay.Refresh();
  947. btnClearData.Enabled = true;
  948. btnClearData.Refresh();
  949. }
  950. }
  951. public bool GetXRayBySingleFeature(uint a_nXRayAQTime, COTSFeatureClr fea, ref uint[] a_XrayData, ref string ele, bool a_bElementInfo)
  952. {
  953. string deviceType = FileHelper.GetXMLInformations("EDSName");
  954. var semtype = FileHelper.GetXMLInformations("SemControllerName");
  955. var eds = EDSController.GetEDSController(semtype, deviceType, Convert.ToInt32(tbRWidth.Text),Convert.ToInt32(tbRHeight.Text),5000,true,"");
  956. var part = new COTSParticleClr();
  957. part.SetFeature(fea);
  958. var parts = new List<COTSParticleClr>();
  959. parts.Add(part);
  960. eds.GetXRayByFeatures(parts, a_nXRayAQTime, a_bElementInfo);
  961. a_XrayData = parts[0].GetXray().GetXrayData();
  962. ele = parts[0].GetXray().GetQuantifiedElementsStr();
  963. return true;
  964. }
  965. private void btnClearData_Click(object sender, EventArgs e)
  966. {
  967. try
  968. {
  969. InitXRayData();
  970. }
  971. catch (Exception ex)
  972. {
  973. //记录日志
  974. log.Error(ex.Message.ToString());
  975. }
  976. }
  977. public void InitXRayData()
  978. {
  979. try
  980. {
  981. //图像数据
  982. uint[] a_XrayData = new uint[2000];
  983. uint a_Milliseconds = 0;
  984. //采集时间
  985. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  986. //采集XRay数据
  987. int[] XData = new int[2000];
  988. uint nXrayCount = 0;
  989. for (int i = 1; i <= 2000; i++)
  990. {
  991. XData[i - 1] = i;
  992. nXrayCount += a_XrayData[i - 1];
  993. }
  994. //绑定数据源
  995. chartData(XData, a_XrayData);
  996. //显示Xray计数
  997. lbXrayCount.Text = nXrayCount.ToString();
  998. chartXRay.Refresh();
  999. ConnectionState = false;
  1000. log.Info("Cleared successfully!");
  1001. }
  1002. catch (Exception ex)
  1003. {
  1004. //记录日志
  1005. log.Error(ex.Message.ToString());
  1006. }
  1007. }
  1008. #region 获取元素分析
  1009. private void btnEanalysis_Click(object sender, EventArgs e)
  1010. {
  1011. try
  1012. {
  1013. string str = table["str1"].ToString();
  1014. btnDisplayXRay.Enabled = false;
  1015. btnDisplayXRay.Refresh();
  1016. btnPointXRay.Enabled = false;
  1017. btnPointXRay.Refresh();
  1018. btnAreaRay.Enabled = false;
  1019. btnAreaRay.Refresh();
  1020. btnEanalysis.Text = str;
  1021. btnEanalysis.Enabled = false;
  1022. btnEanalysis.Refresh();
  1023. btnClearData.Enabled = false;
  1024. btnClearData.Refresh();
  1025. InitXRayData();
  1026. if (ConnectionSem(connectionEnumType.EDSAreaXRay))
  1027. {
  1028. if (EDSInit())
  1029. {
  1030. //图像数据
  1031. uint[] a_XrayData = new uint[2000];
  1032. uint a_Milliseconds = 0;
  1033. //采集时间
  1034. a_Milliseconds = Convert.ToUInt32(tbCollectionTime.Text);
  1035. //采集元素分析数据
  1036. ValueType a_nElementNum = 0;
  1037. string a_strResult = string.Empty;
  1038. try
  1039. {
  1040. GetXRayElements(a_Milliseconds, ref a_XrayData, ref a_nElementNum, ref a_strResult);
  1041. }
  1042. catch (Exception ex)
  1043. {
  1044. log.Error("ControllerSettingForm_btnEanalysis_Click:--GetXRayElements()_Exception" + ex.Message.ToString());
  1045. }
  1046. int[] XData = new int[2000];
  1047. uint nXrayCount = 0;
  1048. for (int i = 1; i <= 2000; i++)
  1049. {
  1050. XData[i - 1] = i;
  1051. nXrayCount += a_XrayData[i - 1];
  1052. }
  1053. //绑定数据源
  1054. chartData(XData, a_XrayData);
  1055. //显示Xray计数
  1056. lbXrayCount.Text = nXrayCount.ToString();
  1057. //显示元素分析结果内容
  1058. ShowXRayElementResultForm showXRayElementResultForm = new ShowXRayElementResultForm((int)a_nElementNum, a_strResult);
  1059. showXRayElementResultForm.ShowDialog();
  1060. }
  1061. }
  1062. log.Info("Element analysis success!");
  1063. }
  1064. catch (Exception ex)
  1065. {
  1066. //记录日志
  1067. log.Error(ex.Message.ToString());
  1068. }
  1069. finally
  1070. {
  1071. string str = table["btneanalysis"].ToString();
  1072. btnPointXRay.Enabled = true;
  1073. btnPointXRay.Refresh();
  1074. btnDisplayXRay.Enabled = true;
  1075. btnDisplayXRay.Refresh();
  1076. btnAreaRay.Enabled = true;
  1077. btnAreaRay.Refresh();
  1078. btnEanalysis.Text = str;
  1079. btnEanalysis.Enabled = true;
  1080. btnEanalysis.Refresh();
  1081. btnClearData.Enabled = true;
  1082. btnClearData.Refresh();
  1083. }
  1084. }
  1085. public bool GetXRayElements(uint a_nXRayAQTime, ref uint[] a_XrayData, ref ValueType a_nElementNum, ref string a_strResult)
  1086. {
  1087. string deviceType = FileHelper.GetXMLInformations("EDSName");
  1088. var semtype = FileHelper.GetXMLInformations("SemControllerName");
  1089. var eds = EDSController.GetEDSController(semtype, deviceType, Convert.ToInt32(tbRWidth.Text), Convert.ToInt32(tbRHeight.Text), 5000,true,"");
  1090. var part = new COTSParticleClr();
  1091. var pos = new Point(10, 10);
  1092. part.SetXRayPos(pos);
  1093. var parts = new List<COTSParticleClr>();
  1094. parts.Add(part);
  1095. eds.GetXRayByParts(parts, a_nXRayAQTime, true);
  1096. a_XrayData = parts[0].GetXray().GetXrayData();
  1097. a_strResult = parts[0].GetXray().GetQuantifiedElementsStr();
  1098. a_nElementNum = parts[0].GetXray().GetElementQuantifyData().Count;
  1099. return true;
  1100. }
  1101. #endregion
  1102. private void btn_continuousshot_Click(object sender, EventArgs e)
  1103. {
  1104. btn_continuousshot.Enabled = false;
  1105. btn_confirm.Enabled = false;
  1106. this.Refresh();
  1107. Graphics g = panel2.CreateGraphics();
  1108. //g.SmoothingMode = SmoothingMode.HighSpeed;
  1109. //g.CompositingQuality = CompositingQuality.HighSpeed;
  1110. g.PixelOffsetMode = PixelOffsetMode.HighQuality;//高质量低速度呈现
  1111. g.SmoothingMode = SmoothingMode.HighQuality;// 指定高质量、低速度呈现。
  1112. g.InterpolationMode = InterpolationMode.NearestNeighbor;
  1113. ISemController m_Sem = SemController.GetSEMController();
  1114. bool flag = m_Sem.Connect();
  1115. //电镜设置对象
  1116. var cfun = ScanController.GetScanController();
  1117. bool IsConnec = cfun.Init();
  1118. double Magnification = 0;
  1119. m_Sem.GetMagnification(ref Magnification);
  1120. //double a_dScanFieldSizeX = 0;
  1121. //double a_dScanFieldSizeY = 0;
  1122. //m_Sem.GetScanFieldSize(ref a_dScanFieldSizeX,ref a_dScanFieldSizeY);
  1123. double scanFieldSize100 = 0;
  1124. double.TryParse(tB_scanFieldSize100.Text, out scanFieldSize100);
  1125. double scanFieldSize = scanFieldSize100 * 100 / Magnification;
  1126. double PositionX = 0;
  1127. double PositionY = 0;
  1128. double PositionR = 0;
  1129. m_Sem.GetSemPositionXY(ref PositionX, ref PositionY, ref PositionR);
  1130. double PositionXO = PositionX;
  1131. double PositionYO = PositionY;
  1132. //double PositionR0 = PositionR;
  1133. int width = 1024;
  1134. int height = 768;
  1135. //设置图像分辨率
  1136. if (cb_imageresolution.Text.Trim() == "")
  1137. {
  1138. MessageBox.Show("imageresolution cannot be null!");
  1139. return;
  1140. }
  1141. else
  1142. {
  1143. width = Convert.ToInt32(cb_imageresolution.Text.Split('*')[0]);
  1144. height = Convert.ToInt32(cb_imageresolution.Text.Split('*')[1]);
  1145. }
  1146. this.Refresh();
  1147. double scanFieldSizeH = scanFieldSize * height / width;
  1148. m_Sem.SetScanExternal(true);
  1149. try
  1150. {
  1151. for (int i = 0; i < 4; i++)
  1152. {
  1153. if (i == 0)
  1154. {
  1155. }
  1156. else if (i == 1)
  1157. {
  1158. switch (cb_Xdirection.SelectedItem.ToString())
  1159. {
  1160. case "RIGHT_TOWARD": PositionX += scanFieldSize; break;
  1161. default: PositionX -= scanFieldSize; break;
  1162. }
  1163. m_Sem.MoveSEMToPoint(PositionX, PositionY);
  1164. }
  1165. else if (i == 2)
  1166. {
  1167. switch (cb_Ydirection.SelectedItem.ToString())
  1168. {
  1169. case "UP_TOWARD": PositionY -= scanFieldSizeH; break;
  1170. default: PositionY += scanFieldSizeH; break;
  1171. }
  1172. m_Sem.MoveSEMToPoint(PositionX, PositionY);
  1173. }
  1174. else
  1175. {
  1176. switch (cb_Xdirection.SelectedItem.ToString())
  1177. {
  1178. case "RIGHT_TOWARD": PositionX -= scanFieldSize; break;
  1179. default: PositionX += scanFieldSize; break;
  1180. }
  1181. m_Sem.MoveSEMToPoint(PositionX, PositionY);
  1182. }
  1183. //Thread.Sleep(50);
  1184. byte[] ImageByte = new byte[width * height];
  1185. bool resultValue = GetScanImage(width, height, "2", ref ImageByte);
  1186. Size size = new Size(panel2.Width / 2, panel2.Height / 2);
  1187. if (resultValue)
  1188. {
  1189. if (ImageByte != null)
  1190. {
  1191. var bitmap = CImageHandler.ToGrayBitmap(ImageByte, width, height);
  1192. switch (i)
  1193. {
  1194. case 0:
  1195. Point point0 = new Point(0,0);
  1196. Rectangle rect0 = new Rectangle(point0,size);
  1197. g.DrawImage(bitmap,rect0);
  1198. break;
  1199. case 1:
  1200. Point point1 = new Point(panel2.Width / 2, 0);
  1201. Rectangle rect1 = new Rectangle(point1, size);
  1202. g.DrawImage(bitmap, rect1);
  1203. break;
  1204. case 2:
  1205. Point point2 = new Point(panel2.Width/2, panel2.Height / 2);
  1206. Rectangle rect2 = new Rectangle(point2, size);
  1207. g.DrawImage(bitmap, rect2);
  1208. break;
  1209. case 3:
  1210. Point point3 = new Point(0, panel2.Height / 2);
  1211. Rectangle rect3 = new Rectangle(point3, size);
  1212. g.DrawImage(bitmap, rect3);
  1213. break;
  1214. }
  1215. //this.Refresh();
  1216. }
  1217. }
  1218. }
  1219. m_Sem.MoveSEMToPoint(PositionXO, PositionYO);
  1220. }
  1221. catch (Exception ex)
  1222. {
  1223. log.Error("continuousshot--错误信息:" + ex.ToString());
  1224. }
  1225. finally
  1226. {
  1227. m_Sem.SetScanExternal(false);
  1228. btn_continuousshot.Enabled = true;
  1229. btn_confirm.Enabled = true;
  1230. btn_continuousshot.Refresh();
  1231. g.Dispose();
  1232. }
  1233. }
  1234. bool ReadConfigXml(string xmlpath,ref string xAxisDir,ref string yAxisDir,ref string scanFieldSize)
  1235. {
  1236. try
  1237. {
  1238. XmlDocument xmlDocument = new XmlDocument();
  1239. xmlDocument.Load(xmlpath);
  1240. XmlNodeList nodeList = xmlDocument.SelectSingleNode("XMLData").ChildNodes;
  1241. foreach (XmlNode xn in nodeList)
  1242. {
  1243. XmlElement xe = (XmlElement)xn;
  1244. if (xe.GetAttribute("RegName") == "StageData")
  1245. {
  1246. scanFieldSize=xe.GetAttribute("scanFieldSize");
  1247. xAxisDir=xe.GetAttribute("xAxisDir");
  1248. yAxisDir=xe.GetAttribute("yAxisDir");
  1249. break;
  1250. }
  1251. }
  1252. }
  1253. catch (Exception ex)
  1254. {
  1255. MessageBox.Show(ex.ToString());
  1256. return false;
  1257. }
  1258. return true;
  1259. }
  1260. bool SaveConfigXml(string xmlpath, string xAxisDir, string yAxisDir, string scanFieldSize)
  1261. {
  1262. try
  1263. {
  1264. XmlDocument xmlDocument = new XmlDocument();
  1265. xmlDocument.Load(xmlpath);
  1266. XmlNodeList nodeList = xmlDocument.SelectSingleNode("XMLData").ChildNodes;
  1267. foreach (XmlNode xn in nodeList)
  1268. {
  1269. XmlElement xe = (XmlElement)xn;
  1270. if (xe.GetAttribute("RegName") == "StageData")
  1271. {
  1272. xe.SetAttribute("scanFieldSize", scanFieldSize);
  1273. xe.SetAttribute("xAxisDir", xAxisDir);
  1274. xe.SetAttribute("yAxisDir", yAxisDir);
  1275. break;
  1276. }
  1277. }
  1278. xmlDocument.Save(xmlpath);
  1279. }
  1280. catch (Exception ex)
  1281. {
  1282. MessageBox.Show(ex.ToString());
  1283. return false;
  1284. }
  1285. return true;
  1286. }
  1287. private void btn_confirm_Click(object sender, EventArgs e)
  1288. {
  1289. double dscanFieldSize100 = 0;
  1290. if (cb_Xdirection.Text.Trim() != null && cb_imageresolution.Text.Trim() != null && cb_Ydirection.Text.Trim() != null && double.TryParse(tB_scanFieldSize100.Text, out dscanFieldSize100))
  1291. {
  1292. string xmlpath = Application.StartupPath + @"\Config\SysData\OTSProgMgrParam.pmf";
  1293. string xAxisDir = "";
  1294. string yAxisDir = "";
  1295. switch (cb_Xdirection.SelectedItem.ToString())
  1296. {
  1297. case "LEFT_TOWARD":
  1298. xAxisDir = "0:LEFT_TOWARD";
  1299. break;
  1300. default:
  1301. xAxisDir = "1:RIGHT_TOWARD";
  1302. break;
  1303. }
  1304. switch(cb_Ydirection.Text)
  1305. {
  1306. case "UP_TOWARD":
  1307. yAxisDir="0:" + cb_Ydirection.Text;
  1308. break;
  1309. default:
  1310. yAxisDir = "1:DOWN_TOWARD";
  1311. break;
  1312. }
  1313. SaveConfigXml(xmlpath, xAxisDir, yAxisDir, tB_scanFieldSize100.Text);
  1314. }
  1315. else
  1316. {
  1317. MessageBox.Show("Please check params!");
  1318. }
  1319. }
  1320. private void btn_Recommendedconfiguration_Click(object sender, EventArgs e)
  1321. {
  1322. if (recommendedConfiguration == null || recommendedConfiguration.IsDisposed)
  1323. {
  1324. recommendedConfiguration = new RecommendedConfiguration(Language.ReadDefaultLanguage());
  1325. recommendedConfiguration.Show();
  1326. }
  1327. else
  1328. {
  1329. recommendedConfiguration.Activate();
  1330. }
  1331. }
  1332. void DrawFrames()
  1333. {
  1334. Graphics g = panel2.CreateGraphics();
  1335. g.SmoothingMode = SmoothingMode.HighQuality;
  1336. Pen pen = new Pen(Color.Black);
  1337. g.DrawLine(pen,new Point(panel2.Width/2,0),new Point(panel2.Width / 2, panel2.Height));
  1338. g.DrawLine(pen, new Point(0, panel2.Height/2), new Point(panel2.Width, panel2.Height/2));
  1339. pen.Dispose();
  1340. g.Dispose();
  1341. }
  1342. private void panel2_Paint(object sender, PaintEventArgs e)
  1343. {
  1344. DrawFrames();
  1345. }
  1346. void InitEvent()
  1347. {
  1348. string edsType = FileHelper.GetXMLInformations("EDSName");
  1349. string SemType = FileHelper.GetXMLInformations("SemControllerName");
  1350. if (SemType == "FEI")
  1351. {
  1352. if (edsType == "FEI")
  1353. {
  1354. cb_imageresolution.SelectedIndex = 2;
  1355. }
  1356. else if (edsType == "Oxford")
  1357. {
  1358. cb_imageresolution.SelectedIndex = 0;
  1359. }
  1360. else if (edsType == "Bruker")
  1361. {
  1362. cb_imageresolution.SelectedIndex = 1;
  1363. }
  1364. else if (edsType == "OffLine")
  1365. {
  1366. cb_imageresolution.SelectedIndex = 1;
  1367. }
  1368. else if (edsType == "PicoSmart")
  1369. {
  1370. cb_imageresolution.SelectedIndex = 1;
  1371. }
  1372. cb_Xdirection.SelectedIndex = 1;
  1373. cb_Ydirection.SelectedIndex = 0;
  1374. }
  1375. }
  1376. }
  1377. }