OTSImageDisHelp.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. 
  2. using OTSIncAReportApp.DataOperation.DataAccess;
  3. using OTSIncAReportApp.DataOperation.Model;
  4. using OTSIncAReportApp.SysMgrTools;
  5. using OTSIncAReportGraph.Class;
  6. using OTSIncAReportGraph.Controls;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Diagnostics;
  12. using System.Drawing;
  13. using System.Drawing.Drawing2D;
  14. using System.IO;
  15. using System.Linq;
  16. namespace OTSIncAReportGraph.OTSIncAReportGraphFuncation
  17. {
  18. public class OTSImageDisHelp
  19. {
  20. #region 枚举定义
  21. /// <summary>
  22. /// 样品台X轴方向
  23. /// </summary>
  24. enum OTS_X_AXIS_DIRECTION
  25. {
  26. LEFT_TOWARD = 0,
  27. RIGHT_TOWARD = 1
  28. }
  29. /// <summary>
  30. /// 样品台Y轴方向
  31. /// </summary>
  32. enum OTS_Y_AXIS_DIRECTION
  33. {
  34. UP_TOWARD = 0,
  35. DOWN_TOWARD = 1
  36. }
  37. #endregion
  38. #region 定义变量
  39. private ResultFile resultFile = null;
  40. //记录field列表的原值
  41. public List<DisplayField> m_original_list_dfield = null;
  42. //记录原值,颗粒和线段
  43. public List<BaseObject> m_original_list_baseobject = null;
  44. NLog.Logger log;
  45. //field的数量
  46. public int m_field_count = 0;
  47. //particle的数量
  48. public int m_particle_count = 0;
  49. //加载使用的时间
  50. public string m_time_str = "";
  51. //加载使用时间计算时间段2
  52. public string m_time_str2 = "";
  53. //电镜设置对象
  54. public ServiceInterface.HardwareController m_cfun = null;
  55. //是否已经连接到了电镜
  56. public bool m_SEMConnectionState = false;
  57. //连接到电镜的ID号
  58. public int m_SEM_ID = 0;
  59. #endregion
  60. #region 构造函数
  61. public OTSImageDisHelp( ResultFile result)
  62. {
  63. m_original_list_dfield = new List<DisplayField>();
  64. m_original_list_baseobject = new List<BaseObject>();
  65. resultFile = result;
  66. m_cfun = ServiceInterface.HardwareController.GetSemController();
  67. log = NLog.LogManager.GetCurrentClassLogger();
  68. }
  69. #endregion
  70. #region 封装自定义方法
  71. public Point GetOTSCoordLeftBottomPoint(List<Point> allFldPos)
  72. {
  73. //the ots coordinate system is always positive on the right and up direction.So the leftbottom point would be the smallest point.
  74. //找出最小的x,y用来做偏移运算
  75. int i_offset_x = 1000000000;
  76. int i_offset_y = 1000000000;
  77. //先取出最小的x,y
  78. for (int i = 0; i < allFldPos.Count; i++)
  79. {
  80. if (i_offset_x > allFldPos[i].X)
  81. {
  82. i_offset_x = allFldPos[i].X;
  83. }
  84. if (i_offset_y > allFldPos[i].Y)
  85. {
  86. i_offset_y = allFldPos[i].Y;
  87. }
  88. }
  89. return new Point(i_offset_x, i_offset_y);
  90. }
  91. public Point ConvertOTSCoordinateToScreenCoord(Point otsleftBottomPoint,double pixelSize, Point currenFldPos,RectangleF wholeImageRec,RectangleF singleImgRec)//
  92. {
  93. var OTSPoint=new Point(currenFldPos.X - otsleftBottomPoint.X, currenFldPos.Y - otsleftBottomPoint.Y);
  94. double screenHeight = wholeImageRec.Height + (0 - (int)(Convert.ToDouble(OTSPoint.Y) / pixelSize));//because the screen coordinate is downward rightward positive,so we need to translate the Y coordinate of the OTS system which is upward rightward positive.
  95. screenHeight = screenHeight - singleImgRec.Height;
  96. var screenPoint = new Point((int)(Convert.ToDouble(OTSPoint.X)/pixelSize), (int)screenHeight);
  97. return screenPoint;
  98. }
  99. public Rectangle ConvertAndGetMaxRect(List<Point> inPoints, int in_width, int in_height)
  100. {
  101. //首先要能确定下来,单个物理坐标的宽和高--------------------------------
  102. int i_wl_width = 0;
  103. int i_wl_height = 0;
  104. RectangleF ls_r = GetPhysicalFieldWidthAndHeight(inPoints,in_width,in_height);
  105. i_wl_width = (int)ls_r.Width;
  106. i_wl_height = (int)ls_r.Height;
  107. //-----------------------------------------------------------------------------
  108. int point_x_min = 10000000;
  109. int point_x_max = -10000000;
  110. int point_y_min = 10000000;
  111. int point_y_max = -10000000;
  112. for (int i = 0; i < inPoints.Count(); i++)
  113. {
  114. Point ls_point = inPoints[i];
  115. //取出正数最大x
  116. if (ls_point.X > point_x_max)
  117. point_x_max = ls_point.X;
  118. if (ls_point.Y > point_y_max)
  119. point_y_max = ls_point.Y;
  120. if (ls_point.X < point_x_min)
  121. point_x_min = ls_point.X;
  122. if (ls_point.Y < point_y_min)
  123. point_y_min = ls_point.Y;
  124. }
  125. //然后分别用最大值+abs(最小值),就是x,和y轴的总长值
  126. point_x_max = point_x_max - point_x_min;
  127. point_y_max = point_y_max - point_y_min;
  128. //该算法有个问题,就是不能直观的得到整个范围的大小,要除以倍数再补1能补充缺少的一个field视域**********
  129. point_x_max = ((point_x_max / i_wl_width) + 1) * i_wl_width;
  130. point_y_max = ((point_y_max / i_wl_height) + 1) * i_wl_height;
  131. //将物理宽高,变换成分辨率宽高
  132. if (i_wl_width != 0) point_x_max = (point_x_max / i_wl_width) * in_width; else point_x_max = 0;
  133. if (i_wl_height != 0) point_y_max = (point_y_max / i_wl_height) * in_height; else point_y_max = 0;
  134. Rectangle ret_rectangle = new Rectangle(0, 0, 0, 0);
  135. //判断一下防止出错,只有在有数据的情况下,进行赋值才行
  136. if (inPoints.Count > 0)
  137. {
  138. ret_rectangle = new Rectangle(0, 0, point_x_max, point_y_max);
  139. }
  140. //这样返回是物理坐标的总大小,应该返回像素坐标大小才对
  141. return ret_rectangle;
  142. }
  143. /// <summary>
  144. /// 计算单个field的物理大小 传入field的list,还有测量结果管理类对象,在无法计算出单field的物理大小的情况下,到这里取再计算得出
  145. /// </summary>
  146. /// <returns></returns>
  147. public RectangleF GetPhysicalFieldWidthAndHeight(List<Point> points,int imageWidth,int imageHeight)
  148. {
  149. int width_max = -10000000;
  150. int height_max = -10000000;
  151. int width_max2 = -10000000;
  152. int height_max2 = -10000000;
  153. //先找出最大的值,
  154. for (int i = 0; i < points.Count(); i++)
  155. {
  156. if (width_max < points[i].X)
  157. width_max = points[i].X;
  158. if (height_max < points[i].Y)
  159. height_max = points[i].Y;
  160. }
  161. //再找出第二大的值
  162. for (int i = 0; i < points.Count(); i++)
  163. {
  164. if (width_max2 < points[i].X && width_max != points[i].X)
  165. width_max2 = points[i].X;
  166. if (height_max2 < points[i].Y && height_max != points[i].Y)
  167. height_max2 = points[i].Y;
  168. }
  169. //需要针对第二大的值,获取时进行判断,感觉这里应该如果并未找到第二大的值的情况下,赋于0值,便于以后进行计算
  170. if (width_max2 == -10000000)
  171. width_max2 = width_max;
  172. if (height_max2 == -10000000)
  173. height_max2 = height_max;
  174. RectangleF ret_rect = new RectangleF(0, 0, width_max - width_max2, height_max - height_max2);
  175. //如果最后计算出的宽高有0则重新到测量数据中获取---------------------------------------
  176. if (ret_rect.Width == 0 || ret_rect.Height == 0)
  177. {
  178. //到参数中去取单个宽
  179. double d_scanFieldSize_width = Convert.ToDouble(((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["scanFieldSize"]);
  180. //然后再用单个宽去计算出高是多少
  181. double d_scanFieldSize_height = 0;
  182. if (d_scanFieldSize_width != 0)
  183. d_scanFieldSize_height = (d_scanFieldSize_width / Convert.ToDouble(imageWidth)) * imageHeight;
  184. ret_rect.Width = (int)d_scanFieldSize_width;
  185. ret_rect.Height = (int)d_scanFieldSize_height;
  186. }
  187. ///-----------because all the fields 's height/width=0.75 so here we make an enforce. gsp add at 2019/10/31
  188. ///sometimes the gbfields are not conform to this for the cuting and merging operation.
  189. //if (ret_rect.Height / ret_rect.Width != 0.75f)
  190. //{
  191. // ret_rect = new Rectangle(ret_rect.X, ret_rect.Y, ret_rect.Width, (int)(ret_rect.Width * 0.75f));
  192. //}
  193. return ret_rect;
  194. }
  195. #endregion
  196. #region 电镜操作相关方法
  197. /// <summary>
  198. /// 连接电镜,分布图使用
  199. /// </summary>
  200. public void ConnectToSEM()
  201. {
  202. log.Trace("(Connection_ForDrawDistrbutionImageAndBSE)" + "Connect to SEM");
  203. if (!m_SEMConnectionState)
  204. {
  205. //和电镜建立通讯连接
  206. m_SEMConnectionState = m_cfun.Connect();
  207. log.Trace("(Connection_ForDrawDistrbutionImageAndBSE)" + "Connect to SEM" + ":--" + m_SEMConnectionState + "---");
  208. }
  209. else
  210. {
  211. log.Trace("(Connection_ForDrawDistrbutionImageAndBSE)" + ":allready connected, state:" + m_SEMConnectionState);
  212. //断开电镜连接
  213. }
  214. }
  215. public void DisConnectSEM()
  216. {
  217. m_SEMConnectionState = false;
  218. m_cfun.DisConnect();
  219. }
  220. /// <summary>
  221. /// 移动电镜到指定的X,Y坐标上,R坐标使用原先的值进行移动
  222. /// </summary>
  223. /// <param name="PositionX"></param>
  224. /// <param name="PositionY"></param>
  225. public void MoveSemToPointXY(double in_PositionX, double in_PositionY)
  226. {
  227. log.Trace("Begin MoveSemToPointXY:(" +in_PositionX.ToString()+","+in_PositionY.ToString()+")");
  228. //首先获取电镜当前的位置,并记录原R值
  229. double ls_PositionX = 0;
  230. double ls_PositionY = 0;
  231. double ls_PositionR = 0;
  232. if (m_SEMConnectionState)
  233. {
  234. m_cfun.GetSemPositionXY(ref ls_PositionX, ref ls_PositionY, ref ls_PositionR);
  235. }
  236. else
  237. {
  238. log.Error("Failed to GetSemPositionXY");
  239. return;
  240. }
  241. if (m_SEMConnectionState)
  242. {
  243. m_cfun.MoveSEMToPoint(new Point((int)in_PositionX, (int)in_PositionY), ls_PositionR);
  244. }
  245. }
  246. #endregion
  247. #region //--------------------------------------颗粒分布图相关部份---------------------------------------------------------------------
  248. /// <summary>
  249. /// 传入颗粒的tagid和fieldid,来获取该颗粒下对应的xray数据
  250. /// </summary>
  251. /// <param name="in_clr_tagid"></param>
  252. /// <param name="in_clr_fieldid"></param>
  253. /// <param name="Search_xray"></param>
  254. /// <param name="Analysis_xray"></param>
  255. public void GetXrayByParticleTagIDAndFieldID_ForDrawDistrbutionImageAndBSE(int in_clr_tagid, int in_clr_fieldid, out uint[] Search_xray, out uint[] Analysis_xray, out int xray_id, out List<Element> list_celementchemistryclr)
  256. {
  257. Search_xray = new uint[2000];
  258. Analysis_xray = new uint[2000];
  259. xray_id = 0;
  260. list_celementchemistryclr = new List<Element>();
  261. //防止为空校验判断
  262. if (resultFile.List_OTSField == null)
  263. return;
  264. Particle particle = resultFile.List_OTSField.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
  265. var tmpPart = new ParticleData(resultFile.FilePath).GetParticleXrayDataByFidAndPid(Convert.ToString(particle.FieldId), Convert.ToString(particle.XrayId));
  266. if (tmpPart != null)
  267. {
  268. particle.XRayData = tmpPart.XRayData;
  269. if (particle.XrayId > -1)
  270. {
  271. for (int i = 0; i < 2000; i++)
  272. {
  273. Analysis_xray[i] = BitConverter.ToUInt32(particle.XRayData, i * 4);
  274. }
  275. Search_xray = Analysis_xray;
  276. xray_id = particle.XrayId;
  277. list_celementchemistryclr = particle.ElementList;
  278. }
  279. }
  280. }
  281. public bool DeleteParticlesFromLibrary(int in_clr_tagid, int in_clr_fieldid)
  282. {
  283. bool DoesItExist = false;
  284. for (int i=1;i<201;i++)
  285. {
  286. if (System.IO.Directory.Exists(resultFile.FilePath + "\\FIELD_FILES\\Backups"+i.ToString()))
  287. {
  288. DoesItExist = true;
  289. break;
  290. }
  291. }
  292. if (!DoesItExist)
  293. {
  294. //备份数据库
  295. BackupDatabase();
  296. }
  297. DoesItExist = false;
  298. //防止为空校验判断
  299. if (resultFile.List_OTSField == null)
  300. return false;
  301. Particle particle = resultFile.List_OTSField.Find(x => x.FieldID == in_clr_fieldid).ParticleList.Find(x => x.ParticleId == in_clr_tagid);
  302. if (new ParticleData(resultFile.FilePath).DeleteFromData(Convert.ToString(particle.FieldId), Convert.ToString(particle.XrayId)))
  303. {
  304. return true;
  305. }else
  306. {
  307. return false;
  308. }
  309. }
  310. public bool BackupDatabase()
  311. {
  312. //创建备份数据库文件夹
  313. string sourcePath = resultFile.FilePath + "\\FIELD_FILES\\Inclusion.db";//源文件路径
  314. string sourceName = "Inclusion.db";//源文件名称
  315. string folderPath = resultFile.FilePath + "\\FIELD_FILES\\Backups";//目标文件夹
  316. string Fields = "";
  317. for (int i = 1; i < 201; i++)
  318. {
  319. if (System.IO.Directory.Exists(folderPath + i.ToString()))
  320. {
  321. Fields = folderPath + i.ToString();
  322. break;
  323. }
  324. else
  325. {
  326. System.IO.Directory.CreateDirectory(folderPath + i.ToString());
  327. Fields = folderPath + i.ToString();
  328. break;
  329. }
  330. }
  331. if (Fields == "")
  332. {
  333. return false;
  334. }
  335. //复制数据库文件
  336. string targetPath = Path.Combine(Fields, sourceName);
  337. FileInfo file = new FileInfo(sourcePath);
  338. if (file.Exists)
  339. {
  340. file.CopyTo(targetPath, true);
  341. }
  342. return true;
  343. }
  344. /// <summary>
  345. /// 传入所有的物理field坐标点,和单个物理field的宽高,返回所有field的左上角位置,和整个field组成的rect大小
  346. /// </summary>
  347. /// <param name="in_list_point"></param>
  348. /// <param name="in_width"></param>
  349. /// <param name="in_height"></param>
  350. /// <returns></returns>
  351. public Rectangle GetWlRectTopLeftAndRect(List<Point> in_list_point, int in_width, int in_height)
  352. {
  353. //分别获取整个rect的xy最小值和最大值
  354. int i_rect_x_min = 100000000;
  355. int i_rect_y_min = 100000000;
  356. int i_rect_x_max = -100000000;
  357. int i_rect_y_max = -100000000;
  358. for (int i = 0; i < in_list_point.Count; i++)
  359. {
  360. if (i_rect_x_min > in_list_point[i].X)
  361. i_rect_x_min = in_list_point[i].X;
  362. if (i_rect_y_min > in_list_point[i].Y)
  363. i_rect_y_min = in_list_point[i].Y;
  364. if (i_rect_x_max < in_list_point[i].X)
  365. i_rect_x_max = in_list_point[i].X;
  366. if (i_rect_y_max < in_list_point[i].Y)
  367. i_rect_y_max = in_list_point[i].Y;
  368. }
  369. Rectangle ret_rect = new Rectangle(i_rect_x_min, i_rect_y_min,
  370. i_rect_x_max - i_rect_x_min, i_rect_y_max - i_rect_y_min);
  371. return ret_rect;
  372. }
  373. /// <summary>
  374. /// 根据Field的ID,来获取Field列表中对应FIeld的OTS 坐标
  375. /// </summary>
  376. /// <param name="in_fieldid"></param>
  377. /// <returns></returns>
  378. public Point GetOTSPointByFieldID(List<DisplayField> in_list_dfield, int in_fieldid)
  379. {
  380. Point ret_point = new Point(0, 0);
  381. for (int i = 0; i < in_list_dfield.Count; i++)
  382. {
  383. //这里TagID先代表的是底层返回的ID
  384. if (in_list_dfield[i].FieldID == in_fieldid.ToString())
  385. {
  386. ret_point = new Point(Convert.ToInt32(in_list_dfield[i].OTSCoordinatePos.X), Convert.ToInt32(in_list_dfield[i].OTSCoordinatePos.Y));
  387. }
  388. }
  389. return ret_point;
  390. }
  391. /// <summary>
  392. /// 将OTS坐标转换为Sem 坐标
  393. /// </summary>
  394. /// <param name="POTSCoord"></param>
  395. /// <returns></returns>
  396. public Point ChangeOTSToSemCoord(Point POTSCoord)
  397. {
  398. //first if m_semstagedata is null to get stage inforation
  399. Convert.ToDouble(((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["scanFieldSize"]);
  400. //after obtaining stage info,calc stage point data
  401. Point ret_SEM_point = new Point();
  402. // get center point, um
  403. long xStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["Members"])["XAxis"])["start"]);
  404. long xEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["Members"])["XAxis"])["end"]);
  405. long xCenter = (xStart + xEnd) / 2;
  406. long yStart = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["Members"])["YAxis"])["start"]);
  407. long yEnd = Convert.ToInt64(((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["Members"])["YAxis"])["end"]);
  408. long yCenter = (yStart + yEnd) / 2;
  409. // delte = SEM - OTSa
  410. long deltex = xCenter - 0;
  411. long deltey = yCenter - 0;
  412. int xdir = Convert.ToInt32(((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["xAxisDir"]);
  413. int ydir = Convert.ToInt32(((Dictionary<string, object>)resultFile.ResultInfo["SEMStageData"])["yAxisDir"]);
  414. if (xdir == (int)OTS_X_AXIS_DIRECTION.LEFT_TOWARD)
  415. {
  416. ret_SEM_point.X = -1 * (POTSCoord.X - Convert.ToInt32(deltex));
  417. }
  418. else if (xdir == (int)OTS_X_AXIS_DIRECTION.RIGHT_TOWARD)
  419. {
  420. ret_SEM_point.X = POTSCoord.X + Convert.ToInt32(deltex);
  421. }
  422. if (ydir == (int)OTS_Y_AXIS_DIRECTION.UP_TOWARD)
  423. {
  424. ret_SEM_point.Y = POTSCoord.Y + Convert.ToInt32(deltey);
  425. }
  426. else if (ydir == (int)OTS_Y_AXIS_DIRECTION.DOWN_TOWARD)
  427. {
  428. ret_SEM_point.Y = -1 * (POTSCoord.Y - Convert.ToInt32(deltey));
  429. }
  430. return ret_SEM_point;
  431. }
  432. #endregion
  433. /// <summary>
  434. /// 判断该点是否在多边形的范围内
  435. /// </summary>
  436. /// <param name="inPoints"></param>
  437. /// <param name="WhetherPoint"></param>
  438. /// <returns></returns>
  439. public bool WhetherInRange(DisplayParticle Part,/*PointF[] inPoints,*/ Point WhetherPoint)
  440. {
  441. var rect = Part.Rect;
  442. if ((rect.Left < WhetherPoint.X && WhetherPoint.X < rect.Right) && (rect.Top < WhetherPoint.Y && WhetherPoint.Y < rect.Bottom))
  443. {
  444. var itm = (BaseObject)Part;
  445. itm.GPath = Part.GetRegionFromDSegments();
  446. PointF[] inPoints = itm.GPath.PathPoints;
  447. bool b_inrange = false;
  448. GraphicsPath myGraphicsPath = new GraphicsPath();
  449. Region myRegion = new Region();
  450. myGraphicsPath.Reset();
  451. myGraphicsPath.AddPolygon(inPoints);
  452. myRegion.MakeEmpty();
  453. myRegion.Union(myGraphicsPath);
  454. //返回判断点是否在多边形里
  455. b_inrange = myRegion.IsVisible(WhetherPoint);
  456. return b_inrange;
  457. }
  458. else
  459. {
  460. return false;
  461. }
  462. }
  463. public bool WhetherInRange(RectangleF rec,PointF[] inPoints, Point WhetherPoint)
  464. {
  465. var rect = rec;
  466. if ((rect.Left < WhetherPoint.X && WhetherPoint.X < rect.Right) && (rect.Top < WhetherPoint.Y && WhetherPoint.Y < rect.Bottom))
  467. {
  468. //var itm = (BaseObject)Part;
  469. //PointF[] inPoints = itm.GPath.PathPoints;
  470. bool b_inrange = false;
  471. GraphicsPath myGraphicsPath = new GraphicsPath();
  472. Region myRegion = new Region();
  473. myGraphicsPath.Reset();
  474. myGraphicsPath.AddPolygon(inPoints);
  475. myRegion.MakeEmpty();
  476. myRegion.Union(myGraphicsPath);
  477. //返回判断点是否在多边形里
  478. b_inrange = myRegion.IsVisible(WhetherPoint);
  479. return b_inrange;
  480. }
  481. else
  482. {
  483. return false;
  484. }
  485. }
  486. /// <summary>
  487. /// 判断该点是否在多边形的范围内的float版本重载
  488. /// </summary>
  489. /// <param name="inPoints"></param>
  490. /// <param name="WhetherPoint"></param>
  491. /// <returns></returns>
  492. public bool WhetherInRange(DisplayParticle Part,/* PointF[] inPoints, */PointF WhetherPoint)
  493. {
  494. var rect = Part.Rect;
  495. if ((rect.Left < WhetherPoint.X && WhetherPoint.X < rect.Right) && (rect.Top < WhetherPoint.Y && WhetherPoint.Y < rect.Bottom))
  496. {
  497. var itm = (BaseObject)Part;
  498. PointF[] inPoints = itm.GPath.PathPoints;
  499. bool b_inrange = false;
  500. GraphicsPath myGraphicsPath = new GraphicsPath();
  501. Region myRegion = new Region();
  502. myGraphicsPath.Reset();
  503. myGraphicsPath.AddPolygon(inPoints);
  504. myRegion.MakeEmpty();
  505. myRegion.Union(myGraphicsPath);
  506. //返回判断点是否在多边形里
  507. b_inrange = myRegion.IsVisible(WhetherPoint);
  508. return b_inrange;
  509. }
  510. else
  511. {
  512. return false;
  513. }
  514. }
  515. }
  516. }