using FEIApiControl;
using OTSCLRINTERFACE;
using OTSModelSharp.ServiceCenter;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace OTSMeasureApp.ServiceCenter
{
class FEIEDSController : IEDSController
{
private APIClass ApiClass = null;
private int AnalyExpCount = 100000;
private string strResolution = "";
private int width = 0;
private int height = 0;
///
/// fei面扫这个参数作用是达到这个数值后采集xray操作停止,而ots期望计数率是lowcount的判断标准,两者概念不同,所以此处用常数5000而非ots期望计数率
///
const int maxCounts = 8000;
public FEIEDSController(int MaxCounts,bool ifautoid,string knownelements)
{
ApiClass = FEISemController.GetApiClassInstance();
ApiClass.SetQuantificationParam(ifautoid, knownelements);
SetAnalyExpCount(MaxCounts);
Connect();
}
public bool GetXRayByFeatures(List a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
{
for (int i = 0; i < a_listParticles.Count; i++)
{
Dictionary eleItems = new Dictionary();
uint[] spectrumItems = new uint[2000];
if (ApiClass.GetSupportPolygon())//判断DLL是否支持多边形面扫
{
List points = CImageHandler.FindContoursBySegment(width, height, a_listParticles[i].GetFeature().GetSegmentsList());
if (!ApiClass.GetXRayByPolygon(points, strResolution, a_nXRayAQTime, maxCounts, a_bElementInfo, ref eleItems, ref spectrumItems))
{
return false;
}
}
else
{
Rectangle rectangle = (Rectangle)a_listParticles[i].GetParticleRect();
if (!ApiClass.GetXRayByRect(rectangle, strResolution, a_nXRayAQTime, maxCounts, a_bElementInfo, ref eleItems, ref spectrumItems))
{
return false;
}
}
var xray = a_listParticles[i].GetXray();
xray.SetXrayData(spectrumItems);
a_listParticles[i].SetXray(xray);
if (a_bElementInfo)
{
List elementChemistryClrs = new List();
for (int j = 0; j < eleItems.Count; j++)
{
CElementChemistryClr chemistryClr = new CElementChemistryClr();
chemistryClr.SetName(eleItems.ElementAt(j).Key);
chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
elementChemistryClrs.Add(chemistryClr);
}
a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
}
}
return true;
}
public bool GetXRayByParts(List a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)
{
for (int i = 0; i < a_listParticles.Count; i++)
{
Point point = (Point)a_listParticles[i].GetXRayPos();
Dictionary eleItems = new Dictionary();
uint[] spectrumItems = new uint[2000];
if (!ApiClass.GetXRayByPoint(point.X, point.Y, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))
{
return false;
}
var xray = a_listParticles[i].GetXray();
xray.SetXrayData(spectrumItems);
a_listParticles[i].SetXray(xray);
if (a_bElementInfo)
{
List elementChemistryClrs = new List();
for (int j = 0; j < eleItems.Count; j++)
{
CElementChemistryClr chemistryClr = new CElementChemistryClr();
chemistryClr.SetName(eleItems.ElementAt(j).Key);
chemistryClr.SetPercentage(eleItems.ElementAt(j).Value);
elementChemistryClrs.Add(chemistryClr);
}
a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);
}
}
return true;
}
public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData)
{
Dictionary eleItems = new Dictionary();
return ApiClass.AcquireSpectrum(false, ref eleItems, ref a_XrayData);
}
public bool Connect()
{
string FEIIP = FileHelper.GetXMLInformations("FEIIP");
string FEIPORT = FileHelper.GetXMLInformations("FEIPORT");
if (FEIIP == "" || FEIPORT == "")
{
NLog.LogManager.GetCurrentClassLogger().Error("FEI电镜端口配置为空!");
return false;
}
if (ApiClass.isConnect())
{
return true;
}
return ApiClass.Connect(FEIIP, FEIPORT);
}
private bool SetAnalyExpCount(int MaxCounts)
{
AnalyExpCount = MaxCounts;
return true;
}
public EDSTYPE GetEDSType()
{
return EDSTYPE.FEI;
}
public void SetFilterKeyEleNames(List KeyNameList)
{
throw new NotImplementedException();
}
void IEDSController.SetResolution(int ResolutionWidth, int ResolutionHeight)
{
ApiClass.SetResolution(ResolutionWidth, ResolutionHeight);
width = ResolutionWidth;
height = ResolutionHeight;
strResolution = ResolutionWidth.ToString() + "x" + ResolutionHeight.ToString();
}
public bool QuantifyXrayByPart(COTSParticleClr part)
{
return true;
}
public int GetExpectCount()
{
return AnalyExpCount;
}
public bool GetIfDelayQuantify()
{
return false;
}
public void SetQuantifiCationParam(bool IfAutoId, string knownElements)
{
ApiClass.SetQuantificationParam(IfAutoId, knownElements);
}
public bool GetXRayByExpandFeatures(List a_listParticles, double a_nXRayAQTime, bool a_bElementInfo)
{
throw new NotImplementedException();
}
}
}