OTSReportGridsFun.cs 8.0 KB

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