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; using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel; namespace OTSMeasureApp { public class OTSSamplespaceGraphicsPanelFun { #region 鼠标移动位置 //public static CRectangleGDIObject GetMouseMoveLocation(CRectangleGDIObject item, MouseEventArgs e) //{ // //item.SetScaleRegionF(new RectangleF( // // item.GetZoomedRegion.Left + e.X - item.DraggingPoint.X, // // item.GetZoomedRegion.Top + e.Y - item.DraggingPoint.Y, // // item.GetZoomedRegion.Width, // // item.GetZoomedRegion.Height // // )); // //PointF p = new PointF(e.X - item.DraggingPoint.X, e.Y - item.DraggingPoint.Y); // item.Move(e.Location); // //item.DraggingPoint = e.Location; // return item; //} #endregion #region 鼠标方法操作 //public static RectangleF MouseWheelFunctionF(RectangleF originalRect,RectangleF curRect,Point mousePoint, float deltaZoomNum) //{ // float curZoom = curRect.Width / originalRect.Width; // float X = (curRect.X - mousePoint.X)/curZoom * deltaZoomNum +curRect.X; // float Y = (curRect.Y - mousePoint.Y)/curZoom * deltaZoomNum + curRect.Y; // float Width = originalRect.Width * (deltaZoomNum+curZoom); // float Height = originalRect.Height * (deltaZoomNum + curZoom); // return new RectangleF(X, Y, Width, Height); //} const int Band = 5; #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 根据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].GetZoomedRegionF().X; // MinY = m_SingleGDIObjects[0].GetZoomedRegionF().Y; // MaxX = m_SingleGDIObjects[0].GetZoomedRegionF().X; // MaxY = m_SingleGDIObjects[0].GetZoomedRegionF().Y; // width = m_SingleGDIObjects[0].GetZoomedRegionF().Width; // height = m_SingleGDIObjects[0].GetZoomedRegionF().Height; // for (int i = 0; i < m_SingleGDIObjects.Count; i++) // { // MinX = Math.Min(m_SingleGDIObjects[i].GetZoomedRegionF().X, MinX); // MinY = Math.Min(m_SingleGDIObjects[i].GetZoomedRegionF().Y, MinY); // MaxX = Math.Max(m_SingleGDIObjects[i].GetZoomedRegionF().X, MaxX); // MaxY = Math.Max(m_SingleGDIObjects[i].GetZoomedRegionF().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].OrigionalDrawRegionF.X; // MinY = m_SingleGDIObjects[0].OrigionalDrawRegionF.Y; // MaxX = m_SingleGDIObjects[0].OrigionalDrawRegionF.X; // MaxY = m_SingleGDIObjects[0].OrigionalDrawRegionF.Y; // width = m_SingleGDIObjects[0].OrigionalDrawRegionF.Width; // height = m_SingleGDIObjects[0].OrigionalDrawRegionF.Height; // for (int i = 0; i < m_SingleGDIObjects.Count; i++) // { // MinX = Math.Min(m_SingleGDIObjects[i].OrigionalDrawRegionF.X, MinX); // MinY = Math.Min(m_SingleGDIObjects[i].OrigionalDrawRegionF.Y, MinY); // MaxX = Math.Max(m_SingleGDIObjects[i].OrigionalDrawRegionF.X, MaxX); // MaxY = Math.Max(m_SingleGDIObjects[i].OrigionalDrawRegionF.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, CRectangleGDIObject m_ObjectGDIObjects) //{ // //获取帧图中心与测量区域中心 // PointF singleCenterPoinF = GetSingleCenterLocation(m_ObjectListGDIObjects); // PointF singleDrawCenterPoinF = GetSingleDrawCenterLocation(m_ObjectListGDIObjects); // //测量区域 已改变为倍数的尺寸 中心点 // PointF measureCenterPoin = m_ObjectGDIObjects.GetCenterPoint(); // //测量区域 正常尺寸 中心点 // PointF measureCenterPoinF = m_ObjectGDIObjects.GetCenterPoint(); // //计算相差的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.GetZoomedRegionF().X + movePoint.X; // float Y = ObjectItem.GetZoomedRegionF().Y + movePoint.Y; // float Width = ObjectItem.GetZoomedRegionF().Width; // float Height = ObjectItem.GetZoomedRegionF().Height; // ObjectItem.SetInitRegionF(new RectangleF(X, Y, Width, Height)); // } //} #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 } }