MeasureDrawObject.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using PaintDotNet.Annotation.Enum;
  2. using System;
  3. using System.Collections;
  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. using System.Windows.Forms;
  11. namespace PaintDotNet.Annotation.Measure
  12. {
  13. /// <summary>
  14. /// 测量抽象类
  15. /// </summary>
  16. public abstract class MeasureDrawObject : DrawObject
  17. {
  18. /// <summary>
  19. /// 数据信息
  20. /// </summary>
  21. public Dictionary<System.Enum, object> data = new Dictionary<System.Enum, object>();
  22. /// <summary>
  23. /// 绘制信息
  24. /// </summary>
  25. public Dictionary<System.Enum, string[]> drawingProperties = new Dictionary<System.Enum, string[]>();
  26. /// <summary>
  27. /// 鼠标在端点上的形状
  28. /// </summary>
  29. protected static Cursor handleCursor = new Cursor(PdnResources.GetResourceStream("Cursors.AnnotationPolyHandle.cur"));
  30. /// <summary>
  31. /// 单位枚举
  32. /// </summary>
  33. public MeasurementUnit measurementUnit;
  34. /// <summary>
  35. /// 单位缩写
  36. /// </summary>
  37. protected string unit = "μm";
  38. /// <summary>
  39. /// 单位名称
  40. /// </summary>
  41. protected string unitString = "微米";
  42. /// <summary>
  43. /// 单位像素长度
  44. /// </summary>
  45. public double unitLength = 0;
  46. /// <summary>
  47. /// 小数位数
  48. /// </summary>
  49. public static int decimalPlaces = 2;
  50. protected string unitAngle = "°";
  51. protected string unitMil = "mil";
  52. protected int precision = 10;
  53. //protected double pxPerUnit = 1;
  54. public double kS;
  55. public double kE;
  56. /// <summary>
  57. /// 绘制信息是否可移动
  58. /// </summary>
  59. public Dictionary<System.Enum, bool> pointChangeObject = new Dictionary<System.Enum, bool>();
  60. /// <summary>
  61. /// 限制绘制(属性改变)
  62. /// </summary>
  63. public bool mouseUpAttribute = false;
  64. /// <summary>
  65. /// 多点测量的每段长度
  66. /// </summary>
  67. public List<string> lengthParagraphs = new List<string>();
  68. public MeasurementUnit MeasurementUnit
  69. {
  70. set
  71. {
  72. this.measurementUnit = value;
  73. if(this.ISurfaceBox!=null)
  74. {
  75. this.ISurfaceBox.GetUnitSymbolsDictionary().TryGetValue((int)measurementUnit, out unit);
  76. this.ISurfaceBox.GetUnitsDictionary().TryGetValue((int)measurementUnit, out unitString);
  77. this.ISurfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);
  78. }
  79. }
  80. }
  81. protected MeasureDrawObject()
  82. {
  83. }
  84. protected MeasureDrawObject(ISurfaceBox surfaceBox)
  85. {
  86. this.objectType = DrawClass.Measure;
  87. base.ISurfaceBox = surfaceBox;
  88. string[] pxPerUnitArr = surfaceBox.GetPxPerUnit();
  89. unit = pxPerUnitArr[2];
  90. //pxPerUnit = double.Parse(pxPerUnitArr[3]);
  91. base.Initialize();
  92. }
  93. public virtual Dictionary<System.Enum, object> GetData() { return null; }
  94. /// <summary>
  95. /// 获取旋转后的矩形位置
  96. /// </summary>
  97. /// <param name="rectangleF"></param>
  98. /// <param name="point"></param>
  99. /// <param name="angle"></param>
  100. /// <returns></returns>
  101. protected bool GetRectanglePosition(RectangleF rectangleF, Point point,PointF rotationPoint, double angle)
  102. {
  103. bool isVisible = false;
  104. Matrix matrix = new Matrix();
  105. matrix.RotateAt((float)angle, rotationPoint);
  106. GraphicsPath graphicsPath = new GraphicsPath();
  107. graphicsPath.AddRectangle(rectangleF);
  108. graphicsPath.Transform(matrix);
  109. isVisible = graphicsPath.IsVisible(point);
  110. graphicsPath.Dispose();
  111. graphicsPath = null;
  112. matrix.Dispose();
  113. matrix = null;
  114. return isVisible;
  115. }
  116. /// <summary>
  117. /// 设置旋转后偏移量
  118. /// </summary>
  119. /// <param name="point"></param>
  120. /// <param name="angle"></param>
  121. /// <returns></returns>
  122. protected Point SetOffsetAfterRotation(Point point, PointF rotationPoint, double angle)
  123. {
  124. Matrix matrix = new Matrix();
  125. matrix.RotateAt((float)-angle, rotationPoint);
  126. Point[] ff = new Point[1];
  127. ff[0] = point;
  128. matrix.TransformPoints(ff);
  129. matrix.Dispose();
  130. matrix = null;
  131. return ff[0];
  132. }
  133. }
  134. }