1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675 |
- using OTSCLRINTERFACE;
- using OTSDataType;
- using OTSCommon;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using OTSModelSharp.ServiceInterface;
- using OTSModelSharp.ServiceCenter;
- namespace OTSMeasureApp
- {
- public class OTSSamplespaceGraphicsPanelFun
- {
- #region 构造方法
- public OTSSamplespaceGraphicsPanelFun()
- {
-
- }
- #endregion
-
- #region 鼠标在样品台中移动获取坐标
- /// <summary>
- /// 鼠标在样品台中移动获取坐标
- /// </summary>
- public static Point GetMouseLocationInRectangleGDIObject(Point mousePoint, ARectangleGDIObject RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, int Width, int Height)
- {
- if (RectangleGDIObjects.Region.Contains(mousePoint))
- {
- Point rectLocation = RectangleGDIObjects.Region.Location;
- //样品台尺寸
- Size rectSize = RectangleGDIObjects.Region.Size;
- //鼠标在工作区域中的位置
- string x = mousePoint.X.ToString();
- string Y = mousePoint.Y.ToString();
- //样品台起始位置c
- string rectLocationX = rectLocation.X.ToString();
- string rectLocationY = rectLocation.Y.ToString();
- //OTS中心点
- string rectLocationCenterX = (rectLocation.X + rectSize.Width / 2).ToString();
- string rectLocationCenterY = (rectLocation.Y + rectSize.Height / 2).ToString();
- //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;
- if (oTSSampleStageData != null)
- {
- //获取样品台两个坐标点
- ValueType XDomain = new Point(oTSSampleStageData.StageDomain.Left, oTSSampleStageData.StageDomain.Top);
- ValueType YDomain = new Point(oTSSampleStageData.StageDomain.Right, oTSSampleStageData.StageDomain.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 / (IsWidth == 0 ? (double)Width : (double)Height)));
- OTSHeight = (OTSY * ((double)widthDomain / (IsWidth == 0 ? (double)Width : (double)Height)));
- }
- Point OTSMousePosition = new Point(Convert.ToInt32(Math.Round(OTSWidth, 0)), Convert.ToInt32(Math.Round(OTSHeight, 0)));
- return OTSMousePosition;
- }
- return new Point(0, 0);
- }
- public static int PixelConvertToMicrons(int Pixel, int widthDomain, int length)
- {
- return Convert.ToInt32((Pixel * ((double)widthDomain / length)));
- }
- public static float PixelConvertToMicron(int Pixel, int widthDomain, int length)
- {
- return (float)(Pixel * ((double)widthDomain / length));
- }
- public static Point GetGDIObjects(Point mousePoint, ARectangleGDIObject RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, int Width, int Height)
- {
- Point rectLocation = RectangleGDIObjects.Region.Location;
- //样品台尺寸
- Size rectSize = RectangleGDIObjects.Region.Size;
- //鼠标在工作区域中的位置
- string x = mousePoint.X.ToString();
- string Y = mousePoint.Y.ToString();
- //样品台起始位置
- string rectLocationX = rectLocation.X.ToString();
- string rectLocationY = rectLocation.Y.ToString();
- //OTS中心点
- string rectLocationCenterX = (rectLocation.X + rectSize.Width / 2).ToString();
- string rectLocationCenterY = (rectLocation.Y + rectSize.Height / 2).ToString();
- //OTS坐标中鼠标的位置
- int OTSX = -((rectLocation.X + rectSize.Width / 2) - mousePoint.X);
- int OTSY = -(mousePoint.Y - (rectLocation.Y + rectSize.Height / 2));
- //OTS坐标中鼠标的尺寸位置
- int OTSWidth = 0;
- int OTSHeight = 0;
- if (oTSSampleStageData != null)
- {
- //获取样品台两个坐标点
- ValueType XDomain = new Point(oTSSampleStageData.StageDomain.Left, oTSSampleStageData.StageDomain.Top);
- ValueType YDomain = new Point(oTSSampleStageData.StageDomain.Right, oTSSampleStageData.StageDomain.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坐标中的位置
- if (OTSX != 0)
- {
- OTSWidth = Convert.ToInt32((OTSX * ((double)widthDomain / (IsWidth == 0 ? (double)Width : (double)Height))));
- OTSHeight = Convert.ToInt32((OTSY * ((double)widthDomain / (IsWidth == 0 ? (double)Width : (double)Height))));
- }
- }
- Point OTSPosition = new Point(0, 0);
- //if (OTSWidth > 0 && OTSHeight > 0)
- //{
- OTSPosition = new Point(Convert.ToInt32(OTSWidth), Convert.ToInt32(OTSHeight));
- //}
- return OTSPosition;
- }
-
- #region 测量区域与样品中心相差的距离
- /// <summary>
- /// 测量区域与样品中心相差的距离
- /// </summary>
- /// <param name="MeasureRectangle"></param>
- /// <param name="SampleRectangle"></param>
- /// <returns></returns>
- public static Point GetSampleCenterDifferCenterPoint(Rectangle MeasureRectangle, Rectangle SampleRectangle)
- {
- Point DifferCenterPoint = new Point();
- //获取测量区域与样品相差中心点距离
- DifferCenterPoint.X = (MeasureRectangle.X + MeasureRectangle.Width / 2) - (SampleRectangle.X + SampleRectangle.Width / 2);
- DifferCenterPoint.Y = (MeasureRectangle.Y + MeasureRectangle.Height / 2) - (SampleRectangle.Y + SampleRectangle.Height / 2);
- return DifferCenterPoint;
- }
- #endregion
- #endregion
- #region 处理方法总汇
- #region 获取中心点
- public static Point GetCenterPoint(ARectangleGDIObject item)
- {
- //声明中心点变量
- Point pCenterPoint = new Point();
- //获取在工作窗口中X,Y位置
- pCenterPoint.X = (int)(item.Region.X + item.Region.Width / 2);
- pCenterPoint.Y = (int)(item.Region.Y + item.Region.Height / 2);
- return pCenterPoint;
- }
- public static Point GetCenterPoint(Rectangle item)
- {
- //声明中心点变量
- Point pCenterPoint = new Point();
- //获取在工作窗口中X,Y位置
- pCenterPoint.X = item.X + item.Width / 2;
- pCenterPoint.Y = item.Y + item.Height / 2;
- return pCenterPoint;
- }
- public static PointF GetCenterPointF(RectangleF item)
- {
- //声明中心点变量
- PointF pCenterPoint = new Point();
- //获取在工作窗口中X,Y位置
- pCenterPoint.X = item.X + item.Width / 2;
- pCenterPoint.Y = item.Y + item.Height / 2;
- return pCenterPoint;
- }
- #endregion
- #region 鼠标移动位置
- public static ARectangleGDIObject GetMouseMoveLocation(ARectangleGDIObject item, MouseEventArgs e)
- {
- item.Region = new Rectangle(
- item.Region.Left + e.X - item.DraggingPoint.X,
- item.Region.Top + e.Y - item.DraggingPoint.Y,
- item.Region.Width,
- item.Region.Height);
- item.DraggingPoint = e.Location;
- return item;
- }
- #endregion
- #region 绘制帧图方法
- public static void DrawSingleImage(List<ARectangleGDIObject> m_SingleGDIObjects)
- {
- foreach (var item in m_SingleGDIObjects)
- {
- m_SingleGDIObjects.Add(item);
- }
- }
- #endregion
- #region 获取工作区域中心点
- public static Point GetWorkAreaCenterPoint(Rectangle rect)
- {
- //声明
- Point centerPoint = new Point();
- //设置X,Y坐标
- centerPoint.X = rect.X + rect.Width / 2;
- centerPoint.Y = rect.Y + rect.Height / 2;
- return centerPoint;
- }
- #endregion
- #endregion
- #region 鼠标方法操作
- public static void MouseWheelFunction(List<ARectangleGDIObject> objList, ARectangleGDIObject m_RectangleGDIObjects, float globalZoomNum)
- {
- for (int i = 0; i < objList.Count; i++)
- {
- //多边形测量区域鼠标缩放
- if (objList[i].Shape == (int)CreateRectangleType.Polygon)
- {
- if (objList[i].DrawPolygonPointRegionF != null)
- {
- int polygonPointCount = objList[i].DrawPolygonPointRegionF.Count;
- if (polygonPointCount > 0)
- {
- for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
- {
- PointF wheelPoint = new PointF();
- wheelPoint = objList[i].DrawPolygonPointRegionF[pointIndex];
- float X = wheelPoint.X * globalZoomNum;
- float Y = wheelPoint.Y * globalZoomNum;
- objList[i].PolygonPointRegionF[pointIndex] = new PointF(wheelPoint.X * globalZoomNum, wheelPoint.Y * globalZoomNum);
- }
- }
- }
- }
- //else
- //{
- RectangleF rectF = new RectangleF();
- rectF = objList[i].RegionF;
- //根据样品孔中心点与样品台中心点的方向 设置宽度与高度\
- RectangleF returnRectF = OTSSamplespaceGraphicsPanelFun.MouseWheelFunctionF(m_RectangleGDIObjects, rectF, globalZoomNum);
- objList[i].Region = new Rectangle((int)returnRectF.X, (int)returnRectF.Y, (int)returnRectF.Width, (int)returnRectF.Height);
- objList[i].BSEImageWitdh = returnRectF.Width;
- objList[i].BSEImageHeight = returnRectF.Height;
- objList[i].BSEImageLocation = new PointF(returnRectF.X, returnRectF.Y);
- objList[i].SEMCenterPoint = returnRectF.Location;
- //重新绘制测量区域路径
- UpdateMeasureGraphicsPath(objList[i], objList[i].Region);
- //}
- }
- }
- public static RectangleF MouseWheelFunctionF(ARectangleGDIObject RectangleGDIObject, RectangleF itemRect, float globalZoomNum)
- {
- //缩放比例
- float X = itemRect.X * globalZoomNum;
- float Y = itemRect.Y * globalZoomNum;
- float Width = itemRect.Width * globalZoomNum;
- float Height = itemRect.Height * globalZoomNum;
- return new RectangleF(X, Y, Width, Height);
- }
- public enum EnumMousePointPosition
- {
- MouseSizeNone = 0, //'无
- MouseSizeRight = 1, //'拉伸右边框
- MouseSizeLeft = 2, //'拉伸左边框
- MouseSizeBottom = 3, //'拉伸下边框
- MouseSizeTop = 4, //'拉伸上边框
- MouseSizeTopLeft = 5, //'拉伸左上角
- MouseSizeTopRight = 6, //'拉伸右上角
- MouseSizeBottomLeft = 7, //'拉伸左下角
- MouseSizeBottomRight = 8, //'拉伸右下角
- MouseDrag = 9 // '鼠标拖动
- }
- const int Band = 5;
- public static EnumMousePointPosition MousePointPosition(Size size, Point e)
- {
- if ((e.X >= -1 * Band) | (e.X <= size.Width) | (e.Y >= -1 * Band) | (e.Y <= size.Height))
- {
- if (e.X < Band)
- {
- if (e.Y < Band) { return EnumMousePointPosition.MouseSizeTopLeft; }
- else
- {
- if (e.Y > -1 * Band + size.Height)
- { return EnumMousePointPosition.MouseSizeBottomLeft; }
- else
- { return EnumMousePointPosition.MouseSizeLeft; }
- }
- }
- else
- {
- if (e.X > -1 * Band + size.Width)
- {
- if (e.Y < Band)
- { return EnumMousePointPosition.MouseSizeTopRight; }
- else
- {
- if (e.Y > -1 * Band + size.Height)
- { return EnumMousePointPosition.MouseSizeBottomRight; }
- else
- { return EnumMousePointPosition.MouseSizeRight; }
- }
- }
- else
- {
- if (e.Y < Band)
- { return EnumMousePointPosition.MouseSizeTop; }
- else
- {
- if (e.Y > -1 * Band + size.Height)
- { return EnumMousePointPosition.MouseSizeBottom; }
- else
- { return EnumMousePointPosition.MouseDrag; }
- }
- }
- }
- }
- else
- { return EnumMousePointPosition.MouseSizeNone; }
- }
- public static EnumMousePointPosition MousePointPosition(Point point, Point e)
- {
- //MouseDrag 中心
- if ((e.X == point.X) && (e.Y == point.Y))
- {
- return EnumMousePointPosition.MouseDrag;
- }
- //MouseSizeTopLeft 上左
- if ((e.X < point.X) && (e.Y < point.Y))
- {
- return EnumMousePointPosition.MouseSizeTopLeft;
- }
- //MouseSizeTopRight 下右
- if ((e.X > point.X) && (e.Y < point.Y))
- {
- return EnumMousePointPosition.MouseSizeTopRight;
- }
- //MouseSizeLeft 左侧
- if ((e.X < point.X) && (e.Y == point.Y))
- {
- return EnumMousePointPosition.MouseSizeLeft;
- }
- //MouseSizeRight 右侧
- if ((e.X > point.X) && (e.Y == point.Y))
- {
- return EnumMousePointPosition.MouseSizeRight;
- }
- //MouseSizeTop 上侧
- if ((e.X == point.X) && (e.Y < point.Y))
- {
- return EnumMousePointPosition.MouseSizeTop;
- }
- //MouseSizeBottom 下侧
- if ((e.X == point.X) && (e.Y > point.Y))
- {
- return EnumMousePointPosition.MouseSizeBottom;
- }
- //MouseSizeBottomRight 下左
- if ((e.X < point.X) && (e.Y > point.Y))
- {
- return EnumMousePointPosition.MouseSizeBottomLeft;
- }
- //MouseSizeBottomRight 下右
- if ((e.X > point.X) && (e.Y > point.Y))
- {
- return EnumMousePointPosition.MouseSizeBottomRight;
- }
- return EnumMousePointPosition.MouseSizeNone;
- }
- #endregion
- #region 切换样品
- /// <summary>
- /// 切换样品
- /// </summary>
- /// <param name="objList">样品信息列表</param>
- /// <param name="stageName">样品台名称</param>
- public static List<ARectangleGDIObject> SelectSampleIndex(List<ARectangleGDIObject> objList, string sampleName)
- {
- ArrayList listIndex = new ArrayList();
- ARectangleGDIObject objItemTemp = null;
- objItemTemp = objList[0];
- for (int i = 0; i < objList.Count; i++)
- {
- if (objList[0].Name == sampleName)
- {
- listIndex.Add(i);
- }
- }
- for (int x = 0; x < listIndex.Count; x++)
- {
- for (int y = 0; y < objList.Count; y++)
- {
- //将第一个元素放入临时项中
- if (y == Convert.ToInt32(listIndex[0]))
- {
- objItemTemp = objList[0];
- }
- //如果循环至最后一个位置,则将第一个元素复制到最后一个元素位置中
- else if ((y) == Convert.ToInt32(listIndex[listIndex.Count - 1]))
- {
- objList[Convert.ToInt32(listIndex[0])] = objList[y];
- objList[y] = objItemTemp;
- objList[y].IsWorkSample = true;
- }
- }
- }
- return objList;
- }
- #endregion
- #region 根据选择的测量区域 切换至最上层
- public static List<ARectangleGDIObject> SelectMeasureIndexIsTop(List<ARectangleGDIObject> objList, string SampleName)
- {
- List<ARectangleGDIObject> objListTemp = objList;
- ARectangleGDIObject itemTemp = null;
- foreach (ARectangleGDIObject item in objList)
- {
- if (item.SampleName == SampleName)
- {
- //临时记录所选测量区域
- itemTemp = item;
- //删除原信息
- objListTemp.Remove(item);
- //添加新信息
- objListTemp.Insert(objListTemp.Count, itemTemp);
- break;
- }
- }
- return objListTemp;
- }
- #endregion
- #region 根据选择的样品 切换至最上层
- public static List<ARectangleGDIObject> SelectSampleIndexIsTop(List<ARectangleGDIObject> objList, string SampleName)
- {
- List<ARectangleGDIObject> objListTemp = objList;
- ARectangleGDIObject itemTemp = null;
- foreach (ARectangleGDIObject item in objList)
- {
- if (item.SampleName == SampleName)
- {
- //临时记录所选样品
- itemTemp = item;
- //删除原信息
- objListTemp.Remove(item);
- //添加新信息
- objListTemp.Insert(objListTemp.Count, itemTemp);
- break;
- }
- }
- return objListTemp;
- }
- #endregion
- #region 获取拍摄BSE图 将byte数组转换为图片
- public static Image GetBSEImage(byte[] ImageByte, int width, int height)
- {
- //图片
- Bitmap bitmap = null;
- //将byte数据转换为图片
- bitmap = CImageHandler.ToGrayBitmap(ImageByte, width, height);
- return bitmap;
- }
- #endregion
- #region 根据对象点 与 相距的宽度 生成一个矩形
- /// <summary>
- /// 根据对象点 与 相距的宽度 生成一个矩形
- /// </summary>
- /// <param name="width"></param>
- /// <param name="xPoint"></param>
- /// <param name="yPoint"></param>
- /// <param name="type">0:圆角矩形 1:圆形 2:文字 3:矩形</param>
- /// <returns></returns>
- public static CreateRectangle GetPixRect(int width, Point xPoint, Point yPoint, int type, string str, string Name, int IsWidth, int Width, int Height)
- {
- try
- {
- //将微米信息 转换为 像素
- Point xPoints = new Point();
- Point yPoints = new Point();
- xPoints.X = (int)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
- xPoints.Y = (int)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
- yPoints.X = (int)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
- yPoints.Y = (int)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
- //计算位置
- xPoints = CalculateLocation(xPoints, Width, Height);
- yPoints = CalculateLocation(yPoints, Width, Height);
- //获取图形四个点
- int realStartX = Math.Min(xPoints.X, yPoints.X);
- int realStartY = Math.Min(xPoints.Y, yPoints.Y);
- int realEndX = Math.Max(xPoints.X, yPoints.X);
- int realEndY = Math.Max(xPoints.Y, yPoints.Y);
- //创建矩形 并返回类型对象
- return new CreateRectangle(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, str, Name);
- }
- catch (Exception)
- {
- return new CreateRectangle(new Rectangle(), 0, "");
- }
- }
- public static Rectangle GetPixRects(int width, Point xPoint, Point yPoint, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
- {
- try
- {
- //将微米信息 转换为 像素
- Point xPoints = new Point();
- Point yPoints = new Point();
- xPoints.X = (int)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
- xPoints.Y = (int)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
- yPoints.X = (int)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
- yPoints.Y = (int)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
- //计算位置
- xPoints = CalculateLocation(xPoints, Width, Height);
- //yPoints = CalculateLocation(yPoints, Width, Height);
- //获取图形四个点
- int realStartX = Math.Min(xPoints.X, yPoints.X);
- int realStartY = Math.Min(xPoints.Y, yPoints.Y);
- int realEndX = Math.Max(xPoints.X, yPoints.X);
- int realEndY = Math.Max(xPoints.Y, yPoints.Y);
- //float startX = realStartX < 0 ? 0 : realStartX;
- //float startY = realStartY < 0 ? 0 : realStartY;
- //float endX = realEndX - Math.Abs(realStartX);
- //float endY = endX / 4*3;
- //xPoint.X = startX;
- //xPoint.Y = startY;
- //yPoint.X = endX;
- //yPoint.Y = endY;
- //创建矩形 并返回类型对象
- return new Rectangle(xPoints.X, xPoints.Y, yPoints.X, yPoints.Y);
- //return new RectangleF(realStartX < 0 ? 0 : realStartX, realStartY < 0 ? 0 : realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY));
- }
- catch (Exception)
- {
- return new Rectangle();
- }
- }
- public static RectangleF GetPixRectF(int width, Point xPoint, Point yPoint, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
- {
- try
- {
- //将微米信息 转换为 像素
- PointF xPoints = new PointF();
- PointF yPoints = new PointF();
- xPoints.X = (float)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
- xPoints.Y = (float)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
- yPoints.X = (float)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
- yPoints.Y = (float)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
- //计算位置
- xPoints = CalculateLocationF(xPoints, Width, Height);
- yPoints = CalculateLocationF(yPoints, Width, Height);
- //创建矩形 并返回类型对象
- return new RectangleF(xPoints.X, xPoints.Y, Math.Abs(yPoints.X - xPoints.X), Math.Abs(yPoints.Y - xPoints.Y));
- }
- catch (Exception)
- {
- return new RectangleF();
- }
- }
- public static CreateRectangle GetChangeSizePixRects(int width, Point xPoint, Point yPoint, int type, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
- {
- try
- {
- //将微米信息 转换为 像素
- Point xPoints = new Point();
- Point yPoints = new Point();
- xPoints.X = (int)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
- xPoints.Y = (int)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
- yPoints.X = (int)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
- yPoints.Y = (int)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
- //计算位置
- //xPoints = CalculateLocation(xPoints, Width, Height);
- //yPoints = CalculateLocation(yPoints, Width, Height);
- //获取图形四个点
- int realStartX = Math.Min(xPoints.X, yPoints.X);
- int realStartY = Math.Min(xPoints.Y, yPoints.Y);
- int realEndX = Math.Max(xPoints.X, yPoints.X);
- int realEndY = Math.Max(xPoints.Y, yPoints.Y);
- //创建矩形 并返回类型对象
- return new CreateRectangle(realStartX < 0 ? 0 : realStartX, realStartY < 0 ? 0 : realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, "", "");
- }
- catch (Exception)
- {
- return new CreateRectangle(new Rectangle(), 0, "");
- }
- }
- public static double MillimetersToPixelsWidth(int width, double PointVal, int IsWidth, int Width, int Height)
- {
- return PointVal / ((double)width / (IsWidth == 0 ? (double)Width : (double)Height));
- }
- public static Point CalculateLocation(Point point, int Width, int Height)
- {
- //获取窗体的高度与宽度
- int screenWidth = Width;
- int screenHeight = Height;
- //获取屏幕中心点
- Point pointXY = new Point();
- Point screenPoint = new Point(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 static PointF CalculateLocationF(PointF point, int Width, int Height)
- {
- //获取窗体的高度与宽度
- int screenWidth = Width;
- int screenHeight = Height;
- //获取屏幕中心点
- 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;
- }
- #endregion
- #region 通过OTS坐标 获取工作区域图形尺寸
- public static void GetWorkSpaceSize(Point pStartPoint, Point pEndPoint)
- {
- int widthDomain = 0;
- int heightDomain = 0;
- //宽度
- widthDomain = Math.Abs(((Point)pStartPoint).X - ((Point)pEndPoint).X);
- heightDomain = Math.Abs(((Point)pStartPoint).Y - ((Point)pEndPoint).Y);
- }
- #endregion
- #region 判断是否相同
- /// <summary>
- /// 判断是否相同
- /// </summary>
- /// <param name="sampleMeasurePara"></param>
- /// <param name="SampleMeasureParaResult"></param>
- /// <returns></returns>
- public static bool IsValidate(OTSIncAMeasureAppForm m_MeasureAppForm, SampleMeasurePara sampleMeasurePara, SampleMeasurePara SampleMeasureParaResult)
- {
- try
- {
- if (sampleMeasurePara.sSampleName != SampleMeasureParaResult.sSampleName)
- {
- return false;
- }
- if (sampleMeasurePara.MeasureRect != SampleMeasureParaResult.MeasureRect)
- {
- return false;
- }
- if (sampleMeasurePara.sHoleName != SampleMeasureParaResult.sHoleName)
- {
- return false;
- }
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
- #endregion
- #region 获取工作样品信息
- /// <summary>
- /// 获取工作样品信息
- /// </summary>
- /// <param name="sampleName"></param>
- /// <returns></returns>
- public static ARectangleGDIObject GetWorkSample(string sampleName)
- {
- foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
- {
- if (itemSample.SampleName == sampleName)
- {
- return itemSample;
- }
- }
- return null;
- }
- #endregion
- #region 获取测量区域
- /// <summary>
- /// 获取测量区域
- /// </summary>
- /// <param name="m_MeasureAppForm"></param>
- /// <param name="sampleName"></param>
- /// <returns></returns>
- public static SampleMeasurePara GetMeasureInfo(OTSIncAMeasureAppForm m_MeasureAppForm, string sampleName, ARectangleGDIObject item, ARectangleGDIObject m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int wDomain, int w)
- {
- SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
- foreach (ARectangleGDIObject measureItem in OTSSamplespaceWindow.m_MeasureGDIObjects)
- {
- if (sampleName == measureItem.SampleName)
- {
- //设置测量区域位置与尺寸
- float left = 0;
- float Top = 0;
- float Right = 0;
- float Bottom = 0;
- float Widths = 0;
- float Height = 0;
- //设置测量区域位置与尺寸
- left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.X, wDomain, w);
- Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Y, wDomain, w);
- Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Right, wDomain, w);
- Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Bottom, wDomain, w);
- Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Width, wDomain, w);
- Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Height, wDomain, w);
- //保存原位置
- RectangleF polygonRectPara = measureItem.DrawRegionF;
- if (measureItem.CreateType == (int)CreateRectangleType.Polygon)
- {
- polygonRectPara = GetPolygonToMinRectangle(measureItem.DrawPolygonPointRegionF);
- //设置测量区域位置与尺寸
- left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.X, wDomain, w);
- Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Y, wDomain, w);
- Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Right, wDomain, w);
- Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Bottom, wDomain, w);
- Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Width, wDomain, w);
- Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Height, wDomain, w);
- }
- //设置测量区域
- 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.sHoleName = item.Name;
- //设置样品名称
- sampleMeasurePara.sSampleName = item.SampleName;
- //设置测量区域形状
- sampleMeasurePara.iShape = item.Shape;
- //设置多边形点集合
- sampleMeasurePara.PolygonPointRegion = PointFConvertPoint(GetPolygonPointToOTSPoint(item.PolygonPointRegionF, wDomain, w));
- sampleMeasurePara.PolygonPointRegionF = GetPolygonPointToOTSPoint(item.PolygonPointRegionF, wDomain, w);
- sampleMeasurePara.DrawPolygonPointRegionF = GetPolygonPointToOTSPoint(item.DrawPolygonPointRegionF, wDomain, w);
- break;
- }
- }
- return sampleMeasurePara;
- }
- public static SampleHolePara GetSampleHoleInfo(OTSIncAMeasureAppForm m_MeasureAppForm, string sampleHoleName, ARectangleGDIObject item, ARectangleGDIObject m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int wDomain, int w)
- {
- SampleHolePara sampleHolePara = new SampleHolePara();
- foreach (ARectangleGDIObject sampleHoleItem in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
- {
- if (sampleHoleName == sampleHoleItem.Name)
- {
- //保存原位置
- Rectangle rectPara = sampleHoleItem.Region;
- //设置测量区域
- sampleHolePara.SampleHoleRect = sampleHoleItem.Region;
- //设置测量区域位置与尺寸
- float left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.X, wDomain, w);
- float Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Y, wDomain, w);
- float Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Right, wDomain, w);
- float Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Bottom, wDomain, w);
- float Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Width, wDomain, w);
- float Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Height, wDomain, w);
- //Size sizeRegion = new Size(PointRB);
- 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;
- break;
- }
- }
- return sampleHolePara;
- }
- #endregion
- #region 获取工作样品的测量区域信息
- /// <summary>
- /// 获取工作样品的测量区域信息
- /// </summary>
- /// <returns></returns>
- public static Rectangle GetWorkMeasure(OTSIncAMeasureAppForm m_MeasureAppForm, ARectangleGDIObject m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int wDomain, int w)
- {
- foreach (ARectangleGDIObject itemMeasure in OTSSamplespaceWindow.m_MeasureGDIObjects)
- {
- if (itemMeasure.IsWorkSample)
- {
- Point startPoint = new Point(itemMeasure.Region.Left, itemMeasure.Region.Top);
- Point endPoint = new Point(itemMeasure.Region.Right, itemMeasure.Region.Bottom);
- SampleMeasurePara rectMaesure = GetMeasureInfo(m_MeasureAppForm, itemMeasure.SampleName, itemMeasure, m_RectangleGDIObjects, oTSSampleStageData, wDomain, w);
- return rectMaesure.MeasureRect;
- }
- }
- return new Rectangle();
- }
- #endregion
- #region 删除样品弹出提示
- public static bool ShowDeleteDialog(string sampleName)
- {
- //国际化
- OTSCommon.Language lan = new OTSCommon.Language();
- Hashtable table = lan.GetNameTable("OTSIncAMeasureAppForm");
- string str1 = table["message5"].ToString();
- string str2 = table["message6"].ToString();
- string sDeleteSampleName = str1;
- sDeleteSampleName += sampleName;
- sDeleteSampleName += " 信息 ?";
- if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Delete sample information prompt", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- #endregion
- #region 将点转换至工作区域
- public void PointToClient(Point rect)
- {
- this.PointToClient(rect);
- }
- #endregion
- #region 删除样品 同时删除帧图
- public static bool DeleteSampleInfo(OTSIncAMeasureAppForm m_MeasureAppForm, string sampleSelectName)
- {
- try
- {
- //提交主窗体响应
- bool deleteResult = false;
- if (OTSSamplespaceGraphicsPanelFun.ShowDeleteDialog(sampleSelectName))
- {
- //设置当前状态
- m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
- deleteResult = m_MeasureAppForm.DeleteSample(sampleSelectName);
- if (deleteResult)
- {
- //样品对象列表中无样品信息 则清除帧图对象列表信息
- bool result = m_MeasureAppForm.m_SamplepaceWindow.SampleIsEmptyClearSingleInfo();
- if(result)
- {
- m_MeasureAppForm.m_MeasureRetWindow.SetInit();
- }
- }
- }
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
- #endregion
- #region 计算两个点之间的距离 (图形与鼠标点击获取的点)
- public static Point StartToEndPointDist(ARectangleGDIObject m_RectangleGDIObjects, Point regionStartPoint)
- {
- Point differentPoint = new Point();
- //获取点击后的样品台位置
- Point m_Region = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects.Region);
- //获取鼠标按下的位置
- Point regionEndPoint = m_Region;
- //获取鼠标按下与抬起 位置差值
- differentPoint.X = regionEndPoint.X - regionStartPoint.X;
- differentPoint.Y = regionEndPoint.Y - regionStartPoint.Y;
- return differentPoint;
- }
- #endregion
- #region 计算两个点之间的距离 (图形中心与屏幕中心相差的距离)
- public static Point RegionCenterToScreenCenterDist(ARectangleGDIObject regionCneter, Point screenCneter)
- {
- Point differentPoint = new Point();
- //获取图形中心位置
- Rectangle rectangle = new Rectangle();
- rectangle.X = (int)regionCneter.RegionF.X;
- rectangle.Y = (int)regionCneter.RegionF.Y;
- rectangle.Width = (int)regionCneter.RegionF.Width;
- rectangle.Height = (int)regionCneter.RegionF.Height;
- Point m_RegionCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(rectangle);
- //获取图形中心与屏幕中心相差的距离
- differentPoint.X = m_RegionCenter.X - screenCneter.X;
- differentPoint.Y = m_RegionCenter.Y - screenCneter.Y;
- return differentPoint;
- }
- #endregion
-
- #region 清除List中所有信息
- public static List<ARectangleGDIObject> ListClear(List<ARectangleGDIObject> ListObject)
- {
- if (ListObject != null)
- {
- if (ListObject.Count > 0)
- {
- ListObject.Clear();
- }
- }
- return ListObject;
- }
- #endregion
- #region 根据颜色枚举 获取颜色值
- public static string GetColorValue(ColorType ColorEnum)
- {
- string ColorStr = string.Empty;
- switch (ColorEnum)
- {
- case ColorType.SingleColor:
- ColorStr = "#fd8f8f";//帧图fd8f8f
- break;
- case ColorType.RoundRectangleColor:
- ColorStr = "#c8c8c8";//c8c8c8圆角矩形
- break;
- case ColorType.FontColor:
- ColorStr = "#90ee90";//90ee90文字颜色
- break;
- case ColorType.SampleColor:
- ColorStr = "#f4f4f4";//f4f4f4 样品未选择
- break;
- case ColorType.SampleSelColor:
- ColorStr = "#505050";//505050 样品选择后
- break;
- }
- return ColorStr;
- }
- #endregion
- #region 获取测量区域的位置
- public static SampleMeasurePara GetSampleMeasureRect(ARectangleGDIObject MeasureItem, OTSIncAMeasureAppForm m_MeasureAppForm, StageDrawingData oTSSampleStageData, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
- {
- int w = (IsWidth == 0 ? Width : Height);
- int iShape = 0;
- Rectangle Srect = new Rectangle();
- SampleMeasurePara sampleMeasureParas = new SampleMeasurePara();
- //获取当前工作的测量区域信息
- bool returnResult = m_MeasureAppForm.m_ProjParam.GetWSampleMrsArea(ref iShape, ref Srect);
- if (returnResult)
- {
- //获取测量区域的OTS位置与尺寸
- sampleMeasureParas = OTSSamplespaceGraphicsPanelFun.GetMeasureInfo(m_MeasureAppForm, MeasureItem.SampleName, MeasureItem, m_RectangleGDIObjects, oTSSampleStageData, wDomain, w);
- //获取工作区域位置与尺寸
- Rectangle WorkAreaRect = new Rectangle(0, 0, Width, Height);
- //获取工作区域 中心点
- Point ScreenPointCenter = OTSSamplespaceGraphicsPanelFun.GetWorkAreaCenterPoint(WorkAreaRect);
- //获取样品台 中心点
- PointF RectanglePointCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPointF(m_RectangleGDIObjects.RegionF);
- //获取屏幕中心点
- float WorkAreaCenterPointX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.X, wDomain, w);
- float WorkAreaCenterPointY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.Y, wDomain, w);
- //获取样品台中心点
- float CenterX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.X, wDomain, w);
- float CenterY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.Y, wDomain, w);
- Rectangle sampleMeasureRect = new Rectangle();
- //根据屏幕中心点获取移动后样品台中心点的偏移位置
- //sampleMeasureRect.X = -(WorkAreaCenterPointX - sampleMeasureParas.MeasureRect.X);
- //sampleMeasureRect.Y = WorkAreaCenterPointY - sampleMeasureParas.MeasureRect.Bottom;
- //根据样品台中心点获取开始点位置
- sampleMeasureRect.X = -((int)CenterX - sampleMeasureParas.MeasureRect.X);
- sampleMeasureRect.Y = (int)CenterY - sampleMeasureParas.MeasureRect.Bottom;
- sampleMeasureParas.MeasureRect.X = sampleMeasureRect.X;
- sampleMeasureParas.MeasureRect.Y = sampleMeasureRect.Y;
- for (int i = 0; i < sampleMeasureParas.DrawPolygonPointRegionF.Count; i++)
- {
- int X = -((int)CenterX - (int)sampleMeasureParas.DrawPolygonPointRegionF[i].X);
- int Y = (int)CenterY - (int)sampleMeasureParas.DrawPolygonPointRegionF[i].Y;
- //sampleMeasureParas.PolygonPointRegion[i] = new Point(X, Y);
- sampleMeasureParas.DrawPolygonPointRegionF[i] = new Point(X, Y);
- }
- }
- return sampleMeasureParas;
- }
- public static SampleHolePara GetSampleHoleRect(ARectangleGDIObject sampleHoleItem, OTSIncAMeasureAppForm m_MeasureAppForm, StageDrawingData oTSSampleStageData, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
- {
- int w = (IsWidth == 0 ? Width : Height);
- SampleHolePara sampleHoleParas = new SampleHolePara();
- //获取样品孔的OTS位置与尺寸
- sampleHoleParas = OTSSamplespaceGraphicsPanelFun.GetSampleHoleInfo(m_MeasureAppForm, sampleHoleItem.Name, sampleHoleItem, m_RectangleGDIObjects, oTSSampleStageData, wDomain, w);
- //获取工作区域位置与尺寸
- Rectangle WorkAreaRect = new Rectangle(0, 0, Width, Height);
- //获取工作区域 中心点
- Point ScreenPointCenter = OTSSamplespaceGraphicsPanelFun.GetWorkAreaCenterPoint(WorkAreaRect);
- //获取样品台 中心点
- PointF RectanglePointCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPointF(m_RectangleGDIObjects.RegionF);
- //获取屏幕中心点
- float WorkAreaCenterPointX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.X, wDomain, w);
- float WorkAreaCenterPointY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.Y, wDomain, w);
- //获取样品台中心点
- float CenterX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.X, wDomain, w);
- float CenterY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.Y, wDomain, w);
- 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;
- }
- #endregion
- #region //设置测量区域信息(位置与大小)
- public static bool SetWorkSamplHoleAndMeasureArea(ARectangleGDIObject MeasureItem, OTSIncAMeasureAppForm m_MeasureAppForm, StageDrawingData oTSSampleStageData, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
- {
- //获取工作样品中的测量区域
- SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
- //设置测量区域位置
- //获取修改后的测量区域的位置与尺寸
- sampleMeasurePara = GetSampleMeasureRect(MeasureItem, m_MeasureAppForm, oTSSampleStageData, m_RectangleGDIObjects, IsWidth, Width, Height, wDomain);
- sampleMeasurePara.sHoleName = MeasureItem.Name;
- sampleMeasurePara.sSampleName = MeasureItem.SampleName;
- //设置测量区域信息(位置与大小)
- SampleMeasurePara SampleMeasureParaResult = m_MeasureAppForm.SetWorkSamplHoleAndMeasureArea(sampleMeasurePara);
- if (OTSSamplespaceGraphicsPanelFun.IsValidate(m_MeasureAppForm, sampleMeasurePara, SampleMeasureParaResult))
- {
- return true;
- }
- return false;
- }
- #endregion
- #region 根据list中的帧图信息 获取中心位置
- public static PointF GetSingleCenterLocation(List<ARectangleGDIObject> m_SingleGDIObjects)
- {
- float MinX = 0f;
- float MinY = 0f;
- float MaxX = 0f;
- float MaxY = 0f;
- float width = 0f;
- float height = 0f;
- //获取最小XY 与最大XY
- MinX = m_SingleGDIObjects[0].RegionF.X;
- MinY = m_SingleGDIObjects[0].RegionF.Y;
- MaxX = m_SingleGDIObjects[0].RegionF.X;
- MaxY = m_SingleGDIObjects[0].RegionF.Y;
- width = m_SingleGDIObjects[0].RegionF.Width;
- height = m_SingleGDIObjects[0].RegionF.Height;
- for (int i = 0; i < m_SingleGDIObjects.Count; i++)
- {
- MinX = Math.Min(m_SingleGDIObjects[i].RegionF.X, MinX);
- MinY = Math.Min(m_SingleGDIObjects[i].RegionF.Y, MinY);
- MaxX = Math.Max(m_SingleGDIObjects[i].RegionF.X, MaxX);
- MaxY = Math.Max(m_SingleGDIObjects[i].RegionF.Y, MaxY);
- }
- //获取帧图的外框矩形
- RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX- MinX+ width, MaxY- MinY+ height);
- //计算外框矩形的中心点
- float PointFX = SingleRect.X + SingleRect.Width / 2;
- float PointFY = SingleRect.Y + SingleRect.Height / 2;
- PointF SingleCenterPoint = new PointF(PointFX, PointFY);
- return SingleCenterPoint;
- }
- public static PointF GetSingleDrawCenterLocation(List<ARectangleGDIObject> m_SingleGDIObjects)
- {
- float MinX = 0f;
- float MinY = 0f;
- float MaxX = 0f;
- float MaxY = 0f;
- float width = 0f;
- float height = 0f;
- //获取最小XY 与最大XY
- MinX = m_SingleGDIObjects[0].DrawRegionF.X;
- MinY = m_SingleGDIObjects[0].DrawRegionF.Y;
- MaxX = m_SingleGDIObjects[0].DrawRegionF.X;
- MaxY = m_SingleGDIObjects[0].DrawRegionF.Y;
- width = m_SingleGDIObjects[0].DrawRegionF.Width;
- height = m_SingleGDIObjects[0].DrawRegionF.Height;
- for (int i = 0; i < m_SingleGDIObjects.Count; i++)
- {
- MinX = Math.Min(m_SingleGDIObjects[i].DrawRegionF.X, MinX);
- MinY = Math.Min(m_SingleGDIObjects[i].DrawRegionF.Y, MinY);
- MaxX = Math.Max(m_SingleGDIObjects[i].DrawRegionF.X, MaxX);
- MaxY = Math.Max(m_SingleGDIObjects[i].DrawRegionF.Y, MaxY);
- }
- //获取帧图的外框矩形
- RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX - MinX + width, MaxY - MinY + height);
- //计算外框矩形的中心点
- float PointFX = SingleRect.X + SingleRect.Width / 2;
- float PointFY = SingleRect.Y + SingleRect.Height / 2;
- PointF SingleCenterPoint = new PointF(PointFX, PointFY);
- return SingleCenterPoint;
- }
- #endregion
- #region 将所有帧图移植测量区域位置
- public static void SetSingleLocationToMeasureLocation(List<ARectangleGDIObject> m_ObjectListGDIObjects, ARectangleGDIObject m_ObjectGDIObjects)
- {
- //获取帧图中心与测量区域中心
- PointF singleCenterPoinF= GetSingleCenterLocation(m_ObjectListGDIObjects);
- PointF singleDrawCenterPoinF = GetSingleDrawCenterLocation(m_ObjectListGDIObjects);
- //测量区域 已改变为倍数的尺寸 中心点
- PointF measureCenterPoin = GetCenterPointF(m_ObjectGDIObjects.Region);
- //测量区域 正常尺寸 中心点
- PointF measureCenterPoinF = GetCenterPointF(m_ObjectGDIObjects.RegionF);
- //计算相差的XY距离
- float moveX = measureCenterPoin.X - singleCenterPoinF.X;
- float moveY = measureCenterPoin.Y - singleCenterPoinF.Y;
- float moveFX = measureCenterPoinF.X - singleDrawCenterPoinF.X;
- float moveFY = measureCenterPoinF.Y - singleDrawCenterPoinF.Y;
- //需要移动的位置
- PointF movePoint = new PointF(moveX, moveY);
- PointF movePointF = new PointF(moveFX, moveFY);
- foreach (var ObjectItem in m_ObjectListGDIObjects)
- {
- //计算移动后的位置
- float X = ObjectItem.RegionF.X + movePoint.X;
- float Y = ObjectItem.RegionF.Y + movePoint.Y;
- float Width = ObjectItem.RegionF.Width;
- float Height = ObjectItem.RegionF.Height;
- ObjectItem.Region = new Rectangle((int)X, (int)Y, (int)Width, (int)Height);
- ObjectItem.RegionF = new RectangleF(X, Y, Width, Height);
- ObjectItem.DrawRegionF = new RectangleF(ObjectItem.DrawRegionF.X + movePointF.X, ObjectItem.DrawRegionF.Y + movePointF.Y, ObjectItem.DrawRegionF.Width, ObjectItem.DrawRegionF.Height);
- }
- }
- #endregion
- /// <summary>
- /// 获取XML中电镜的选项
- /// </summary>
-
- #region 测量区域中心移动至SEM当前位置
- /// <summary>
- /// 测量区域中心移动至SEM当前位置
- /// </summary>
- /// <param name="m_SamplespaceWindow">样品台窗体对象</param>
- /// <param name="mouseLocation">当前鼠标的位置</param>
- public static void NewLocationDrawMeasureInfo(OTSSamplespaceWindow m_SamplespaceWindow, List<ARectangleGDIObject> m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, Point moveToSEMLocation, List<ARectangleGDIObject> UpdateLocationGDIObject,float m_GlobalZoomNum)
- {
- //样品台中心点位置
- Point m_StageCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0]);
- //当前与中心点相差距离
- 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 = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(item);
- 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 == (int)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 static bool NewLocationDrawSingleInfo(OTSIncAMeasureAppForm m_MeasureAppForm, OTSSamplespaceWindow m_SamplespaceWindow, List<ARectangleGDIObject> m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, Point moveToSEMLocation, List<ARectangleGDIObject> UpdateLocationGDIObject, ARectangleGDIObject WorkMeasure, float m_GlobalZoomNum)
- {
- //样品台中心点位置
- Point m_StageCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0]);
- //当前与中心点相差距离
- 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 = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(WorkMeasure);
- 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;
- }
- #endregion
- #region 通过样品孔名称 获取在列表中的索引
- /// <summary>
- /// 通过样品孔名称 获取在列表中的索引
- /// </summary>
- /// <param name="oTSSampleStageData">样品台文件</param>
- /// <param name="sampleHoleName">样品孔名称</param>
- /// <returns></returns>
- public static int GetSampleHoleIndex(StageDrawingData oTSSampleStageData,string sampleHoleName, ref OTSSampleHoleInfo sampleHoleInfo)
- {
- try
- {
- int sampleHoleIndex = -1;
- if (oTSSampleStageData.sSHoleInfoList.Count > 0)
- {
- for (int i = 0; i < oTSSampleStageData.sSHoleInfoList.Count; i++)
- {
- if (oTSSampleStageData.sSHoleInfoList[i].sSHoleName == sampleHoleName)
- {
- sampleHoleInfo = oTSSampleStageData.sSHoleInfoList[i];
- sampleHoleIndex = i;
- break;
- }
- }
- }
- return sampleHoleIndex;
- }
- catch (Exception)
- {
- return -1;
- }
- }
- #endregion
-
- #region 添加帧图信息
- /// <summary>
- /// 添加帧图信息
- /// </summary>
- /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
- /// <param name="m_SingleGDIObjects">帧图对象列表</param>
- /// <param name="sampleName">样品名称</param>
- /// <returns></returns>
- public static bool AddALLSingleInfo(List<ARectangleGDIObject> m_ALLSingleGDIObjects, List<ARectangleGDIObject> m_SingleGDIObjects, string sampleName)
- {
- bool result = false;
- //判断ALLSingle对象列表中是否为空
- if (m_ALLSingleGDIObjects != null)
- {
- bool IsExist = true;
- if (m_ALLSingleGDIObjects.Count > 0)
- {
-
- //判断是否包含样品名称
- foreach (var item in m_ALLSingleGDIObjects)
- {
- if (item.SampleName.Equals(sampleName))
- {
- IsExist = false;
- break;
- }
- }
- }
- if (IsExist)
- {
- result = true;
- foreach (var item in m_SingleGDIObjects)
- {
- m_ALLSingleGDIObjects.Add(item);
- }
- }
- return result;
- }
- return result;
- }
- #endregion
- #region 删除帧图信息
- /// <summary>
- /// 删除帧图信息
- /// </summary>
- /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
- /// <param name="sampleName">样品名称</param>
- /// <returns></returns>
- public static bool DeleteALLSingleInfo(List<ARectangleGDIObject> m_ALLSingleGDIObjects, string sampleName)
- {
- bool result = false;
- int resultCount = 0;
- //判断ALLSingle对象列表中是否为空
- if (m_ALLSingleGDIObjects != null)
- {
- if (m_ALLSingleGDIObjects.Count > 0)
- {
- for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_ALLSingleGDIObjects[i].SampleName.Equals(sampleName))
- {
- m_ALLSingleGDIObjects.RemoveAt(i);
- resultCount++;
- }
- }
- }
- else
- {
- result = true;
- }
- if (resultCount > 0)
- {
- result = true;
- }
- }
- return result;
- }
- #endregion
- #region 切换样品 填充帧图信息
- public static void ChangeSampleFillSingleInfo(List<ARectangleGDIObject> m_ALLSingleGDIObjects, List<ARectangleGDIObject> m_SingleGDIObjects, string sampleName)
- {
- //判断帧图对象中是否存在当前工作样品帧图信息
- bool IsExist = true;
- //判断ALLSingle对象列表中是否为空
- if (m_ALLSingleGDIObjects != null)
- {
- if (m_ALLSingleGDIObjects.Count > 0)
- {
- foreach (var item in m_SingleGDIObjects)
- {
- if (item.SampleName.Equals(sampleName))
- {
- IsExist = false;
- }
- }
- if (IsExist)
- {
- //判断是否包含样品名称
- foreach (var item in m_ALLSingleGDIObjects)
- {
- if (item.SampleName.Equals(sampleName))
- {
- m_SingleGDIObjects.Add(item);
- }
- }
- }
- }
- }
- }
- #endregion
- #region 修改已存在的帧图中样品名称
- public static void EditWorkSampleName(List<ARectangleGDIObject> m_ALLSingleGDIObjects, string oldSampleName, string newSampleName)
- {
- int resultCount = 0;
- //判断ALLSingle对象列表中是否为空
- if (m_ALLSingleGDIObjects != null)
- {
- if (m_ALLSingleGDIObjects.Count > 0)
- {
- for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
- {
- if (m_ALLSingleGDIObjects[i].SampleName.Equals(oldSampleName))
- {
- m_ALLSingleGDIObjects[i].SampleName = newSampleName;
- resultCount++;
- }
- }
- }
- }
- }
- #endregion
- #region 修改测量区域中GraphicsPath属性
- public static void UpdateMeasureGraphicsPath(ARectangleGDIObject measureItem, Rectangle rectPara)
- {
- //重新绘制测量区域路径
- GraphicsPath GPath = new GraphicsPath();
- if (measureItem.CreateType == (int)CreateRectangleType.Polygon)
- {
- GraphicsPath PolygonMeasurePath = new GraphicsPath();
- PolygonMeasurePath.AddPolygon(measureItem.PolygonPointRegionF.ToArray());
- GPath = PolygonMeasurePath;
- }
- else if(measureItem.CreateType == (int)CreateRectangleType.CircleByThreePoints)
- {
- GPath.AddEllipse(rectPara);
- }
- else
- {
- if (measureItem.Shape == (int)CreateRectangleType.Circle)
- {
- GPath.AddEllipse(rectPara);
- }
- else
- {
- GPath.AddRectangle(rectPara);
- }
- }
- measureItem.GPath = GPath;
- }
- #endregion
- #region OnMouseWheel
- public static void RecoverInitialPosition(List<ARectangleGDIObject> l_GDIObjects,float m_GlobalZoomNum)
- {
- for (int i = 0; i < l_GDIObjects.Count; i++)
- {
- RectangleF rectF = new RectangleF();
- rectF = l_GDIObjects[i].DrawRegionF;
- //根据样品孔中心点与样品台中心点的方向 设置宽度与高度\
- l_GDIObjects[i].Region = new Rectangle((int)(rectF.X * m_GlobalZoomNum), (int)(rectF.Y * m_GlobalZoomNum), (int)(rectF.Width * m_GlobalZoomNum), (int)(rectF.Height * m_GlobalZoomNum));
- PointF pointF = new PointF(rectF.X * m_GlobalZoomNum, rectF.Y * m_GlobalZoomNum);
- SizeF sizeF = new SizeF((rectF.Width * m_GlobalZoomNum), (rectF.Height * m_GlobalZoomNum));
- l_GDIObjects[i].RegionF = new RectangleF(pointF, sizeF);
- }
- }
- #endregion
- #region 判断当前位置是否在不规则形状里面
- /// <summary>
- /// 判断当前位置是否在不规则形状里面
- /// </summary>
- /// <param name="PointList">不规则形状坐标集合</param>
- /// <param name="currentMouseLocation">当前鼠标坐标</param>
- /// <returns></returns>
- public static bool PositionPnpoly(List<Point> polygonPointList, Point currentMouseLocation)
- {
- double testx = currentMouseLocation.X;
- double testy = currentMouseLocation.Y;
- int nvert = polygonPointList.Count;
- List<double> vertx = new List<double>();
- List<double> verty = new List<double>();
- for (int pointIndex = 0; pointIndex < polygonPointList.Count; pointIndex++)
- {
- vertx.Add(polygonPointList[pointIndex].X);
- verty.Add(polygonPointList[pointIndex].Y);
- }
- int i, j, c = 0;
- for (i = 0, j = nvert - 1; i < nvert; j = i++)
- {
- if (((verty[i] > testy) != (verty[j] > testy)) && (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i]))
- {
- c = 1 + c; ;
- }
- }
- if (c % 2 == 0)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- #endregion
- #region 获取多边形最小外接矩形
- /// <summary>
- /// 获取多边形最小外接矩形
- /// </summary>
- /// <param name="polygonPointList">不规则形状坐标集合</param>
- /// <returns></returns>
- public static Rectangle GetPolygonToMinRectangle(List<PointF> polygonPointList)
- {
- if (polygonPointList != null)
- {
- if (polygonPointList.Count > 0)
- {
- int pCount = polygonPointList.Count;
- float minX = polygonPointList[0].X;
- float minY = polygonPointList[0].Y;
- float maxX = polygonPointList[0].X;
- float maxY = polygonPointList[0].Y;
- //获取最小X,Y 最大X,Y
- for (int i = 0; i < pCount; i++)
- {
- minX = Math.Min(minX, polygonPointList[i].X);
- minY = Math.Min(minY, polygonPointList[i].Y);
- maxX = Math.Max(maxX, polygonPointList[i].X);
- maxY = Math.Max(maxY, polygonPointList[i].Y);
- }
- //创建外接矩形
- Rectangle rect = new Rectangle();
- rect.Location = new Point((int)minX, (int)minY);
- rect.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY);
- return rect;
- }
- }
- return new Rectangle();
- }
- #endregion
- #region 将多边形屏幕坐标转换为OTS坐标
- /// <summary>
- /// 将多边形屏幕坐标转换为OTS坐标
- /// </summary>
- /// <param name="polygonPointList">不规则形状坐标集合</param>
- /// <returns></returns>
- public static List<PointF> GetPolygonPointToOTSPoint(List<PointF> polygonPointList, int widthDomain, int length)
- {
- List<PointF> OTSPoint = new List<PointF>();
- float X = 0;
- float Y = 0;
- if (polygonPointList != null)
- {
- foreach (var item in polygonPointList)
- {
- X = (float)(item.X * ((double)widthDomain / length));
- Y = (float)(item.Y * ((double)widthDomain / length));
- OTSPoint.Add(new PointF(X, Y));
- }
- }
- return OTSPoint;
- }
- #endregion
- #region List<Point> 转换为 List<PointF>
- /// <summary>
- /// List<Point> 转换为 List<PointF>
- /// </summary>
- /// <param name="Points"></param>
- /// <returns></returns>
- public static List<PointF> PointConvertPointF(List<Point> Points)
- {
- List<PointF> PointFs = new List<PointF>();
- if (Points != null)
- {
- foreach (var itemPoint in Points)
- {
- PointFs.Add(itemPoint);
- }
- }
- return PointFs;
- }
- public static 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 static Point[] PointFConvertPoint(PointF[] PointFs)
- {
- Point[] Points = new Point[PointFs.Length];
- if (Points != null)
- {
- for (int i = 0; i < Points.Length; i++)
- {
- Points[i] = new Point((int)PointFs[i].X, (int)PointFs[i].Y);
- }
- }
- return Points;
- }
- /// <summary>
- /// List<PointF> 转换为 List<Point>
- /// </summary>
- /// <param name="Points"></param>
- /// <returns></returns>
- public static List<Point> PointFConvertPoint(List<PointF> Points)
- {
- List<Point> PointFs = new List<Point>();
- if (Points != null)
- {
- foreach (var itemPoint in Points)
- {
- PointFs.Add(new Point((int)itemPoint.X, (int)itemPoint.Y));
- }
- }
- return PointFs;
- }
- #endregion
- #region 获取 Rectangle 外框点集合
- public static Point[] GetRectangleToPoint(RectangleF rectangleF)
- {
- int Left = (int)rectangleF.Left;
- int Top = (int)rectangleF.Top;
- int Right = (int)rectangleF.Right;
- int Bottom = (int)rectangleF.Bottom;
- List<Point> addPoint = new List<Point>();
- for (int i = Left; i <= Right; i++)
- {
- addPoint.Add(new Point(Left + 1, Top));
- }
- for (int i = Top; i <= Bottom; i++)
- {
- addPoint.Add(new Point(Right,Top + 1));
- }
- for (int i = Right; i >= Left; i--)
- {
- addPoint.Add(new Point(Right - 1, Bottom));
- }
- for (int i = Bottom; i >= Top; i--)
- {
- addPoint.Add(new Point(Left,Bottom - 1));
- }
- return addPoint.ToArray();
- }
- #endregion
- //检查测量区域是否超过样品台区域
- //RMeasureArea: 样品台的当前测量区域; RStageArea: 样品台区域; RMeasureArea《RStageArea
-
- public static bool CheckMeasureAreaIsBeyondStageArea(Rectangle RMeasureArea, Rectangle RStageArea, int iShape)
- {
- Rectangle pMeasureArea = RMeasureArea;
- Rectangle pStageArea = RStageArea;
-
- 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);
- }
- #region 重新绘制
- /// <summary>
- /// 重新绘制
- /// </summary>
- /// <param name="e"></param>
- /// <param name="m_ObjectGDIObjects"></param>
- public static void OnPaint(PaintEventArgs e, List<ARectangleGDIObject> m_ObjectGDIObjects)//处理重绘情况
- {
- foreach (ARectangleGDIObject item in m_ObjectGDIObjects)
- {
- if (item != null)
- {
- item.OnPaint(e);
- }
- }
- }
- #endregion
- #region 显示XY轴
- /// <summary>
- /// 显示XY轴
- /// </summary>
- public static void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm, List<ARectangleGDIObject> m_RectangleGDIObjects, StageDrawingData m_OTSSampleStageData,int IsWidth)
- {
- foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
- {
- if (item.Region.Contains(mPoint))
- {
- //鼠标在样品台中移动获取坐标
- Point mousePoint = OTSSamplespaceGraphicsPanelFun.GetMouseLocationInRectangleGDIObject(mPoint, m_RectangleGDIObjects[0], m_OTSSampleStageData, IsWidth, m_RectangleGDIObjects[0].Region.Width, m_RectangleGDIObjects[0].Region.Height);
- PointF SEMPoint = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(mousePoint);
- //将微米转换为毫米
- 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);
- }
- }
- }
- #endregion
- }
- }
|