OTSSamplespaceGraphicsPanelFun.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. using OTSCLRINTERFACE;
  2. using OTSDataType;
  3. using OTSCommon;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Drawing.Drawing2D;
  9. using System.Windows.Forms;
  10. using OTSModelSharp.ServiceInterface;
  11. using OTSModelSharp.ServiceCenter;
  12. using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel;
  13. namespace OTSMeasureApp
  14. {
  15. public class OTSSamplespaceGraphicsPanelFun
  16. {
  17. #region 鼠标移动位置
  18. //public static CRectangleGDIObject GetMouseMoveLocation(CRectangleGDIObject item, MouseEventArgs e)
  19. //{
  20. // //item.SetScaleRegionF(new RectangleF(
  21. // // item.GetZoomedRegion.Left + e.X - item.DraggingPoint.X,
  22. // // item.GetZoomedRegion.Top + e.Y - item.DraggingPoint.Y,
  23. // // item.GetZoomedRegion.Width,
  24. // // item.GetZoomedRegion.Height
  25. // // ));
  26. // //PointF p = new PointF(e.X - item.DraggingPoint.X, e.Y - item.DraggingPoint.Y);
  27. // item.Move(e.Location);
  28. // //item.DraggingPoint = e.Location;
  29. // return item;
  30. //}
  31. #endregion
  32. #region 鼠标方法操作
  33. //public static RectangleF MouseWheelFunctionF(RectangleF originalRect,RectangleF curRect,Point mousePoint, float deltaZoomNum)
  34. //{
  35. // float curZoom = curRect.Width / originalRect.Width;
  36. // float X = (curRect.X - mousePoint.X)/curZoom * deltaZoomNum +curRect.X;
  37. // float Y = (curRect.Y - mousePoint.Y)/curZoom * deltaZoomNum + curRect.Y;
  38. // float Width = originalRect.Width * (deltaZoomNum+curZoom);
  39. // float Height = originalRect.Height * (deltaZoomNum + curZoom);
  40. // return new RectangleF(X, Y, Width, Height);
  41. //}
  42. const int Band = 5;
  43. #endregion
  44. #region 根据颜色枚举 获取颜色值
  45. public static string GetColorValue(ColorType ColorEnum)
  46. {
  47. string ColorStr = string.Empty;
  48. switch (ColorEnum)
  49. {
  50. case ColorType.SingleColor:
  51. ColorStr = "#fd8f8f";//帧图fd8f8f
  52. break;
  53. case ColorType.RoundRectangleColor:
  54. ColorStr = "#c8c8c8";//c8c8c8圆角矩形
  55. break;
  56. case ColorType.FontColor:
  57. ColorStr = "#90ee90";//90ee90文字颜色
  58. break;
  59. case ColorType.SampleColor:
  60. ColorStr = "#f4f4f4";//f4f4f4 样品未选择
  61. break;
  62. case ColorType.SampleSelColor:
  63. ColorStr = "#505050";//505050 样品选择后
  64. break;
  65. }
  66. return ColorStr;
  67. }
  68. #endregion
  69. #region 根据list中的帧图信息 获取中心位置
  70. //public static PointF GetSingleCenterLocation(List<CRectangleGDIObject> m_SingleGDIObjects)
  71. //{
  72. // float MinX = 0f;
  73. // float MinY = 0f;
  74. // float MaxX = 0f;
  75. // float MaxY = 0f;
  76. // float width = 0f;
  77. // float height = 0f;
  78. // //获取最小XY 与最大XY
  79. // MinX = m_SingleGDIObjects[0].GetZoomedRegionF().X;
  80. // MinY = m_SingleGDIObjects[0].GetZoomedRegionF().Y;
  81. // MaxX = m_SingleGDIObjects[0].GetZoomedRegionF().X;
  82. // MaxY = m_SingleGDIObjects[0].GetZoomedRegionF().Y;
  83. // width = m_SingleGDIObjects[0].GetZoomedRegionF().Width;
  84. // height = m_SingleGDIObjects[0].GetZoomedRegionF().Height;
  85. // for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  86. // {
  87. // MinX = Math.Min(m_SingleGDIObjects[i].GetZoomedRegionF().X, MinX);
  88. // MinY = Math.Min(m_SingleGDIObjects[i].GetZoomedRegionF().Y, MinY);
  89. // MaxX = Math.Max(m_SingleGDIObjects[i].GetZoomedRegionF().X, MaxX);
  90. // MaxY = Math.Max(m_SingleGDIObjects[i].GetZoomedRegionF().Y, MaxY);
  91. // }
  92. // //获取帧图的外框矩形
  93. // RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX- MinX+ width, MaxY- MinY+ height);
  94. // //计算外框矩形的中心点
  95. // float PointFX = SingleRect.X + SingleRect.Width / 2;
  96. // float PointFY = SingleRect.Y + SingleRect.Height / 2;
  97. // PointF SingleCenterPoint = new PointF(PointFX, PointFY);
  98. // return SingleCenterPoint;
  99. //}
  100. //public static PointF GetSingleDrawCenterLocation(List<CRectangleGDIObject> m_SingleGDIObjects)
  101. //{
  102. // float MinX = 0f;
  103. // float MinY = 0f;
  104. // float MaxX = 0f;
  105. // float MaxY = 0f;
  106. // float width = 0f;
  107. // float height = 0f;
  108. // //获取最小XY 与最大XY
  109. // MinX = m_SingleGDIObjects[0].OrigionalDrawRegionF.X;
  110. // MinY = m_SingleGDIObjects[0].OrigionalDrawRegionF.Y;
  111. // MaxX = m_SingleGDIObjects[0].OrigionalDrawRegionF.X;
  112. // MaxY = m_SingleGDIObjects[0].OrigionalDrawRegionF.Y;
  113. // width = m_SingleGDIObjects[0].OrigionalDrawRegionF.Width;
  114. // height = m_SingleGDIObjects[0].OrigionalDrawRegionF.Height;
  115. // for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  116. // {
  117. // MinX = Math.Min(m_SingleGDIObjects[i].OrigionalDrawRegionF.X, MinX);
  118. // MinY = Math.Min(m_SingleGDIObjects[i].OrigionalDrawRegionF.Y, MinY);
  119. // MaxX = Math.Max(m_SingleGDIObjects[i].OrigionalDrawRegionF.X, MaxX);
  120. // MaxY = Math.Max(m_SingleGDIObjects[i].OrigionalDrawRegionF.Y, MaxY);
  121. // }
  122. // //获取帧图的外框矩形
  123. // RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX - MinX + width, MaxY - MinY + height);
  124. // //计算外框矩形的中心点
  125. // float PointFX = SingleRect.X + SingleRect.Width / 2;
  126. // float PointFY = SingleRect.Y + SingleRect.Height / 2;
  127. // PointF SingleCenterPoint = new PointF(PointFX, PointFY);
  128. // return SingleCenterPoint;
  129. //}
  130. #endregion
  131. #region 将所有帧图移植测量区域位置
  132. //public static void SetSingleLocationToMeasureLocation(List<CRectangleGDIObject> m_ObjectListGDIObjects, CRectangleGDIObject m_ObjectGDIObjects)
  133. //{
  134. // //获取帧图中心与测量区域中心
  135. // PointF singleCenterPoinF = GetSingleCenterLocation(m_ObjectListGDIObjects);
  136. // PointF singleDrawCenterPoinF = GetSingleDrawCenterLocation(m_ObjectListGDIObjects);
  137. // //测量区域 已改变为倍数的尺寸 中心点
  138. // PointF measureCenterPoin = m_ObjectGDIObjects.GetCenterPoint();
  139. // //测量区域 正常尺寸 中心点
  140. // PointF measureCenterPoinF = m_ObjectGDIObjects.GetCenterPoint();
  141. // //计算相差的XY距离
  142. // float moveX = measureCenterPoin.X - singleCenterPoinF.X;
  143. // float moveY = measureCenterPoin.Y - singleCenterPoinF.Y;
  144. // float moveFX = measureCenterPoinF.X - singleDrawCenterPoinF.X;
  145. // float moveFY = measureCenterPoinF.Y - singleDrawCenterPoinF.Y;
  146. // //需要移动的位置
  147. // PointF movePoint = new PointF(moveX, moveY);
  148. // PointF movePointF = new PointF(moveFX, moveFY);
  149. // foreach (var ObjectItem in m_ObjectListGDIObjects)
  150. // {
  151. // //计算移动后的位置
  152. // float X = ObjectItem.GetZoomedRegionF().X + movePoint.X;
  153. // float Y = ObjectItem.GetZoomedRegionF().Y + movePoint.Y;
  154. // float Width = ObjectItem.GetZoomedRegionF().Width;
  155. // float Height = ObjectItem.GetZoomedRegionF().Height;
  156. // ObjectItem.SetInitRegionF(new RectangleF(X, Y, Width, Height));
  157. // }
  158. //}
  159. #endregion
  160. #region 判断当前位置是否在不规则形状里面
  161. /// <summary>
  162. /// 判断当前位置是否在不规则形状里面
  163. /// </summary>
  164. /// <param name="PointList">不规则形状坐标集合</param>
  165. /// <param name="currentMouseLocation">当前鼠标坐标</param>
  166. /// <returns></returns>
  167. public static bool PositionPnpoly(List<Point> polygonPointList, Point currentMouseLocation)
  168. {
  169. double testx = currentMouseLocation.X;
  170. double testy = currentMouseLocation.Y;
  171. int nvert = polygonPointList.Count;
  172. List<double> vertx = new List<double>();
  173. List<double> verty = new List<double>();
  174. for (int pointIndex = 0; pointIndex < polygonPointList.Count; pointIndex++)
  175. {
  176. vertx.Add(polygonPointList[pointIndex].X);
  177. verty.Add(polygonPointList[pointIndex].Y);
  178. }
  179. int i, j, c = 0;
  180. for (i = 0, j = nvert - 1; i < nvert; j = i++)
  181. {
  182. if (((verty[i] > testy) != (verty[j] > testy)) && (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i]))
  183. {
  184. c = 1 + c; ;
  185. }
  186. }
  187. if (c % 2 == 0)
  188. {
  189. return false;
  190. }
  191. else
  192. {
  193. return true;
  194. }
  195. }
  196. #endregion
  197. #region 获取多边形最小外接矩形
  198. /// <summary>
  199. /// 获取多边形最小外接矩形
  200. /// </summary>
  201. /// <param name="polygonPointList">不规则形状坐标集合</param>
  202. /// <returns></returns>
  203. public static Rectangle GetMinRectangleOfPolygon(List<PointF> polygonPointList)
  204. {
  205. if (polygonPointList != null)
  206. {
  207. if (polygonPointList.Count > 0)
  208. {
  209. int pCount = polygonPointList.Count;
  210. float minX = polygonPointList[0].X;
  211. float minY = polygonPointList[0].Y;
  212. float maxX = polygonPointList[0].X;
  213. float maxY = polygonPointList[0].Y;
  214. //获取最小X,Y 最大X,Y
  215. for (int i = 0; i < pCount; i++)
  216. {
  217. minX = Math.Min(minX, polygonPointList[i].X);
  218. minY = Math.Min(minY, polygonPointList[i].Y);
  219. maxX = Math.Max(maxX, polygonPointList[i].X);
  220. maxY = Math.Max(maxY, polygonPointList[i].Y);
  221. }
  222. //创建外接矩形
  223. Rectangle rect = new Rectangle();
  224. rect.Location = new Point((int)minX, (int)minY);
  225. rect.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY);
  226. return rect;
  227. }
  228. }
  229. return new Rectangle();
  230. }
  231. #endregion
  232. }
  233. }