OTSReportGridsFun.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. 
  2. using OTSCLRINTERFACE;
  3. using OTSCommon.DBOperate.Model;
  4. using OTSIncAReportApp.SysMgrTools;
  5. using OTSModelSharp.ServiceCenter;
  6. using ServiceInterface;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.Drawing;
  11. using System.Linq;
  12. namespace OTSIncAReportGrids.OTSIncAReportGridsFuncation
  13. {
  14. public class OTSReportGridsFun
  15. {
  16. #region 定义变量
  17. //为了加快颗粒列表抠图的速度,这里保存一个全局变量
  18. public List<Field> m_list_COTSFieldMgrClr = null;
  19. //是否已经连接到了电镜
  20. public bool m_SEMConnectionState = false;
  21. //连接到电镜的ID号
  22. public int m_SEM_ID = 0;
  23. public HardwareController m_cfun = null;
  24. #endregion
  25. #region 构造函数
  26. /// <summary>
  27. /// 需传入,主窗体对象,与要获取数据窗体的对象
  28. /// </summary>
  29. /// <param name="in_frmReportApp"></param>
  30. /// <param name="form"></param>
  31. public OTSReportGridsFun()
  32. {
  33. m_cfun = HardwareController.GetSemController();// It's better to reinitialize, but it's not good to uninitialize
  34. }
  35. #endregion
  36. #region 自定义方法封装
  37. /// <summary>
  38. /// 传入颗粒的tagid和fieldid,来获取该颗粒下对应的xray数据
  39. /// </summary>
  40. /// <param name="in_clr_tagid"></param>
  41. /// <param name="in_clr_fieldid"></param>
  42. /// <param name="Search_xray"></param>
  43. /// <param name="Analysis_xray"></param>
  44. public void GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(int in_clr_tagid, int in_clr_fieldid, out uint[] Search_xray, out uint[] Analysis_xray, out int xray_id, out List<Element> list_celementchemistryclr)
  45. {
  46. Search_xray = new uint[2000];
  47. Analysis_xray = new uint[2000];
  48. xray_id = 0;
  49. list_celementchemistryclr = new List<Element>();
  50. //防止为空校验判断
  51. if (m_list_COTSFieldMgrClr == null)
  52. return;
  53. Particle particle = m_list_COTSFieldMgrClr.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
  54. if (particle.XrayId > -1)
  55. {
  56. for (int i = 0; i < 2000; i++)
  57. {
  58. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  59. }
  60. Search_xray = Analysis_xray;
  61. xray_id = particle.XrayId;
  62. list_celementchemistryclr = particle.ElementList;
  63. }
  64. }
  65. /// <summary>
  66. /// 临时创建一个用于组建particle类的小segment类结构
  67. /// </summary>
  68. class ShowSegment
  69. {
  70. Rectangle m_rect = new Rectangle();
  71. List<Color> m_list_color = new List<Color>();
  72. public Rectangle Rect
  73. {
  74. get { return m_rect; }
  75. set { m_rect = value; }
  76. }
  77. public List<Color> List_Color
  78. {
  79. get { return m_list_color; }
  80. set { m_list_color = value; }
  81. }
  82. /// <summary>
  83. /// 传入showsegment的list对象列表,返回从该对象列表计算出的外边rect矩形[目前宽度计算错误]
  84. /// </summary>
  85. /// <param name="in_list_showsegment"></param>
  86. /// <returns></returns>
  87. public Rectangle GetRectByListRectangle(List<ShowSegment> in_list_showsegment)
  88. {
  89. int x = 10000, y = 10000;
  90. int width = 0, height = 0;
  91. for (int i = 0; i < in_list_showsegment.Count(); i++)
  92. {
  93. if (x > in_list_showsegment[i].Rect.X)
  94. x = in_list_showsegment[i].Rect.X;
  95. if (y > in_list_showsegment[i].Rect.Y)
  96. y = in_list_showsegment[i].Rect.Y;
  97. if (width < in_list_showsegment[i].Rect.X + in_list_showsegment[i].Rect.Width)
  98. width = in_list_showsegment[i].Rect.X + in_list_showsegment[i].Rect.Width;
  99. if (height < in_list_showsegment[i].Rect.Height)
  100. height = in_list_showsegment[i].Rect.Height;
  101. }
  102. width = width - x;//计算时已增加了x在里面,计算完成后,再将x的值去掉
  103. //height就是线的数量
  104. return new Rectangle(x, y, width + 3, in_list_showsegment.Count() + 3);
  105. }
  106. }
  107. #endregion
  108. #region 连接电镜相关
  109. /// <summary>
  110. /// 连接电镜,颗粒列表使用
  111. /// </summary>
  112. public bool Connection_ForParticlesGrid()
  113. {
  114. if (!m_SEMConnectionState)
  115. {
  116. m_SEMConnectionState = m_cfun.Connect();
  117. }
  118. return m_SEMConnectionState;
  119. }
  120. /// <summary>
  121. /// 移动电镜到指定的X,Y坐标上,R坐标使用原先的值进行移动
  122. /// </summary>
  123. /// <param name="PositionX"></param>
  124. /// <param name="PositionY"></param>
  125. public bool MoveSemToPointXY_ForParticlesGrid(double in_PositionX, double in_PositionY)
  126. {
  127. bool isSuccess = false;
  128. //首先获取电镜当前的位置,并记录原R值
  129. double ls_PositionX = 0;
  130. double ls_PositionY = 0;
  131. double ls_PositionR = 0;
  132. if (m_SEMConnectionState)
  133. {
  134. isSuccess = m_cfun.GetSemPositionXY(ref ls_PositionX, ref ls_PositionY, ref ls_PositionR);
  135. }
  136. if (m_SEMConnectionState)
  137. {
  138. isSuccess = m_cfun.MoveSEMToPoint(new Point((int)in_PositionX, (int)in_PositionY), ls_PositionR);
  139. }
  140. return isSuccess;
  141. }
  142. /// <summary>
  143. /// 设置放大倍数
  144. /// </summary>
  145. /// <param name="a_dMagnification"></param>
  146. /// <returns></returns>
  147. public bool SetMagnification(double a_dMagnification)
  148. {
  149. bool isSuccess = false;
  150. if (m_SEMConnectionState)
  151. {
  152. isSuccess = m_cfun.SetMagnification(a_dMagnification);
  153. }
  154. return isSuccess;
  155. }
  156. public bool AcquireBSEImage(string sampleName, int width, int height, DwellTimeLevel dwellTime, ref byte[] ImageByte)
  157. {
  158. bool isSuccess = false;
  159. if (m_SEMConnectionState)
  160. {
  161. isSuccess = m_cfun.AcquireBSEImage(sampleName, width, height, dwellTime, ref ImageByte);
  162. }
  163. return isSuccess;
  164. }
  165. public bool AcquisitionSpectrum(string samplePath, int xrayMode, double new_PixelSize, ref Particle particle, uint a_nXRayAQTime)
  166. {
  167. bool isSuccess = false;
  168. if (m_SEMConnectionState)
  169. {
  170. isSuccess = m_cfun.AcquisitionSpectrum(samplePath, xrayMode, new_PixelSize, ref particle, a_nXRayAQTime);
  171. }
  172. return isSuccess;
  173. }
  174. #endregion
  175. }
  176. }