ControllerSettingForm.cs 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  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();
  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. else if (edsType == "PicoSmart")
  1349. {
  1350. cb_imageresolution.SelectedIndex = 1;
  1351. }
  1352. cb_Xdirection.SelectedIndex = 1;
  1353. cb_Ydirection.SelectedIndex = 0;
  1354. }
  1355. }
  1356. }
  1357. }