| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 | using OTSDataType;using FEIApiControl;using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using OTSCLRINTERFACE;namespace OTSModelSharp.ServiceInterface{    using  OTSCLRINTERFACE;    using System.Drawing;    using System.Windows.Forms;    public class EDSController : IEDSController    {        public COTSControlFunExport eds;        static EDSController edsctrl = null;        public static APIClass ApiClass = null;        private static bool isFEI = false;        private int AnalyExpCount = 100000;        private string strResolution = "";        private int width = 0;        private int height = 0;        public List<string> nameList = new List<string>();        public static EDSController GetEDSController()        {            if (FileHelper.GetXMLInformations("EDSName") == "FEI")            {                isFEI = true;            }            if (edsctrl == null)            {                edsctrl = new EDSController();            }            return edsctrl;        }        private EDSController()        {            if (isFEI)            {                ApiClass = new APIClass();                Connect();            }            else            {                eds = OTSCLRINTERFACE.COTSControlFunExport.GetControllerInstance();            }        }        public bool GetXRayByFeatures(List<COTSParticleClr> a_listParticles,  double a_nXRayAQTime, bool a_bElementInfo)        {            if (isFEI)            {                for (int i = 0; i < a_listParticles.Count; i++)                {                    Dictionary<string, double> eleItems = new Dictionary<string, double>();                    uint[] spectrumItems = new uint[2000];                    if (ApiClass.GetSupportPolygon())//判断DLL是否支持多边形面扫                    {                        List<Point> points = CImageHandler.FindContoursBySegment(width, height, a_listParticles[i].GetFeature().GetSegmentsList());                        if (!ApiClass.GetXRayByPolygon(points, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))                        {                            return false;                        }                    }                    else                    {                        Rectangle rectangle = (Rectangle)a_listParticles[i].GetParticleRect();                        if (!ApiClass.GetXRayByRect(rectangle, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))                        {                            return false;                        }                    }                    a_listParticles[i].GetXray().SetXrayData(spectrumItems);                    if (a_bElementInfo)                    {                        List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();                        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;            }            else            {                if (!eds.IsConnected())                {                    return false;                }                if (eds.GetEDSName() == "EDS Bruker")                {                    for (int i = 0; i < a_listParticles.Count; i++)                    {                        List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();                        for (int j = 0; j < nameList.Count; j++)                        {                            CElementChemistryClr chemistryClr = new CElementChemistryClr();                            chemistryClr.SetName(nameList[j]);                            elementChemistryClrs.Add(chemistryClr);                        }                        a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);                    }                }                    COTSParticleClr[] parts = a_listParticles.ToArray();                return eds.GetXRayByFeatures((uint)a_nXRayAQTime, parts, a_bElementInfo);            }        }        public bool GetXRayByPoints(List<COTSParticleClr> a_listParticles, uint a_nXRayAQTime, bool a_bElementInfo)        {            if (isFEI)            {                for (int i = 0; i < a_listParticles.Count; i++)                {                    Point point = (Point)a_listParticles[i].GetXRayPos();                    Dictionary<string, double> eleItems = new Dictionary<string, double>();                    uint[] spectrumItems = new uint[2000];                    if (!ApiClass.GetXRayByPoint(point.X, point.Y, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref spectrumItems))                    {                        return false;                    }                    a_listParticles[i].GetXray().SetXrayData(spectrumItems);                    if (a_bElementInfo)                    {                        List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();                        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;            }            else            {                if (!eds.IsConnected())                {                    return false;                }                int xrayNum = a_listParticles.Count;                Point[] Ps = new Point[xrayNum];                for (int i = 0; i < xrayNum; i++)                {                    Point p = (Point)a_listParticles[i].GetXRayPos();                    Ps[i].X = p.X;                    Ps[i].Y = p.Y;                }                if (eds.GetEDSName() == "EDS Bruker")                {                    for (int i = 0; i < a_listParticles.Count; i++)                    {                        List<CElementChemistryClr> elementChemistryClrs = new List<CElementChemistryClr>();                        for (int j = 0; j < nameList.Count; j++)                        {                            CElementChemistryClr chemistryClr = new CElementChemistryClr();                            chemistryClr.SetName(nameList[j]);                            elementChemistryClrs.Add(chemistryClr);                        }                        a_listParticles[i].GetXray().SetElementQuantifyData(elementChemistryClrs);                    }                }                COTSParticleClr[] parts = a_listParticles.ToArray();                return eds.GetXRayByPoints(a_nXRayAQTime, Ps, parts, a_bElementInfo);            }        }        public bool CollectSpectrum(uint a_nXRayAQTime, ref uint[] a_XrayData)        {            if (isFEI)            {                Dictionary<string, double> eleItems = new Dictionary<string, double>();                return ApiClass.AcquireSpectrum(false, ref eleItems, ref a_XrayData);            }            else            {                if (!eds.IsConnected())                {                    return false;                }                return eds.CollectSpectrum(a_nXRayAQTime, ref a_XrayData);            }        }        public bool GetXRayBySinglePoint(uint a_nXRayAQTime, Point point, ref uint[] a_XrayData, ref string ele, bool a_bElementInfo)        {            if (isFEI)            {                double x = point.X;                double y = point.Y;                double z = 0;                double r = 0;                double t = 0;                Dictionary<string, double> eleItems = new Dictionary<string, double>();                if (!ApiClass.GetSemPositionXYZRT(ref x, ref y, ref z, ref r, ref t))                {                    return false;                }                return ApiClass.GetXRayByPoint((int)x, (int)y, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref a_XrayData);            }            else            {                if (!eds.IsConnected())                {                    return false;                }                return eds.GetXRayBySinglePoint(a_nXRayAQTime, point, ref a_XrayData, ref ele, a_bElementInfo);            }        }        public bool GetXRayBySingleFeature(uint a_nXRayAQTime, COTSFeatureClr fea, ref uint[] a_XrayData, ref string ele, bool a_bElementInfo)        {            if (isFEI)            {                Dictionary<string, double> eleItems = new Dictionary<string, double>();                if (ApiClass.GetSupportPolygon())//判断DLL是否支持多边形面扫                {                    List<Point> points = CImageHandler.FindContoursBySegment(width, height, fea.GetSegmentsList());                    return ApiClass.GetXRayByPolygon(points, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref a_XrayData);                }                else                {                    Rectangle rectangle = new Rectangle();                    rectangle.X = fea.GetSegmentsList().Min(a => a.GetStart());                    rectangle.Y = fea.GetSegmentsList().Min(a => a.GetHeight());                    rectangle.Width = fea.GetSegmentsList().Max(a => a.GetLength());                    rectangle.Height = Math.Abs(rectangle.Y - rectangle.X);                    return ApiClass.GetXRayByRect(rectangle, strResolution, a_nXRayAQTime, AnalyExpCount, a_bElementInfo, ref eleItems, ref a_XrayData);                }            }            else            {                if (!eds.IsConnected())                {                    return false;                }                return eds.GetXRayBySingleFeature(a_nXRayAQTime, fea, ref a_XrayData, ref ele, false);            }        }        public bool GetXRayElements(uint a_nXRayAQTime, ref uint[] a_XrayData, ref ValueType a_nElementNum, ref string a_strResult)        {            if (isFEI)            {                Dictionary<string, double> eleItems = new Dictionary<string, double>();                bool isTrue = ApiClass.AcquireSpectrum(true, ref eleItems, ref a_XrayData);                a_nElementNum = eleItems.Count;                for (int i = 0; i < eleItems.Count; i++)                {                    a_strResult += eleItems.ElementAt(i).Key + ":" + eleItems.ElementAt(i).Value + "\n";                }                return isTrue;            }            else            {                if (!eds.IsConnected())                {                    return false;                }                return eds.GetXRayElements(a_nXRayAQTime, ref a_XrayData, ref a_nElementNum, ref a_strResult);            }        }        public bool GetXRayAndElements(uint a_nXRayAQTime, int dMouseImgX, int dMouseImgY, ref uint[] a_XrayData, ref ValueType a_nElementNum, ref string a_strResult)        {            if (isFEI)            {                Dictionary<string, double> eleItems = new Dictionary<string, double>();                bool isTrue = ApiClass.GetXRayByPoint(dMouseImgX, dMouseImgY, strResolution, a_nXRayAQTime, AnalyExpCount, true, ref eleItems, ref a_XrayData);                a_nElementNum = eleItems.Count;                for (int i = 0; i < eleItems.Count; i++)                {                    a_strResult += eleItems.ElementAt(i).Key + ":" + eleItems.ElementAt(i).Value + "\n";                }                return isTrue;            }            else            {                if (!eds.IsConnected())                {                    return false;                }                return eds.GetXRayAndElements(a_nXRayAQTime, dMouseImgX, dMouseImgY, ref a_XrayData, ref a_nElementNum, ref a_strResult);            }        }        public bool Init()        {            if (isFEI)            {                return ApiClass.isConnect();            }            else            {                bool m_init = eds.EDSInit();                return m_init;            }        }        public bool ScanInit()        {            if (isFEI)            {                return ApiClass.isConnect();            }            else            {                bool m_init = eds.ScanInit();                return m_init;            }        }        public bool Connect()        {            if (isFEI)            {                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);            }            else            {                if (!eds.Init())                {                    return false;                }                if (eds.IsConnected())                {                    return true;                }                return eds.ConncetSem();            }        }        public bool DisConnect()        {            if (isFEI)            {                return ApiClass.DisConnect();            }            else            {                if (eds.IsConnected())                {                    return eds.DisconnectSem();                }                return true;            }        }        public bool SetResolution(int ResolutionWidth, int ResolutionHeight)        {            if (isFEI)            {                width = ResolutionWidth;                height = ResolutionHeight;                strResolution = ResolutionWidth + "x" + ResolutionHeight;            }            return true;        }        public bool SetAnalyExpCount(int MaxCounts)        {            if (isFEI)            {                AnalyExpCount = MaxCounts;            }            return true;        }    }}
 |