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.Linq; using System.Windows.Forms; namespace PaintDotNet.Annotation.Measure { using PointList = List; /// /// 测量->圆->点到圆距离 /// public class MeasurePointArcSize : MeasureDrawObject { /// /// 点集合 /// public PointList pointArray; /// /// 样式 /// private MeasureStyleModel.MeasurePointArcSize measurePointArcSize; /// /// 圆心横坐标 /// double x0; /// /// 圆心纵坐标 /// double y0; /// /// 直径 /// double radius = 0; /// /// 直线与圆心的交点 /// Point distantPoint; /// /// 距离 /// //private double length = 0.0; private GraphicsPath areaPath = null; private Pen areaPen = null; private Region areaRegion = null; /// /// 测量信息矩形定义 /// 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 RectangleF rectangleF10 = new RectangleF(); private RectangleF rectangleF11 = new RectangleF(); private RectangleF rectangleF12 = new RectangleF(); private RectangleF rectangleF13 = new RectangleF(); private RectangleF rectangleF14 = new RectangleF(); private RectangleF rectangleF15 = new RectangleF(); private RectangleF rectangleF16 = new RectangleF(); private RectangleF rectangleF17 = 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; /// /// 限制绘制(绘制中) /// public bool mouseUpPointChange = false; public MeasurePointArcSize(ISurfaceBox surfaceBox) : base(surfaceBox) { this.objectType = DrawClass.Measure; this.drawToolType = DrawToolType.MeasurePointArcSize; measurePointArcSize = surfaceBox.GetMeasureStyleModel().measurePointArcSize; pointArray = new PointList(); Initialize(); } public MeasurePointArcSize(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox) { this.objectType = DrawClass.Measure; this.drawToolType = DrawToolType.MeasurePointArcSize; measurePointArcSize = surfaceBox.GetMeasureStyleModel().measurePointArcSize; pointArray = new PointList(); 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]; Initialize(); } public MeasurePointArcSize(ISurfaceBox surfaceBox, List points, ParentStyleModel parentStyleModel, Object content) : base(surfaceBox) { this.objectType = DrawClass.Measure; this.drawToolType = DrawToolType.MeasurePointArcSize; this.ISurfaceBox = surfaceBox; measurePointArcSize = (MeasureStyleModel.MeasurePointArcSize)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() { MeasurePointArcSize drawPointEdgeSize = new MeasurePointArcSize(ISurfaceBox, (int)pointArray[0].X, (int)pointArray[0].Y, false); drawPointEdgeSize.ISurfaceBox = ISurfaceBox; foreach (PointF p in this.pointArray) { drawPointEdgeSize.pointArray.Add(p); } if (drawingPropertiesList != null) drawPointEdgeSize.drawingPropertiesListClone = drawingPropertiesList; FillDrawObjectFields(drawPointEdgeSize); return drawPointEdgeSize; } public override DrawObject Clone(ISurfaceBox surfaceBox) { MeasurePointArcSize drawPointEdgeSize = new MeasurePointArcSize(surfaceBox, this.GetPoints(), this.measurePointArcSize, null); if (drawingPropertiesList != null) drawPointEdgeSize.drawingPropertiesListClone = drawingPropertiesList; FillDrawObjectFields(drawPointEdgeSize); return drawPointEdgeSize; } /// /// 测量属性 /// /// public override Dictionary GetData() { if (data.ContainsKey(MeasureAttributes.MeasureMethod)) data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"); else data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.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.PixelDistance)) data[MeasureAttributes.PixelDistance] = Math.Round(this.length, decimalPlaces); else data.Add(MeasureAttributes.PixelDistance, Math.Round(this.length, decimalPlaces)); string s = Math.Round(this.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.PhysicalDistance)) data[MeasureAttributes.PhysicalDistance] = s; else data.Add(MeasureAttributes.PhysicalDistance, s); if (data.ContainsKey(MeasureAttributes.PixelArea)) data[MeasureAttributes.PixelArea] = Math.Round(Math.PI * radius / 2 * radius / 2, decimalPlaces); else data.Add(MeasureAttributes.PixelArea, Math.Round(Math.PI * radius / 2 * radius / 2, decimalPlaces)); s = Math.Round(Math.PI * radius / 2 * radius / 2 * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } if (data.ContainsKey(MeasureAttributes.PhysicalArea)) data[MeasureAttributes.PhysicalArea] = s; else data.Add(MeasureAttributes.PhysicalArea, s); if (data.ContainsKey(MeasureAttributes.PixelCircumference)) data[MeasureAttributes.PixelCircumference] = Math.Round(Math.PI * radius , decimalPlaces); else data.Add(MeasureAttributes.PixelCircumference, Math.Round(Math.PI * radius, decimalPlaces)); s = Math.Round(Math.PI * radius * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } if (data.ContainsKey(MeasureAttributes.PhysicalCircumference)) data[MeasureAttributes.PhysicalCircumference] = s; else data.Add(MeasureAttributes.PhysicalCircumference, s); if (data.ContainsKey(MeasureAttributes.PixelCenterX)) data[MeasureAttributes.PixelCenterX] = Math.Round(this.x0, decimalPlaces); else data.Add(MeasureAttributes.PixelCenterX, Math.Round(this.x0, decimalPlaces)); if (data.ContainsKey(MeasureAttributes.PixelCenterY)) data[MeasureAttributes.PixelCenterY] = Math.Round(this.y0, decimalPlaces); else data.Add(MeasureAttributes.PixelCenterY, Math.Round(this.y0, decimalPlaces)); if (data.ContainsKey(MeasureAttributes.PhysicalCenterX)) data[MeasureAttributes.PhysicalCenterX] = Math.Round(this.x0 * unitLength, decimalPlaces); else data.Add(MeasureAttributes.PhysicalCenterX, Math.Round(this.x0 * unitLength, decimalPlaces)); if (data.ContainsKey(MeasureAttributes.PhysicalCenterY)) data[MeasureAttributes.PhysicalCenterY] = Math.Round(this.y0 * unitLength, decimalPlaces); else data.Add(MeasureAttributes.PhysicalCenterY, Math.Round(this.y0 * unitLength, decimalPlaces)); if (data.ContainsKey(MeasureAttributes.PixelRadius)) data[MeasureAttributes.PixelRadius] = Math.Round(radius / 2, decimalPlaces); else data.Add(MeasureAttributes.PixelRadius, Math.Round(radius / 2, decimalPlaces)); s = Math.Round(radius / 2 * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } if (data.ContainsKey(MeasureAttributes.PhysicalRadius)) data[MeasureAttributes.PhysicalRadius] = s; else data.Add(MeasureAttributes.PhysicalRadius, s); if (data.ContainsKey(MeasureAttributes.PixelDiameter)) data[MeasureAttributes.PixelDiameter] = Math.Round(radius, decimalPlaces); else data.Add(MeasureAttributes.PixelDiameter, Math.Round(radius, decimalPlaces)); s = Math.Round(radius * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } if (data.ContainsKey(MeasureAttributes.PhysicalDiameter)) data[MeasureAttributes.PhysicalDiameter] = s; else data.Add(MeasureAttributes.PhysicalDiameter, s); return data; } GraphicsPath path = new GraphicsPath(); public override void Draw(Graphics g) { path = new GraphicsPath(); measurePointArcSize = this.ISurfaceBox.GetMeasureStyleModel().measurePointArcSize; drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList); pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange); Color color = Color.FromArgb(this.measurePointArcSize.lineColor); Pen pen = new Pen(color, PenWidth); int penWidth = this.measurePointArcSize.lineWidth; pen.DashStyle = (DashStyle)this.measurePointArcSize.lineStyle; pen.Width = penWidth; Font textfont = new Font(measurePointArcSize.font, measurePointArcSize.fontSize); Brush textbrush = new SolidBrush(Color.FromArgb(measurePointArcSize.textColor)); Pen linePen = new Pen(Color.FromArgb(measurePointArcSize.lineColor), measurePointArcSize.lineWidth); linePen.DashStyle = (DashStyle)measurePointArcSize.lineStyle; if (this.Selected) { if (measurePointArcSize.chooseStyle != null) { textfont = new Font(measurePointArcSize.chooseStyle.font, measurePointArcSize.chooseStyle.fontSize); textbrush = new SolidBrush(Color.FromArgb(measurePointArcSize.chooseStyle.textColor)); linePen = new Pen(Color.FromArgb(measurePointArcSize.chooseStyle.lineColor), measurePointArcSize.chooseStyle.lineWidth); linePen.DashStyle = (DashStyle)measurePointArcSize.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(); rectangleF10 = new RectangleF(); rectangleF11 = new RectangleF(); rectangleF12 = new RectangleF(); rectangleF13 = new RectangleF(); rectangleF14 = new RectangleF(); rectangleF15 = new RectangleF(); rectangleF16 = new RectangleF(); rectangleF17 = new RectangleF(); } g.SmoothingMode = SmoothingMode.AntiAlias; if (HandleCount - 1 == 2) { g.DrawLine(linePen, pointArray[0].X, pointArray[0].Y, pointArray[1].X, pointArray[1].Y); } string frontStr = string.Empty; if (this.measurePointArcSize.showSuffix) { frontStr = this.measurePointArcSize.suffixName; } if (this.measurePointArcSize.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.measurePointArcSize.showAlias) { frontStr = this.measurePointArcSize.aliasName + frontStr; } if (HandleCount - 1 > 2) { if (drawingPropertiesList == null) { drawingPropertiesList = drawingPropertiesListClone; this.configurationFile = true; } double a = pointArray[0].X - pointArray[1].X; double b = pointArray[0].Y - pointArray[1].Y; double c = pointArray[0].X - pointArray[2].X; double d = pointArray[0].Y - pointArray[2].Y; double e = ((pointArray[0].X * pointArray[0].X - pointArray[1].X * pointArray[1].X) + (pointArray[0].Y * pointArray[0].Y - pointArray[1].Y * pointArray[1].Y)) / 2.0; double f = ((pointArray[0].X * pointArray[0].X - pointArray[2].X * pointArray[2].X) + (pointArray[0].Y * pointArray[0].Y - pointArray[2].Y * pointArray[2].Y)) / 2.0; double det = b * c - a * d; if (Math.Abs(det) > 0.001) { //x0,y0为计算得到的原点 x0 = -(d * e - b * f) / det; y0 = -(a * f - c * e) / det; radius = Math.Sqrt((pointArray[0].X - x0) * (pointArray[0].X - x0) + (pointArray[0].Y - y0) * (pointArray[0].Y - y0)); double angle1; double angle2; double angle3; double sinValue1; double cosValue1; double sinValue2; double cosValue2; double sinValue3; double cosValue3; sinValue1 = (pointArray[0].Y - y0) / radius; cosValue1 = (pointArray[0].X - x0) / radius; if (cosValue1 >= 0.99999) cosValue1 = 0.99999; if (cosValue1 <= -0.99999) cosValue1 = -0.99999; angle1 = Math.Acos(cosValue1); angle1 = angle1 / 3.14 * 180; if (sinValue1 < -0.05) angle1 = 360 - angle1; sinValue2 = (pointArray[1].Y - y0) / radius; cosValue2 = (pointArray[1].X - x0) / radius; if (cosValue2 >= 0.99999) cosValue2 = 0.99999; if (cosValue2 <= -0.99999) cosValue2 = -0.99999; angle2 = Math.Acos(cosValue2); angle2 = angle2 / 3.14 * 180; if (sinValue2 < -0.05) angle2 = 360 - angle2; sinValue3 = (pointArray[2].Y - y0) / radius; cosValue3 = (pointArray[2].X - x0) / radius; if (cosValue3 >= 0.99999) cosValue3 = 0.99999; if (cosValue3 <= -0.99999) cosValue3 = -0.99999; angle3 = Math.Acos(cosValue3); angle3 = angle3 / 3.14 * 180; if (sinValue3 < -0.05) angle3 = 360 - angle3; bool PosDown = false; double Delta13; if (angle1 < angle3) { Delta13 = angle3 - angle1; } else Delta13 = angle3 - angle1 + 360; double Delta12; if (angle1 < angle2) { Delta12 = angle2 - angle1; } else Delta12 = angle2 - angle1 + 360; if (Delta13 > Delta12) PosDown = true; else PosDown = false; double radius1 = radius + 5; if (PosDown) { if (angle3 > angle1) { g.DrawArc(pen, (int)(x0 - radius), (int)(y0 - radius), (int)(2 * radius), (int)(2 * radius), (int)(angle1), (int)(angle3 - angle1)); path.AddArc((int)(x0 - radius1), (int)(y0 - radius1), (int)(2 * radius1), (int)(2 * radius1), (int)(angle1), (int)(angle3 - angle1)); } else { g.DrawArc(pen, (int)(x0 - radius), (int)(y0 - radius), (int)(2 * radius), (int)(2 * radius), (int)(angle1), (int)(angle3 - angle1 + 360)); path.AddArc((int)(x0 - radius1), (int)(y0 - radius1), (int)(2 * radius1), (int)(2 * radius1), (int)(angle1), (int)(angle3 - angle1 + 360)); } } else { if (angle1 > angle3) { g.DrawArc(pen, (int)(x0 - radius), (int)(y0 - radius), (int)(2 * radius), (int)(2 * radius), (int)(angle3), (int)(angle1 - angle3)); path.AddArc((int)(x0 - radius1), (int)(y0 - radius1), (int)(2 * radius1), (int)(2 * radius1), (int)(angle3), (int)(angle1 - angle3)); } else { g.DrawArc(pen, (int)(x0 - radius), (int)(y0 - radius), (int)(2 * radius), (int)(2 * radius), (int)(angle3), (int)(angle1 - angle3 + 360)); path.AddArc((int)(x0 - radius1), (int)(y0 - radius1), (int)(2 * radius1), (int)(2 * radius1), (int)(angle3), (int)(angle1 - angle3 + 360)); } } } float x1 = pointArray[0].X; float y1 = pointArray[0].Y; float x2 = pointArray[1].X; float y2 = pointArray[1].Y; float x3 = pointArray[2].X; float y3 = pointArray[2].Y; a = x1 - x2; b = y1 - y2; c = x1 - x3; d = y1 - y3; e = ((x1 * x1 - x2 * x2) + (y1 * y1 - y2 * y2)) / 2.0; f = ((x1 * x1 - x3 * x3) + (y1 * y1 - y3 * y3)) / 2.0; x0 = x1; y0 = y1; double det1 = b * c - a * d; if (Math.Abs(det1) > 0.001) { //x0,y0为计算得到的原点 x0 = -(d * e - b * f) / det1; y0 = -(a * f - c * e) / det1; radius = Math.Round(Math.Sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) * 2, 2); } rectangle.X = Convert.ToInt32(x0 - radius / 2); rectangle.Y = Convert.ToInt32(y0 - radius / 2); rectangle.Width = Convert.ToInt32(radius); rectangle.Height = Convert.ToInt32(radius); if (HandleCount - 1 == 4) { if (drawingPropertiesList == null) { drawingPropertiesList = drawingPropertiesListClone; this.configurationFile = true; } SizeF sizeF1 = new SizeF(); double towPointDistance = BasicCalculationHelper.GetDistance(new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), new PointF(pointArray[3].X, pointArray[3].Y), 2); double edgeSize = Math.Abs(towPointDistance - (radius / 2)); double arrowAngle = BasicCalculationHelper.CalculateAngle(x0, y0, x0 - radius / 2, y0, pointArray[3].X, pointArray[3].Y); if (pointArray[3].X - x0 >= 0 && pointArray[3].Y - y0 <= 0) { arrowAngle = arrowAngle + 180; } if (pointArray[3].X - x0 >= 0 && pointArray[3].Y - y0 >= 0) { arrowAngle = arrowAngle - 180; } distantPoint = BasicCalculationHelper.GetAnglePoint(new Point(Convert.ToInt32(x0 - radius / 2), Convert.ToInt32(y0)), new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), arrowAngle); System.Drawing.Region region = new Region(path); double length = BasicCalculationHelper.GetDistance(distantPoint, pointArray[0], 0); double length1 = BasicCalculationHelper.GetDistance(distantPoint, pointArray[2], 0); if (!region.IsVisible(distantPoint)) { if(length >= length1) { pointArray[3] = BasicCalculationHelper.GetIntersection(new PointF((float)x0, (float)y0), pointArray[2], pointArray[3], new PointF(pointArray[3].X + 10, pointArray[3].Y)); distantPoint = new Point((int)pointArray[2].X, (int)pointArray[2].Y); } else { pointArray[3] = BasicCalculationHelper.GetIntersection(new PointF((float)x0, (float)y0), pointArray[0], pointArray[3], new PointF(pointArray[3].X + 10, pointArray[3].Y)); distantPoint = new Point((int)pointArray[0].X, (int)pointArray[0].Y); } } g.DrawLine(linePen, pointArray[3].X, pointArray[3].Y, distantPoint.X, distantPoint.Y); this.length = edgeSize; if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute) { int offsetValue = measurePointArcSize.fontSize + measurePointArcSize.fontSize / 2; int offsetValue1 = measurePointArcSize.lineWidth * 2 / 3; int offset = offsetValue1; this.pointL = new Point((int)pointArray[0].X, (int)pointArray[0].Y); if (drawingPropertiesList != null) { if (drawingPropertiesList.Contains(MeasureAttributes.PixelDistance.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.length, decimalPlaces) + "px", textfont); rectangleF16.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDistance.ToString())) { string s = Math.Round(this.length * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.length * unitLength, decimalPlaces) + this.unit, textfont); rectangleF17.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PixelRadius.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(radius / 2, decimalPlaces) + "px", textfont); rectangleF12.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalRadius.ToString())) { string s = Math.Round(radius / 2 * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont); rectangleF13.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PixelDiameter.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(radius, decimalPlaces) + "px", textfont); rectangleF14.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDiameter.ToString())) { string s = Math.Round(radius * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont); rectangleF15.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont); rectangleF6.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString())) { string s = Math.Round(Math.PI * radius * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont); rectangleF7.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont); rectangleF4.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString())) { string s = Math.Round(Math.PI * (radius / 2) * (radius / 2) * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + s + this.unit + "²", textfont); rectangleF5.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterX.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.x0, decimalPlaces), textfont); rectangleF8.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.y0, decimalPlaces), textfont); rectangleF9.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.x0 * unitLength, decimalPlaces), textfont); rectangleF10.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.y0 * unitLength, decimalPlaces), textfont); rectangleF11.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"), textfont); rectangleF1.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + this.unitString, textfont); rectangleF2.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + this.unit, textfont); rectangleF3.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset); offset += offsetValue; } } } if (drawingPropertiesList != null) { if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"), textfont); rectangleF1.Width = sizeF1.Width; rectangleF1.Height = sizeF1.Height; g.DrawString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"), textfont, textbrush, rectangleF1); } else { rectangleF1 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + this.unitString, textfont); rectangleF2.Width = sizeF1.Width; rectangleF2.Height = sizeF1.Height; g.DrawString(frontStr + "" + this.unitString, textfont, textbrush, rectangleF2); } else { rectangleF2 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + this.unit, textfont); rectangleF3.Width = sizeF1.Width; rectangleF3.Height = sizeF1.Height; g.DrawString(frontStr + "" + this.unit, textfont, textbrush, rectangleF3); } else { rectangleF3 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont); rectangleF4.Width = sizeF1.Width; rectangleF4.Height = sizeF1.Height; g.DrawString(frontStr + "" + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont, textbrush, rectangleF4); } else { rectangleF4 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString())) { string s = Math.Round(Math.PI * (radius / 2) * (radius / 2) * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + s + this.unit + "²", textfont); rectangleF5.Width = sizeF1.Width; rectangleF5.Height = sizeF1.Height; g.DrawString(frontStr + s + this.unit + "²", textfont, textbrush, rectangleF5); } else { rectangleF5 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont); rectangleF6.Width = sizeF1.Width; rectangleF6.Height = sizeF1.Height; g.DrawString(frontStr + "" + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont, textbrush, rectangleF6); } else { rectangleF6 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString())) { string s = Math.Round(Math.PI * radius * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont); rectangleF7.Width = sizeF1.Width; rectangleF7.Height = sizeF1.Height; g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF7); } else { rectangleF7 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterX.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.x0, decimalPlaces), textfont); rectangleF8.Width = sizeF1.Width; rectangleF8.Height = sizeF1.Height; g.DrawString(frontStr + "" + Math.Round(this.x0, decimalPlaces), textfont, textbrush, rectangleF8); } else { rectangleF8 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.y0, decimalPlaces), textfont); rectangleF9.Width = sizeF1.Width; rectangleF9.Height = sizeF1.Height; g.DrawString(frontStr + "" + Math.Round(this.y0, decimalPlaces), textfont, textbrush, rectangleF9); } else { rectangleF9 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.x0 * unitLength, decimalPlaces), textfont); rectangleF10.Width = sizeF1.Width; rectangleF10.Height = sizeF1.Height; g.DrawString(frontStr + "" + Math.Round(this.x0 * unitLength, decimalPlaces), textfont, textbrush, rectangleF10); } else { rectangleF10 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.y0 * unitLength, decimalPlaces), textfont); rectangleF11.Width = sizeF1.Width; rectangleF11.Height = sizeF1.Height; g.DrawString(frontStr + "" + Math.Round(this.y0 * unitLength, decimalPlaces), textfont, textbrush, rectangleF11); } else { rectangleF11 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PixelRadius.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(radius / 2, decimalPlaces) + "px", textfont); rectangleF12.Width = sizeF1.Width; rectangleF12.Height = sizeF1.Height; g.DrawString(frontStr + "" + Math.Round(radius / 2, decimalPlaces) + "px", textfont, textbrush, rectangleF12); } else { rectangleF12 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalRadius.ToString())) { string s = Math.Round(radius / 2 * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont); rectangleF13.Width = sizeF1.Width; rectangleF13.Height = sizeF1.Height; g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF13); } else { rectangleF13 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PixelDiameter.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(radius, decimalPlaces) + "px", textfont); rectangleF14.Width = sizeF1.Width; rectangleF14.Height = sizeF1.Height; g.DrawString(frontStr + "" + Math.Round(radius, decimalPlaces) + "px", textfont, textbrush, rectangleF14); } else { rectangleF14 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDiameter.ToString())) { string s = Math.Round(radius * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont); rectangleF15.Width = sizeF1.Width; rectangleF15.Height = sizeF1.Height; g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF15); } else { rectangleF15 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PixelDistance.ToString())) { sizeF1 = g.MeasureString(frontStr + "" + Math.Round(this.length, decimalPlaces) + "px", textfont); rectangleF16.Width = sizeF1.Width; rectangleF16.Height = sizeF1.Height; g.DrawString(frontStr + "" + Math.Round(this.length, decimalPlaces) + "px", textfont, textbrush, rectangleF16); } else { rectangleF16 = new RectangleF(); } if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDistance.ToString())) { string s = Math.Round(this.length * unitLength, decimalPlaces).ToString(); if (s.IndexOf(".") == -1) { for (int i = 0; i < decimalPlaces; i++) { if (i == 0) s += "."; s += "0"; } } else { int dic = s.Length - s.IndexOf(".") - 1; if (dic < decimalPlaces) { for (int i = 0; i < decimalPlaces - dic; i++) { s += "0"; } } } sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont); rectangleF17.Width = sizeF1.Width; rectangleF17.Height = sizeF1.Height; g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF17); } else { rectangleF17 = new RectangleF(); } } } } pen.Dispose(); linePen.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) { float x = 0; float y = 0; switch (handleNumber) { case 1: x = pointArray[0].X; y = pointArray[0].Y; break; case 2: x = pointArray[1].X; y = pointArray[1].Y; break; case 3: x = pointArray[2].X; y = pointArray[2].Y; break; case 4: x = pointArray[3].X; y = pointArray[3].Y; break; case 5: x = distantPoint.X; y = distantPoint.Y; break; case 6: x = Convert.ToInt32(x0); y = Convert.ToInt32(y0); break; case 7: x = this.pointL.X; y = this.pointL.Y; break; } return new PointF(x, y); } /// /// 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 <= 6; i++) { if (GetHandleRectangle(i).Contains(point)) return i; } if (this.rectangleF1.Contains(point)) { this.pointL = point; moveKb = 1; return 7; } else if (this.rectangleF2.Contains(point)) { this.pointL = point; moveKb = 2; return 7; } else if (this.rectangleF3.Contains(point)) { this.pointL = point; moveKb = 3; return 7; } else if (this.rectangleF4.Contains(point)) { this.pointL = point; moveKb = 4; return 7; } else if (this.rectangleF5.Contains(point)) { this.pointL = point; moveKb = 5; return 7; } else if (this.rectangleF6.Contains(point)) { this.pointL = point; moveKb = 6; return 7; } else if (this.rectangleF7.Contains(point)) { this.pointL = point; moveKb = 7; return 7; } else if (this.rectangleF8.Contains(point)) { this.pointL = point; moveKb = 8; return 7; } else if (this.rectangleF9.Contains(point)) { this.pointL = point; moveKb = 9; return 7; } else if (this.rectangleF10.Contains(point)) { this.pointL = point; moveKb = 10; return 7; } else if (this.rectangleF11.Contains(point)) { this.pointL = point; moveKb = 11; return 7; } else if (this.rectangleF12.Contains(point)) { this.pointL = point; moveKb = 12; return 7; } else if (this.rectangleF13.Contains(point)) { this.pointL = point; moveKb = 13; return 7; } else if (this.rectangleF14.Contains(point)) { this.pointL = point; moveKb = 14; return 7; } else if (this.rectangleF15.Contains(point)) { this.pointL = point; moveKb = 15; return 7; } else if (this.rectangleF16.Contains(point)) { this.pointL = point; moveKb = 16; return 7; } else if (this.rectangleF17.Contains(point)) { this.pointL = point; moveKb = 17; return 7; } } if (PointInObject(point)) return 0; return -1; } protected override bool PointInObject(Point point) { CreateObjects(); return rectangle.Contains(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); } protected GraphicsPath AreaPath { get { return areaPath; } set { areaPath = value; } } protected Region AreaRegion { get { return areaRegion; } set { areaRegion = value; } } protected Pen AreaPen { get { return areaPen; } set { areaPen = value; } } public override Cursor GetHandleCursor(int handleNumber) { return handleCursor; } public override void MoveHandleTo(Point point, int handleNumber) { //aaa = false; //System.Drawing.Region region = new Region(path); //if (region.IsVisible(distantPoint)) //{ // aaa = true; //} if (handleNumber < 5) { 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); this.rectangleF10.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y); this.rectangleF11.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y); this.rectangleF12.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y); this.rectangleF13.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y); this.rectangleF14.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y); this.rectangleF15.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y); this.rectangleF16.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y); this.rectangleF17.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y); } //else if (handleNumber == 4) //{ // if (aaa) // pointArray[handleNumber - 1] = point; // else // { // //pointArray[handleNumber - 1] = pointF; // } //} //else pointArray[handleNumber - 1] = point; } else if (handleNumber == 7) { 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); else if (this.moveKb == 10) this.rectangleF10.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y); else if (this.moveKb == 11) this.rectangleF11.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y); else if (this.moveKb == 12) this.rectangleF12.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y); else if (this.moveKb == 13) this.rectangleF13.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y); else if (this.moveKb == 14) this.rectangleF14.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y); else if (this.moveKb == 15) this.rectangleF15.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y); else if (this.moveKb == 16) this.rectangleF16.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y); else if (this.moveKb == 17) this.rectangleF17.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y); this.pointL = point; } } public override void Move(int deltaX, int deltaY) { for (int i = 0; i < pointArray.Count; i++) { pointArray[i] = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY)); } 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); this.rectangleF10.Offset(x, y); this.rectangleF11.Offset(x, y); this.rectangleF12.Offset(x, y); this.rectangleF13.Offset(x, y); this.rectangleF14.Offset(x, y); this.rectangleF15.Offset(x, y); this.rectangleF16.Offset(x, y); this.rectangleF17.Offset(x, y); Invalidate(); } /// /// 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; } } /// /// Normalize rectangle /// public override void Normalize() { rectangle = Annotation.DrawObject.GetNormalizedRectangle(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); } public override void DrawTracker(Graphics g) { if (!Selected) return; if (pointArray.Count >= 4) { SolidBrush brush = new SolidBrush(Color.FromArgb(MarkpointAreaColor)); Pen pen = new Pen(Color.FromArgb(MarkpointLineColor), MarkpointLineWidth); for (int i = 1; i <= 6; i++) { if (i == 7) { 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); } } public override List GetPoints() { return pointArray; } public override ParentStyleModel GetStyle() { return measurePointArcSize; } } }