DisplayParticle.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. using DevExpress.Utils.Extensions;
  2. using OTSCommon.DBOperate.Model;
  3. using OTSIncAReportGraph.Class;
  4. using OTSMeasureApp._0_OTSModel.OTSDataType;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Drawing;
  9. using System.Drawing.Drawing2D;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace OTSIncAReportGraph
  15. {
  16. /// <summary>
  17. /// Particle对象上操作状态的枚举
  18. /// </summary>
  19. public enum PaintState
  20. {
  21. PAINT = 0,
  22. NOPAINT = 1,
  23. CONCISEPAINT=2,// display as a "+"
  24. }
  25. public enum DisplayState
  26. {
  27. DISPLAY = 0,
  28. NODISPLAY = 1,
  29. }
  30. /// <summary>
  31. /// Particle对象上操作xray的枚举状态,显示xray数据,不显示
  32. /// </summary>
  33. public enum ParticleShowXray
  34. {
  35. DISPLAYXRAY = 0,
  36. NODISPLAY = 1,
  37. }
  38. /// <summary>
  39. /// Segment对象绘制的枚举,以点绘制,还是以线绘制
  40. /// </summary>
  41. public enum SegmentShowMode
  42. {
  43. DRAWPARTICLEIMAGE = 0,
  44. DRAWCOLORIMAGE = 1,
  45. DRAWGROUPCOLORIMAGE = 2
  46. }
  47. /// <summary>
  48. /// 颗粒类
  49. /// </summary>
  50. public class DisplayParticle : ICloneable
  51. {
  52. private const float m_zoom_displayThreshold = 0.1f;
  53. public Particle objParticleData;
  54. private Guid m_id;
  55. private RectangleF m_Globalrect;
  56. private PointF m_OTSPointF;
  57. private RectangleF m_smallRect;
  58. private bool m_isSelected;
  59. private bool m_isDeleted;
  60. private bool m_isMouseOver;
  61. private PaintState m_paintState = PaintState.PAINT;
  62. private ParticleShowXray m_operator_showxray = ParticleShowXray.NODISPLAY;//选定显示XRAY,不显示XRAY,默认应为(不显示XRAY)
  63. private bool m_isdragging;
  64. private PointF m_dragingpoint;
  65. private Color m_color;
  66. private DisplayState m_displayState;
  67. private SegmentShowMode show_mode = SegmentShowMode.DRAWPARTICLEIMAGE;//绘线,绘点,默认绘点,意思为默认显示BSE原图像
  68. private Bitmap m_BSEimage;
  69. private Bitmap m_Colorimage;
  70. private Bitmap m_GroupColorimage;
  71. private Bitmap originalFieldImage;
  72. private string m_sort_type = "从大到小";
  73. private float m_f_size = 0;
  74. private string m_str_lj = "颗粒粒级";
  75. private string m_str_klzl = "颗粒种类";
  76. private string m_str_klfl = "颗粒分类";
  77. private float m_CurrentZoomNum = 1;
  78. public COTSRect OTSRect=new COTSRect();
  79. public int TypeId
  80. {
  81. get
  82. {
  83. return objParticleData.TypeId;
  84. }
  85. }
  86. //TypeName
  87. public string TypeName
  88. {
  89. get
  90. {
  91. return objParticleData.TypeName;
  92. }
  93. }
  94. //XRayId
  95. public int XRayId
  96. {
  97. get
  98. {
  99. return objParticleData.XrayId;
  100. }
  101. }
  102. public int SEMPosX
  103. {
  104. get
  105. {
  106. return objParticleData.SEMPosX;
  107. }
  108. }
  109. public int SEMPosY
  110. {
  111. get
  112. {
  113. return objParticleData.SEMPosY;
  114. }
  115. }
  116. public DisplayParticle()
  117. {
  118. m_id = System.Guid.NewGuid();
  119. }
  120. public DisplayParticle(Particle part)
  121. {
  122. m_id = System.Guid.NewGuid();
  123. objParticleData = part;
  124. this.Color = DrawFunction.GetColorBySTDTypeIDForBSEAndSorImage(part.TypeColor, part.TypeId);
  125. }
  126. public DisplayParticle(Particle particle,PointF FieldLeftTop,Bitmap a_originalFieldImage/*,Bitmap fieldParticleImage*/)
  127. {
  128. m_id = System.Guid.NewGuid();
  129. objParticleData = particle;
  130. originalFieldImage = a_originalFieldImage;
  131. this.Color = DrawFunction.GetColorBySTDTypeIDForBSEAndSorImage(particle.TypeColor, particle.TypeId);
  132. SetPaintState(PaintState.PAINT);
  133. m_Globalrect.X = particle.RectLeft + FieldLeftTop.X;
  134. m_Globalrect.Y = particle.RectTop + FieldLeftTop.Y;
  135. m_Globalrect.Width = particle.RectWidth;
  136. m_Globalrect.Height = particle.RectHeight;
  137. }
  138. public void InitImageData()
  139. {
  140. List<Segment> list_seg;
  141. list_seg = objParticleData.SegmentList;
  142. this.m_BSEimage = new Bitmap(objParticleData.RectWidth + 1, objParticleData.RectHeight + 1);
  143. this.m_Colorimage = new Bitmap(objParticleData.RectWidth + 1, objParticleData.RectHeight + 1);
  144. m_GroupColorimage = new Bitmap(objParticleData.RectWidth + 1, objParticleData.RectHeight + 1);
  145. //再循环取出里面所有的segment
  146. foreach (Segment seg in list_seg)
  147. {
  148. #region
  149. //合成图像完成,开始抠取像素-----------------------------------------------------------------
  150. for (int m = 0; m < seg.Length; m++)
  151. {
  152. int lsjs_x = seg.Start + m;
  153. int lsjs_y = seg.Height;
  154. var pixelColor = originalFieldImage.GetPixel(lsjs_x, lsjs_y);
  155. var GroupColor = DrawFunction.colorHx16toRGB(objParticleData.GroupColor);
  156. lsjs_x = seg.Start - objParticleData.RectLeft + m;
  157. lsjs_y = seg.Height - objParticleData.RectTop;
  158. //Debug.Assert(lsjs_x > -1);
  159. //Debug.Assert(lsjs_y > -1);
  160. //Debug.Assert(lsjs_x < m_BSEimage.Width);
  161. //Debug.Assert(lsjs_y< m_BSEimage.Height);
  162. m_BSEimage.SetPixel(lsjs_x, lsjs_y, pixelColor);//ls_list_colors[m]
  163. m_Colorimage.SetPixel(lsjs_x, lsjs_y, m_color);
  164. m_GroupColorimage.SetPixel(lsjs_x, lsjs_y, GroupColor);
  165. }
  166. #endregion //------------------------------------------------------------------------------
  167. }
  168. }
  169. public bool WhetherInRange(Point WhetherPoint)
  170. {
  171. var rect = GetShowRect();
  172. if(rect.Contains(WhetherPoint))
  173. {
  174. m_smallRect = GetSmallRectangleFromRect();
  175. bool b_inrange;
  176. b_inrange=m_smallRect.Contains(WhetherPoint);
  177. return b_inrange;
  178. }
  179. else
  180. {
  181. return false;
  182. }
  183. }
  184. public DisplayParticle( DisplayParticle in_particle)
  185. {
  186. objParticleData = in_particle.objParticleData;
  187. m_id = in_particle.m_id;
  188. m_paintState = in_particle.m_paintState;
  189. m_operator_showxray = in_particle.m_operator_showxray;
  190. m_Globalrect = in_particle.m_Globalrect;
  191. this.m_BSEimage = in_particle.m_BSEimage;
  192. this.m_Colorimage = in_particle.m_Colorimage;
  193. }
  194. /// <summary>
  195. /// 设置显示的方式,可以用,绘线显示查看标准库颜色的,也可以用绘点,查看BSE原图颗粒图色的
  196. /// </summary>
  197. public SegmentShowMode ShowMode
  198. {
  199. get { return show_mode; }
  200. set { show_mode = value; }
  201. }
  202. /// <summary>
  203. /// 克隆方法
  204. /// </summary>
  205. /// <returns></returns>
  206. public object Clone()
  207. {
  208. return new DisplayParticle( this);
  209. }
  210. public PointF GetCenterPoint()
  211. {
  212. return new PointF(m_Globalrect.X + m_Globalrect.Width / 2, m_Globalrect.Y + m_Globalrect.Height / 2);
  213. }
  214. /// <summary>
  215. /// ID
  216. /// </summary>
  217. public Guid guid
  218. {
  219. get { return m_id; }
  220. set { m_id = value; }
  221. }
  222. /// <summary>
  223. /// 颗粒的外边框大小
  224. /// </summary>
  225. public RectangleF GetShowRect()
  226. {
  227. return m_Globalrect;
  228. }
  229. public void SetShowRect(RectangleF rectangleF)
  230. {
  231. m_Globalrect= rectangleF;
  232. }
  233. /// <summary>
  234. /// OTSPointF
  235. /// </summary>
  236. public PointF OTSPointF
  237. {
  238. get { return m_OTSPointF; }
  239. set { m_OTSPointF = value; }
  240. }
  241. public bool IsSelect
  242. {
  243. get { return m_isSelected; }
  244. set { m_isSelected = value; }
  245. }
  246. /// <summary>
  247. /// 该颗粒是否被设置成,选中状态
  248. /// </summary>
  249. public PaintState GetPaintState()
  250. {
  251. if (GetDisplayState() == DisplayState.NODISPLAY)
  252. {
  253. m_paintState = PaintState.NOPAINT;
  254. }
  255. return m_paintState;
  256. }
  257. /// <summary>
  258. /// 该颗粒是否被设置成,选中状态
  259. /// </summary>
  260. public void SetPaintState(PaintState value)
  261. {
  262. if (value == PaintState.PAINT)
  263. {
  264. if (m_CurrentZoomNum >= m_zoom_displayThreshold)
  265. {
  266. m_paintState = PaintState.PAINT;
  267. }
  268. else
  269. {
  270. m_paintState = PaintState.CONCISEPAINT;
  271. }
  272. }
  273. else
  274. {
  275. m_paintState = value;
  276. }
  277. }
  278. /// <summary>
  279. /// 是否对该颗粒选定显示X-Ray能谱图
  280. /// </summary>
  281. public ParticleShowXray Operator_ShowXRay
  282. {
  283. get { return m_operator_showxray; }
  284. set { m_operator_showxray = value; }
  285. }
  286. /// <summary>
  287. /// 是否在被拖动
  288. /// </summary>
  289. public bool IsDragging
  290. {
  291. get { return m_isdragging; }
  292. set { m_isdragging = value; }
  293. }
  294. /// <summary>
  295. /// 被拖动到的位置坐标
  296. /// </summary>
  297. public PointF DraggingPoint
  298. {
  299. get { return m_dragingpoint; }
  300. set {
  301. m_dragingpoint = value;
  302. }
  303. }
  304. /// <summary>
  305. /// 线的颜色
  306. /// </summary>
  307. public Color Color
  308. {
  309. get { return m_color; }
  310. set { m_color = value; }
  311. }
  312. /// <summary>
  313. /// 里面包含的多个线的集合
  314. /// </summary>
  315. public List<Segment> GetDSegments()
  316. { return objParticleData.SegmentList; }
  317. public void Zoom(float zoomDelta,PointF refPoint)
  318. {
  319. //var rec = m_rect;
  320. m_Globalrect.Width = (float)(m_Globalrect.Width + Convert.ToDouble(m_Globalrect.Width / m_CurrentZoomNum * zoomDelta));
  321. m_Globalrect.Height = (float)(m_Globalrect.Height + Convert.ToDouble(m_Globalrect.Height / m_CurrentZoomNum * zoomDelta));
  322. //锚点缩放补差值计算,得出差值
  323. float xShiftOld = m_Globalrect.X - refPoint.X;
  324. float yShiftOld = m_Globalrect.Y - refPoint.Y;
  325. float xShift = m_Globalrect.X - refPoint.X + xShiftOld / m_CurrentZoomNum * zoomDelta;
  326. float yShift = m_Globalrect.Y - refPoint.Y + yShiftOld / m_CurrentZoomNum * zoomDelta;
  327. //对背景矩形与所有的segment进行修补差值
  328. m_Globalrect.X = refPoint.X + xShift;
  329. m_Globalrect.Y = refPoint.Y + yShift;
  330. m_CurrentZoomNum += zoomDelta;
  331. if (m_CurrentZoomNum < 0.7)
  332. {
  333. m_isMouseOver = false;
  334. }
  335. //设置缩放到多少倍时进行显示
  336. if (m_CurrentZoomNum >= m_zoom_displayThreshold)
  337. {
  338. m_paintState = PaintState.PAINT;
  339. }
  340. else
  341. {
  342. m_paintState = PaintState.CONCISEPAINT;
  343. }
  344. }
  345. public void DraggingMove(PointF mousePoint)
  346. {
  347. m_Globalrect.X = m_Globalrect.X + mousePoint.X - this.DraggingPoint.X; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  348. m_Globalrect.Y = m_Globalrect.Y + mousePoint.Y - this.DraggingPoint.Y;
  349. this.DraggingPoint = mousePoint;
  350. }
  351. public void Move(SizeF xyShift)
  352. {
  353. m_Globalrect.X =m_Globalrect.X - xyShift.Width; //获取到原先点与移动点的增减量,+原先的x坐标,就是新的坐标
  354. m_Globalrect.Y = m_Globalrect.Y - xyShift.Height;
  355. }
  356. /// <summary>
  357. /// 设置排序的类型
  358. /// </summary>
  359. public string SortType
  360. {
  361. get { return m_sort_type; }
  362. set { m_sort_type = value; }
  363. }
  364. /// <summary>
  365. /// 设置该多边形的尺寸大小
  366. /// </summary>
  367. public float FSize
  368. {
  369. get { return m_f_size; }
  370. set { m_f_size = value; }
  371. }
  372. /// <summary>
  373. /// 设置粒级
  374. /// </summary>
  375. public string ParticleLJ
  376. {
  377. get { return m_str_lj; }
  378. set { m_str_lj = value; }
  379. }
  380. /// <summary>
  381. /// 设置种类
  382. /// </summary>
  383. public string ParticleZL
  384. {
  385. get { return m_str_klzl; }
  386. set { m_str_klzl = value; }
  387. }
  388. /// <summary>
  389. /// 设置分类
  390. /// </summary>
  391. public string ParticleFL
  392. {
  393. get { return m_str_klfl; }
  394. set { m_str_klfl = value; }
  395. }
  396. /// <summary>
  397. /// 获取或设置该Particle对应底层的FieldID值
  398. /// </summary>
  399. public int FieldId
  400. {
  401. get { return objParticleData.FieldId; }
  402. }
  403. /// <summary>
  404. /// 获取或设置该Particle对应底层的ParticleID值
  405. /// </summary>
  406. public int ParticleId
  407. {
  408. get { return objParticleData.ParticleId; }
  409. }
  410. public bool IsDeleted { get => m_isDeleted; set => m_isDeleted = value; }
  411. public bool IsMouseOver { get => m_isMouseOver; set => m_isMouseOver = value; }
  412. public Image GetImage()
  413. {
  414. return m_BSEimage;
  415. }
  416. public void SetImage(Image value)
  417. {
  418. m_BSEimage = (Bitmap)value;
  419. }
  420. public DisplayState GetDisplayState()
  421. {
  422. if (m_isDeleted)
  423. {
  424. m_displayState = DisplayState.NODISPLAY;
  425. }
  426. return m_displayState;
  427. }
  428. public void SetDisplayState(DisplayState value)
  429. {
  430. m_displayState = value;
  431. if (m_displayState == DisplayState.DISPLAY)
  432. {
  433. m_paintState = PaintState.PAINT;
  434. }
  435. }
  436. /// <summary>
  437. /// 绘制函数
  438. /// </summary>
  439. /// <param name="e"></param>
  440. public void Paint(Graphics g)
  441. {
  442. //Graphics g = e.Graphics;
  443. //绘制鼠标移动到颗粒上时的边框,需要判断当前鼠标在颗粒上,及颗粒的操作为正常显示
  444. if (m_isMouseOver == true)
  445. {
  446. //如果有鼠标在该矩形上,那么进行描边
  447. ControlPaint.DrawBorder(g,
  448. Rectangle.Round(this.GetShowRect()),
  449. Color.Lime,
  450. 1,
  451. ButtonBorderStyle.Solid,
  452. Color.Lime,
  453. 1,
  454. ButtonBorderStyle.Solid,
  455. Color.Lime,
  456. 1,
  457. ButtonBorderStyle.Solid,
  458. Color.Lime,
  459. 1,
  460. ButtonBorderStyle.Solid);
  461. }
  462. if (GetPaintState() == PaintState.PAINT)
  463. {
  464. if (this.ShowMode == SegmentShowMode.DRAWPARTICLEIMAGE)
  465. {
  466. g.DrawImage(m_BSEimage, m_Globalrect);
  467. }
  468. else
  469. if (this.ShowMode == SegmentShowMode.DRAWCOLORIMAGE)
  470. {
  471. g.DrawImage(m_Colorimage, m_Globalrect);
  472. }
  473. else
  474. {
  475. g.DrawImage(m_GroupColorimage, m_Globalrect);
  476. }
  477. }
  478. if (GetPaintState() == PaintState.CONCISEPAINT)
  479. {
  480. if (m_isSelected)
  481. {
  482. g.DrawString("+", new Font("黑体", 12), new SolidBrush(Color.Red), new PointF(GetCenterPoint().X, GetCenterPoint().Y));
  483. }
  484. else
  485. {
  486. g.DrawString("+", new Font("黑体", 6), new SolidBrush(Color.DarkSlateBlue), new PointF(GetCenterPoint().X, GetCenterPoint().Y));
  487. }
  488. }
  489. if (m_isSelected)
  490. {
  491. //如果説该矩形被选择上了的话,那么也显示边框
  492. ControlPaint.DrawBorder(g,
  493. Rectangle.Round(this.GetShowRect()),
  494. Color.Blue,
  495. 1,
  496. ButtonBorderStyle.Solid,
  497. Color.Blue,
  498. 1,
  499. ButtonBorderStyle.Solid,
  500. Color.Blue,
  501. 1,
  502. ButtonBorderStyle.Solid,
  503. Color.Blue,
  504. 1,
  505. ButtonBorderStyle.Solid);
  506. }
  507. if (ParticleShowXray.DISPLAYXRAY == m_operator_showxray && PaintState.NOPAINT != GetPaintState())
  508. {
  509. //当鼠标在该颗粒上进行点击,则对颗粒状态更改为选定状态,用来显示X-ray能谱表
  510. ControlPaint.DrawBorder(g,
  511. Rectangle.Round(this.GetShowRect()),
  512. Color.DeepSkyBlue,
  513. 1,
  514. ButtonBorderStyle.Solid,
  515. Color.DeepSkyBlue,
  516. 1,
  517. ButtonBorderStyle.Solid,
  518. Color.DeepSkyBlue,
  519. 1,
  520. ButtonBorderStyle.Solid,
  521. Color.DeepSkyBlue,
  522. 1,
  523. ButtonBorderStyle.Solid);
  524. }
  525. }
  526. /// <summary>
  527. /// 从已经确定的外边框来计算出里面的+号小框位置
  528. /// </summary>
  529. /// <returns></returns>
  530. private RectangleF GetSmallRectangleFromRect()
  531. {
  532. RectangleF rect = new RectangleF();
  533. //用外边框的坐标,除2获得中心点,然后再分别+,- 4
  534. float x = 0, y = 0;
  535. x = m_Globalrect.X + (m_Globalrect.Width / 2);
  536. y = m_Globalrect.Y + (m_Globalrect.Height / 2);
  537. var smallwidth = m_Globalrect.Width * 1 / 5;
  538. var smallheight = m_Globalrect.Height * 1 / 5;
  539. rect.X = x - smallwidth/2;
  540. rect.Y = y - smallheight / 2;
  541. rect.Width = smallwidth;
  542. rect.Height = smallheight;
  543. return rect;
  544. }
  545. /// <summary>
  546. /// 根据该多边形所有包含的线长度,计算出,该多边形的面积大小
  547. /// </summary>
  548. /// <returns></returns>
  549. public float GetAreaFormSegments()
  550. {
  551. float f_size_sum = 0;
  552. foreach (var ls_ds in this.objParticleData.SegmentList)
  553. {
  554. f_size_sum = f_size_sum + ls_ds.Length;
  555. }
  556. return f_size_sum;
  557. }
  558. }
  559. }