OTSSamplespaceGraphicsPanelFun.cs 77 KB

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