OTSReportGridsFun.cs 8.2 KB

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