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 鼠标在样品台中移动获取坐标
///
/// 鼠标在样品台中移动获取坐标
///
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 测量区域与样品中心相差的距离
///
/// 测量区域与样品中心相差的距离
///
///
///
///
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 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 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 切换样品
///
/// 切换样品
///
/// 样品信息列表
/// 样品台名称
public static List SelectSampleIndex(List 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 SelectMeasureIndexIsTop(List objList, string SampleName)
{
List 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 SelectSampleIndexIsTop(List objList, string SampleName)
{
List 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 根据对象点 与 相距的宽度 生成一个矩形
///
/// 根据对象点 与 相距的宽度 生成一个矩形
///
///
///
///
/// 0:圆角矩形 1:圆形 2:文字 3:矩形
///
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 判断是否相同
///
/// 判断是否相同
///
///
///
///
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 获取工作样品信息
///
/// 获取工作样品信息
///
///
///
public static ARectangleGDIObject GetWorkSample(string sampleName)
{
foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
{
if (itemSample.SampleName == sampleName)
{
return itemSample;
}
}
return null;
}
#endregion
#region 获取测量区域
///
/// 获取测量区域
///
///
///
///
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 获取工作样品的测量区域信息
///
/// 获取工作样品的测量区域信息
///
///
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 ListClear(List 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 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 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 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
///
/// 获取XML中电镜的选项
///
#region 测量区域中心移动至SEM当前位置
///
/// 测量区域中心移动至SEM当前位置
///
/// 样品台窗体对象
/// 当前鼠标的位置
public static void NewLocationDrawMeasureInfo(OTSSamplespaceWindow m_SamplespaceWindow, List m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, Point moveToSEMLocation, List 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 m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, Point moveToSEMLocation, List 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 通过样品孔名称 获取在列表中的索引
///
/// 通过样品孔名称 获取在列表中的索引
///
/// 样品台文件
/// 样品孔名称
///
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 添加帧图信息
///
/// 添加帧图信息
///
/// 帧图对象列表
/// 帧图对象列表
/// 样品名称
///
public static bool AddALLSingleInfo(List m_ALLSingleGDIObjects, List 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 删除帧图信息
///
/// 删除帧图信息
///
/// 帧图对象列表
/// 样品名称
///
public static bool DeleteALLSingleInfo(List 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 m_ALLSingleGDIObjects, List 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 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 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 判断当前位置是否在不规则形状里面
///
/// 判断当前位置是否在不规则形状里面
///
/// 不规则形状坐标集合
/// 当前鼠标坐标
///
public static bool PositionPnpoly(List polygonPointList, Point currentMouseLocation)
{
double testx = currentMouseLocation.X;
double testy = currentMouseLocation.Y;
int nvert = polygonPointList.Count;
List vertx = new List();
List verty = new List();
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 获取多边形最小外接矩形
///
/// 获取多边形最小外接矩形
///
/// 不规则形状坐标集合
///
public static Rectangle GetPolygonToMinRectangle(List 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坐标
///
/// 将多边形屏幕坐标转换为OTS坐标
///
/// 不规则形状坐标集合
///
public static List GetPolygonPointToOTSPoint(List polygonPointList, int widthDomain, int length)
{
List OTSPoint = new List();
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 转换为 List
///
/// List 转换为 List
///
///
///
public static List PointConvertPointF(List Points)
{
List PointFs = new List();
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;
}
///
/// List 转换为 List
///
///
///
public static 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;
}
#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 addPoint = new List();
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 重新绘制
///
/// 重新绘制
///
///
///
public static void OnPaint(PaintEventArgs e, List m_ObjectGDIObjects)//处理重绘情况
{
foreach (ARectangleGDIObject item in m_ObjectGDIObjects)
{
if (item != null)
{
item.OnPaint(e);
}
}
}
#endregion
#region 显示XY轴
///
/// 显示XY轴
///
public static void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm, List 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
}
}