InclusionDrawObject.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 InclusionDrawObject(ISurfaceBox surfaceBox, Inclusion inclusion) : base(surfaceBox)
  20. {
  21. this.drawToolType = DrawToolType.InclusionSelect;
  22. this.inclusion = inclusion;
  23. this.is_showRectangle = true;
  24. }
  25. public InclusionDrawObject(ISurfaceBox surfaceBox, Inclusion inclusion, int is_full) : base(surfaceBox)
  26. {
  27. this.drawToolType = DrawToolType.InclusionSelect;
  28. this.inclusion = inclusion;
  29. this.is_full = is_full;
  30. this.is_showRectangle = true;
  31. }
  32. public InclusionDrawObject(ISurfaceBox surfaceBox, Inclusion inclusion, bool is_showRectangle, bool is_showOval,int is_full) :base(surfaceBox)
  33. {
  34. this.drawToolType = DrawToolType.InclusionSelect;
  35. this.inclusion = inclusion;
  36. this.is_showRectangle = is_showRectangle;
  37. this.is_showOval = is_showOval;
  38. this.is_full = is_full;
  39. }
  40. public override void Draw(Graphics g)
  41. {
  42. Drawing(g);
  43. }
  44. public override DrawObject Clone()
  45. {
  46. return new InclusionDrawObject(this.ISurfaceBox,this.inclusion);
  47. }
  48. public override RectangleF GetBoundingBox()
  49. {
  50. throw new NotImplementedException();
  51. }
  52. public override void DrawTracker(Graphics g)
  53. {
  54. Drawing(g);
  55. }
  56. private void Drawing(Graphics g)
  57. {
  58. g.SmoothingMode = SmoothingMode.AntiAlias;
  59. foreach (Particle particle in this.inclusion.particles)
  60. {
  61. if (is_showRectangle)
  62. {
  63. g.DrawRectangle(new Pen(Color.Red,0.1f), particle.rectProfile.X, particle.rectProfile.Y, particle.rectProfile.Width, particle.rectProfile.Height);
  64. }
  65. if (particle.points2.Count() > 2)
  66. {
  67. // 填充夹杂物
  68. if (is_full == 1)
  69. {
  70. g.FillPolygon(new SolidBrush(Color.FromArgb(this.inclusion.type.showColor)), particle.points2);
  71. }
  72. else
  73. {
  74. g.DrawPolygon(new Pen(Color.FromArgb(this.inclusion.type.showColor), 0.1f), particle.points2);
  75. }
  76. }
  77. }
  78. if (is_showRectangle) {
  79. 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);
  80. }
  81. if (is_showOval) {
  82. g.DrawEllipse(new Pen(Color.Green), this.inclusion.rectProfile.X, this.inclusion.rectProfile.Y, this.inclusion.rectProfile.Width, this.inclusion.rectProfile.Height);
  83. }
  84. if (this.inclusion.pixelLength > 0)
  85. {
  86. Font type = new Font(System.Drawing.SystemFonts.DefaultFont.FontFamily, (float)(this.inclusion.pixelLength / 10), System.Drawing.SystemFonts.DefaultFont.Style);
  87. Font chemicalCharacteristics = new Font(type.FontFamily, type.Size / 2);
  88. g.DrawString(this.inclusion.type.type, type, new SolidBrush(Color.Blue), this.inclusion.rectProfile.Right, this.inclusion.rectProfile.Bottom - type.Size);
  89. 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);
  90. }
  91. }
  92. }
  93. }