SEMDATAFieldManage.cs 13 KB

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