OTSSamplespaceGraphicsPanelFun.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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.Region = new Rectangle(
  21. item.Region.Left + e.X - item.DraggingPoint.X,
  22. item.Region.Top + e.Y - item.DraggingPoint.Y,
  23. item.Region.Width,
  24. item.Region.Height);
  25. item.DraggingPoint = e.Location;
  26. return item;
  27. }
  28. #endregion
  29. #region 鼠标方法操作
  30. public static void MouseWheelFunction(List<CRectangleGDIObject> objList, CRectangleGDIObject m_RectangleGDIObjects, float globalZoomNum)
  31. {
  32. for (int i = 0; i < objList.Count; i++)
  33. {
  34. //多边形测量区域鼠标缩放
  35. if (objList[i].CreateType == CreateRectangleType.Polygon)
  36. {
  37. if (objList[i].DrawPolygonPointRegionF != null)
  38. {
  39. int polygonPointCount = objList[i].DrawPolygonPointRegionF.Count;
  40. if (polygonPointCount > 0)
  41. {
  42. for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
  43. {
  44. PointF wheelPoint = new PointF();
  45. wheelPoint = objList[i].DrawPolygonPointRegionF[pointIndex];
  46. float X = wheelPoint.X * globalZoomNum;
  47. float Y = wheelPoint.Y * globalZoomNum;
  48. objList[i].PolygonPointRegionF[pointIndex] = new PointF(wheelPoint.X * globalZoomNum, wheelPoint.Y * globalZoomNum);
  49. }
  50. }
  51. }
  52. }
  53. else
  54. {
  55. RectangleF rectF = new RectangleF();
  56. rectF = objList[i].RegionF;
  57. //根据样品孔中心点与样品台中心点的方向 设置宽度与高度\
  58. RectangleF returnRectF = OTSSamplespaceGraphicsPanelFun.MouseWheelFunctionF(m_RectangleGDIObjects, rectF, globalZoomNum);
  59. objList[i].Region = new Rectangle((int)returnRectF.X, (int)returnRectF.Y, (int)returnRectF.Width, (int)returnRectF.Height);
  60. objList[i].BSEImageWitdh = returnRectF.Width;
  61. objList[i].BSEImageHeight = returnRectF.Height;
  62. objList[i].BSEImageLocation = new PointF(returnRectF.X, returnRectF.Y);
  63. objList[i].SEMCenterPoint = returnRectF.Location;
  64. //重新绘制测量区域路径
  65. UpdateMeasureGraphicsPath(objList[i], objList[i].Region);
  66. }
  67. }
  68. }
  69. public static RectangleF MouseWheelFunctionF(CRectangleGDIObject RectangleGDIObject, RectangleF itemRect, float globalZoomNum)
  70. {
  71. //缩放比例
  72. float X = itemRect.X * globalZoomNum;
  73. float Y = itemRect.Y * globalZoomNum;
  74. float Width = itemRect.Width * globalZoomNum;
  75. float Height = itemRect.Height * globalZoomNum;
  76. return new RectangleF(X, Y, Width, Height);
  77. }
  78. public enum EnumMousePointPosition
  79. {
  80. MouseSizeNone = 0, //'无
  81. MouseSizeRight = 1, //'拉伸右边框
  82. MouseSizeLeft = 2, //'拉伸左边框
  83. MouseSizeBottom = 3, //'拉伸下边框
  84. MouseSizeTop = 4, //'拉伸上边框
  85. MouseSizeTopLeft = 5, //'拉伸左上角
  86. MouseSizeTopRight = 6, //'拉伸右上角
  87. MouseSizeBottomLeft = 7, //'拉伸左下角
  88. MouseSizeBottomRight = 8, //'拉伸右下角
  89. MouseDrag = 9 // '鼠标拖动
  90. }
  91. const int Band = 5;
  92. public static EnumMousePointPosition MousePointPosition(Point point, Point e)
  93. {
  94. //MouseDrag 中心
  95. if ((e.X == point.X) && (e.Y == point.Y))
  96. {
  97. return EnumMousePointPosition.MouseDrag;
  98. }
  99. //MouseSizeTopLeft 上左
  100. if ((e.X < point.X) && (e.Y < point.Y))
  101. {
  102. return EnumMousePointPosition.MouseSizeTopLeft;
  103. }
  104. //MouseSizeTopRight 下右
  105. if ((e.X > point.X) && (e.Y < point.Y))
  106. {
  107. return EnumMousePointPosition.MouseSizeTopRight;
  108. }
  109. //MouseSizeLeft 左侧
  110. if ((e.X < point.X) && (e.Y == point.Y))
  111. {
  112. return EnumMousePointPosition.MouseSizeLeft;
  113. }
  114. //MouseSizeRight 右侧
  115. if ((e.X > point.X) && (e.Y == point.Y))
  116. {
  117. return EnumMousePointPosition.MouseSizeRight;
  118. }
  119. //MouseSizeTop 上侧
  120. if ((e.X == point.X) && (e.Y < point.Y))
  121. {
  122. return EnumMousePointPosition.MouseSizeTop;
  123. }
  124. //MouseSizeBottom 下侧
  125. if ((e.X == point.X) && (e.Y > point.Y))
  126. {
  127. return EnumMousePointPosition.MouseSizeBottom;
  128. }
  129. //MouseSizeBottomRight 下左
  130. if ((e.X < point.X) && (e.Y > point.Y))
  131. {
  132. return EnumMousePointPosition.MouseSizeBottomLeft;
  133. }
  134. //MouseSizeBottomRight 下右
  135. if ((e.X > point.X) && (e.Y > point.Y))
  136. {
  137. return EnumMousePointPosition.MouseSizeBottomRight;
  138. }
  139. return EnumMousePointPosition.MouseSizeNone;
  140. }
  141. #endregion
  142. #region 根据选择的测量区域 切换至最上层
  143. public static List<CRectangleGDIObject> SelectMeasureIndexIsTop(List<CRectangleGDIObject> objList, string SampleName)
  144. {
  145. List<CRectangleGDIObject> objListTemp = objList;
  146. CRectangleGDIObject itemTemp = null;
  147. foreach (CRectangleGDIObject item in objList)
  148. {
  149. if (item.SampleName == SampleName)
  150. {
  151. //临时记录所选测量区域
  152. itemTemp = item;
  153. //删除原信息
  154. objListTemp.Remove(item);
  155. //添加新信息
  156. objListTemp.Insert(objListTemp.Count, itemTemp);
  157. break;
  158. }
  159. }
  160. return objListTemp;
  161. }
  162. #endregion
  163. #region 根据选择的样品 切换至最上层
  164. public static List<CRectangleGDIObject> SelectSampleIndexIsTop(List<CRectangleGDIObject> objList, string SampleName)
  165. {
  166. List<CRectangleGDIObject> objListTemp = objList;
  167. CRectangleGDIObject itemTemp = null;
  168. foreach (CRectangleGDIObject item in objList)
  169. {
  170. if (item.SampleName == SampleName)
  171. {
  172. //临时记录所选样品
  173. itemTemp = item;
  174. //删除原信息
  175. objListTemp.Remove(item);
  176. //添加新信息
  177. objListTemp.Insert(objListTemp.Count, itemTemp);
  178. break;
  179. }
  180. }
  181. return objListTemp;
  182. }
  183. #endregion
  184. #region 获取拍摄BSE图 将byte数组转换为图片
  185. public static Image GetBSEImage(byte[] ImageByte, int width, int height)
  186. {
  187. //图片
  188. Bitmap bitmap = null;
  189. //将byte数据转换为图片
  190. bitmap = CImageHandler.ToGrayBitmap(ImageByte, width, height);
  191. return bitmap;
  192. }
  193. #endregion
  194. #region 删除样品弹出提示
  195. public static bool ShowDeleteDialog(string sampleName)
  196. {
  197. //国际化
  198. OTSCommon.Language lan = new OTSCommon.Language();
  199. Hashtable table = lan.GetNameTable("OTSIncAMeasureAppForm");
  200. string str1 = table["message5"].ToString();
  201. string str2 = table["message6"].ToString();
  202. string sDeleteSampleName = str1;
  203. sDeleteSampleName += sampleName;
  204. sDeleteSampleName += " 信息 ?";
  205. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Delete sample information prompt", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  206. {
  207. return true;
  208. }
  209. else
  210. {
  211. return false;
  212. }
  213. }
  214. #endregion
  215. //#region 将点转换至工作区域
  216. //public void PointToClient(Point rect)
  217. //{
  218. // this.PointToClient(rect);
  219. //}
  220. //#endregion
  221. #region 删除样品 同时删除帧图
  222. public static bool DeleteSampleInfo(OTSIncAMeasureAppForm m_MeasureAppForm, string sampleSelectName)
  223. {
  224. try
  225. {
  226. //提交主窗体响应
  227. bool deleteResult = false;
  228. if (OTSSamplespaceGraphicsPanelFun.ShowDeleteDialog(sampleSelectName))
  229. {
  230. //设置当前状态
  231. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  232. deleteResult = m_MeasureAppForm.DeleteSample(sampleSelectName);
  233. if (deleteResult)
  234. {
  235. //样品对象列表中无样品信息 则清除帧图对象列表信息
  236. bool result = m_MeasureAppForm.m_SamplepaceWindow.SampleIsEmptyClearSingleInfo();
  237. if(result)
  238. {
  239. m_MeasureAppForm.m_MeasureRetWindow.SetInit();
  240. }
  241. }
  242. }
  243. return true;
  244. }
  245. catch (Exception)
  246. {
  247. return false;
  248. }
  249. }
  250. #endregion
  251. #region 根据颜色枚举 获取颜色值
  252. public static string GetColorValue(ColorType ColorEnum)
  253. {
  254. string ColorStr = string.Empty;
  255. switch (ColorEnum)
  256. {
  257. case ColorType.SingleColor:
  258. ColorStr = "#fd8f8f";//帧图fd8f8f
  259. break;
  260. case ColorType.RoundRectangleColor:
  261. ColorStr = "#c8c8c8";//c8c8c8圆角矩形
  262. break;
  263. case ColorType.FontColor:
  264. ColorStr = "#90ee90";//90ee90文字颜色
  265. break;
  266. case ColorType.SampleColor:
  267. ColorStr = "#f4f4f4";//f4f4f4 样品未选择
  268. break;
  269. case ColorType.SampleSelColor:
  270. ColorStr = "#505050";//505050 样品选择后
  271. break;
  272. }
  273. return ColorStr;
  274. }
  275. #endregion
  276. #region 根据list中的帧图信息 获取中心位置
  277. public static PointF GetSingleCenterLocation(List<CRectangleGDIObject> m_SingleGDIObjects)
  278. {
  279. float MinX = 0f;
  280. float MinY = 0f;
  281. float MaxX = 0f;
  282. float MaxY = 0f;
  283. float width = 0f;
  284. float height = 0f;
  285. //获取最小XY 与最大XY
  286. MinX = m_SingleGDIObjects[0].RegionF.X;
  287. MinY = m_SingleGDIObjects[0].RegionF.Y;
  288. MaxX = m_SingleGDIObjects[0].RegionF.X;
  289. MaxY = m_SingleGDIObjects[0].RegionF.Y;
  290. width = m_SingleGDIObjects[0].RegionF.Width;
  291. height = m_SingleGDIObjects[0].RegionF.Height;
  292. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  293. {
  294. MinX = Math.Min(m_SingleGDIObjects[i].RegionF.X, MinX);
  295. MinY = Math.Min(m_SingleGDIObjects[i].RegionF.Y, MinY);
  296. MaxX = Math.Max(m_SingleGDIObjects[i].RegionF.X, MaxX);
  297. MaxY = Math.Max(m_SingleGDIObjects[i].RegionF.Y, MaxY);
  298. }
  299. //获取帧图的外框矩形
  300. RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX- MinX+ width, MaxY- MinY+ height);
  301. //计算外框矩形的中心点
  302. float PointFX = SingleRect.X + SingleRect.Width / 2;
  303. float PointFY = SingleRect.Y + SingleRect.Height / 2;
  304. PointF SingleCenterPoint = new PointF(PointFX, PointFY);
  305. return SingleCenterPoint;
  306. }
  307. public static PointF GetSingleDrawCenterLocation(List<CRectangleGDIObject> m_SingleGDIObjects)
  308. {
  309. float MinX = 0f;
  310. float MinY = 0f;
  311. float MaxX = 0f;
  312. float MaxY = 0f;
  313. float width = 0f;
  314. float height = 0f;
  315. //获取最小XY 与最大XY
  316. MinX = m_SingleGDIObjects[0].DrawRegionF.X;
  317. MinY = m_SingleGDIObjects[0].DrawRegionF.Y;
  318. MaxX = m_SingleGDIObjects[0].DrawRegionF.X;
  319. MaxY = m_SingleGDIObjects[0].DrawRegionF.Y;
  320. width = m_SingleGDIObjects[0].DrawRegionF.Width;
  321. height = m_SingleGDIObjects[0].DrawRegionF.Height;
  322. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  323. {
  324. MinX = Math.Min(m_SingleGDIObjects[i].DrawRegionF.X, MinX);
  325. MinY = Math.Min(m_SingleGDIObjects[i].DrawRegionF.Y, MinY);
  326. MaxX = Math.Max(m_SingleGDIObjects[i].DrawRegionF.X, MaxX);
  327. MaxY = Math.Max(m_SingleGDIObjects[i].DrawRegionF.Y, MaxY);
  328. }
  329. //获取帧图的外框矩形
  330. RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX - MinX + width, MaxY - MinY + height);
  331. //计算外框矩形的中心点
  332. float PointFX = SingleRect.X + SingleRect.Width / 2;
  333. float PointFY = SingleRect.Y + SingleRect.Height / 2;
  334. PointF SingleCenterPoint = new PointF(PointFX, PointFY);
  335. return SingleCenterPoint;
  336. }
  337. #endregion
  338. #region 将所有帧图移植测量区域位置
  339. public static void SetSingleLocationToMeasureLocation(List<CRectangleGDIObject> m_ObjectListGDIObjects, CRectangleGDIObject m_ObjectGDIObjects)
  340. {
  341. //获取帧图中心与测量区域中心
  342. PointF singleCenterPoinF= GetSingleCenterLocation(m_ObjectListGDIObjects);
  343. PointF singleDrawCenterPoinF = GetSingleDrawCenterLocation(m_ObjectListGDIObjects);
  344. //测量区域 已改变为倍数的尺寸 中心点
  345. PointF measureCenterPoin = m_ObjectGDIObjects. GetCenterPoint();
  346. //测量区域 正常尺寸 中心点
  347. PointF measureCenterPoinF = m_ObjectGDIObjects. GetCenterPoint();
  348. //计算相差的XY距离
  349. float moveX = measureCenterPoin.X - singleCenterPoinF.X;
  350. float moveY = measureCenterPoin.Y - singleCenterPoinF.Y;
  351. float moveFX = measureCenterPoinF.X - singleDrawCenterPoinF.X;
  352. float moveFY = measureCenterPoinF.Y - singleDrawCenterPoinF.Y;
  353. //需要移动的位置
  354. PointF movePoint = new PointF(moveX, moveY);
  355. PointF movePointF = new PointF(moveFX, moveFY);
  356. foreach (var ObjectItem in m_ObjectListGDIObjects)
  357. {
  358. //计算移动后的位置
  359. float X = ObjectItem.RegionF.X + movePoint.X;
  360. float Y = ObjectItem.RegionF.Y + movePoint.Y;
  361. float Width = ObjectItem.RegionF.Width;
  362. float Height = ObjectItem.RegionF.Height;
  363. ObjectItem.Region = new Rectangle((int)X, (int)Y, (int)Width, (int)Height);
  364. ObjectItem.RegionF = new RectangleF(X, Y, Width, Height);
  365. ObjectItem.DrawRegionF = new RectangleF(ObjectItem.DrawRegionF.X + movePointF.X, ObjectItem.DrawRegionF.Y + movePointF.Y, ObjectItem.DrawRegionF.Width, ObjectItem.DrawRegionF.Height);
  366. }
  367. }
  368. #endregion
  369. #region 通过样品孔名称 获取在列表中的索引
  370. /// <summary>
  371. /// 通过样品孔名称 获取在列表中的索引
  372. /// </summary>
  373. /// <param name="oTSSampleStageData">样品台文件</param>
  374. /// <param name="sampleHoleName">样品孔名称</param>
  375. /// <returns></returns>
  376. public static int GetSampleHoleIndex(StageDrawingData oTSSampleStageData,string sampleHoleName, ref OTSSampleHoleInfo sampleHoleInfo)
  377. {
  378. try
  379. {
  380. int sampleHoleIndex = -1;
  381. if (oTSSampleStageData.sSHoleInfoList.Count > 0)
  382. {
  383. for (int i = 0; i < oTSSampleStageData.sSHoleInfoList.Count; i++)
  384. {
  385. if (oTSSampleStageData.sSHoleInfoList[i].sSHoleName == sampleHoleName)
  386. {
  387. sampleHoleInfo = oTSSampleStageData.sSHoleInfoList[i];
  388. sampleHoleIndex = i;
  389. break;
  390. }
  391. }
  392. }
  393. return sampleHoleIndex;
  394. }
  395. catch (Exception)
  396. {
  397. return -1;
  398. }
  399. }
  400. #endregion
  401. #region 添加帧图信息
  402. /// <summary>
  403. /// 添加帧图信息
  404. /// </summary>
  405. /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
  406. /// <param name="m_SingleGDIObjects">帧图对象列表</param>
  407. /// <param name="sampleName">样品名称</param>
  408. /// <returns></returns>
  409. public static bool AddALLSingleInfo(List<CRectangleGDIObject> m_ALLSingleGDIObjects, List<CRectangleGDIObject> m_SingleGDIObjects, string sampleName)
  410. {
  411. bool result = false;
  412. //判断ALLSingle对象列表中是否为空
  413. if (m_ALLSingleGDIObjects != null)
  414. {
  415. bool IsExist = true;
  416. if (m_ALLSingleGDIObjects.Count > 0)
  417. {
  418. //判断是否包含样品名称
  419. foreach (var item in m_ALLSingleGDIObjects)
  420. {
  421. if (item.SampleName.Equals(sampleName))
  422. {
  423. IsExist = false;
  424. break;
  425. }
  426. }
  427. }
  428. if (IsExist)
  429. {
  430. result = true;
  431. foreach (var item in m_SingleGDIObjects)
  432. {
  433. m_ALLSingleGDIObjects.Add(item);
  434. }
  435. }
  436. return result;
  437. }
  438. return result;
  439. }
  440. #endregion
  441. #region 删除帧图信息
  442. /// <summary>
  443. /// 删除帧图信息
  444. /// </summary>
  445. /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
  446. /// <param name="sampleName">样品名称</param>
  447. /// <returns></returns>
  448. public static bool DeleteALLSingleInfo(List<CRectangleGDIObject> m_ALLSingleGDIObjects, string sampleName)
  449. {
  450. bool result = false;
  451. int resultCount = 0;
  452. //判断ALLSingle对象列表中是否为空
  453. if (m_ALLSingleGDIObjects != null)
  454. {
  455. if (m_ALLSingleGDIObjects.Count > 0)
  456. {
  457. for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
  458. {
  459. if (m_ALLSingleGDIObjects[i].SampleName.Equals(sampleName))
  460. {
  461. m_ALLSingleGDIObjects.RemoveAt(i);
  462. resultCount++;
  463. }
  464. }
  465. }
  466. else
  467. {
  468. result = true;
  469. }
  470. if (resultCount > 0)
  471. {
  472. result = true;
  473. }
  474. }
  475. return result;
  476. }
  477. #endregion
  478. #region 切换样品 填充帧图信息
  479. public static void ChangeSampleFillSingleInfo(List<CRectangleGDIObject> m_ALLSingleGDIObjects, List<CRectangleGDIObject> m_SingleGDIObjects, string sampleName)
  480. {
  481. //判断帧图对象中是否存在当前工作样品帧图信息
  482. bool IsExist = true;
  483. //判断ALLSingle对象列表中是否为空
  484. if (m_ALLSingleGDIObjects != null)
  485. {
  486. if (m_ALLSingleGDIObjects.Count > 0)
  487. {
  488. foreach (var item in m_SingleGDIObjects)
  489. {
  490. if (item.SampleName.Equals(sampleName))
  491. {
  492. IsExist = false;
  493. }
  494. }
  495. if (IsExist)
  496. {
  497. //判断是否包含样品名称
  498. foreach (var item in m_ALLSingleGDIObjects)
  499. {
  500. if (item.SampleName.Equals(sampleName))
  501. {
  502. m_SingleGDIObjects.Add(item);
  503. }
  504. }
  505. }
  506. }
  507. }
  508. }
  509. #endregion
  510. #region 修改已存在的帧图中样品名称
  511. public static void EditWorkSampleName(List<CRectangleGDIObject> m_ALLSingleGDIObjects, string oldSampleName, string newSampleName)
  512. {
  513. int resultCount = 0;
  514. //判断ALLSingle对象列表中是否为空
  515. if (m_ALLSingleGDIObjects != null)
  516. {
  517. if (m_ALLSingleGDIObjects.Count > 0)
  518. {
  519. for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
  520. {
  521. if (m_ALLSingleGDIObjects[i].SampleName.Equals(oldSampleName))
  522. {
  523. m_ALLSingleGDIObjects[i].SampleName = newSampleName;
  524. resultCount++;
  525. }
  526. }
  527. }
  528. }
  529. }
  530. #endregion
  531. #region 修改测量区域中GraphicsPath属性
  532. public static void UpdateMeasureGraphicsPath(CRectangleGDIObject measureItem, Rectangle rectPara)
  533. {
  534. //重新绘制测量区域路径
  535. GraphicsPath GPath = new GraphicsPath();
  536. if (measureItem.CreateType == CreateRectangleType.Polygon)
  537. {
  538. GraphicsPath PolygonMeasurePath = new GraphicsPath();
  539. PolygonMeasurePath.AddPolygon(measureItem.PolygonPointRegionF.ToArray());
  540. GPath = PolygonMeasurePath;
  541. }
  542. else if(measureItem.CreateType == CreateRectangleType.CircleByThreePoints)
  543. {
  544. GPath.AddEllipse(rectPara);
  545. }
  546. else
  547. {
  548. if (measureItem.Shape == (int)CreateRectangleType.Circle)
  549. {
  550. GPath.AddEllipse(rectPara);
  551. }
  552. else
  553. {
  554. GPath.AddRectangle(rectPara);
  555. }
  556. }
  557. measureItem.GPath = GPath;
  558. }
  559. #endregion
  560. #region OnMouseWheel
  561. public static void RestoreInitialPosition(List<CRectangleGDIObject> l_GDIObjects,float m_GlobalZoomNum)
  562. {
  563. for (int i = 0; i < l_GDIObjects.Count; i++)
  564. {
  565. RectangleF rectF = new RectangleF();
  566. rectF = l_GDIObjects[i].DrawRegionF;
  567. //根据样品孔中心点与样品台中心点的方向 设置宽度与高度\
  568. 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));
  569. PointF pointF = new PointF(rectF.X * m_GlobalZoomNum, rectF.Y * m_GlobalZoomNum);
  570. SizeF sizeF = new SizeF((rectF.Width * m_GlobalZoomNum), (rectF.Height * m_GlobalZoomNum));
  571. l_GDIObjects[i].RegionF = new RectangleF(pointF, sizeF);
  572. }
  573. }
  574. #endregion
  575. #region 判断当前位置是否在不规则形状里面
  576. /// <summary>
  577. /// 判断当前位置是否在不规则形状里面
  578. /// </summary>
  579. /// <param name="PointList">不规则形状坐标集合</param>
  580. /// <param name="currentMouseLocation">当前鼠标坐标</param>
  581. /// <returns></returns>
  582. public static bool PositionPnpoly(List<Point> polygonPointList, Point currentMouseLocation)
  583. {
  584. double testx = currentMouseLocation.X;
  585. double testy = currentMouseLocation.Y;
  586. int nvert = polygonPointList.Count;
  587. List<double> vertx = new List<double>();
  588. List<double> verty = new List<double>();
  589. for (int pointIndex = 0; pointIndex < polygonPointList.Count; pointIndex++)
  590. {
  591. vertx.Add(polygonPointList[pointIndex].X);
  592. verty.Add(polygonPointList[pointIndex].Y);
  593. }
  594. int i, j, c = 0;
  595. for (i = 0, j = nvert - 1; i < nvert; j = i++)
  596. {
  597. if (((verty[i] > testy) != (verty[j] > testy)) && (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i]))
  598. {
  599. c = 1 + c; ;
  600. }
  601. }
  602. if (c % 2 == 0)
  603. {
  604. return false;
  605. }
  606. else
  607. {
  608. return true;
  609. }
  610. }
  611. #endregion
  612. #region 获取多边形最小外接矩形
  613. /// <summary>
  614. /// 获取多边形最小外接矩形
  615. /// </summary>
  616. /// <param name="polygonPointList">不规则形状坐标集合</param>
  617. /// <returns></returns>
  618. public static Rectangle GetPolygonToMinRectangle(List<PointF> polygonPointList)
  619. {
  620. if (polygonPointList != null)
  621. {
  622. if (polygonPointList.Count > 0)
  623. {
  624. int pCount = polygonPointList.Count;
  625. float minX = polygonPointList[0].X;
  626. float minY = polygonPointList[0].Y;
  627. float maxX = polygonPointList[0].X;
  628. float maxY = polygonPointList[0].Y;
  629. //获取最小X,Y 最大X,Y
  630. for (int i = 0; i < pCount; i++)
  631. {
  632. minX = Math.Min(minX, polygonPointList[i].X);
  633. minY = Math.Min(minY, polygonPointList[i].Y);
  634. maxX = Math.Max(maxX, polygonPointList[i].X);
  635. maxY = Math.Max(maxY, polygonPointList[i].Y);
  636. }
  637. //创建外接矩形
  638. Rectangle rect = new Rectangle();
  639. rect.Location = new Point((int)minX, (int)minY);
  640. rect.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY);
  641. return rect;
  642. }
  643. }
  644. return new Rectangle();
  645. }
  646. #endregion
  647. #region 获取 Rectangle 外框点集合
  648. public static Point[] GetRectangleToPoint(RectangleF rectangleF)
  649. {
  650. int Left = (int)rectangleF.Left;
  651. int Top = (int)rectangleF.Top;
  652. int Right = (int)rectangleF.Right;
  653. int Bottom = (int)rectangleF.Bottom;
  654. List<Point> addPoint = new List<Point>();
  655. for (int i = Left; i <= Right; i++)
  656. {
  657. addPoint.Add(new Point(Left + 1, Top));
  658. }
  659. for (int i = Top; i <= Bottom; i++)
  660. {
  661. addPoint.Add(new Point(Right,Top + 1));
  662. }
  663. for (int i = Right; i >= Left; i--)
  664. {
  665. addPoint.Add(new Point(Right - 1, Bottom));
  666. }
  667. for (int i = Bottom; i >= Top; i--)
  668. {
  669. addPoint.Add(new Point(Left,Bottom - 1));
  670. }
  671. return addPoint.ToArray();
  672. }
  673. #endregion
  674. }
  675. }