ControllerSettingForm.cs 53 KB

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