MeasureDrawObject.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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
  46. {
  47. get
  48. {
  49. double value = 1;
  50. ISurfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out value);
  51. return value;
  52. }
  53. }
  54. /// <summary>
  55. /// 小数位数
  56. /// </summary>
  57. public static int decimalPlaces = 2;
  58. protected string unitAngle = "°";
  59. protected string unitMil = "mil";
  60. protected int precision = 10;
  61. //protected double pxPerUnit = 1;
  62. public double kS;
  63. public double kE;
  64. /// <summary>
  65. /// 绘制信息是否可移动
  66. /// </summary>
  67. public Dictionary<System.Enum, bool> pointChangeObject = new Dictionary<System.Enum, bool>();
  68. /// <summary>
  69. /// 限制绘制(属性改变)
  70. /// </summary>
  71. public bool mouseUpAttribute = false;
  72. /// <summary>
  73. /// 多点测量的每段长度
  74. /// </summary>
  75. public List<string> lengthParagraphs = new List<string>();
  76. public MeasurementUnit MeasurementUnit
  77. {
  78. set
  79. {
  80. this.measurementUnit = value;
  81. if (this.ISurfaceBox != null)
  82. {
  83. this.ISurfaceBox.GetUnitSymbolsDictionary().TryGetValue((int)measurementUnit, out unit);
  84. this.ISurfaceBox.GetUnitsDictionary().TryGetValue((int)measurementUnit, out unitString);
  85. }
  86. }
  87. }
  88. protected MeasureDrawObject()
  89. {
  90. }
  91. protected MeasureDrawObject(ISurfaceBox surfaceBox)
  92. {
  93. this.objectType = DrawClass.Measure;
  94. base.ISurfaceBox = surfaceBox;
  95. string[] pxPerUnitArr = surfaceBox.GetPxPerUnit();
  96. unit = pxPerUnitArr[2];
  97. //pxPerUnit = double.Parse(pxPerUnitArr[3]);
  98. base.Initialize();
  99. }
  100. public virtual Dictionary<System.Enum, object> GetData() { return null; }
  101. /// <summary>
  102. /// 获取旋转后的矩形位置
  103. /// </summary>
  104. /// <param name="rectangleF"></param>
  105. /// <param name="point"></param>
  106. /// <param name="angle"></param>
  107. /// <returns></returns>
  108. protected bool GetRectanglePosition(RectangleF rectangleF, Point point, PointF rotationPoint, double angle)
  109. {
  110. bool isVisible = false;
  111. Matrix matrix = new Matrix();
  112. matrix.RotateAt((float)angle, rotationPoint);
  113. GraphicsPath graphicsPath = new GraphicsPath();
  114. graphicsPath.AddRectangle(rectangleF);
  115. graphicsPath.Transform(matrix);
  116. isVisible = graphicsPath.IsVisible(point);
  117. graphicsPath.Dispose();
  118. graphicsPath = null;
  119. matrix.Dispose();
  120. matrix = null;
  121. return isVisible;
  122. }
  123. /// <summary>
  124. /// 设置旋转后偏移量
  125. /// </summary>
  126. /// <param name="point"></param>
  127. /// <param name="angle"></param>
  128. /// <returns></returns>
  129. protected Point SetOffsetAfterRotation(Point point, PointF rotationPoint, double angle)
  130. {
  131. Matrix matrix = new Matrix();
  132. matrix.RotateAt((float)-angle, rotationPoint);
  133. Point[] ff = new Point[1];
  134. ff[0] = point;
  135. matrix.TransformPoints(ff);
  136. matrix.Dispose();
  137. matrix = null;
  138. return ff[0];
  139. }
  140. }
  141. }