frmReMeasure.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using OTSDataType;
  2. using OTSCommon.Model;
  3. using OTSMeasureApp;
  4. using OTSModelSharp.ResourceManage;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using OTSIncAReportGrids.OTSIncAReportGridsFuncation;
  15. using System.Threading;
  16. using static OTSDataType.otsdataconst;
  17. using OTSModelSharp.ServiceCenter;
  18. namespace OTSIncAReportApp._1_UI
  19. {
  20. public partial class frmReMeasure : Form
  21. {
  22. OTSReportGridsFun m_OTSIncAReportGridsFun;
  23. List<Particle> SelectedParticles;
  24. ResultFile resultFile;
  25. int nBrukerDwellTime = 0;
  26. private delegate void DelSetPro(string txt, RichTextBox richTextBox);//设置进度条进度的委托方法
  27. /// <summary>
  28. /// 设置进度。
  29. /// </summary>
  30. /// <param name="pro"></param>
  31. /// <param name="proBar"></param>
  32. private void SetProgressMessage(string txt, RichTextBox richTextBox)
  33. {
  34. //如果当前调用方不是创建控件的一方,则需要使用this.Invoke()
  35. //在这里,ProgressBar控件是由主线程创建的,所以子线程要对该控件进行操作
  36. //必须执行this.InvokeRequired进行判断。
  37. if (this.InvokeRequired)
  38. {
  39. DelSetPro setPro = new DelSetPro(SetProgressMessage);
  40. this.Invoke(setPro, new object[] { txt, richTextBox });
  41. }
  42. else
  43. {
  44. WriteRictBox(txt);
  45. }
  46. }
  47. #region 将文本追加到RictBox的尾部上
  48. /// <summary>
  49. /// 将文本追加到RictBox的尾部上
  50. /// </summary>
  51. public void WriteRictBox(string in_str)
  52. {
  53. //追加到rictbox尾部
  54. richTextBox_process.AppendText("[" + DateTime.Now.Hour.ToString() + ":"
  55. + DateTime.Now.Minute.ToString() + ":"
  56. + DateTime.Now.Second.ToString() + "]"
  57. + in_str + Environment.NewLine);
  58. richTextBox_process.ScrollToCaret();
  59. }
  60. #endregion
  61. public frmReMeasure(OTSReportGridsFun m_OTSIncAReportGridsFun, List<Particle> SelectedParticles, ResultFile resultFile)
  62. {
  63. InitializeComponent();
  64. this.m_OTSIncAReportGridsFun = m_OTSIncAReportGridsFun;
  65. this.SelectedParticles = SelectedParticles;
  66. this.resultFile = resultFile;
  67. }
  68. private void frmReMeasure_Load(object sender, EventArgs e)
  69. {
  70. //图像扫描精度
  71. IDC_COMBO_IMGSCANSPEED.Items.Clear();
  72. foreach (otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS enum_one in Enum.GetValues(typeof(otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS)))
  73. {
  74. ComboBoxItem cbi = new ComboBoxItem();
  75. cbi.Text = GetScanSpeedString(enum_one);
  76. cbi.Value = (int)enum_one;
  77. IDC_COMBO_IMGSCANSPEED.Items.Add(cbi);
  78. }
  79. IDC_COMBO_IMGSCANSPEED.SelectedIndex = (int)otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.high;
  80. //X-Ray扫描方式
  81. IDC_COMBO_XRAYSCANMODE.Items.Clear();
  82. foreach (otsdataconst.OTS_X_RAY_SCAN_MODE enum_one in Enum.GetValues(typeof(otsdataconst.OTS_X_RAY_SCAN_MODE)))
  83. {
  84. ComboBoxItem cbi = new ComboBoxItem();
  85. cbi.Text = GetXRayScanModeIdString(enum_one);
  86. cbi.Value = (int)enum_one;
  87. IDC_COMBO_XRAYSCANMODE.Items.Add(cbi);
  88. }
  89. IDC_COMBO_XRAYSCANMODE.SelectedIndex = (int)otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode;
  90. //旧放大倍数
  91. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
  92. Dictionary<string, object> SEMDataMsr = (Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["SEMDataMsr"]);
  93. double ScanFieldSize = double.Parse(SEMDataMsr["ScanFieldSize"].ToString());
  94. double ScanFieldSize100 = double.Parse(SEMDataMsr["ScanFieldSize100"].ToString());
  95. double oldMag = Math.Round((ScanFieldSize100 / ScanFieldSize) * 100, 2);
  96. LB_OLDMAGVALUE.Text = oldMag.ToString();
  97. NUD_MAG.Minimum = (decimal)oldMag;
  98. NUD_MAG.Value = (decimal)(oldMag * 2);
  99. }
  100. public string GetScanSpeedString(otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS a_nScanSpeed)
  101. {
  102. string strScanSpeedId = "";
  103. if (a_nScanSpeed >= otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.low && a_nScanSpeed <= otsdataconst.OTS_IMAGE_SCANSPEED_OPTIONS.high)
  104. {
  105. strScanSpeedId = XmlResourceData.GetInstance().GetStringByKey(ResourceID.GrpOtherParam, ResourceID.IDS_SCANSPEED + (int)a_nScanSpeed);
  106. }
  107. return strScanSpeedId;
  108. }
  109. public static string GetXRayScanModeIdString(otsdataconst.OTS_X_RAY_SCAN_MODE a_nXRayScanMode)
  110. {
  111. string strXRayScanModeId = "";
  112. if (a_nXRayScanMode >= otsdataconst.OTS_X_RAY_SCAN_MODE.PointMode && a_nXRayScanMode <= otsdataconst.OTS_X_RAY_SCAN_MODE.FeatureMode)
  113. {
  114. strXRayScanModeId = XmlResourceData.GetInstance().GetStringByKey(ResourceID.GrpOtherParam, ResourceID.IDS_XRAYSCANMODE + (int)a_nXRayScanMode);
  115. }
  116. return strXRayScanModeId;
  117. }
  118. private void BTN_NO_Click(object sender, EventArgs e)
  119. {
  120. this.Close();
  121. }
  122. private void BTN_YES_Click(object sender, EventArgs e)
  123. {
  124. //参数定义
  125. int nBrukerDwellTimeId = 3;
  126. switch (IDC_COMBO_IMGSCANSPEED.SelectedIndex)
  127. {
  128. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.low:
  129. nBrukerDwellTimeId = 3;
  130. break;
  131. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.meddium:
  132. nBrukerDwellTimeId = 4;
  133. break;
  134. case (int)OTS_IMAGE_SCANSPEED_OPTIONS.high:
  135. nBrukerDwellTimeId = 5;
  136. break;
  137. default:
  138. nBrukerDwellTimeId = 3;
  139. break;
  140. }
  141. nBrukerDwellTime = DWELLTIME_BRUKER_VALUES[nBrukerDwellTimeId];
  142. bgw_process.RunWorkerAsync();
  143. }
  144. private Point GetPartPoint(string leftOrRight, string downOrUp, string ScanFieldSize, Particle particle)
  145. {
  146. Point point = new Point();
  147. if (leftOrRight == "RIGHT")
  148. {
  149. point.X = particle.SEMPosX - int.Parse(ScanFieldSize) / 2 + particle.PosX;
  150. }
  151. else
  152. {
  153. point.X = particle.SEMPosX + int.Parse(ScanFieldSize) / 2 + particle.PosX;
  154. }
  155. if (downOrUp == "UP")
  156. {
  157. point.Y = particle.SEMPosY + int.Parse(ScanFieldSize) / 2 + particle.PosY;
  158. }
  159. else
  160. {
  161. point.Y = particle.SEMPosY - int.Parse(ScanFieldSize) / 2 + particle.PosY;
  162. }
  163. return point;
  164. }
  165. private void bgw_process_DoWork(object sender, DoWorkEventArgs e)
  166. {
  167. //颗粒信息
  168. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["Sample"])["Members"]);
  169. Dictionary<string, object> imageScanParam = (Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["MsrParams"])["Members"])["ImageScanParam"];
  170. string ImageResolution = imageScanParam["ImageResolution"].ToString();
  171. int width = int.Parse(ImageResolution.Split('_')[1]);
  172. int height = int.Parse(ImageResolution.Split('_')[2]);
  173. Dictionary<string, object> SEMStageData = (Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"];
  174. string ScanFieldSize = SEMStageData["scanFieldSize"].ToString();
  175. string leftOrRight = SEMStageData["xAxisDir"].ToString().Split('_')[0];
  176. string downOrUp = SEMStageData["yAxisDir"].ToString().Split('_')[0];
  177. #region 按帧图分类
  178. //Dictionary<int, List<Particle>> keyValues = new Dictionary<int, List<Particle>>();
  179. //ParticleList.OrderBy(a => a.FieldId).ToList();
  180. //for (int i = 0; i < ParticleList.Count; i++)
  181. //{
  182. // if (keyValues.ContainsKey(ParticleList[i].FieldId))
  183. // {
  184. // List<Particle> Particles = keyValues[ParticleList[i].FieldId];
  185. // Particles.Add(ParticleList[i]);
  186. // keyValues[ParticleList[i].FieldId] = Particles;
  187. // }
  188. // else
  189. // {
  190. // List<Particle> Particles = new List<Particle>();
  191. // Particles.Add(ParticleList[i]);
  192. // keyValues.Add(ParticleList[i].FieldId, Particles);
  193. // }
  194. //}
  195. #endregion
  196. //第一步,连接电镜
  197. m_OTSIncAReportGridsFun.Connection_ForParticlesGrid();
  198. Thread.Sleep(500);
  199. SetProgressMessage("设置放大倍数", richTextBox_process);
  200. if (!m_OTSIncAReportGridsFun.SetMagnification((double)NUD_MAG.Value))
  201. {
  202. SetProgressMessage("设置放大倍数失败", richTextBox_process);
  203. }
  204. for (int i = 0; i < SelectedParticles.Count; i++)
  205. {
  206. SetProgressMessage("开始处理颗粒:" + (i + 1), richTextBox_process);
  207. if (m_OTSIncAReportGridsFun.m_SEMConnectionState == true)
  208. {
  209. Point point = GetPartPoint(leftOrRight, downOrUp, ScanFieldSize, SelectedParticles[i]);
  210. SetProgressMessage("移动到颗粒中心位置", richTextBox_process);
  211. if (!m_OTSIncAReportGridsFun.MoveSemToPointXY_ForParticlesGrid(point.X, point.Y))
  212. {
  213. SetProgressMessage("移动到颗粒中心位置失败", richTextBox_process);
  214. }
  215. SetProgressMessage("拍图", richTextBox_process);
  216. byte[] ImageByte = new byte[width * height];
  217. if (!m_OTSIncAReportGridsFun.AcquireBSEImage(width, height, nBrukerDwellTime, ref ImageByte))
  218. {
  219. SetProgressMessage("拍图失败", richTextBox_process);
  220. }
  221. bgw_process.ReportProgress(0, CImageHandler.ToGrayBitmap(ImageByte, width, height));
  222. SetProgressMessage("寻找新位置颗粒信息", richTextBox_process);
  223. if (!m_OTSIncAReportGridsFun.AcquireBSEImage(width, height, nBrukerDwellTime, ref ImageByte))
  224. {
  225. SetProgressMessage("拍图失败", richTextBox_process);
  226. }
  227. }
  228. }
  229. Thread.Sleep(500);
  230. }
  231. private void bgw_process_ProgressChanged(object sender, ProgressChangedEventArgs e)
  232. {
  233. switch (e.ProgressPercentage)
  234. {
  235. case 0: pictureBox_part.Image = (Bitmap)e.UserState; break;
  236. default:
  237. break;
  238. }
  239. }
  240. }
  241. }