using FEIApiControl; using OTSCLRINTERFACE; using OxfordExtenderWrapper; using OTSModelSharp.ServiceCenter; using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Runtime.Remoting.Channels.Ipc; using System.Runtime.Remoting.Channels; using OTSMeasureApp.ServiceCenter.OxfordExtender; namespace OTSMeasureApp.ServiceCenter { class OxfordEDSController : IEDSController { ExtenderIpcUI iExtender; private int AnalyExpCount = 100000; private string strResolution = ""; public ExtenderIpcUI GetIExtender() { return iExtender; } public void SetIExtender(ExtenderIpcUI value) { iExtender = value; } public OxfordEDSController( int MaxCounts,bool ifautoid, string knownelements) { iExtender = ExtenderWrapperIpc.GetExtenderWrapper(); iExtender.SetQuantifiCationParam1(ifautoid, knownelements); SetAnalyExpCount(MaxCounts); } public bool GetXRayByFeatures(List a_listParticles, double a_nXRayAQTime, bool a_bElementInfo) { List areaPrms = new List(); foreach (var part in a_listParticles) { var p = new AreaXrayParam(); p.dMilliSecondsTime = a_nXRayAQTime; var feas = part.GetFeature().GetSegmentsList(); foreach (var f in feas) { p.a_listChord.Add(new Segment() { X = f.GetStart(), Y = f.GetHeight(), Length = f.GetLength() }); } areaPrms.Add(p); } NLog.LogManager.GetCurrentClassLogger().Info("Begin to acquire feature xray data :" + areaPrms.Count); iExtender.CollectXrayByFeatures(ref areaPrms, a_nXRayAQTime, a_bElementInfo); NLog.LogManager.GetCurrentClassLogger().Info("End acquiring feature xray data :" + areaPrms.Count); for (int i = 0; i < a_listParticles.Count; i++) { CPosXrayClr xray = a_listParticles[i].GetXray(); xray.SetXrayData(areaPrms[i].XrayData); var listElement = areaPrms[i].listElement; List chelist = new List(); foreach (var ele in listElement) { var che = new CElementChemistryClr(); che.SetName(ele.Key); che.SetPercentage(ele.Value); chelist.Add(che); } xray.SetElementQuantifyData(chelist); a_listParticles[i].SetXray(xray); } return true; } public bool GetXRayByParts(List a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo) { List pointXrayPrms = new List(); foreach (var part in a_listParticles) { var p = new PointXrayParam(); p.dMilliSecondsTime = a_nXRayAQTime; var Pos = (Point)(part.GetXRayPos()); p.x = Pos.X; p.y = Pos.Y; pointXrayPrms.Add(p); } NLog.LogManager.GetCurrentClassLogger().Info("Begin to acquire point xray data :"+ pointXrayPrms.Count); iExtender.CollectXrayByPoints(ref pointXrayPrms, a_nXRayAQTime, a_bElementInfo); NLog.LogManager.GetCurrentClassLogger().Info("End acquiring point xray data :" + pointXrayPrms.Count); for (int i = 0; i < a_listParticles.Count; i++) { CPosXrayClr xray = a_listParticles[i].GetXray(); xray.SetXrayData(pointXrayPrms[i].XrayData); var listElement = pointXrayPrms[i].listElement; List chelist = new List(); foreach (var ele in listElement) { var che = new CElementChemistryClr(); che.SetName(ele.Key); che.SetPercentage(ele.Value); chelist.Add(che); } xray.SetElementQuantifyData(chelist); a_listParticles[i].SetXray(xray); } return true; } public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData) { Dictionary eleItems = new Dictionary(); var p = new PointXrayParam(); p.x = 10; p.y = 10; p.dMilliSecondsTime = a_nXRayAQTime; if (iExtender.XrayPointCollecting(ref p)) { a_XrayData = p.XrayData; return true; } else { a_XrayData = p.XrayData; return false; } } public bool Connect() { iExtender = ExtenderWrapperIpc.GetExtenderWrapper(); return true; } private bool SetAnalyExpCount(int MaxCounts) { AnalyExpCount = MaxCounts; return true; } public EDSTYPE GetEDSType() { return EDSTYPE.OXFORD; } public void SetFilterKeyEleNames(List KeyNameList) { throw new NotImplementedException(); } public bool QuantifyXrayByParts(List a_listParticles) { return true; } void IEDSController.SetResolution(int resolutionWidth, int resolutionHeight) { return; } public bool QuantifyXrayByPart(COTSParticleClr part) { return true; } public int GetExpectCount() { return AnalyExpCount; } public bool GetIfDelayQuantify() { return false; } public void SetQuantifiCationParam(bool IfAutoId, string knownElements) { iExtender.SetQuantifiCationParam1(IfAutoId, knownElements); } public bool GetXRayByExpandFeatures(List a_listParticles, double a_nXRayAQTime, bool a_bElementInfo) { List areaPrms = new List(); foreach (var part in a_listParticles) { var p = new AreaXrayParam(); p.dMilliSecondsTime = a_nXRayAQTime; var feas = part.GetFeature().GetSegmentsList(); foreach (var f in feas) { var len = f.GetLength(); var start = f.GetStart() - len*2; if (start < 0) { start = 0; } len = len * 3; p.a_listChord.Add(new Segment() { X = start, Y = f.GetHeight(), Length =len }); } areaPrms.Add(p); } NLog.LogManager.GetCurrentClassLogger().Info("Begin to acquire feature xray data :" + areaPrms.Count); iExtender.CollectXrayByFeatures(ref areaPrms, a_nXRayAQTime, a_bElementInfo); NLog.LogManager.GetCurrentClassLogger().Info("End acquiring feature xray data :" + areaPrms.Count); for (int i = 0; i < a_listParticles.Count; i++) { CPosXrayClr xray = a_listParticles[i].GetXray(); xray.SetXrayData(areaPrms[i].XrayData); var listElement = areaPrms[i].listElement; List chelist = new List(); foreach (var ele in listElement) { var che = new CElementChemistryClr(); che.SetName(ele.Key); che.SetPercentage(ele.Value); chelist.Add(che); } xray.SetElementQuantifyData(chelist); a_listParticles[i].SetXray(xray); } return true; } } }