FEIEDSController.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using FEIApiControl;
  2. using OTSCLRINTERFACE;
  3. using OTSModelSharp.ServiceCenter;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Linq;
  8. namespace OTSMeasureApp.ServiceCenter
  9. {
  10. class FEIEDSController : IEDSController
  11. {
  12. private APIClass ApiClass = null;
  13. private int AnalyExpCount = 100000;
  14. private string strResolution = "";
  15. private int width = 0;
  16. private int height = 0;
  17. public FEIEDSController(int MaxCounts)
  18. {
  19. ApiClass = FEISemController.GetApiClassInstance();
  20. SetAnalyExpCount(MaxCounts);
  21. Connect();
  22. }
  23. public bool GetXRayByFeatures(List<COTSParticleClr> a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
  24. {
  25. for (int i = 0; i < a_listParticles.Count; i++)
  26. {
  27. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  28. uint[] spectrumItems = new uint[2000];
  29. if (ApiClass.GetSupportPolygon())//判断DLL是否支持多边形面扫
  30. {
  31. List<Point> points = CImageHandler.FindContoursBySegment(width, height, a_listParticles[i].GetFeature().GetSegmentsList());
  32. if (!ApiClass.GetXRayByPolygon(points, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))
  33. {
  34. return false;
  35. }
  36. }
  37. else
  38. {
  39. Rectangle rectangle = (Rectangle)a_listParticles[i].GetParticleRect();
  40. if (!ApiClass.GetXRayByRect(rectangle, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))
  41. {
  42. return false;
  43. }
  44. }
  45. var xray = a_listParticles[i].GetXray();
  46. xray.SetXrayData(spectrumItems);
  47. a_listParticles[i].SetXray(xray);
  48. if (a_bElementInfo)
  49. {
  50. List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
  51. for (int j = 0; j < eleItems.Count; j++)
  52. {
  53. CElementChemistryClr chemistryClr = new CElementChemistryClr();
  54. chemistryClr.SetName(eleItems.ElementAt(j).Key);
  55. chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
  56. elementChemistryClrs.Add(chemistryClr);
  57. }
  58. a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
  59. }
  60. }
  61. return true;
  62. }
  63. public bool GetXRayByParts(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)
  64. {
  65. for (int i = 0; i < a_listParticles.Count; i++)
  66. {
  67. Point point = (Point)a_listParticles[i].GetXRayPos();
  68. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  69. uint[] spectrumItems = new uint[2000];
  70. if (!ApiClass.GetXRayByPoint(point.X, point.Y, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))
  71. {
  72. return false;
  73. }
  74. //Rectangle r = new Rectangle(point.X, point.Y, 0, 0);
  75. //if (!ApiClass.GetXRayByRect(r, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))
  76. //{
  77. // return false;
  78. //}
  79. var xray = a_listParticles[i].GetXray();
  80. xray.SetXrayData(spectrumItems);
  81. a_listParticles[i].SetXray(xray);
  82. if (a_bElementInfo)
  83. {
  84. List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
  85. for (int j = 0; j < eleItems.Count; j++)
  86. {
  87. CElementChemistryClr chemistryClr = new CElementChemistryClr();
  88. chemistryClr.SetName(eleItems.ElementAt(j).Key);
  89. chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
  90. elementChemistryClrs.Add(chemistryClr);
  91. }
  92. a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
  93. }
  94. }
  95. return true;
  96. }
  97. public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData)
  98. {
  99. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  100. return ApiClass.AcquireSpectrum(false, ref eleItems, ref a_XrayData);
  101. }
  102. public bool Connect()
  103. {
  104. string FEIIP = FileHelper.GetXMLInformations("FEIIP");
  105. string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
  106. if (FEIIP == "" || FEIPORT == "")
  107. {
  108. NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
  109. return false;
  110. }
  111. if (ApiClass.isConnect())
  112. {
  113. return true;
  114. }
  115. return ApiClass.Connect(FEIIP, FEIPORT);
  116. }
  117. private bool SetAnalyExpCount(int MaxCounts)
  118. {
  119. AnalyExpCount = MaxCounts;
  120. return true;
  121. }
  122. public EDSTYPE GetEDSType()
  123. {
  124. return EDSTYPE.FEI;
  125. }
  126. public void SetFilterKeyEleNames(List<string> KeyNameList)
  127. {
  128. throw new NotImplementedException();
  129. }
  130. void IEDSController.SetResolution(int ResolutionWidth, int ResolutionHeight)
  131. {
  132. ApiClass.SetResolution(ResolutionWidth, ResolutionHeight);
  133. width = ResolutionWidth;
  134. height = ResolutionHeight;
  135. strResolution = ResolutionWidth.ToString() + "x" + ResolutionHeight.ToString();
  136. }
  137. public bool QuantifyXrayByPart(COTSParticleClr part)
  138. {
  139. return true;
  140. }
  141. public int GetExpectCount()
  142. {
  143. return AnalyExpCount;
  144. }
  145. public bool GetIfDelayQuantify()
  146. {
  147. return false;
  148. }
  149. }
  150. }