| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 | using System;using System.Collections.Generic;using OTSCLRINTERFACE;using System.Drawing;using OTSDataType;using OTSModelSharp;using OTSModelSharp.ServiceCenter;using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel;namespace OTSMeasureApp{    public class SEMControlService     {        #region 全部变量声明                       //电镜设置对象        ISemController cSemfun = null;        IScanController cScanfun = null;        //IEDSController cEDSfun = null;               NLog.Logger log ;        #endregion        #region 构造方法            public SEMControlService()        {            log = NLog.LogManager.GetCurrentClassLogger();               }        /// <summary>        /// 初始化其他参数        /// </summary>        public bool InitAndConnection()        {            try            {                //控制类对象初始化                if (cSemfun == null)                {                    cSemfun = SemController.GetSEMController();                }                if (cScanfun == null)                {                    cScanfun = ScanController.GetScanController();                }                                         return cSemfun.Connect();            }            catch (Exception ex)            {                log.Error(ex.ToString() );                return false;            }        }        #endregion            #region 获取放大倍数        private double GetGMagnification()        {            try            {                double a_dMagnification = 0;                //获取放大倍数                bool result = cSemfun.GetMagnification(ref a_dMagnification);                if (result)                {                    //赋值 显示                    return a_dMagnification;                }                else                {                    //配置结果提示                    return 0;                }            }            catch (Exception)            {                return 0;            }        }        #endregion        #region 获取工作距离        private double GetSemWorkingDistance()        {            try            {                double a_WorkingDistance = 0;                //获取工作距离                bool result = cSemfun.GetWorkingDistance(ref a_WorkingDistance);                if (result)                {                    //赋值 显示                    return a_WorkingDistance;                }                else                {                    //配置结果提示                    return 0;                }            }            catch (Exception ex)            {                log.Error(ex.ToString() );                return 0;            }        }        private double GetSemBrightness()        {            try            {                double brightness = 0;                //获取工作距离                bool result = cSemfun.GetSemBrightness(ref brightness);                if (result)                {                    //赋值 显示                    return brightness;                }                else                {                    //配置结果提示                    return 0;                }            }            catch (Exception ex)            {                log.Error(ex.ToString());                return 0;            }        }        private double GetSemContrast()        {            try            {                double contrast = 0;                //获取工作距离                bool result = cSemfun.GetSemContrast(ref contrast);                if (result)                {                    //赋值 显示                    return contrast;                }                else                {                    //配置结果提示                    return 0;                }            }            catch (Exception ex)            {                log.Error(ex.ToString());                return 0;            }        }        private double GetSemKv()        {            try            {                double kv = 0;                //获取工作距离                bool result = cSemfun.GetSemHighTension(ref kv);                if (result)                {                    //赋值 显示                    return kv;                }                else                {                    //配置结果提示                    return 0;                }            }            catch (Exception ex)            {                log.Error(ex.ToString());                return 0;            }        }        #endregion        #region 设置放大倍数        public bool SetGMagnification(double a_dMagnification)        {            try            {                //获取放大倍数                bool result = cSemfun.SetMagnification(a_dMagnification);                return result;            }            catch (Exception ex)            {                log.Error( ex.ToString() );                return false;            }        }        #endregion        #region 设置工作距离        public bool SetSemWorkingDistance(double a_WorkingDistance)        {            try            {                bool result = cSemfun.SetWorkingDistance(a_WorkingDistance);                return result;            }            catch (Exception ex)            {                log.Error(ex.ToString() );                return false;            }        }        #endregion        public bool SetSembrightness(double bri)        {            try            {                bool result = cSemfun.SetSemBrightness(bri);                return result;            }            catch (Exception ex)            {                log.Error(ex.ToString());                return false;            }        }        public bool SetSemContrast(double contra)        {            try            {                bool result = cSemfun.SetSemContrast(contra);                return result;            }            catch (Exception ex)            {                log.Error(ex.ToString());                return false;            }        }        public bool SetSemHT(double ht)        {            try            {                bool result = cSemfun.SetSemHighTension(ht);                return result;            }            catch (Exception ex)            {                log.Error(ex.ToString());                return false;            }        }        #region 获取电镜参数 放大倍数与工作距离        public List<double> GetSEMMagAndWDParameter()        {            List<double> semParameter = new List<double>();            //放大倍数            double magnification = GetGMagnification();            //工作距离            double semWorkingDistance = GetSemWorkingDistance();            double bri = GetSemBrightness();            double contra=GetSemContrast();            double kv=GetSemKv();               //添加 放大倍数、工作距离            semParameter.Add(magnification);            semParameter.Add(semWorkingDistance);            semParameter.Add(bri);            semParameter.Add(contra);            semParameter.Add(kv);            return semParameter;        }        #endregion        public bool MoveSEMToPoint(double x, double y, double r)        {            return cSemfun.MoveSEMToPoint(x, y,r);        }        #region 驱动SEM到当前位置        public bool SetSEMCurrentLocation( Point mousePoint, CVisualStage stage)        {            try            {                             if (!stage.IfMouseInStage(mousePoint))                {                    //获取在范围中的样品                    return false;                                   }                              //判断是否鼠标在样品台范围中                Point OTSLocation = new Point();                              //鼠标在样品台中移动获取坐标                OTSLocation = stage.GetMouseOTSLocation(mousePoint);                PointF SEMPoint=new PointF(0,0);                 stage.m_SEMStageData.ConvertOTSToSEMCoord(OTSLocation,ref SEMPoint);                               bool result = cSemfun.MoveSEMToPoint(SEMPoint.X, SEMPoint.Y);                                   return result;                           }            catch (Exception ex)            {                log.Error(ex.ToString());                return false;            }        }        #endregion        #region 驱动SEM到中心位置        public bool DriveSEMToLocation(Point mousePoint,CVisualStage stage, List<CVisualFieldGDIObject> m_MeasureFieldGDIObjects)        {            try            {                                              if (!stage.IfMouseInStage(mousePoint))                {                    return false;                }                              //判断是否鼠标在样品台范围中                Point OTSLocation = new Point();                             //鼠标在样品台中移动获取坐标                OTSLocation = stage.GetMouseOTSLocation(mousePoint);                PointF SEMPoint = new PointF(0, 0);                    stage.m_SEMStageData.ConvertOTSToSEMCoord(OTSLocation,ref SEMPoint);                //循环single中所有对象 进行位置匹配                for (int i = 0; i < m_MeasureFieldGDIObjects.Count; i++)                {                    if (m_MeasureFieldGDIObjects[i].GetZoomedRegion.Contains(mousePoint))                    {                        //获取帧图左上坐标                        Point LT = new Point((int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Left, (int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Top);                        PointF lTLocation = stage.GetMouseOTSLocation(LT);                        //lTLocation =                            stage.m_SEMStageData.ConvertOTSToSEMCoord(lTLocation,ref lTLocation);                        //获取帧图右下坐标                        Point RB = new Point((int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Right, (int)m_MeasureFieldGDIObjects[i].GetZoomedRegionF().Bottom);                        PointF rbLocation = stage.GetMouseOTSLocation(RB);                        stage.m_SEMStageData.ConvertOTSToSEMCoord(rbLocation, ref rbLocation);                        float  diffX = Math.Abs(rbLocation.X - lTLocation.X) / 2;                        float  diffY = Math.Abs(rbLocation.Y - lTLocation.Y) / 2;                        //移动至帧图中心位置                         float  moveCenterX = lTLocation.X - diffX;                        float  moveCenterY = lTLocation.Y + diffY;                        bool result = cSemfun.MoveSEMToPoint(moveCenterX, moveCenterY);                        if (result)                        {                            return result;                        }                    }                }                               return false;        }            catch (Exception)            {                return false;            }        }        #endregion        #region 获取SEM位置        public bool GetSemLocation(ref List<double> SemLocation)        {            //获取SEM位置 a_dPositionX:X轴 a_dPositionY:Z轴 a_dPositionR:角度            double a_dPositionX = 0;            double a_dPositionY = 0;            double a_dPositionR = 0;            if (cSemfun != null)            {                if (cSemfun.GetSemPositionXY(ref a_dPositionX, ref a_dPositionY, ref a_dPositionR))                {                    SemLocation.Add(a_dPositionX);                    SemLocation.Add(a_dPositionY);                    SemLocation.Add(a_dPositionR);                    return true;                }            }            return false;        }        #endregion    }}
 |