SEMDATAFieldManage.cs 13 KB

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