CRingGDIObject.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using OTSMeasureApp._4_OTSSamplespaceGraphicsPanel.VisualGDIObjects;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace OTSMeasureApp._4_OTSSamplespaceGraphicsPanel
  11. {
  12. class CRingGDIObject : CMeasureArea
  13. {
  14. private float ringWidth = 10;//the distance between outline circle and inside circle.
  15. public float GetRingWidth()
  16. {
  17. return ringWidth * m_zoomNum;
  18. }
  19. public void SetRingWidth(float value)
  20. {
  21. ringWidth = value;
  22. }
  23. public CRingGDIObject(RectangleF rect, string holename, string name, Color selColor)
  24. {
  25. m_OrigineRegionF = rect;
  26. SetInitRegionF(m_OrigineRegionF);
  27. sampleName = name;
  28. nameOrHoleName = holename;
  29. SelColor = selColor;
  30. ID = System.Guid.NewGuid().ToString();
  31. }
  32. public override void OnPaint(PaintEventArgs e)
  33. {
  34. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //图片柔顺模式选择
  35. e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;//高质量
  36. e.Graphics.CompositingQuality = CompositingQuality.HighQuality;//再加一点
  37. e.Graphics.DrawEllipse(Pens.Red, m_RegionF);
  38. RectangleF insideRegine = new RectangleF();
  39. insideRegine.X = m_RegionF.X + GetRingWidth();
  40. insideRegine.Y = m_RegionF.Y + GetRingWidth();
  41. insideRegine.Width = m_RegionF.Width - GetRingWidth() * 2;
  42. insideRegine.Height = m_RegionF.Height - GetRingWidth() * 2;
  43. e.Graphics.DrawEllipse(Pens.Red, insideRegine);
  44. if (subItems.Count != 0)
  45. {
  46. foreach (var item in subItems)
  47. {
  48. item.OnPaint(e);
  49. }
  50. }
  51. }
  52. private GraphicsPath GetInsideCirclePath()
  53. {
  54. RectangleF insideRegine = new RectangleF();
  55. insideRegine.X = m_OrigineRegionF.X + ringWidth;
  56. insideRegine.Y = m_OrigineRegionF.Y + ringWidth;
  57. insideRegine.Width = m_OrigineRegionF.Width - ringWidth * 2;
  58. insideRegine.Height = m_OrigineRegionF.Height - ringWidth * 2;
  59. GraphicsPath GPath = new GraphicsPath();
  60. GPath.AddEllipse(insideRegine);
  61. return GPath;
  62. }
  63. private bool ifRectangleIntersect(CDisplayGDIObject otherUnZoomgdi)
  64. {
  65. var path = GetInsideCirclePath();//the inside circle is the blank area that there's no field rect.
  66. var vertexPoints = otherUnZoomgdi.GetOriginalRegionVertexPoints();
  67. foreach (var p in vertexPoints)
  68. {
  69. if (!path.IsVisible(p))
  70. {
  71. return true;
  72. }
  73. }
  74. return false;
  75. }
  76. override public void AddSubItems(CVisualFieldGDIObject item)
  77. {
  78. if (subItems == null) subItems = new List<CVisualFieldGDIObject>();
  79. if (ifRectangleIntersect(item))
  80. {
  81. var r = item;
  82. r.SequenceNum = subItems.Count ;
  83. subItems.Add(item);
  84. }
  85. }
  86. }
  87. }