| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324 | using SmartCoalApplication.Annotation.Enum;using SmartCoalApplication.Base.SettingModel;using System;using System.Collections.Generic;using System.Drawing;using System.Drawing.Drawing2D;using System.Globalization;using System.Windows.Forms;using SmartCoalApplication.Base.CommTool;using SmartCoalApplication.Annotation.Measure;using System.Linq;using Resources;namespace SmartCoalApplication.Annotation.Measure{    using PointList = List<PointF>;    /// <summary>    /// 测量->长度测量->长度    /// </summary>    public class MeasureLength : MeasureDrawObject    {        public PointList pointArray;        private const string entryLength = "Length";        private const string entryPoint = "Point";        /// <summary>        ///  Graphic objects for hit test        /// </summary>        private GraphicsPath areaPath = null;        private Pen areaPen = null;        private Region areaRegion = null;        ///<summary>        ///长度        ///</summary>        private double length = 0.0;        /// <summary>        /// 测量信息矩形定义        /// </summary>        private RectangleF rectangleF1 = new RectangleF();        private RectangleF rectangleF2 = new RectangleF();        private RectangleF rectangleF3 = new RectangleF();        private RectangleF rectangleF4 = new RectangleF();        private RectangleF rectangleF5 = new RectangleF();        private RectangleF rectangleF6 = new RectangleF();        private RectangleF rectangleF7 = new RectangleF();        private RectangleF rectangleF8 = new RectangleF();        private RectangleF rectangleF9 = new RectangleF();        /// <summary>        /// 文本上用于拖动的点        /// </summary>        private Point pointL = new Point();        /// <summary>        /// 绘制限制(第一次绘制时)        /// </summary>        public bool pointChange = true;        /// <summary>        /// 区分移动文本        /// </summary>        private int moveKb;        /// <summary>        /// 绘制限制(从配置文件加载)        /// </summary>        public bool configurationFile = false;        /// <summary>        /// 绘制限制(更改属性时)        /// </summary>        private bool SavePointChange;        /// <summary>        /// 绘制属性        /// </summary>        private string[] drawingPropertiesList;        /// <summary>        /// 绘制属性(克隆)        /// </summary>        private string[] drawingPropertiesListClone;        /// <summary>        /// 旋转角度        /// </summary>        private double angleClass;        /// <summary>        /// 属性绘制点        /// </summary>        private PointF rotationPoint;        /// <summary>        /// 限制绘制(绘制中)        /// </summary>        public bool mouseUpPointChange = false;        /// <summary>        /// 测量样式信息model        /// </summary>        private MeasureStyleModel.MeasureLength measureStyleModel;        public MeasureStyleModel.MeasureLength MeasureStyleModel        {            set            {                this.measureStyleModel = value;            }        }        public MeasureLength(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox)        {            this.objectType = DrawClass.Measure;            this.drawToolType = DrawToolType.MeasureLength;            measureStyleModel = surfaceBox.GetMeasureStyleModel().measureLength;            pointArray = new PointList();            startPoint.X = x1;            startPoint.Y = y1;            if(clone)                pointArray.Add(new Point(x1, y1));            this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);            this.unitString = surfaceBox.GetPxPerUnit()[1];            this.unit = surfaceBox.GetPxPerUnit()[2];            surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);            Initialize();        }        public MeasureLength(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()        {            this.objectType = DrawClass.Measure;            this.drawToolType = DrawToolType.MeasureLength;            this.ISurfaceBox = surfaceBox;            measureStyleModel = (MeasureStyleModel.MeasureLength)parentStyleModel;            pointArray = DrawRulerHelper.DeepCopyListByReflect(points);            startPoint = points[0];            this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);            this.unitString = surfaceBox.GetPxPerUnit()[1];            this.unit = surfaceBox.GetPxPerUnit()[2];            surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);            this.configurationFile = true;        }        /// <summary>        /// Clone this instance        /// </summary>        public override DrawObject Clone()        {            MeasureLength drawPolygon = new MeasureLength(ISurfaceBox, (int)this.pointArray[0].X, (int)this.pointArray[0].Y, false);            drawPolygon.ISurfaceBox = ISurfaceBox;            foreach (PointF p in this.pointArray)            {                drawPolygon.pointArray.Add(p);            }            if (drawingPropertiesList != null)                drawPolygon.drawingPropertiesListClone = drawingPropertiesList;            FillDrawObjectFields(drawPolygon);            return drawPolygon;        }        public override DrawObject Clone(ISurfaceBox surfaceBox)        {            MeasureLength drawPolygon = new MeasureLength(surfaceBox, this.GetPoints(), this.measureStyleModel, null);                if (drawingPropertiesList != null)                drawPolygon.drawingPropertiesListClone = drawingPropertiesList;            FillDrawObjectFields(drawPolygon);            return drawPolygon;        }        /// <summary>        /// 测量属性        /// </summary>        /// <returns></returns>        public override Dictionary<System.Enum, object> GetData()        {            if (data.ContainsKey(MeasureAttributes.MeasureMethod))                data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text");            else                data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text"));            if (data.ContainsKey(MeasureAttributes.MeasureUnitCN))                data[MeasureAttributes.MeasureUnitCN] = this.unitString;            else                data.Add(MeasureAttributes.MeasureUnitCN, this.unitString);            if (data.ContainsKey(MeasureAttributes.MeasureUnitEN))                data[MeasureAttributes.MeasureUnitEN] = this.unit;            else                data.Add(MeasureAttributes.MeasureUnitEN, this.unit);            if (data.ContainsKey(MeasureAttributes.PixelStartX))                data[MeasureAttributes.PixelStartX] = startPoint.X;            else                data.Add(MeasureAttributes.PixelStartX, startPoint.X);            if (data.ContainsKey(MeasureAttributes.PixelStartY))                data[MeasureAttributes.PixelStartY] = startPoint.Y;            else                data.Add(MeasureAttributes.PixelStartY, startPoint.Y);            if (data.ContainsKey(MeasureAttributes.PhysicalStartX))                data[MeasureAttributes.PhysicalStartX] = Math.Round(startPoint.X * unitLength, decimalPlaces);            else                data.Add(MeasureAttributes.PhysicalStartX, Math.Round(startPoint.X * unitLength, decimalPlaces));            if (data.ContainsKey(MeasureAttributes.PhysicalStartY))                data[MeasureAttributes.PhysicalStartY] = Math.Round(startPoint.Y * unitLength, decimalPlaces);            else                data.Add(MeasureAttributes.PhysicalStartY, Math.Round(startPoint.Y * unitLength, decimalPlaces));            if (data.ContainsKey(MeasureAttributes.PixelLength))                data[MeasureAttributes.PixelLength] = Math.Round(length, decimalPlaces);            else                data.Add(MeasureAttributes.PixelLength, Math.Round(length, decimalPlaces));            string s = Math.Round(length * unitLength, decimalPlaces).ToString();            if (s.IndexOf(".") == -1)            {                for (int i = 0; i < decimalPlaces; i++)                {                    if (i == 0)                        s += ".";                    s += "0";                }            }            else            {                int a = s.Length - s.IndexOf(".") - 1;                if (a < decimalPlaces)                {                    for (int i = 0; i < decimalPlaces - a; i++)                    {                        s += "0";                    }                }            }            if (data.ContainsKey(MeasureAttributes.PhysicalLength))                data[MeasureAttributes.PhysicalLength] = s;            else                data.Add(MeasureAttributes.PhysicalLength, s);            return data;        }                public override void Draw(Graphics g)        {            drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);            pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);            Font textfont = new Font(measureStyleModel.font, measureStyleModel.fontSize);            Brush textbrush = new SolidBrush(Color.FromArgb(measureStyleModel.textColor));            g.SmoothingMode = SmoothingMode.AntiAlias;            Color color = Color.FromArgb(this.measureStyleModel.lineColor);            Pen pen = new Pen(color, this.measureStyleModel.lineWidth);            pen.DashStyle = (DashStyle)this.measureStyleModel.lineStyle;            Matrix mtxSave = g.Transform;            Matrix matrix = g.Transform;            if (pointArray.Count == 2)            {                g.DrawLine(pen, pointArray[0], pointArray[1]);                length = BasicCalculationHelper.GetDistance(pointArray[0], pointArray[1], 10);            }            SizeF sizeF = new SizeF();            if (pointArray.Count >= 3)            {                if (drawingPropertiesList == null)                {                    drawingPropertiesList = drawingPropertiesListClone;                    this.configurationFile = true;                }                // 垂足坐标                PointF footPoint = new PointF();                // 垂足坐标                footPoint = BasicCalculationHelper.GetDropFeet(pointArray[1], pointArray[0], pointArray[2]);                // 点到直线距离                double lengthF = BasicCalculationHelper.GetDistance(footPoint, pointArray[2], 2);                // 第二个点与X轴的夹角                double point2ToX = Math.Round(BasicCalculationHelper.AngleText(pointArray[0],                    new PointF(pointArray[0].X + 10, pointArray[0].Y), pointArray[1]), 2);                // 第三个点与X轴的夹角                double point3ToX = Math.Round(BasicCalculationHelper.AngleText(pointArray[0],                    new PointF(pointArray[0].X + 10, pointArray[0].Y), pointArray[2]), 2);                // 两点直线与X轴夹角                double angle = BasicCalculationHelper.AngleText(pointArray[0], new PointF(pointArray[0].X + 20, pointArray[0].Y), pointArray[1]);                if (point2ToX > 90)                {                    point2ToX = 180 - point2ToX;                }                if (point3ToX > 90)                {                    point3ToX = 180 - point3ToX;                }                if (angle > 90)                {                    angle = 180 - angle;                }                //判断第二个点相对于第一个点的象限                int x2 = (int)(pointArray[1].X - pointArray[0].X);                if (x2 == 0)                    x2 = 1;                int y2 = (int)(pointArray[1].Y - pointArray[0].Y);                if (y2 == 0)                    y2 = 1;                int i2 = 0;                if (x2 > 0 && y2 > 0)             //第4象限                {                    i2 = 4;                }                else if (x2 > 0 && y2 < 0)      //第1象限                {                    i2 = 1;                }                else if (x2 < 0 && y2 < 0)       //第2象限                {                    i2 = 2;                }                else if (x2 < 0 && y2 > 0)          //第3象限                {                    i2 = 3;                }                //判断第三个点相对于第一个点的象限                int x3 = (int)(pointArray[2].X - pointArray[0].X);                if (x3 == 0)                    x3 = 1;                int y3 = (int)(pointArray[2].Y - pointArray[0].Y);                if (y3 == 0)                    y3 = 1;                int i3 = 0;                if (x3 > 0 && y3 > 0)             //第4象限                {                    i3 = 4;                }                else if (x3 > 0 && y3 < 0)      //第1象限                {                    i3 = 1;                }                else if (x3 < 0 && y3 < 0)       //第2象限                {                    i3 = 2;                }                else if (x3 < 0 && y3 > 0)          //第3象限                {                    i3 = 3;                }                double angle1 = 0.0;                double angle2 = 0.0;                if ((pointArray[1].Y == pointArray[0].Y) && (i3 == 1 || i3 == 2))                {                    angle1 = 270;                    angle2 = 90;                }                else if ((pointArray[1].Y == pointArray[0].Y) && (i3 == 3 || i3 == 4))                {                    angle1 = 90;                    angle2 = 270;                }                else if ((pointArray[1].X == pointArray[0].X) && (i3 == 1 || i3 == 4))                {                    angle1 = 0;                    angle2 = 180;                }                else if ((pointArray[1].X == pointArray[0].X) && (i3 == 2 || i3 == 3))                {                    angle1 = 180;                    angle2 = 0;                }                else if ((i2 == 1 && i3 == 1) || (i2 == 3 && i3 == 1))                {                    if (point3ToX > point2ToX)                    {                        angle1 = 270 - angle;                        angle2 = 90 - angle;                    }                    else                    {                        angle1 = 90 - angle;                        angle2 = 270 - angle;                    }                }                else if ((i2 == 1 && i3 == 2) || (i2 == 3 && i3 == 2))                {                    angle1 = 270 - angle;                    angle2 = 90 - angle;                }                else if ((i2 == 1 && i3 == 3) || (i2 == 3 && i3 == 3))                {                    if (point3ToX > point2ToX)                    {                        angle1 = 90 - angle;                        angle2 = 270 - angle;                    }                    else                    {                        angle1 = 270 - angle;                        angle2 = 90 - angle;                    }                }                else if ((i2 == 1 && i3 == 4) || (i2 == 3 && i3 == 4))                {                    angle1 = 90 - angle;                    angle2 = 270 - angle;                }                else if ((i2 == 2 && i3 == 1) || (i2 == 4 && i3 == 1))                {                    angle1 = 270 + angle;                    angle2 = 90 + angle;                }                else if ((i2 == 2 && i3 == 2) || (i2 == 4 && i3 == 2))                {                    if (point3ToX > point2ToX)                    {                        angle1 = 270 + angle;                        angle2 = 90 + angle;                    }                    else                    {                        angle1 = 90 + angle;                        angle2 = 270 + angle;                    }                }                else if ((i2 == 2 && i3 == 3) || (i2 == 4 && i3 == 3))                {                    angle1 = 90 + angle;                    angle2 = 270 + angle;                }                else if ((i2 == 2 && i3 == 4) || (i2 == 4 && i3 == 4))                {                    if (point3ToX > point2ToX)                    {                        angle1 = 90 + angle;                        angle2 = 270 + angle;                    }                    else                    {                        angle1 = 270 + angle;                        angle2 = 90 + angle;                    }                }                PointF point = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[0].X + (int)lengthF,                    pointArray[0].Y), pointArray[0], angle1);                PointF point1 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[1].X - (int)lengthF,                    pointArray[1].Y), pointArray[1], angle2);                // 求中点坐标                float x = (point.X + point1.X) / 2;                float y = (point.Y + point1.Y) / 2;                // 绘制长度                g.DrawLine(pen, point, point1);                g.DrawLine(pen, point, pointArray[0]);                g.DrawLine(pen, point1, pointArray[1]);                // 长度                length = BasicCalculationHelper.GetDistance(pointArray[0], pointArray[1], 10);                pen.Dispose();                //计算需要旋转的角度                this.angleClass = BasicCalculationHelper.Angle(point, point1, new PointF(point.X, point1.Y));                int offsetValuePoint = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;                int offsetValue1Point = measureStyleModel.lineWidth * 2 / 3;                int offsetPoint = offsetValue1Point;                if (drawingPropertiesList != null)                {                    // 像素长度                    if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))                    {                        offsetPoint += offsetValuePoint;                    }                    // 物理长度                    if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))                    {                        offsetPoint += offsetValuePoint;                    }                    // 测量方式                    if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))                    {                        offsetPoint += offsetValuePoint;                    }                    // 测量单位(中文)                    if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))                    {                        offsetPoint += offsetValuePoint;                    }                    // 测量单位(英文)                    if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))                    {                        offsetPoint += offsetValuePoint;                    }                    // 像素起始点X                    if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))                    {                        offsetPoint += offsetValuePoint;                    }                    // 像素起始点Y                    if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))                    {                        offsetPoint += offsetValuePoint;                    }                    // 物理起始点X                    if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))                    {                        offsetPoint += offsetValuePoint;                    }                    // 物理起始点Y                    if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))                    {                        offsetPoint += offsetValuePoint;                    }                }                PointF pointF1;                PointF pointF2;                if (angleClass < 90)                    pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)point.X + offsetPoint + offsetValue1Point, (int)point.Y), point, angleClass - 90);                else                    pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)point.X + offsetPoint + offsetValue1Point, (int)point.Y), point, angleClass + 90);                if (angleClass < 90)                    pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)point1.X + offsetPoint + offsetValue1Point, (int)point1.Y), point1, angleClass - 90);                else                    pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)point1.X + offsetPoint + offsetValue1Point, (int)point1.Y), point1, angleClass + 90);                PointF pointF3 = new PointF((pointF1.X + pointF2.X) / 2, (pointF1.Y + pointF2.Y) / 2);                if (measureStyleModel.linePosition == 0)                    this.rotationPoint = pointArray[0];                else if (measureStyleModel.linePosition == 1)                    this.rotationPoint = pointF3;                else if (measureStyleModel.linePosition == 2)                    this.rotationPoint = pointArray[1];                else if (measureStyleModel.linePosition == 3)                    this.rotationPoint = point;                else if (measureStyleModel.linePosition == 4)                    this.rotationPoint = new PointF(x, y);                else if (measureStyleModel.linePosition == 5)                    this.rotationPoint = point1;                // 画布旋转                if (this.angleClass < 90)                {                    matrix.RotateAt((float)this.angleClass, this.rotationPoint);                    g.Transform = matrix;                }                else                {                    this.angleClass = BasicCalculationHelper.Angle(point1, point, new PointF(point1.X, point.Y));                    matrix.RotateAt((float)this.angleClass, this.rotationPoint);                    g.Transform = matrix;                }                // 是否绘制                if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)                {                    // 属性文本的间隔定义                    int offsetValue = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;                    int offsetValue1 = measureStyleModel.lineWidth * 2 / 3;                    int offset = offsetValue1;                    this.pointL = new Point((int)this.rotationPoint.X, (int)this.rotationPoint.Y);                    if (drawingPropertiesList != null)                    {                        // 像素长度                        if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))                        {                            sizeF = g.MeasureString("" + Math.Round(length, decimalPlaces) + "px", textfont);                            rectangleF8.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);                            offset += offsetValue;                        }                        // 物理长度                        if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))                        {                            string s = Math.Round(length * unitLength, decimalPlaces).ToString();                            if (s.IndexOf(".") == -1)                            {                                for (int i = 0; i < decimalPlaces; i++)                                {                                    if (i == 0)                                        s += ".";                                    s += "0";                                }                            }                            else                            {                                int a = s.Length - s.IndexOf(".") - 1;                                if (a < decimalPlaces)                                {                                    for (int i = 0; i < decimalPlaces - a; i++)                                    {                                        s += "0";                                    }                                }                            }                            sizeF = g.MeasureString(s + this.unit, textfont);                            rectangleF9.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);                            offset += offsetValue;                        }                        // 测量方式                        if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))                        {                            sizeF = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text"), textfont);                            rectangleF1.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);                            offset += offsetValue;                        }                        // 测量单位(中文)                        if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))                        {                            sizeF = g.MeasureString("" + this.unitString, textfont);                            rectangleF2.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);                            offset += offsetValue;                        }                        // 测量单位(英文)                        if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))                        {                            sizeF = g.MeasureString("" + this.unit, textfont);                            rectangleF3.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);                            offset += offsetValue;                        }                        // 像素起始点X                        if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))                        {                            sizeF = g.MeasureString("" + pointArray[0].X, textfont);                            rectangleF4.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);                            offset += offsetValue;                        }                        // 像素起始点Y                        if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))                        {                            sizeF = g.MeasureString("" + pointArray[0].Y, textfont);                            rectangleF5.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);                            offset += offsetValue;                        }                        // 物理起始点X                        if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))                        {                            sizeF = g.MeasureString("" + Math.Round(pointArray[0].X * unitLength, decimalPlaces), textfont);                            rectangleF6.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);                            offset += offsetValue;                        }                        // 物理起始点Y                        if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))                        {                            sizeF = g.MeasureString("" + Math.Round(pointArray[0].Y * unitLength, decimalPlaces), textfont);                            rectangleF7.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);                            offset += offsetValue;                        }                    }                }                if (drawingPropertiesList != null)                {                    // 测量方式                    if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))                    {                        sizeF = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text"), textfont);                        rectangleF1.Width = sizeF.Width;                        rectangleF1.Height = sizeF.Height;                        g.DrawString("" + PdnResources.GetString("Menu.MeasureAction.LengthMeasurement.Text"), textfont, textbrush, rectangleF1);                    }                    else                    {                        rectangleF1 = new RectangleF();                    }                    // 测量单位(中文)                    if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))                    {                        sizeF = g.MeasureString("" + this.unitString, textfont);                        rectangleF2.Width = sizeF.Width;                        rectangleF2.Height = sizeF.Height;                        g.DrawString("" + this.unitString, textfont, textbrush, rectangleF2);                    }                    else                    {                        rectangleF2 = new RectangleF();                    }                    // 测量单位(英文)                    if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))                    {                        sizeF = g.MeasureString("" + this.unit, textfont);                        rectangleF3.Width = sizeF.Width;                        rectangleF3.Height = sizeF.Height;                        g.DrawString("" + this.unit, textfont, textbrush, rectangleF3);                    }                    else                    {                        rectangleF3 = new RectangleF();                    }                    // 像素起始点X                    if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))                    {                        sizeF = g.MeasureString("" + pointArray[0].X, textfont);                        rectangleF4.Width = sizeF.Width;                        rectangleF4.Height = sizeF.Height;                        g.DrawString("" + pointArray[0].X, textfont, textbrush, rectangleF4);                    }                    else                    {                        rectangleF4 = new RectangleF();                    }                    // 像素起始点Y                    if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))                    {                        sizeF = g.MeasureString("" + pointArray[0].Y, textfont);                        rectangleF5.Width = sizeF.Width;                        rectangleF5.Height = sizeF.Height;                        g.DrawString("" + pointArray[0].Y, textfont, textbrush, rectangleF5);                    }                    else                    {                        rectangleF5 = new RectangleF();                    }                    // 物理起始点X                    if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))                    {                        sizeF = g.MeasureString("" + Math.Round(pointArray[0].X * unitLength, decimalPlaces), textfont);                        rectangleF6.Width = sizeF.Width;                        rectangleF6.Height = sizeF.Height;                        g.DrawString("" + Math.Round(pointArray[0].X * unitLength, decimalPlaces), textfont, textbrush, rectangleF6);                    }                    else                    {                        rectangleF6 = new RectangleF();                    }                    // 物理起始点Y                    if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))                    {                        sizeF = g.MeasureString("" + Math.Round(pointArray[0].Y * unitLength, decimalPlaces), textfont);                        rectangleF7.Width = sizeF.Width;                        rectangleF7.Height = sizeF.Height;                        g.DrawString("" + Math.Round(pointArray[0].Y * unitLength, decimalPlaces), textfont, textbrush, rectangleF7);                    }                    else                    {                        rectangleF7 = new RectangleF();                    }                    // 像素长度                    if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))                    {                        sizeF = g.MeasureString("" + Math.Round(length, decimalPlaces) + "px", textfont);                        rectangleF8.Width = sizeF.Width;                        rectangleF8.Height = sizeF.Height;                        g.DrawString("" + Math.Round(length, decimalPlaces) + "px", textfont, textbrush, rectangleF8);                    }                    else                    {                        rectangleF8 = new RectangleF();                    }                    // 物理长度                    if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))                    {                        string s = Math.Round(length * unitLength, decimalPlaces).ToString();                        if (s.IndexOf(".") == -1)                        {                            for (int i = 0; i < decimalPlaces; i++)                            {                                if (i == 0)                                    s += ".";                                s += "0";                            }                        }                        else                        {                            int a = s.Length - s.IndexOf(".") - 1;                            if (a < decimalPlaces)                            {                                for (int i = 0; i < decimalPlaces - a; i++)                                {                                    s += "0";                                }                            }                        }                        sizeF = g.MeasureString(s + this.unit, textfont);                        rectangleF9.Width = sizeF.Width;                        rectangleF9.Height = sizeF.Height;                        g.DrawString(s + this.unit, textfont, textbrush, rectangleF9);                    }                    else                    {                        rectangleF9 = new RectangleF();                    }                }                //还原为原始旋转矩阵                g.Transform = mtxSave;            }            matrix.Dispose();            if (this.configurationFile)                this.pointChange = false;            this.mouseUpAttribute = false;            pointChangeObject.Remove(this.drawToolType);        }        /// <summary>        /// 停止绘制时        /// </summary>        /// <param name="up"></param>        public override void MouseUp(bool up)        {            mouseUpPointChange = up;        }        public void AddPoint(Point point)        {            pointArray.Add(point);        }        public override int HandleCount        {            get            {                return 6;            }        }        /// <summary>        /// Get handle pointscroll by 1-based number        /// </summary>        /// <param name="handleNumber"></param>        /// <returns></returns>        public override PointF GetHandle(int handleNumber)        {            if (handleNumber < 1)                handleNumber = 1;            if (handleNumber > pointArray.Count && handleNumber <= 3)                handleNumber = pointArray.Count;            if (handleNumber == 1)                return pointArray[0];            else if (handleNumber == 2)                return pointArray[1];            else if (handleNumber == 6)                return pointL;            else if (handleNumber > 2 && pointArray.Count >= 3)            {                // 垂足坐标                PointF footPoint = new PointF();                // 垂足坐标                footPoint = BasicCalculationHelper.GetDropFeet(pointArray[1], pointArray[0], pointArray[2]);                // 点到直线距离                double length = BasicCalculationHelper.GetDistance(footPoint, pointArray[2], 2);                // 第二个点与X轴的夹角                double point2ToX = Math.Round(BasicCalculationHelper.AngleText(pointArray[0],                    new PointF(pointArray[0].X + 10, pointArray[0].Y), pointArray[1]), 2);                // 第三个点与X轴的夹角                double point3ToX = Math.Round(BasicCalculationHelper.AngleText(pointArray[0],                    new PointF(pointArray[0].X + 10, pointArray[0].Y), pointArray[2]), 2);                // 两点直线与X轴夹角                double angle = BasicCalculationHelper.AngleText(pointArray[0], new PointF(pointArray[0].X + 20, pointArray[0].Y), pointArray[1]);                if (point2ToX > 90)                {                    point2ToX = 180 - point2ToX;                }                if (point3ToX > 90)                {                    point3ToX = 180 - point3ToX;                }                if (angle > 90)                {                    angle = 180 - angle;                }                //判断第二个点相对于第一个点的象限                int x2 = (int)(pointArray[1].X - pointArray[0].X);                if (x2 == 0)                    x2 = 1;                int y2 = (int)(pointArray[1].Y - pointArray[0].Y);                if (y2 == 0)                    y2 = 1;                int i2 = 0;                if (x2 > 0 && y2 > 0)             //第4象限                {                    i2 = 4;                }                else if (x2 > 0 && y2 < 0)      //第1象限                {                    i2 = 1;                }                else if (x2 < 0 && y2 < 0)       //第2象限                {                    i2 = 2;                }                else if (x2 < 0 && y2 > 0)          //第3象限                {                    i2 = 3;                }                //判断第三个点相对于第一个点的象限                int x3 = (int)(pointArray[2].X - pointArray[0].X);                if (x3 == 0)                    x3 = 1;                int y3 = (int)(pointArray[2].Y - pointArray[0].Y);                if (y3 == 0)                    y3 = 1;                int i3 = 0;                if (x3 > 0 && y3 > 0)             //第4象限                {                    i3 = 4;                }                else if (x3 > 0 && y3 < 0)      //第1象限                {                    i3 = 1;                }                else if (x3 < 0 && y3 < 0)       //第2象限                {                    i3 = 2;                }                else if (x3 < 0 && y3 > 0)          //第3象限                {                    i3 = 3;                }                double angle1 = 0.0;                double angle2 = 0.0;                if ((pointArray[1].Y == pointArray[0].Y) && (i3 == 1 || i3 == 2))                {                    angle1 = 270;                    angle2 = 90;                }                else if ((pointArray[1].Y == pointArray[0].Y) && (i3 == 3 || i3 == 4))                {                    angle1 = 90;                    angle2 = 270;                }                else if ((pointArray[1].X == pointArray[0].X) && (i3 == 1 || i3 == 4))                {                    angle1 = 0;                    angle2 = 180;                }                else if ((pointArray[1].X == pointArray[0].X) && (i3 == 2 || i3 == 3))                {                    angle1 = 180;                    angle2 = 0;                }                else if ((i2 == 1 && i3 == 1) || (i2 == 3 && i3 == 1))                {                    if (point3ToX > point2ToX)                    {                        angle1 = 270 - angle;                        angle2 = 90 - angle;                    }                    else                    {                        angle1 = 90 - angle;                        angle2 = 270 - angle;                    }                }                else if ((i2 == 1 && i3 == 2) || (i2 == 3 && i3 == 2))                {                    angle1 = 270 - angle;                    angle2 = 90 - angle;                }                else if ((i2 == 1 && i3 == 3) || (i2 == 3 && i3 == 3))                {                    if (point3ToX > point2ToX)                    {                        angle1 = 90 - angle;                        angle2 = 270 - angle;                    }                    else                    {                        angle1 = 270 - angle;                        angle2 = 90 - angle;                    }                }                else if ((i2 == 1 && i3 == 4) || (i2 == 3 && i3 == 4))                {                    angle1 = 90 - angle;                    angle2 = 270 - angle;                }                else if ((i2 == 2 && i3 == 1) || (i2 == 4 && i3 == 1))                {                    angle1 = 270 + angle;                    angle2 = 90 + angle;                }                else if ((i2 == 2 && i3 == 2) || (i2 == 4 && i3 == 2))                {                    if (point3ToX > point2ToX)                    {                        angle1 = 270 + angle;                        angle2 = 90 + angle;                    }                    else                    {                        angle1 = 90 + angle;                        angle2 = 270 + angle;                    }                }                else if ((i2 == 2 && i3 == 3) || (i2 == 4 && i3 == 3))                {                    angle1 = 90 + angle;                    angle2 = 270 + angle;                }                else if ((i2 == 2 && i3 == 4) || (i2 == 4 && i3 == 4))                {                    if (point3ToX > point2ToX)                    {                        angle1 = 90 + angle;                        angle2 = 270 + angle;                    }                    else                    {                        angle1 = 270 + angle;                        angle2 = 90 + angle;                    }                }                PointF point = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[0].X + (int)length,                    pointArray[0].Y), pointArray[0], angle1);                PointF point1 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[1].X - (int)length,                    pointArray[1].Y), pointArray[1], angle2);                // 求中点坐标                float x = (point.X + point1.X) / 2;                float y = (point.Y + point1.Y) / 2;                if (handleNumber == 3)                    return point;                else if (handleNumber == 4)                    return point1;                else                    return new PointF(x, y);            }            else            {                return pointArray[0];            }        }        public override Cursor GetHandleCursor(int handleNumber)        {            return handleCursor;        }        public override void MoveHandleTo(Point point, int handleNumber)        {            if (handleNumber < 1)                handleNumber = 1;            if (handleNumber > pointArray.Count && handleNumber != 6)                handleNumber = pointArray.Count;            if (handleNumber == 6)            {                point = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                if (this.moveKb == 1)                    this.rectangleF1.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);                else if (this.moveKb == 2)                    this.rectangleF2.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);                else if (this.moveKb == 3)                    this.rectangleF3.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);                else if (this.moveKb == 4)                    this.rectangleF4.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);                else if (this.moveKb == 5)                    this.rectangleF5.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);                else if (this.moveKb == 6)                    this.rectangleF6.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);                else if (this.moveKb == 7)                    this.rectangleF7.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);                else if (this.moveKb == 8)                    this.rectangleF8.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);                else if (this.moveKb == 9)                    this.rectangleF9.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);                this.pointL = point;            }            else            {                this.mouseUpPointChange = true;                if (handleNumber == 1)                {                    this.rectangleF1.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);                    this.rectangleF2.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);                    this.rectangleF3.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);                    this.rectangleF4.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);                    this.rectangleF5.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);                    this.rectangleF6.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);                    this.rectangleF7.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);                    this.rectangleF8.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);                    this.rectangleF9.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);                }                pointArray[handleNumber - 1] = point;            }            this.startPoint = pointArray[0];            Invalidate();        }        public override void Move(int deltaX, int deltaY)        {            int n = pointArray.Count;            PointF point;            for (int i = 0; i < n; i++)            {                point = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY));                pointArray[i] = point;            }            this.startPoint = pointArray[0];            int x = ISurfaceBox.UnscaleScalar(deltaX);            int y = ISurfaceBox.UnscaleScalar(deltaY);            pointL.X += x;            pointL.Y += y;            this.rectangleF1.Offset(x, y);            this.rectangleF2.Offset(x, y);            this.rectangleF3.Offset(x, y);            this.rectangleF4.Offset(x, y);            this.rectangleF5.Offset(x, y);            this.rectangleF6.Offset(x, y);            this.rectangleF7.Offset(x, y);            this.rectangleF8.Offset(x, y);            this.rectangleF9.Offset(x, y);            Invalidate();        }        /// <summary>        /// 用于创建一个路径或者是闭合的范围        /// 用于响应点击选中        /// 需要咨询用户是仅点击线还是矩形选择        /// </summary>        protected virtual void CreateObjects()        {            if (AreaPath != null)                return;            AreaPath = new GraphicsPath();            AreaPath.AddRectangle(GetBoundingBox());            AreaPath.CloseFigure();            AreaRegion = new Region(AreaPath);        }        /// <summary>        /// Invalidate object.        /// When object is invalidated, path used for hit test        /// is released and should be created again.        /// </summary>        protected void Invalidate()        {            if (AreaPath != null)            {                AreaPath.Dispose();                AreaPath = null;            }            if (AreaPen != null)            {                AreaPen.Dispose();                AreaPen = null;            }            if (AreaRegion != null)            {                AreaRegion.Dispose();                AreaRegion = null;            }        }        protected GraphicsPath AreaPath        {            get            {                return areaPath;            }            set            {                areaPath = value;            }        }        protected Pen AreaPen        {            get            {                return areaPen;            }            set            {                areaPen = value;            }        }        protected Region AreaRegion        {            get            {                return areaRegion;            }            set            {                areaRegion = value;            }        }        /// <summary>        /// Draw tracker for selected object        /// </summary>        /// <param name="g"></param>        public override void DrawTracker(Graphics g)        {            if (!Selected)                return;            SolidBrush brush = new SolidBrush(Color.Black);            for (int i = 1; i <= HandleCount; i++)            {                if (i == 6)                    brush = new SolidBrush(Color.Transparent);                g.FillRectangle(brush, GetHandleRectangle(i));            }            brush.Dispose();            RectangleF r = GetBoundingBox();            //g.DrawRectangle(new Pen(Color.White), r.X, r.Y, r.Width, r.Height);        }        /// <summary>        /// Hit test.        /// Return value: -1 - no hit        ///                0 - hit anywhere        ///                > 1 - handle number        /// </summary>        /// <param name="pointscroll"></param>        /// <returns></returns>        public override int HitTest(Point point)        {            if (Selected)            {                for (int i = 1; i <= HandleCount; i++)                {                    if (GetHandleRectangle(i).Contains(point))                        return i;                }                if (GetRectanglePosition(this.rectangleF1, point, this.rotationPoint, this.angleClass))                {                    this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                    moveKb = 1;                    return 6;                }                else if (GetRectanglePosition(this.rectangleF2, point, this.rotationPoint, this.angleClass))                {                    this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                    moveKb = 2;                    return 6;                }                else if (GetRectanglePosition(this.rectangleF3, point, this.rotationPoint, this.angleClass))                {                    this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                    moveKb = 3;                    return 6;                }                else if (GetRectanglePosition(this.rectangleF4, point, this.rotationPoint, this.angleClass))                {                    this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                    moveKb = 4;                    return 6;                }                else if (GetRectanglePosition(this.rectangleF5, point, this.rotationPoint, this.angleClass))                {                    this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                    moveKb = 5;                    return 6;                }                else if (GetRectanglePosition(this.rectangleF6, point, this.rotationPoint, this.angleClass))                {                    this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                    moveKb = 6;                    return 6;                }                else if (GetRectanglePosition(this.rectangleF7, point, this.rotationPoint, this.angleClass))                {                    this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                    moveKb = 7;                    return 6;                }                else if (GetRectanglePosition(this.rectangleF8, point, this.rotationPoint, this.angleClass))                {                    this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                    moveKb = 8;                    return 6;                }                else if (GetRectanglePosition(this.rectangleF9, point, this.rotationPoint, this.angleClass))                {                    this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, this.angleClass);                    moveKb = 9;                    return 6;                }            }            if (PointInObject(point))                return 0;            return -1;        }        protected override bool PointInObject(Point point)        {            CreateObjects();            return AreaRegion.IsVisible(point);        }        public override bool IntersectsWith(Rectangle rectangle)        {            CreateObjects();            return AreaRegion.IsVisible(rectangle);        }        public override RectangleF GetBoundingBox()        {            Rectangle rectangle;            int minx = 0, maxx = 0, miny = 0, maxy = 0;            for (int i = 0; i < pointArray.Count; i++)            {                if (i == 0)                {                    minx = maxx = (int)pointArray[i].X;                    miny = maxy = (int)pointArray[i].Y;                }                else                {                    if (pointArray[i].X > maxx) maxx = (int)pointArray[i].X;                    if (pointArray[i].X < minx) minx = (int)pointArray[i].X;                    if (pointArray[i].Y > maxy) maxy = (int)pointArray[i].Y;                    if (pointArray[i].Y < miny) miny = (int)pointArray[i].Y;                }            }            rectangle = new Rectangle(minx, miny, maxx - minx, maxy - miny);            return rectangle;        }        internal void setNextPoint(Point p)        {            AddPoint(p);            startPoint = endPoint;            endPoint = p;        }        internal void setEndPoint(Point p)        {            endPoint = p;        }        public override List<PointF> GetPoints()        {            return pointArray;        }        public override ParentStyleModel GetStyle()        {            return measureStyleModel;        }    }}
 |