123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212 |
- 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.Linq;
- namespace PaintDotNet.Annotation.Measure
- {
- using PointList = List<PointF>;
- /// <summary>
- /// 测量->多点线段->多点水平线
- /// </summary>
- public class MeasureMulHVLine : 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 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;
- private bool drawing;
- /// <summary>
- /// 属性绘制点
- /// </summary>
- private PointF rotationPoint;
- private PointF rotationPoint1;
- /// <summary>
- /// 限制绘制(绘制中)
- /// </summary>
- public bool mouseUpPointChange = false;
- /// <summary>
- /// 测量样式信息model
- /// </summary>
- private MeasureStyleModel.MeasureMulHVLine measureStyleModel;
- public MeasureStyleModel.MeasureMulHVLine MeasureStyleModel
- {
- set
- {
- this.measureStyleModel = value;
- }
- }
- public MeasureMulHVLine(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox)
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureMulHVLine;
- measureStyleModel = surfaceBox.GetMeasureStyleModel().measureMulHVLine;
- 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 MeasureMulHVLine(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureMulHVLine;
- this.ISurfaceBox = surfaceBox;
- measureStyleModel = (MeasureStyleModel.MeasureMulHVLine)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()
- {
- MeasureMulHVLine drawPolygon = new MeasureMulHVLine(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)
- {
- MeasureMulHVLine drawPolygon = new MeasureMulHVLine(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)
- {
- lengthParagraphs = new List<string>();
- drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
- measureStyleModel = this.ISurfaceBox.GetMeasureStyleModel().measureMulHVLine;
- if (drawingPropertiesList == null)
- {
- drawingPropertiesList = drawingPropertiesListClone;
- if (!this.drawing)
- this.configurationFile = true;
- }
- pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
- 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++)
- {
- 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;
- g.SmoothingMode = SmoothingMode.AntiAlias;
- 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();
- }
- //length = BasicCalculationHelper.GetDistance(pointArray[i - 1], pointArray[i], 10) / pxPerUnit;
- length = BasicCalculationHelper.GetDistance(pointArray[i - 1], pointArray[i], 10);
- PointF point = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i - 1].X, pointArray[i - 1].Y + measureStyleModel.vLineLength), pointArray[i - 1], 0);
- PointF point1 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i - 1].X, pointArray[i - 1].Y - measureStyleModel.vLineLength), pointArray[i - 1], 0);
- PointF point2 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i].X, pointArray[i].Y + measureStyleModel.vLineLength), pointArray[i], 180);
- PointF point3 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i].X, pointArray[i].Y - measureStyleModel.vLineLength), pointArray[i], 180);
- 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], 0);
- point1 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i - 1].X, pointArray[i - 1].Y - measureStyleModel.chooseStyle.vLineLength), pointArray[i - 1], 0);
- point2 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i].X, pointArray[i].Y + measureStyleModel.chooseStyle.vLineLength), pointArray[i], 180);
- point3 = BasicCalculationHelper.GetAnglePoint(new PointF(pointArray[i].X, pointArray[i].Y - measureStyleModel.chooseStyle.vLineLength), pointArray[i], 180);
- }
- }
- 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]);
- alllength = alllength + length;
- 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;
- }
- }
- if (measureStyleModel.linePositionP == 0)
- this.rotationPoint1 = new PointF(pointArray[i - 1].X, pointArray[i - 1].Y - offsetPoint - offsetValue1Point);
- else if (measureStyleModel.linePositionP == 1)
- this.rotationPoint1 = new PointF((pointArray[i - 1].X + pointArray[i].X) / 2, pointArray[i - 1].Y - offsetPoint - offsetValue1Point);
- else if (measureStyleModel.linePositionP == 2)
- this.rotationPoint1 = new PointF(pointArray[i].X, pointArray[i].Y - offsetPoint - offsetValue1Point);
- 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];
- 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)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.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)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.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)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.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)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.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)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.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)this.rotationPoint1.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.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;
- }
- }
- linePen.Dispose();
- }
- this.allLength = alllength;
- if(pointArray.Count > 1)
- {
- // 是否绘制
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- 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;
- }
- }
- if (measureStyleModel.linePositionL == 0)
- this.rotationPoint = new PointF(pointArray[0].X, pointArray[0].Y - offsetPoint - offsetValue1Point - offsetValuePoint);
- else if (measureStyleModel.linePositionL == 1)
- this.rotationPoint = new PointF((pointArray[0].X + pointArray[1].X) / 2, pointArray[0].Y - offsetPoint - offsetValue1Point - offsetValuePoint);
- else if (measureStyleModel.linePositionL == 2)
- this.rotationPoint = new PointF(pointArray[1].X, pointArray[1].Y - offsetPoint - offsetValue1Point - offsetValuePoint);
- 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];
- // 文本间隔定义
- int offsetValue = measureStyleModel.fontSize + measureStyleModel.fontSize / 2;
- int offsetValue1 = measureStyleModel.lineWidth * 2 / 3;
- int offset = offsetValue1;
- this.pointL = new Point((int)this.rotationPoint.X, (int)this.rotationPoint.Y);
- if (drawingPropertiesList != null)
- {
- // 像素平均截距
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelAverageIntercept.ToString()))
- {
- sizeF = g.MeasureString(frontStr + Math.Round(allLength / (pointArray.Count - 1), decimalPlaces) + "px", textfont1);
- rectangleF4.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.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)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.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)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- // 测量单位(中文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + this.unitString, textfont1);
- rectangleF2.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- // 测量单位(英文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + this.unit, textfont1);
- rectangleF3.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- }
- }
- if (drawingPropertiesList != null)
- {
- // 测量方式
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- sizeF = g.MeasureString(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();
- }
- }
- 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;
- }
- public override void MoveHandleTo(Point point, int handleNumber)
- {
- if (handleNumber < 1)
- handleNumber = 1;
- if (handleNumber > pointArray.Count && handleNumber != pointArray.Count + 1)
- handleNumber = pointArray.Count;
- if (handleNumber == pointArray.Count + 1)
- {
- if (this.moveKb == 1)
- this.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++)
- {
- RectangleF rectangleF = this.RectangleFList[i];
- if (this.moveKb == -i)
- rectangleF.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- this.RectangleFList[i] = rectangleF;
- }
- }
- this.pointL = point;
- }
- else
- {
- this.mouseUpPointChange = true;
- if (handleNumber != 1)
- {
- 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, pointArray[handleNumber - 2].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, pointArray[handleNumber - 2].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, pointArray[handleNumber - 2].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, pointArray[handleNumber - 2].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, pointArray[handleNumber - 2].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, pointArray[handleNumber - 2].Y - this.pointArray[i - 1].Y);
- this.RectangleFList[i * 6 - 7] = rectangleF;
- }
- }
- pointArray[handleNumber - 1] = new PointF(point.X, pointArray[handleNumber - 2].Y);
- }
- else
- {
- this.rectangleF1.Offset(point.X - this.pointArray[0].X, pointArray[0].Y - this.pointArray[0].Y);
- this.rectangleF2.Offset(point.X - this.pointArray[0].X, pointArray[0].Y - this.pointArray[0].Y);
- this.rectangleF3.Offset(point.X - this.pointArray[0].X, pointArray[0].Y - this.pointArray[0].Y);
- this.rectangleF4.Offset(point.X - this.pointArray[0].X, pointArray[0].Y - this.pointArray[0].Y);
- this.rectangleF5.Offset(point.X - this.pointArray[0].X, pointArray[0].Y - this.pointArray[0].Y);
- pointArray[0] = new PointF(point.X, pointArray[0].Y);
- }
- }
- this.startPoint = pointArray[0];
- Invalidate();
- }
- public override void Move(int deltaX, int deltaY)
- {
- int n = pointArray.Count;
- for (int i = 0; i < n; i++)
- {
- PointF point = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY));
- pointArray[i] = point;
- }
- this.startPoint = pointArray[0];
- int x = ISurfaceBox.UnscaleScalar(deltaX);
- int y = ISurfaceBox.UnscaleScalar(deltaY);
- pointL.X += x;
- pointL.Y += y;
- this.rectangleF1.Offset(x, y);
- this.rectangleF2.Offset(x, y);
- this.rectangleF3.Offset(x, y);
- this.rectangleF4.Offset(x, y);
- this.rectangleF5.Offset(x, y);
- for (int i = 0; i < this.RectangleFList.Count; i++)
- {
- RectangleF rectangleF = this.RectangleFList[i];
- rectangleF.Offset(x, y);
- this.RectangleFList[i] = rectangleF;
- }
- Invalidate();
- }
- /// <summary>
- /// 用于创建一个路径或者是闭合的范围
- /// 用于响应点击选中
- /// 需要咨询用户是仅点击线还是矩形选择
- /// </summary>
- protected virtual void CreateObjects()
- {
- if (AreaPath != null)
- return;
- // Create path which contains wide line
- // for easy mouse selection
- AreaPath = new GraphicsPath();
- AreaPen = new Pen(Color.Black, 7);
- AreaPath.AddLines(pointArray.ToArray());
- AreaPath.Widen(AreaPen);
- // Create region from the path
- 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;
- }
- }
- pen.Dispose();
- brush.Dispose();
- //RectangleF r = GetBoundingBox();
- ////g.DrawRectangle(new Pen(Color.White), r.X, r.Y, r.Width, r.Height);
- }
- /// <summary>
- /// Hit test.
- /// Return value: -1 - no hit
- /// 0 - hit anywhere
- /// > 1 - handle number
- /// </summary>
- /// <param name="pointscroll"></param>
- /// <returns></returns>
- public override int HitTest(Point point)
- {
- if (Selected)
- {
- for (int i = 1; i <= HandleCount; i++)
- {
- if (GetHandleRectangle(i).Contains(point))
- return i;
- }
- if (this.rectangleF1.Contains(point))
- {
- this.pointL = point;
- moveKb = 1;
- return this.pointArray.Count;
- }
- else if (this.rectangleF2.Contains(point))
- {
- this.pointL = point;
- moveKb = 2;
- return this.pointArray.Count;
- }
- else if (this.rectangleF3.Contains(point))
- {
- this.pointL = point;
- moveKb = 3;
- return this.pointArray.Count;
- }
- else if (this.rectangleF4.Contains(point))
- {
- this.pointL = point;
- moveKb = 4;
- return this.pointArray.Count;
- }
- else if (this.rectangleF5.Contains(point))
- {
- this.pointL = point;
- moveKb = 5;
- return this.pointArray.Count;
- }
- for (int i = 0; i < this.RectangleFList.Count; i++)
- {
- RectangleF rectangleF = this.RectangleFList[i];
- if (rectangleF.Contains(point))
- {
- this.pointL = point;
- moveKb = -i;
- return this.pointArray.Count;
- }
- }
- }
- if (PointInObject(point))
- return 0;
- return -1;
- }
- protected override bool PointInObject(Point point)
- {
- CreateObjects();
- return AreaRegion.IsVisible(point);
- }
- public override bool IntersectsWith(Rectangle rectangle)
- {
- CreateObjects();
- return AreaRegion.IsVisible(rectangle);
- }
- public override RectangleF GetBoundingBox()
- {
- float minx = 0, maxx = 0, miny = 0, maxy = 0;
- for (int i = 0; i < pointArray.Count; i++)
- {
- if (i == 0)
- {
- minx = maxx = pointArray[i].X;
- miny = maxy = pointArray[i].Y;
- }
- else
- {
- if (pointArray[i].X >= maxx) maxx = pointArray[i].X;
- if (pointArray[i].X <= minx) minx = pointArray[i].X;
- if (pointArray[i].Y >= maxy) maxy = pointArray[i].Y;
- if (pointArray[i].Y <= miny) miny = pointArray[i].Y;
- }
- }
- return new RectangleF(minx, miny, maxx - minx, maxy - miny);
- }
- internal void setNextPoint(Point p)
- {
- AddPoint(p);
- //startPoint = endPoint;
- //endPoint = p;
- }
- internal void setEndPoint(Point p)
- {
- endPoint = p;
- }
- public override List<PointF> GetPoints()
- {
- return pointArray;
- }
- public override ParentStyleModel GetStyle()
- {
- return measureStyleModel;
- }
- }
- }
|