using PaintDotNet.Annotation.Enum; using PaintDotNet.Base.SettingModel; using PaintDotNet.Base.CommTool; using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Globalization; using System.Linq; using System.Windows.Forms; namespace PaintDotNet.Annotation.Measure { using PointEnumerator = IEnumerator; using PointList = List; /// /// 测量->曲线->轨迹曲线 /// public class MeasureTraceCurve : MeasureDrawObject { private PointList pointArray; private GraphicsPath areaPath = null; private Pen areaPen = null; private Region areaRegion = null; /// /// 曲线长度 /// private double Length = 0.0; /// /// 属性绘制点 /// private PointF rotationPoint; /// /// 测量信息矩形定义 /// 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 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 double angle; /// /// 限制绘制(绘制中) /// public bool mouseUpPointChange = false; /// /// 是否移动了鼠标 /// public bool moved = false; private MeasureStyleModel.MeasureTraceCurve measureTraceCurve; public MeasureTraceCurve() : base() { this.objectType = DrawClass.Measure; this.drawToolType = DrawToolType.MeasureTraceCurve; pointArray = new PointList(); Initialize(); } public MeasureTraceCurve(ISurfaceBox surfaceBox, float x1, float y1, float x2, float y2) : base(surfaceBox) { this.objectType = DrawClass.Measure; this.drawToolType = DrawToolType.MeasureTraceCurve; this.pointArray = new PointList(); pointArray.Add(new PointF(x1, y1)); pointArray.Add(new PointF(x2, y2)); startPoint = new PointF(x1, y1); measureTraceCurve = this.ISurfaceBox.GetMeasureStyleModel().measureTraceCurve; this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]); this.unitString = surfaceBox.GetPxPerUnit()[1]; this.unit = surfaceBox.GetPxPerUnit()[2]; Initialize(); } public MeasureTraceCurve(ISurfaceBox surfaceBox, List points, ParentStyleModel parentStyleModel, Object content) : base(surfaceBox) { this.objectType = DrawClass.Measure; this.drawToolType = DrawToolType.MeasureTraceCurve; this.moved = true; this.pointArray = DrawRulerHelper.DeepCopyListByReflect(points); this.startPoint = points[0]; this.measureTraceCurve = this.ISurfaceBox.GetMeasureStyleModel().measureTraceCurve; this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]); this.unitString = surfaceBox.GetPxPerUnit()[1]; this.unit = surfaceBox.GetPxPerUnit()[2]; this.configurationFile = true; Initialize(); } /// /// Clone this instance /// public override DrawObject Clone() { MeasureTraceCurve drawPolygon = new MeasureTraceCurve(ISurfaceBox, this.startPoint.X, this.startPoint.Y, this.endPoint.X, this.endPoint.Y); drawPolygon.pointArray.Clear(); foreach (PointF p in this.pointArray) { drawPolygon.pointArray.Add(p); } if (drawingPropertiesList != null) drawPolygon.drawingPropertiesListClone = drawingPropertiesList; drawPolygon.moved = true; FillDrawObjectFields(drawPolygon); return drawPolygon; } /// /// Clone this instance /// public override DrawObject Clone(ISurfaceBox surfaceBox) { MeasureTraceCurve drawPolygon = new MeasureTraceCurve(surfaceBox, this.GetPoints(), this.measureTraceCurve, null); if (drawingPropertiesList != null) drawPolygon.drawingPropertiesListClone = drawingPropertiesList; drawPolygon.moved = true; FillDrawObjectFields(drawPolygon); return drawPolygon; } /// /// 测量属性 /// /// public override Dictionary GetData() { if (data.ContainsKey(MeasureAttributes.MeasureMethod)) data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.CurveLength.Text"); else data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.CurveLength.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; } 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; } } public override void Draw(Graphics g) { if(this.moved) { measureTraceCurve = this.ISurfaceBox.GetMeasureStyleModel().measureTraceCurve; drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList); pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange); SizeF sizeF = new SizeF(); Font textfont = new Font(measureTraceCurve.font, measureTraceCurve.fontSize); Brush textbrush = new SolidBrush(Color.FromArgb(measureTraceCurve.textColor)); Pen linePen = new Pen(Color.FromArgb(measureTraceCurve.lineColor), measureTraceCurve.lineWidth); linePen.DashStyle = (DashStyle)measureTraceCurve.lineStyle; if (this.Selected) { if (measureTraceCurve.chooseStyle != null) { textfont = new Font(measureTraceCurve.chooseStyle.font, measureTraceCurve.chooseStyle.fontSize); textbrush = new SolidBrush(Color.FromArgb(measureTraceCurve.chooseStyle.textColor)); linePen = new Pen(Color.FromArgb(measureTraceCurve.chooseStyle.lineColor), measureTraceCurve.chooseStyle.lineWidth); linePen.DashStyle = (DashStyle)measureTraceCurve.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(); } Matrix mtxSave = g.Transform; Matrix matrix = g.Transform; float x1 = 0, y1 = 0; // previous pointscroll float x2, y2; // current pointscroll string frontStr = string.Empty; if (this.measureTraceCurve.showSuffix) { frontStr = this.measureTraceCurve.suffixName; } if (this.measureTraceCurve.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.measureTraceCurve.showAlias) { frontStr = this.measureTraceCurve.aliasName + frontStr; } g.SmoothingMode = SmoothingMode.AntiAlias; PointF firstPoint = new PointF(); PointF secondPoint = new PointF(); PointEnumerator enumerator = pointArray.GetEnumerator(); if (pointArray.Count > 2) { if (drawingPropertiesList == null) { drawingPropertiesList = drawingPropertiesListClone; this.configurationFile = true; } firstPoint = pointArray[0]; secondPoint = pointArray[1]; } if (enumerator.MoveNext()) { x1 = ((PointF)enumerator.Current).X; y1 = ((PointF)enumerator.Current).Y; } double length = 0f; while (enumerator.MoveNext()) { x2 = ((PointF)enumerator.Current).X; y2 = ((PointF)enumerator.Current).Y; g.DrawLine(linePen, x1, y1, x2, y2); length += BasicCalculationHelper.GetDistance(new PointF(x1, y1), new PointF(x2, y2), 4); x1 = x2; y1 = y2; } this.Length = length; //计算需要旋转的角度 if (measureTraceCurve.linePosition == 0) { angle = BasicCalculationHelper.Angle(pointArray[0], pointArray[1], new PointF(pointArray[0].X, pointArray[1].Y)); rotationPoint = pointArray[0]; } else if (measureTraceCurve.linePosition == 1) { angle = BasicCalculationHelper.Angle(pointArray[pointArray.Count - 2], pointArray[pointArray.Count - 1], new PointF(pointArray[pointArray.Count - 2].X, pointArray[pointArray.Count - 1].Y)); rotationPoint = pointArray[pointArray.Count - 1]; } // 画布旋转 if (angle < 90) { matrix.RotateAt((float)angle, new PointF(rotationPoint.X, rotationPoint.Y)); g.Transform = matrix; } else { if (measureTraceCurve.linePosition == 0) { angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[0], new PointF(pointArray[1].X, pointArray[0].Y)); } else if (measureTraceCurve.linePosition == 1) { angle = BasicCalculationHelper.Angle(pointArray[pointArray.Count - 1], pointArray[pointArray.Count - 2], new PointF(pointArray[pointArray.Count - 1].X, pointArray[pointArray.Count - 2].Y)); } matrix.RotateAt((float)angle, new PointF(rotationPoint.X, rotationPoint.Y)); g.Transform = matrix; } // 是否绘制 if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute) { // 属性文本的间隔定义 int offsetValue = measureTraceCurve.fontSize + measureTraceCurve.fontSize / 2; int offsetValue1 = measureTraceCurve.lineWidth * 2 / 3; int offset = offsetValue1; this.pointL = new Point((int)rotationPoint.X, (int)rotationPoint.Y); if (drawingPropertiesList != null) { // 像素长度 if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(length, decimalPlaces) + "px", textfont); rectangleF8.Location = new Point((int)rotationPoint.X - (int)sizeF.Width / 2, (int)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(frontStr + s + this.unit, textfont); rectangleF9.Location = new Point((int)rotationPoint.X - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset); offset += offsetValue; } // 测量方式 if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString())) { sizeF = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.CurveLength.Text"), textfont); rectangleF1.Location = new Point((int)rotationPoint.X - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset); offset += offsetValue; } // 测量单位(中文) if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString())) { sizeF = g.MeasureString(frontStr + "" + this.unitString, textfont); rectangleF2.Location = new Point((int)rotationPoint.X - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset); offset += offsetValue; } // 测量单位(英文) if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString())) { sizeF = g.MeasureString(frontStr + "" + this.unit, textfont); rectangleF3.Location = new Point((int)rotationPoint.X - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset); offset += offsetValue; } // 像素起始点X if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString())) { sizeF = g.MeasureString(frontStr + "" + startPoint.X, textfont); rectangleF4.Location = new Point((int)rotationPoint.X - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset); offset += offsetValue; } // 像素起始点Y if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString())) { sizeF = g.MeasureString(frontStr + "" + startPoint.Y, textfont); rectangleF5.Location = new Point((int)rotationPoint.X - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset); offset += offsetValue; } // 物理起始点X if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont); rectangleF6.Location = new Point((int)rotationPoint.X - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset); offset += offsetValue; } // 物理起始点Y if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont); rectangleF7.Location = new Point((int)rotationPoint.X - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset); offset += offsetValue; } } } if (drawingPropertiesList != null) { // 测量方式 if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString())) { sizeF = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.CurveLength.Text"), textfont); rectangleF1.Width = sizeF.Width; rectangleF1.Height = sizeF.Height; g.DrawString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.CurveLength.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(); } // 像素起始点X if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString())) { sizeF = g.MeasureString(frontStr + "" + startPoint.X, textfont); rectangleF4.Width = sizeF.Width; rectangleF4.Height = sizeF.Height; g.DrawString(frontStr + "" + startPoint.X, textfont, textbrush, rectangleF4); } else { rectangleF4 = new RectangleF(); } // 像素起始点Y if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString())) { sizeF = g.MeasureString(frontStr + "" + startPoint.Y, textfont); rectangleF5.Width = sizeF.Width; rectangleF5.Height = sizeF.Height; g.DrawString(frontStr + "" + startPoint.Y, textfont, textbrush, rectangleF5); } else { rectangleF5 = new RectangleF(); } // 物理起始点X if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont); rectangleF6.Width = sizeF.Width; rectangleF6.Height = sizeF.Height; g.DrawString(frontStr + "" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont, textbrush, rectangleF6); } else { rectangleF6 = new RectangleF(); } // 物理起始点Y if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString())) { sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont); rectangleF7.Width = sizeF.Width; rectangleF7.Height = sizeF.Height; g.DrawString(frontStr + "" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont, textbrush, rectangleF7); } else { rectangleF7 = new RectangleF(); } // 像素长度 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(); } } //还原为原始旋转矩阵 g.Transform = mtxSave; linePen.Dispose(); matrix.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) { point = SetOffsetAfterRotation(point, rotationPoint, angle); 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.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); this.rectangleF4.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y); this.rectangleF5.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y); this.rectangleF6.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y); this.rectangleF7.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y); this.rectangleF8.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.Y); this.rectangleF9.Offset(point.X - this.rotationPoint.X, point.Y - this.rotationPoint.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(); } /// /// 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, angle)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle); moveKb = 1; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF2, point, rotationPoint, angle)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle); moveKb = 2; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF3, point, rotationPoint, angle)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle); moveKb = 3; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF4, point, rotationPoint, angle)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle); moveKb = 4; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF5, point, rotationPoint, angle)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle); moveKb = 5; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF6, point, rotationPoint, angle)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle); moveKb = 6; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF7, point, rotationPoint, angle)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle); moveKb = 7; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF8, point, rotationPoint, angle)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle); moveKb = 8; return this.pointArray.Count + 1; } else if (GetRectanglePosition(this.rectangleF9, point, rotationPoint, angle)) { this.pointL = SetOffsetAfterRotation(point, rotationPoint, angle); 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); } 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; } } /// /// 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; } } brush.Dispose(); pen.Dispose(); RectangleF r = GetBoundingBox(); //g.DrawRectangle(new Pen(Color.White), r.X, r.Y, r.Width, r.Height); } public override RectangleF GetBoundingBox() { RectangleF rectangle; 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; } } rectangle = new RectangleF(minx, miny, maxx - minx, maxy - miny); return rectangle; } public override List GetPoints() { return pointArray; } public override ParentStyleModel GetStyle() { return measureTraceCurve; } } }