ControllerSettingForm.cs 52 KB

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