DisplayParticle.cs 29 KB

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