DisplayParticle.cs 20 KB

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