1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492 |
- 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.Net.NetworkInformation;
- using System.Collections;
- using System.Linq;
- namespace PaintDotNet.Annotation.Measure
- {
- using PointList = List<PointF>;
- /// <summary>
- /// 测量->多点线段->多点直线
- /// </summary>
- public class MeasureMulLine : MeasureDrawObject
- {
- public PointList pointArray;
- private const string entryLength = "Length";
- private const string entryPoint = "Point";
- /// <summary>
- /// Graphic objects for hit test
- /// </summary>
- private GraphicsPath areaPath = null;
- private Pen areaPen = null;
- private Region areaRegion = null;
- /// <summary>
- /// 长度
- /// </summary>
- private double allLength = 0.0;
- /// <summary>
- /// 测量信息矩形定义
- /// </summary>
- private RectangleF rectangleF1 = new RectangleF();
- private RectangleF rectangleF2 = new RectangleF();
- private RectangleF rectangleF3 = new RectangleF();
- private RectangleF rectangleF4 = new RectangleF();
- private RectangleF rectangleF5 = new RectangleF();
- /// <summary>
- /// 文本上用于拖动的点
- /// </summary>
- private Point pointL = new Point();
- /// <summary>
- /// 绘制限制(第一次绘制时)
- /// </summary>
- public bool pointChange = true;
- /// <summary>
- /// 属性绘制点
- /// </summary>
- private PointF rotationPoint;
- private PointF rotationPoint1;
- /// <summary>
- /// 区分移动文本
- /// </summary>
- private int moveKb;
- /// <summary>
- /// 绘制限制(从配置文件加载)
- /// </summary>
- public bool configurationFile = false;
- /// <summary>
- /// 绘制限制(更改属性时)
- /// </summary>
- private bool SavePointChange;
- /// <summary>
- /// 多点绘制时的文本矩形集合
- /// </summary>
- public List<RectangleF> RectangleFList = new List<RectangleF>();
- /// <summary>
- /// 绘制属性
- /// </summary>
- private string[] drawingPropertiesList;
- /// <summary>
- /// 绘制属性(克隆)
- /// </summary>
- private string[] drawingPropertiesListClone;
- /// <summary>
- /// 旋转角度
- /// </summary>
- private double angle;
- private double angle1 = 0;
- private int num = 0;
- private bool drawing;
- /// <summary>
- /// 限制绘制(绘制中)
- /// </summary>
- public bool mouseUpPointChange = false;
- /// <summary>
- /// 测量样式信息model
- /// </summary>
- private MeasureStyleModel.MeasureMulLine measureStyleModel;
- public MeasureStyleModel.MeasureMulLine MeasureStyleModel
- {
- set
- {
- this.measureStyleModel = value;
- }
- }
- public MeasureMulLine(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox)
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureMulLine;
- measureStyleModel = surfaceBox.GetMeasureStyleModel().measureMulLine;
- 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 MeasureMulLine(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureCurveLine;
- this.ISurfaceBox = surfaceBox;
- measureStyleModel = (MeasureStyleModel.MeasureMulLine)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];
-
- for (int i = 0; i < (points.Count - 1) * 6; i++)
- {
- this.RectangleFList.Add(new RectangleF());
- }
- this.configurationFile = true;
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- public override DrawObject Clone()
- {
- MeasureMulLine drawPolygon = new MeasureMulLine(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;
- foreach (var rectangleF in RectangleFList)
- {
- drawPolygon.RectangleFList.Add(rectangleF);
- }
- FillDrawObjectFields(drawPolygon);
- return drawPolygon;
- }
- public override DrawObject Clone(ISurfaceBox surfaceBox)
- {
- MeasureMulLine drawPolygon = new MeasureMulLine(surfaceBox, this.GetPoints(), this.measureStyleModel, null);
- if (drawingPropertiesList != null)
- drawPolygon.drawingPropertiesListClone = drawingPropertiesList;
- foreach (var rectangleF in RectangleFList)
- {
- drawPolygon.RectangleFList.Add(rectangleF);
- }
- FillDrawObjectFields(drawPolygon);
- return drawPolygon;
- }
- /// <summary>
- /// 测量属性
- /// </summary>
- /// <returns></returns>
- public override Dictionary<System.Enum, object> GetData()
- {
- if (data.ContainsKey(MeasureAttributes.MeasureMethod))
- data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.MeasureMulSegment.Text");
- else
- data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.MeasureMulSegment.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(allLength, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelLength, Math.Round(allLength, decimalPlaces));
- string s = Math.Round(allLength * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int c = 0; c < decimalPlaces; c++)
- {
- if (c == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int a = s.Length - s.IndexOf(".") - 1;
- if (a < decimalPlaces)
- {
- for (int c = 0; c < decimalPlaces - a; c++)
- {
- s += "0";
- }
- }
- }
- if (data.ContainsKey(MeasureAttributes.PhysicalLength))
- data[MeasureAttributes.PhysicalLength] = s;
- else
- data.Add(MeasureAttributes.PhysicalLength, s);
- if (data.ContainsKey(MeasureAttributes.PixelAverageIntercept))
- data[MeasureAttributes.PixelAverageIntercept] = Math.Round(allLength / (pointArray.Count - 1), decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelAverageIntercept, Math.Round(allLength / (pointArray.Count - 1), decimalPlaces));
- s = Math.Round(allLength * unitLength / (pointArray.Count - 1), 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.PhysicalAverage))
- data[MeasureAttributes.PhysicalAverage] = s;
- else
- data.Add(MeasureAttributes.PhysicalAverage, s);
- return data;
- }
-
- public override void Draw(Graphics g)
- {
- measureStyleModel = this.ISurfaceBox.GetMeasureStyleModel().measureMulLine;
- lengthParagraphs = new List<string>();
- drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
- if (drawingPropertiesList == null)
- {
- drawingPropertiesList = drawingPropertiesListClone;
- if (!this.drawing)
- this.configurationFile = true;
- }
- pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
- Matrix mtxSave1 = g.Transform;
- Matrix matrix1 = g.Transform;
- Font textfont1 = new Font(measureStyleModel.font, measureStyleModel.fontSize);
- Brush textbrush1 = new SolidBrush(Color.FromArgb(measureStyleModel.textColor));
- // 总长度
- double alllength = 0.0;
- // 段长度
- double length = 0.0;
- SizeF sizeF = new SizeF();
- int a1 = 0;
- int a2 = 1;
- int a3 = 2;
- int a4 = 3;
- int a5 = 4;
- int a6 = 5;
- RectangleF rectangleF;
- string frontStr = string.Empty;
- if (this.measureStyleModel.showSuffix)
- {
- frontStr = this.measureStyleModel.suffixName;
- }
- if (this.measureStyleModel.showSerial)
- {
- #region [获取序号]
- List<DrawObject> newGraphicsList = new List<DrawObject>();
- 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;
- }
- // 多点绘制
- for (int i = 1; i <= pointArray.Count - 1; i++)
- {
- Matrix mtxSave = g.Transform;
- Matrix matrix = g.Transform;
- int offsetValuePoint = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
- int offsetValue1Point = measureStyleModel.lineWidth * 2 / 3;
- int offsetPoint = offsetValue1Point;
- if (drawingPropertiesList != null)
- {
- // 像素长度
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- // 物理长度
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- // 像素起始点X
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- // 像素起始点Y
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- // 物理起始点X
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- // 物理起始点Y
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- }
- PointF pointF1;
- PointF pointF2;
- //计算需要旋转的角度
- double angle = BasicCalculationHelper.Angle(pointArray[i - 1], pointArray[i], new PointF(pointArray[i - 1].X, pointArray[i].Y));
- if (angle < 90)
- pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[i - 1].X + offsetPoint + offsetValue1Point, (int)pointArray[i - 1].Y), pointArray[i - 1], angle - 90);
- else
- pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[i - 1].X + offsetPoint + offsetValue1Point, (int)pointArray[i - 1].Y), pointArray[i - 1], angle + 90);
- if (angle < 90)
- pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[i].X + offsetPoint + offsetValue1Point, (int)pointArray[i].Y), pointArray[i], angle - 90);
- else
- pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[i].X + offsetPoint + offsetValue1Point, (int)pointArray[i].Y), pointArray[i], angle + 90);
- PointF 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 = pointArray[i - 1];
- else if (measureStyleModel.linePositionP == 4)
- this.rotationPoint1 = new PointF((pointArray[i - 1].X + pointArray[i].X) / 2, (pointArray[i - 1].Y + pointArray[i].Y) / 2);
- else if (measureStyleModel.linePositionP == 5)
- this.rotationPoint1 = pointArray[i];
-
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, rotationPoint1);
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(pointArray[i], pointArray[i - 1], new PointF(pointArray[i].X, pointArray[i - 1].Y));
- matrix.RotateAt((float)angle, rotationPoint1);
- g.Transform = matrix;
- }
- Font textfont = new Font(measureStyleModel.font, measureStyleModel.fontSize);
- Brush textbrush = new SolidBrush(Color.FromArgb(measureStyleModel.textColor));
- Pen linePen = new Pen(Color.FromArgb(measureStyleModel.lineColor), measureStyleModel.lineWidth);
- linePen.DashStyle = (DashStyle)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));
- linePen = new Pen(Color.FromArgb(measureStyleModel.chooseStyle.lineColor), measureStyleModel.chooseStyle.lineWidth);
- linePen.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();
- }
- g.SmoothingMode = SmoothingMode.AntiAlias;
- // 段长度
- length = BasicCalculationHelper.GetDistance(pointArray[i - 1], pointArray[i], 10);
- //length = BasicCalculationHelper.GetDistance(pointArray[i - 1], pointArray[i], 10) / pxPerUnit;
- // 总长度
- alllength = alllength + length;
- int offsetValue = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
- int offsetValue1 = measureStyleModel.lineWidth * 2 / 3;
- int offset = offsetValue1;
- if (drawingPropertiesList != null)
- {
- // 像素长度
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelLength.ToString()))
- {
- rectangleF = this.RectangleFList[a1];
- sizeF = g.MeasureString("" + Math.Round(length, decimalPlaces) + "px", textfont1);
- rectangleF.Width = sizeF.Width;
- rectangleF.Height = sizeF.Height;
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- rectangleF.Location = new PointF((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset);
- offset += offsetValue;
- this.RectangleFList[a1] = rectangleF;
- }
- g.DrawString("" + Math.Round(length, decimalPlaces) + "px", textfont1, textbrush1, this.RectangleFList[a1]);
- a1 += 6;
- }
- else
- {
- this.RectangleFList[a1] = new RectangleF();
- a1 += 6;
- }
- string s = Math.Round(length * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int c = 0; c < decimalPlaces; c++)
- {
- if (c == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int a = s.Length - s.IndexOf(".") - 1;
- if (a < decimalPlaces)
- {
- for (int c = 0; c < decimalPlaces - a; c++)
- {
- s += "0";
- }
- }
- }
- lengthParagraphs.Add(s);
- // 物理长度
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalLength.ToString()))
- {
- rectangleF = this.RectangleFList[a2];
- if (i == 1)
- {
- sizeF = g.MeasureString(frontStr + "" + s + this.unit, textfont1);
- }
- else {
- sizeF = g.MeasureString("" + s + this.unit, textfont1);
- }
- rectangleF.Width = sizeF.Width;
- rectangleF.Height = sizeF.Height;
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- rectangleF.Location = new PointF((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset);
- offset += offsetValue;
- this.RectangleFList[a2] = rectangleF;
- }
- if (i == 1)
- {
- g.DrawString(frontStr + "" + s + this.unit, textfont1, textbrush1, this.RectangleFList[a2]);
- }
- else
- {
- g.DrawString("" + s + this.unit, textfont1, textbrush1, this.RectangleFList[a2]);
- }
- a2 += 6;
- }
- else
- {
- this.RectangleFList[a2] = new RectangleF();
- a2 += 6;
- }
- // 像素起始点X
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
- {
- rectangleF = this.RectangleFList[a3];
- sizeF = g.MeasureString("" + pointArray[i].X, textfont1);
- rectangleF.Width = sizeF.Width;
- rectangleF.Height = sizeF.Height;
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- rectangleF.Location = new PointF((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset);
- offset += offsetValue;
- this.RectangleFList[a3] = rectangleF;
- }
- g.DrawString("" + pointArray[i].X, textfont1, textbrush1, this.RectangleFList[a3]);
- a3 += 6;
- }
- else
- {
- this.RectangleFList[a3] = new RectangleF();
- a3 += 6;
- }
- // 像素起始点Y
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
- {
- rectangleF = this.RectangleFList[a4];
- sizeF = g.MeasureString("" + pointArray[i].Y, textfont1);
- rectangleF.Width = sizeF.Width;
- rectangleF.Height = sizeF.Height;
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- rectangleF.Location = new PointF((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset);
- offset += offsetValue;
- this.RectangleFList[a4] = rectangleF;
- }
- g.DrawString("" + pointArray[i].Y, textfont1, textbrush1, this.RectangleFList[a4]);
- a4 += 6;
- }
- else
- {
- this.RectangleFList[a4] = new RectangleF();
- a4 += 6;
- }
- // 物理起始点X
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
- {
- rectangleF = this.RectangleFList[a5];
- sizeF = g.MeasureString("" + Math.Round(pointArray[i].X * unitLength, decimalPlaces), textfont1);
- rectangleF.Width = sizeF.Width;
- rectangleF.Height = sizeF.Height;
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- rectangleF.Location = new PointF((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset);
- offset += offsetValue;
- this.RectangleFList[a5] = rectangleF;
- }
- g.DrawString("" + Math.Round(pointArray[i].X * unitLength, decimalPlaces), textfont1, textbrush1, this.RectangleFList[a5]);
- a5 += 6;
- }
- else
- {
- this.RectangleFList[a5] = new RectangleF();
- a5 += 6;
- }
- // 物理起始点Y
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
- {
- rectangleF = this.RectangleFList[a6];
- sizeF = g.MeasureString("" + Math.Round(pointArray[i].Y * unitLength, decimalPlaces), textfont1);
- rectangleF.Width = sizeF.Width;
- rectangleF.Height = sizeF.Height;
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- rectangleF.Location = new PointF((int)rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint1.Y + offset);
- offset += offsetValue;
- this.RectangleFList[a6] = rectangleF;
- }
- g.DrawString("" + Math.Round(pointArray[i].Y * unitLength, decimalPlaces), textfont1, textbrush1, this.RectangleFList[a6]);
- a6 += 6;
- }
- else
- {
- this.RectangleFList[a6] = new RectangleF();
- a6 += 6;
- }
- }
- //还原为原始旋转矩阵
- g.Transform = mtxSave;
- matrix.Dispose();
- PointF point = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i - 1].X, pointArray[i - 1].Y + measureStyleModel.vLineLength), pointArray[i - 1], angle);
- PointF point1 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i - 1].X, pointArray[i - 1].Y - measureStyleModel.vLineLength), pointArray[i - 1], angle);
- PointF point2 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i].X, pointArray[i].Y + measureStyleModel.vLineLength), pointArray[i], angle);
- PointF point3 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i].X, pointArray[i].Y - measureStyleModel.vLineLength), pointArray[i], angle);
- if (this.Selected)
- {
- if (measureStyleModel.chooseStyle != null)
- {
- point = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i - 1].X, pointArray[i - 1].Y + measureStyleModel.chooseStyle.vLineLength), pointArray[i - 1], angle);
- point1 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i - 1].X, pointArray[i - 1].Y - measureStyleModel.chooseStyle.vLineLength), pointArray[i - 1], angle);
- point2 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i].X, pointArray[i].Y + measureStyleModel.chooseStyle.vLineLength), pointArray[i], angle);
- point3 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i].X, pointArray[i].Y - measureStyleModel.chooseStyle.vLineLength), pointArray[i], angle);
- }
- }
- g.DrawLine(linePen, point.X, point.Y, point1.X, point1.Y);
- g.DrawLine(linePen, point2.X, point2.Y, point3.X, point3.Y);
- g.DrawLine(linePen, pointArray[i - 1], pointArray[i]);
- linePen.Dispose();
- }
- this.allLength = alllength;
- if (pointArray.Count > 1)
- {
- // 旋转角度
- this.angle = 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.PixelAverageIntercept.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- // 物理平均截距
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalAverage.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- // 测量方式
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- // 测量单位(中文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- }
- // 测量单位(英文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- }
- PointF pointF1;
- PointF pointF2;
- if (angle < 90)
- pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[0].X + offsetPoint + offsetValue1Point, (int)pointArray[0].Y), pointArray[0], angle - 90);
- else
- pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[0].X + offsetPoint + offsetValue1Point, (int)pointArray[0].Y), pointArray[0], angle + 90);
- if (angle < 90)
- pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[1].X + offsetPoint + offsetValue1Point, (int)pointArray[1].Y), pointArray[1], angle - 90);
- else
- pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)pointArray[1].X + offsetPoint + offsetValue1Point, (int)pointArray[1].Y), pointArray[1], angle + 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];
- if (this.angle < 90)
- {
- matrix1.RotateAt((float)this.angle, new PointF(rotationPoint.X, rotationPoint.Y));
- g.Transform = matrix1;
- }
- else
- {
- this.angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[0], new PointF(pointArray[1].X, pointArray[0].Y));
- matrix1.RotateAt((float)this.angle, new PointF(rotationPoint.X, rotationPoint.Y));
- g.Transform = matrix1;
- }
- }
- // 是否绘制
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- // 文本间隔定义
- int offsetValue = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
- int offsetValue1 = measureStyleModel.lineWidth * 2 / 3;
- int offset = offsetValue1 - offsetValue;
- if (measureStyleModel.linePositionL == 3 || measureStyleModel.linePositionL == 4 || measureStyleModel.linePositionL == 5)
- offset = offsetValue1;
- this.pointL = new Point((int)rotationPoint.X, (int)rotationPoint.Y);
- if (drawingPropertiesList != null)
- {
- // 像素平均截距
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelAverageIntercept.ToString()))
- {
- sizeF = g.MeasureString(frontStr + Math.Round(allLength / (pointArray.Count - 1), decimalPlaces) + "px", textfont1);
- rectangleF4.Location = new Point((int)rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset);
- offset += offsetValue;
- }
- // 物理平均截距
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalAverage.ToString()))
- {
- string s = Math.Round(allLength * unitLength / (pointArray.Count - 1), 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, textfont1);
- rectangleF5.Location = new Point((int)rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset);
- offset += offsetValue;
- }
- // 测量方式
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- sizeF = g.MeasureString(frontStr + PdnResources.GetString("Menu.MeasureAction.MeasureMulSegment.Text"), textfont1);
- rectangleF1.Location = new Point((int)rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset);
- offset += offsetValue;
- }
- // 测量单位(中文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + this.unitString, textfont1);
- rectangleF2.Location = new Point((int)rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)rotationPoint.Y + offset);
- offset += offsetValue;
- }
- // 测量单位(英文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + this.unit, textfont1);
- rectangleF3.Location = new Point((int)rotationPoint.X + offsetValue1 - (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.MeasureMulSegment.Text"), textfont1);
- rectangleF1.Width = sizeF.Width;
- rectangleF1.Height = sizeF.Height;
- g.DrawString(frontStr + PdnResources.GetString("Menu.MeasureAction.MeasureMulSegment.Text"), textfont1, textbrush1, rectangleF1);
- }
- else
- {
- rectangleF1 = new RectangleF();
- }
- // 测量单位(中文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + this.unitString, textfont1);
- rectangleF2.Width = sizeF.Width;
- rectangleF2.Height = sizeF.Height;
- g.DrawString(frontStr + this.unitString, textfont1, textbrush1, rectangleF2);
- }
- else
- {
- rectangleF2 = new RectangleF();
- }
- // 测量单位(英文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + this.unit, textfont1);
- rectangleF3.Width = sizeF.Width;
- rectangleF3.Height = sizeF.Height;
- g.DrawString(frontStr + this.unit, textfont1, textbrush1, rectangleF3);
- }
- else
- {
- rectangleF3 = new RectangleF();
- }
- // 像素平均截距
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelAverageIntercept.ToString()))
- {
- sizeF = g.MeasureString(frontStr + Math.Round(allLength / (pointArray.Count - 1), decimalPlaces) + "px", textfont1);
- rectangleF4.Width = sizeF.Width;
- rectangleF4.Height = sizeF.Height;
- g.DrawString(frontStr + Math.Round(allLength / (pointArray.Count - 1), decimalPlaces) + "px", textfont1, textbrush1, rectangleF4);
- }
- else
- {
- rectangleF4 = new RectangleF();
- }
- // 物理平均截距
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalAverage.ToString()))
- {
- string s = Math.Round(allLength * unitLength / (pointArray.Count - 1), 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, textfont1);
- rectangleF5.Width = sizeF.Width;
- rectangleF5.Height = sizeF.Height;
- g.DrawString(frontStr + s + this.unit, textfont1, textbrush1, rectangleF5);
- }
- else
- {
- rectangleF5 = new RectangleF();
- }
- }
- g.Transform = mtxSave1;
- matrix1.Dispose();
- if (this.configurationFile)
- this.pointChange = false;
- this.mouseUpAttribute = false;
- pointChangeObject.Remove(this.drawToolType);
- }
- /// 停止绘制时
- /// </summary>
- /// <param name="up"></param>
- public override void MouseUp(bool up)
- {
- mouseUpPointChange = up;
- }
- public void AddPoint(Point point)
- {
- pointArray.Add(point);
- }
- public override int HandleCount
- {
- get
- {
- return pointArray.Count + 1;
- }
- }
- /// <summary>
- /// Get handle pointscroll by 1-based number
- /// </summary>
- /// <param name="handleNumber"></param>
- /// <returns></returns>
- public override PointF GetHandle(int handleNumber)
- {
- if (handleNumber < 1)
- handleNumber = 1;
- if (handleNumber > pointArray.Count && handleNumber != 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;
- }
- private Point GetInsectPoint(Point pt1, Point pt2, int insectPtY)
- {
- Point pt = new Point();
- float k = 0f;
- if (pt1.X == pt2.X)//不存在斜率x=x1为直线方程90度
- {
- pt.X = pt1.X;
- pt.Y = insectPtY;
- return pt;
- }
- else if (pt1.Y == pt2.Y && pt1.Y != insectPtY)//y=y1为直线方程,0度,两条直线平行没有交点
- {
- return pt;
- }
- else if (pt1.Y == pt2.Y && pt1.Y == insectPtY)//0度,两条直线重合,任意点即为交点
- {
- pt.X = pt1.X;
- pt.Y = insectPtY;
- return pt;
- }
- else
- {
- k = (float)(pt2.Y - pt1.Y) / (float)(pt2.X - pt1.X);
- float b = pt1.Y - k * pt1.X;
- float x = (insectPtY - b) / k;
- pt.X = (int)x;
- pt.Y = insectPtY;
- }
- return pt;
- }
- public override void MoveHandleTo(Point point, int handleNumber)
- {
- double k = 0.0;
- if (handleNumber < 1)
- handleNumber = 1;
- if (handleNumber > pointArray.Count && handleNumber != pointArray.Count + 1)
- handleNumber = pointArray.Count;
- if (handleNumber > 2)
- {
- if (handleNumber == pointArray.Count + 1)
- {
- if (this.moveKb == 1 || this.moveKb == 2 || this.moveKb == 3 || this.moveKb == 4 || this.moveKb == 5)
- {
- 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
- {
- for (int i = 0; i < this.RectangleFList.Count; i++)
- {
- num = i / 6;
- if (num + 1 < pointArray.Count)
- {
- //计算需要旋转的角度
- angle1 = BasicCalculationHelper.Angle(pointArray[num], pointArray[num + 1], new PointF(pointArray[num].X, pointArray[num + 1].Y));
- if (angle1 > 90)
- {
- angle1 = BasicCalculationHelper.Angle(pointArray[num + 1], pointArray[num], new PointF(pointArray[num + 1].X, pointArray[num].Y));
- }
- }
- RectangleF rectangleF = this.RectangleFList[i];
- if (this.moveKb == -i)
- {
- point = SetOffsetAfterRotation(point, pointArray[num + 1], angle1);
- rectangleF.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- this.RectangleFList[i] = rectangleF;
- break;
- }
-
- }
- }
- this.pointL = point;
- }
- else
- {
- this.mouseUpPointChange = true;
- // 求直线斜率
- if (pointArray[0].X != pointArray[1].X && pointArray[0].Y != pointArray[1].Y)
- {
- k = (double)(pointArray[1].Y - pointArray[0].Y) / (pointArray[1].X - pointArray[0].X);
- if(Math.Abs(k) >= 1)
- point = GetInsectPoint(new Point((int)pointArray[0].X, (int)pointArray[0].Y), new Point((int)pointArray[1].X, (int)pointArray[1].Y), point.Y);
- else
- point.Y = (int)(k * (point.X - pointArray[handleNumber - 2].X) + pointArray[handleNumber - 2].Y);
- for (int i = 1; i <= this.RectangleFList.Count; i++)
- {
- if (i == handleNumber)
- {
- RectangleF rectangleF = this.RectangleFList[i * 6 - 12];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 12] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 11];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 11] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 10];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 10] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 9];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 9] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 8];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 8] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 7];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 7] = rectangleF;
- }
- }
- pointArray[handleNumber - 1] = point;
- }
- if (pointArray[0].X == pointArray[1].X)
- {
- point.X = (int)pointArray[0].X;
- for (int i = 1; i <= this.RectangleFList.Count; i++)
- {
- if (i == handleNumber)
- {
- RectangleF rectangleF = this.RectangleFList[i * 6 - 12];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 12] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 11];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 11] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 10];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 10] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 9];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 9] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 8];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 8] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 7];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 7] = rectangleF;
- }
- }
- pointArray[handleNumber - 1] = point;
- }
- if (pointArray[0].Y == pointArray[1].Y)
- {
- point.Y = (int)pointArray[0].Y;
- for (int i = 1; i <= this.RectangleFList.Count; i++)
- {
- if (i == handleNumber)
- {
- RectangleF rectangleF = this.RectangleFList[i * 6 - 12];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 12] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 11];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 11] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 10];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 10] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 9];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 9] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 8];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 8] = rectangleF;
- rectangleF = this.RectangleFList[i * 6 - 7];
- rectangleF.Offset(point.X - this.pointArray[i - 1].X, point.Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 7] = rectangleF;
- }
- }
- pointArray[handleNumber - 1] = point;
- }
- }
- }
- else
- {
- if (handleNumber == 1)
- {
- this.mouseUpPointChange = true;
- 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);
- }
- else if (handleNumber == 2)
- {
- RectangleF rectangleF = this.RectangleFList[0];
- rectangleF.Offset(point.X - this.pointArray[1].X, point.Y - this.pointArray[1].Y);
- this.RectangleFList[0] = rectangleF;
- rectangleF = this.RectangleFList[1];
- rectangleF.Offset(point.X - this.pointArray[1].X, point.Y - this.pointArray[1].Y);
- this.RectangleFList[1] = rectangleF;
- rectangleF = this.RectangleFList[2];
- rectangleF.Offset(point.X - this.pointArray[1].X, point.Y - this.pointArray[1].Y);
- this.RectangleFList[2] = rectangleF;
- rectangleF = this.RectangleFList[3];
- rectangleF.Offset(point.X - this.pointArray[1].X, point.Y - this.pointArray[1].Y);
- this.RectangleFList[3] = rectangleF;
- rectangleF = this.RectangleFList[4];
- rectangleF.Offset(point.X - this.pointArray[1].X, point.Y - this.pointArray[1].Y);
- this.RectangleFList[4] = rectangleF;
- rectangleF = this.RectangleFList[5];
- rectangleF.Offset(point.X - this.pointArray[1].X, point.Y - this.pointArray[1].Y);
- this.RectangleFList[5] = rectangleF;
- }
- this.mouseUpPointChange = true;
- pointArray[handleNumber - 1] = point;
- }
- this.startPoint = pointArray[0];
- Invalidate();
- }
- public override void Move(int deltaX, int deltaY)
- {
- for (int i = 0; i < pointArray.Count; 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);
- for (int i = 0; i < this.RectangleFList.Count; i++)
- {
- RectangleF rectangleF = this.RectangleFList[i];
- rectangleF.Offset(x, y);
- this.RectangleFList[i] = rectangleF;
- }
- Invalidate();
- }
- public override void SaveToStream(System.Runtime.Serialization.SerializationInfo info, int orderNumber)
- {
- info.AddValue(
- String.Format(CultureInfo.InvariantCulture,
- "{0}{1}",
- entryLength, orderNumber),
- pointArray.Count);
- int i = 0;
- foreach (PointF p in pointArray)
- {
- info.AddValue(
- String.Format(CultureInfo.InvariantCulture,
- "{0}{1}-{2}",
- entryPoint, orderNumber, i++),
- p);
- }
- base.SaveToStream(info, orderNumber); // ??
- }
- public override void LoadFromStream(System.Runtime.Serialization.SerializationInfo info, int orderNumber)
- {
- Point point;
- int n = info.GetInt32(
- String.Format(CultureInfo.InvariantCulture,
- "{0}{1}",
- entryLength, orderNumber));
- for (int i = 0; i < n; i++)
- {
- point = (Point)info.GetValue(
- String.Format(CultureInfo.InvariantCulture,
- "{0}{1}-{2}",
- entryPoint, orderNumber, i),
- typeof(Point));
- pointArray.Add(point);
- }
- base.LoadFromStream(info, orderNumber);
- }
- /// <summary>
- /// 用于创建一个路径或者是闭合的范围
- /// 用于响应点击选中
- /// 需要咨询用户是仅点击线还是矩形选择
- /// </summary>
- protected virtual void CreateObjects()
- {
- if (AreaPath != null)
- return;
- AreaPath = new GraphicsPath();
- AreaPath.AddRectangle(GetBoundingBox());
- AreaPath.CloseFigure();
- AreaRegion = new Region(AreaPath);
- }
- /// <summary>
- /// Invalidate object.
- /// When object is invalidated, path used for hit test
- /// is released and should be created again.
- /// </summary>
- protected void Invalidate()
- {
- if (AreaPath != null)
- {
- AreaPath.Dispose();
- AreaPath = null;
- }
- if (AreaPen != null)
- {
- AreaPen.Dispose();
- AreaPen = null;
- }
- if (AreaRegion != null)
- {
- AreaRegion.Dispose();
- AreaRegion = null;
- }
- }
- protected GraphicsPath AreaPath
- {
- get
- {
- return areaPath;
- }
- set
- {
- areaPath = value;
- }
- }
- protected Pen AreaPen
- {
- get
- {
- return areaPen;
- }
- set
- {
- areaPen = value;
- }
- }
- protected Region AreaRegion
- {
- get
- {
- return areaRegion;
- }
- set
- {
- areaRegion = value;
- }
- }
- /// <summary>
- /// Draw tracker for selected object
- /// </summary>
- /// <param name="g"></param>
- public override void DrawTracker(Graphics g)
- {
- if (!Selected)
- return;
- SolidBrush brush = new SolidBrush(Color.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;
- }
- }
- //g.DrawRectangle(new Pen(Color.White), GetBoundingBox());
- brush.Dispose();
- pen.Dispose();
- }
- /// <summary>
- /// Hit test.
- /// Return value: -1 - no hit
- /// 0 - hit anywhere
- /// > 1 - handle number
- /// </summary>
- /// <param name="pointscroll"></param>
- /// <returns></returns>
- public override int HitTest(Point point)
- {
- if (Selected)
- {
- for (int i = 1; i <= HandleCount; i++)
- {
- if (GetHandleRectangle(i).Contains(point))
- return i;
- }
- if (GetRectanglePosition(this.rectangleF1, point, 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;
- }
- for (int i = 0; i < this.RectangleFList.Count; i++)
- {
- num = i / 6;
- RectangleF rectangleF = this.RectangleFList[i];
- if (num + 1 < pointArray.Count)
- {
- //计算需要旋转的角度
- angle1 = BasicCalculationHelper.Angle(pointArray[num], pointArray[num + 1], new PointF(pointArray[num].X, pointArray[num + 1].Y));
- if (angle1 > 90)
- {
- angle1 = BasicCalculationHelper.Angle(pointArray[num + 1], pointArray[num], new PointF(pointArray[num + 1].X, pointArray[num].Y));
- }
- if (GetRectanglePosition(rectangleF, point, pointArray[num + 1], angle1))
- {
- this.pointL = SetOffsetAfterRotation(point, pointArray[num + 1], angle1);
- moveKb = -i;
- 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()
- {
- Rectangle rectangle;
- int minx = 0, maxx = 0, miny = 0, maxy = 0;
- for (int i = 0; i < pointArray.Count; i++)
- {
- if (i == 0)
- {
- minx = maxx = (int)pointArray[i].X;
- miny = maxy = (int)pointArray[i].Y;
- }
- else
- {
- if (pointArray[i].X > maxx) maxx = (int)pointArray[i].X;
- if (pointArray[i].X < minx) minx = (int)pointArray[i].X;
- if (pointArray[i].Y > maxy) maxy = (int)pointArray[i].Y;
- if (pointArray[i].Y < miny) miny = (int)pointArray[i].Y;
- }
- }
- rectangle = new Rectangle(minx, miny, maxx - minx, maxy - miny);
- return rectangle;
- }
- internal void setNextPoint(Point p)
- {
- AddPoint(p);
- //startPoint = endPoint;
- //endPoint = p;
- }
- internal void setEndPoint(Point p)
- {
- endPoint = p;
- }
- public override List<PointF> GetPoints()
- {
- return pointArray;
- }
- public override ParentStyleModel GetStyle()
- {
- return measureStyleModel;
- }
- }
- }
|