SEMControlService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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 SEMControlService
  12. {
  13. #region 全部变量声明
  14. //电镜设置对象
  15. ISemController cSemfun = null;
  16. IScanController cScanfun = null;
  17. //IEDSController cEDSfun = null;
  18. NLog.Logger log ;
  19. #endregion
  20. #region 构造方法
  21. public SEMControlService()
  22. {
  23. log = NLog.LogManager.GetCurrentClassLogger();
  24. }
  25. /// <summary>
  26. /// 初始化其他参数
  27. /// </summary>
  28. public bool InitAndConnection()
  29. {
  30. try
  31. {
  32. //控制类对象初始化
  33. if (cSemfun == null)
  34. {
  35. cSemfun = SemController.GetSEMController();
  36. }
  37. if (cScanfun == null)
  38. {
  39. cScanfun = ScanController.GetScanController();
  40. }
  41. return cSemfun.Connect();
  42. }
  43. catch (Exception ex)
  44. {
  45. log.Error(ex.ToString() );
  46. return false;
  47. }
  48. }
  49. #endregion
  50. #region 获取放大倍数
  51. private double GetGMagnification()
  52. {
  53. try
  54. {
  55. double a_dMagnification = 0;
  56. //获取放大倍数
  57. bool result = cSemfun.GetMagnification(ref a_dMagnification);
  58. if (result)
  59. {
  60. //赋值 显示
  61. return a_dMagnification;
  62. }
  63. else
  64. {
  65. //配置结果提示
  66. return 0;
  67. }
  68. }
  69. catch (Exception)
  70. {
  71. return 0;
  72. }
  73. }
  74. #endregion
  75. #region 获取工作距离
  76. private double GetSemWorkingDistance()
  77. {
  78. try
  79. {
  80. double a_WorkingDistance = 0;
  81. //获取工作距离
  82. bool result = cSemfun.GetWorkingDistance(ref a_WorkingDistance);
  83. if (result)
  84. {
  85. //赋值 显示
  86. return a_WorkingDistance;
  87. }
  88. else
  89. {
  90. //配置结果提示
  91. return 0;
  92. }
  93. }
  94. catch (Exception ex)
  95. {
  96. log.Error(ex.ToString() );
  97. return 0;
  98. }
  99. }
  100. private double GetSemBrightness()
  101. {
  102. try
  103. {
  104. double brightness = 0;
  105. //获取工作距离
  106. bool result = cSemfun.GetSemBrightness(ref brightness);
  107. if (result)
  108. {
  109. //赋值 显示
  110. return brightness;
  111. }
  112. else
  113. {
  114. //配置结果提示
  115. return 0;
  116. }
  117. }
  118. catch (Exception ex)
  119. {
  120. log.Error(ex.ToString());
  121. return 0;
  122. }
  123. }
  124. private double GetSemContrast()
  125. {
  126. try
  127. {
  128. double contrast = 0;
  129. //获取工作距离
  130. bool result = cSemfun.GetSemContrast(ref contrast);
  131. if (result)
  132. {
  133. //赋值 显示
  134. return contrast;
  135. }
  136. else
  137. {
  138. //配置结果提示
  139. return 0;
  140. }
  141. }
  142. catch (Exception ex)
  143. {
  144. log.Error(ex.ToString());
  145. return 0;
  146. }
  147. }
  148. private double GetSemKv()
  149. {
  150. try
  151. {
  152. double kv = 0;
  153. //获取工作距离
  154. bool result = cSemfun.GetSemHighTension(ref kv);
  155. if (result)
  156. {
  157. //赋值 显示
  158. return kv;
  159. }
  160. else
  161. {
  162. //配置结果提示
  163. return 0;
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. log.Error(ex.ToString());
  169. return 0;
  170. }
  171. }
  172. #endregion
  173. #region 设置放大倍数
  174. public bool SetGMagnification(double a_dMagnification)
  175. {
  176. try
  177. {
  178. //获取放大倍数
  179. bool result = cSemfun.SetMagnification(a_dMagnification);
  180. return result;
  181. }
  182. catch (Exception ex)
  183. {
  184. log.Error( ex.ToString() );
  185. return false;
  186. }
  187. }
  188. #endregion
  189. #region 设置工作距离
  190. public bool SetSemWorkingDistance(double a_WorkingDistance)
  191. {
  192. try
  193. {
  194. bool result = cSemfun.SetWorkingDistance(a_WorkingDistance);
  195. return result;
  196. }
  197. catch (Exception ex)
  198. {
  199. log.Error(ex.ToString() );
  200. return false;
  201. }
  202. }
  203. #endregion
  204. public bool SetSembrightness(double bri)
  205. {
  206. try
  207. {
  208. bool result = cSemfun.SetSemBrightness(bri);
  209. return result;
  210. }
  211. catch (Exception ex)
  212. {
  213. log.Error(ex.ToString());
  214. return false;
  215. }
  216. }
  217. public bool SetSemContrast(double contra)
  218. {
  219. try
  220. {
  221. bool result = cSemfun.SetSemContrast(contra);
  222. return result;
  223. }
  224. catch (Exception ex)
  225. {
  226. log.Error(ex.ToString());
  227. return false;
  228. }
  229. }
  230. public bool SetSemHT(double ht)
  231. {
  232. try
  233. {
  234. bool result = cSemfun.SetSemHighTension(ht);
  235. return result;
  236. }
  237. catch (Exception ex)
  238. {
  239. log.Error(ex.ToString());
  240. return false;
  241. }
  242. }
  243. #region 获取电镜参数 放大倍数与工作距离
  244. public List<double> GetSEMMagAndWDParameter()
  245. {
  246. List<double> semParameter = new List<double>();
  247. //放大倍数
  248. double magnification = GetGMagnification();
  249. //工作距离
  250. double semWorkingDistance = GetSemWorkingDistance();
  251. double bri = GetSemBrightness();
  252. double contra=GetSemContrast();
  253. double kv=GetSemKv();
  254. //添加 放大倍数、工作距离
  255. semParameter.Add(magnification);
  256. semParameter.Add(semWorkingDistance);
  257. semParameter.Add(bri);
  258. semParameter.Add(contra);
  259. semParameter.Add(kv);
  260. return semParameter;
  261. }
  262. #endregion
  263. #region 驱动SEM到当前位置
  264. public bool SetSEMCurrentLocation( Point mousePoint, CVisualStage stage)
  265. {
  266. try
  267. {
  268. if (!stage.IfMouseInStage(mousePoint))
  269. {
  270. //获取在范围中的样品
  271. return false;
  272. }
  273. //判断是否鼠标在样品台范围中
  274. Point OTSLocation = new Point();
  275. //鼠标在样品台中移动获取坐标
  276. OTSLocation = stage.GetMouseOTSLocation(mousePoint);
  277. PointF SEMPoint=new PointF(0,0);
  278. stage.m_SEMStageData.ConvertOTSToSEMCoord(OTSLocation,ref SEMPoint);
  279. bool result = cSemfun.MoveSEMToPoint(SEMPoint.X, SEMPoint.Y);
  280. return result;
  281. }
  282. catch (Exception ex)
  283. {
  284. log.Error(ex.ToString());
  285. return false;
  286. }
  287. }
  288. #endregion
  289. #region 驱动SEM到中心位置
  290. public bool DriveSEMToLocation(Point mousePoint,CVisualStage stage, List<CVisualFieldGDIObject> m_MeasureFieldGDIObjects)
  291. {
  292. try
  293. {
  294. if (!stage.IfMouseInStage(mousePoint))
  295. {
  296. return false;
  297. }
  298. //判断是否鼠标在样品台范围中
  299. Point OTSLocation = new Point();
  300. //鼠标在样品台中移动获取坐标
  301. OTSLocation = stage.GetMouseOTSLocation(mousePoint);
  302. PointF SEMPoint = new PointF(0, 0);
  303. stage.m_SEMStageData.ConvertOTSToSEMCoord(OTSLocation,ref SEMPoint);
  304. //循环single中所有对象 进行位置匹配
  305. for (int i = 0; i < m_MeasureFieldGDIObjects.Count; i++)
  306. {
  307. if (m_MeasureFieldGDIObjects[i].GetZoomedRegion.Contains(mousePoint))
  308. {
  309. //获取帧图左上坐标
  310. Point LT = new Point((int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Left, (int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Top);
  311. PointF lTLocation = stage.GetMouseOTSLocation(LT);
  312. //lTLocation =
  313. stage.m_SEMStageData.ConvertOTSToSEMCoord(lTLocation,ref lTLocation);
  314. //获取帧图右下坐标
  315. Point RB = new Point((int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Right, (int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Bottom);
  316. PointF rbLocation = stage.GetMouseOTSLocation(RB);
  317. stage.m_SEMStageData.ConvertOTSToSEMCoord(rbLocation, ref rbLocation);
  318. float diffX = Math.Abs(rbLocation.X - lTLocation.X) / 2;
  319. float diffY = Math.Abs(rbLocation.Y - lTLocation.Y) / 2;
  320. //移动至帧图中心位置
  321. float moveCenterX = lTLocation.X - diffX;
  322. float moveCenterY = lTLocation.Y + diffY;
  323. bool result = cSemfun.MoveSEMToPoint(moveCenterX, moveCenterY);
  324. if (result)
  325. {
  326. return result;
  327. }
  328. }
  329. }
  330. return false;
  331. }
  332. catch (Exception)
  333. {
  334. return false;
  335. }
  336. }
  337. #endregion
  338. #region 获取SEM位置
  339. public bool GetSemLocation(ref List<double> SemLocation)
  340. {
  341. //获取SEM位置 a_dPositionX:X轴 a_dPositionY:Z轴 a_dPositionR:角度
  342. double a_dPositionX = 0;
  343. double a_dPositionY = 0;
  344. double a_dPositionR = 0;
  345. if (cSemfun != null)
  346. {
  347. if (cSemfun.GetSemPositionXY(ref a_dPositionX, ref a_dPositionY, ref a_dPositionR))
  348. {
  349. SemLocation.Add(a_dPositionX);
  350. SemLocation.Add(a_dPositionY);
  351. SemLocation.Add(a_dPositionR);
  352. return true;
  353. }
  354. }
  355. return false;
  356. }
  357. #endregion
  358. }
  359. }