using PaintDotNet.Annotation.Enum; using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PaintDotNet.Annotation.Measure { /// /// 测量抽象类 /// public abstract class MeasureDrawObject : DrawObject { /// /// 数据信息 /// public Dictionary data = new Dictionary(); /// /// 绘制信息 /// public Dictionary drawingProperties = new Dictionary(); /// /// 鼠标在端点上的形状 /// protected static Cursor handleCursor = new Cursor(PdnResources.GetResourceStream("Cursors.AnnotationPolyHandle.cur")); /// /// 单位枚举 /// public MeasurementUnit measurementUnit; /// /// 单位缩写 /// protected string unit = "μm"; /// /// 单位名称 /// protected string unitString = "微米"; /// /// 单位像素长度 /// public double unitLength { get { double value = 1; ISurfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out value); return value; } } /// /// 小数位数 /// public static int decimalPlaces = 2; protected string unitAngle = "°"; protected string unitMil = "mil"; protected int precision = 10; //protected double pxPerUnit = 1; public double kS; public double kE; /// /// 绘制信息是否可移动 /// public Dictionary pointChangeObject = new Dictionary(); /// /// 限制绘制(属性改变) /// public bool mouseUpAttribute = false; /// /// 多点测量的每段长度 /// public List lengthParagraphs = new List(); public MeasurementUnit MeasurementUnit { set { this.measurementUnit = value; if (this.ISurfaceBox != null) { this.ISurfaceBox.GetUnitSymbolsDictionary().TryGetValue((int)measurementUnit, out unit); this.ISurfaceBox.GetUnitsDictionary().TryGetValue((int)measurementUnit, out unitString); } } } protected MeasureDrawObject() { } protected MeasureDrawObject(ISurfaceBox surfaceBox) { this.objectType = DrawClass.Measure; base.ISurfaceBox = surfaceBox; string[] pxPerUnitArr = surfaceBox.GetPxPerUnit(); unit = pxPerUnitArr[2]; //pxPerUnit = double.Parse(pxPerUnitArr[3]); base.Initialize(); } public virtual Dictionary GetData() { return null; } /// /// 获取旋转后的矩形位置 /// /// /// /// /// protected bool GetRectanglePosition(RectangleF rectangleF, Point point, PointF rotationPoint, double angle) { bool isVisible = false; Matrix matrix = new Matrix(); matrix.RotateAt((float)angle, rotationPoint); GraphicsPath graphicsPath = new GraphicsPath(); graphicsPath.AddRectangle(rectangleF); graphicsPath.Transform(matrix); isVisible = graphicsPath.IsVisible(point); graphicsPath.Dispose(); graphicsPath = null; matrix.Dispose(); matrix = null; return isVisible; } /// /// 设置旋转后偏移量 /// /// /// /// protected Point SetOffsetAfterRotation(Point point, PointF rotationPoint, double angle) { Matrix matrix = new Matrix(); matrix.RotateAt((float)-angle, rotationPoint); Point[] ff = new Point[1]; ff[0] = point; matrix.TransformPoints(ff); matrix.Dispose(); matrix = null; return ff[0]; } } }