DisplayParticle.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. using OTSCommon.Model;
  2. using OTSIncAReportGraph.Class;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace OTSIncAReportGraph
  12. {
  13. /// <summary>
  14. /// Particle对象上操作状态的枚举,显示,不显示,已删除,已选择
  15. /// </summary>
  16. public enum PaintState
  17. {
  18. PAINT = 0,
  19. NOPAINT = 1,
  20. CONCISEPAINT=2,// display as a "+"
  21. }
  22. public enum DisplayState
  23. {
  24. DISPLAY = 0,
  25. NODISPLAY = 1,
  26. }
  27. /// <summary>
  28. /// Particle对象上操作xray的枚举状态,显示xray数据,不显示
  29. /// </summary>
  30. public enum ParticleShowXray
  31. {
  32. DISPLAYXRAY = 0,
  33. NODISPLAY = 1,
  34. }
  35. /// <summary>
  36. /// Segment对象绘制的枚举,以点绘制,还是以线绘制
  37. /// </summary>
  38. public enum SegmentShowMode
  39. {
  40. DRAWPOINT = 0,
  41. DRAWLINE = 1,
  42. }
  43. /// <summary>
  44. /// 颗粒类
  45. /// </summary>
  46. public class DisplayParticle : ICloneable
  47. {
  48. private const float m_zoom_displayThreshold = 0.1f;
  49. public Particle objParticleData;
  50. private Guid m_id;
  51. private RectangleF m_rect;
  52. private PointF m_OTSPointF;
  53. private RectangleF m_smallRect;
  54. private bool m_isSelected_smallrect;
  55. private bool m_showSmallx;
  56. private bool m_isSelected;
  57. private bool m_isDeleted;
  58. private bool m_isMouseOver;
  59. private PaintState m_paintState = PaintState.PAINT;
  60. private ParticleShowXray m_operator_showxray = ParticleShowXray.NODISPLAY;//选定显示XRAY,不显示XRAY,默认应为(不显示XRAY)
  61. private bool m_isdragging;
  62. private PointF m_dragingpoint;
  63. private Color m_color;
  64. private GraphicsPath m_gpath;
  65. private List<DisplaySegment> m_listdsegment = new List<DisplaySegment>();
  66. private DisplayState m_displayState;
  67. private SegmentShowMode show_mode = SegmentShowMode.DRAWPOINT;//绘线,绘点,默认绘点,意思为默认显示BSE原图像
  68. private Image m_image;
  69. private string m_sort_type = "从大到小";
  70. private float m_f_size = 0;
  71. private string m_str_lj = "颗粒粒级";
  72. private string m_str_klzl = "颗粒种类";
  73. private string m_str_klfl = "颗粒分类";
  74. private float m_CurrentZoomNum = 1;
  75. public int TypeId
  76. {
  77. get
  78. {
  79. return objParticleData.TypeId;
  80. }
  81. }
  82. //TypeName
  83. public string TypeName
  84. {
  85. get
  86. {
  87. return objParticleData.TypeName;
  88. }
  89. }
  90. //XRayId
  91. public int XRayId
  92. {
  93. get
  94. {
  95. return objParticleData.XrayId;
  96. }
  97. }
  98. public int SEMPosX
  99. {
  100. get
  101. {
  102. return objParticleData.SEMPosX;
  103. }
  104. }
  105. public int SEMPosY
  106. {
  107. get
  108. {
  109. return objParticleData.SEMPosY;
  110. }
  111. }
  112. public DisplayParticle()
  113. {
  114. m_id = System.Guid.NewGuid();
  115. }
  116. public DisplayParticle(Particle particle,Point screenPos,Bitmap originalFieldImage,Bitmap fieldParticleImage)
  117. {
  118. m_id = System.Guid.NewGuid();
  119. objParticleData = particle;
  120. this.Color = DrawFunction.GetColorBySTDTypeIDForBSEAndSorImage(particle.TypeColor, particle.TypeId);
  121. List<Segment> list_seg;
  122. list_seg = particle.SegmentList;
  123. //创建颗粒分布图对应的类对象
  124. List<DisplaySegment> list_dsegment = new List<DisplaySegment>();
  125. //再循环取出里面所有的segment
  126. foreach (Segment seg in list_seg)
  127. {
  128. #region 创建DSegment对象,并将STD分析出的化合物颜色保存到DSegment对象中
  129. //对Particle里的Segment进行偏移的计算等,创建了DSegment的大小
  130. DisplaySegment ds = new DisplaySegment();
  131. ds.SetShowRect(new Rectangle(seg.Start + screenPos.X,
  132. seg.Height + screenPos.Y,
  133. seg.Length,
  134. 1));
  135. ds.Color = this.Color;//将线的颜色对应到颗粒的颜色
  136. #endregion
  137. #region //这里是在Field中,抠取出原BSE图像到DSegment中--------------------------------
  138. //合成图像完成,开始抠取像素-----------------------------------------------------------------
  139. int f_length = seg.Length;
  140. for (int m = 0; m < f_length; m++)
  141. {
  142. //这里实现一下代码保护
  143. int lsjs_x = seg.Start + m;
  144. int lsjs_y = seg.Height;
  145. var pixelColor = originalFieldImage.GetPixel(lsjs_x, lsjs_y);
  146. fieldParticleImage.SetPixel(lsjs_x, lsjs_y, pixelColor);//ls_list_colors[m]
  147. }
  148. #endregion //------------------------------------------------------------------------------
  149. list_dsegment.Add(ds);
  150. }
  151. SetPaintState(PaintState.PAINT);
  152. SetDSegments(list_dsegment);
  153. var currentRect = new RectangleF(m_rect.X - screenPos.X, m_rect.Y - screenPos.Y, m_rect.Width, m_rect.Height);
  154. var dpImg = fieldParticleImage.Clone(currentRect, fieldParticleImage.PixelFormat);
  155. SetImage(dpImg);
  156. }
  157. public DisplayParticle(List<DisplaySegment> in_list_segment, DisplayParticle in_particle)
  158. {
  159. objParticleData = in_particle.objParticleData;
  160. m_id = in_particle.m_id;
  161. m_paintState = in_particle.m_paintState;
  162. m_operator_showxray = in_particle.m_operator_showxray;
  163. foreach (DisplaySegment e in in_list_segment)
  164. {
  165. m_listdsegment.Add(e.Clone() as DisplaySegment);
  166. }
  167. m_rect = GetRectFromDSegment();
  168. m_smallRect = GetSmallRectangleFromRect();
  169. m_gpath = GetRegionFromDSegments();
  170. }
  171. /// <summary>
  172. /// 设置显示的方式,可以用,绘线显示查看标准库颜色的,也可以用绘点,查看BSE原图颗粒图色的
  173. /// </summary>
  174. public SegmentShowMode ShowMode
  175. {
  176. get { return show_mode; }
  177. set { show_mode = value; }
  178. }
  179. /// <summary>
  180. /// 克隆方法
  181. /// </summary>
  182. /// <returns></returns>
  183. public object Clone()
  184. {
  185. return new DisplayParticle(this.m_listdsegment, this);
  186. }
  187. public PointF GetCenterPoint()
  188. {
  189. return new PointF(m_rect.X + m_rect.Width / 2, m_rect.Y + m_rect.Height / 2);
  190. }
  191. /// <summary>
  192. /// ID
  193. /// </summary>
  194. public Guid guid
  195. {
  196. get { return m_id; }
  197. set { m_id = value; }
  198. }
  199. /// <summary>
  200. /// 颗粒的外边框大小
  201. /// </summary>
  202. public RectangleF GetShowRect()
  203. {
  204. m_rect= this.GetRectFromDSegment();
  205. return m_rect;
  206. }
  207. /// <summary>
  208. /// OTSPointF
  209. /// </summary>
  210. public PointF OTSPointF
  211. {
  212. get { return m_OTSPointF; }
  213. set { m_OTSPointF = value; }
  214. }
  215. /// <summary>
  216. /// 颗粒里+号位置的外边框大小
  217. /// </summary>
  218. public RectangleF GetSmallRect()
  219. {
  220. m_smallRect=this.GetSmallRectangleFromRect();
  221. return m_smallRect;
  222. }
  223. public bool IsSelect
  224. {
  225. get { return m_isSelected; }
  226. set { m_isSelected = value; }
  227. }
  228. /// <summary>
  229. /// 该颗粒是否被设置成,选中状态
  230. /// </summary>
  231. public PaintState GetPaintState()
  232. {
  233. if (GetDisplayState() == DisplayState.NODISPLAY)
  234. {
  235. m_paintState = PaintState.NOPAINT;
  236. }
  237. return m_paintState;
  238. }
  239. /// <summary>
  240. /// 该颗粒是否被设置成,选中状态
  241. /// </summary>
  242. public void SetPaintState(PaintState value)
  243. {
  244. if (value == PaintState.PAINT)
  245. {
  246. if (m_CurrentZoomNum >= m_zoom_displayThreshold)
  247. {
  248. m_paintState = PaintState.PAINT;
  249. }
  250. else
  251. {
  252. m_paintState = PaintState.CONCISEPAINT;
  253. }
  254. }
  255. else
  256. {
  257. m_paintState = value;
  258. }
  259. }
  260. /// <summary>
  261. /// 是否对该颗粒选定显示X-Ray能谱图
  262. /// </summary>
  263. public ParticleShowXray Operator_ShowXRay
  264. {
  265. get { return m_operator_showxray; }
  266. set { m_operator_showxray = value; }
  267. }
  268. /// <summary>
  269. /// 是否显示x号
  270. /// </summary>
  271. public bool IsShowSmallX
  272. {
  273. get { return m_showSmallx; }
  274. set { m_showSmallx = value; }
  275. }
  276. /// <summary>
  277. /// 颗粒的x-ray的点,是否被选择上了
  278. /// </summary>
  279. public bool IsSelectedSmallRect
  280. {
  281. get { return m_isSelected_smallrect; }
  282. set { m_isSelected_smallrect = value; }
  283. }
  284. /// <summary>
  285. /// 是否在被拖动
  286. /// </summary>
  287. public bool IsDragging
  288. {
  289. get { return m_isdragging; }
  290. set { m_isdragging = value; }
  291. }
  292. /// <summary>
  293. /// 被拖动到的位置坐标
  294. /// </summary>
  295. public PointF DraggingPoint
  296. {
  297. get { return m_dragingpoint; }
  298. set {
  299. m_dragingpoint = value;
  300. }
  301. }
  302. /// <summary>
  303. /// 线的颜色
  304. /// </summary>
  305. public Color Color
  306. {
  307. get { return m_color; }
  308. set { m_color = value; }
  309. }
  310. /// <summary>
  311. /// 多边形的图形路径边缘
  312. /// </summary>
  313. public GraphicsPath GetGPath()
  314. {
  315. m_gpath = this.GetRegionFromDSegments();
  316. return m_gpath;
  317. }
  318. /// <summary>
  319. /// 里面包含的多个线的集合
  320. /// </summary>
  321. public List<DisplaySegment> GetDSegments()
  322. { return m_listdsegment; }
  323. /// <summary>
  324. /// 里面包含的多个线的集合
  325. /// </summary>
  326. public void SetDSegments(List<DisplaySegment> value)
  327. {
  328. m_listdsegment = value;
  329. m_rect=GetRectFromDSegment();
  330. m_gpath=GetRegionFromDSegments();
  331. m_smallRect=GetSmallRectangleFromRect();
  332. }
  333. public void Zoom(float zoomDelta,PointF refPoint)
  334. {
  335. for (int y = 0; y < this.GetDSegments().Count(); y++)
  336. {
  337. //这里重新设置每条线的高度,和x,y坐标
  338. DisplaySegment ds = this.GetDSegments()[y];
  339. var rec = ds.GetShowRect();
  340. rec.Width = (float)(rec.Width + Convert.ToDouble(rec.Width/m_CurrentZoomNum * zoomDelta));
  341. rec.Height = (float)(rec.Height + Convert.ToDouble(rec.Height/m_CurrentZoomNum * zoomDelta));
  342. //锚点缩放补差值计算,得出差值
  343. float xShiftOld = rec.X - refPoint.X;
  344. float yShiftOld = rec.Y - refPoint.Y;
  345. float xShift = rec.X - refPoint.X + xShiftOld/m_CurrentZoomNum * zoomDelta;
  346. float yShift = rec.Y - refPoint.Y + yShiftOld/m_CurrentZoomNum * zoomDelta;
  347. //对背景矩形与所有的segment进行修补差值
  348. rec.X = refPoint.X + xShift;
  349. rec.Y = refPoint.Y + yShift;
  350. ds.SetShowRect(rec);
  351. }
  352. m_rect=GetRectFromDSegment();
  353. //重新计算小矩形边框
  354. m_smallRect=GetSmallRectangleFromRect();
  355. //设置缩放到多少倍时进行显示
  356. if (m_CurrentZoomNum >= m_zoom_displayThreshold)
  357. {
  358. m_paintState = PaintState.PAINT;
  359. }
  360. else
  361. {
  362. m_paintState = PaintState.CONCISEPAINT;
  363. }
  364. m_CurrentZoomNum += zoomDelta;
  365. }
  366. public void DraggingMove(PointF mousePoint)
  367. {
  368. foreach (DisplaySegment ds in this.GetDSegments())
  369. {
  370. var rec = ds.GetShowRect();
  371. rec.X = ds.GetShowRect().X + mousePoint.X - this.DraggingPoint.X; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  372. rec.Y = ds.GetShowRect().Y + mousePoint.Y - this.DraggingPoint.Y;
  373. ds.SetShowRect(rec);
  374. }
  375. this.DraggingPoint = mousePoint;
  376. //获取矩形的rectangle
  377. m_rect = GetRectFromDSegment();
  378. ////重新计算小矩形边框
  379. m_smallRect = GetSmallRectangleFromRect();
  380. }
  381. public void Move(SizeF xyShift)
  382. {
  383. foreach (DisplaySegment ds in this.GetDSegments())
  384. {
  385. var rec = ds.GetShowRect();
  386. rec.X = ds.GetShowRect().X -xyShift.Width; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  387. rec.Y = ds.GetShowRect().Y - xyShift.Height ;
  388. ds.SetShowRect(rec);
  389. }
  390. //获取矩形的rectangle
  391. m_rect = GetRectFromDSegment();
  392. //重新计算小矩形边框
  393. m_smallRect = GetSmallRectangleFromRect();
  394. }
  395. /// <summary>
  396. /// 设置排序的类型
  397. /// </summary>
  398. public string SortType
  399. {
  400. get { return m_sort_type; }
  401. set { m_sort_type = value; }
  402. }
  403. /// <summary>
  404. /// 设置该多边形的尺寸大小
  405. /// </summary>
  406. public float FSize
  407. {
  408. get { return m_f_size; }
  409. set { m_f_size = value; }
  410. }
  411. /// <summary>
  412. /// 设置粒级
  413. /// </summary>
  414. public string ParticleLJ
  415. {
  416. get { return m_str_lj; }
  417. set { m_str_lj = value; }
  418. }
  419. /// <summary>
  420. /// 设置种类
  421. /// </summary>
  422. public string ParticleZL
  423. {
  424. get { return m_str_klzl; }
  425. set { m_str_klzl = value; }
  426. }
  427. /// <summary>
  428. /// 设置分类
  429. /// </summary>
  430. public string ParticleFL
  431. {
  432. get { return m_str_klfl; }
  433. set { m_str_klfl = value; }
  434. }
  435. /// <summary>
  436. /// 获取或设置该Particle对应底层的FieldID值
  437. /// </summary>
  438. public int FieldId
  439. {
  440. get { return objParticleData.FieldId; }
  441. }
  442. /// <summary>
  443. /// 获取或设置该Particle对应底层的ParticleID值
  444. /// </summary>
  445. public int ParticleId
  446. {
  447. get { return objParticleData.ParticleId; }
  448. }
  449. public bool IsDeleted { get => m_isDeleted; set => m_isDeleted = value; }
  450. public bool IsMouseOver { get => m_isMouseOver; set => m_isMouseOver = value; }
  451. public Image GetImage()
  452. {
  453. return m_image;
  454. }
  455. public void SetImage(Image value)
  456. {
  457. m_image = value;
  458. }
  459. public DisplayState GetDisplayState()
  460. {
  461. if (m_isDeleted)
  462. {
  463. m_displayState = DisplayState.NODISPLAY;
  464. }
  465. return m_displayState;
  466. }
  467. public void SetDisplayState(DisplayState value)
  468. {
  469. m_displayState = value;
  470. }
  471. /// <summary>
  472. /// 绘制函数
  473. /// </summary>
  474. /// <param name="e"></param>
  475. public void OnPaint(PaintEventArgs e)
  476. {
  477. Graphics g = e.Graphics;
  478. //绘制鼠标移动到颗粒上时的边框,需要判断当前鼠标在颗粒上,及颗粒的操作为正常显示
  479. if (m_isMouseOver == true)
  480. {
  481. //如果有鼠标在该矩形上,那么进行描边
  482. ControlPaint.DrawBorder(g,
  483. Rectangle.Round(this.GetShowRect()),
  484. Color.Lime,
  485. 1,
  486. ButtonBorderStyle.Solid,
  487. Color.Lime,
  488. 1,
  489. ButtonBorderStyle.Solid,
  490. Color.Lime,
  491. 1,
  492. ButtonBorderStyle.Solid,
  493. Color.Lime,
  494. 1,
  495. ButtonBorderStyle.Solid);
  496. }
  497. if (GetPaintState() == PaintState.PAINT)
  498. {
  499. if (m_listdsegment.Count > 0)
  500. {
  501. //DisplaySegment ds = m_listdsegment[0];
  502. if (this.ShowMode == SegmentShowMode.DRAWPOINT)
  503. {
  504. //try
  505. //{
  506. e.Graphics.DrawImage(m_image, m_rect);
  507. //}
  508. //catch (Exception ex)
  509. //{
  510. // NLog.LogManager.GetCurrentClassLogger().Error(ex.ToString());
  511. //}
  512. }
  513. else
  514. {
  515. //调用绘制基本线
  516. foreach (DisplaySegment item in m_listdsegment)
  517. {
  518. item.OnPaint(e);
  519. }
  520. }
  521. }
  522. }
  523. if (GetPaintState() == PaintState.CONCISEPAINT)
  524. {
  525. g.DrawString("+", new Font("黑体", 6), new SolidBrush(Color.DarkSlateBlue), new PointF(m_smallRect.X, m_smallRect.Y));
  526. }
  527. if (m_isSelected)
  528. {
  529. //如果説该矩形被选择上了的话,那么也显示边框
  530. ControlPaint.DrawBorder(g,
  531. Rectangle.Round(this.GetShowRect()),
  532. Color.Blue,
  533. 1,
  534. ButtonBorderStyle.Solid,
  535. Color.Blue,
  536. 1,
  537. ButtonBorderStyle.Solid,
  538. Color.Blue,
  539. 1,
  540. ButtonBorderStyle.Solid,
  541. Color.Blue,
  542. 1,
  543. ButtonBorderStyle.Solid);
  544. }
  545. if (ParticleShowXray.DISPLAYXRAY == m_operator_showxray && PaintState.NOPAINT != GetPaintState())
  546. {
  547. //当鼠标在该颗粒上进行点击,则对颗粒状态更改为选定状态,用来显示X-ray能谱表
  548. ControlPaint.DrawBorder(g,
  549. Rectangle.Round(this.GetShowRect()),
  550. Color.DeepSkyBlue,
  551. 1,
  552. ButtonBorderStyle.Solid,
  553. Color.DeepSkyBlue,
  554. 1,
  555. ButtonBorderStyle.Solid,
  556. Color.DeepSkyBlue,
  557. 1,
  558. ButtonBorderStyle.Solid,
  559. Color.DeepSkyBlue,
  560. 1,
  561. ButtonBorderStyle.Solid);
  562. }
  563. }
  564. /// <summary>
  565. /// 从Line中获取矩形的边缘闭合路径
  566. /// </summary>
  567. /// <returns></returns>
  568. private GraphicsPath GetRegionFromDSegments()
  569. {
  570. GraphicsPath gpath = new GraphicsPath();
  571. List<PointF> list_leftpointf = new List<PointF>();
  572. List<PointF> list_rightpointf = new List<PointF>();
  573. //从y循环,这里假设y轴会按lines集合来计算,然后将所有的左x,和右x取出排成两个队列
  574. foreach (DisplaySegment ds in this.m_listdsegment)
  575. {
  576. list_leftpointf.Add(new PointF(ds.GetShowRect().X, ds.GetShowRect().Y));
  577. list_rightpointf.Add(new PointF(ds.GetShowRect().X + ds.GetShowRect().Width, ds.GetShowRect().Y));
  578. }
  579. PointF[] lsp = new PointF[list_leftpointf.Count + list_rightpointf.Count];
  580. //再将两个x,y点依次添加到闭合路径中
  581. for (int i = 0; i < list_leftpointf.Count(); i++)
  582. {
  583. lsp[i] = list_leftpointf[i];
  584. }
  585. //右节点
  586. for (int i = 0; i < list_rightpointf.Count(); i++)
  587. {
  588. //这边倒着存入
  589. lsp[list_rightpointf.Count() + i] = list_rightpointf[list_rightpointf.Count() - i - 1];
  590. }
  591. //防止从低层拿到无数据的外边路径,在我的程序里却需要计算,而防止程序报死,这里做一下特殊处理。
  592. if (lsp.Count() >= 3)
  593. {
  594. gpath.AddPolygon(lsp);
  595. }
  596. else
  597. {
  598. //有时居然有颗粒,有没有segment的时候,防止报错
  599. if (this.GetDSegments().Count == 0)
  600. {
  601. lsp = new PointF[3] { new PointF(0, 0), new PointF(0, 0), new PointF(0, 0) };
  602. gpath.AddPolygon(lsp);
  603. return gpath;
  604. }
  605. //有2条数据
  606. if (lsp[1].X != 0 && lsp[1].Y != 0)
  607. {
  608. lsp = new PointF[3] { new PointF(lsp[0].X, lsp[0].Y), new PointF(lsp[1].X, lsp[1].Y), new PointF(lsp[1].X, lsp[1].Y) };
  609. }
  610. //有1条数据
  611. else if (lsp[0].X != 0 && lsp[0].Y != 0)
  612. {
  613. lsp = new PointF[3] { new PointF(lsp[0].X, lsp[0].Y), new PointF(lsp[0].X, lsp[0].Y), new PointF(lsp[0].X, lsp[0].Y) };
  614. }
  615. //剩下的情况
  616. else
  617. {
  618. lsp = new PointF[3] { new PointF(0, 0), new PointF(0, 0), new PointF(0,0) };
  619. }
  620. gpath.AddPolygon(lsp);
  621. }
  622. return gpath;
  623. }
  624. /// <summary>
  625. /// 从已经确定的外边框来计算出里面的+号小框位置
  626. /// </summary>
  627. /// <returns></returns>
  628. private RectangleF GetSmallRectangleFromRect()
  629. {
  630. RectangleF rect = new RectangleF();
  631. //用外边框的坐标,除2获得中心点,然后再分别+,- 4
  632. float x = 0, y = 0;
  633. x = m_rect.X + (m_rect.Width / 2);
  634. y = m_rect.Y + (m_rect.Height / 2);
  635. rect.X = x - 4;
  636. rect.Y = y - 4;
  637. rect.Width = 8;
  638. rect.Height = 4;
  639. return rect;
  640. }
  641. /// <summary>
  642. /// 根据该多边形所有包含的线长度,计算出,该多边形的面积大小
  643. /// </summary>
  644. /// <returns></returns>
  645. public float GetAreaFormSegments()
  646. {
  647. float f_size_sum = 0;
  648. foreach (DisplaySegment ls_ds in this.m_listdsegment)
  649. {
  650. f_size_sum = f_size_sum + ls_ds.GetShowRect().Width;
  651. }
  652. return f_size_sum;
  653. }
  654. /// <summary>
  655. /// 从基本线中获取整个矩形的Rectangle
  656. /// </summary>
  657. /// <returns></returns>
  658. private RectangleF GetRectFromDSegment()
  659. {
  660. RectangleF rect = new RectangleF();
  661. float x1 = 0, y1 = 0;
  662. float i_width = 0, i_height = 0;
  663. //先从自身中初始化x,y,和宽,高
  664. if (this.m_listdsegment.Count > 0)
  665. {
  666. x1 = this.m_listdsegment[0].GetShowRect().X;
  667. y1 = this.m_listdsegment[0].GetShowRect().Y;
  668. i_width = x1 + this.m_listdsegment[0].GetShowRect().Width;
  669. i_height = this.m_listdsegment[0].GetShowRect().Y;
  670. }
  671. foreach (DisplaySegment ds in this.m_listdsegment)
  672. {
  673. //分别取出,最小的x,y,
  674. if (ds.GetShowRect().X < x1)
  675. {
  676. x1 = ds.GetShowRect().X;
  677. }
  678. if (ds.GetShowRect().Y < y1)
  679. {
  680. y1 = ds.GetShowRect().Y;
  681. }
  682. //最大的x,y
  683. if (ds.GetShowRect().X + ds.GetShowRect().Width > i_width)
  684. {
  685. i_width = ds.GetShowRect().X + ds.GetShowRect().Width;
  686. }
  687. if (ds.GetShowRect().Y > i_height)
  688. {
  689. i_height = ds.GetShowRect().Y;
  690. }
  691. }
  692. rect.X = x1 ;
  693. rect.Y = y1 ;
  694. rect.Width = i_width - rect.X ;
  695. rect.Height = i_height - rect.Y ;
  696. return rect;
  697. }
  698. }
  699. }