InclusionDrawObject.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Base.DedicatedAnalysis.Inclusions.Model;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace PaintDotNet.Annotation.DedicatedAnalysis
  11. {
  12. public class InclusionDrawObject : DedicatedAnalysisDrawObject
  13. {
  14. public Inclusion inclusion;
  15. public bool is_showRectangle;
  16. public bool is_showOval;
  17. public int is_full;
  18. public bool is_edit;
  19. public bool showStr;
  20. public InclusionDrawObject(ISurfaceBox surfaceBox, Inclusion inclusion) : base(surfaceBox)
  21. {
  22. this.drawToolType = DrawToolType.InclusionSelect;
  23. this.inclusion = inclusion;
  24. this.is_showRectangle = true;
  25. }
  26. public InclusionDrawObject(ISurfaceBox surfaceBox, Inclusion inclusion, int is_full) : base(surfaceBox)
  27. {
  28. this.drawToolType = DrawToolType.InclusionSelect;
  29. this.inclusion = inclusion;
  30. this.is_full = is_full;
  31. this.is_showRectangle = true;
  32. }
  33. public InclusionDrawObject(ISurfaceBox surfaceBox, Inclusion inclusion, bool is_showRectangle, int is_full) : base(surfaceBox)
  34. {
  35. this.drawToolType = DrawToolType.InclusionSelect;
  36. this.inclusion = inclusion;
  37. this.is_full = is_full;
  38. this.is_showRectangle = is_showRectangle;
  39. }
  40. public InclusionDrawObject(ISurfaceBox surfaceBox, Inclusion inclusion, bool is_showRectangle, bool is_showOval,int is_full,bool showStr) :base(surfaceBox)
  41. {
  42. this.drawToolType = DrawToolType.InclusionSelect;
  43. this.inclusion = inclusion;
  44. this.is_showRectangle = is_showRectangle;
  45. this.is_showOval = is_showOval;
  46. this.is_full = is_full;
  47. this.showStr = showStr;
  48. }
  49. public override void Draw(Graphics g)
  50. {
  51. Drawing(g);
  52. }
  53. public override DrawObject Clone()
  54. {
  55. return new InclusionDrawObject(this.ISurfaceBox,this.inclusion);
  56. }
  57. public override RectangleF GetBoundingBox()
  58. {
  59. throw new NotImplementedException();
  60. }
  61. public override void DrawTracker(Graphics g)
  62. {
  63. Drawing(g);
  64. }
  65. private void Drawing(Graphics g)
  66. {
  67. g.SmoothingMode = SmoothingMode.AntiAlias;
  68. foreach (Particle particle in this.inclusion.particles)
  69. {
  70. if (is_showRectangle)
  71. {
  72. g.DrawRectangle(new Pen(Color.Red,0.1f), particle.rectProfile.X, particle.rectProfile.Y, particle.rectProfile.Width, particle.rectProfile.Height);
  73. }
  74. if (particle.points2.Count() > 2)
  75. {
  76. // 填充夹杂物
  77. if (is_full == 1)
  78. {
  79. g.FillPolygon(new SolidBrush(Color.FromArgb(this.inclusion.type.showColor)), particle.points2);
  80. }
  81. else
  82. {
  83. g.DrawPolygon(new Pen(Color.FromArgb(this.inclusion.type.showColor), 0.1f), particle.points2);
  84. }
  85. }
  86. }
  87. if (is_showRectangle) {
  88. g.DrawRectangle(new Pen(Color.Blue, Selected ? 3 : 0.1f), this.inclusion.rectProfile.X, this.inclusion.rectProfile.Y, this.inclusion.rectProfile.Width, this.inclusion.rectProfile.Height);
  89. }
  90. if (is_showOval) {
  91. g.DrawEllipse(new Pen(Color.Green), this.inclusion.rectProfile.X, this.inclusion.rectProfile.Y, this.inclusion.rectProfile.Width, this.inclusion.rectProfile.Height);
  92. }
  93. if (this.inclusion.pixelLength > 0)
  94. {
  95. if (this.showStr)
  96. {
  97. Font type = new Font(System.Drawing.SystemFonts.DefaultFont.FontFamily, (float)(this.inclusion.pixelLength / 10), System.Drawing.SystemFonts.DefaultFont.Style);
  98. Font chemicalCharacteristics = new Font(type.FontFamily, type.Size / 2);
  99. g.DrawString(this.inclusion.type.type, type, new SolidBrush(Color.Blue), this.inclusion.rectProfile.Right, this.inclusion.rectProfile.Bottom - type.Size);
  100. g.DrawString(this.inclusion.chemicalCharacteristics, chemicalCharacteristics, new SolidBrush(Color.Blue), this.inclusion.rectProfile.Right + (this.inclusion.type.type.Length * type.Size), this.inclusion.rectProfile.Bottom - chemicalCharacteristics.Size);
  101. }
  102. }
  103. }
  104. }
  105. }