OTSSamplespaceGraphicsPanelFun.cs 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607
  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 RectangleF GetPixRectF(int width, Point xPoint, Point yPoint, string sampleName, string sampleHoleName, int IsWidth, int Width, int Height)
  487. {
  488. try
  489. {
  490. //将微米信息 转换为 像素
  491. PointF xPoints = new PointF();
  492. PointF yPoints = new PointF();
  493. xPoints.X = (float)MillimetersToPixelsWidth(width, xPoint.X, IsWidth, Width, Height);
  494. xPoints.Y = (float)MillimetersToPixelsWidth(width, xPoint.Y, IsWidth, Width, Height);
  495. yPoints.X = (float)MillimetersToPixelsWidth(width, yPoint.X, IsWidth, Width, Height);
  496. yPoints.Y = (float)MillimetersToPixelsWidth(width, yPoint.Y, IsWidth, Width, Height);
  497. //计算位置
  498. xPoints = CalculateLocationF(xPoints, Width, Height);
  499. yPoints = CalculateLocationF(yPoints, Width, Height);
  500. //创建矩形 并返回类型对象
  501. return new RectangleF(xPoints.X, xPoints.Y, Math.Abs(yPoints.X - xPoints.X), Math.Abs(yPoints.Y - xPoints.Y));
  502. }
  503. catch (Exception)
  504. {
  505. return new RectangleF();
  506. }
  507. }
  508. public static double MillimetersToPixelsWidth(int width, double PointVal, int IsWidth, int Width, int Height)
  509. {
  510. return PointVal / ((double)width / (IsWidth == 0 ? (double)Width : (double)Height));
  511. }
  512. public static Point CalculateLocation(Point point, int Width, int Height)
  513. {
  514. //获取窗体的高度与宽度
  515. int screenWidth = Width;
  516. int screenHeight = Height;
  517. //获取屏幕中心点
  518. Point pointXY = new Point();
  519. Point screenPoint = new Point(screenWidth / 2, screenHeight / 2);
  520. pointXY.X = screenPoint.X + point.X; //(IsWidth == 0 ? screenPoint.X : screenPoint.Y) + point.X;
  521. pointXY.Y = screenPoint.Y - point.Y;
  522. return pointXY;
  523. }
  524. public static PointF CalculateLocationF(PointF point, int Width, int Height)
  525. {
  526. //获取窗体的高度与宽度
  527. int screenWidth = Width;
  528. int screenHeight = Height;
  529. //获取屏幕中心点
  530. PointF pointXY = new PointF();
  531. PointF screenPoint = new PointF(screenWidth / 2, screenHeight / 2);
  532. pointXY.X = screenPoint.X + point.X; //(IsWidth == 0 ? screenPoint.X : screenPoint.Y) + point.X;
  533. pointXY.Y = screenPoint.Y - point.Y;
  534. return pointXY;
  535. }
  536. #endregion
  537. #region 通过OTS坐标 获取工作区域图形尺寸
  538. public static void GetWorkSpaceSize(Point pStartPoint, Point pEndPoint)
  539. {
  540. int widthDomain = 0;
  541. int heightDomain = 0;
  542. //宽度
  543. widthDomain = Math.Abs(((Point)pStartPoint).X - ((Point)pEndPoint).X);
  544. heightDomain = Math.Abs(((Point)pStartPoint).Y - ((Point)pEndPoint).Y);
  545. }
  546. #endregion
  547. #region 判断是否相同
  548. /// <summary>
  549. /// 判断是否相同
  550. /// </summary>
  551. /// <param name="sampleMeasurePara"></param>
  552. /// <param name="SampleMeasureParaResult"></param>
  553. /// <returns></returns>
  554. public static bool IsValidate(OTSIncAMeasureAppForm m_MeasureAppForm, SampleMeasurePara sampleMeasurePara, SampleMeasurePara SampleMeasureParaResult)
  555. {
  556. try
  557. {
  558. if (sampleMeasurePara.sSampleName != SampleMeasureParaResult.sSampleName)
  559. {
  560. return false;
  561. }
  562. if (sampleMeasurePara.MeasureRect != SampleMeasureParaResult.MeasureRect)
  563. {
  564. return false;
  565. }
  566. if (sampleMeasurePara.sHoleName != SampleMeasureParaResult.sHoleName)
  567. {
  568. return false;
  569. }
  570. return true;
  571. }
  572. catch (Exception)
  573. {
  574. return false;
  575. }
  576. }
  577. #endregion
  578. #region 获取工作样品信息
  579. /// <summary>
  580. /// 获取工作样品信息
  581. /// </summary>
  582. /// <param name="sampleName"></param>
  583. /// <returns></returns>
  584. public static ARectangleGDIObject GetWorkSample(string sampleName)
  585. {
  586. foreach (ARectangleGDIObject itemSample in OTSSamplespaceWindow.m_SampleGDIObjects)
  587. {
  588. if (itemSample.SampleName == sampleName)
  589. {
  590. return itemSample;
  591. }
  592. }
  593. return null;
  594. }
  595. #endregion
  596. #region 获取测量区域
  597. /// <summary>
  598. /// 获取测量区域
  599. /// </summary>
  600. /// <param name="m_MeasureAppForm"></param>
  601. /// <param name="sampleName"></param>
  602. /// <returns></returns>
  603. public static SampleMeasurePara GetMeasureInfo( string sampleName, ARectangleGDIObject item, int wDomain, int w)
  604. {
  605. SampleMeasurePara sampleMeasurePara = new SampleMeasurePara();
  606. foreach (ARectangleGDIObject measureItem in OTSSamplespaceWindow.m_MeasureGDIObjects)
  607. {
  608. if (sampleName == measureItem.SampleName)
  609. {
  610. //设置测量区域位置与尺寸
  611. float left = 0;
  612. float Top = 0;
  613. float Right = 0;
  614. float Bottom = 0;
  615. float Widths = 0;
  616. float Height = 0;
  617. //设置测量区域位置与尺寸
  618. left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.X, wDomain, w);
  619. Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Y, wDomain, w);
  620. Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Right, wDomain, w);
  621. Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Bottom, wDomain, w);
  622. Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Width, wDomain, w);
  623. Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Height, wDomain, w);
  624. //保存原位置
  625. RectangleF polygonRectPara = measureItem.DrawRegionF;
  626. if (measureItem.CreateType == (int)CreateRectangleType.Polygon)
  627. {
  628. polygonRectPara = GetPolygonToMinRectangle(measureItem.DrawPolygonPointRegionF);
  629. //设置测量区域位置与尺寸
  630. left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.X, wDomain, w);
  631. Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Y, wDomain, w);
  632. Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Right, wDomain, w);
  633. Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Bottom, wDomain, w);
  634. Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Width, wDomain, w);
  635. Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)polygonRectPara.Height, wDomain, w);
  636. }
  637. //设置测量区域
  638. PointF startPoint = new PointF(left, Top);
  639. SizeF MeasureSize = new SizeF(Widths, Height);
  640. sampleMeasurePara.MeasureRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)MeasureSize.Width, (int)MeasureSize.Height));
  641. //设置样品孔名称
  642. sampleMeasurePara.sHoleName = item.Name;
  643. //设置样品名称
  644. sampleMeasurePara.sSampleName = item.SampleName;
  645. //设置测量区域形状
  646. sampleMeasurePara.iShape = item.Shape;
  647. //设置多边形点集合
  648. sampleMeasurePara.PolygonPointRegion = PointFConvertPoint(GetPolygonPointToOTSPoint(item.PolygonPointRegionF, wDomain, w));
  649. sampleMeasurePara.PolygonPointRegionF = GetPolygonPointToOTSPoint(item.PolygonPointRegionF, wDomain, w);
  650. sampleMeasurePara.DrawPolygonPointRegionF = GetPolygonPointToOTSPoint(item.DrawPolygonPointRegionF, wDomain, w);
  651. break;
  652. }
  653. }
  654. return sampleMeasurePara;
  655. }
  656. public static SampleHolePara GetSampleHoleInfo(string sampleHoleName, ARectangleGDIObject item, int wDomain, int w)
  657. {
  658. SampleHolePara sampleHolePara = new SampleHolePara();
  659. foreach (ARectangleGDIObject sampleHoleItem in OTSSamplespaceWindow.m_SampleHoleGDIObjects)
  660. {
  661. if (sampleHoleName == sampleHoleItem.Name)
  662. {
  663. //保存原位置
  664. Rectangle rectPara = sampleHoleItem.Region;
  665. //设置测量区域
  666. sampleHolePara.SampleHoleRect = sampleHoleItem.Region;
  667. //设置测量区域位置与尺寸
  668. float left = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.X, wDomain, w);
  669. float Top = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Y, wDomain, w);
  670. float Right = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Right, wDomain, w);
  671. float Bottom = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Bottom, wDomain, w);
  672. float Widths = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Width, wDomain, w);
  673. float Height = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)item.RegionF.Height, wDomain, w);
  674. //Size sizeRegion = new Size(PointRB);
  675. PointF startPoint = new PointF(left, Top);
  676. SizeF sampleHoleSize = new SizeF(Widths, Height);
  677. sampleHolePara.SampleHoleRect = new Rectangle(new Point((int)startPoint.X, (int)startPoint.Y), new Size((int)sampleHoleSize.Width, (int)sampleHoleSize.Height));
  678. //设置样品孔名称
  679. sampleHolePara.sHoleName = item.Name;
  680. //设置测量区域形状
  681. sampleHolePara.iShape = item.Shape;
  682. break;
  683. }
  684. }
  685. return sampleHolePara;
  686. }
  687. #endregion
  688. #region 获取工作样品的测量区域信息
  689. /// <summary>
  690. /// 获取工作样品的测量区域信息
  691. /// </summary>
  692. /// <returns></returns>
  693. //public static Rectangle GetWorkMeasure( int wDomain, int w)
  694. //{
  695. // foreach (ARectangleGDIObject itemMeasure in OTSSamplespaceWindow.m_MeasureGDIObjects)
  696. // {
  697. // if (itemMeasure.IsWorkSample)
  698. // {
  699. // Point startPoint = new Point(itemMeasure.Region.Left, itemMeasure.Region.Top);
  700. // Point endPoint = new Point(itemMeasure.Region.Right, itemMeasure.Region.Bottom);
  701. // SampleMeasurePara rectMaesure = GetMeasureInfo(itemMeasure.SampleName, itemMeasure, wDomain, w);
  702. // return rectMaesure.MeasureRect;
  703. // }
  704. // }
  705. // return new Rectangle();
  706. //}
  707. #endregion
  708. #region 删除样品弹出提示
  709. public static bool ShowDeleteDialog(string sampleName)
  710. {
  711. //国际化
  712. OTSCommon.Language lan = new OTSCommon.Language();
  713. Hashtable table = lan.GetNameTable("OTSIncAMeasureAppForm");
  714. string str1 = table["message5"].ToString();
  715. string str2 = table["message6"].ToString();
  716. string sDeleteSampleName = str1;
  717. sDeleteSampleName += sampleName;
  718. sDeleteSampleName += " 信息 ?";
  719. if (DialogResult.OK == MessageBox.Show(sDeleteSampleName, "Delete sample information prompt", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
  720. {
  721. return true;
  722. }
  723. else
  724. {
  725. return false;
  726. }
  727. }
  728. #endregion
  729. #region 将点转换至工作区域
  730. public void PointToClient(Point rect)
  731. {
  732. this.PointToClient(rect);
  733. }
  734. #endregion
  735. #region 删除样品 同时删除帧图
  736. public static bool DeleteSampleInfo(OTSIncAMeasureAppForm m_MeasureAppForm, string sampleSelectName)
  737. {
  738. try
  739. {
  740. //提交主窗体响应
  741. bool deleteResult = false;
  742. if (OTSSamplespaceGraphicsPanelFun.ShowDeleteDialog(sampleSelectName))
  743. {
  744. //设置当前状态
  745. m_MeasureAppForm.m_MessageStates = (int)MessageState.StartMeasure;
  746. deleteResult = m_MeasureAppForm.DeleteSample(sampleSelectName);
  747. if (deleteResult)
  748. {
  749. //样品对象列表中无样品信息 则清除帧图对象列表信息
  750. bool result = m_MeasureAppForm.m_SamplepaceWindow.SampleIsEmptyClearSingleInfo();
  751. if(result)
  752. {
  753. m_MeasureAppForm.m_MeasureRetWindow.SetInit();
  754. }
  755. }
  756. }
  757. return true;
  758. }
  759. catch (Exception)
  760. {
  761. return false;
  762. }
  763. }
  764. #endregion
  765. #region 计算两个点之间的距离 (图形与鼠标点击获取的点)
  766. public static Point StartToEndPointDist(ARectangleGDIObject m_RectangleGDIObjects, Point regionStartPoint)
  767. {
  768. Point differentPoint = new Point();
  769. //获取点击后的样品台位置
  770. Point m_Region = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects.Region);
  771. //获取鼠标按下的位置
  772. Point regionEndPoint = m_Region;
  773. //获取鼠标按下与抬起 位置差值
  774. differentPoint.X = regionEndPoint.X - regionStartPoint.X;
  775. differentPoint.Y = regionEndPoint.Y - regionStartPoint.Y;
  776. return differentPoint;
  777. }
  778. #endregion
  779. #region 计算两个点之间的距离 (图形中心与屏幕中心相差的距离)
  780. //public static Point RegionCenterToScreenCenterDist(ARectangleGDIObject regionCneter, Point screenCneter)
  781. //{
  782. // Point differentPoint = new Point();
  783. // //获取图形中心位置
  784. // Rectangle rectangle = new Rectangle();
  785. // rectangle.X = (int)regionCneter.RegionF.X;
  786. // rectangle.Y = (int)regionCneter.RegionF.Y;
  787. // rectangle.Width = (int)regionCneter.RegionF.Width;
  788. // rectangle.Height = (int)regionCneter.RegionF.Height;
  789. // Point m_RegionCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(rectangle);
  790. // //获取图形中心与屏幕中心相差的距离
  791. // differentPoint.X = m_RegionCenter.X - screenCneter.X;
  792. // differentPoint.Y = m_RegionCenter.Y - screenCneter.Y;
  793. // return differentPoint;
  794. //}
  795. #endregion
  796. #region 清除List中所有信息
  797. public static List<ARectangleGDIObject> ListClear(List<ARectangleGDIObject> ListObject)
  798. {
  799. if (ListObject != null)
  800. {
  801. if (ListObject.Count > 0)
  802. {
  803. ListObject.Clear();
  804. }
  805. }
  806. return ListObject;
  807. }
  808. #endregion
  809. #region 根据颜色枚举 获取颜色值
  810. public static string GetColorValue(ColorType ColorEnum)
  811. {
  812. string ColorStr = string.Empty;
  813. switch (ColorEnum)
  814. {
  815. case ColorType.SingleColor:
  816. ColorStr = "#fd8f8f";//帧图fd8f8f
  817. break;
  818. case ColorType.RoundRectangleColor:
  819. ColorStr = "#c8c8c8";//c8c8c8圆角矩形
  820. break;
  821. case ColorType.FontColor:
  822. ColorStr = "#90ee90";//90ee90文字颜色
  823. break;
  824. case ColorType.SampleColor:
  825. ColorStr = "#f4f4f4";//f4f4f4 样品未选择
  826. break;
  827. case ColorType.SampleSelColor:
  828. ColorStr = "#505050";//505050 样品选择后
  829. break;
  830. }
  831. return ColorStr;
  832. }
  833. #endregion
  834. #region 获取测量区域的位置
  835. public static SampleMeasurePara GetSampleMeasureRect(ARectangleGDIObject MeasureItem, OTSIncAMeasureAppForm m_MeasureAppForm, StageDrawingData oTSSampleStageData, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
  836. {
  837. int w = (IsWidth == 0 ? Width : Height);
  838. int iShape = 0;
  839. Rectangle Srect = new Rectangle();
  840. SampleMeasurePara sampleMeasureParas = new SampleMeasurePara();
  841. //获取当前工作的测量区域信息
  842. bool returnResult = m_MeasureAppForm.m_ProjParam.GetWSampleMrsArea(ref iShape, ref Srect);
  843. if (returnResult)
  844. {
  845. //获取测量区域的OTS位置与尺寸
  846. sampleMeasureParas = OTSSamplespaceGraphicsPanelFun.GetMeasureInfo( MeasureItem.SampleName, MeasureItem, wDomain, w);
  847. //获取工作区域位置与尺寸
  848. Rectangle WorkAreaRect = new Rectangle(0, 0, Width, Height);
  849. //获取工作区域 中心点
  850. Point ScreenPointCenter = OTSSamplespaceGraphicsPanelFun.GetWorkAreaCenterPoint(WorkAreaRect);
  851. //获取样品台 中心点
  852. PointF RectanglePointCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPointF(m_RectangleGDIObjects.RegionF);
  853. //获取屏幕中心点
  854. float WorkAreaCenterPointX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.X, wDomain, w);
  855. float WorkAreaCenterPointY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.Y, wDomain, w);
  856. //获取样品台中心点
  857. float CenterX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.X, wDomain, w);
  858. float CenterY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.Y, wDomain, w);
  859. Rectangle sampleMeasureRect = new Rectangle();
  860. //根据样品台中心点获取开始点位置
  861. sampleMeasureRect.X = -((int)CenterX - sampleMeasureParas.MeasureRect.X);
  862. sampleMeasureRect.Y = (int)CenterY - sampleMeasureParas.MeasureRect.Bottom;
  863. sampleMeasureParas.MeasureRect.X = sampleMeasureRect.X;
  864. sampleMeasureParas.MeasureRect.Y = sampleMeasureRect.Y;
  865. for (int i = 0; i < sampleMeasureParas.DrawPolygonPointRegionF.Count; i++)
  866. {
  867. int X = -((int)CenterX - (int)sampleMeasureParas.DrawPolygonPointRegionF[i].X);
  868. int Y = (int)CenterY - (int)sampleMeasureParas.DrawPolygonPointRegionF[i].Y;
  869. //sampleMeasureParas.PolygonPointRegion[i] = new Point(X, Y);
  870. sampleMeasureParas.DrawPolygonPointRegionF[i] = new Point(X, Y);
  871. }
  872. }
  873. return sampleMeasureParas;
  874. }
  875. public static SampleHolePara GetSampleHoleRect(ARectangleGDIObject sampleHoleItem, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
  876. {
  877. int w = (IsWidth == 0 ? Width : Height);
  878. SampleHolePara sampleHoleParas = new SampleHolePara();
  879. //获取样品孔的OTS位置与尺寸
  880. sampleHoleParas = OTSSamplespaceGraphicsPanelFun.GetSampleHoleInfo( sampleHoleItem.Name, sampleHoleItem, wDomain, w);
  881. //获取工作区域位置与尺寸
  882. Rectangle WorkAreaRect = new Rectangle(0, 0, Width, Height);
  883. //获取工作区域 中心点
  884. Point ScreenPointCenter = OTSSamplespaceGraphicsPanelFun.GetWorkAreaCenterPoint(WorkAreaRect);
  885. //获取样品台 中心点
  886. PointF RectanglePointCenter = OTSSamplespaceGraphicsPanelFun.GetCenterPointF(m_RectangleGDIObjects.RegionF);
  887. //获取屏幕中心点
  888. float WorkAreaCenterPointX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.X, wDomain, w);
  889. float WorkAreaCenterPointY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron(ScreenPointCenter.Y, wDomain, w);
  890. //获取样品台中心点
  891. float CenterX = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.X, wDomain, w);
  892. float CenterY = OTSSamplespaceGraphicsPanelFun.PixelConvertToMicron((int)RectanglePointCenter.Y, wDomain, w);
  893. Rectangle sampleHoleRect = new Rectangle();
  894. //根据样品台中心点获取开始点位置
  895. sampleHoleRect.X = -((int)CenterX - sampleHoleParas.SampleHoleRect.X);
  896. sampleHoleRect.Y = (int)CenterY - sampleHoleParas.SampleHoleRect.Bottom;
  897. sampleHoleParas.SampleHoleRect.X = sampleHoleRect.X;
  898. sampleHoleParas.SampleHoleRect.Y = sampleHoleRect.Y;
  899. return sampleHoleParas;
  900. }
  901. #endregion
  902. #region //设置测量区域信息(位置与大小)
  903. public static bool SetWorkSamplHoleAndMeasureArea(ARectangleGDIObject MeasureItem, OTSIncAMeasureAppForm m_MeasureAppForm, StageDrawingData oTSSampleStageData, ARectangleGDIObject m_RectangleGDIObjects, int IsWidth, int Width, int Height, int wDomain)
  904. {
  905. //获取工作样品中的测量区域
  906. //设置测量区域位置
  907. //获取修改后的测量区域的位置与尺寸
  908. var sampleMeasurePara = GetSampleMeasureRect(MeasureItem, m_MeasureAppForm, oTSSampleStageData, m_RectangleGDIObjects, IsWidth, Width, Height, wDomain);
  909. sampleMeasurePara.sHoleName = MeasureItem.Name;
  910. sampleMeasurePara.sSampleName = MeasureItem.SampleName;
  911. //设置测量区域信息(位置与大小)
  912. SampleMeasurePara SampleMeasureParaResult = m_MeasureAppForm.SetWorkSamplHoleAndMeasureArea(sampleMeasurePara);
  913. if (OTSSamplespaceGraphicsPanelFun.IsValidate(m_MeasureAppForm, sampleMeasurePara, SampleMeasureParaResult))
  914. {
  915. return true;
  916. }
  917. return false;
  918. }
  919. #endregion
  920. #region 根据list中的帧图信息 获取中心位置
  921. public static PointF GetSingleCenterLocation(List<ARectangleGDIObject> m_SingleGDIObjects)
  922. {
  923. float MinX = 0f;
  924. float MinY = 0f;
  925. float MaxX = 0f;
  926. float MaxY = 0f;
  927. float width = 0f;
  928. float height = 0f;
  929. //获取最小XY 与最大XY
  930. MinX = m_SingleGDIObjects[0].RegionF.X;
  931. MinY = m_SingleGDIObjects[0].RegionF.Y;
  932. MaxX = m_SingleGDIObjects[0].RegionF.X;
  933. MaxY = m_SingleGDIObjects[0].RegionF.Y;
  934. width = m_SingleGDIObjects[0].RegionF.Width;
  935. height = m_SingleGDIObjects[0].RegionF.Height;
  936. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  937. {
  938. MinX = Math.Min(m_SingleGDIObjects[i].RegionF.X, MinX);
  939. MinY = Math.Min(m_SingleGDIObjects[i].RegionF.Y, MinY);
  940. MaxX = Math.Max(m_SingleGDIObjects[i].RegionF.X, MaxX);
  941. MaxY = Math.Max(m_SingleGDIObjects[i].RegionF.Y, MaxY);
  942. }
  943. //获取帧图的外框矩形
  944. RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX- MinX+ width, MaxY- MinY+ height);
  945. //计算外框矩形的中心点
  946. float PointFX = SingleRect.X + SingleRect.Width / 2;
  947. float PointFY = SingleRect.Y + SingleRect.Height / 2;
  948. PointF SingleCenterPoint = new PointF(PointFX, PointFY);
  949. return SingleCenterPoint;
  950. }
  951. public static PointF GetSingleDrawCenterLocation(List<ARectangleGDIObject> m_SingleGDIObjects)
  952. {
  953. float MinX = 0f;
  954. float MinY = 0f;
  955. float MaxX = 0f;
  956. float MaxY = 0f;
  957. float width = 0f;
  958. float height = 0f;
  959. //获取最小XY 与最大XY
  960. MinX = m_SingleGDIObjects[0].DrawRegionF.X;
  961. MinY = m_SingleGDIObjects[0].DrawRegionF.Y;
  962. MaxX = m_SingleGDIObjects[0].DrawRegionF.X;
  963. MaxY = m_SingleGDIObjects[0].DrawRegionF.Y;
  964. width = m_SingleGDIObjects[0].DrawRegionF.Width;
  965. height = m_SingleGDIObjects[0].DrawRegionF.Height;
  966. for (int i = 0; i < m_SingleGDIObjects.Count; i++)
  967. {
  968. MinX = Math.Min(m_SingleGDIObjects[i].DrawRegionF.X, MinX);
  969. MinY = Math.Min(m_SingleGDIObjects[i].DrawRegionF.Y, MinY);
  970. MaxX = Math.Max(m_SingleGDIObjects[i].DrawRegionF.X, MaxX);
  971. MaxY = Math.Max(m_SingleGDIObjects[i].DrawRegionF.Y, MaxY);
  972. }
  973. //获取帧图的外框矩形
  974. RectangleF SingleRect = new RectangleF(MinX, MinY, MaxX - MinX + width, MaxY - MinY + height);
  975. //计算外框矩形的中心点
  976. float PointFX = SingleRect.X + SingleRect.Width / 2;
  977. float PointFY = SingleRect.Y + SingleRect.Height / 2;
  978. PointF SingleCenterPoint = new PointF(PointFX, PointFY);
  979. return SingleCenterPoint;
  980. }
  981. #endregion
  982. #region 将所有帧图移植测量区域位置
  983. public static void SetSingleLocationToMeasureLocation(List<ARectangleGDIObject> m_ObjectListGDIObjects, ARectangleGDIObject m_ObjectGDIObjects)
  984. {
  985. //获取帧图中心与测量区域中心
  986. PointF singleCenterPoinF= GetSingleCenterLocation(m_ObjectListGDIObjects);
  987. PointF singleDrawCenterPoinF = GetSingleDrawCenterLocation(m_ObjectListGDIObjects);
  988. //测量区域 已改变为倍数的尺寸 中心点
  989. PointF measureCenterPoin = GetCenterPointF(m_ObjectGDIObjects.Region);
  990. //测量区域 正常尺寸 中心点
  991. PointF measureCenterPoinF = GetCenterPointF(m_ObjectGDIObjects.RegionF);
  992. //计算相差的XY距离
  993. float moveX = measureCenterPoin.X - singleCenterPoinF.X;
  994. float moveY = measureCenterPoin.Y - singleCenterPoinF.Y;
  995. float moveFX = measureCenterPoinF.X - singleDrawCenterPoinF.X;
  996. float moveFY = measureCenterPoinF.Y - singleDrawCenterPoinF.Y;
  997. //需要移动的位置
  998. PointF movePoint = new PointF(moveX, moveY);
  999. PointF movePointF = new PointF(moveFX, moveFY);
  1000. foreach (var ObjectItem in m_ObjectListGDIObjects)
  1001. {
  1002. //计算移动后的位置
  1003. float X = ObjectItem.RegionF.X + movePoint.X;
  1004. float Y = ObjectItem.RegionF.Y + movePoint.Y;
  1005. float Width = ObjectItem.RegionF.Width;
  1006. float Height = ObjectItem.RegionF.Height;
  1007. ObjectItem.Region = new Rectangle((int)X, (int)Y, (int)Width, (int)Height);
  1008. ObjectItem.RegionF = new RectangleF(X, Y, Width, Height);
  1009. ObjectItem.DrawRegionF = new RectangleF(ObjectItem.DrawRegionF.X + movePointF.X, ObjectItem.DrawRegionF.Y + movePointF.Y, ObjectItem.DrawRegionF.Width, ObjectItem.DrawRegionF.Height);
  1010. }
  1011. }
  1012. #endregion
  1013. /// <summary>
  1014. /// 获取XML中电镜的选项
  1015. /// </summary>
  1016. #region 测量区域中心移动至SEM当前位置
  1017. /// <summary>
  1018. /// 测量区域中心移动至SEM当前位置
  1019. /// </summary>
  1020. /// <param name="m_SamplespaceWindow">样品台窗体对象</param>
  1021. /// <param name="mouseLocation">当前鼠标的位置</param>
  1022. public static void NewLocationDrawMeasureInfo(OTSSamplespaceWindow m_SamplespaceWindow, List<ARectangleGDIObject> m_RectangleGDIObjects, StageDrawingData oTSSampleStageData, int IsWidth, Point moveToSEMLocation, List<ARectangleGDIObject> UpdateLocationGDIObject,float m_GlobalZoomNum)
  1023. {
  1024. //样品台中心点位置
  1025. Point m_StageCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0]);
  1026. //当前与中心点相差距离
  1027. int m_StageCenterDiffX = 0;
  1028. int m_StageCenterDiffY = 0;
  1029. int diffNewX = 0;
  1030. int diffNewY = 0;
  1031. Point m_UpdateCenterPoint = new Point();
  1032. foreach (var item in UpdateLocationGDIObject)
  1033. {
  1034. if(item.IsWorkSample)
  1035. {
  1036. m_UpdateCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(item);
  1037. m_StageCenterDiffX = (int)((m_StageCenterPoint.X - m_UpdateCenterPoint.X) * 1);
  1038. m_StageCenterDiffY = (int)((m_StageCenterPoint.Y - m_UpdateCenterPoint.Y) * 1);
  1039. diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum);
  1040. diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum);
  1041. //根据鼠标_更改测量区域的位置
  1042. 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));
  1043. 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));
  1044. item.DrawRegionF = item.RegionF;
  1045. //修改多边形的绘制点集合
  1046. if (item.CreateType == (int)CreateRectangleType.Polygon)
  1047. {
  1048. for (int i = 0; i < item.PolygonPointRegion.Count; i++)
  1049. {
  1050. item.PolygonPointRegion[i] = new Point(item.PolygonPointRegion[i].X + m_StageCenterDiffX + diffNewX, item.PolygonPointRegion[i].Y + m_StageCenterDiffY - diffNewY);
  1051. item.PolygonPointRegionF[i] = new PointF(item.PolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX), item.PolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY));
  1052. item.DrawPolygonPointRegionF[i] = new PointF(item.DrawPolygonPointRegionF[i].X + (m_StageCenterDiffX + diffNewX) / m_GlobalZoomNum, item.DrawPolygonPointRegionF[i].Y + (m_StageCenterDiffY - diffNewY) / m_GlobalZoomNum);
  1053. }
  1054. }
  1055. }
  1056. }
  1057. }
  1058. 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)
  1059. {
  1060. //样品台中心点位置
  1061. Point m_StageCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(m_RectangleGDIObjects[0]);
  1062. //当前与中心点相差距离
  1063. int m_StageCenterDiffX = 0;
  1064. int m_StageCenterDiffY = 0;
  1065. Point m_WorkMeasureCenterPoint = new Point();
  1066. if (UpdateLocationGDIObject == null)
  1067. {
  1068. return false;
  1069. }
  1070. int diffNewX = 0;
  1071. int diffNewY = 0;
  1072. bool IsOK = true;
  1073. diffNewX = moveToSEMLocation.X;
  1074. diffNewY = moveToSEMLocation.Y;
  1075. if (IsOK)
  1076. {
  1077. foreach (var item in UpdateLocationGDIObject)
  1078. {
  1079. m_WorkMeasureCenterPoint = OTSSamplespaceGraphicsPanelFun.GetCenterPoint(WorkMeasure);
  1080. m_StageCenterDiffX = m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X;//(int)((m_StageCenterPoint.X - m_WorkMeasureCenterPoint.X) * m_GlobalZoomNum);
  1081. m_StageCenterDiffY = m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y;// (int)((m_StageCenterPoint.Y - m_WorkMeasureCenterPoint.Y) * m_GlobalZoomNum);
  1082. diffNewX = (int)(moveToSEMLocation.X * m_GlobalZoomNum);
  1083. diffNewY = (int)(moveToSEMLocation.Y * m_GlobalZoomNum);
  1084. //根据鼠标_更改测量区域的位置
  1085. 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));
  1086. 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));
  1087. 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));
  1088. }
  1089. }
  1090. return IsOK;
  1091. }
  1092. #endregion
  1093. #region 通过样品孔名称 获取在列表中的索引
  1094. /// <summary>
  1095. /// 通过样品孔名称 获取在列表中的索引
  1096. /// </summary>
  1097. /// <param name="oTSSampleStageData">样品台文件</param>
  1098. /// <param name="sampleHoleName">样品孔名称</param>
  1099. /// <returns></returns>
  1100. public static int GetSampleHoleIndex(StageDrawingData oTSSampleStageData,string sampleHoleName, ref OTSSampleHoleInfo sampleHoleInfo)
  1101. {
  1102. try
  1103. {
  1104. int sampleHoleIndex = -1;
  1105. if (oTSSampleStageData.sSHoleInfoList.Count > 0)
  1106. {
  1107. for (int i = 0; i < oTSSampleStageData.sSHoleInfoList.Count; i++)
  1108. {
  1109. if (oTSSampleStageData.sSHoleInfoList[i].sSHoleName == sampleHoleName)
  1110. {
  1111. sampleHoleInfo = oTSSampleStageData.sSHoleInfoList[i];
  1112. sampleHoleIndex = i;
  1113. break;
  1114. }
  1115. }
  1116. }
  1117. return sampleHoleIndex;
  1118. }
  1119. catch (Exception)
  1120. {
  1121. return -1;
  1122. }
  1123. }
  1124. #endregion
  1125. #region 添加帧图信息
  1126. /// <summary>
  1127. /// 添加帧图信息
  1128. /// </summary>
  1129. /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
  1130. /// <param name="m_SingleGDIObjects">帧图对象列表</param>
  1131. /// <param name="sampleName">样品名称</param>
  1132. /// <returns></returns>
  1133. public static bool AddALLSingleInfo(List<ARectangleGDIObject> m_ALLSingleGDIObjects, List<ARectangleGDIObject> m_SingleGDIObjects, string sampleName)
  1134. {
  1135. bool result = false;
  1136. //判断ALLSingle对象列表中是否为空
  1137. if (m_ALLSingleGDIObjects != null)
  1138. {
  1139. bool IsExist = true;
  1140. if (m_ALLSingleGDIObjects.Count > 0)
  1141. {
  1142. //判断是否包含样品名称
  1143. foreach (var item in m_ALLSingleGDIObjects)
  1144. {
  1145. if (item.SampleName.Equals(sampleName))
  1146. {
  1147. IsExist = false;
  1148. break;
  1149. }
  1150. }
  1151. }
  1152. if (IsExist)
  1153. {
  1154. result = true;
  1155. foreach (var item in m_SingleGDIObjects)
  1156. {
  1157. m_ALLSingleGDIObjects.Add(item);
  1158. }
  1159. }
  1160. return result;
  1161. }
  1162. return result;
  1163. }
  1164. #endregion
  1165. #region 删除帧图信息
  1166. /// <summary>
  1167. /// 删除帧图信息
  1168. /// </summary>
  1169. /// <param name="m_ALLSingleGDIObjects">帧图对象列表</param>
  1170. /// <param name="sampleName">样品名称</param>
  1171. /// <returns></returns>
  1172. public static bool DeleteALLSingleInfo(List<ARectangleGDIObject> m_ALLSingleGDIObjects, string sampleName)
  1173. {
  1174. bool result = false;
  1175. int resultCount = 0;
  1176. //判断ALLSingle对象列表中是否为空
  1177. if (m_ALLSingleGDIObjects != null)
  1178. {
  1179. if (m_ALLSingleGDIObjects.Count > 0)
  1180. {
  1181. for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
  1182. {
  1183. if (m_ALLSingleGDIObjects[i].SampleName.Equals(sampleName))
  1184. {
  1185. m_ALLSingleGDIObjects.RemoveAt(i);
  1186. resultCount++;
  1187. }
  1188. }
  1189. }
  1190. else
  1191. {
  1192. result = true;
  1193. }
  1194. if (resultCount > 0)
  1195. {
  1196. result = true;
  1197. }
  1198. }
  1199. return result;
  1200. }
  1201. #endregion
  1202. #region 切换样品 填充帧图信息
  1203. public static void ChangeSampleFillSingleInfo(List<ARectangleGDIObject> m_ALLSingleGDIObjects, List<ARectangleGDIObject> m_SingleGDIObjects, string sampleName)
  1204. {
  1205. //判断帧图对象中是否存在当前工作样品帧图信息
  1206. bool IsExist = true;
  1207. //判断ALLSingle对象列表中是否为空
  1208. if (m_ALLSingleGDIObjects != null)
  1209. {
  1210. if (m_ALLSingleGDIObjects.Count > 0)
  1211. {
  1212. foreach (var item in m_SingleGDIObjects)
  1213. {
  1214. if (item.SampleName.Equals(sampleName))
  1215. {
  1216. IsExist = false;
  1217. }
  1218. }
  1219. if (IsExist)
  1220. {
  1221. //判断是否包含样品名称
  1222. foreach (var item in m_ALLSingleGDIObjects)
  1223. {
  1224. if (item.SampleName.Equals(sampleName))
  1225. {
  1226. m_SingleGDIObjects.Add(item);
  1227. }
  1228. }
  1229. }
  1230. }
  1231. }
  1232. }
  1233. #endregion
  1234. #region 修改已存在的帧图中样品名称
  1235. public static void EditWorkSampleName(List<ARectangleGDIObject> m_ALLSingleGDIObjects, string oldSampleName, string newSampleName)
  1236. {
  1237. int resultCount = 0;
  1238. //判断ALLSingle对象列表中是否为空
  1239. if (m_ALLSingleGDIObjects != null)
  1240. {
  1241. if (m_ALLSingleGDIObjects.Count > 0)
  1242. {
  1243. for (int i = m_ALLSingleGDIObjects.Count - 1; i >= 0; i--)
  1244. {
  1245. if (m_ALLSingleGDIObjects[i].SampleName.Equals(oldSampleName))
  1246. {
  1247. m_ALLSingleGDIObjects[i].SampleName = newSampleName;
  1248. resultCount++;
  1249. }
  1250. }
  1251. }
  1252. }
  1253. }
  1254. #endregion
  1255. #region 修改测量区域中GraphicsPath属性
  1256. public static void UpdateMeasureGraphicsPath(ARectangleGDIObject measureItem, Rectangle rectPara)
  1257. {
  1258. //重新绘制测量区域路径
  1259. GraphicsPath GPath = new GraphicsPath();
  1260. if (measureItem.CreateType == (int)CreateRectangleType.Polygon)
  1261. {
  1262. GraphicsPath PolygonMeasurePath = new GraphicsPath();
  1263. PolygonMeasurePath.AddPolygon(measureItem.PolygonPointRegionF.ToArray());
  1264. GPath = PolygonMeasurePath;
  1265. }
  1266. else if(measureItem.CreateType == (int)CreateRectangleType.CircleByThreePoints)
  1267. {
  1268. GPath.AddEllipse(rectPara);
  1269. }
  1270. else
  1271. {
  1272. if (measureItem.Shape == (int)CreateRectangleType.Circle)
  1273. {
  1274. GPath.AddEllipse(rectPara);
  1275. }
  1276. else
  1277. {
  1278. GPath.AddRectangle(rectPara);
  1279. }
  1280. }
  1281. measureItem.GPath = GPath;
  1282. }
  1283. #endregion
  1284. #region OnMouseWheel
  1285. public static void RecoverInitialPosition(List<ARectangleGDIObject> l_GDIObjects,float m_GlobalZoomNum)
  1286. {
  1287. for (int i = 0; i < l_GDIObjects.Count; i++)
  1288. {
  1289. RectangleF rectF = new RectangleF();
  1290. rectF = l_GDIObjects[i].DrawRegionF;
  1291. //根据样品孔中心点与样品台中心点的方向 设置宽度与高度\
  1292. 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));
  1293. PointF pointF = new PointF(rectF.X * m_GlobalZoomNum, rectF.Y * m_GlobalZoomNum);
  1294. SizeF sizeF = new SizeF((rectF.Width * m_GlobalZoomNum), (rectF.Height * m_GlobalZoomNum));
  1295. l_GDIObjects[i].RegionF = new RectangleF(pointF, sizeF);
  1296. }
  1297. }
  1298. #endregion
  1299. #region 判断当前位置是否在不规则形状里面
  1300. /// <summary>
  1301. /// 判断当前位置是否在不规则形状里面
  1302. /// </summary>
  1303. /// <param name="PointList">不规则形状坐标集合</param>
  1304. /// <param name="currentMouseLocation">当前鼠标坐标</param>
  1305. /// <returns></returns>
  1306. public static bool PositionPnpoly(List<Point> polygonPointList, Point currentMouseLocation)
  1307. {
  1308. double testx = currentMouseLocation.X;
  1309. double testy = currentMouseLocation.Y;
  1310. int nvert = polygonPointList.Count;
  1311. List<double> vertx = new List<double>();
  1312. List<double> verty = new List<double>();
  1313. for (int pointIndex = 0; pointIndex < polygonPointList.Count; pointIndex++)
  1314. {
  1315. vertx.Add(polygonPointList[pointIndex].X);
  1316. verty.Add(polygonPointList[pointIndex].Y);
  1317. }
  1318. int i, j, c = 0;
  1319. for (i = 0, j = nvert - 1; i < nvert; j = i++)
  1320. {
  1321. if (((verty[i] > testy) != (verty[j] > testy)) && (testx < (vertx[j] - vertx[i]) * (testy - verty[i]) / (verty[j] - verty[i]) + vertx[i]))
  1322. {
  1323. c = 1 + c; ;
  1324. }
  1325. }
  1326. if (c % 2 == 0)
  1327. {
  1328. return false;
  1329. }
  1330. else
  1331. {
  1332. return true;
  1333. }
  1334. }
  1335. #endregion
  1336. #region 获取多边形最小外接矩形
  1337. /// <summary>
  1338. /// 获取多边形最小外接矩形
  1339. /// </summary>
  1340. /// <param name="polygonPointList">不规则形状坐标集合</param>
  1341. /// <returns></returns>
  1342. public static Rectangle GetPolygonToMinRectangle(List<PointF> polygonPointList)
  1343. {
  1344. if (polygonPointList != null)
  1345. {
  1346. if (polygonPointList.Count > 0)
  1347. {
  1348. int pCount = polygonPointList.Count;
  1349. float minX = polygonPointList[0].X;
  1350. float minY = polygonPointList[0].Y;
  1351. float maxX = polygonPointList[0].X;
  1352. float maxY = polygonPointList[0].Y;
  1353. //获取最小X,Y 最大X,Y
  1354. for (int i = 0; i < pCount; i++)
  1355. {
  1356. minX = Math.Min(minX, polygonPointList[i].X);
  1357. minY = Math.Min(minY, polygonPointList[i].Y);
  1358. maxX = Math.Max(maxX, polygonPointList[i].X);
  1359. maxY = Math.Max(maxY, polygonPointList[i].Y);
  1360. }
  1361. //创建外接矩形
  1362. Rectangle rect = new Rectangle();
  1363. rect.Location = new Point((int)minX, (int)minY);
  1364. rect.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY);
  1365. return rect;
  1366. }
  1367. }
  1368. return new Rectangle();
  1369. }
  1370. #endregion
  1371. #region 将多边形屏幕坐标转换为OTS坐标
  1372. /// <summary>
  1373. /// 将多边形屏幕坐标转换为OTS坐标
  1374. /// </summary>
  1375. /// <param name="polygonPointList">不规则形状坐标集合</param>
  1376. /// <returns></returns>
  1377. public static List<PointF> GetPolygonPointToOTSPoint(List<PointF> polygonPointList, int widthDomain, int length)
  1378. {
  1379. List<PointF> OTSPoint = new List<PointF>();
  1380. float X = 0;
  1381. float Y = 0;
  1382. if (polygonPointList != null)
  1383. {
  1384. foreach (var item in polygonPointList)
  1385. {
  1386. X = (float)(item.X * ((double)widthDomain / length));
  1387. Y = (float)(item.Y * ((double)widthDomain / length));
  1388. OTSPoint.Add(new PointF(X, Y));
  1389. }
  1390. }
  1391. return OTSPoint;
  1392. }
  1393. #endregion
  1394. #region List<Point> 转换为 List<PointF>
  1395. /// <summary>
  1396. /// List<Point> 转换为 List<PointF>
  1397. /// </summary>
  1398. /// <param name="Points"></param>
  1399. /// <returns></returns>
  1400. public static List<PointF> PointConvertPointF(List<Point> Points)
  1401. {
  1402. List<PointF> PointFs = new List<PointF>();
  1403. if (Points != null)
  1404. {
  1405. foreach (var itemPoint in Points)
  1406. {
  1407. PointFs.Add(itemPoint);
  1408. }
  1409. }
  1410. return PointFs;
  1411. }
  1412. public static PointF[] PointConvertPointF(Point[] Points)
  1413. {
  1414. PointF[] PointFs = new PointF[Points.Length];
  1415. if (Points != null)
  1416. {
  1417. for (int i = 0; i < Points.Length; i++)
  1418. {
  1419. PointFs[i] = Points[i];
  1420. }
  1421. }
  1422. return PointFs;
  1423. }
  1424. public static Point[] PointFConvertPoint(PointF[] PointFs)
  1425. {
  1426. Point[] Points = new Point[PointFs.Length];
  1427. if (Points != null)
  1428. {
  1429. for (int i = 0; i < Points.Length; i++)
  1430. {
  1431. Points[i] = new Point((int)PointFs[i].X, (int)PointFs[i].Y);
  1432. }
  1433. }
  1434. return Points;
  1435. }
  1436. /// <summary>
  1437. /// List<PointF> 转换为 List<Point>
  1438. /// </summary>
  1439. /// <param name="Points"></param>
  1440. /// <returns></returns>
  1441. public static List<Point> PointFConvertPoint(List<PointF> Points)
  1442. {
  1443. List<Point> PointFs = new List<Point>();
  1444. if (Points != null)
  1445. {
  1446. foreach (var itemPoint in Points)
  1447. {
  1448. PointFs.Add(new Point((int)itemPoint.X, (int)itemPoint.Y));
  1449. }
  1450. }
  1451. return PointFs;
  1452. }
  1453. #endregion
  1454. #region 获取 Rectangle 外框点集合
  1455. public static Point[] GetRectangleToPoint(RectangleF rectangleF)
  1456. {
  1457. int Left = (int)rectangleF.Left;
  1458. int Top = (int)rectangleF.Top;
  1459. int Right = (int)rectangleF.Right;
  1460. int Bottom = (int)rectangleF.Bottom;
  1461. List<Point> addPoint = new List<Point>();
  1462. for (int i = Left; i <= Right; i++)
  1463. {
  1464. addPoint.Add(new Point(Left + 1, Top));
  1465. }
  1466. for (int i = Top; i <= Bottom; i++)
  1467. {
  1468. addPoint.Add(new Point(Right,Top + 1));
  1469. }
  1470. for (int i = Right; i >= Left; i--)
  1471. {
  1472. addPoint.Add(new Point(Right - 1, Bottom));
  1473. }
  1474. for (int i = Bottom; i >= Top; i--)
  1475. {
  1476. addPoint.Add(new Point(Left,Bottom - 1));
  1477. }
  1478. return addPoint.ToArray();
  1479. }
  1480. #endregion
  1481. //检查测量区域是否超过样品台区域
  1482. //RMeasureArea: 样品台的当前测量区域; RStageArea: 样品台区域; RMeasureArea《RStageArea
  1483. public static bool CheckMeasureAreaIsBeyondStageArea(Rectangle RMeasureArea, Rectangle RStageArea, int iShape)
  1484. {
  1485. Rectangle pMeasureArea = RMeasureArea;
  1486. Rectangle pStageArea = RStageArea;
  1487. CDomain a_DomainMeasureArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pMeasureArea);
  1488. CDomain a_DomainStageArea = new CDomain((otsdataconst.DOMAIN_SHAPE)iShape, pStageArea);
  1489. return a_DomainStageArea.DomainInDomain(a_DomainMeasureArea);
  1490. }
  1491. #region 重新绘制
  1492. /// <summary>
  1493. /// 重新绘制
  1494. /// </summary>
  1495. /// <param name="e"></param>
  1496. /// <param name="m_ObjectGDIObjects"></param>
  1497. public static void OnPaint(PaintEventArgs e, List<ARectangleGDIObject> m_ObjectGDIObjects)//处理重绘情况
  1498. {
  1499. foreach (ARectangleGDIObject item in m_ObjectGDIObjects)
  1500. {
  1501. if (item != null)
  1502. {
  1503. item.OnPaint(e);
  1504. }
  1505. }
  1506. }
  1507. #endregion
  1508. #region 显示XY轴
  1509. /// <summary>
  1510. /// 显示XY轴
  1511. /// </summary>
  1512. public static void ShowSemCoordvAL(Point mPoint, OTSIncAMeasureAppForm m_MeasureAppForm, List<ARectangleGDIObject> m_RectangleGDIObjects, StageDrawingData m_OTSSampleStageData,int IsWidth)
  1513. {
  1514. foreach (ARectangleGDIObject item in m_RectangleGDIObjects)
  1515. {
  1516. if (item.Region.Contains(mPoint))
  1517. {
  1518. //鼠标在样品台中移动获取坐标
  1519. Point mousePoint = OTSSamplespaceGraphicsPanelFun.GetMouseLocationInRectangleGDIObject(mPoint, m_RectangleGDIObjects[0], m_OTSSampleStageData, IsWidth, m_RectangleGDIObjects[0].Region.Width, m_RectangleGDIObjects[0].Region.Height);
  1520. PointF SEMPoint = m_MeasureAppForm.m_ProjParam.ChangeOTSToSemCoord(mousePoint);
  1521. //将微米转换为毫米
  1522. float mousePointX = Convert.ToSingle((SEMPoint.X / 1000).ToString("F2"));
  1523. float mousePointY = Convert.ToSingle((SEMPoint.Y / 1000).ToString("F2"));
  1524. //将样品台坐标转换为Sem 坐标
  1525. //编辑显示内容
  1526. string STSemCoordinate = "X:" + mousePointX + "|Y:" + mousePointY + "";
  1527. //显示XY轴
  1528. m_MeasureAppForm.ShowSemCoordvAL(STSemCoordinate);
  1529. }
  1530. }
  1531. }
  1532. #endregion
  1533. }
  1534. }