DisplayParticle.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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. this.m_image = in_particle.m_image;
  168. m_rect = GetRectFromDSegment();
  169. m_smallRect = GetSmallRectangleFromRect();
  170. m_gpath = GetRegionFromDSegments();
  171. }
  172. /// <summary>
  173. /// 设置显示的方式,可以用,绘线显示查看标准库颜色的,也可以用绘点,查看BSE原图颗粒图色的
  174. /// </summary>
  175. public SegmentShowMode ShowMode
  176. {
  177. get { return show_mode; }
  178. set { show_mode = value; }
  179. }
  180. /// <summary>
  181. /// 克隆方法
  182. /// </summary>
  183. /// <returns></returns>
  184. public object Clone()
  185. {
  186. return new DisplayParticle(this.m_listdsegment, this);
  187. }
  188. public PointF GetCenterPoint()
  189. {
  190. return new PointF(m_rect.X + m_rect.Width / 2, m_rect.Y + m_rect.Height / 2);
  191. }
  192. /// <summary>
  193. /// ID
  194. /// </summary>
  195. public Guid guid
  196. {
  197. get { return m_id; }
  198. set { m_id = value; }
  199. }
  200. /// <summary>
  201. /// 颗粒的外边框大小
  202. /// </summary>
  203. public RectangleF GetShowRect()
  204. {
  205. m_rect= this.GetRectFromDSegment();
  206. return m_rect;
  207. }
  208. /// <summary>
  209. /// OTSPointF
  210. /// </summary>
  211. public PointF OTSPointF
  212. {
  213. get { return m_OTSPointF; }
  214. set { m_OTSPointF = value; }
  215. }
  216. /// <summary>
  217. /// 颗粒里+号位置的外边框大小
  218. /// </summary>
  219. public RectangleF GetSmallRect()
  220. {
  221. m_smallRect=this.GetSmallRectangleFromRect();
  222. return m_smallRect;
  223. }
  224. public bool IsSelect
  225. {
  226. get { return m_isSelected; }
  227. set { m_isSelected = value; }
  228. }
  229. /// <summary>
  230. /// 该颗粒是否被设置成,选中状态
  231. /// </summary>
  232. public PaintState GetPaintState()
  233. {
  234. if (GetDisplayState() == DisplayState.NODISPLAY)
  235. {
  236. m_paintState = PaintState.NOPAINT;
  237. }
  238. return m_paintState;
  239. }
  240. /// <summary>
  241. /// 该颗粒是否被设置成,选中状态
  242. /// </summary>
  243. public void SetPaintState(PaintState value)
  244. {
  245. if (value == PaintState.PAINT)
  246. {
  247. if (m_CurrentZoomNum >= m_zoom_displayThreshold)
  248. {
  249. m_paintState = PaintState.PAINT;
  250. }
  251. else
  252. {
  253. m_paintState = PaintState.CONCISEPAINT;
  254. }
  255. }
  256. else
  257. {
  258. m_paintState = value;
  259. }
  260. }
  261. /// <summary>
  262. /// 是否对该颗粒选定显示X-Ray能谱图
  263. /// </summary>
  264. public ParticleShowXray Operator_ShowXRay
  265. {
  266. get { return m_operator_showxray; }
  267. set { m_operator_showxray = value; }
  268. }
  269. /// <summary>
  270. /// 是否显示x号
  271. /// </summary>
  272. public bool IsShowSmallX
  273. {
  274. get { return m_showSmallx; }
  275. set { m_showSmallx = value; }
  276. }
  277. /// <summary>
  278. /// 颗粒的x-ray的点,是否被选择上了
  279. /// </summary>
  280. public bool IsSelectedSmallRect
  281. {
  282. get { return m_isSelected_smallrect; }
  283. set { m_isSelected_smallrect = value; }
  284. }
  285. /// <summary>
  286. /// 是否在被拖动
  287. /// </summary>
  288. public bool IsDragging
  289. {
  290. get { return m_isdragging; }
  291. set { m_isdragging = value; }
  292. }
  293. /// <summary>
  294. /// 被拖动到的位置坐标
  295. /// </summary>
  296. public PointF DraggingPoint
  297. {
  298. get { return m_dragingpoint; }
  299. set {
  300. m_dragingpoint = value;
  301. }
  302. }
  303. /// <summary>
  304. /// 线的颜色
  305. /// </summary>
  306. public Color Color
  307. {
  308. get { return m_color; }
  309. set { m_color = value; }
  310. }
  311. /// <summary>
  312. /// 多边形的图形路径边缘
  313. /// </summary>
  314. public GraphicsPath GetGPath()
  315. {
  316. m_gpath = this.GetRegionFromDSegments();
  317. return m_gpath;
  318. }
  319. /// <summary>
  320. /// 里面包含的多个线的集合
  321. /// </summary>
  322. public List<DisplaySegment> GetDSegments()
  323. { return m_listdsegment; }
  324. /// <summary>
  325. /// 里面包含的多个线的集合
  326. /// </summary>
  327. public void SetDSegments(List<DisplaySegment> value)
  328. {
  329. m_listdsegment = value;
  330. m_rect=GetRectFromDSegment();
  331. m_gpath=GetRegionFromDSegments();
  332. m_smallRect=GetSmallRectangleFromRect();
  333. }
  334. public void Zoom(float zoomDelta,PointF refPoint)
  335. {
  336. var segs = this.GetDSegments();
  337. for (int y = 0; y < segs.Count(); y++)
  338. {
  339. DisplaySegment ds = segs[y];
  340. var rec = ds.GetShowRect();
  341. rec.Width = (float)(rec.Width + Convert.ToDouble(rec.Width/m_CurrentZoomNum * zoomDelta));
  342. rec.Height = (float)(rec.Height + Convert.ToDouble(rec.Height/m_CurrentZoomNum * zoomDelta));
  343. //锚点缩放补差值计算,得出差值
  344. float xShiftOld = rec.X - refPoint.X;
  345. float yShiftOld = rec.Y - refPoint.Y;
  346. float xShift = rec.X - refPoint.X + xShiftOld/m_CurrentZoomNum * zoomDelta;
  347. float yShift = rec.Y - refPoint.Y + yShiftOld/m_CurrentZoomNum * zoomDelta;
  348. //对背景矩形与所有的segment进行修补差值
  349. rec.X = refPoint.X + xShift;
  350. rec.Y = refPoint.Y + yShift;
  351. ds.SetShowRect(rec);
  352. }
  353. m_rect=GetRectFromDSegment();
  354. //重新计算小矩形边框
  355. m_smallRect=GetSmallRectangleFromRect();
  356. //设置缩放到多少倍时进行显示
  357. if (m_CurrentZoomNum >= m_zoom_displayThreshold)
  358. {
  359. m_paintState = PaintState.PAINT;
  360. }
  361. else
  362. {
  363. m_paintState = PaintState.CONCISEPAINT;
  364. }
  365. m_CurrentZoomNum += zoomDelta;
  366. }
  367. public void DraggingMove(PointF mousePoint)
  368. {
  369. foreach (DisplaySegment ds in this.GetDSegments())
  370. {
  371. var rec = ds.GetShowRect();
  372. rec.X = ds.GetShowRect().X + mousePoint.X - this.DraggingPoint.X; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  373. rec.Y = ds.GetShowRect().Y + mousePoint.Y - this.DraggingPoint.Y;
  374. ds.SetShowRect(rec);
  375. }
  376. this.DraggingPoint = mousePoint;
  377. //获取矩形的rectangle
  378. m_rect = GetRectFromDSegment();
  379. ////重新计算小矩形边框
  380. m_smallRect = GetSmallRectangleFromRect();
  381. }
  382. public void Move(SizeF xyShift)
  383. {
  384. foreach (DisplaySegment ds in this.GetDSegments())
  385. {
  386. var rec = ds.GetShowRect();
  387. rec.X = ds.GetShowRect().X -xyShift.Width; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  388. rec.Y = ds.GetShowRect().Y - xyShift.Height ;
  389. ds.SetShowRect(rec);
  390. }
  391. //获取矩形的rectangle
  392. m_rect = GetRectFromDSegment();
  393. //重新计算小矩形边框
  394. m_smallRect = GetSmallRectangleFromRect();
  395. }
  396. /// <summary>
  397. /// 设置排序的类型
  398. /// </summary>
  399. public string SortType
  400. {
  401. get { return m_sort_type; }
  402. set { m_sort_type = value; }
  403. }
  404. /// <summary>
  405. /// 设置该多边形的尺寸大小
  406. /// </summary>
  407. public float FSize
  408. {
  409. get { return m_f_size; }
  410. set { m_f_size = value; }
  411. }
  412. /// <summary>
  413. /// 设置粒级
  414. /// </summary>
  415. public string ParticleLJ
  416. {
  417. get { return m_str_lj; }
  418. set { m_str_lj = value; }
  419. }
  420. /// <summary>
  421. /// 设置种类
  422. /// </summary>
  423. public string ParticleZL
  424. {
  425. get { return m_str_klzl; }
  426. set { m_str_klzl = value; }
  427. }
  428. /// <summary>
  429. /// 设置分类
  430. /// </summary>
  431. public string ParticleFL
  432. {
  433. get { return m_str_klfl; }
  434. set { m_str_klfl = value; }
  435. }
  436. /// <summary>
  437. /// 获取或设置该Particle对应底层的FieldID值
  438. /// </summary>
  439. public int FieldId
  440. {
  441. get { return objParticleData.FieldId; }
  442. }
  443. /// <summary>
  444. /// 获取或设置该Particle对应底层的ParticleID值
  445. /// </summary>
  446. public int ParticleId
  447. {
  448. get { return objParticleData.ParticleId; }
  449. }
  450. public bool IsDeleted { get => m_isDeleted; set => m_isDeleted = value; }
  451. public bool IsMouseOver { get => m_isMouseOver; set => m_isMouseOver = value; }
  452. public Image GetImage()
  453. {
  454. return m_image;
  455. }
  456. public void SetImage(Image value)
  457. {
  458. m_image = value;
  459. }
  460. public DisplayState GetDisplayState()
  461. {
  462. if (m_isDeleted)
  463. {
  464. m_displayState = DisplayState.NODISPLAY;
  465. }
  466. return m_displayState;
  467. }
  468. public void SetDisplayState(DisplayState value)
  469. {
  470. m_displayState = value;
  471. }
  472. /// <summary>
  473. /// 绘制函数
  474. /// </summary>
  475. /// <param name="e"></param>
  476. public void OnPaint(PaintEventArgs e)
  477. {
  478. Graphics g = e.Graphics;
  479. //绘制鼠标移动到颗粒上时的边框,需要判断当前鼠标在颗粒上,及颗粒的操作为正常显示
  480. if (m_isMouseOver == true)
  481. {
  482. //如果有鼠标在该矩形上,那么进行描边
  483. ControlPaint.DrawBorder(g,
  484. Rectangle.Round(this.GetShowRect()),
  485. Color.Lime,
  486. 1,
  487. ButtonBorderStyle.Solid,
  488. Color.Lime,
  489. 1,
  490. ButtonBorderStyle.Solid,
  491. Color.Lime,
  492. 1,
  493. ButtonBorderStyle.Solid,
  494. Color.Lime,
  495. 1,
  496. ButtonBorderStyle.Solid);
  497. }
  498. if (GetPaintState() == PaintState.PAINT)
  499. {
  500. if (m_listdsegment.Count > 0)
  501. {
  502. //DisplaySegment ds = m_listdsegment[0];
  503. if (this.ShowMode == SegmentShowMode.DRAWPOINT)
  504. {
  505. //try
  506. //{
  507. e.Graphics.DrawImage(m_image, m_rect);
  508. //}
  509. //catch (Exception ex)
  510. //{
  511. // NLog.LogManager.GetCurrentClassLogger().Error(ex.ToString());
  512. //}
  513. }
  514. else
  515. {
  516. //调用绘制基本线
  517. foreach (DisplaySegment item in m_listdsegment)
  518. {
  519. item.OnPaint(e);
  520. }
  521. }
  522. }
  523. }
  524. if (GetPaintState() == PaintState.CONCISEPAINT)
  525. {
  526. g.DrawString("+", new Font("黑体", 6), new SolidBrush(Color.DarkSlateBlue), new PointF(m_smallRect.X, m_smallRect.Y));
  527. }
  528. if (m_isSelected)
  529. {
  530. //如果説该矩形被选择上了的话,那么也显示边框
  531. ControlPaint.DrawBorder(g,
  532. Rectangle.Round(this.GetShowRect()),
  533. Color.Blue,
  534. 1,
  535. ButtonBorderStyle.Solid,
  536. Color.Blue,
  537. 1,
  538. ButtonBorderStyle.Solid,
  539. Color.Blue,
  540. 1,
  541. ButtonBorderStyle.Solid,
  542. Color.Blue,
  543. 1,
  544. ButtonBorderStyle.Solid);
  545. }
  546. if (ParticleShowXray.DISPLAYXRAY == m_operator_showxray && PaintState.NOPAINT != GetPaintState())
  547. {
  548. //当鼠标在该颗粒上进行点击,则对颗粒状态更改为选定状态,用来显示X-ray能谱表
  549. ControlPaint.DrawBorder(g,
  550. Rectangle.Round(this.GetShowRect()),
  551. Color.DeepSkyBlue,
  552. 1,
  553. ButtonBorderStyle.Solid,
  554. Color.DeepSkyBlue,
  555. 1,
  556. ButtonBorderStyle.Solid,
  557. Color.DeepSkyBlue,
  558. 1,
  559. ButtonBorderStyle.Solid,
  560. Color.DeepSkyBlue,
  561. 1,
  562. ButtonBorderStyle.Solid);
  563. }
  564. }
  565. /// <summary>
  566. /// 从Line中获取矩形的边缘闭合路径
  567. /// </summary>
  568. /// <returns></returns>
  569. private GraphicsPath GetRegionFromDSegments()
  570. {
  571. GraphicsPath gpath = new GraphicsPath();
  572. List<PointF> list_leftpointf = new List<PointF>();
  573. List<PointF> list_rightpointf = new List<PointF>();
  574. //从y循环,这里假设y轴会按lines集合来计算,然后将所有的左x,和右x取出排成两个队列
  575. foreach (DisplaySegment ds in this.m_listdsegment)
  576. {
  577. list_leftpointf.Add(new PointF(ds.GetShowRect().X, ds.GetShowRect().Y));
  578. list_rightpointf.Add(new PointF(ds.GetShowRect().X + ds.GetShowRect().Width, ds.GetShowRect().Y));
  579. }
  580. PointF[] lsp = new PointF[list_leftpointf.Count + list_rightpointf.Count];
  581. //再将两个x,y点依次添加到闭合路径中
  582. for (int i = 0; i < list_leftpointf.Count(); i++)
  583. {
  584. lsp[i] = list_leftpointf[i];
  585. }
  586. //右节点
  587. for (int i = 0; i < list_rightpointf.Count(); i++)
  588. {
  589. //这边倒着存入
  590. lsp[list_rightpointf.Count() + i] = list_rightpointf[list_rightpointf.Count() - i - 1];
  591. }
  592. //防止从低层拿到无数据的外边路径,在我的程序里却需要计算,而防止程序报死,这里做一下特殊处理。
  593. if (lsp.Count() >= 3)
  594. {
  595. gpath.AddPolygon(lsp);
  596. }
  597. else
  598. {
  599. //有时居然有颗粒,有没有segment的时候,防止报错
  600. if (this.GetDSegments().Count == 0)
  601. {
  602. lsp = new PointF[3] { new PointF(0, 0), new PointF(0, 0), new PointF(0, 0) };
  603. gpath.AddPolygon(lsp);
  604. return gpath;
  605. }
  606. //有2条数据
  607. if (lsp[1].X != 0 && lsp[1].Y != 0)
  608. {
  609. 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) };
  610. }
  611. //有1条数据
  612. else if (lsp[0].X != 0 && lsp[0].Y != 0)
  613. {
  614. 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) };
  615. }
  616. //剩下的情况
  617. else
  618. {
  619. lsp = new PointF[3] { new PointF(0, 0), new PointF(0, 0), new PointF(0,0) };
  620. }
  621. gpath.AddPolygon(lsp);
  622. }
  623. return gpath;
  624. }
  625. /// <summary>
  626. /// 从已经确定的外边框来计算出里面的+号小框位置
  627. /// </summary>
  628. /// <returns></returns>
  629. private RectangleF GetSmallRectangleFromRect()
  630. {
  631. RectangleF rect = new RectangleF();
  632. //用外边框的坐标,除2获得中心点,然后再分别+,- 4
  633. float x = 0, y = 0;
  634. x = m_rect.X + (m_rect.Width / 2);
  635. y = m_rect.Y + (m_rect.Height / 2);
  636. rect.X = x - 4;
  637. rect.Y = y - 4;
  638. rect.Width = 8;
  639. rect.Height = 4;
  640. return rect;
  641. }
  642. /// <summary>
  643. /// 根据该多边形所有包含的线长度,计算出,该多边形的面积大小
  644. /// </summary>
  645. /// <returns></returns>
  646. public float GetAreaFormSegments()
  647. {
  648. float f_size_sum = 0;
  649. foreach (DisplaySegment ls_ds in this.m_listdsegment)
  650. {
  651. f_size_sum = f_size_sum + ls_ds.GetShowRect().Width;
  652. }
  653. return f_size_sum;
  654. }
  655. /// <summary>
  656. /// 从基本线中获取整个矩形的Rectangle
  657. /// </summary>
  658. /// <returns></returns>
  659. private RectangleF GetRectFromDSegment()
  660. {
  661. RectangleF rect = new RectangleF();
  662. float x1 = 0, y1 = 0;
  663. float i_width = 0, i_height = 0;
  664. //先从自身中初始化x,y,和宽,高
  665. if (this.m_listdsegment.Count > 0)
  666. {
  667. x1 = this.m_listdsegment[0].GetShowRect().X;
  668. y1 = this.m_listdsegment[0].GetShowRect().Y;
  669. i_width = x1 + this.m_listdsegment[0].GetShowRect().Width;
  670. i_height = this.m_listdsegment[0].GetShowRect().Y;
  671. }
  672. foreach (DisplaySegment ds in this.m_listdsegment)
  673. {
  674. //分别取出,最小的x,y,
  675. if (ds.GetShowRect().X < x1)
  676. {
  677. x1 = ds.GetShowRect().X;
  678. }
  679. if (ds.GetShowRect().Y < y1)
  680. {
  681. y1 = ds.GetShowRect().Y;
  682. }
  683. //最大的x,y
  684. if (ds.GetShowRect().X + ds.GetShowRect().Width > i_width)
  685. {
  686. i_width = ds.GetShowRect().X + ds.GetShowRect().Width;
  687. }
  688. if (ds.GetShowRect().Y > i_height)
  689. {
  690. i_height = ds.GetShowRect().Y;
  691. }
  692. }
  693. rect.X = x1 ;
  694. rect.Y = y1 ;
  695. rect.Width = i_width - rect.X ;
  696. rect.Height = i_height - rect.Y ;
  697. return rect;
  698. }
  699. }
  700. }