123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515 |
- using PaintDotNet.Base.SettingModel;
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using PaintDotNet.Annotation.Enum;
- using System.Collections.Generic;
- using PaintDotNet.Base.CommTool;
- using System.Linq;
- namespace PaintDotNet.Annotation.Measure
- {
- /// <summary>
- /// 测量->多边形测量->任意矩形
- /// </summary>
- public class MeasureRandRectangle : MeasureDrawObject
- {
- /// <summary>
- /// 标注样式信息model
- /// </summary>
- public MeasureStyleModel.MeasureRandRectangle measureRandRectangle;
- /// <summary>
- /// 坐标点集合
- /// </summary>
- public List<PointF> pointArray;
- /// <summary>
- /// 第三个点
- /// </summary>
- PointF linePoint;
- /// <summary>
- /// 第四个点
- /// </summary>
- PointF linePoint1;
- /// <summary>
- /// 中心点
- /// </summary>
- PointF centerPoint;
- /// <summary>
- /// 旋转时的最后一个点记录,用于计算角度
- /// </summary>
- PointF lastPoint;
- /// <summary>
- /// 旋转时的标记
- /// </summary>
- public bool isPress = false;
- /// <summary>
- /// 初始绘制时第一个点和第二个点的角度
- /// </summary>
- public double angleF = 0;
- /// <summary>
- /// 初始绘制的标记
- /// </summary>
- public bool first = false;
- /// <summary>
- /// 绘制完成的标记
- /// </summary>
- public bool finish = false;
- /// <summary>
- /// 第一个点和第二个点的组成的直线的斜率
- /// </summary>
- public double k1;
- /// <summary>
- /// 重新计算过的外接矩形
- /// </summary>
- RectangleF largerRect;
- /// <summary>
- /// 周长
- /// </summary>
- //private double length = 0.0;
- /// <summary>
- /// 面积
- /// </summary>
- private double area = 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();
- 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();
- /// <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>
- private string[] drawingPropertiesList;
- /// <summary>
- /// 绘制属性(克隆)
- /// </summary>
- private string[] drawingPropertiesListClone;
- private bool drawing;
- /// <summary>
- /// 旋转角度
- /// </summary>
- private double angle;
- /// <summary>
- /// 限制绘制(绘制中)
- /// </summary>
- public bool mouseUpPointChange = false;
- /// <summary>
- /// 绘制点
- /// </summary>
- private PointF PointF = new PointF();
- public MeasureRandRectangle(ISurfaceBox surfaceBox, int x1, int y1, int x2, int y2, bool clone) : base()
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureRandRectangle;
- this.pointArray = new List<PointF>();
- this.measureRandRectangle = surfaceBox.GetMeasureStyleModel().measureRandRectangle;
- this.startPoint.X = x1;
- this.startPoint.Y = y1;
- this.endPoint.X = x2;
- this.endPoint.Y = y2;
- if (clone)
- {
- drawing = true;
- this.pointArray.Add(this.startPoint);
- this.pointArray.Add(this.endPoint);
- }
- this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
- this.unitString = surfaceBox.GetPxPerUnit()[1];
- this.unit = surfaceBox.GetPxPerUnit()[2];
-
- }
- /// <summary>
- /// 测量属性
- /// </summary>
- /// <returns></returns>
- public override Dictionary<System.Enum, object> GetData()
- {
- if (data.ContainsKey(MeasureAttributes.MeasureMethod))
- data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text");
- else
- data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.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.PixelArea))
- data[MeasureAttributes.PixelArea] = Math.Round(area, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelArea, Math.Round(area, decimalPlaces));
- string s = Math.Round(this.area * 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.PhysicalArea))
- data[MeasureAttributes.PhysicalArea] = s;
- else
- data.Add(MeasureAttributes.PhysicalArea, s);
- if (data.ContainsKey(MeasureAttributes.PixelCircumference))
- data[MeasureAttributes.PixelCircumference] = Math.Round(length, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelCircumference, Math.Round(length, decimalPlaces));
- 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.PhysicalCircumference))
- data[MeasureAttributes.PhysicalCircumference] = s;
- else
- data.Add(MeasureAttributes.PhysicalCircumference, s);
- return data;
- }
- public MeasureRandRectangle(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureRandRectangle;
- this.ISurfaceBox = surfaceBox;
- measureRandRectangle = (MeasureStyleModel.MeasureRandRectangle)parentStyleModel;
- pointArray = DrawRulerHelper.DeepCopyListByReflect(points);
- startPoint.X = points[0].X;
- startPoint.Y = points[0].Y;
- endPoint.X = points[1].X;
- endPoint.Y = points[1].Y;
- linePoint.X = points[2].X;
- linePoint.Y = points[2].Y;
- linePoint1.X = points[3].X;
- linePoint1.Y = points[3].Y;
- finish = true;
- CalcSlope();
- CalcOtherRectangle();
- CalcCenter();
- largerRect = GetBoundingBox();
- this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
- this.unitString = surfaceBox.GetPxPerUnit()[1];
- this.unit = surfaceBox.GetPxPerUnit()[2];
-
- this.configurationFile = true;
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- public override DrawObject Clone()
- {
- MeasureRandRectangle measureRandRectangle = new MeasureRandRectangle(ISurfaceBox, 0, 0, 0, 1, false);
- measureRandRectangle.objectType = DrawClass.Measure;
- measureRandRectangle.drawToolType = DrawToolType.MeasureRandRectangle;
- measureRandRectangle.ISurfaceBox = this.ISurfaceBox;
- foreach (PointF p in this.pointArray)
- {
- measureRandRectangle.pointArray.Add(p);
- }
- measureRandRectangle.startPoint = this.startPoint;
- measureRandRectangle.endPoint = this.endPoint;
- measureRandRectangle.linePoint = this.linePoint;
- measureRandRectangle.linePoint1 = this.linePoint1;
- measureRandRectangle.finish = true;
- measureRandRectangle.first = true;
- if (drawingPropertiesList != null)
- measureRandRectangle.drawingPropertiesListClone = drawingPropertiesList;
- FillDrawObjectFields(measureRandRectangle);
- return measureRandRectangle;
- }
- public override DrawObject Clone(ISurfaceBox surfaceBox)
- {
- MeasureRandRectangle measureRandRectangle = new MeasureRandRectangle(surfaceBox, this.GetPoints(), this.measureRandRectangle, null);
-
- measureRandRectangle.finish = true;
- measureRandRectangle.first = true;
- if (drawingPropertiesList != null)
- measureRandRectangle.drawingPropertiesListClone = drawingPropertiesList;
- FillDrawObjectFields(measureRandRectangle);
- return measureRandRectangle;
- }
- public override void Draw(Graphics g)
- {
- this.measureRandRectangle = this.ISurfaceBox.GetMeasureStyleModel().measureRandRectangle;
- drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
- if (drawingPropertiesList == null)
- {
- drawingPropertiesList = drawingPropertiesListClone;
- if (!this.drawing)
- this.configurationFile = true;
- }
- pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
- g.SmoothingMode = SmoothingMode.AntiAlias;
- Font textfont = new Font(this.measureRandRectangle.font, this.measureRandRectangle.fontSize);
- Brush textbrush = new SolidBrush(Color.FromArgb(this.measureRandRectangle.textColor));
- Color color = Color.FromArgb(this.measureRandRectangle.lineColor);
- Pen pen = new Pen(color, this.measureRandRectangle.lineWidth);
- //Pen pen = new Pen(color, 1);
- pen.DashStyle = (DashStyle)this.measureRandRectangle.lineStyle;
- if (this.Selected)
- {
- if (measureRandRectangle.chooseStyle != null)
- {
- textfont = new Font(measureRandRectangle.chooseStyle.font, measureRandRectangle.chooseStyle.fontSize);
- textbrush = new SolidBrush(Color.FromArgb(measureRandRectangle.chooseStyle.textColor));
- pen = new Pen(Color.FromArgb(measureRandRectangle.chooseStyle.lineColor), measureRandRectangle.chooseStyle.lineWidth);
- pen.DashStyle = (DashStyle)measureRandRectangle.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();
- }
- Matrix mtxSave = g.Transform;
- Matrix matrix = g.Transform;
- string frontStr = string.Empty;
- if (this.measureRandRectangle.showSuffix)
- {
- frontStr = this.measureRandRectangle.suffixName;
- }
- if (this.measureRandRectangle.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.measureRandRectangle.showAlias)
- {
- frontStr = this.measureRandRectangle.aliasName + frontStr;
- }
- if (pointArray.Count == 2)
- {
- g.DrawLine(pen, pointArray[0].X, pointArray[0].Y, pointArray[1].X, pointArray[1].Y);
- }
- else if (pointArray.Count >= 4)
- {
- SizeF sizeF = new SizeF();
- g.DrawLine(pen, pointArray[0].X, pointArray[0].Y, pointArray[1].X, pointArray[1].Y);
- g.DrawLine(pen, pointArray[1].X, pointArray[1].Y, pointArray[2].X, pointArray[2].Y);
- g.DrawLine(pen, pointArray[0].X, pointArray[0].Y, pointArray[3].X, pointArray[3].Y);
- g.DrawLine(pen, pointArray[2].X, pointArray[2].Y, pointArray[3].X, pointArray[3].Y);
- // 计算矩形长和宽
- double h = BasicCalculationHelper.GetDistance(pointArray[0], pointArray[1], 10);
- double w = BasicCalculationHelper.GetDistance(pointArray[0], pointArray[3], 10);
- length = (h + w) * 2;
- area = h * w;
- if (pointArray[0].X < pointArray[1].X && pointArray[0].X < pointArray[2].X && pointArray[0].X < pointArray[3].X)
- {
- this.PointF = pointArray[0];
- if (pointArray[1].Y > pointArray[3].Y)
- {
- //计算需要旋转的角度
- angle = BasicCalculationHelper.Angle(pointArray[0], pointArray[3], new PointF(pointArray[0].X, pointArray[3].Y));
- // 画布旋转
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, new PointF(pointArray[0].X, pointArray[0].Y));
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(pointArray[3], pointArray[0], new PointF(pointArray[3].X, pointArray[0].Y));
- matrix.RotateAt((float)angle, new PointF(pointArray[0].X, pointArray[0].Y));
- g.Transform = matrix;
- }
- }
- else
- {
- //计算需要旋转的角度
- angle = BasicCalculationHelper.Angle(pointArray[0], pointArray[1], new PointF(pointArray[0].X, pointArray[1].Y));
- // 画布旋转
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, new PointF(pointArray[0].X, pointArray[0].Y));
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[0], new PointF(pointArray[1].X, pointArray[0].Y));
- matrix.RotateAt((float)angle, new PointF(pointArray[0].X, pointArray[0].Y));
- g.Transform = matrix;
- }
- }
-
- }
- else if (pointArray[1].X < pointArray[0].X && pointArray[1].X < pointArray[2].X && pointArray[1].X < pointArray[3].X)
- {
- this.PointF = pointArray[1];
- if(pointArray[0].Y > pointArray[2].Y)
- {
- //计算需要旋转的角度
- angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[2], new PointF(pointArray[1].X, pointArray[2].Y));
- // 画布旋转
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, new PointF(pointArray[1].X, pointArray[1].Y));
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(pointArray[2], pointArray[1], new PointF(pointArray[2].X, pointArray[1].Y));
- matrix.RotateAt((float)angle, new PointF(pointArray[1].X, pointArray[1].Y));
- g.Transform = matrix;
- }
- }
- else
- {
- //计算需要旋转的角度
- angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[0], new PointF(pointArray[1].X, pointArray[0].Y));
- // 画布旋转
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, new PointF(pointArray[1].X, pointArray[1].Y));
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(pointArray[0], pointArray[1], new PointF(pointArray[0].X, pointArray[1].Y));
- matrix.RotateAt((float)angle, new PointF(pointArray[1].X, pointArray[1].Y));
- g.Transform = matrix;
- }
- }
-
- }
- else if (pointArray[2].X < pointArray[0].X && pointArray[2].X < pointArray[1].X && pointArray[2].X < pointArray[3].X)
- {
- this.PointF = pointArray[2];
- if(pointArray[1].Y > pointArray[3].Y)
- {
- //计算需要旋转的角度
- angle = BasicCalculationHelper.Angle(pointArray[2], pointArray[3], new PointF(pointArray[2].X, pointArray[3].Y));
- // 画布旋转
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, new PointF(pointArray[2].X, pointArray[2].Y));
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(pointArray[3], pointArray[2], new PointF(pointArray[3].X, pointArray[2].Y));
- matrix.RotateAt((float)angle, new PointF(pointArray[2].X, pointArray[2].Y));
- g.Transform = matrix;
- }
- }
- else
- {
- //计算需要旋转的角度
- angle = BasicCalculationHelper.Angle(pointArray[2], pointArray[1], new PointF(pointArray[2].X, pointArray[1].Y));
- // 画布旋转
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, new PointF(pointArray[2].X, pointArray[2].Y));
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[2], new PointF(pointArray[1].X, pointArray[2].Y));
- matrix.RotateAt((float)angle, new PointF(pointArray[2].X, pointArray[2].Y));
- g.Transform = matrix;
- }
- }
-
- }
- else if (pointArray[3].X < pointArray[0].X && pointArray[3].X < pointArray[1].X && pointArray[3].X < pointArray[2].X)
- {
- this.PointF = pointArray[3];
- if(pointArray[0].Y > pointArray[2].Y)
- {
- //计算需要旋转的角度
- angle = BasicCalculationHelper.Angle(pointArray[3], pointArray[2], new PointF(pointArray[3].X, pointArray[2].Y));
- // 画布旋转
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, new PointF(pointArray[3].X, pointArray[3].Y));
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(pointArray[2], pointArray[3], new PointF(pointArray[2].X, pointArray[3].Y));
- matrix.RotateAt((float)angle, new PointF(pointArray[3].X, pointArray[3].Y));
- g.Transform = matrix;
- }
- }
- else
- {
- //计算需要旋转的角度
- angle = BasicCalculationHelper.Angle(pointArray[3], pointArray[0], new PointF(pointArray[3].X, pointArray[0].Y));
- // 画布旋转
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, new PointF(pointArray[3].X, pointArray[3].Y));
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(pointArray[0], pointArray[3], new PointF(pointArray[0].X, pointArray[3].Y));
- matrix.RotateAt((float)angle, new PointF(pointArray[3].X, pointArray[3].Y));
- g.Transform = matrix;
- }
- }
-
- }
- // 是否绘制
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- // 属性文本的间隔定义
- int offsetValue = measureRandRectangle.fontSize + measureRandRectangle.fontSize / 2;
- int offsetValue1 = measureRandRectangle.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.PixelCircumference.ToString()))
- {
- sizeF = g.MeasureString("" + Math.Round(this.length, decimalPlaces) + "px", textfont);
- rectangleF10.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 物理周长
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.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 a = s.Length - s.IndexOf(".") - 1;
- if (a < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - a; i++)
- {
- s += "0";
- }
- }
- }
- sizeF = g.MeasureString(frontStr + s + this.unit, textfont);
- rectangleF11.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 像素面积
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + Math.Round(this.area, decimalPlaces) + "px²", textfont);
- rectangleF8.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 物理面积
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
- {
- string s = Math.Round(this.area * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int a = s.Length - s.IndexOf(".") - 1;
- if (a < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - a; i++)
- {
- s += "0";
- }
- }
- }
- sizeF = g.MeasureString(frontStr + s + this.unit + "²", textfont);
- rectangleF9.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 测量方式
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"), textfont);
- rectangleF1.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 测量单位(中文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + this.unitString, textfont);
- rectangleF2.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 测量单位(英文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + this.unit, textfont);
- rectangleF3.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 像素起始点X
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + startPoint.X, textfont);
- rectangleF4.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 像素起始点Y
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + startPoint.Y, textfont);
- rectangleF5.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 物理起始点X
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont);
- rectangleF6.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- // 物理起始点Y
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont);
- rectangleF7.Location = new Point((int) this.PointF .X + offsetValue1 - (int)sizeF.Width / 2, (int) this.PointF .Y + offset);
- offset += offsetValue;
- }
- }
- }
- if (drawingPropertiesList != null)
- {
- // 测量方式
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"), textfont);
- rectangleF1.Width = sizeF.Width;
- rectangleF1.Height = sizeF.Height;
- g.DrawString(frontStr + "" + PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"), textfont, textbrush, rectangleF1);
- }
- else
- {
- rectangleF1 = new RectangleF();
- }
- // 测量单位(中文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + this.unitString, textfont);
- rectangleF2.Width = sizeF.Width;
- rectangleF2.Height = sizeF.Height;
- g.DrawString(frontStr + "" + this.unitString, textfont, textbrush, rectangleF2);
- }
- else
- {
- rectangleF2 = new RectangleF();
- }
- // 测量单位(英文)
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + this.unit, textfont);
- rectangleF3.Width = sizeF.Width;
- rectangleF3.Height = sizeF.Height;
- g.DrawString(frontStr + "" + this.unit, textfont, textbrush, rectangleF3);
- }
- else
- {
- rectangleF3 = new RectangleF();
- }
- // 像素起始点X
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + startPoint.X, textfont);
- rectangleF4.Width = sizeF.Width;
- rectangleF4.Height = sizeF.Height;
- g.DrawString(frontStr + "" + startPoint.X, textfont, textbrush, rectangleF4);
- }
- else
- {
- rectangleF4 = new RectangleF();
- }
- // 像素起始点Y
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + startPoint.Y, textfont);
- rectangleF5.Width = sizeF.Width;
- rectangleF5.Height = sizeF.Height;
- g.DrawString(frontStr + "" + startPoint.Y, textfont, textbrush, rectangleF5);
- }
- else
- {
- rectangleF5 = new RectangleF();
- }
- // 物理起始点X
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont);
- rectangleF6.Width = sizeF.Width;
- rectangleF6.Height = sizeF.Height;
- g.DrawString(frontStr + "" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont, textbrush, rectangleF6);
- }
- else
- {
- rectangleF6 = new RectangleF();
- }
- // 物理起始点Y
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont);
- rectangleF7.Width = sizeF.Width;
- rectangleF7.Height = sizeF.Height;
- g.DrawString(frontStr + "" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont, textbrush, rectangleF7);
- }
- else
- {
- rectangleF7 = new RectangleF();
- }
- // 像素面积
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + Math.Round(this.area, decimalPlaces) + "px²", textfont);
- rectangleF8.Width = sizeF.Width;
- rectangleF8.Height = sizeF.Height;
- g.DrawString(frontStr + "" + Math.Round(this.area, decimalPlaces) + "px²", textfont, textbrush, rectangleF8);
- }
- else
- {
- rectangleF8 = new RectangleF();
- }
- // 物理面积
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
- {
- string s = Math.Round(this.area * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int a = s.Length - s.IndexOf(".") - 1;
- if (a < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - a; i++)
- {
- s += "0";
- }
- }
- }
- sizeF = g.MeasureString(frontStr + s + this.unit + "²", textfont);
- rectangleF9.Width = sizeF.Width;
- rectangleF9.Height = sizeF.Height;
- g.DrawString(frontStr + s + this.unit + "²", textfont, textbrush, rectangleF9);
- }
- else
- {
- rectangleF9 = new RectangleF();
- }
- // 像素周长
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
- {
- sizeF = g.MeasureString(frontStr + "" + Math.Round(this.length, decimalPlaces) + "px", textfont);
- rectangleF10.Width = sizeF.Width;
- rectangleF10.Height = sizeF.Height;
- g.DrawString(frontStr + "" + Math.Round(this.length, decimalPlaces) + "px", textfont, textbrush, rectangleF10);
- }
- else
- {
- rectangleF10 = new RectangleF();
- }
- // 物理周长
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.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 a = s.Length - s.IndexOf(".") - 1;
- if (a < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - a; i++)
- {
- s += "0";
- }
- }
- }
- sizeF = g.MeasureString(frontStr + s + this.unit, textfont);
- rectangleF11.Width = sizeF.Width;
- rectangleF11.Height = sizeF.Height;
- g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF11);
- }
- else
- {
- rectangleF11 = new RectangleF();
- }
- }
- //还原为原始旋转矩阵
- g.Transform = mtxSave;
- }
- matrix.Dispose();
- if (this.configurationFile)
- this.pointChange = false;
- this.mouseUpAttribute = false;
- pointChangeObject.Remove(this.drawToolType);
- }
- /// <summary>
- /// 停止绘制时
- /// </summary>
- /// <param name="up"></param>
- public override void MouseUp(bool up)
- {
- mouseUpPointChange = up;
- }
- public void CalcCenter()
- {
- centerPoint = new PointF(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2);//中心点
- first = true;
- }
- public void CalcSlope()
- {
- //计算斜率
- k1 = (double)(pointArray[1].Y - pointArray[0].Y) / (pointArray[1].X - pointArray[0].X);
- }
- public override int HandleCount
- {
- get
- {
- return 13;
- }
- }
- /// <summary>
- /// Get handle pointscroll by 1-based number
- /// </summary>
- /// <param name="handleNumber"></param>
- /// <returns></returns>
- public override PointF GetHandle(int handleNumber)
- {
- float x = 0;
- float y = 0;
- switch (handleNumber)
- {
- case 1:
- x = (int)pointArray[0].X;
- y = (int)pointArray[0].Y;
- break;
- case 2:
- x = (int)pointArray[1].X;
- y = (int)pointArray[1].Y;
- break;
- case 3:
- if (pointArray.Count >= 3)
- {
- x = (int)pointArray[2].X;
- y = (int)pointArray[2].Y;
- }
- break;
- case 4:
- if (pointArray.Count >= 4)
- {
- x = (int)pointArray[3].X;
- y = (int)pointArray[3].Y;
- }
- break;
- case 5:
- x = ((int)pointArray[0].X + (int)pointArray[1].X) / 2;
- y = ((int)pointArray[0].Y + (int)pointArray[1].Y) / 2;
- break;
- case 6:
- if (pointArray.Count >= 3)
- {
- x = ((int)pointArray[1].X + (int)pointArray[2].X) / 2;
- y = ((int)pointArray[1].Y + (int)pointArray[2].Y) / 2;
- }
- break;
- case 7:
- if (pointArray.Count >= 4)
- {
- x = ((int)pointArray[2].X + (int)pointArray[3].X) / 2;
- y = ((int)pointArray[2].Y + (int)pointArray[3].Y) / 2;
- }
- break;
- case 8:
- if (pointArray.Count >= 4)
- {
- x = ((int)pointArray[3].X + (int)pointArray[0].X) / 2;
- y = ((int)pointArray[3].Y + (int)pointArray[0].Y) / 2;
- }
- break;
- case 9:
- x = largerRect.X;
- y = largerRect.Y;
- break;
- case 10:
- x = largerRect.Right;
- y = largerRect.Y;
- break;
- case 11:
- x = largerRect.Right;
- y = largerRect.Bottom;
- break;
- case 12:
- x = largerRect.X;
- y = largerRect.Bottom;
- break;
- case 13:
- x = this.pointL.X;
- y = this.pointL.Y;
- break;
-
- }
- return new PointF(x, y);
- }
- /// <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)
- {
- System.Console.WriteLine(point.X + "|" + point.Y);
- if (Selected)
- {
- for (int i = 1; i <= HandleCount; i++)
- {
- if (GetHandleRectangle(i).Contains(point))
- {
- System.Console.WriteLine(i);
- return i;
- }
- }
- if (GetRectanglePosition(this.rectangleF1, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 1;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF2, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 2;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF3, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 3;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF4, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 4;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF5, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 5;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF6, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 6;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF7, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 7;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF8, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 8;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF9, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 9;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF10, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 10;
- return 13;
- }
- else if (GetRectanglePosition(this.rectangleF11, point, this.PointF , angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
- moveKb = 11;
- return 13;
- }
- }
- if (PointInObject(point))
- return 0;
- return -1;
- }
- protected override bool PointInObject(Point point)
- {
- return largerRect.Contains(point);
- }
- public override bool IntersectsWith(Rectangle rectangle)
- {
- return largerRect.IntersectsWith(rectangle);
- }
- public override Cursor GetHandleCursor(int handleNumber)
- {
- return handleCursor;
- }
- public override void MoveHandleTo(Point point, int handleNumber)
- {
- if (handleNumber < 9)
- {
- this.mouseUpPointChange = true;
- switch (handleNumber)
- {
- case 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);
- //更新第一个点
- startPoint = point;
- this.pointArray[0] = startPoint;
- //计算第二个点
- this.pointArray[1] = BasicCalculationHelper.GetDropFeet(startPoint, k1, linePoint);
- endPoint.X = (int)this.pointArray[1].X;
- endPoint.Y = (int)this.pointArray[1].Y;
- //计算第四个点
- this.pointArray[3] = BasicCalculationHelper.GetDropFeet(startPoint, -1/k1, linePoint);
- linePoint1.X = (int)this.pointArray[3].X;
- linePoint1.Y = (int)this.pointArray[3].Y;
- break;
- case 2:
- endPoint = point;
- this.pointArray[1] = endPoint;
- if(this.pointArray.Count>3)
- {
- //计算第一个点
- this.pointArray[0] = BasicCalculationHelper.GetDropFeet(endPoint, k1, linePoint1);
- startPoint.X = (int)this.pointArray[0].X;
- startPoint.Y = (int)this.pointArray[0].Y;
- //计算第三个点
- this.pointArray[2] = BasicCalculationHelper.GetDropFeet(endPoint, -1 / k1, linePoint1);
- linePoint.X = (int)this.pointArray[2].X;
- linePoint.Y = (int)this.pointArray[2].Y;
- }
- break;
- case 3:
- linePoint = point;
- CalcSlope();
- this.pointArray[1] = BasicCalculationHelper.GetDropFeet(point, -1 / k1, this.pointArray[0]);
- endPoint.X = (int)this.pointArray[1].X;
- endPoint.Y = (int)this.pointArray[1].Y;
- if (this.pointArray.Count == 2)
- {
- this.pointArray.Add(point);
- this.CalcOtherPoint(point);
- }
- else
- {
- this.pointArray[2] = linePoint;
- if(!finish) this.CalcOtherPoint(point);
- if (this.pointArray.Count == 4 && finish)
- {
- //计算第二个点
- //this.pointArray[1] = BasicCalculationHelper.GetDropFeet(linePoint, -1/k1, this.pointArray[0]);
- //endPoint.X = (int)this.pointArray[1].X;
- //endPoint.Y = (int)this.pointArray[1].Y;
- //计算第四个点
- this.pointArray[3] = BasicCalculationHelper.GetDropFeet(linePoint, k1, this.pointArray[0]);
- linePoint1.X = (int)this.pointArray[3].X;
- linePoint1.Y = (int)this.pointArray[3].Y;
- }
- }
- break;
- case 4:
- this.linePoint1 = point;
- if (this.pointArray.Count == 3)
- {
- this.pointArray.Add(point);
- }
- else
- {
- this.pointArray[3] = point;
- //if(finish)
- {
- //计算第一个点
- this.pointArray[0] = BasicCalculationHelper.GetDropFeet(linePoint1, -1 / k1, endPoint);
- startPoint.X = (int)this.pointArray[0].X;
- startPoint.Y = (int)this.pointArray[0].Y;
- //计算第三个点
- this.pointArray[2] = BasicCalculationHelper.GetDropFeet(linePoint1, k1, endPoint);
- linePoint.X = (int)this.pointArray[2].X;
- linePoint.Y = (int)this.pointArray[2].Y;
- }
- }
- break;
- case 5:
- this.pointArray[0] = BasicCalculationHelper.GetDropFeet(point, k1, this.pointArray[0]);
- startPoint.X = (int)this.pointArray[0].X;
- startPoint.Y = (int)this.pointArray[0].Y;
- this.pointArray[1] = BasicCalculationHelper.GetDropFeet(point, k1, this.pointArray[1]);
- endPoint.X = (int)this.pointArray[1].X;
- endPoint.Y = (int)this.pointArray[1].Y;
- break;
- case 6:
- this.pointArray[1] = BasicCalculationHelper.GetDropFeet(point, -1 / k1, this.pointArray[1]);
- endPoint.X = (int)this.pointArray[1].X;
- endPoint.Y = (int)this.pointArray[1].Y;
- this.pointArray[2] = BasicCalculationHelper.GetDropFeet(point, -1 / k1, this.pointArray[2]);
- linePoint.X = (int)this.pointArray[2].X;
- linePoint.Y = (int)this.pointArray[2].Y;
- break;
- case 7:
- this.pointArray[2] = BasicCalculationHelper.GetDropFeet(point, k1, this.pointArray[2]);
- linePoint.X = (int)this.pointArray[2].X;
- linePoint.Y = (int)this.pointArray[2].Y;
- this.pointArray[3] = BasicCalculationHelper.GetDropFeet(point, k1, this.pointArray[3]);
- linePoint1.X = (int)this.pointArray[3].X;
- linePoint1.Y = (int)this.pointArray[3].Y;
- break;
- case 8:
- this.pointArray[3] = BasicCalculationHelper.GetDropFeet(point, -1 / k1, this.pointArray[3]);
- linePoint1.X = (int)this.pointArray[3].X;
- linePoint1.Y = (int)this.pointArray[3].Y;
- this.pointArray[0] = BasicCalculationHelper.GetDropFeet(point, -1 / k1, this.pointArray[0]);
- startPoint.X = (int)this.pointArray[0].X;
- startPoint.Y = (int)this.pointArray[0].Y;
- break;
- }
- if(this.pointArray.Count == 4)
- {
- CalcOtherRectangle();
- CalcCenter();
- }
- }
- else
- {
- float x = 0, y = 0;
- switch (handleNumber)
- {
- case 9:
- this.mouseUpPointChange = true;
- x = largerRect.X;
- y = largerRect.Y;
- break;
- case 10:
- this.mouseUpPointChange = true;
- x = largerRect.Right;
- y = largerRect.Y;
- break;
- case 11:
- this.mouseUpPointChange = true;
- x = largerRect.Right;
- y = largerRect.Bottom;
- break;
- case 12:
- this.mouseUpPointChange = true;
- x = largerRect.X;
- y = largerRect.Bottom;
- break;
- case 13:
- point = SetOffsetAfterRotation(point, this.PointF , angle);
- if (this.moveKb == 1)
- this.rectangleF1.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 2)
- this.rectangleF2.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 3)
- this.rectangleF3.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 4)
- this.rectangleF4.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 5)
- this.rectangleF5.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 6)
- this.rectangleF6.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 7)
- this.rectangleF7.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 8)
- this.rectangleF8.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 9)
- this.rectangleF9.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- 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);
- this.pointL = point;
- break;
- }
- if(handleNumber != 13)
- {
- this.mouseUpPointChange = true;
- if (!this.isPress)
- {
- this.isPress = true;
- lastPoint = new PointF(x, y);
- }
- double angle = BasicCalculationHelper.CalculateAngle(centerPoint.X, centerPoint.Y, lastPoint.X, lastPoint.Y, point.X, point.Y);
- lastPoint = point;
- for (int l = 0; l < pointArray.Count; l++)
- {
- pointArray[l] = BasicCalculationHelper.GetAnglePoint(pointArray[l], centerPoint, angle);
- }
- startPoint = BasicCalculationHelper.GetAnglePoint(startPoint, centerPoint, angle);
- endPoint = BasicCalculationHelper.GetAnglePoint(endPoint, centerPoint, angle);
- linePoint = BasicCalculationHelper.GetAnglePoint(linePoint, centerPoint, angle);
- linePoint1 = BasicCalculationHelper.GetAnglePoint(linePoint1, centerPoint, angle);
- CalcSlope();
- }
- }
- }
- /// <summary>
- /// 计算点
- /// </summary>
- private void CalcOtherPoint(PointF temp)
- {
- if (!first)
- {
- angleF = BasicCalculationHelper.Angle(startPoint, endPoint, new PointF(startPoint.X, endPoint.Y));
- if (startPoint.X > endPoint.X)
- {
- angleF += 180;
- }
- }
-
- float height = temp.Y - endPoint.Y;
- linePoint = new PointF(endPoint.X, endPoint.Y + height);
- linePoint = BasicCalculationHelper.GetAnglePoint(linePoint, new PointF(endPoint.X, endPoint.Y), angleF);
- if (this.pointArray.Count == 2)
- {
- this.pointArray.Add(linePoint);
- }
- else
- {
- this.pointArray[2] = linePoint;
- }
- linePoint1 = new PointF(startPoint.X, startPoint.Y + height);
- linePoint1 = BasicCalculationHelper.GetAnglePoint(linePoint1, new PointF(startPoint.X, startPoint.Y), angleF);
- if (this.pointArray.Count == 3)
- {
- this.pointArray.Add(linePoint1);
- }
- else
- {
- this.pointArray[3] = linePoint1;
- }
- CalcOtherRectangle();
- }
- /// <summary>
- /// 计算外接矩形
- /// </summary>
- private void CalcOtherRectangle()
- {
- float[] pointX = new float[] { pointArray[0].X, pointArray[1].X, pointArray[2].X, pointArray[3].X };
- rectangle.X = (int)pointX.Min();
- float[] pointY = new float[] { pointArray[0].Y, pointArray[1].Y, pointArray[2].Y, pointArray[3].Y };
- rectangle.Y = (int)pointY.Min();
- rectangle.Width = (int)Math.Abs(pointX.Max() - pointX.Min());
- rectangle.Height = (int)Math.Abs(pointY.Max() - pointY.Min());
- }
- /// <summary>
- /// 对象移动
- /// </summary>
- /// <param name="deltaX"></param>
- /// <param name="deltaY"></param>
- public override void Move(int deltaX, int deltaY)
- {
- int x = ISurfaceBox.UnscaleScalar(deltaX);
- int y = ISurfaceBox.UnscaleScalar(deltaY);
- startPoint.X += x;
- startPoint.Y += y;
- endPoint.X += x;
- endPoint.Y += y;
- linePoint.X += x;
- linePoint.Y += y;
- linePoint1.X += x;
- linePoint1.Y += y;
- 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];
- 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);
- CalcOtherRectangle();
- CalcCenter();
- }
- public override RectangleF GetBoundingBox()
- {
- RectangleF temp = new RectangleF();
- temp.X = rectangle.X - 10;
- temp.Y = rectangle.Y - 10;
- temp.Width = rectangle.Width + 20;
- temp.Height = rectangle.Height + 20;
- return temp;
- }
- /// <summary>
- /// Draw tracker for selected object
- /// </summary>
- /// <param name="g"></param>
- public override void DrawTracker(Graphics g)
- {
- if (!Selected)
- return;
- if (pointArray.Count >= 3)
- {
- SolidBrush brush = new SolidBrush(Color.FromArgb(MarkpointAreaColor));
- Pen pen = new Pen(Color.FromArgb(MarkpointLineColor), MarkpointLineWidth);
- for (int i = 1; i <= HandleCount; i++)
- {
- if (i == HandleCount)
- {
- brush = new SolidBrush(Color.Transparent);
- pen = new Pen(Color.Transparent);
- }
- switch (MarkpointStyle)
- {
- case 0:
- g.FillRectangle(brush, GetHandleRectangle(i));
- g.DrawRectangle(pen, GetHandleRectangle(i));
- break;
- case 1:
- g.FillEllipse(brush, GetHandleRectangle(i));
- g.DrawEllipse(pen, GetHandleRectangle(i));
- break;
- case 2:
- g.FillPolygon(brush, GetHandlePoint(i));
- g.DrawPolygon(pen, GetHandlePoint(i));
- break;
- }
- }
- brush.Dispose();
- pen.Dispose();
- //g.DrawRectangle(new Pen(Color.Black), largerRect.X, largerRect.Y, largerRect.Width, largerRect.Height);
- }
- }
- /// <summary>
- /// 标准化外接矩形
- /// </summary>
- public override void Normalize()
- {
- this.isPress = false;
- CalcOtherRectangle();
- }
- /// <summary>
- /// 获取点集合
- /// </summary>
- /// <returns></returns>
- public override List<PointF> GetPoints()
- {
- return pointArray;
- }
- /// <summary>
- /// 获取样式
- /// </summary>
- /// <returns></returns>
- public override ParentStyleModel GetStyle()
- {
- return measureRandRectangle;
- }
- }
- }
|