OTSReportGridsFun.cs 8.2 KB

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