123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- 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.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 RectangleF MouseWheelFunctionF(CRectangleGDIObject 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);
- }
- 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<CRectangleGDIObject> 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<CRectangleGDIObject> 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<CRectangleGDIObject> 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.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
- #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
-
- }
- }
|