OTSSamplespaceGraphicsPanelFun.cs 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669
  1. using OTSCLRINTERFACE;
  2. using OTSDataType;
  3. using OTSSysMgrTools;
  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. namespace OTSMeasureApp
  11. {
  12. public class OTSSamplespaceGraphicsPanelFun
  13. {
  14. #region 构造方法
  15. public OTSSamplespaceGraphicsPanelFun()
  16. {
  17. }
  18. #endregion
  19. #region 鼠标在样品台中移动获取坐标
  20. /// <summary>
  21. /// 鼠标在样品台中移动获取坐标
  22. /// </summary>
  23. public static Point GetMouseLocationInRectangleGDIObject(Point mousePoint, ARectangleGDIObject RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, int Width, int Height)
  24. {
  25. if (RectangleGDIObjects.Region.Contains(mousePoint))
  26. {
  27. Point rectLocation = RectangleGDIObjects.Region.Location;
  28. //样品台尺寸
  29. Size rectSize = RectangleGDIObjects.Region.Size;
  30. //鼠标在工作区域中的位置
  31. string x = mousePoint.X.ToString();
  32. string Y = mousePoint.Y.ToString();
  33. //样品台起始位置c
  34. string rectLocationX = rectLocation.X.ToString();
  35. string rectLocationY = rectLocation.Y.ToString();
  36. //OTS中心点
  37. string rectLocationCenterX = (rectLocation.X + rectSize.Width / 2).ToString();
  38. string rectLocationCenterY = (rectLocation.Y + rectSize.Height / 2).ToString();
  39. //OTS坐标中鼠标的位置
  40. int OTSX = -((rectLocation.X + rectSize.Width / 2) - mousePoint.X);
  41. int OTSY = -(mousePoint.Y - (rectLocation.Y + rectSize.Height / 2));
  42. //OTS坐标中鼠标的尺寸位置
  43. double OTSWidth = 0;
  44. double OTSHeight = 0;
  45. if (oTSSampleStageData != null)
  46. {
  47. //获取样品台两个坐标点
  48. ValueType XDomain = new Point(oTSSampleStageData.StageDomain.Left, oTSSampleStageData.StageDomain.Top);
  49. ValueType YDomain = new Point(oTSSampleStageData.StageDomain.Right, oTSSampleStageData.StageDomain.Bottom);
  50. //转换类型
  51. Point xDomain = ((System.Drawing.Point)XDomain);
  52. Point yDomain = ((System.Drawing.Point)YDomain);
  53. //宽度
  54. int widthDomain = Math.Abs(((Point)yDomain).X - ((Point)xDomain).X);
  55. int heightDomain = Math.Abs(((Point)yDomain).Y - ((Point)xDomain).Y);
  56. //换算鼠标在OTS坐标中的位置
  57. OTSWidth = (OTSX * ((double)widthDomain / (IsWidth == 0 ? (double)Width : (double)Height)));
  58. OTSHeight = (OTSY * ((double)widthDomain / (IsWidth == 0 ? (double)Width : (double)Height)));
  59. }
  60. Point OTSMousePosition = new Point(Convert.ToInt32(OTSWidth), Convert.ToInt32(OTSHeight));
  61. return OTSMousePosition;
  62. }
  63. return new Point(0, 0);
  64. }
  65. public static int PixelConvertToMicrons(int Pixel, int widthDomain, int length)
  66. {
  67. return Convert.ToInt32((Pixel * ((double)widthDomain / length)));
  68. }
  69. public static float PixelConvertToMicron(int Pixel, int widthDomain, int length)
  70. {
  71. return (float)(Pixel * ((double)widthDomain / length));
  72. }
  73. public static Point GetGDIObjects(Point mousePoint, ARectangleGDIObject RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, int Width, int Height)
  74. {
  75. Point rectLocation = RectangleGDIObjects.Region.Location;
  76. //样品台尺寸
  77. Size rectSize = RectangleGDIObjects.Region.Size;
  78. //鼠标在工作区域中的位置
  79. string x = mousePoint.X.ToString();
  80. string Y = mousePoint.Y.ToString();
  81. //样品台起始位置
  82. string rectLocationX = rectLocation.X.ToString();
  83. string rectLocationY = rectLocation.Y.ToString();
  84. //OTS中心点
  85. string rectLocationCenterX = (rectLocation.X + rectSize.Width / 2).ToString();
  86. string rectLocationCenterY = (rectLocation.Y + rectSize.Height / 2).ToString();
  87. //OTS坐标中鼠标的位置
  88. int OTSX = -((rectLocation.X + rectSize.Width / 2) - mousePoint.X);
  89. int OTSY = -(mousePoint.Y - (rectLocation.Y + rectSize.Height / 2));
  90. //OTS坐标中鼠标的尺寸位置
  91. int OTSWidth = 0;
  92. int OTSHeight = 0;
  93. if (oTSSampleStageData != null)
  94. {
  95. //获取样品台两个坐标点
  96. ValueType XDomain = new Point(oTSSampleStageData.StageDomain.Left, oTSSampleStageData.StageDomain.Top);
  97. ValueType YDomain = new Point(oTSSampleStageData.StageDomain.Right, oTSSampleStageData.StageDomain.Bottom);
  98. //转换类型
  99. Point xDomain = ((System.Drawing.Point)XDomain);
  100. Point yDomain = ((System.Drawing.Point)YDomain);
  101. //宽度
  102. int widthDomain = Math.Abs(((Point)yDomain).X - ((Point)xDomain).X);
  103. int heightDomain = Math.Abs(((Point)yDomain).Y - ((Point)xDomain).Y);
  104. //换算鼠标在OTS坐标中的位置
  105. if (OTSX != 0)
  106. {
  107. OTSWidth = Convert.ToInt32((OTSX * ((double)widthDomain / (IsWidth == 0 ? (double)Width : (double)Height))));
  108. OTSHeight = Convert.ToInt32((OTSY * ((double)widthDomain / (IsWidth == 0 ? (double)Width : (double)Height))));
  109. }
  110. }
  111. Point OTSPosition = new Point(0, 0);
  112. //if (OTSWidth > 0 && OTSHeight > 0)
  113. //{
  114. OTSPosition = new Point(Convert.ToInt32(OTSWidth), Convert.ToInt32(OTSHeight));
  115. //}
  116. return OTSPosition;
  117. }
  118. #region 测量区域与样品中心相差的距离
  119. /// <summary>
  120. /// 测量区域与样品中心相差的距离
  121. /// </summary>
  122. /// <param name="MeasureRectangle"></param>
  123. /// <param name="SampleRectangle"></param>
  124. /// <returns></returns>
  125. public static Point GetSampleCenterDifferCenterPoint(Rectangle MeasureRectangle, Rectangle SampleRectangle)
  126. {
  127. Point DifferCenterPoint = new Point();
  128. //获取测量区域与样品相差中心点距离
  129. DifferCenterPoint.X = (MeasureRectangle.X + MeasureRectangle.Width / 2) - (SampleRectangle.X + SampleRectangle.Width / 2);
  130. DifferCenterPoint.Y = (MeasureRectangle.Y + MeasureRectangle.Height / 2) - (SampleRectangle.Y + SampleRectangle.Height / 2);
  131. return DifferCenterPoint;
  132. }
  133. #endregion
  134. #endregion
  135. #region 处理方法总汇
  136. #region 获取中心点
  137. public static Point GetCenterPoint(ARectangleGDIObject item)
  138. {
  139. //声明中心点变量
  140. Point pCenterPoint = new Point();
  141. //获取在工作窗口中X,Y位置
  142. pCenterPoint.X = (int)(item.Region.X + item.Region.Width / 2);
  143. pCenterPoint.Y = (int)(item.Region.Y + item.Region.Height / 2);
  144. return pCenterPoint;
  145. }
  146. public static Point GetCenterPoint(Rectangle item)
  147. {
  148. //声明中心点变量
  149. Point pCenterPoint = new Point();
  150. //获取在工作窗口中X,Y位置
  151. pCenterPoint.X = item.X + item.Width / 2;
  152. pCenterPoint.Y = item.Y + item.Height / 2;
  153. return pCenterPoint;
  154. }
  155. public static PointF GetCenterPointF(RectangleF item)
  156. {
  157. //声明中心点变量
  158. PointF pCenterPoint = new Point();
  159. //获取在工作窗口中X,Y位置
  160. pCenterPoint.X = item.X + item.Width / 2;
  161. pCenterPoint.Y = item.Y + item.Height / 2;
  162. return pCenterPoint;
  163. }
  164. #endregion
  165. #region 鼠标移动位置
  166. public static ARectangleGDIObject GetMouseMoveLocation(ARectangleGDIObject item, MouseEventArgs e)
  167. {
  168. item.Region = new Rectangle(
  169. item.Region.Left + e.X - item.DraggingPoint.X,
  170. item.Region.Top + e.Y - item.DraggingPoint.Y,
  171. item.Region.Width,
  172. item.Region.Height);
  173. item.DraggingPoint = e.Location;
  174. return item;
  175. }
  176. #endregion
  177. #region 绘制帧图方法
  178. public static void DrawSingleImage(List<ARectangleGDIObject> m_SingleGDIObjects)
  179. {
  180. foreach (var item in m_SingleGDIObjects)
  181. {
  182. m_SingleGDIObjects.Add(item);
  183. }
  184. }
  185. #endregion
  186. #region 获取工作区域中心点
  187. public static Point GetWorkAreaCenterPoint(Rectangle rect)
  188. {
  189. //声明
  190. Point centerPoint = new Point();
  191. //设置X,Y坐标
  192. centerPoint.X = rect.X + rect.Width / 2;
  193. centerPoint.Y = rect.Y + rect.Height / 2;
  194. return centerPoint;
  195. }
  196. #endregion
  197. #endregion
  198. #region 鼠标方法操作
  199. public static void MouseWheelFunction(List<ARectangleGDIObject> objList, ARectangleGDIObject m_RectangleGDIObjects, float globalZoomNum)
  200. {
  201. for (int i = 0; i < objList.Count; i++)
  202. {
  203. //多边形测量区域鼠标缩放
  204. if (objList[i].Shape == (int)CreateRectangleType.Polygon)
  205. {
  206. if (objList[i].DrawPolygonPointRegionF != null)
  207. {
  208. int polygonPointCount = objList[i].DrawPolygonPointRegionF.Count;
  209. if (polygonPointCount > 0)
  210. {
  211. for (int pointIndex = 0; pointIndex < polygonPointCount; pointIndex++)
  212. {
  213. PointF wheelPoint = new PointF();
  214. wheelPoint = objList[i].DrawPolygonPointRegionF[pointIndex];
  215. float X = wheelPoint.X * globalZoomNum;
  216. float Y = wheelPoint.Y * globalZoomNum;
  217. objList[i].PolygonPointRegionF[pointIndex] = new PointF(wheelPoint.X * globalZoomNum, wheelPoint.Y * globalZoomNum);
  218. }
  219. }
  220. }
  221. }
  222. //else
  223. //{
  224. RectangleF rectF = new RectangleF();
  225. rectF = objList[i].RegionF;
  226. //根据样品孔中心点与样品台中心点的方向 设置宽度与高度\
  227. RectangleF returnRectF = OTSSamplespaceGraphicsPanelFun.MouseWheelFunctionF(m_RectangleGDIObjects, rectF, globalZoomNum);
  228. objList[i].Region = new Rectangle((int)returnRectF.X, (int)returnRectF.Y, (int)returnRectF.Width, (int)returnRectF.Height);
  229. objList[i].BSEImageWitdh = returnRectF.Width;
  230. objList[i].BSEImageHeight = returnRectF.Height;
  231. objList[i].BSEImageLocation = new PointF(returnRectF.X, returnRectF.Y);
  232. objList[i].SEMCenterPoint = returnRectF.Location;
  233. //重新绘制测量区域路径
  234. UpdateMeasureGraphicsPath(objList[i], objList[i].Region);
  235. //}
  236. }
  237. }
  238. public static RectangleF MouseWheelFunctionF(ARectangleGDIObject RectangleGDIObject, RectangleF itemRect, float globalZoomNum)
  239. {
  240. //缩放比例
  241. float X = itemRect.X * globalZoomNum;
  242. float Y = itemRect.Y * globalZoomNum;
  243. float Width = itemRect.Width * globalZoomNum;
  244. float Height = itemRect.Height * globalZoomNum;
  245. return new RectangleF(X, Y, Width, Height);
  246. }
  247. public enum EnumMousePointPosition
  248. {
  249. MouseSizeNone = 0, //'无
  250. MouseSizeRight = 1, //'拉伸右边框
  251. MouseSizeLeft = 2, //'拉伸左边框
  252. MouseSizeBottom = 3, //'拉伸下边框
  253. MouseSizeTop = 4, //'拉伸上边框
  254. MouseSizeTopLeft = 5, //'拉伸左上角
  255. MouseSizeTopRight = 6, //'拉伸右上角
  256. MouseSizeBottomLeft = 7, //'拉伸左下角
  257. MouseSizeBottomRight = 8, //'拉伸右下角
  258. MouseDrag = 9 // '鼠标拖动
  259. }
  260. const int Band = 5;
  261. public static EnumMousePointPosition MousePointPosition(Size size, Point e)
  262. {
  263. if ((e.X >= -1 * Band) | (e.X <= size.Width) | (e.Y >= -1 * Band) | (e.Y <= size.Height))
  264. {
  265. if (e.X < Band)
  266. {
  267. if (e.Y < Band) { return EnumMousePointPosition.MouseSizeTopLeft; }
  268. else
  269. {
  270. if (e.Y > -1 * Band + size.Height)
  271. { return EnumMousePointPosition.MouseSizeBottomLeft; }
  272. else
  273. { return EnumMousePointPosition.MouseSizeLeft; }
  274. }
  275. }
  276. else
  277. {
  278. if (e.X > -1 * Band + size.Width)
  279. {
  280. if (e.Y < Band)
  281. { return EnumMousePointPosition.MouseSizeTopRight; }
  282. else
  283. {
  284. if (e.Y > -1 * Band + size.Height)
  285. { return EnumMousePointPosition.MouseSizeBottomRight; }
  286. else
  287. { return EnumMousePointPosition.MouseSizeRight; }
  288. }
  289. }
  290. else
  291. {
  292. if (e.Y < Band)
  293. { return EnumMousePointPosition.MouseSizeTop; }
  294. else
  295. {
  296. if (e.Y > -1 * Band + size.Height)
  297. { return EnumMousePointPosition.MouseSizeBottom; }
  298. else
  299. { return EnumMousePointPosition.MouseDrag; }
  300. }
  301. }
  302. }
  303. }
  304. else
  305. { return EnumMousePointPosition.MouseSizeNone; }
  306. }
  307. public static EnumMousePointPosition MousePointPosition(Point point, Point e)
  308. {
  309. //MouseDrag 中心
  310. if ((e.X == point.X) && (e.Y == point.Y))
  311. {
  312. return EnumMousePointPosition.MouseDrag;
  313. }
  314. //MouseSizeTopLeft 上左
  315. if ((e.X < point.X) && (e.Y < point.Y))
  316. {
  317. return EnumMousePointPosition.MouseSizeTopLeft;
  318. }
  319. //MouseSizeTopRight 下右
  320. if ((e.X > point.X) && (e.Y < point.Y))
  321. {
  322. return EnumMousePointPosition.MouseSizeTopRight;
  323. }
  324. //MouseSizeLeft 左侧
  325. if ((e.X < point.X) && (e.Y == point.Y))
  326. {
  327. return EnumMousePointPosition.MouseSizeLeft;
  328. }
  329. //MouseSizeRight 右侧
  330. if ((e.X > point.X) && (e.Y == point.Y))
  331. {
  332. return EnumMousePointPosition.MouseSizeRight;
  333. }
  334. //MouseSizeTop 上侧
  335. if ((e.X == point.X) && (e.Y < point.Y))
  336. {
  337. return EnumMousePointPosition.MouseSizeTop;
  338. }
  339. //MouseSizeBottom 下侧
  340. if ((e.X == point.X) && (e.Y > point.Y))
  341. {
  342. return EnumMousePointPosition.MouseSizeBottom;
  343. }
  344. //MouseSizeBottomRight 下左
  345. if ((e.X < point.X) && (e.Y > point.Y))
  346. {
  347. return EnumMousePointPosition.MouseSizeBottomLeft;
  348. }
  349. //MouseSizeBottomRight 下右
  350. if ((e.X > point.X) && (e.Y > point.Y))
  351. {
  352. return EnumMousePointPosition.MouseSizeBottomRight;
  353. }
  354. return EnumMousePointPosition.MouseSizeNone;
  355. }
  356. #endregion
  357. #region 切换样品
  358. /// <summary>
  359. /// 切换样品
  360. /// </summary>
  361. /// <param name="objList">样品信息列表</param>
  362. /// <param name="stageName">样品台名称</param>
  363. public static List<ARectangleGDIObject> SelectSampleIndex(List<ARectangleGDIObject> objList, string sampleName)
  364. {
  365. ArrayList listIndex = new ArrayList();
  366. ARectangleGDIObject objItemTemp = null;
  367. objItemTemp = objList[0];
  368. for (int i = 0; i < objList.Count; i++)
  369. {
  370. if (objList[0].Name == sampleName)
  371. {
  372. listIndex.Add(i);
  373. }
  374. }
  375. for (int x = 0; x < listIndex.Count; x++)
  376. {
  377. for (int y = 0; y < objList.Count; y++)
  378. {
  379. //将第一个元素放入临时项中
  380. if (y == Convert.ToInt32(listIndex[0]))
  381. {
  382. objItemTemp = objList[0];
  383. }
  384. //如果循环至最后一个位置,则将第一个元素复制到最后一个元素位置中
  385. else if ((y) == Convert.ToInt32(listIndex[listIndex.Count - 1]))
  386. {
  387. objList[Convert.ToInt32(listIndex[0])] = objList[y];
  388. objList[y] = objItemTemp;
  389. objList[y].IsWorkSample = true;
  390. }
  391. }
  392. }
  393. return objList;
  394. }
  395. #endregion
  396. #region 根据选择的测量区域 切换至最上层
  397. public static List<ARectangleGDIObject> SelectMeasureIndexIsTop(List<ARectangleGDIObject> objList, string SampleName)
  398. {
  399. List<ARectangleGDIObject> objListTemp = objList;
  400. ARectangleGDIObject itemTemp = null;
  401. foreach (ARectangleGDIObject item in objList)
  402. {
  403. if (item.SampleName == SampleName)
  404. {
  405. //临时记录所选测量区域
  406. itemTemp = item;
  407. //删除原信息
  408. objListTemp.Remove(item);
  409. //添加新信息
  410. objListTemp.Insert(objListTemp.Count, itemTemp);
  411. break;
  412. }
  413. }
  414. return objListTemp;
  415. }
  416. #endregion
  417. #region 根据选择的样品 切换至最上层
  418. public static List<ARectangleGDIObject> SelectSampleIndexIsTop(List<ARectangleGDIObject> objList, string SampleName)
  419. {
  420. List<ARectangleGDIObject> objListTemp = objList;
  421. ARectangleGDIObject itemTemp = null;
  422. foreach (ARectangleGDIObject item in objList)
  423. {
  424. if (item.SampleName == SampleName)
  425. {
  426. //临时记录所选样品
  427. itemTemp = item;
  428. //删除原信息
  429. objListTemp.Remove(item);
  430. //添加新信息
  431. objListTemp.Insert(objListTemp.Count, itemTemp);
  432. break;
  433. }
  434. }
  435. return objListTemp;
  436. }
  437. #endregion
  438. #region 获取拍摄BSE图 将byte数组转换为图片
  439. public static Image GetBSEImage(byte[] ImageByte, int width, int height)
  440. {
  441. //图片
  442. Bitmap bitmap = null;
  443. //将byte数据转换为图片
  444. bitmap = Imagepro.ToGrayBitmap(ImageByte, width, height);
  445. return bitmap;
  446. }
  447. #endregion
  448. #region 根据对象点 与 相距的宽度 生成一个矩形
  449. /// <summary>
  450. /// 根据对象点 与 相距的宽度 生成一个矩形
  451. /// </summary>
  452. /// <param name="width"></param>
  453. /// <param name="xPoint"></param>
  454. /// <param name="yPoint"></param>
  455. /// <param name="type">0:圆角矩形 1:圆形 2:文字 3:矩形</param>
  456. /// <returns></returns>
  457. public static CreateRectangle GetPixRect(int width, Point xPoint, Point yPoint, int type, string str, string Name, int IsWidth, int Width, int Height)
  458. {
  459. try
  460. {
  461. //将微米信息 转换为 像素
  462. Point xPoints = new Point();
  463. Point yPoints = new Point();
  464. xPoints.X = (int)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
  465. xPoints.Y = (int)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
  466. yPoints.X = (int)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
  467. yPoints.Y = (int)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
  468. //计算位置
  469. xPoints = CalculateLocation(xPoints, Width, Height);
  470. yPoints = CalculateLocation(yPoints, Width, Height);
  471. //获取图形四个点
  472. int realStartX = Math.Min(xPoints.X, yPoints.X);
  473. int realStartY = Math.Min(xPoints.Y, yPoints.Y);
  474. int realEndX = Math.Max(xPoints.X, yPoints.X);
  475. int realEndY = Math.Max(xPoints.Y, yPoints.Y);
  476. //创建矩形 并返回类型对象
  477. return new CreateRectangle(realStartX, realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, str, Name);
  478. }
  479. catch (Exception)
  480. {
  481. return new CreateRectangle(new Rectangle(), 0, "");
  482. }
  483. }
  484. public static Rectangle GetPixRects(int width, Point xPoint, Point yPoint, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
  485. {
  486. try
  487. {
  488. //将微米信息 转换为 像素
  489. Point xPoints = new Point();
  490. Point yPoints = new Point();
  491. xPoints.X = (int)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
  492. xPoints.Y = (int)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
  493. yPoints.X = (int)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
  494. yPoints.Y = (int)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
  495. //计算位置
  496. xPoints = CalculateLocation(xPoints, Width, Height);
  497. //yPoints = CalculateLocation(yPoints, Width, Height);
  498. //获取图形四个点
  499. int realStartX = Math.Min(xPoints.X, yPoints.X);
  500. int realStartY = Math.Min(xPoints.Y, yPoints.Y);
  501. int realEndX = Math.Max(xPoints.X, yPoints.X);
  502. int realEndY = Math.Max(xPoints.Y, yPoints.Y);
  503. //float startX = realStartX < 0 ? 0 : realStartX;
  504. //float startY = realStartY < 0 ? 0 : realStartY;
  505. //float endX = realEndX - Math.Abs(realStartX);
  506. //float endY = endX / 4*3;
  507. //xPoint.X = startX;
  508. //xPoint.Y = startY;
  509. //yPoint.X = endX;
  510. //yPoint.Y = endY;
  511. //创建矩形 并返回类型对象
  512. return new Rectangle(xPoints.X, xPoints.Y, yPoints.X, yPoints.Y);
  513. //return new RectangleF(realStartX < 0 ? 0 : realStartX, realStartY < 0 ? 0 : realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY));
  514. }
  515. catch (Exception)
  516. {
  517. return new Rectangle();
  518. }
  519. }
  520. public static RectangleF GetPixRectF(int width, Point xPoint, Point yPoint, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
  521. {
  522. try
  523. {
  524. //将微米信息 转换为 像素
  525. PointF xPoints = new PointF();
  526. PointF yPoints = new PointF();
  527. xPoints.X = (float)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
  528. xPoints.Y = (float)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
  529. yPoints.X = (float)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
  530. yPoints.Y = (float)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
  531. //计算位置
  532. xPoints = CalculateLocationF(xPoints, Width, Height);
  533. yPoints = CalculateLocationF(yPoints, Width, Height);
  534. //创建矩形 并返回类型对象
  535. return new RectangleF(xPoints.X, xPoints.Y, Math.Abs(yPoints.X - xPoints.X), Math.Abs(yPoints.Y - xPoints.Y));
  536. }
  537. catch (Exception)
  538. {
  539. return new RectangleF();
  540. }
  541. }
  542. public static CreateRectangle GetChangeSizePixRects(int width, Point xPoint, Point yPoint, int type, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
  543. {
  544. try
  545. {
  546. //将微米信息 转换为 像素
  547. Point xPoints = new Point();
  548. Point yPoints = new Point();
  549. xPoints.X = (int)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
  550. xPoints.Y = (int)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
  551. yPoints.X = (int)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
  552. yPoints.Y = (int)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
  553. //计算位置
  554. //xPoints = CalculateLocation(xPoints, Width, Height);
  555. //yPoints = CalculateLocation(yPoints, Width, Height);
  556. //获取图形四个点
  557. int realStartX = Math.Min(xPoints.X, yPoints.X);
  558. int realStartY = Math.Min(xPoints.Y, yPoints.Y);
  559. int realEndX = Math.Max(xPoints.X, yPoints.X);
  560. int realEndY = Math.Max(xPoints.Y, yPoints.Y);
  561. //创建矩形 并返回类型对象
  562. return new CreateRectangle(realStartX < 0 ? 0 : realStartX, realStartY < 0 ? 0 : realStartY, realEndX - Math.Abs(realStartX), realEndY - Math.Abs(realStartY), type, "", "");
  563. }
  564. catch (Exception)
  565. {
  566. return new CreateRectangle(new Rectangle(), 0, "");
  567. }
  568. }
  569. public static double MillimetersToPixelsWidth(int width, double PointVal, int IsWidth, int Width, int Height)
  570. {
  571. return PointVal / ((double)width / (IsWidth == 0 ? (double)Width : (double)Height));
  572. }
  573. public static Point CalculateLocation(Point point, int Width, int Height)
  574. {
  575. //获取窗体的高度与宽度
  576. int screenWidth = Width;
  577. int screenHeight = Height;
  578. //获取屏幕中心点
  579. Point pointXY = new Point();
  580. Point screenPoint = new Point(screenWidth / 2, screenHeight / 2);
  581. pointXY.X = screenPoint.X + point.X; //(IsWidth == 0 ? screenPoint.X : screenPoint.Y) + point.X;
  582. pointXY.Y = screenPoint.Y - point.Y;
  583. return pointXY;
  584. }
  585. public static PointF CalculateLocationF(PointF point, int Width, int Height)
  586. {
  587. //获取窗体的高度与宽度
  588. int screenWidth = Width;
  589. int screenHeight = Height;
  590. //获取屏幕中心点
  591. PointF pointXY = new PointF();
  592. PointF screenPoint = new PointF(screenWidth / 2, screenHeight / 2);
  593. pointXY.X = screenPoint.X + point.X; //(IsWidth == 0 ? screenPoint.X : screenPoint.Y) + point.X;
  594. pointXY.Y = screenPoint.Y - point.Y;
  595. return pointXY;
  596. }
  597. #endregion
  598. #region 通过OTS坐标 获取工作区域图形尺寸
  599. public static void GetWorkSpaceSize(Point pStartPoint, Point pEndPoint)
  600. {
  601. int widthDomain = 0;
  602. int heightDomain = 0;
  603. //宽度
  604. widthDomain = Math.Abs(((Point)pStartPoint).X - ((Point)pEndPoint).X);
  605. heightDomain = Math.Abs(((Point)pStartPoint).Y - ((Point)pEndPoint).Y);
  606. }
  607. #endregion
  608. #region 判断是否相同
  609. /// <summary>
  610. /// 判断是否相同
  611. /// </summary>
  612. /// <param name="sampleMeasurePara"></param>
  613. /// <param name="SampleMeasureParaResult"></param>
  614. /// <returns></returns>
  615. public static bool IsValidate(OTSIncAMeasureAppForm m_MeasureAppForm, SampleMeasurePara sampleMeasurePara, SampleMeasurePara SampleMeasureParaResult)
  616. {
  617. try
  618. {
  619. if (sampleMeasurePara.sSampleName != SampleMeasureParaResult.sSampleName)
  620. {
  621. return false;
  622. }
  623. if (sampleMeasurePara.MeasureRect != SampleMeasureParaResult.MeasureRect)
  624. {
  625. return false;
  626. }
  627. if (sampleMeasurePara.sHoleName != SampleMeasureParaResult.sHoleName)
  628. {
  629. return false;
  630. }
  631. return true;
  632. }
  633. catch (Exception)
  634. {
  635. return false;
  636. }
  637. }
  638. #endregion
  639. #region 获取工作样品信息
  640. /// <summary>
  641. /// 获取工作样品信息
  642. /// </summary>
  643. /// <param name="sampleName"></param>
  644. /// <returns></returns>
  645. public static ARectangleGDIObject GetWorkSample(string sampleName)
  646. {
  647. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  648. {
  649. if (itemSample.SampleName == sampleName)
  650. {
  651. return itemSample;
  652. }
  653. }
  654. return null;
  655. }
  656. #endregion
  657. #region 获取测量区域
  658. /// <summary>
  659. /// 获取测量区域
  660. /// </summary>
  661. /// <param name="m_MeasureAppForm"></param>
  662. /// <param name="sampleName"></param>
  663. /// <returns></returns>
  664. public static SampleMeasurePara GetMeasureInfo(OTSIncAMeasureAppForm m_MeasureAppForm, string sampleName, ARectangleGDIObject item, ARectangleGDIObject m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int wDomain, int w)
  665. {
  666. SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
  667. foreach (ARectangleGDIObject measureItem in OTSSamplespaceWindow.m_MeasureGDIObjects)
  668. {
  669. if (sampleName == measureItem.SampleName)
  670. {
  671. //设置测量区域位置与尺寸
  672. float left = 0;
  673. float Top = 0;
  674. float Right = 0;
  675. float Bottom = 0;
  676. float Widths = 0;
  677. float Height = 0;
  678. //设置测量区域位置与尺寸
  679. left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.X, wDomain, w);
  680. Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Y, wDomain, w);
  681. Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Right, wDomain, w);
  682. Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Bottom, wDomain, w);
  683. Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Width, wDomain, w);
  684. Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Height, wDomain, w);
  685. //保存原位置
  686. RectangleF polygonRectPara = measureItem.DrawRegionF;
  687. if (measureItem.CreateType == (int)CreateRectangleType.Polygon)
  688. {
  689. polygonRectPara = GetPolygonToMinRectangle(measureItem.DrawPolygonPointRegionF);
  690. //设置测量区域位置与尺寸
  691. left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.X, wDomain, w);
  692. Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Y, wDomain, w);
  693. Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Right, wDomain, w);
  694. Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Bottom, wDomain, w);
  695. Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Width, wDomain, w);
  696. Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Height, wDomain, w);
  697. }
  698. //设置测量区域
  699. PointF startPoint = new PointF(left, Top);
  700. SizeF MeasureSize = new SizeF(Widths, Height);
  701. sampleMeasurePara.MeasureRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)MeasureSize.Width, (int)MeasureSize.Height));
  702. //设置样品孔名称
  703. sampleMeasurePara.sHoleName = item.Name;
  704. //设置样品名称
  705. sampleMeasurePara.sSampleName = item.SampleName;
  706. //设置测量区域形状
  707. sampleMeasurePara.iShape = item.Shape;
  708. //设置多边形点集合
  709. sampleMeasurePara.PolygonPointRegion = PointFConvertPoint(GetPolygonPointToOTSPoint(item.PolygonPointRegionF, wDomain, w));
  710. sampleMeasurePara.PolygonPointRegionF = GetPolygonPointToOTSPoint(item.PolygonPointRegionF, wDomain, w);
  711. sampleMeasurePara.DrawPolygonPointRegionF = GetPolygonPointToOTSPoint(item.DrawPolygonPointRegionF, wDomain, w);
  712. break;
  713. }
  714. }
  715. return sampleMeasurePara;
  716. }
  717. public static SampleHolePara GetSampleHoleInfo(OTSIncAMeasureAppForm m_MeasureAppForm, string sampleHoleName, ARectangleGDIObject item, ARectangleGDIObject m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int wDomain, int w)
  718. {
  719. SampleHolePara sampleHolePara = new SampleHolePara();
  720. foreach (ARectangleGDIObject sampleHoleItem in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
  721. {
  722. if (sampleHoleName == sampleHoleItem.Name)
  723. {
  724. //保存原位置
  725. Rectangle rectPara = sampleHoleItem.Region;
  726. //设置测量区域
  727. sampleHolePara.SampleHoleRect = sampleHoleItem.Region;
  728. //设置测量区域位置与尺寸
  729. float left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.X, wDomain, w);
  730. float Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Y, wDomain, w);
  731. float Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Right, wDomain, w);
  732. float Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Bottom, wDomain, w);
  733. float Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Width, wDomain, w);
  734. float Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Height, wDomain, w);
  735. //Size sizeRegion = new Size(PointRB);
  736. PointF startPoint = new PointF(left, Top);
  737. SizeF sampleHoleSize = new SizeF(Widths, Height);
  738. sampleHolePara.SampleHoleRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)sampleHoleSize.Width, (int)sampleHoleSize.Height));
  739. //设置样品孔名称
  740. sampleHolePara.sHoleName = item.Name;
  741. //设置测量区域形状
  742. sampleHolePara.iShape = item.Shape;
  743. break;
  744. }
  745. }
  746. return sampleHolePara;
  747. }
  748. #endregion
  749. #region 获取工作样品的测量区域信息
  750. /// <summary>
  751. /// 获取工作样品的测量区域信息
  752. /// </summary>
  753. /// <returns></returns>
  754. public static Rectangle GetWorkMeasure(OTSIncAMeasureAppForm m_MeasureAppForm, ARectangleGDIObject m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int wDomain, int w)
  755. {
  756. foreach (ARectangleGDIObject itemMeasure in OTSSamplespaceWindow.m_MeasureGDIObjects)
  757. {
  758. if (itemMeasure.IsWorkSample)
  759. {
  760. Point startPoint = new Point(itemMeasure.Region.Left, itemMeasure.Region.Top);
  761. Point endPoint = new Point(itemMeasure.Region.Right, itemMeasure.Region.Bottom);
  762. SampleMeasurePara rectMaesure = GetMeasureInfo(m_MeasureAppForm, itemMeasure.SampleName, itemMeasure, m_RectangleGDIObjects, oTSSampleStageData, wDomain, w);
  763. return rectMaesure.MeasureRect;
  764. }
  765. }
  766. return new Rectangle();
  767. }
  768. #endregion
  769. #region 删除样品弹出提示
  770. public static bool ShowDeleteDialog(string sampleName)
  771. {
  772. //国际化
  773. OTSSysMgrTools.Language lan = new OTSSysMgrTools.Language();
  774. Hashtable table = lan.GetNameTable("OTSIncAMeasureAppForm");
  775. string str1 = table["message5"].ToString();
  776. string str2 = table["message6"].ToString();
  777. string sDeleteSampleName = str1;
  778. sDeleteSampleName += sampleName;
  779. sDeleteSampleName += " 信息 ?";
  780. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Delete sample information prompt", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  781. {
  782. return true;
  783. }
  784. else
  785. {
  786. return false;
  787. }
  788. }
  789. #endregion
  790. #region 将点转换至工作区域
  791. public void PointToClient(Point rect)
  792. {
  793. this.PointToClient(rect);
  794. }
  795. #endregion
  796. #region 删除样品 同时删除帧图
  797. public static bool DeleteSampleInfo(OTSIncAMeasureAppForm m_MeasureAppForm, string sampleSelectName)
  798. {
  799. try
  800. {
  801. //提交主窗体响应
  802. bool deleteResult = false;
  803. if (OTSSamplespaceGraphicsPanelFun.ShowDeleteDialog(sampleSelectName))
  804. {
  805. //设置当前状态
  806. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  807. deleteResult = m_MeasureAppForm.DeleteSample(sampleSelectName);
  808. if (deleteResult)
  809. {
  810. //样品对象列表中无样品信息 则清除帧图对象列表信息
  811. bool result = m_MeasureAppForm.m_SamplepaceWindow.SampleIsEmptyClearSingleInfo();
  812. if(result)
  813. {
  814. m_MeasureAppForm.m_MeasureRetWindow.SetInit();
  815. }
  816. }
  817. }
  818. return true;
  819. }
  820. catch (Exception)
  821. {
  822. return false;
  823. }
  824. }
  825. #endregion
  826. #region 计算两个点之间的距离 (图形与鼠标点击获取的点)
  827. public static Point StartToEndPointDist(ARectangleGDIObject m_RectangleGDIObjects, Point regionStartPoint)
  828. {
  829. Point differentPoint = new Point();
  830. //获取点击后的样品台位置
  831. Point m_Region = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects.Region);
  832. //获取鼠标按下的位置
  833. Point regionEndPoint = m_Region;
  834. //获取鼠标按下与抬起 位置差值
  835. differentPoint.X = regionEndPoint.X - regionStartPoint.X;
  836. differentPoint.Y = regionEndPoint.Y - regionStartPoint.Y;
  837. return differentPoint;
  838. }
  839. #endregion
  840. #region 计算两个点之间的距离 (图形中心与屏幕中心相差的距离)
  841. public static Point RegionCenterToScreenCenterDist(ARectangleGDIObject regionCneter, Point screenCneter)
  842. {
  843. Point differentPoint = new Point();
  844. //获取图形中心位置
  845. Rectangle rectangle = new Rectangle();
  846. rectangle.X = (int)regionCneter.RegionF.X;
  847. rectangle.Y = (int)regionCneter.RegionF.Y;
  848. rectangle.Width = (int)regionCneter.RegionF.Width;
  849. rectangle.Height = (int)regionCneter.RegionF.Height;
  850. Point m_RegionCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(rectangle);
  851. //获取图形中心与屏幕中心相差的距离
  852. differentPoint.X = m_RegionCenter.X - screenCneter.X;
  853. differentPoint.Y = m_RegionCenter.Y - screenCneter.Y;
  854. return differentPoint;
  855. }
  856. #endregion
  857. #region 清除List中所有信息
  858. public static List<ARectangleGDIObject> ListClear(List<ARectangleGDIObject> ListObject)
  859. {
  860. if (ListObject != null)
  861. {
  862. if (ListObject.Count > 0)
  863. {
  864. ListObject.Clear();
  865. }
  866. }
  867. return ListObject;
  868. }
  869. #endregion
  870. #region 根据颜色枚举 获取颜色值
  871. public static string GetColorValue(ColorType ColorEnum)
  872. {
  873. string ColorStr = string.Empty;
  874. switch (ColorEnum)
  875. {
  876. case ColorType.SingleColor:
  877. ColorStr = "#fd8f8f";//帧图fd8f8f
  878. break;
  879. case ColorType.RoundRectangleColor:
  880. ColorStr = "#c8c8c8";//c8c8c8圆角矩形
  881. break;
  882. case ColorType.FontColor:
  883. ColorStr = "#90ee90";//90ee90文字颜色
  884. break;
  885. case ColorType.SampleColor:
  886. ColorStr = "#f4f4f4";//f4f4f4 样品未选择
  887. break;
  888. case ColorType.SampleSelColor:
  889. ColorStr = "#505050";//505050 样品选择后
  890. break;
  891. }
  892. return ColorStr;
  893. }
  894. #endregion
  895. #region 获取测量区域的位置
  896. public static SampleMeasurePara GetSampleMeasureRect(ARectangleGDIObject MeasureItem, OTSIncAMeasureAppForm m_MeasureAppForm, StageDrawingData oTSSampleStageData, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
  897. {
  898. int w = (IsWidth == 0 ? Width : Height);
  899. int iShape = 0;
  900. Rectangle Srect = new Rectangle();
  901. SampleMeasurePara sampleMeasureParas = new SampleMeasurePara();
  902. //获取当前工作的测量区域信息
  903. bool returnResult = m_MeasureAppForm.m_ProjParam.GetWSampleMrsArea(ref iShape, ref Srect);
  904. if (returnResult)
  905. {
  906. //获取测量区域的OTS位置与尺寸
  907. sampleMeasureParas = OTSSamplespaceGraphicsPanelFun.GetMeasureInfo(m_MeasureAppForm, MeasureItem.SampleName, MeasureItem, m_RectangleGDIObjects, oTSSampleStageData, wDomain, w);
  908. //获取工作区域位置与尺寸
  909. Rectangle WorkAreaRect = new Rectangle(0, 0, Width, Height);
  910. //获取工作区域 中心点
  911. Point ScreenPointCenter = OTSSamplespaceGraphicsPanelFun.GetWorkAreaCenterPoint(WorkAreaRect);
  912. //获取样品台 中心点
  913. PointF RectanglePointCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPointF(m_RectangleGDIObjects.RegionF);
  914. //获取屏幕中心点
  915. float WorkAreaCenterPointX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.X, wDomain, w);
  916. float WorkAreaCenterPointY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.Y, wDomain, w);
  917. //获取样品台中心点
  918. float CenterX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.X, wDomain, w);
  919. float CenterY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.Y, wDomain, w);
  920. Rectangle sampleMeasureRect = new Rectangle();
  921. //根据屏幕中心点获取移动后样品台中心点的偏移位置
  922. //sampleMeasureRect.X = -(WorkAreaCenterPointX - sampleMeasureParas.MeasureRect.X);
  923. //sampleMeasureRect.Y = WorkAreaCenterPointY - sampleMeasureParas.MeasureRect.Bottom;
  924. //根据样品台中心点获取开始点位置
  925. sampleMeasureRect.X = -((int)CenterX - sampleMeasureParas.MeasureRect.X);
  926. sampleMeasureRect.Y = (int)CenterY - sampleMeasureParas.MeasureRect.Bottom;
  927. sampleMeasureParas.MeasureRect.X = sampleMeasureRect.X;
  928. sampleMeasureParas.MeasureRect.Y = sampleMeasureRect.Y;
  929. for (int i = 0; i < sampleMeasureParas.DrawPolygonPointRegionF.Count; i++)
  930. {
  931. int X = -((int)CenterX - (int)sampleMeasureParas.DrawPolygonPointRegionF[i].X);
  932. int Y = (int)CenterY - (int)sampleMeasureParas.DrawPolygonPointRegionF[i].Y;
  933. //sampleMeasureParas.PolygonPointRegion[i] = new Point(X, Y);
  934. sampleMeasureParas.DrawPolygonPointRegionF[i] = new Point(X, Y);
  935. }
  936. }
  937. return sampleMeasureParas;
  938. }
  939. public static SampleHolePara GetSampleHoleRect(ARectangleGDIObject sampleHoleItem, OTSIncAMeasureAppForm m_MeasureAppForm, StageDrawingData oTSSampleStageData, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
  940. {
  941. int w = (IsWidth == 0 ? Width : Height);
  942. SampleHolePara sampleHoleParas = new SampleHolePara();
  943. //获取样品孔的OTS位置与尺寸
  944. sampleHoleParas = OTSSamplespaceGraphicsPanelFun.GetSampleHoleInfo(m_MeasureAppForm, sampleHoleItem.Name, sampleHoleItem, m_RectangleGDIObjects, oTSSampleStageData, wDomain, w);
  945. //获取工作区域位置与尺寸
  946. Rectangle WorkAreaRect = new Rectangle(0, 0, Width, Height);
  947. //获取工作区域 中心点
  948. Point ScreenPointCenter = OTSSamplespaceGraphicsPanelFun.GetWorkAreaCenterPoint(WorkAreaRect);
  949. //获取样品台 中心点
  950. PointF RectanglePointCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPointF(m_RectangleGDIObjects.RegionF);
  951. //获取屏幕中心点
  952. float WorkAreaCenterPointX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.X, wDomain, w);
  953. float WorkAreaCenterPointY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.Y, wDomain, w);
  954. //获取样品台中心点
  955. float CenterX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.X, wDomain, w);
  956. float CenterY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.Y, wDomain, w);
  957. Rectangle sampleHoleRect = new Rectangle();
  958. //根据样品台中心点获取开始点位置
  959. sampleHoleRect.X = -((int)CenterX - sampleHoleParas.SampleHoleRect.X);
  960. sampleHoleRect.Y = (int)CenterY - sampleHoleParas.SampleHoleRect.Bottom;
  961. sampleHoleParas.SampleHoleRect.X = sampleHoleRect.X;
  962. sampleHoleParas.SampleHoleRect.Y = sampleHoleRect.Y;
  963. return sampleHoleParas;
  964. }
  965. #endregion
  966. #region //设置测量区域信息(位置与大小)
  967. public static bool SetWorkSamplHoleAndMeasureArea(ARectangleGDIObject MeasureItem, OTSIncAMeasureAppForm m_MeasureAppForm, StageDrawingData oTSSampleStageData, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
  968. {
  969. //获取工作样品中的测量区域
  970. SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
  971. //设置测量区域位置
  972. //获取修改后的测量区域的位置与尺寸
  973. sampleMeasurePara = GetSampleMeasureRect(MeasureItem, m_MeasureAppForm, oTSSampleStageData, m_RectangleGDIObjects, IsWidth, Width, Height, wDomain);
  974. sampleMeasurePara.sHoleName = MeasureItem.Name;
  975. sampleMeasurePara.sSampleName = MeasureItem.SampleName;
  976. //设置测量区域信息(位置与大小)
  977. SampleMeasurePara SampleMeasureParaResult = m_MeasureAppForm.SetWorkSamplHoleAndMeasureArea(sampleMeasurePara);
  978. if (OTSSamplespaceGraphicsPanelFun.IsValidate(m_MeasureAppForm, sampleMeasurePara, SampleMeasureParaResult))
  979. {
  980. return true;
  981. }
  982. return false;
  983. }
  984. #endregion
  985. #region 根据list中的帧图信息 获取中心位置
  986. public static PointF GetSingleCenterLocation(List<ARectangleGDIObject> m_SingleGDIObjects)
  987. {
  988. float MinX = 0f;
  989. float MinY = 0f;
  990. float MaxX = 0f;
  991. float MaxY = 0f;
  992. float width = 0f;
  993. float height = 0f;
  994. //获取最小XY 与最大XY
  995. MinX = m_SingleGDIObjects[0].RegionF.X;
  996. MinY = m_SingleGDIObjects[0].RegionF.Y;
  997. MaxX = m_SingleGDIObjects[0].RegionF.X;
  998. MaxY = m_SingleGDIObjects[0].RegionF.Y;
  999. width = m_SingleGDIObjects[0].RegionF.Width;
  1000. height = m_SingleGDIObjects[0].RegionF.Height;
  1001. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  1002. {
  1003. MinX = Math.Min(m_SingleGDIObjects[i].RegionF.X, MinX);
  1004. MinY = Math.Min(m_SingleGDIObjects[i].RegionF.Y, MinY);
  1005. MaxX = Math.Max(m_SingleGDIObjects[i].RegionF.X, MaxX);
  1006. MaxY = Math.Max(m_SingleGDIObjects[i].RegionF.Y, MaxY);
  1007. }
  1008. //获取帧图的外框矩形
  1009. RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX- MinX+ width, MaxY- MinY+ height);
  1010. //计算外框矩形的中心点
  1011. float PointFX = SingleRect.X + SingleRect.Width / 2;
  1012. float PointFY = SingleRect.Y + SingleRect.Height / 2;
  1013. PointF SingleCenterPoint = new PointF(PointFX, PointFY);
  1014. return SingleCenterPoint;
  1015. }
  1016. public static PointF GetSingleDrawCenterLocation(List<ARectangleGDIObject> m_SingleGDIObjects)
  1017. {
  1018. float MinX = 0f;
  1019. float MinY = 0f;
  1020. float MaxX = 0f;
  1021. float MaxY = 0f;
  1022. float width = 0f;
  1023. float height = 0f;
  1024. //获取最小XY 与最大XY
  1025. MinX = m_SingleGDIObjects[0].DrawRegionF.X;
  1026. MinY = m_SingleGDIObjects[0].DrawRegionF.Y;
  1027. MaxX = m_SingleGDIObjects[0].DrawRegionF.X;
  1028. MaxY = m_SingleGDIObjects[0].DrawRegionF.Y;
  1029. width = m_SingleGDIObjects[0].DrawRegionF.Width;
  1030. height = m_SingleGDIObjects[0].DrawRegionF.Height;
  1031. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  1032. {
  1033. MinX = Math.Min(m_SingleGDIObjects[i].DrawRegionF.X, MinX);
  1034. MinY = Math.Min(m_SingleGDIObjects[i].DrawRegionF.Y, MinY);
  1035. MaxX = Math.Max(m_SingleGDIObjects[i].DrawRegionF.X, MaxX);
  1036. MaxY = Math.Max(m_SingleGDIObjects[i].DrawRegionF.Y, MaxY);
  1037. }
  1038. //获取帧图的外框矩形
  1039. RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX - MinX + width, MaxY - MinY + height);
  1040. //计算外框矩形的中心点
  1041. float PointFX = SingleRect.X + SingleRect.Width / 2;
  1042. float PointFY = SingleRect.Y + SingleRect.Height / 2;
  1043. PointF SingleCenterPoint = new PointF(PointFX, PointFY);
  1044. return SingleCenterPoint;
  1045. }
  1046. #endregion
  1047. #region 将所有帧图移植测量区域位置
  1048. public static void SetSingleLocationToMeasureLocation(List<ARectangleGDIObject> m_ObjectListGDIObjects, ARectangleGDIObject m_ObjectGDIObjects)
  1049. {
  1050. //获取帧图中心与测量区域中心
  1051. PointF singleCenterPoinF= GetSingleCenterLocation(m_ObjectListGDIObjects);
  1052. PointF singleDrawCenterPoinF = GetSingleDrawCenterLocation(m_ObjectListGDIObjects);
  1053. //测量区域 已改变为倍数的尺寸 中心点
  1054. PointF measureCenterPoin = GetCenterPointF(m_ObjectGDIObjects.Region);
  1055. //测量区域 正常尺寸 中心点
  1056. PointF measureCenterPoinF = GetCenterPointF(m_ObjectGDIObjects.RegionF);
  1057. //计算相差的XY距离
  1058. float moveX = measureCenterPoin.X - singleCenterPoinF.X;
  1059. float moveY = measureCenterPoin.Y - singleCenterPoinF.Y;
  1060. float moveFX = measureCenterPoinF.X - singleDrawCenterPoinF.X;
  1061. float moveFY = measureCenterPoinF.Y - singleDrawCenterPoinF.Y;
  1062. //需要移动的位置
  1063. PointF movePoint = new PointF(moveX, moveY);
  1064. PointF movePointF = new PointF(moveFX, moveFY);
  1065. foreach (var ObjectItem in m_ObjectListGDIObjects)
  1066. {
  1067. //计算移动后的位置
  1068. float X = ObjectItem.RegionF.X + movePoint.X;
  1069. float Y = ObjectItem.RegionF.Y + movePoint.Y;
  1070. float Width = ObjectItem.RegionF.Width;
  1071. float Height = ObjectItem.RegionF.Height;
  1072. ObjectItem.Region = new Rectangle((int)X, (int)Y, (int)Width, (int)Height);
  1073. ObjectItem.RegionF = new RectangleF(X, Y, Width, Height);
  1074. ObjectItem.DrawRegionF = new RectangleF(ObjectItem.DrawRegionF.X + movePointF.X, ObjectItem.DrawRegionF.Y + movePointF.Y, ObjectItem.DrawRegionF.Width, ObjectItem.DrawRegionF.Height);
  1075. }
  1076. }
  1077. #endregion
  1078. /// <summary>
  1079. /// 获取XML中电镜的选项
  1080. /// </summary>
  1081. #region 测量区域中心移动至SEM当前位置
  1082. /// <summary>
  1083. /// 测量区域中心移动至SEM当前位置
  1084. /// </summary>
  1085. /// <param name="m_SamplespaceWindow">样品台窗体对象</param>
  1086. /// <param name="mouseLocation">当前鼠标的位置</param>
  1087. public static void NewLocationDrawMeasureInfo(OTSSamplespaceWindow m_SamplespaceWindow, List<ARectangleGDIObject> m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, Point moveToSEMLocation, List<ARectangleGDIObject> UpdateLocationGDIObject,float m_GlobalZoomNum)
  1088. {
  1089. //样品台中心点位置
  1090. Point m_StageCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0]);
  1091. //当前与中心点相差距离
  1092. int m_StageCenterDiffX = 0;
  1093. int m_StageCenterDiffY = 0;
  1094. int diffNewX = 0;
  1095. int diffNewY = 0;
  1096. Point m_UpdateCenterPoint = new Point();
  1097. foreach (var item in UpdateLocationGDIObject)
  1098. {
  1099. if(item.IsWorkSample)
  1100. {
  1101. m_UpdateCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(item);
  1102. m_StageCenterDiffX = (int)((m_StageCenterPoint.X - m_UpdateCenterPoint.X) * 1);
  1103. m_StageCenterDiffY = (int)((m_StageCenterPoint.Y - m_UpdateCenterPoint.Y) * 1);
  1104. diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum);
  1105. diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum);
  1106. //根据鼠标_更改测量区域的位置
  1107. 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));
  1108. 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));
  1109. item.DrawRegionF = item.RegionF;
  1110. //修改多边形的绘制点集合
  1111. if (item.CreateType == (int)CreateRectangleType.Polygon)
  1112. {
  1113. for (int i = 0; i < item.PolygonPointRegion.Count; i++)
  1114. {
  1115. item.PolygonPointRegion[i] = new Point(item.PolygonPointRegion[i].X + m_StageCenterDiffX + diffNewX, item.PolygonPointRegion[i].Y + m_StageCenterDiffY - diffNewY);
  1116. item.PolygonPointRegionF[i] = new PointF(item.PolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX), item.PolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY));
  1117. item.DrawPolygonPointRegionF[i] = new PointF(item.DrawPolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.DrawPolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum);
  1118. }
  1119. }
  1120. }
  1121. }
  1122. }
  1123. public static bool NewLocationDrawSingleInfo(OTSIncAMeasureAppForm m_MeasureAppForm, OTSSamplespaceWindow m_SamplespaceWindow, List<ARectangleGDIObject> m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, Point moveToSEMLocation, List<ARectangleGDIObject> UpdateLocationGDIObject, ARectangleGDIObject WorkMeasure, float m_GlobalZoomNum)
  1124. {
  1125. //样品台中心点位置
  1126. Point m_StageCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0]);
  1127. //当前与中心点相差距离
  1128. int m_StageCenterDiffX = 0;
  1129. int m_StageCenterDiffY = 0;
  1130. Point m_WorkMeasureCenterPoint = new Point();
  1131. if (UpdateLocationGDIObject == null)
  1132. {
  1133. return false;
  1134. }
  1135. int diffNewX = 0;
  1136. int diffNewY = 0;
  1137. bool IsOK = true;
  1138. diffNewX = moveToSEMLocation.X;
  1139. diffNewY = moveToSEMLocation.Y;
  1140. if (IsOK)
  1141. {
  1142. foreach (var item in UpdateLocationGDIObject)
  1143. {
  1144. m_WorkMeasureCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(WorkMeasure);
  1145. m_StageCenterDiffX = m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X;//(int)((m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X) * m_GlobalZoomNum);
  1146. m_StageCenterDiffY = m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y;// (int)((m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y) * m_GlobalZoomNum);
  1147. diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum);
  1148. diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum);
  1149. //根据鼠标_更改测量区域的位置
  1150. 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));
  1151. 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));
  1152. 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));
  1153. }
  1154. }
  1155. return IsOK;
  1156. }
  1157. #endregion
  1158. #region 通过样品孔名称 获取在列表中的索引
  1159. /// <summary>
  1160. /// 通过样品孔名称 获取在列表中的索引
  1161. /// </summary>
  1162. /// <param name="oTSSampleStageData">样品台文件</param>
  1163. /// <param name="sampleHoleName">样品孔名称</param>
  1164. /// <returns></returns>
  1165. public static int GetSampleHoleIndex(StageDrawingData oTSSampleStageData,string sampleHoleName, ref OTSSampleHoleInfo sampleHoleInfo)
  1166. {
  1167. try
  1168. {
  1169. int sampleHoleIndex = -1;
  1170. if (oTSSampleStageData.sSHoleInfoList.Count > 0)
  1171. {
  1172. for (int i = 0; i < oTSSampleStageData.sSHoleInfoList.Count; i++)
  1173. {
  1174. if (oTSSampleStageData.sSHoleInfoList[i].sSHoleName == sampleHoleName)
  1175. {
  1176. sampleHoleInfo = oTSSampleStageData.sSHoleInfoList[i];
  1177. sampleHoleIndex = i;
  1178. break;
  1179. }
  1180. }
  1181. }
  1182. return sampleHoleIndex;
  1183. }
  1184. catch (Exception)
  1185. {
  1186. return -1;
  1187. }
  1188. }
  1189. #endregion
  1190. #region 添加帧图信息
  1191. /// <summary>
  1192. /// 添加帧图信息
  1193. /// </summary>
  1194. /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
  1195. /// <param name="m_SingleGDIObjects">帧图对象列表</param>
  1196. /// <param name="sampleName">样品名称</param>
  1197. /// <returns></returns>
  1198. public static bool AddALLSingleInfo(List<ARectangleGDIObject> m_ALLSingleGDIObjects, List<ARectangleGDIObject> m_SingleGDIObjects, string sampleName)
  1199. {
  1200. bool result = false;
  1201. //判断ALLSingle对象列表中是否为空
  1202. if (m_ALLSingleGDIObjects != null)
  1203. {
  1204. bool IsExist = true;
  1205. if (m_ALLSingleGDIObjects.Count > 0)
  1206. {
  1207. //判断是否包含样品名称
  1208. foreach (var item in m_ALLSingleGDIObjects)
  1209. {
  1210. if (item.SampleName.Equals(sampleName))
  1211. {
  1212. IsExist = false;
  1213. break;
  1214. }
  1215. }
  1216. }
  1217. if (IsExist)
  1218. {
  1219. result = true;
  1220. foreach (var item in m_SingleGDIObjects)
  1221. {
  1222. m_ALLSingleGDIObjects.Add(item);
  1223. }
  1224. }
  1225. return result;
  1226. }
  1227. return result;
  1228. }
  1229. #endregion
  1230. #region 删除帧图信息
  1231. /// <summary>
  1232. /// 删除帧图信息
  1233. /// </summary>
  1234. /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
  1235. /// <param name="sampleName">样品名称</param>
  1236. /// <returns></returns>
  1237. public static bool DeleteALLSingleInfo(List<ARectangleGDIObject> m_ALLSingleGDIObjects, string sampleName)
  1238. {
  1239. bool result = false;
  1240. int resultCount = 0;
  1241. //判断ALLSingle对象列表中是否为空
  1242. if (m_ALLSingleGDIObjects != null)
  1243. {
  1244. if (m_ALLSingleGDIObjects.Count > 0)
  1245. {
  1246. for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
  1247. {
  1248. if (m_ALLSingleGDIObjects[i].SampleName.Equals(sampleName))
  1249. {
  1250. m_ALLSingleGDIObjects.RemoveAt(i);
  1251. resultCount++;
  1252. }
  1253. }
  1254. }
  1255. else
  1256. {
  1257. result = true;
  1258. }
  1259. if (resultCount > 0)
  1260. {
  1261. result = true;
  1262. }
  1263. }
  1264. return result;
  1265. }
  1266. #endregion
  1267. #region 切换样品 填充帧图信息
  1268. public static void ChangeSampleFillSingleInfo(List<ARectangleGDIObject> m_ALLSingleGDIObjects, List<ARectangleGDIObject> m_SingleGDIObjects, string sampleName)
  1269. {
  1270. //判断帧图对象中是否存在当前工作样品帧图信息
  1271. bool IsExist = true;
  1272. //判断ALLSingle对象列表中是否为空
  1273. if (m_ALLSingleGDIObjects != null)
  1274. {
  1275. if (m_ALLSingleGDIObjects.Count > 0)
  1276. {
  1277. foreach (var item in m_SingleGDIObjects)
  1278. {
  1279. if (item.SampleName.Equals(sampleName))
  1280. {
  1281. IsExist = false;
  1282. }
  1283. }
  1284. if (IsExist)
  1285. {
  1286. //判断是否包含样品名称
  1287. foreach (var item in m_ALLSingleGDIObjects)
  1288. {
  1289. if (item.SampleName.Equals(sampleName))
  1290. {
  1291. m_SingleGDIObjects.Add(item);
  1292. }
  1293. }
  1294. }
  1295. }
  1296. }
  1297. }
  1298. #endregion
  1299. #region 修改已存在的帧图中样品名称
  1300. public static void EditWorkSampleName(List<ARectangleGDIObject> m_ALLSingleGDIObjects, string oldSampleName, string newSampleName)
  1301. {
  1302. int resultCount = 0;
  1303. //判断ALLSingle对象列表中是否为空
  1304. if (m_ALLSingleGDIObjects != null)
  1305. {
  1306. if (m_ALLSingleGDIObjects.Count > 0)
  1307. {
  1308. for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
  1309. {
  1310. if (m_ALLSingleGDIObjects[i].SampleName.Equals(oldSampleName))
  1311. {
  1312. m_ALLSingleGDIObjects[i].SampleName = newSampleName;
  1313. resultCount++;
  1314. }
  1315. }
  1316. }
  1317. }
  1318. }
  1319. #endregion
  1320. #region 修改测量区域中GraphicsPath属性
  1321. public static void UpdateMeasureGraphicsPath(ARectangleGDIObject measureItem, Rectangle rectPara)
  1322. {
  1323. //重新绘制测量区域路径
  1324. GraphicsPath GPath = new GraphicsPath();
  1325. if (measureItem.CreateType == (int)CreateRectangleType.Polygon)
  1326. {
  1327. GraphicsPath PolygonMeasurePath = new GraphicsPath();
  1328. PolygonMeasurePath.AddPolygon(measureItem.PolygonPointRegionF.ToArray());
  1329. GPath = PolygonMeasurePath;
  1330. }
  1331. else
  1332. {
  1333. if (measureItem.Shape == (int)CreateRectangleType.Circle)
  1334. {
  1335. GPath.AddEllipse(rectPara);
  1336. }
  1337. else
  1338. {
  1339. GPath.AddRectangle(rectPara);
  1340. }
  1341. }
  1342. measureItem.GPath = GPath;
  1343. }
  1344. #endregion
  1345. #region OnMouseWheel
  1346. public static void RecoverInitialPosition(List<ARectangleGDIObject> l_GDIObjects,float m_GlobalZoomNum)
  1347. {
  1348. for (int i = 0; i < l_GDIObjects.Count; i++)
  1349. {
  1350. RectangleF rectF = new RectangleF();
  1351. rectF = l_GDIObjects[i].DrawRegionF;
  1352. //根据样品孔中心点与样品台中心点的方向 设置宽度与高度\
  1353. 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));
  1354. PointF pointF = new PointF(rectF.X * m_GlobalZoomNum, rectF.Y * m_GlobalZoomNum);
  1355. SizeF sizeF = new SizeF((rectF.Width * m_GlobalZoomNum), (rectF.Height * m_GlobalZoomNum));
  1356. l_GDIObjects[i].RegionF = new RectangleF(pointF, sizeF);
  1357. }
  1358. }
  1359. #endregion
  1360. #region 判断当前位置是否在不规则形状里面
  1361. /// <summary>
  1362. /// 判断当前位置是否在不规则形状里面
  1363. /// </summary>
  1364. /// <param name="PointList">不规则形状坐标集合</param>
  1365. /// <param name="currentMouseLocation">当前鼠标坐标</param>
  1366. /// <returns></returns>
  1367. public static bool PositionPnpoly(List<Point> polygonPointList, Point currentMouseLocation)
  1368. {
  1369. double testx = currentMouseLocation.X;
  1370. double testy = currentMouseLocation.Y;
  1371. int nvert = polygonPointList.Count;
  1372. List<double> vertx = new List<double>();
  1373. List<double> verty = new List<double>();
  1374. for (int pointIndex = 0; pointIndex < polygonPointList.Count; pointIndex++)
  1375. {
  1376. vertx.Add(polygonPointList[pointIndex].X);
  1377. verty.Add(polygonPointList[pointIndex].Y);
  1378. }
  1379. int i, j, c = 0;
  1380. for (i = 0, j = nvert - 1; i < nvert; j = i++)
  1381. {
  1382. if (((verty[i] > testy) != (verty[j] > testy)) && (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i]))
  1383. {
  1384. c = 1 + c; ;
  1385. }
  1386. }
  1387. if (c % 2 == 0)
  1388. {
  1389. return false;
  1390. }
  1391. else
  1392. {
  1393. return true;
  1394. }
  1395. }
  1396. #endregion
  1397. #region 获取多边形最小外接矩形
  1398. /// <summary>
  1399. /// 获取多边形最小外接矩形
  1400. /// </summary>
  1401. /// <param name="polygonPointList">不规则形状坐标集合</param>
  1402. /// <returns></returns>
  1403. public static Rectangle GetPolygonToMinRectangle(List<PointF> polygonPointList)
  1404. {
  1405. if (polygonPointList != null)
  1406. {
  1407. if (polygonPointList.Count > 0)
  1408. {
  1409. int pCount = polygonPointList.Count;
  1410. float minX = polygonPointList[0].X;
  1411. float minY = polygonPointList[0].Y;
  1412. float maxX = polygonPointList[0].X;
  1413. float maxY = polygonPointList[0].Y;
  1414. //获取最小X,Y 最大X,Y
  1415. for (int i = 0; i < pCount; i++)
  1416. {
  1417. minX = Math.Min(minX, polygonPointList[i].X);
  1418. minY = Math.Min(minY, polygonPointList[i].Y);
  1419. maxX = Math.Max(maxX, polygonPointList[i].X);
  1420. maxY = Math.Max(maxY, polygonPointList[i].Y);
  1421. }
  1422. //创建外接矩形
  1423. Rectangle rect = new Rectangle();
  1424. rect.Location = new Point((int)minX, (int)minY);
  1425. rect.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY);
  1426. return rect;
  1427. }
  1428. }
  1429. return new Rectangle();
  1430. }
  1431. #endregion
  1432. #region 将多边形屏幕坐标转换为OTS坐标
  1433. /// <summary>
  1434. /// 将多边形屏幕坐标转换为OTS坐标
  1435. /// </summary>
  1436. /// <param name="polygonPointList">不规则形状坐标集合</param>
  1437. /// <returns></returns>
  1438. public static List<PointF> GetPolygonPointToOTSPoint(List<PointF> polygonPointList, int widthDomain, int length)
  1439. {
  1440. List<PointF> OTSPoint = new List<PointF>();
  1441. float X = 0;
  1442. float Y = 0;
  1443. if (polygonPointList != null)
  1444. {
  1445. foreach (var item in polygonPointList)
  1446. {
  1447. X = (float)(item.X * ((double)widthDomain / length));
  1448. Y = (float)(item.Y * ((double)widthDomain / length));
  1449. OTSPoint.Add(new PointF(X, Y));
  1450. }
  1451. }
  1452. return OTSPoint;
  1453. }
  1454. #endregion
  1455. #region List<Point> 转换为 List<PointF>
  1456. /// <summary>
  1457. /// List<Point> 转换为 List<PointF>
  1458. /// </summary>
  1459. /// <param name="Points"></param>
  1460. /// <returns></returns>
  1461. public static List<PointF> PointConvertPointF(List<Point> Points)
  1462. {
  1463. List<PointF> PointFs = new List<PointF>();
  1464. if (Points != null)
  1465. {
  1466. foreach (var itemPoint in Points)
  1467. {
  1468. PointFs.Add(itemPoint);
  1469. }
  1470. }
  1471. return PointFs;
  1472. }
  1473. public static PointF[] PointConvertPointF(Point[] Points)
  1474. {
  1475. PointF[] PointFs = new PointF[Points.Length];
  1476. if (Points != null)
  1477. {
  1478. for (int i = 0; i < Points.Length; i++)
  1479. {
  1480. PointFs[i] = Points[i];
  1481. }
  1482. }
  1483. return PointFs;
  1484. }
  1485. public static Point[] PointFConvertPoint(PointF[] PointFs)
  1486. {
  1487. Point[] Points = new Point[PointFs.Length];
  1488. if (Points != null)
  1489. {
  1490. for (int i = 0; i < Points.Length; i++)
  1491. {
  1492. Points[i] = new Point((int)PointFs[i].X, (int)PointFs[i].Y);
  1493. }
  1494. }
  1495. return Points;
  1496. }
  1497. /// <summary>
  1498. /// List<PointF> 转换为 List<Point>
  1499. /// </summary>
  1500. /// <param name="Points"></param>
  1501. /// <returns></returns>
  1502. public static List<Point> PointFConvertPoint(List<PointF> Points)
  1503. {
  1504. List<Point> PointFs = new List<Point>();
  1505. if (Points != null)
  1506. {
  1507. foreach (var itemPoint in Points)
  1508. {
  1509. PointFs.Add(new Point((int)itemPoint.X, (int)itemPoint.Y));
  1510. }
  1511. }
  1512. return PointFs;
  1513. }
  1514. #endregion
  1515. #region 获取 Rectangle 外框点集合
  1516. public static Point[] GetRectangleToPoint(RectangleF rectangleF)
  1517. {
  1518. int Left = (int)rectangleF.Left;
  1519. int Top = (int)rectangleF.Top;
  1520. int Right = (int)rectangleF.Right;
  1521. int Bottom = (int)rectangleF.Bottom;
  1522. List<Point> addPoint = new List<Point>();
  1523. for (int i = Left; i <= Right; i++)
  1524. {
  1525. addPoint.Add(new Point(Left + 1, Top));
  1526. }
  1527. for (int i = Top; i <= Bottom; i++)
  1528. {
  1529. addPoint.Add(new Point(Right,Top + 1));
  1530. }
  1531. for (int i = Right; i >= Left; i--)
  1532. {
  1533. addPoint.Add(new Point(Right - 1, Bottom));
  1534. }
  1535. for (int i = Bottom; i >= Top; i--)
  1536. {
  1537. addPoint.Add(new Point(Left,Bottom - 1));
  1538. }
  1539. return addPoint.ToArray();
  1540. }
  1541. #endregion
  1542. //检查测量区域是否超过样品台区域
  1543. //RMeasureArea: 样品台的当前测量区域; RStageArea: 样品台区域; RMeasureArea《RStageArea
  1544. public static bool CheckMeasureAreaIsBeyondStageArea(Rectangle RMeasureArea, Rectangle RStageArea, int iShape)
  1545. {
  1546. Rectangle pMeasureArea = RMeasureArea;
  1547. Rectangle pStageArea = RStageArea;
  1548. CDomain a_DomainMeasureArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pMeasureArea);
  1549. CDomain a_DomainStageArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pStageArea);
  1550. return a_DomainStageArea.DomainInDomain(a_DomainMeasureArea);
  1551. }
  1552. #region 重新绘制
  1553. /// <summary>
  1554. /// 重新绘制
  1555. /// </summary>
  1556. /// <param name="e"></param>
  1557. /// <param name="m_ObjectGDIObjects"></param>
  1558. public static void OnPaint(PaintEventArgs e, List<ARectangleGDIObject> m_ObjectGDIObjects)//处理重绘情况
  1559. {
  1560. foreach (ARectangleGDIObject item in m_ObjectGDIObjects)
  1561. {
  1562. if (item != null)
  1563. {
  1564. item.OnPaint(e);
  1565. }
  1566. }
  1567. }
  1568. #endregion
  1569. #region 显示XY轴
  1570. /// <summary>
  1571. /// 显示XY轴
  1572. /// </summary>
  1573. public static void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm, List<ARectangleGDIObject> m_RectangleGDIObjects, StageDrawingData m_OTSSampleStageData,int IsWidth)
  1574. {
  1575. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  1576. {
  1577. if (item.Region.Contains(mPoint))
  1578. {
  1579. //鼠标在样品台中移动获取坐标
  1580. Point mousePoint = OTSSamplespaceGraphicsPanelFun.GetMouseLocationInRectangleGDIObject(mPoint, m_RectangleGDIObjects[0], m_OTSSampleStageData, IsWidth, m_RectangleGDIObjects[0].Region.Width, m_RectangleGDIObjects[0].Region.Height);
  1581. PointF SEMPoint = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(mousePoint);
  1582. //将微米转换为毫米
  1583. float mousePointX = Convert.ToSingle((SEMPoint.X / 1000).ToString("F2"));
  1584. float mousePointY = Convert.ToSingle((SEMPoint.Y / 1000).ToString("F2"));
  1585. //将样品台坐标转换为Sem 坐标
  1586. //编辑显示内容
  1587. string STSemCoordinate = "X:" + mousePointX + "|Y:" + mousePointY + "";
  1588. //显示XY轴
  1589. m_MeasureAppForm.ShowSemCoordvAL(STSemCoordinate);
  1590. }
  1591. }
  1592. }
  1593. #endregion
  1594. }
  1595. }