SEMDATAFieldManage.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. private double GetSemBrightness()
  112. {
  113. try
  114. {
  115. double brightness = 0;
  116. //获取工作距离
  117. bool result = cSemfun.GetSemBrightness(ref brightness);
  118. if (result)
  119. {
  120. //赋值 显示
  121. return brightness;
  122. }
  123. else
  124. {
  125. //配置结果提示
  126. return 0;
  127. }
  128. }
  129. catch (Exception ex)
  130. {
  131. log.Error(ex.ToString());
  132. return 0;
  133. }
  134. }
  135. private double GetSemContrast()
  136. {
  137. try
  138. {
  139. double contrast = 0;
  140. //获取工作距离
  141. bool result = cSemfun.GetSemContrast(ref contrast);
  142. if (result)
  143. {
  144. //赋值 显示
  145. return contrast;
  146. }
  147. else
  148. {
  149. //配置结果提示
  150. return 0;
  151. }
  152. }
  153. catch (Exception ex)
  154. {
  155. log.Error(ex.ToString());
  156. return 0;
  157. }
  158. }
  159. private double GetSemKv()
  160. {
  161. try
  162. {
  163. double kv = 0;
  164. //获取工作距离
  165. bool result = cSemfun.GetSemHighTension(ref kv);
  166. if (result)
  167. {
  168. //赋值 显示
  169. return kv;
  170. }
  171. else
  172. {
  173. //配置结果提示
  174. return 0;
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. log.Error(ex.ToString());
  180. return 0;
  181. }
  182. }
  183. #endregion
  184. #region 设置放大倍数
  185. public bool SetGMagnification(double a_dMagnification)
  186. {
  187. try
  188. {
  189. //获取放大倍数
  190. bool result = cSemfun.SetMagnification(a_dMagnification);
  191. return result;
  192. }
  193. catch (Exception ex)
  194. {
  195. log.Error( ex.ToString() );
  196. return false;
  197. }
  198. }
  199. #endregion
  200. #region 设置工作距离
  201. public bool SetSemWorkingDistance(double a_WorkingDistance)
  202. {
  203. try
  204. {
  205. bool result = cSemfun.SetWorkingDistance(a_WorkingDistance);
  206. return result;
  207. }
  208. catch (Exception ex)
  209. {
  210. log.Error(ex.ToString() );
  211. return false;
  212. }
  213. }
  214. #endregion
  215. public bool SetSembrightness(double bri)
  216. {
  217. try
  218. {
  219. bool result = cSemfun.SetSemBrightness(bri);
  220. return result;
  221. }
  222. catch (Exception ex)
  223. {
  224. log.Error(ex.ToString());
  225. return false;
  226. }
  227. }
  228. public bool SetSemContrast(double contra)
  229. {
  230. try
  231. {
  232. bool result = cSemfun.SetSemContrast(contra);
  233. return result;
  234. }
  235. catch (Exception ex)
  236. {
  237. log.Error(ex.ToString());
  238. return false;
  239. }
  240. }
  241. public bool SetSemHT(double ht)
  242. {
  243. try
  244. {
  245. bool result = cSemfun.SetSemHighTension(ht);
  246. return result;
  247. }
  248. catch (Exception ex)
  249. {
  250. log.Error(ex.ToString());
  251. return false;
  252. }
  253. }
  254. #region 获取电镜参数 放大倍数与工作距离
  255. public List<double> GetSEMMagAndWDParameter()
  256. {
  257. List<double> semParameter = new List<double>();
  258. //放大倍数
  259. double magnification = GetGMagnification();
  260. //工作距离
  261. double semWorkingDistance = GetSemWorkingDistance();
  262. double bri = GetSemBrightness();
  263. double contra=GetSemContrast();
  264. double kv=GetSemKv();
  265. //添加 放大倍数、工作距离
  266. semParameter.Add(magnification);
  267. semParameter.Add(semWorkingDistance);
  268. semParameter.Add(bri);
  269. semParameter.Add(contra);
  270. semParameter.Add(kv);
  271. return semParameter;
  272. }
  273. #endregion
  274. #region 驱动SEM到当前位置
  275. public bool SetSEMCurrentLocation( Point mousePoint, CVisualStage stage)
  276. {
  277. try
  278. {
  279. if (!stage.IfMouseInStage(mousePoint))
  280. {
  281. //获取在范围中的样品
  282. return false;
  283. }
  284. //判断是否鼠标在样品台范围中
  285. Point OTSLocation = new Point();
  286. //鼠标在样品台中移动获取坐标
  287. OTSLocation = stage.GetMouseOTSLocation(mousePoint);
  288. PointF SEMPoint =m_ProjData.ConvertOTSToSemCoord(OTSLocation);
  289. bool result = cSemfun.MoveSEMToPoint(SEMPoint.X, SEMPoint.Y);
  290. return result;
  291. }
  292. catch (Exception ex)
  293. {
  294. log.Error(ex.ToString());
  295. return false;
  296. }
  297. }
  298. #endregion
  299. #region 驱动SEM到中心位置
  300. public bool DriveSEMToLocation(Point mousePoint,CVisualStage stage, List<CVisualFieldGDIObject> m_MeasureFieldGDIObjects)
  301. {
  302. try
  303. {
  304. if (!stage.IfMouseInStage(mousePoint))
  305. {
  306. return false;
  307. }
  308. //判断是否鼠标在样品台范围中
  309. Point OTSLocation = new Point();
  310. //鼠标在样品台中移动获取坐标
  311. OTSLocation = stage.GetMouseOTSLocation(mousePoint);
  312. PointF SEMPoint = m_ProjData.ConvertOTSToSemCoord(OTSLocation);
  313. //循环single中所有对象 进行位置匹配
  314. for (int i = 0; i < m_MeasureFieldGDIObjects.Count; i++)
  315. {
  316. if (m_MeasureFieldGDIObjects[i].GetZoomedRegion.Contains(mousePoint))
  317. {
  318. //获取帧图左上坐标
  319. Point LT = new Point((int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Left, (int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Top);
  320. PointF lTLocation = stage.GetMouseOTSLocation(LT);
  321. lTLocation = m_ProjData.ConvertOTSToSemCoord(lTLocation);
  322. //获取帧图右下坐标
  323. Point RB = new Point((int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Right, (int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Bottom);
  324. PointF rbLocation = stage.GetMouseOTSLocation(RB);
  325. rbLocation = m_ProjData.ConvertOTSToSemCoord(rbLocation);
  326. float diffX = Math.Abs(rbLocation.X - lTLocation.X) / 2;
  327. float diffY = Math.Abs(rbLocation.Y - lTLocation.Y) / 2;
  328. //移动至帧图中心位置
  329. float moveCenterX = lTLocation.X - diffX;
  330. float moveCenterY = lTLocation.Y + diffY;
  331. bool result = cSemfun.MoveSEMToPoint(moveCenterX, moveCenterY);
  332. if (result)
  333. {
  334. return result;
  335. }
  336. }
  337. }
  338. return false;
  339. }
  340. catch (Exception)
  341. {
  342. return false;
  343. }
  344. }
  345. #endregion
  346. #region 获取SEM位置
  347. public bool GetSemLocation(ref List<double> SemLocation)
  348. {
  349. //获取SEM位置 a_dPositionX:X轴 a_dPositionY:Z轴 a_dPositionR:角度
  350. double a_dPositionX = 0;
  351. double a_dPositionY = 0;
  352. double a_dPositionR = 0;
  353. if (cSemfun != null)
  354. {
  355. if (cSemfun.GetSemPositionXY(ref a_dPositionX, ref a_dPositionY, ref a_dPositionR))
  356. {
  357. SemLocation.Add(a_dPositionX);
  358. SemLocation.Add(a_dPositionY);
  359. SemLocation.Add(a_dPositionR);
  360. return true;
  361. }
  362. }
  363. return false;
  364. }
  365. #endregion
  366. }
  367. }