FEIEDSController.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. Init();
  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. var xray = a_listParticles[i].GetXray();
  75. xray.SetXrayData(spectrumItems);
  76. a_listParticles[i].SetXray(xray);
  77. if (a_bElementInfo)
  78. {
  79. List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();
  80. for (int j = 0; j < eleItems.Count; j++)
  81. {
  82. CElementChemistryClr chemistryClr = new CElementChemistryClr();
  83. chemistryClr.SetName(eleItems.ElementAt(j).Key);
  84. chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
  85. elementChemistryClrs.Add(chemistryClr);
  86. }
  87. a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
  88. }
  89. }
  90. return true;
  91. }
  92. public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData)
  93. {
  94. Dictionary<string, double> eleItems = new Dictionary<string, double>();
  95. return ApiClass.AcquireSpectrum(false, ref eleItems, ref a_XrayData);
  96. }
  97. public bool Init()
  98. {
  99. string FEIIP = FileHelper.GetXMLInformations("FEIIP");
  100. string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
  101. if (FEIIP == "" || FEIPORT == "")
  102. {
  103. NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
  104. return false;
  105. }
  106. if (ApiClass.isConnect())
  107. {
  108. return true;
  109. }
  110. return ApiClass.Connect(FEIIP, FEIPORT);
  111. }
  112. //private bool SetResolution(int ResolutionWidth, int ResolutionHeight)
  113. //{
  114. // strResolution = ResolutionWidth + "x" + ResolutionHeight;
  115. // return true;
  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. }
  138. }