SEMDATAFieldManage.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. using System;
  2. using System.Collections.Generic;
  3. using OTSCLRINTERFACE;
  4. using System.Drawing;
  5. using OTSDataType;
  6. using OTSModelSharp;
  7. using OTSModelSharp.ServiceCenter;
  8. using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel;
  9. namespace OTSMeasureApp
  10. {
  11. public class SEMDATAFieldManage
  12. {
  13. #region 全部变量声明
  14. //电镜设置对象
  15. ISemController cSemfun = null;
  16. IScanController cScanfun = null;
  17. //IEDSController cEDSfun = null;
  18. //主窗体对象
  19. COTSMeasureParam m_ProjData;
  20. NLog.Logger log ;
  21. #endregion
  22. #region 构造方法
  23. public SEMDATAFieldManage(COTSMeasureParam a_DataMgr)
  24. {
  25. log = NLog.LogManager.GetCurrentClassLogger();
  26. //获取主窗体对象
  27. if (m_ProjData == null)
  28. {
  29. m_ProjData = a_DataMgr;
  30. }
  31. }
  32. /// <summary>
  33. /// 初始化其他参数
  34. /// </summary>
  35. public bool InitAndConnection()
  36. {
  37. try
  38. {
  39. //控制类对象初始化
  40. if (cSemfun == null)
  41. {
  42. cSemfun = SemController.GetSEMController();
  43. }
  44. if (cScanfun == null)
  45. {
  46. cScanfun = ScanController.GetScanController();
  47. }
  48. //if (cEDSfun == null)
  49. //{
  50. // cEDSfun = EDSController.GetEDSController();
  51. //}
  52. return cSemfun.Connect();
  53. }
  54. catch (Exception ex)
  55. {
  56. log.Error(ex.ToString() );
  57. return false;
  58. }
  59. }
  60. #endregion
  61. #region 获取放大倍数
  62. private double GetGMagnification()
  63. {
  64. try
  65. {
  66. double a_dMagnification = 0;
  67. //获取放大倍数
  68. bool result = cSemfun.GetMagnification(ref a_dMagnification);
  69. if (result)
  70. {
  71. //赋值 显示
  72. return a_dMagnification;
  73. }
  74. else
  75. {
  76. //配置结果提示
  77. return 0;
  78. }
  79. }
  80. catch (Exception)
  81. {
  82. return 0;
  83. }
  84. }
  85. #endregion
  86. #region 获取工作距离
  87. private double GetSemWorkingDistance()
  88. {
  89. try
  90. {
  91. double a_WorkingDistance = 0;
  92. //获取工作距离
  93. bool result = cSemfun.GetWorkingDistance(ref a_WorkingDistance);
  94. if (result)
  95. {
  96. //赋值 显示
  97. return a_WorkingDistance;
  98. }
  99. else
  100. {
  101. //配置结果提示
  102. return 0;
  103. }
  104. }
  105. catch (Exception ex)
  106. {
  107. log.Error(ex.ToString() );
  108. return 0;
  109. }
  110. }
  111. #endregion
  112. #region 设置放大倍数
  113. public bool SetGMagnification(double a_dMagnification)
  114. {
  115. try
  116. {
  117. //获取放大倍数
  118. bool result = cSemfun.SetMagnification(a_dMagnification);
  119. return result;
  120. }
  121. catch (Exception ex)
  122. {
  123. log.Error( ex.ToString() );
  124. return false;
  125. }
  126. }
  127. #endregion
  128. #region 设置工作距离
  129. public bool SetSemWorkingDistance(double a_WorkingDistance)
  130. {
  131. try
  132. {
  133. bool result = cSemfun.SetWorkingDistance(a_WorkingDistance);
  134. return result;
  135. }
  136. catch (Exception ex)
  137. {
  138. log.Error(ex.ToString() );
  139. return false;
  140. }
  141. }
  142. #endregion
  143. #region 获取电镜参数 放大倍数与工作距离
  144. public List<double> GetSEMMagAndWDParameter()
  145. {
  146. List<double> semParameter = new List<double>();
  147. //放大倍数
  148. double magnification = GetGMagnification();
  149. //工作距离
  150. double semWorkingDistance = GetSemWorkingDistance();
  151. //添加 放大倍数、工作距离
  152. semParameter.Add(magnification);
  153. semParameter.Add(semWorkingDistance);
  154. return semParameter;
  155. }
  156. #endregion
  157. #region 驱动SEM到当前位置
  158. public bool SetSEMCurrentLocation( Point mousePoint, CVisualStage stage)
  159. {
  160. try
  161. {
  162. if (!stage.IfMouseInStage(mousePoint))
  163. {
  164. //获取在范围中的样品
  165. return false;
  166. }
  167. //判断是否鼠标在样品台范围中
  168. Point OTSLocation = new Point();
  169. //鼠标在样品台中移动获取坐标
  170. OTSLocation = stage.GetMouseOTSLocation(mousePoint);
  171. PointF SEMPoint =m_ProjData.ConvertOTSToSemCoord(OTSLocation);
  172. bool result = cSemfun.MoveSEMToPoint(SEMPoint.X, SEMPoint.Y);
  173. return result;
  174. }
  175. catch (Exception ex)
  176. {
  177. log.Error(ex.ToString());
  178. return false;
  179. }
  180. }
  181. #endregion
  182. #region 驱动SEM到中心位置
  183. public bool DriveSEMToLocation(Point mousePoint,CVisualStage stage, List<CRectangleGDIObject> m_MeasureFieldGDIObjects)
  184. {
  185. try
  186. {
  187. if (!stage.IfMouseInStage(mousePoint))
  188. {
  189. return false;
  190. }
  191. //判断是否鼠标在样品台范围中
  192. Point OTSLocation = new Point();
  193. //鼠标在样品台中移动获取坐标
  194. OTSLocation = stage.GetMouseOTSLocation(mousePoint);
  195. PointF SEMPoint = m_ProjData.ConvertOTSToSemCoord(OTSLocation);
  196. //循环single中所有对象 进行位置匹配
  197. for (int i = 0; i < m_MeasureFieldGDIObjects.Count; i++)
  198. {
  199. if (m_MeasureFieldGDIObjects[i].GetZoomedRegion.Contains(mousePoint))
  200. {
  201. //获取帧图左上坐标
  202. Point LT = new Point((int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Left, (int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Top);
  203. PointF lTLocation = stage.GetMouseOTSLocation(LT);
  204. lTLocation = m_ProjData.ConvertOTSToSemCoord(lTLocation);
  205. //获取帧图右下坐标
  206. Point RB = new Point((int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Right, (int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Bottom);
  207. PointF rbLocation = stage.GetMouseOTSLocation(RB);
  208. rbLocation = m_ProjData.ConvertOTSToSemCoord(rbLocation);
  209. float diffX = Math.Abs(rbLocation.X - lTLocation.X) / 2;
  210. float diffY = Math.Abs(rbLocation.Y - lTLocation.Y) / 2;
  211. //移动至帧图中心位置
  212. float moveCenterX = lTLocation.X - diffX;
  213. float moveCenterY = lTLocation.Y + diffY;
  214. bool result = cSemfun.MoveSEMToPoint(moveCenterX, moveCenterY);
  215. if (result)
  216. {
  217. return result;
  218. }
  219. }
  220. }
  221. return false;
  222. }
  223. catch (Exception)
  224. {
  225. return false;
  226. }
  227. }
  228. #endregion
  229. #region 获取SEM位置
  230. public bool GetSemLocation(ref List<double> SemLocation)
  231. {
  232. //获取SEM位置 a_dPositionX:X轴 a_dPositionY:Z轴 a_dPositionR:角度
  233. double a_dPositionX = 0;
  234. double a_dPositionY = 0;
  235. double a_dPositionR = 0;
  236. if (cSemfun != null)
  237. {
  238. if (cSemfun.GetSemPositionXY(ref a_dPositionX, ref a_dPositionY, ref a_dPositionR))
  239. {
  240. SemLocation.Add(a_dPositionX);
  241. SemLocation.Add(a_dPositionY);
  242. SemLocation.Add(a_dPositionR);
  243. return true;
  244. }
  245. }
  246. return false;
  247. }
  248. #endregion
  249. }
  250. }