SEMDATAFieldManage.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. using System;
  2. using System.Collections.Generic;
  3. using OTSCLRINTERFACE;
  4. using System.Drawing;
  5. using OTSDataType;
  6. using OTSModelSharp;
  7. using OTSModelSharp.ServiceInterface;
  8. namespace OTSMeasureApp
  9. {
  10. public class SEMDATAFieldManage
  11. {
  12. #region 全部变量声明
  13. //连接状态
  14. public bool ConnectionState = false;
  15. // 判断是否是模拟状态 FASE: 不是在模拟环境下 True: 在模拟环境下
  16. public bool IsSimulationStatus = false;
  17. //获取当前电镜的ID号
  18. //int SemType = 0;
  19. //获取XML 路径
  20. static string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFilePath"].ConnectionString;
  21. //日志路径
  22. static string LogPath = System.Configuration.ConfigurationManager.ConnectionStrings["LogPath"].ConnectionString;
  23. //电镜设置对象
  24. SemController cSemfun = null;
  25. ScanController cScanfun = null;
  26. EDSController cEDSfun = null;
  27. //主窗体对象
  28. COTSMeasureParam m_ProjData;
  29. //CFieldPositionMgr cFieldMgrClr;
  30. NLog.Logger log ;
  31. #endregion
  32. #region 构造方法
  33. public SEMDATAFieldManage(COTSMeasureParam a_DataMgr)
  34. {
  35. log = NLog.LogManager.GetCurrentClassLogger();
  36. //获取主窗体对象
  37. if (m_ProjData == null)
  38. {
  39. m_ProjData = a_DataMgr;
  40. }
  41. }
  42. /// <summary>
  43. /// 初始化其他参数
  44. /// </summary>
  45. public bool InitAndConnection()
  46. {
  47. try
  48. {
  49. //控制类对象初始化
  50. if (cSemfun == null)
  51. {
  52. cSemfun = SemController.GetSEMController();
  53. }
  54. if (cScanfun == null)
  55. {
  56. cScanfun = ScanController.GetScanController();
  57. }
  58. if (cEDSfun == null)
  59. {
  60. cEDSfun = EDSController.GetEDSController();
  61. }
  62. return cSemfun.Connect();
  63. }
  64. catch (Exception ex)
  65. {
  66. log.Error("SEMDATAFieldManage_InitAndConntion:--Error:" + ex.ToString() + "");
  67. return false;
  68. }
  69. }
  70. #endregion
  71. #region 获取放大倍数
  72. private double GetGMagnification()
  73. {
  74. try
  75. {
  76. double a_dMagnification = 0;
  77. //获取放大倍数
  78. bool result = cSemfun.GetMagnification(ref a_dMagnification);
  79. if (result)
  80. {
  81. //赋值 显示
  82. return a_dMagnification;
  83. }
  84. else
  85. {
  86. //配置结果提示
  87. return 0;
  88. }
  89. }
  90. catch (Exception)
  91. {
  92. return 0;
  93. }
  94. }
  95. #endregion
  96. #region 获取工作距离
  97. private double GetSemWorkingDistance()
  98. {
  99. try
  100. {
  101. double a_WorkingDistance = 0;
  102. //获取工作距离
  103. bool result = cSemfun.GetWorkingDistance(ref a_WorkingDistance);
  104. if (result)
  105. {
  106. //赋值 显示
  107. return a_WorkingDistance;
  108. }
  109. else
  110. {
  111. //配置结果提示
  112. return 0;
  113. }
  114. }
  115. catch (Exception ex)
  116. {
  117. log.Error("SEMDATAFieldManage_GetSemWorkingDistance--错误日志:" + ex.ToString() + "");
  118. return 0;
  119. }
  120. }
  121. #endregion
  122. #region 设置放大倍数
  123. private bool SetGMagnification(double a_dMagnification)
  124. {
  125. try
  126. {
  127. //获取放大倍数
  128. bool result = cSemfun.SetMagnification(a_dMagnification);
  129. return result;
  130. }
  131. catch (Exception ex)
  132. {
  133. log.Error("SEMDATAFieldManage_SetSemWorkingDistance--错误日志:" + ex.ToString() + "");
  134. return false;
  135. }
  136. }
  137. #endregion
  138. #region 设置工作距离
  139. private bool SetSemWorkingDistance(double a_WorkingDistance)
  140. {
  141. try
  142. {
  143. bool result = cSemfun.SetWorkingDistance(a_WorkingDistance);
  144. return result;
  145. }
  146. catch (Exception ex)
  147. {
  148. log.Error("SEMDATAFieldManage_SetSemWorkingDistance--错误日志:" + ex.ToString() + "");
  149. return false;
  150. }
  151. }
  152. #endregion
  153. #region 获取单点Xray与元素信息
  154. /// <summary>
  155. /// 获取单点Xray与元素信息
  156. /// </summary>
  157. /// <param name="a_Milliseconds">采集时间</param>
  158. /// <param name="a_BSEX">鼠标在BSE图中X轴</param>
  159. /// <param name="a_BSEY">鼠标在BSE图中Y轴</param>
  160. /// <param name="a_ElementXrayData">Xray数组</param>
  161. /// <param name="a_nElementNum">元素数量</param>
  162. /// <param name="a_strElementName">元素名称</param>
  163. /// <returns></returns>
  164. public bool GetXRayAndElementInfo(uint a_Milliseconds, int a_BSEX, int a_BSEY, ref int[] a_ElementXrayData, ref ValueType a_nElementNum, ref string a_strElementName)
  165. {
  166. //获取Xray与元素信息
  167. return false;// cfun.GetEDSControl().GetXRayByPoints(a_Milliseconds, a_BSEX, a_BSEY, ref a_ElementXrayData, ref a_nElementNum, ref a_strElementName);
  168. }
  169. #endregion
  170. #region 获取电镜参数 放大倍数与工作距离
  171. public List<double> GetSEMMagAndWDParameter()
  172. {
  173. List<double> semParameter = new List<double>();
  174. //放大倍数
  175. double magnification = GetGMagnification();
  176. //工作距离
  177. double semWorkingDistance = GetSemWorkingDistance();
  178. //添加 放大倍数、工作距离
  179. semParameter.Add(magnification);
  180. semParameter.Add(semWorkingDistance);
  181. return semParameter;
  182. }
  183. #endregion
  184. #region 设置电镜 放大倍数与工作距离
  185. /// <summary>
  186. /// 设置电镜 放大倍数
  187. /// </summary>
  188. /// <param name="a_dMagnification"></param>
  189. /// <param name="a_WorkingDistance"></param>
  190. /// <returns></returns>
  191. public bool SetSEMMagnificationParameter(double a_dMagnification)
  192. {
  193. return SetGMagnification(a_dMagnification);
  194. }
  195. /// <summary>
  196. /// 设置电镜 工作距离
  197. /// </summary>
  198. /// <param name="a_WorkingDistance"></param>
  199. /// <returns></returns>
  200. public bool SetSEMWorkingDistanceParameter(double a_WorkingDistance)
  201. {
  202. return SetSemWorkingDistance(a_WorkingDistance);
  203. }
  204. #endregion
  205. #region 驱动SEM到当前位置
  206. public bool SetSEMCurrentLocation( Point mousePoint, List<ARectangleGDIObject> m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, int Width, int Height)
  207. {
  208. try
  209. {
  210. ARectangleGDIObject RectangleGDIObject = null;
  211. //循环判断是否鼠标在样品范围中
  212. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  213. {
  214. if (item.Region.Contains(mousePoint))
  215. {
  216. //获取在范围中的样品
  217. RectangleGDIObject = item;
  218. break;
  219. }
  220. }
  221. //判断是否鼠标在样品台范围中
  222. Point OTSLocation = new Point();
  223. if (RectangleGDIObject != null)
  224. {
  225. //鼠标在样品台中移动获取坐标
  226. OTSLocation = OTSSamplespaceGraphicsPanelFun.GetMouseLocationInRectangleGDIObject(mousePoint, m_RectangleGDIObjects[0], oTSSampleStageData, IsWidth, m_RectangleGDIObjects[0].Region.Width, m_RectangleGDIObjects[0].Region.Height);
  227. Point SEMPoint =m_ProjData.ChangeOTSToSemCoord(OTSLocation);
  228. //调用C++ controller中的方法
  229. //移动至当前位置
  230. bool result = cSemfun.MoveSEMToPoint(SEMPoint.X, SEMPoint.Y);
  231. if (result)
  232. {
  233. return result;
  234. }
  235. }
  236. return false;
  237. }
  238. catch (Exception)
  239. {
  240. return false;
  241. }
  242. }
  243. #endregion
  244. #region 驱动SEM到中心位置
  245. public bool DriveSEMToLocation(Point mousePoint, List<ARectangleGDIObject> m_RectangleGDIObjects, List<ARectangleGDIObject> m_SingleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, int Width, int Height)
  246. {
  247. try
  248. {
  249. ARectangleGDIObject RectangleGDIObject = null;
  250. //循环判断是否鼠标在样品范围中
  251. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  252. {
  253. if (item.Region.Contains(mousePoint))
  254. {
  255. //获取在范围中的样品台对象
  256. RectangleGDIObject = item;
  257. break;
  258. }
  259. }
  260. //判断是否鼠标在样品台范围中
  261. Point OTSLocation = new Point();
  262. if (RectangleGDIObject != null)
  263. {
  264. //鼠标在样品台中移动获取坐标
  265. OTSLocation = OTSSamplespaceGraphicsPanelFun.GetMouseLocationInRectangleGDIObject(mousePoint, RectangleGDIObject, oTSSampleStageData, IsWidth, RectangleGDIObject.Region.Width, RectangleGDIObject.Region.Height);
  266. Point SEMPoint = m_ProjData.ChangeOTSToSemCoord(OTSLocation);
  267. //循环single中所有对象 进行位置匹配
  268. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  269. {
  270. if (m_SingleGDIObjects[i].Region.Contains(mousePoint))
  271. {
  272. //获取帧图左上坐标
  273. Point LT = new Point((int)m_SingleGDIObjects[i].RegionF.Left, (int)m_SingleGDIObjects[i].RegionF.Top);
  274. Point lTLocation = OTSSamplespaceGraphicsPanelFun.GetMouseLocationInRectangleGDIObject(LT, RectangleGDIObject, oTSSampleStageData, IsWidth, RectangleGDIObject.Region.Width, RectangleGDIObject.Region.Height);
  275. lTLocation = m_ProjData.ChangeOTSToSemCoord(lTLocation);
  276. //获取帧图右下坐标
  277. Point RB = new Point((int)m_SingleGDIObjects[i].RegionF.Right, (int)m_SingleGDIObjects[i].RegionF.Bottom);
  278. Point rbLocation = OTSSamplespaceGraphicsPanelFun.GetMouseLocationInRectangleGDIObject(RB, RectangleGDIObject, oTSSampleStageData, IsWidth, RectangleGDIObject.Region.Width, RectangleGDIObject.Region.Height);
  279. rbLocation = m_ProjData.ChangeOTSToSemCoord(rbLocation);
  280. int diffX = Math.Abs(rbLocation.X - lTLocation.X) / 2;
  281. int diffY = Math.Abs(rbLocation.Y - lTLocation.Y) / 2;
  282. //移动至帧图中心位置
  283. int moveCenterX = lTLocation.X - diffX;
  284. int moveCenterY = lTLocation.Y + diffY;
  285. bool result = cSemfun.MoveSEMToPoint(moveCenterX, moveCenterY);
  286. if (result)
  287. {
  288. return result;
  289. }
  290. }
  291. }
  292. }
  293. return false;
  294. }
  295. catch (Exception)
  296. {
  297. return false;
  298. }
  299. }
  300. #endregion
  301. #region 获取SEM位置
  302. public bool GetSemLocation(ref List<double> SemLocation)
  303. {
  304. //获取SEM位置 a_dPositionX:X轴 a_dPositionY:Z轴 a_dPositionR:角度
  305. double a_dPositionX = 0;
  306. double a_dPositionY = 0;
  307. double a_dPositionR = 0;
  308. if (cSemfun != null)
  309. {
  310. if (cSemfun.GetSemPositionXY(ref a_dPositionX, ref a_dPositionY, ref a_dPositionR))
  311. {
  312. SemLocation.Add(a_dPositionX);
  313. SemLocation.Add(a_dPositionY);
  314. SemLocation.Add(a_dPositionR);
  315. return true;
  316. }
  317. }
  318. return false;
  319. }
  320. #endregion
  321. }
  322. }