ControllerSettingForm.cs 53 KB

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