using OTSDataType; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel { public class CVisualStage { //original data CStage m_SStage; CSEMStageData m_SEMStageData; //interchange object StageDrawingData m_OTSSampleStageData; Point StageLTPointToSEMLocation = new Point(0, 0); Point StageRBPointToSEMLocation = new Point(0, 0); int m_VisualStageEdgeLength; int m_OTSCoordStageEdgeLength = 0; int m_totalCtrlWidth; int m_totalCtrlHeight; //记录绘制样品台时的中心位置 Point m_RegionStartCenterPoint = new Point(0, 0); //样品台存在的List集合 the rectangle on the edge of stage ,usually one. private List m_StageEdgeGDIObjects; //标样存在的List集合 usually it is a samll circle. private List m_SpecimenGDIObjects; private List m_SampleHoleGDIObjects;// the hole gdi of the stage //文字内容 private List m_ContentGDIObjects;//the text that will display in the hole. public StageDrawingData GetOTSSampleStageData() { return m_OTSSampleStageData; } public void SetOTSSampleStageData(StageDrawingData value) { m_OTSSampleStageData = value; } public CVisualStage(StageDrawingData oTSSampleStageData) { //样品台 m_StageEdgeGDIObjects = new List(); //标样 m_SpecimenGDIObjects = new List(); //样品孔 m_SampleHoleGDIObjects = new List(); //样品孔文字内容 m_ContentGDIObjects = new List(); m_OTSSampleStageData = new StageDrawingData(); SetOTSSampleStageData(oTSSampleStageData ?? throw new ArgumentNullException(nameof(oTSSampleStageData))); } public CVisualStage() { //样品台 m_StageEdgeGDIObjects = new List(); //标样 m_SpecimenGDIObjects = new List(); //样品孔 m_SampleHoleGDIObjects = new List(); //样品孔文字内容 m_ContentGDIObjects = new List(); m_OTSSampleStageData = new StageDrawingData(); } public CRectangleGDIObject GetEdgeGDIObj() { return m_StageEdgeGDIObjects[0]; } public CRectangleGDIObject GetHoleGDIBySampleName(string name) { foreach (var g in m_SampleHoleGDIObjects) { if (g.SampleName == name) { return g; } } return null; } public CRectangleGDIObject GetHoleGDIByHoleName(string name) { foreach (var g in m_SampleHoleGDIObjects) { if (g.Name == name) { return g; } } return null; } public CRectangleGDIObject GetHoleGDIByMousePoint(Point mousePoint) { foreach (var g in m_SampleHoleGDIObjects) { if (g.IfContains(mousePoint)) { return g; } } return null; } public void cleargdiobj() { m_StageEdgeGDIObjects.Clear(); m_SpecimenGDIObjects.Clear(); m_SampleHoleGDIObjects.Clear(); m_ContentGDIObjects.Clear(); } public void InitSampleStageData(CStage SStage, CSEMStageData SEMStageData, int ctrlWidth, int ctrlHeight) { //获取样品台信息 if (null == SStage) { return; } m_SStage = SStage; m_SEMStageData = SEMStageData; //获得样品台数据 GetOTSSampleStageData().sStageName = SStage.GetName(); GetOTSSampleStageData().bStageShape = (ShapeType)SStage.GetBoundary().GetShape(); GetOTSSampleStageData().StageDomain = SStage.GetBoundary().GetRectDomain(); GetOTSSampleStageData().bSampleShape = (ShapeType)SStage.GetSTD().GetShape(); GetOTSSampleStageData().SampleRect = (Rectangle)SStage.GetSTD().GetRectDomain(); int iSHoleCount = SStage.GetHoleList().Count; //样品孔个数 if (GetOTSSampleStageData().sSHoleInfoList.Count > 0) { GetOTSSampleStageData().sSHoleInfoList.Clear(); } var holeLst = SStage.GetHoleList(); for (int i = 0; i < iSHoleCount; i++) { CHole d = holeLst[i]; OTSSampleHoleInfo SHoleInfo = new OTSSampleHoleInfo(); //获取样品口的名称,形状,坐标 SHoleInfo.sSHoleName = d.GetName(); SHoleInfo.iSHoleShape = (int)d.GetShape(); Rectangle r = (Rectangle)d.GetRectDomain(); SHoleInfo.HoleRect = r; GetOTSSampleStageData().sSHoleInfoList.Add(SHoleInfo); } //获取SEMData 绘制样品 GetOTSSampleStageData().iScanFieldSize100 = SEMStageData.GetScanFieldSize100(); //放大倍数为100倍时的屏幕尺寸 GetOTSSampleStageData().iXAxisDir = (int)SEMStageData.GetXAxisDir(); GetOTSSampleStageData().iYAxisDir = (int)SEMStageData.GetYAxisDir(); GetOTSSampleStageData().iXAxisStartVal = SEMStageData.GetXAxis().GetStart(); GetOTSSampleStageData().iXAxisEndVal = SEMStageData.GetXAxis().GetEnd(); GetOTSSampleStageData().iYAxisStartVal = SEMStageData.GetYAxis().GetStart(); GetOTSSampleStageData().iYAxisEndVal = SEMStageData.GetYAxis().GetEnd(); string stageName = GetOTSSampleStageData().sStageName; //获取样品台 ShapeType StageShape = GetOTSSampleStageData().bStageShape; Point xDomain = new Point(GetOTSSampleStageData().StageDomain.Left, GetOTSSampleStageData().StageDomain.Top); Point yDomain = new Point(GetOTSSampleStageData().StageDomain.Right, GetOTSSampleStageData().StageDomain.Bottom); //OTS宽度高度差值 int widthDomain = Math.Abs(yDomain.X - xDomain.X); int heightDomain = Math.Abs(yDomain.Y - xDomain.Y); //样品台转换在电镜位置的宽度与高度 //设置样品台宽度 m_OTSCoordStageEdgeLength = widthDomain;//the stage must be a square.So we can only memorize an edge length.this is millimeter usually. m_VisualStageEdgeLength = ctrlHeight > ctrlWidth ? ctrlWidth : ctrlHeight;//the stage must be a square.So we can memorize an edge length only. //记录添加帧图的尺寸 鼠标滚动时使用的原值 m_totalCtrlWidth = ctrlWidth; m_totalCtrlHeight = ctrlHeight; return; } public PointF GetCenterPointF() { var item = m_StageEdgeGDIObjects[0].RegionF; //声明中心点变量 PointF pCenterPoint = new Point(); //获取在工作窗口中X,Y位置 pCenterPoint.X = item.X + item.Width / 2; pCenterPoint.Y = item.Y + item.Height / 2; return pCenterPoint; } public Point GetCenterPoint() { return m_StageEdgeGDIObjects[0].GetCenterPoint(); //声明中心点变量 } public void DrawSampleStage() { StageDrawingData SData = GetOTSSampleStageData(); try { if (SData.StageDomain.X == 0 && SData.StageDomain.Y == 0) { return; } string stageName = SData.sStageName; //获取样品台 ShapeType StageShape = SData.bStageShape; Point stageLeftTop = new Point(SData.StageDomain.Left, SData.StageDomain.Top); Point stageRightBottom = new Point(SData.StageDomain.Right, SData.StageDomain.Bottom); m_SEMStageData.ConvertSEMToOTSCoord(stageLeftTop, ref StageLTPointToSEMLocation); m_SEMStageData.ConvertSEMToOTSCoord(stageRightBottom, ref StageRBPointToSEMLocation); RectangleF Bourary; Bourary = GetCtrlCoordRectF(stageLeftTop, stageRightBottom); CreateRectangle CreateBourary; //0:圆角矩形 1:圆形 2:文字 3:矩形 if (SData.bStageShape == (ShapeType.RECTANGLE)) { CreateBourary = new CreateRectangle(Bourary, CreateRectangleType.SampleBackGround_Rectangle); } else { CreateBourary = new CreateRectangle(Bourary, CreateRectangleType.Circle); } //添加样品台 对象 //设置路径 GraphicsPath MeasurePath = new GraphicsPath(); if (StageShape == (int)CreateRectangleType.Circle) { MeasurePath.AddEllipse(CreateBourary.Region); } else { MeasurePath.AddRectangle(CreateBourary.Region); } CreateBourary.GPath = MeasurePath; CreateBourary.Shape = StageShape; m_StageEdgeGDIObjects.Add(CreateBourary); //绘制后的样品台中心位置 Point m_Region = GetCenterPoint(); //获取绘制后的样品台中心位置 if (m_RegionStartCenterPoint.X != m_Region.X || m_RegionStartCenterPoint.Y != m_Region.Y) { m_RegionStartCenterPoint = m_Region; } //获取样品孔 System.Collections.Generic.List ChloeClrList = SData.sSHoleInfoList; if (ChloeClrList.Count > 0) { for (int i = 0; i < ChloeClrList.Count; i++) { //获取微米信息 var xHole = new Point(ChloeClrList[i].HoleRect.Left, ChloeClrList[i].HoleRect.Top); var yHole = new Point(ChloeClrList[i].HoleRect.Right, ChloeClrList[i].HoleRect.Bottom); //将微米转换为像素 int widthHole = Math.Abs(yHole.X - xHole.X); int heightHole = Math.Abs(yHole.Y - xHole.Y); var RecF = GetCtrlCoordRectF(xHole, yHole); //获取矩形 CreateRectangle CreateHole = null; //0:圆角矩形 1:圆形 2:文字 3:矩形 if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.SampleBackGround_Rectangle) { CreateHole = new CreateRectangle(RecF, CreateRectangleType.Rectangle); } else { CreateHole = new CreateRectangle(RecF, CreateRectangleType.Circle); } //绘制样品孔路径 GraphicsPath HolePath = new GraphicsPath(); if (ChloeClrList[i].iSHoleShape == (int)CreateRectangleType.Circle) { HolePath.AddEllipse(CreateHole.Region); } else { HolePath.AddRectangle(CreateHole.Region); } CreateHole.GPath = HolePath; CreateHole.Name= ChloeClrList[i].sSHoleName; m_SampleHoleGDIObjects.Add(CreateHole); //添加文字 CreateRectangle CreateContent = GetCtrlCoordRect(xHole, yHole, CreateRectangleType.Rectangle, "", ""); //类型 文字:2 CreateContent.CreateType = CreateRectangleType.Text; CreateContent.Region = CreateContent.Region; CreateContent.strContent = ChloeClrList[i].sSHoleName; CreateContent.Name = ChloeClrList[i].sSHoleName; m_ContentGDIObjects.Add(CreateContent); } } //获取标样 ShapeType StageShapes = SData.bStageShape; stageLeftTop = new Point(SData.SampleRect.Left, SData.SampleRect.Top); stageRightBottom = new Point(SData.SampleRect.Right, SData.SampleRect.Bottom); //获取矩形 CreateRectangle CreateSTD; if (StageShapes == (int)CreateRectangleType.Circle) { CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenCircle, "", ""); } else { CreateSTD = GetCtrlCoordRect(stageLeftTop, stageRightBottom, CreateRectangleType.SpecimenRectangle, "", ""); } //绘制标样路径 GraphicsPath STDPath = new GraphicsPath(); if (StageShapes == (int)CreateRectangleType.Circle) { STDPath.AddEllipse(CreateSTD.Region); } else { STDPath.AddRectangle(CreateSTD.Region); } CreateSTD.GPath = STDPath; m_SpecimenGDIObjects.Add(CreateSTD); return; } catch (Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error( ex.ToString() ); } } public CreateRectangle GetCtrlCoordRect(Point OTSLeftTop, Point OTSRightBottom, CreateRectangleType type, string content, string name) { try { //将微米信息 转换为 像素 PointF xPoints = new Point(); PointF yPoints = new Point(); xPoints.X = (int)MillimetersToPixelsWidth(OTSLeftTop.X ); xPoints.Y = (int)MillimetersToPixelsWidth( OTSLeftTop.Y ); yPoints.X = (int)MillimetersToPixelsWidth( OTSRightBottom.X ); yPoints.Y = (int)MillimetersToPixelsWidth(OTSRightBottom.Y); //计算位置 xPoints = (PointF)CalculateLocationF(xPoints); yPoints = CalculateLocationF(yPoints); //获取图形四个点 float realStartX = Math.Min(xPoints.X, yPoints.X); float realStartY = Math.Min(xPoints.Y, yPoints.Y); float realEndX = Math.Max(xPoints.X, yPoints.X); float realEndY = Math.Max(xPoints.Y, yPoints.Y); //创建矩形 并返回类型对象 return new CreateRectangle(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, content, name); } catch (Exception) { return new CreateRectangle(new Rectangle(), 0, ""); } } public RectangleF GetCtrlCoordRectF(Point OTSLeftTop, Point OTSRightBottom) { try { //将微米信息 转换为 像素 PointF leftTop = new PointF(); PointF rightBottom = new PointF(); leftTop.X = (float)MillimetersToPixelsWidth( OTSLeftTop.X); leftTop.Y = (float)MillimetersToPixelsWidth( OTSLeftTop.Y); rightBottom.X = (float)MillimetersToPixelsWidth( OTSRightBottom.X); rightBottom.Y = (float)MillimetersToPixelsWidth(OTSRightBottom.Y); //计算位置 leftTop = CalculateLocationF(leftTop ); rightBottom = CalculateLocationF(rightBottom); //获取图形四个点 float realStartX = Math.Min(leftTop.X, rightBottom.X); float realStartY = Math.Min(leftTop.Y, rightBottom.Y); float realEndX = Math.Max(leftTop.X, rightBottom.X); float realEndY = Math.Max(leftTop.Y, rightBottom.Y); //创建矩形 并返回类型对象 return new RectangleF(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY)); } catch (Exception) { return new RectangleF(); } } public PointF CalculateLocationF(PointF point) { //获取窗体的高度与宽度 int screenWidth = m_totalCtrlWidth; int screenHeight = m_totalCtrlHeight; //获取屏幕中心点 PointF pointXY = new PointF(); PointF screenPoint = new PointF(screenWidth / 2, screenHeight / 2); pointXY.X = screenPoint.X + point.X; //(IsWidth == 0 ? screenPoint.X : screenPoint.Y) + point.X; pointXY.Y = screenPoint.Y - point.Y; return pointXY; } public double MillimetersToPixelsWidth( double PointVal) { var v = m_VisualStageEdgeLength; return PointVal / ((double)m_OTSCoordStageEdgeLength / v); } internal void DecreaseSampleCount(string holeName) { foreach (var hole in m_SampleHoleGDIObjects) { if (hole.Name == holeName) { hole.SampleCount -= 1; } } } public bool AddSample(SampleMeasurePara SMeasurePara, float globalZoomNum, out CRectangleGDIObject SampleGDIObject,out CRectangleGDIObject MeasureGDIObject) { Point xHole = new Point(SMeasurePara.MeasureRect.Left, SMeasurePara.MeasureRect.Top); Point yHole = new Point(SMeasurePara.MeasureRect.Right, SMeasurePara.MeasureRect.Bottom); RectangleF SampleRectangleF =GetCtrlCoordRectF(xHole, yHole); CRectangleGDIObject m_SampleGDIObject = GetCtrlCoordRect(xHole, yHole, (CreateRectangleType)SMeasurePara.iShape, "", ""); m_SampleGDIObject.Region = new Rectangle((int)SampleRectangleF.X, (int)SampleRectangleF.Y, (int)SampleRectangleF.Width, (int)SampleRectangleF.Height); m_SampleGDIObject.RegionF = SampleRectangleF; m_SampleGDIObject.DrawRegionF = SampleRectangleF; //测量区域名称 样品名称 m_SampleGDIObject.SampleName = SMeasurePara.sSampleName; //测量区域类型 m_SampleGDIObject.CreateType = (CreateRectangleType)SMeasurePara.iShape; string SampleHoleName = SMeasurePara.sampleHoleName; string SampleName = SMeasurePara.sSampleName; CRectangleGDIObject m_MeasureGDIObject; //设置样品选择状态为非工作样品 foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects) { if (item.Name == SampleHoleName) { //设置颜色 string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor); Color selColor = ColorTranslator.FromHtml(ColorStr); CreateRectangle NewSample = new CreateRectangle(item.Region, CreateRectangleType.SelectSample, item.Shape, item.Name, selColor); //累加样品数量 item.SampleCount += 1; item.IsWorkSample = true; NewSample.SampleName = SampleName; NewSample.Name = item.Name; //设置当前添加的样品为工作样品 NewSample.IsWorkSample = true; // 获取样品孔的大小与初始大小 NewSample.Region = item.Region; NewSample.RegionF = item.RegionF; NewSample.DrawRegionF = item.DrawRegionF; //绘制样品路径 GraphicsPath NewSamplePath = new GraphicsPath(); if (NewSample.Shape == (int)CreateRectangleType.Circle) { NewSamplePath.AddEllipse(NewSample.Region); } else { NewSamplePath.AddRectangle(NewSample.Region); } NewSample.GPath = NewSamplePath; SampleGDIObject = NewSample; //获取测量区域尺寸与位置 m_MeasureGDIObject = GetSampleMeasureInfo(NewSample, m_SampleGDIObject, globalZoomNum); //设置样品孔名称 m_MeasureGDIObject.Name = item.Name; //根据节点设置样品台窗口中所选择的样品名称 //添加测量区域 bool ret= AddMeasure(m_MeasureGDIObject,out MeasureGDIObject); return ret; } } SampleGDIObject = null; MeasureGDIObject = null; return false; } #region 根据样品位置 获取测量区域位置 public CRectangleGDIObject GetSampleMeasureInfo(CRectangleGDIObject NewSample, CRectangleGDIObject m_MeasureGDIObjects, float globalZoomNum) { //根据样品位置 获取测量区域位置 int MeasurePointX = (int)(NewSample.Region.Location.X + ((NewSample.Region.Size.Width - (m_MeasureGDIObjects.Region.Width * globalZoomNum)) / 2)); int MeasurePointY = (int)(NewSample.Region.Location.Y + ((NewSample.Region.Size.Height - (m_MeasureGDIObjects.Region.Height * globalZoomNum)) / 2)); int MeasureWidth = Convert.ToInt32(m_MeasureGDIObjects.Region.Width * globalZoomNum); int MeasureHeight = Convert.ToInt32(m_MeasureGDIObjects.Region.Height * globalZoomNum); float MeasureFPointX = (float)(NewSample.RegionF.Location.X + (NewSample.RegionF.Size.Width - m_MeasureGDIObjects.Region.Width) / 2); float MeasureFPointY = (float)(NewSample.RegionF.Location.Y + (NewSample.RegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2); float MeasureFWidth = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Width); float MeasureFHeight = Convert.ToSingle(m_MeasureGDIObjects.RegionF.Height); float MeasureDrawPointX = (float)(NewSample.DrawRegionF.Location.X + (NewSample.DrawRegionF.Size.Width - m_MeasureGDIObjects.Region.Width) / 2); float MeasureDrawPointY = (float)(NewSample.DrawRegionF.Location.Y + (NewSample.DrawRegionF.Size.Height - m_MeasureGDIObjects.Region.Height) / 2); float MeasureDrawWidth = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Width); float MeasureDrawHeight = Convert.ToSingle(m_MeasureGDIObjects.DrawRegionF.Height); m_MeasureGDIObjects.Region = new Rectangle(new Point(MeasurePointX, MeasurePointY), new Size(MeasureWidth, MeasureHeight)); m_MeasureGDIObjects.RegionF = new RectangleF(new PointF(MeasureFPointX, MeasureFPointY), new SizeF(MeasureFWidth, MeasureFHeight)); m_MeasureGDIObjects.DrawRegionF = new RectangleF(new PointF(MeasureDrawPointX, MeasureDrawPointY), new SizeF(MeasureDrawWidth, MeasureDrawHeight)); return m_MeasureGDIObjects; } public SampleMeasurePara GetSampleMeasurePara(CRectangleGDIObject MeasureItem) { //获取测量区域的OTS位置与尺寸 SampleMeasurePara sampleMeasurePara = GetMeasureInfo(MeasureItem); //获取样品台 中心点 PointF RectanglePointCenter = GetCenterPointF(); //获取样品台中心点 float CenterX = PixelConvertToMicron((int)RectanglePointCenter.X ); float CenterY = PixelConvertToMicron((int)RectanglePointCenter.Y); Rectangle sampleMeasureRect = new Rectangle(); //根据样品台中心点获取开始点位置 sampleMeasureRect.X = -((int)CenterX - sampleMeasurePara.MeasureRect.X); sampleMeasureRect.Y = (int)CenterY - sampleMeasurePara.MeasureRect.Bottom; sampleMeasurePara.MeasureRect.X = sampleMeasureRect.X; sampleMeasurePara.MeasureRect.Y = sampleMeasureRect.Y; for (int i = 0; i < sampleMeasurePara.DrawPolygonPointRegionF.Count; i++) { int X = -((int)CenterX - (int)sampleMeasurePara.DrawPolygonPointRegionF[i].X); int Y = (int)CenterY - (int)sampleMeasurePara.DrawPolygonPointRegionF[i].Y; sampleMeasurePara.DrawPolygonPointRegionF[i] = new Point(X, Y); } sampleMeasurePara.sSampleName = MeasureItem.SampleName ; sampleMeasurePara.sampleHoleName =MeasureItem.Name; return sampleMeasurePara; } public SampleMeasurePara GetMeasureInfo(CRectangleGDIObject item) { SampleMeasurePara sampleMeasurePara = new SampleMeasurePara(); //设置测量区域位置与尺寸 float left = 0; float Top = 0; float Right = 0; float Bottom = 0; float Widths = 0; float Height = 0; //设置测量区域位置与尺寸 left = PixelConvertToMicron((int)item.RegionF.X); Top = PixelConvertToMicron((int)item.RegionF.Y); Right = PixelConvertToMicron((int)item.RegionF.Right); Bottom = PixelConvertToMicron((int)item.RegionF.Bottom); Widths = PixelConvertToMicron((int)item.RegionF.Width); Height = PixelConvertToMicron((int)item.RegionF.Height); //保存原位置 RectangleF polygonRectPara = item.DrawRegionF; if (item.CreateType == CreateRectangleType.Polygon) { polygonRectPara = OTSSamplespaceGraphicsPanelFun.GetPolygonToMinRectangle(item.DrawPolygonPointRegionF); //设置测量区域位置与尺寸 left = PixelConvertToMicron((int)polygonRectPara.X); Top = PixelConvertToMicron((int)polygonRectPara.Y); Right = PixelConvertToMicron((int)polygonRectPara.Right); Bottom = PixelConvertToMicron((int)polygonRectPara.Bottom); Widths = PixelConvertToMicron((int)polygonRectPara.Width); Height = PixelConvertToMicron((int)polygonRectPara.Height); } //设置测量区域 PointF startPoint = new PointF(left, Top); SizeF MeasureSize = new SizeF(Widths, Height); sampleMeasurePara.MeasureRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)MeasureSize.Width, (int)MeasureSize.Height)); //设置样品孔名称 sampleMeasurePara.sampleHoleName = item.Name; //设置样品名称 sampleMeasurePara.sSampleName = item.SampleName; //设置测量区域形状 sampleMeasurePara.iShape = item.Shape; //设置多边形点集合 sampleMeasurePara.PolygonPointRegion = PointFConvertPoint(ConvertPolygonPointToOTSPoint(item.PolygonPointRegionF)); sampleMeasurePara.PolygonPointRegionF = ConvertPolygonPointToOTSPoint(item.PolygonPointRegionF); sampleMeasurePara.DrawPolygonPointRegionF = ConvertPolygonPointToOTSPoint(item.DrawPolygonPointRegionF); return sampleMeasurePara; } public List ConvertPolygonPointToOTSPoint(List polygonPointList) { List OTSPoint = new List(); float X = 0; float Y = 0; if (polygonPointList != null) { foreach (var item in polygonPointList) { X = (float)(item.X * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength)); Y = (float)(item.Y * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength)); OTSPoint.Add(new PointF(X, Y)); } } return OTSPoint; } public float PixelConvertToMicron(int Pixel) { return (float)(Pixel * ((double)m_OTSCoordStageEdgeLength / m_VisualStageEdgeLength)); } public List PointFConvertPoint(List Points) { List PointFs = new List(); if (Points != null) { foreach (var itemPoint in Points) { PointFs.Add(new Point((int)itemPoint.X, (int)itemPoint.Y)); } } return PointFs; } public PointF[] PointConvertPointF(Point[] Points) { PointF[] PointFs = new PointF[Points.Length]; if (Points != null) { for (int i = 0; i < Points.Length; i++) { PointFs[i] = Points[i]; } } return PointFs; } public List PointConvertPointF(List Points) { List PointFs = new List(); if (Points != null) { foreach (var itemPoint in Points) { PointFs.Add(itemPoint); } } return PointFs; } #endregion #region 添加测量 /// /// 添加测量 /// /// 是否选择样品 0:未选择 1:选择 /// 样品名称 /// 是否成功 public bool AddMeasure( CRectangleGDIObject MeasureGDIObject,out CRectangleGDIObject outMeasureRect) { //添加测量区域 CreateRectangleType shape = MeasureGDIObject.CreateType;// == 1 ? 1 : 0; GraphicsPath MeasurePath = new GraphicsPath(); if (shape == CreateRectangleType.Rectangle) { MeasurePath.AddRectangle(MeasureGDIObject.Region); } else { MeasurePath.AddEllipse(MeasureGDIObject.Region); } //缩小与样品的尺寸 Rectangle rectMeasure = MeasureGDIObject.Region; Color MeasureColor = Color.Red; CreateRectangle MeasureRect = new CreateRectangle(rectMeasure, CreateRectangleType.MeasureArea, MeasureGDIObject.Shape, MeasureGDIObject.Name, MeasureGDIObject.SampleName, MeasureColor); MeasureRect.GPath = MeasurePath; MeasureRect.sampleName = MeasureGDIObject.SampleName; MeasureRect.Name = MeasureGDIObject.Name; //获取缩放前尺寸与位置 MeasureRect.RegionF = MeasureGDIObject.RegionF; MeasureRect.DrawRegionF = MeasureGDIObject.DrawRegionF; outMeasureRect = MeasureRect; return true; } #endregion public bool CheckMeasureAreaIsBeyondStageArea(RectangleF RMeasureArea) { otsdataconst.DOMAIN_SHAPE iShape = (otsdataconst.DOMAIN_SHAPE)m_StageEdgeGDIObjects[0].CreateType; Rectangle pStageArea = m_StageEdgeGDIObjects[0].Region; Rectangle pMeasureArea = new Rectangle((int)RMeasureArea.Left, (int)RMeasureArea.Top, (int)RMeasureArea.Width, (int)RMeasureArea.Height); CDomain a_DomainMeasureArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pMeasureArea); CDomain a_DomainStageArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pStageArea); return a_DomainStageArea.DomainInDomain(a_DomainMeasureArea); } public void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm) { //鼠标在样品台中移动获取坐标 Point mousePoint = GetMouseSEMLocation(mPoint); Point SEMPoint = new Point(); m_SEMStageData.ConvertOTSToSEMCoord(mousePoint, ref SEMPoint); //将微米转换为毫米 float mousePointX = Convert.ToSingle((SEMPoint.X / 1000).ToString("F2")); float mousePointY = Convert.ToSingle((SEMPoint.Y / 1000).ToString("F2")); //将样品台坐标转换为Sem 坐标 //编辑显示内容 string STSemCoordinate = "X:" + mousePointX + "|Y:" + mousePointY + ""; //显示XY轴 m_MeasureAppForm.ShowSemCoordvAL(STSemCoordinate); } public Point GetMouseSEMLocation(Point mousePoint) { var domain = GetOTSSampleStageData().StageDomain; Point rectLocation = m_StageEdgeGDIObjects[0].Region.Location; //样品台尺寸 Size rectSize = m_StageEdgeGDIObjects[0].Region.Size; //鼠标在工作区域中的位置 //OTS坐标中鼠标的位置 int OTSX = -((rectLocation.X + rectSize.Width / 2) - mousePoint.X); int OTSY = -(mousePoint.Y - (rectLocation.Y + rectSize.Height / 2)); //OTS坐标中鼠标的尺寸位置 double OTSWidth = 0; double OTSHeight = 0; int width = m_VisualStageEdgeLength; int height = m_VisualStageEdgeLength; //获取样品台两个坐标点 var XDomain = new Point(domain.Left, domain.Top); var YDomain = new Point(domain.Right, domain.Bottom); //转换类型 Point xDomain = ((System.Drawing.Point)XDomain); Point yDomain = ((System.Drawing.Point)YDomain); //宽度 int widthDomain = Math.Abs(((Point)yDomain).X - ((Point)xDomain).X); int heightDomain = Math.Abs(((Point)yDomain).Y - ((Point)xDomain).Y); //换算鼠标在OTS坐标中的位置 OTSWidth = (OTSX * ((double)widthDomain / width)); OTSHeight = (OTSY * ((double)widthDomain / height)); Point OTSMousePosition = new Point(Convert.ToInt32(Math.Round(OTSWidth, 0)), Convert.ToInt32(Math.Round(OTSHeight, 0))); return OTSMousePosition; } public bool IfMouseInSampleHole(Point mousePoint,out CRectangleGDIObject gdiItem) { foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects) { if (item.IfContains(mousePoint)) { gdiItem = item; return true; ; } } gdiItem = null; return false; } public bool IfMouseInStage(Point mousePoint,out CRectangleGDIObject gdiobj) { foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects) { if (item.IfContains(mousePoint)) { gdiobj = item; return true; } } gdiobj = null; return false; } public bool IfMouseInStage(Point mousePoint ) { foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects) { if (item.IfContains(mousePoint)) { return true; } } return false; } public void OnMouseMove(CRectangleGDIObject item,MouseEventArgs e) { foreach (CRectangleGDIObject sampleHoleItem in m_SampleHoleGDIObjects) { //获取样品孔中心点 Point sampleHoleCenterPoint = sampleHoleItem.GetCenterPoint(); if (item.IfContains(sampleHoleCenterPoint)) { if (item.Name != sampleHoleItem.Name) { //获取颜色 string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleColor); item.SelColor = ColorTranslator.FromHtml(ColorStr); break; } } else { //获取颜色 string ColorStr = OTSSamplespaceGraphicsPanelFun.GetColorValue(ColorType.SampleSelColor); item.SelColor = ColorTranslator.FromHtml(ColorStr); } } } public void OnMouseMove( MouseEventArgs e) { foreach (CRectangleGDIObject item in m_ContentGDIObjects) { item.IsDragging = true; item.DraggingPoint = e.Location; } foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects) { item.IsDragging = true; item.DraggingPoint = e.Location; } foreach (CRectangleGDIObject item in m_SpecimenGDIObjects) { item.IsDragging = true; item.DraggingPoint = e.Location; } } public List GetAllGDIObject() { var allobj = new List(); foreach (CRectangleGDIObject item in m_StageEdgeGDIObjects) { allobj.Add(item); } foreach (CRectangleGDIObject item in m_SampleHoleGDIObjects) { allobj.Add(item); } foreach (CRectangleGDIObject item in m_SpecimenGDIObjects) { allobj.Add(item); } foreach (CRectangleGDIObject item in m_ContentGDIObjects) { allobj.Add(item); } return allobj; } public bool NewLocationDrawSingleInfo( Point moveToSEMLocation, List UpdateLocationGDIObject, CRectangleGDIObject WorkMeasure, float m_GlobalZoomNum) { //样品台中心点位置 Point m_StageCenterPoint = GetCenterPoint(); //当前与中心点相差距离 int m_StageCenterDiffX = 0; int m_StageCenterDiffY = 0; Point m_WorkMeasureCenterPoint = new Point(); if (UpdateLocationGDIObject == null) { return false; } int diffNewX = 0; int diffNewY = 0; bool IsOK = true; diffNewX = moveToSEMLocation.X; diffNewY = moveToSEMLocation.Y; if (IsOK) { foreach (var item in UpdateLocationGDIObject) { m_WorkMeasureCenterPoint = WorkMeasure.GetCenterPoint(); m_StageCenterDiffX = m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X;//(int)((m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X) * m_GlobalZoomNum); m_StageCenterDiffY = m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y;// (int)((m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y) * m_GlobalZoomNum); diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum); diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum); //根据鼠标_更改测量区域的位置 item.Region = new Rectangle(new Point(item.Region.X + m_StageCenterDiffX + diffNewX, item.Region.Y + m_StageCenterDiffY - diffNewY), new Size(item.Region.Width, item.Region.Height)); item.RegionF = new RectangleF(new PointF(item.RegionF.X + (m_StageCenterDiffX + diffNewX), item.RegionF.Y + (m_StageCenterDiffY - diffNewY)), new SizeF(item.RegionF.Width, item.RegionF.Height)); item.DrawRegionF = new RectangleF(new PointF(item.DrawRegionF.X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.DrawRegionF.Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum), new SizeF(item.DrawRegionF.Width, item.DrawRegionF.Height)); } } return IsOK; } public void NewLocationDrawMeasureInfo( Point moveToSEMLocation, List UpdateLocationGDIObject, float m_GlobalZoomNum) { //样品台中心点位置 Point m_StageCenterPoint = GetCenterPoint(); //当前与中心点相差距离 int m_StageCenterDiffX = 0; int m_StageCenterDiffY = 0; int diffNewX = 0; int diffNewY = 0; Point m_UpdateCenterPoint = new Point(); foreach (var item in UpdateLocationGDIObject) { if (item.IsWorkSample) { m_UpdateCenterPoint = item.GetCenterPoint(); m_StageCenterDiffX = (int)((m_StageCenterPoint.X - m_UpdateCenterPoint.X) * 1); m_StageCenterDiffY = (int)((m_StageCenterPoint.Y - m_UpdateCenterPoint.Y) * 1); diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum); diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum); //根据鼠标_更改测量区域的位置 item.Region = new Rectangle(new Point(item.Region.X + m_StageCenterDiffX + diffNewX, item.Region.Y + m_StageCenterDiffY - diffNewY), new Size(item.Region.Width, item.Region.Height)); item.RegionF = new RectangleF(new PointF(item.RegionF.X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.RegionF.Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum), new SizeF(item.RegionF.Width, item.RegionF.Height)); item.DrawRegionF = item.RegionF; //修改多边形的绘制点集合 if (item.CreateType == CreateRectangleType.Polygon) { for (int i = 0; i < item.PolygonPointRegion.Count; i++) { item.PolygonPointRegion[i] = new Point(item.PolygonPointRegion[i].X + m_StageCenterDiffX + diffNewX, item.PolygonPointRegion[i].Y + m_StageCenterDiffY - diffNewY); item.PolygonPointRegionF[i] = new PointF(item.PolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX), item.PolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY)); item.DrawPolygonPointRegionF[i] = new PointF(item.DrawPolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.DrawPolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum); } } } } } public SampleHolePara GetSampleHolePara(CRectangleGDIObject sampleHoleItem) { //int w = (IsWidth == 0 ? Width : Height); SampleHolePara sampleHoleParas = new SampleHolePara(); //获取样品孔的OTS位置与尺寸 sampleHoleParas = GetSampleHoleInfo(sampleHoleItem); //获取工作区域位置与尺寸 Rectangle WorkAreaRect = new Rectangle(0, 0, m_totalCtrlWidth, m_totalCtrlHeight); //获取工作区域 中心点 Point ScreenPointCenter = GetCenterPoint(WorkAreaRect); //获取样品台 中心点 PointF RectanglePointCenter =GetCenterPoint(); //获取屏幕中心点 float WorkAreaCenterPointX = PixelConvertToMicron(ScreenPointCenter.X); float WorkAreaCenterPointY = PixelConvertToMicron(ScreenPointCenter.Y); //获取样品台中心点 float CenterX = PixelConvertToMicron((int)RectanglePointCenter.X); float CenterY = PixelConvertToMicron((int)RectanglePointCenter.Y); Rectangle sampleHoleRect = new Rectangle(); //根据样品台中心点获取开始点位置 sampleHoleRect.X = -((int)CenterX - sampleHoleParas.SampleHoleRect.X); sampleHoleRect.Y = (int)CenterY - sampleHoleParas.SampleHoleRect.Bottom; sampleHoleParas.SampleHoleRect.X = sampleHoleRect.X; sampleHoleParas.SampleHoleRect.Y = sampleHoleRect.Y; return sampleHoleParas; } public Point GetCenterPoint(Rectangle rect) { //声明 Point centerPoint = new Point(); //设置X,Y坐标 centerPoint.X = rect.X + rect.Width / 2; centerPoint.Y = rect.Y + rect.Height / 2; return centerPoint; } public SampleHolePara GetSampleHoleInfo(CRectangleGDIObject item) { SampleHolePara sampleHolePara = new SampleHolePara(); //保存原位置 Rectangle rectPara = item.Region; //设置测量区域 sampleHolePara.SampleHoleRect = item.Region; //设置测量区域位置与尺寸 float left = PixelConvertToMicron((int)item.RegionF.X); float Top = PixelConvertToMicron((int)item.RegionF.Y); float Right = PixelConvertToMicron((int)item.RegionF.Right); float Bottom = PixelConvertToMicron((int)item.RegionF.Bottom); float Widths = PixelConvertToMicron((int)item.RegionF.Width); float Height = PixelConvertToMicron((int)item.RegionF.Height); PointF startPoint = new PointF(left, Top); SizeF sampleHoleSize = new SizeF(Widths, Height); sampleHolePara.SampleHoleRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)sampleHoleSize.Width, (int)sampleHoleSize.Height)); //设置样品孔名称 sampleHolePara.sHoleName = item.Name; //设置测量区域形状 sampleHolePara.iShape = item.Shape; return sampleHolePara; } } }