OTSSamplespaceGraphicsPanelFun.cs 77 KB

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