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(); } /// /// 初始化其他参数 /// 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 GetSEMMagAndWDParameter() { List semParameter = new List(); //放大倍数 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 #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 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 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 } }