123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- 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
- {
- /// <summary>
- /// 测量抽象类
- /// </summary>
- public abstract class MeasureDrawObject : DrawObject
- {
- /// <summary>
- /// 数据信息
- /// </summary>
- public Dictionary<System.Enum, object> data = new Dictionary<System.Enum, object>();
- /// <summary>
- /// 绘制信息
- /// </summary>
- public Dictionary<System.Enum, string[]> drawingProperties = new Dictionary<System.Enum, string[]>();
- /// <summary>
- /// 鼠标在端点上的形状
- /// </summary>
- protected static Cursor handleCursor = new Cursor(PdnResources.GetResourceStream("Cursors.AnnotationPolyHandle.cur"));
- /// <summary>
- /// 单位枚举
- /// </summary>
- public MeasurementUnit measurementUnit;
- /// <summary>
- /// 单位缩写
- /// </summary>
- protected string unit = "μm";
- /// <summary>
- /// 单位名称
- /// </summary>
- protected string unitString = "微米";
- /// <summary>
- /// 单位像素长度
- /// </summary>
- public double unitLength
- {
- get
- {
- double value = 1;
- ISurfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out value);
- return value;
- }
- }
- /// <summary>
- /// 小数位数
- /// </summary>
- 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;
- /// <summary>
- /// 绘制信息是否可移动
- /// </summary>
- public Dictionary<System.Enum, bool> pointChangeObject = new Dictionary<System.Enum, bool>();
- /// <summary>
- /// 限制绘制(属性改变)
- /// </summary>
- public bool mouseUpAttribute = false;
- /// <summary>
- /// 多点测量的每段长度
- /// </summary>
- public List<string> lengthParagraphs = new List<string>();
- 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<System.Enum, object> GetData() { return null; }
- /// <summary>
- /// 获取旋转后的矩形位置
- /// </summary>
- /// <param name="rectangleF"></param>
- /// <param name="point"></param>
- /// <param name="angle"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 设置旋转后偏移量
- /// </summary>
- /// <param name="point"></param>
- /// <param name="angle"></param>
- /// <returns></returns>
- 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];
- }
- }
- }
|