DisplayParticle.cs 20 KB

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