using PaintDotNet.Annotation.Enum; using PaintDotNet.Base.SettingModel; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Globalization; using System.Windows.Forms; using PaintDotNet.Base.CommTool; using System.Linq; namespace PaintDotNet.Annotation.Measure { using PointList = List; /// /// 测量->平行线测量->平行线 /// public class MeasureParallelLine : MeasureDrawObject { public PointList pointArray; private const string entryLength = "Length"; private const string entryPoint = "Point"; /// /// Graphic objects for hit test /// private GraphicsPath areaPath = null; private Pen areaPen = null; private Region areaRegion = null; /// /// 总长度 /// private double Length = 0.0; /// /// 测量信息矩形定义 /// 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(); private int autoNum = 0; /// /// 文本上用于拖动的点 /// private Point pointL = new Point(); /// /// 绘制限制(第一次绘制时) /// public bool pointChange = true; /// /// 区分移动文本 /// private int moveKb; /// /// 绘制限制(从配置文件加载) /// public bool configurationFile = false; /// /// 绘制限制(更改属性时) /// private bool SavePointChange; /// /// 绘制属性 /// private string[] drawingPropertiesList; /// /// 绘制属性(克隆) /// private string[] drawingPropertiesListClone; private bool drawing; /// /// 旋转角度 /// private double angleClass; /// /// 旋转角度 /// private double angleClass1; /// /// 属性绘制点 /// private PointF rotationPoint; private PointF rotationPoint1; /// /// 限制绘制(绘制中) /// public bool mouseUpPointChange = false; /// /// 测量样式信息model /// private MeasureStyleModel.MeasureParallelLine measureStyleModel; public MeasureStyleModel.MeasureParallelLine MeasureStyleModel { set { this.measureStyleModel = value; } } public MeasureParallelLine(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox) { this.objectType = DrawClass.Measure; this.drawToolType = DrawToolType.MeasureParallelLine; measureStyleModel = surfaceBox.GetMeasureStyleModel().measureParallelLine; pointArray = new PointList(); startPoint.X = x1; startPoint.Y = y1; if (clone) { drawing = true; 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]; Initialize(); } /// /// 测量属性 /// /// public override Dictionary GetData() { if (data.ContainsKey(MeasureAttributes.MeasureMethod)) data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.ParallelLines.Text"); else data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.ParallelLines.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); if (data.ContainsKey(MeasureAttributes.PixelAverageDistance)) data[MeasureAttributes.PixelAverageDistance] = Math.Round(Length, decimalPlaces); else data.Add(MeasureAttributes.PixelAverageDistance, Math.Round(Length, decimalPlaces)); if (data.ContainsKey(MeasureAttributes.PhysicalAverageDistance)) data[MeasureAttributes.PhysicalAverageDistance] = Math.Round(Length * unitLength, decimalPlaces); else data.Add(MeasureAttributes.PhysicalAverageDistance, Math.Round(Length * unitLength, decimalPlaces)); return data; } public MeasureParallelLine(ISurfaceBox surfaceBox, List points, ParentStyleModel parentStyleModel, Object content) : base() { this.objectType = DrawClass.Measure; this.drawToolType = DrawToolType.MeasureParallelLine; this.ISurfaceBox = surfaceBox; measureStyleModel = (MeasureStyleModel.MeasureParallelLine)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]; this.configurationFile = true; } /// /// Clone this instance /// public override DrawObject Clone() { MeasureParallelLine drawPolygon = new MeasureParallelLine(ISurfaceBox, (int)pointArray[0].X, (int)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) { MeasureParallelLine drawPolygon = new MeasureParallelLine(surfaceBox, this.GetPoints(), this.measureStyleModel, null); if (drawingPropertiesList != null) drawPolygon.drawingPropertiesListClone = drawingPropertiesList; FillDrawObjectFields(drawPolygon); return drawPolygon; } public override void Draw(Graphics g) { measureStyleModel = this.ISurfaceBox.GetMeasureStyleModel().measureParallelLine; drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList); if (drawingPropertiesList == null) { drawingPropertiesList = drawingPropertiesListClone; if (!this.drawing) this.configurationFile = true; } pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange); if (HandleCount - 1 >= 2) { autoNum = 0; 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; if (this.Selected) { if (measureStyleModel.chooseStyle != null) { textfont = new Font(measureStyleModel.chooseStyle.font, measureStyleModel.chooseStyle.fontSize); textbrush = new SolidBrush(Color.FromArgb(measureStyleModel.chooseStyle.textColor)); pen = new Pen(Color.FromArgb(measureStyleModel.chooseStyle.lineColor), measureStyleModel.chooseStyle.lineWidth); pen.DashStyle = (DashStyle)measureStyleModel.chooseStyle.lineStyle; } } if (!this.Selected) { this.pointChange = true; rectangleF1 = new RectangleF(); rectangleF2 = new RectangleF(); rectangleF3 = new RectangleF(); rectangleF4 = new RectangleF(); rectangleF5 = new RectangleF(); rectangleF6 = new RectangleF(); rectangleF7 = new RectangleF(); rectangleF8 = new RectangleF(); rectangleF9 = new RectangleF(); } g.DrawLine(pen, pointArray[0], pointArray[1]); if (HandleCount - 1 == 3) { SizeF sizeF = new SizeF(); // 垂足坐标 PointF footPoint = new PointF(); footPoint = BasicCalculationHelper.GetDropFeet(pointArray[1], pointArray[0], pointArray[2]); g.DrawLine(pen, pointArray[2], footPoint); // 点到直线距离 double length = BasicCalculationHelper.GetDistance(footPoint, pointArray[2], 10); // 第二个点与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; } //判断第二个点相对于第一个点的象限 float x2 = pointArray[1].X - pointArray[0].X; if (x2 == 0) x2 = 1; float y2 = 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; } //判断第三个点相对于第一个点的象限 float x3 = pointArray[2].X - pointArray[0].X; if (x3 == 0) x3 = 1; float y3 = 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); g.DrawLine(pen, point, point1); // 长度文本显示 //g.DrawString(Math.Round(length * unitLength, decimalPlaces) + unit, textfont, textbrush, footPoint); Matrix mtxSave = g.Transform; Matrix matrix = g.Transform; //计算需要旋转的角度 this.angleClass = BasicCalculationHelper.Angle(pointArray[0], pointArray[1], new PointF(pointArray[0].X, pointArray[1].Y)); int offsetValuePoint = measureStyleModel.fontSize + measureStyleModel.fontSize / 2; int offsetValue1Point = measureStyleModel.lineWidth * 2 / 3; int offsetPoint = offsetValue1Point; if (drawingPropertiesList != null) { // 测量方式 if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString())) { offsetPoint += offsetValuePoint; } // 测量单位(中文) if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString())) { offsetPoint += offsetValuePoint; } // 测量单位(英文) if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString())) { offsetPoint += offsetValuePoint; } } PointF pointF1; PointF pointF2; if (angleClass < 90) pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[0].X + offsetPoint + offsetValue1Point, (int)pointArray[0].Y), pointArray[0], angleClass - 90); else pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[0].X + offsetPoint + offsetValue1Point, (int)pointArray[0].Y), pointArray[0], angleClass + 90); if (angleClass < 90) pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[1].X + offsetPoint + offsetValue1Point, (int)pointArray[1].Y), pointArray[1], angleClass - 90); else pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[1].X + offsetPoint + offsetValue1Point, (int)pointArray[1].Y), pointArray[1], angleClass + 90); PointF pointF3 = new PointF((pointF1.X + pointF2.X) / 2, (pointF1.Y + pointF2.Y) / 2); if (measureStyleModel.linePositionL == 0) this.rotationPoint = pointF1; else if (measureStyleModel.linePositionL == 1) this.rotationPoint = pointF3; else if (measureStyleModel.linePositionL == 2) this.rotationPoint = pointF2; else if (measureStyleModel.linePositionL == 3) this.rotationPoint = pointArray[0]; else if (measureStyleModel.linePositionL == 4) this.rotationPoint = new PointF((pointArray[0].X + pointArray[1].X) / 2, (pointArray[0].Y + pointArray[1].Y) / 2); else if (measureStyleModel.linePositionL == 5) this.rotationPoint = pointArray[1]; string frontStr = string.Empty; if (this.measureStyleModel.showSuffix) { frontStr = this.measureStyleModel.suffixName; } if (this.measureStyleModel.showSerial) { #region [获取序号] List newGraphicsList = new List(); int n = ISurfaceBox.GraphicsList.Count; int num = 0; for (int i = n - 1; i >= 0; i--) { newGraphicsList.Add(ISurfaceBox.GraphicsList[i].Clone()); } var newGraphics = newGraphicsList.Where(m => m.ID.Equals(this.ID)).FirstOrDefault(); if (newGraphics != null) { num = newGraphicsList.IndexOf(newGraphics) + 1; } #endregion frontStr = $"[{ num }]{frontStr}"; } if (this.measureStyleModel.showAlias) { frontStr = this.measureStyleModel.aliasName + frontStr; } if (measureStyleModel.followLine) { // 画布旋转 if (this.angleClass < 90) { matrix.RotateAt((float)this.angleClass, this.rotationPoint); g.Transform = matrix; } else { this.angleClass = BasicCalculationHelper.Angle(pointArray[1], pointArray[0], new PointF(pointArray[1].X, pointArray[0].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 offset0 = offsetValue1; int offset2 = offsetValue1; this.pointL = new Point((int)this.rotationPoint.X, (int)this.rotationPoint.Y); if (drawingPropertiesList != null) { // 测量方式 if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString())) { sizeF = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.ParallelLines.Text"), textfont); if (measureStyleModel.followLine) { rectangleF1.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset0); } else { if (measureStyleModel.linePositionP == 1 || measureStyleModel.linePositionP == 4) { rectangleF1.Location = getLevelPoint(this.rotationPoint, sizeF, measureStyleModel.linePositionP, offset0, angleClass,pointArray,false); } else { rectangleF1.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset0); } } offset0 += offsetValue; } // 测量单位(中文) if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString())) { sizeF = g.MeasureString(frontStr + "" + this.unitString, textfont); if (measureStyleModel.followLine) { rectangleF2.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset0); } else { if (measureStyleModel.linePositionP == 1 || measureStyleModel.linePositionP == 4) { rectangleF2.Location = getLevelPoint(this.rotationPoint, sizeF, measureStyleModel.linePositionP, offset0, angleClass, pointArray, false); } else { rectangleF2.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset0); } } offset0 += offsetValue; } // 测量单位(英文) if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString())) { sizeF = g.MeasureString(frontStr + "" + this.unit, textfont); if (measureStyleModel.followLine) { rectangleF3.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset0); } else { if (measureStyleModel.linePositionP == 1 || measureStyleModel.linePositionP == 4) { rectangleF3.Location = getLevelPoint(this.rotationPoint, sizeF, measureStyleModel.linePositionP, offset0, angleClass, pointArray, false); } else { rectangleF3.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset0); } } offset0 += offsetValue; } } } if (drawingPropertiesList != null) { // 测量方式 if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString())) { sizeF = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.ParallelLines.Text"), textfont); rectangleF1.Width = sizeF.Width; rectangleF1.Height = sizeF.Height; g.DrawString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.ParallelLines.Text"), textfont, textbrush, rectangleF1); } else { rectangleF1 = new RectangleF(); } // 测量单位(中文) if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString())) { sizeF = g.MeasureString(frontStr + "" + this.unitString, textfont); rectangleF2.Width = sizeF.Width; rectangleF2.Height = sizeF.Height; g.DrawString(frontStr + "" + this.unitString, textfont, textbrush, rectangleF2); } else { rectangleF2 = new RectangleF(); } // 测量单位(英文) if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString())) { sizeF = g.MeasureString(frontStr + "" + this.unit, textfont); rectangleF3.Width = sizeF.Width; rectangleF3.Height = sizeF.Height; g.DrawString(frontStr + "" + this.unit, textfont, textbrush, rectangleF3); } else { rectangleF3 = new RectangleF(); } } //还原为原始旋转矩阵 g.Transform = mtxSave; matrix.Dispose(); Matrix mtxSave1 = g.Transform; Matrix matrix1 = g.Transform; //计算需要旋转的角度 this.angleClass1 = BasicCalculationHelper.Angle(footPoint, pointArray[2], new PointF(footPoint.X, pointArray[2].Y)); offsetValuePoint = measureStyleModel.fontSize + measureStyleModel.fontSize / 2; offsetValue1Point = measureStyleModel.lineWidth * 2 / 3; offsetPoint = offsetValue1Point; if (drawingPropertiesList != null) { // 像素长度 if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString())) { offsetPoint += offsetValuePoint; } // 物理长度 if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.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; } } if (angleClass1 < 90) pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)footPoint.X + offsetPoint + offsetValue1Point, (int)footPoint.Y), footPoint, angleClass1 - 90); else pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)footPoint.X + offsetPoint + offsetValue1Point, (int)footPoint.Y), footPoint, angleClass1 + 90); if (angleClass1 < 90) pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[2].X + offsetPoint + offsetValue1Point, (int)pointArray[2].Y), pointArray[2], angleClass1 - 90); else pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[2].X + offsetPoint + offsetValue1Point, (int)pointArray[2].Y), pointArray[2], angleClass1 + 90); pointF3 = new PointF((pointF1.X + pointF2.X) / 2, (pointF1.Y + pointF2.Y) / 2); if (measureStyleModel.linePositionP == 0) this.rotationPoint1 = pointF1; else if (measureStyleModel.linePositionP == 1) this.rotationPoint1 = pointF3; else if (measureStyleModel.linePositionP == 2) this.rotationPoint1 = pointF2; else if (measureStyleModel.linePositionP == 3) this.rotationPoint1 = footPoint; else if (measureStyleModel.linePositionP == 4) this.rotationPoint1 = new PointF((footPoint.X + pointArray[2].X) / 2, (footPoint.Y + pointArray[2].Y) / 2); else if (measureStyleModel.linePositionP == 5) this.rotationPoint1 = pointArray[2]; if (measureStyleModel.followLine) { // 画布旋转 if (this.angleClass1 < 90) { matrix1.RotateAt((float)this.angleClass1, this.rotationPoint1); g.Transform = matrix1; } else { this.angleClass1 = BasicCalculationHelper.Angle(pointArray[2], footPoint, new PointF(pointArray[2].X, footPoint.Y)); matrix1.RotateAt((float)this.angleClass1, this.rotationPoint1); g.Transform = matrix1; } } #region [没办法] int leftNum = 0; if (drawingPropertiesList != null) { if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString())) { leftNum += 1; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString())) { leftNum += 1; } if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString())) { leftNum += 1; } if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString())) { leftNum += 1; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString())) { leftNum += 1; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString())) { leftNum += 1; } } #endregion // 是否绘制 if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute) { // 属性文本的间隔定义 int offsetValue = measureStyleModel.fontSize + measureStyleModel.fontSize / 2; int offsetValue1 = measureStyleModel.lineWidth * 2 / 3; int offset0 = offsetValue1; int offset2 = offsetValue1; this.pointL = new Point((int)this.rotationPoint1.X, (int)this.rotationPoint1.Y); if (drawingPropertiesList != null) { // 像素长度 if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(length, decimalPlaces) + "px", textfont); if (measureStyleModel.followLine) { rectangleF8.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } else { if (measureStyleModel.linePositionP == 1 || measureStyleModel.linePositionP == 4) { rectangleF8.Location = getLevelPoint(this.rotationPoint1, sizeF, measureStyleModel.linePositionP, offset2, angleClass, pointArray,true ,leftNum); } else { rectangleF8.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } } offset2 += 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(frontStr + s + this.unit, textfont); if (measureStyleModel.followLine) { rectangleF9.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } else { if (measureStyleModel.linePositionP == 1 || measureStyleModel.linePositionP == 4) { rectangleF9.Location = getLevelPoint(this.rotationPoint1, sizeF, measureStyleModel.linePositionP, offset2, angleClass, pointArray, true, leftNum); } else { rectangleF9.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } } offset2 += offsetValue; } // 像素起始点X if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString())) { sizeF = g.MeasureString(frontStr + "" + pointArray[2].X, textfont); if (measureStyleModel.followLine) { rectangleF4.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } else { if (measureStyleModel.linePositionP == 1 || measureStyleModel.linePositionP == 4) { rectangleF4.Location = getLevelPoint(this.rotationPoint1, sizeF, measureStyleModel.linePositionP, offset2, angleClass, pointArray, true, leftNum); } else { rectangleF4.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } } offset2 += offsetValue; } // 像素起始点Y if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString())) { sizeF = g.MeasureString(frontStr + "" + pointArray[2].Y, textfont); if (measureStyleModel.followLine) { rectangleF5.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } else { if (measureStyleModel.linePositionP == 1 || measureStyleModel.linePositionP == 4) { rectangleF5.Location = getLevelPoint(this.rotationPoint1, sizeF, measureStyleModel.linePositionP, offset2, angleClass, pointArray, true, leftNum); } else { rectangleF5.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } } offset2 += offsetValue; } // 物理起始点X if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(pointArray[2].X * unitLength, decimalPlaces), textfont); if (measureStyleModel.followLine) { rectangleF6.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } else { if (measureStyleModel.linePositionP == 1 || measureStyleModel.linePositionP == 4) { rectangleF6.Location = getLevelPoint(this.rotationPoint1, sizeF, measureStyleModel.linePositionP, offset2, angleClass, pointArray, true, leftNum); } else { rectangleF6.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } } offset2 += offsetValue; } // 物理起始点Y if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(pointArray[2].Y * unitLength, decimalPlaces), textfont); if (measureStyleModel.followLine) { rectangleF7.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } else { if (measureStyleModel.linePositionP == 1 || measureStyleModel.linePositionP == 4) { rectangleF7.Location = getLevelPoint(this.rotationPoint1, sizeF, measureStyleModel.linePositionP, offset2, angleClass, pointArray, true, leftNum); } else { rectangleF7.Location = new Point((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset2); } } offset2 += offsetValue; } } } if (drawingPropertiesList != null) { // 像素长度 if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(length, decimalPlaces) + "px", textfont); rectangleF8.Width = sizeF.Width; rectangleF8.Height = sizeF.Height; g.DrawString(frontStr + "" + 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(frontStr + s + this.unit, textfont); rectangleF9.Width = sizeF.Width; rectangleF9.Height = sizeF.Height; g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF9); } else { rectangleF9 = new RectangleF(); } // 像素起始点X if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString())) { sizeF = g.MeasureString(frontStr + "" + pointArray[2].X, textfont); rectangleF4.Width = sizeF.Width; rectangleF4.Height = sizeF.Height; g.DrawString(frontStr + "" + pointArray[2].X, textfont, textbrush, rectangleF4); } else { rectangleF4 = new RectangleF(); } // 像素起始点Y if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString())) { sizeF = g.MeasureString(frontStr + "" + pointArray[2].Y, textfont); rectangleF5.Width = sizeF.Width; rectangleF5.Height = sizeF.Height; g.DrawString(frontStr + "" + pointArray[2].Y, textfont, textbrush, rectangleF5); } else { rectangleF5 = new RectangleF(); } // 物理起始点X if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(pointArray[2].X * unitLength, decimalPlaces), textfont); rectangleF6.Width = sizeF.Width; rectangleF6.Height = sizeF.Height; g.DrawString(frontStr + "" + Math.Round(pointArray[2].X * unitLength, decimalPlaces), textfont, textbrush, rectangleF6); } else { rectangleF6 = new RectangleF(); } // 物理起始点Y if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(pointArray[2].Y * unitLength, decimalPlaces), textfont); rectangleF7.Width = sizeF.Width; rectangleF7.Height = sizeF.Height; g.DrawString(frontStr + "" + Math.Round(pointArray[2].Y * unitLength, decimalPlaces), textfont, textbrush, rectangleF7); } else { rectangleF7 = new RectangleF(); } } //还原为原始旋转矩阵 g.Transform = mtxSave1; matrix1.Dispose(); this.Length = length; pen.Dispose(); } } if (this.configurationFile) this.pointChange = false; this.mouseUpAttribute = false; pointChangeObject.Remove(this.drawToolType); } /// /// 停止绘制时 /// /// public override void MouseUp(bool up) { mouseUpPointChange = up; } public void AddPoint(Point point) { pointArray.Add(point); } public override int HandleCount { get { return pointArray.Count + 1; } } /// /// Get handle pointscroll by 1-based number /// /// /// public override PointF GetHandle(int handleNumber) { if (handleNumber < 1) handleNumber = 1; if (handleNumber > pointArray.Count && handleNumber != pointArray.Count + 1) handleNumber = pointArray.Count; if (handleNumber == pointArray.Count + 1) return this.pointL; else return pointArray[handleNumber - 1]; } 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 != pointArray.Count + 1) handleNumber = pointArray.Count; if (handleNumber == pointArray.Count + 1) { if (this.moveKb == 1 || this.moveKb == 2 || this.moveKb == 3) { point = SetOffsetAfterRotation(point, rotationPoint, 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 { point = SetOffsetAfterRotation(point, rotationPoint1, angleClass1); 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.rotationPoint.X, point.Y - this.rotationPoint.Y); this.rectangleF2.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y); this.rectangleF3.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y); } else if (handleNumber == 3) { this.rectangleF4.Offset(point.X - this.rotationPoint1.X, point.Y - this.rotationPoint1.Y); this.rectangleF5.Offset(point.X - this.rotationPoint1.X, point.Y - this.rotationPoint1.Y); this.rectangleF6.Offset(point.X - this.rotationPoint1.X, point.Y - this.rotationPoint1.Y); this.rectangleF7.Offset(point.X - this.rotationPoint1.X, point.Y - this.rotationPoint1.Y); this.rectangleF8.Offset(point.X - this.rotationPoint1.X, point.Y - this.rotationPoint1.Y); this.rectangleF9.Offset(point.X - this.rotationPoint1.X, point.Y - this.rotationPoint1.Y); } pointArray[handleNumber - 1] = point; } Invalidate(); } public override void Move(int deltaX, int deltaY) { int n = pointArray.Count; for (int i = 0; i < n; i++) { PointF 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(); } /// /// 用于创建一个路径或者是闭合的范围 /// 用于响应点击选中 /// 需要咨询用户是仅点击线还是矩形选择 /// protected virtual void CreateObjects() { if (AreaPath != null) return; AreaPath = new GraphicsPath(); AreaPath.AddRectangle(GetBoundingBox()); AreaPath.CloseFigure(); AreaRegion = new Region(AreaPath); } /// /// Invalidate object. /// When object is invalidated, path used for hit test /// is released and should be created again. /// 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; } } /// /// Draw tracker for selected object /// /// public override void DrawTracker(Graphics g) { if (!Selected) return; SolidBrush brush = new SolidBrush(Color.FromArgb(MarkpointAreaColor)); Pen pen = new Pen(Color.FromArgb(MarkpointLineColor), MarkpointLineWidth); for (int i = 1; i <= HandleCount; i++) { if (i == HandleCount) { brush = new SolidBrush(Color.Transparent); pen = new Pen(Color.Transparent); } switch (MarkpointStyle) { case 0: g.FillRectangle(brush, GetHandleRectangle(i)); g.DrawRectangle(pen, GetHandleRectangle(i)); break; case 1: g.FillEllipse(brush, GetHandleRectangle(i)); g.DrawEllipse(pen, GetHandleRectangle(i)); break; case 2: g.FillPolygon(brush, GetHandlePoint(i)); g.DrawPolygon(pen, GetHandlePoint(i)); break; } } pen.Dispose(); brush.Dispose(); RectangleF r = GetBoundingBox(); //g.DrawRectangle(new Pen(Color.White), r.X, r.Y, r.Width, r.Height); } /// /// Hit test. /// Return value: -1 - no hit /// 0 - hit anywhere /// > 1 - handle number /// /// /// 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, rotationPoint, angleClass)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angleClass); moveKb = 1; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF2, point, rotationPoint, angleClass)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angleClass); moveKb = 2; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF3, point, rotationPoint, angleClass)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angleClass); moveKb = 3; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF4, point, rotationPoint1, angleClass1)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint1, angleClass1); moveKb = 4; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF5, point, rotationPoint1, angleClass1)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint1, angleClass1); moveKb = 5; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF6, point, rotationPoint1, angleClass1)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint1, angleClass1); moveKb = 6; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF7, point, rotationPoint1, angleClass1)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint1, angleClass1); moveKb = 7; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF8, point, rotationPoint1, angleClass1)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint1, angleClass1); moveKb = 8; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF9, point, rotationPoint1, angleClass1)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint1, angleClass1); moveKb = 9; return this.pointArray.Count + 1; } } 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() { float minx = 0, maxx = 0, miny = 0, maxy = 0; for (int i = 0; i < pointArray.Count; i++) { if (i == 0) { minx = maxx = pointArray[i].X; miny = maxy = pointArray[i].Y; } else { if (pointArray[i].X > maxx) maxx = pointArray[i].X; if (pointArray[i].X < minx) minx = pointArray[i].X; if (pointArray[i].Y > maxy) maxy = pointArray[i].Y; if (pointArray[i].Y < miny) miny = pointArray[i].Y; } } return new RectangleF(minx, miny, maxx - minx, maxy - miny); } internal void setNextPoint(Point p) { AddPoint(p); //startPoint = endPoint; //endPoint = p; } internal void setEndPoint(Point p) { endPoint = p; } public override List GetPoints() { return pointArray; } public override ParentStyleModel GetStyle() { return measureStyleModel; } /// /// 获取水平文字时的起始坐标 /// /// private PointF getLevelPoint(PointF point, SizeF sizeF, int type, int offset,double angle, PointList pointFList,bool shuiZhi,int num = 0) { var startPoint = new PointF(); if (shuiZhi) { int offsetY = 0; if ((type == 1 || type == 4)) { int averageNum; bool isDan = false; if (num % 2 == 0) { averageNum = num / 2; } else { averageNum = (num - 1) / 2; isDan = true; } if (averageNum != 0) { if (autoNum < averageNum) { offsetY = (int)(((averageNum - autoNum)) * sizeF.Height); } else { offsetY = (int)(0 - (autoNum - averageNum) * sizeF.Height); } } if (isDan && autoNum == num) { offsetY += (int)sizeF.Height; } autoNum += 1; } switch (type) { case 0: break; case 1: if (angle < -5) { startPoint = new PointF(point.X + 10, point.Y - sizeF.Height + offset); } else if (angle < 5) { if (num <= 1) { startPoint = new PointF(pointFList[2].X + 10, (pointFList[2].Y + pointFList[0].Y) / 2 - (sizeF.Height / 2) + offsetY); } else { startPoint = new PointF(pointFList[2].X + 10, (pointFList[2].Y + pointFList[0].Y) / 2 - offsetY); } } else if (angle < 90) { startPoint = new PointF(point.X - sizeF.Width - 10, (pointFList[2].Y + pointFList[0].Y) / 2 + offset); } else if (angle < 175) { startPoint = new PointF(point.X - 10, point.Y - sizeF.Height + offset); } else if (angle < 185) { if (num <= 1) { startPoint = new PointF(point.X - 10, (pointFList[2].Y + pointFList[0].Y) / 2 - (sizeF.Height / 2) + offsetY); } else { startPoint = new PointF(point.X - 10, (pointFList[2].Y + pointFList[0].Y) / 2 - offsetY); } } else if (angle <= 270) { startPoint = new PointF(point.X - 10, point.Y + offset); } break; case 2: break; case 3: break; case 4: if (angle < -5) { startPoint = new PointF(point.X - sizeF.Width - 10, point.Y + sizeF.Height + offset); } else if (angle < 5) { if (num <= 1) { startPoint = new PointF(pointFList[2].X + 10, (pointFList[2].Y + pointFList[0].Y) / 2 - (sizeF.Height / 2) + offsetY); } else { startPoint = new PointF(pointFList[2].X + 10, (pointFList[2].Y + pointFList[0].Y) / 2 - offsetY); } } else if (angle < 90) { startPoint = new PointF(point.X - sizeF.Width - 10, (pointFList[2].Y + pointFList[0].Y) / 2 + offset); } else if (angle < 175) { startPoint = new PointF(point.X - 10, point.Y - sizeF.Height + offset); } else if (angle < 185) { if (num <= 1) { startPoint = new PointF(point.X - 10, (pointFList[2].Y + pointFList[0].Y) / 2 - (sizeF.Height / 2) + offsetY); } else { startPoint = new PointF(point.X - 10, (pointFList[2].Y + pointFList[0].Y) / 2 - offsetY); } } else if (angle <= 270) { startPoint = new PointF(point.X + sizeF.Width + 10, point.Y + offset); } break; case 5: break; } } else { switch (type) { case 0: break; case 1: if (angle < -5) { startPoint = new PointF(point.X - sizeF.Width - 10, point.Y + offset); } else if (angle < 5) { startPoint = new PointF(point.X - sizeF.Width / 2, point.Y + offset); } else if (angle < 90) { startPoint = new PointF(point.X + 10, point.Y + offset); } else if (angle < 175) { startPoint = new PointF(point.X - sizeF.Width - 10, point.Y + offset); } else if (angle < 185) { startPoint = new PointF(point.X - sizeF.Width / 2, point.Y + offset); } else if (angle <= 270) { startPoint = new PointF(point.X + 10, point.Y + offset); } break; case 2: break; case 3: break; case 4: if (angle < -5) { startPoint = new PointF(point.X + 10, point.Y + offset); } else if (angle < 5) { startPoint = new PointF(point.X - sizeF.Width / 2, point.Y + offset); } else if (angle < 90) { startPoint = new PointF(point.X - sizeF.Width - 10, point.Y + offset); } else if (angle < 180) { startPoint = new PointF(point.X + 10, point.Y + offset); } else if (angle <= 270) { startPoint = new PointF(point.X - sizeF.Width - 10, point.Y + offset); } break; case 5: break; } } return startPoint; } } }