MeasureDrawObject.cs 4.8 KB

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