SEMDATAFieldManage.cs 13 KB

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