1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486 |
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.Base.CommTool;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Linq;
- using System.Windows.Forms;
- namespace PaintDotNet.Annotation.Measure
- {
- using PointList = List<PointF>;
- /// <summary>
- /// 测量->圆->三点圆
- /// </summary>
- public class MeasureCircle : MeasureDrawObject
- {
- /// <summary>
- /// 点集合
- /// </summary>
- public PointList pointArray;
- /// <summary>
- /// 样式
- /// </summary>
- private MeasureStyleModel.MeasureCircle measureCircle;
- /// <summary>
- /// 箭头的原点
- /// </summary>
- PointF linePoint;
- /// <summary>
- /// 文字的原点
- /// </summary>
- PointF messagePoint;
- /// <summary>
- /// 辅助计算旋转角度的点
- /// </summary>
- PointF lastPoint;
- /// <summary>
- /// 圆心横坐标
- /// </summary>
- double x0;
- /// <summary>
- /// 圆心纵坐标
- /// </summary>
- double y0;
- /// <summary>
- /// 直径
- /// </summary>
- double radius = 0;
- /// <summary>
- /// 圆的旋转角度
- /// </summary>
- double angle = 0;
- double jangle = 0;
- /// <summary>
- /// 箭头的旋转角度
- /// </summary>
- double arrowAngle = 0;
- /// <summary>
- /// 辅助为箭头及文字原点赋初始值
- /// </summary>
- public bool arrowPosition = true;
- public bool isPress = false;
- private GraphicsPath areaPath = null;
- private Pen areaPen = null;
- private Region areaRegion = null;
- /// <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();
- private RectangleF rectangleF12 = new RectangleF();
- private RectangleF rectangleF13 = new RectangleF();
- private RectangleF rectangleF14 = new RectangleF();
- private RectangleF rectangleF15 = 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;
- /// <summary>
- /// 限制绘制(绘制中)
- /// </summary>
- public bool mouseUpPointChange = false;
- public MeasureCircle(ISurfaceBox surfaceBox) : base(surfaceBox)
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureCircle;
- pointArray = new PointList();
- Initialize();
- }
- public MeasureCircle(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox)
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureCircle;
- this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
- this.unitString = surfaceBox.GetPxPerUnit()[1];
- this.unit = surfaceBox.GetPxPerUnit()[2];
-
- measureCircle = this.ISurfaceBox.GetMeasureStyleModel().measureCircle;
- pointArray = new PointList();
- if (clone)
- pointArray.Add(new Point(x1, y1));
- Initialize();
- }
- public MeasureCircle(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureCircle;
- this.ISurfaceBox = surfaceBox;
- measureCircle = (MeasureStyleModel.MeasureCircle)parentStyleModel;
- pointArray = DrawRulerHelper.DeepCopyListByReflect(points);
- startPoint = points[0];
- this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
- this.unitString = surfaceBox.GetPxPerUnit()[1];
- this.unit = surfaceBox.GetPxPerUnit()[2];
-
- this.configurationFile = true;
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- public override DrawObject Clone()
- {
- MeasureCircle drawRectangle = new MeasureCircle(ISurfaceBox, (int)pointArray[0].X, (int)pointArray[0].Y, false);
- drawRectangle.objectType = DrawClass.Measure;
- drawRectangle.drawToolType = DrawToolType.MeasureCircle;
- drawRectangle.ISurfaceBox = ISurfaceBox;
- foreach (PointF p in this.pointArray)
- {
- drawRectangle.pointArray.Add(p);
- }
- if (drawingPropertiesList != null)
- drawRectangle.drawingPropertiesListClone = drawingPropertiesList;
- FillDrawObjectFields(drawRectangle);
- return drawRectangle;
- }
- public override DrawObject Clone(ISurfaceBox surfaceBox)
- {
- MeasureCircle drawRectangle = new MeasureCircle(surfaceBox, this.GetPoints(), this.measureCircle, null);
- if (drawingPropertiesList != null)
- drawRectangle.drawingPropertiesListClone = drawingPropertiesList;
- FillDrawObjectFields(drawRectangle);
- return drawRectangle;
- }
- /// <summary>
- /// 测量属性
- /// </summary>
- /// <returns></returns>
- public override Dictionary<System.Enum, object> GetData()
- {
- if (data.ContainsKey(MeasureAttributes.MeasureMethod))
- data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text");
- else
- data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"));
- if (data.ContainsKey(MeasureAttributes.MeasureUnitCN))
- data[MeasureAttributes.MeasureUnitCN] = this.unitString;
- else
- data.Add(MeasureAttributes.MeasureUnitCN, this.unitString);
- if (data.ContainsKey(MeasureAttributes.MeasureUnitEN))
- data[MeasureAttributes.MeasureUnitEN] = this.unit;
- else
- data.Add(MeasureAttributes.MeasureUnitEN, this.unit);
- if (data.ContainsKey(MeasureAttributes.PixelArea))
- data[MeasureAttributes.PixelArea] = Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelArea, Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces));
- string s = Math.Round(Math.PI * (radius / 2) * (radius / 2) * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- if (data.ContainsKey(MeasureAttributes.PhysicalArea))
- data[MeasureAttributes.PhysicalArea] = s;
- else
- data.Add(MeasureAttributes.PhysicalArea, s);
- if (data.ContainsKey(MeasureAttributes.PixelCircumference))
- data[MeasureAttributes.PixelCircumference] = Math.Round(Math.PI * radius, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelCircumference, Math.Round(Math.PI * radius, decimalPlaces));
- s = Math.Round(Math.PI * radius * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- if (data.ContainsKey(MeasureAttributes.PhysicalCircumference))
- data[MeasureAttributes.PhysicalCircumference] = s;
- else
- data.Add(MeasureAttributes.PhysicalCircumference,s);
- if (data.ContainsKey(MeasureAttributes.PixelCenterX))
- data[MeasureAttributes.PixelCenterX] = Math.Round(this.x0, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelCenterX, Math.Round(this.x0, decimalPlaces));
- if (data.ContainsKey(MeasureAttributes.PixelCenterY))
- data[MeasureAttributes.PixelCenterY] = Math.Round(this.y0, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelCenterY, Math.Round(this.y0, decimalPlaces));
- if (data.ContainsKey(MeasureAttributes.PhysicalCenterX))
- data[MeasureAttributes.PhysicalCenterX] = Math.Round(this.x0 * unitLength, decimalPlaces);
- else
- data.Add(MeasureAttributes.PhysicalCenterX, Math.Round(this.x0 * unitLength, decimalPlaces));
- if (data.ContainsKey(MeasureAttributes.PhysicalCenterY))
- data[MeasureAttributes.PhysicalCenterY] = Math.Round(this.y0 * unitLength, decimalPlaces);
- else
- data.Add(MeasureAttributes.PhysicalCenterY, Math.Round(this.y0 * unitLength, decimalPlaces));
- if (data.ContainsKey(MeasureAttributes.PixelRadius))
- data[MeasureAttributes.PixelRadius] = Math.Round(radius / 2, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelRadius, Math.Round(radius / 2, decimalPlaces));
- s = Math.Round(radius / 2 * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- if (data.ContainsKey(MeasureAttributes.PhysicalRadius))
- data[MeasureAttributes.PhysicalRadius] = s;
- else
- data.Add(MeasureAttributes.PhysicalRadius,s);
- if (data.ContainsKey(MeasureAttributes.PixelDiameter))
- data[MeasureAttributes.PixelDiameter] = Math.Round(radius, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelDiameter, Math.Round(radius, decimalPlaces));
- s = Math.Round(radius * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- if (data.ContainsKey(MeasureAttributes.PhysicalDiameter))
- data[MeasureAttributes.PhysicalDiameter] = s;
- else
- data.Add(MeasureAttributes.PhysicalDiameter, s);
- return data;
- }
-
- public override void Draw(Graphics g)
- {
- string frontStr = string.Empty;
- if (this.measureCircle.showSuffix)
- {
- frontStr = this.measureCircle.suffixName;
- }
- if (this.measureCircle.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.measureCircle.showAlias)
- {
- frontStr = this.measureCircle.aliasName + frontStr;
- }
- measureCircle = this.ISurfaceBox.GetMeasureStyleModel().measureCircle;
- drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
- pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
- Color color = Color.FromArgb(this.measureCircle.lineColor);
- Pen pen = new Pen(color, PenWidth);
- int penWidth = this.measureCircle.lineWidth;
- pen.DashStyle = (DashStyle)this.measureCircle.lineStyle;
- pen.Width = penWidth;
- Font textfont = new Font(measureCircle.font, measureCircle.fontSize);
- Brush textbrush = new SolidBrush(Color.FromArgb(measureCircle.textColor));
- Pen linePen = new Pen(Color.FromArgb(measureCircle.lineColor), measureCircle.lineWidth);
- linePen.DashStyle = (DashStyle)measureCircle.lineStyle;
- if (this.Selected)
- {
- if (measureCircle.chooseStyle != null)
- {
- textfont = new Font(measureCircle.chooseStyle.font, measureCircle.chooseStyle.fontSize);
- textbrush = new SolidBrush(Color.FromArgb(measureCircle.chooseStyle.textColor));
- linePen = new Pen(Color.FromArgb(measureCircle.chooseStyle.lineColor), measureCircle.chooseStyle.lineWidth);
- linePen.DashStyle = (DashStyle)measureCircle.chooseStyle.lineStyle;
- pen = new Pen(Color.FromArgb(measureCircle.chooseStyle.lineColor), measureCircle.chooseStyle.lineWidth);
- pen.DashStyle = (DashStyle)measureCircle.chooseStyle.lineStyle;
- }
- }
- if (!this.Selected)
- {
- this.pointChange = true;
- rectangleF1 = new RectangleF();
- rectangleF2 = new RectangleF();
- rectangleF3 = new RectangleF();
- rectangleF4 = new RectangleF();
- rectangleF5 = new RectangleF();
- rectangleF6 = new RectangleF();
- rectangleF7 = new RectangleF();
- rectangleF8 = new RectangleF();
- rectangleF9 = new RectangleF();
- rectangleF10 = new RectangleF();
- rectangleF11 = new RectangleF();
- rectangleF12 = new RectangleF();
- rectangleF13 = new RectangleF();
- rectangleF14 = new RectangleF();
- rectangleF15 = new RectangleF();
- }
- g.SmoothingMode = SmoothingMode.AntiAlias;
- if (HandleCount - 1 == 2) {
- g.DrawLine(linePen, pointArray[0].X, pointArray[0].Y, pointArray[1].X, pointArray[1].Y);
- }
-
- if (HandleCount - 1 == 3)
- {
- if (drawingPropertiesList == null)
- {
- drawingPropertiesList = drawingPropertiesListClone;
- this.configurationFile = true;
- }
- SizeF sizeF1 = new SizeF();
- float x1 = pointArray[0].X;
- float y1 = pointArray[0].Y;
- float x2 = pointArray[1].X;
- float y2 = pointArray[1].Y;
- float x3 = pointArray[2].X;
- float y3 = pointArray[2].Y;
- double a = x1 - x2;
- double b = y1 - y2;
- double c = x1 - x3;
- double d = y1 - y3;
- double e = ((x1 * x1 - x2 * x2) + (y1 * y1 - y2 * y2)) / 2.0;
- double f = ((x1 * x1 - x3 * x3) + (y1 * y1 - y3 * y3)) / 2.0;
- x0 = x1;
- y0 = y1;
- double det = b * c - a * d;
- if (Math.Abs(det) > 0.001)
- {
- //x0,y0为计算得到的原点
- x0 = -(d * e - b * f) / det;
- y0 = -(a * f - c * e) / det;
- radius = Math.Round(Math.Sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) * 2, 10);
- }
-
- linePen.StartCap = LineCap.ArrowAnchor;
- linePen.EndCap = LineCap.Round;
- rectangle.X = (float)(x0 - radius / 2);
- rectangle.Y = (float)(y0 - radius / 2);
- rectangle.Width = (float)radius;
- rectangle.Height = (float)radius;
- string circleMessage = Math.Round(Math.PI * (radius / 2) * (radius / 2) * unitLength, decimalPlaces) + unit + "²\r\n"
- + Math.Round(radius / 2 * unitLength, decimalPlaces) + unit + "\r\n" + Math.Round(radius * unitLength, decimalPlaces) + unit + "\r\n";//圆的信息字符串
- SizeF sizeF = g.MeasureString(circleMessage, textfont);//获取字符串对应的矩形尺寸
- RectangleF recMessage = new RectangleF();
- recMessage.Width = sizeF.Width;
- recMessage.Height = sizeF.Height;
- if (jangle == 0)
- {
- if (arrowPosition)
- {
- linePoint = new Point(Convert.ToInt32(x0 - radius / 2), Convert.ToInt32(y0));
- messagePoint = new Point(Convert.ToInt32(x0 - radius / 4), Convert.ToInt32(y0));
- }
- recMessage.X = messagePoint.X;
- recMessage.Y = messagePoint.Y;
- g.DrawEllipse(pen, rectangle);
- g.DrawLine(linePen, linePoint.X , linePoint.Y , Convert.ToInt32(x0), Convert.ToInt32(y0));
- //g.DrawString(circleMessage, textfont, textbrush, recMessage);
- }
- else
- {
- recMessage.X = messagePoint.X;
- recMessage.Y = messagePoint.Y;
- Matrix mtxSave = g.Transform;
- Matrix matrix = g.Transform;
- matrix.RotateAt((float)jangle, new PointF(float.Parse(x0.ToString()), float.Parse(y0.ToString())));
- g.Transform = matrix;
- g.DrawEllipse(pen, rectangle);
- g.Transform = mtxSave;
- matrix.Dispose();
- g.DrawLine(linePen, linePoint.X, linePoint.Y, Convert.ToInt32(x0), Convert.ToInt32(y0));
- //g.DrawString(circleMessage, textfont, textbrush, recMessage);
- }
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- int offsetValue = measureCircle.fontSize + measureCircle.fontSize / 2;
- int offsetValue1 = measureCircle.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.PixelRadius.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(radius / 2, decimalPlaces) + "px", textfont);
- rectangleF12.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalRadius.ToString()))
- {
- string s = Math.Round(radius / 2 * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont);
- rectangleF13.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelDiameter.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(radius, decimalPlaces) + "px", textfont);
- rectangleF14.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDiameter.ToString()))
- {
- string s = Math.Round(radius * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont);
- rectangleF15.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont);
- rectangleF6.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
- {
- string s = Math.Round(Math.PI * radius * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont);
- rectangleF7.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont);
- rectangleF4.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
- {
- string s = Math.Round(Math.PI * (radius / 2) * (radius / 2) * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- sizeF1 = g.MeasureString(frontStr + s + this.unit + "²", textfont);
- rectangleF5.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterX.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.x0, decimalPlaces), textfont);
- rectangleF8.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.y0, decimalPlaces), textfont);
- rectangleF9.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.x0 * unitLength, decimalPlaces), textfont);
- rectangleF10.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.y0 * unitLength, decimalPlaces), textfont);
- rectangleF11.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"), textfont);
- rectangleF1.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + this.unitString, textfont);
- rectangleF2.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + this.unit, textfont);
- rectangleF3.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
- offset += offsetValue;
- }
- }
- }
- if (drawingPropertiesList != null)
- {
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"), textfont);
- rectangleF1.Width = sizeF1.Width;
- rectangleF1.Height = sizeF1.Height;
- g.DrawString(frontStr + PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"), textfont, textbrush, rectangleF1);
- }
- else
- {
- rectangleF1 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + this.unitString, textfont);
- rectangleF2.Width = sizeF1.Width;
- rectangleF2.Height = sizeF1.Height;
- g.DrawString(frontStr + this.unitString, textfont, textbrush, rectangleF2);
- }
- else
- {
- rectangleF2 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + this.unit, textfont);
- rectangleF3.Width = sizeF1.Width;
- rectangleF3.Height = sizeF1.Height;
- g.DrawString(frontStr + this.unit, textfont, textbrush, rectangleF3);
- }
- else
- {
- rectangleF3 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont);
- rectangleF4.Width = sizeF1.Width;
- rectangleF4.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont, textbrush, rectangleF4);
- }
- else
- {
- rectangleF4 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
- {
- string s = Math.Round(Math.PI * (radius / 2) * (radius / 2) * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- sizeF1 = g.MeasureString(frontStr + s + this.unit + "²", textfont);
- rectangleF5.Width = sizeF1.Width;
- rectangleF5.Height = sizeF1.Height;
- g.DrawString(frontStr + s + this.unit + "²", textfont, textbrush, rectangleF5);
- }
- else
- {
- rectangleF5 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont);
- rectangleF6.Width = sizeF1.Width;
- rectangleF6.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont, textbrush, rectangleF6);
- }
- else
- {
- rectangleF6 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
- {
- string s = Math.Round(Math.PI * radius * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont);
- rectangleF7.Width = sizeF1.Width;
- rectangleF7.Height = sizeF1.Height;
- g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF7);
- }
- else
- {
- rectangleF7 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterX.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.x0, decimalPlaces), textfont);
- rectangleF8.Width = sizeF1.Width;
- rectangleF8.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(this.x0, decimalPlaces), textfont, textbrush, rectangleF8);
- }
- else
- {
- rectangleF8 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.y0, decimalPlaces), textfont);
- rectangleF9.Width = sizeF1.Width;
- rectangleF9.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(this.y0, decimalPlaces), textfont, textbrush, rectangleF9);
- }
- else
- {
- rectangleF9 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.x0 * unitLength, decimalPlaces), textfont);
- rectangleF10.Width = sizeF1.Width;
- rectangleF10.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(this.x0 * unitLength, decimalPlaces), textfont, textbrush, rectangleF10);
- }
- else
- {
- rectangleF10 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.y0 * unitLength, decimalPlaces), textfont);
- rectangleF11.Width = sizeF1.Width;
- rectangleF11.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(this.y0 * unitLength, decimalPlaces), textfont, textbrush, rectangleF11);
- }
- else
- {
- rectangleF11 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelRadius.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(radius / 2, decimalPlaces) + "px", textfont);
- rectangleF12.Width = sizeF1.Width;
- rectangleF12.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(radius / 2, decimalPlaces) + "px", textfont, textbrush, rectangleF12);
- }
- else
- {
- rectangleF12 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalRadius.ToString()))
- {
- string s = Math.Round(radius / 2 * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont);
- rectangleF13.Width = sizeF1.Width;
- rectangleF13.Height = sizeF1.Height;
- g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF13);
- }
- else
- {
- rectangleF13 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelDiameter.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(radius, decimalPlaces) + "px", textfont);
- rectangleF14.Width = sizeF1.Width;
- rectangleF14.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(radius, decimalPlaces) + "px", textfont, textbrush, rectangleF14);
- }
- else
- {
- rectangleF14 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDiameter.ToString()))
- {
- string s = Math.Round(radius * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- sizeF1 = g.MeasureString(frontStr + s + this.unit, textfont);
- rectangleF15.Width = sizeF1.Width;
- rectangleF15.Height = sizeF1.Height;
- g.DrawString(frontStr + s + this.unit, textfont, textbrush, rectangleF15);
- }
- else
- {
- rectangleF15 = new RectangleF();
- }
- }
- }
- pen.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 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)
- {
- float x = 0;
- float y = 0;
- switch (handleNumber)
- {
- case 1:
- x = pointArray[0].X;
- y = pointArray[0].Y;
- break;
- case 2:
- x = pointArray[1].X;
- y = pointArray[1].Y;
- break;
- case 3:
- x = pointArray[2].X;
- y = pointArray[2].Y;
- break;
- case 4:
- x = rectangle.X;
- y = rectangle.Y;
- break;
- case 5:
- x = rectangle.Right;
- y = rectangle.Y;
- break;
- case 6:
- x = rectangle.Right;
- y = rectangle.Bottom;
- break;
- case 7:
- x = rectangle.X;
- y = rectangle.Bottom;
- break;
- case 8:
- x = linePoint.X;
- y = linePoint.Y;
- break;
- case 9:
- 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)
- {
- if (Selected)
- {
- for (int i = 1; i <= 8; i++)
- {
- if (GetHandleRectangle(i).Contains(point))
- return i;
- }
- if (this.rectangleF1.Contains(point))
- {
- this.pointL = point;
- moveKb = 1;
- return 9;
- }
- else if (this.rectangleF2.Contains(point))
- {
- this.pointL = point;
- moveKb = 2;
- return 9;
- }
- else if (this.rectangleF3.Contains(point))
- {
- this.pointL = point;
- moveKb = 3;
- return 9;
- }
- else if (this.rectangleF4.Contains(point))
- {
- this.pointL = point;
- moveKb = 4;
- return 9;
- }
- else if (this.rectangleF5.Contains(point))
- {
- this.pointL = point;
- moveKb = 5;
- return 9;
- }
- else if (this.rectangleF6.Contains(point))
- {
- this.pointL = point;
- moveKb = 6;
- return 9;
- }
- else if (this.rectangleF7.Contains(point))
- {
- this.pointL = point;
- moveKb = 7;
- return 9;
- }
- else if (this.rectangleF8.Contains(point))
- {
- this.pointL = point;
- moveKb = 8;
- return 9;
- }
- else if (this.rectangleF9.Contains(point))
- {
- this.pointL = point;
- moveKb = 9;
- return 9;
- }
- else if (this.rectangleF10.Contains(point))
- {
- this.pointL = point;
- moveKb = 10;
- return 9;
- }
- else if (this.rectangleF11.Contains(point))
- {
- this.pointL = point;
- moveKb = 11;
- return 9;
- }
- else if (this.rectangleF12.Contains(point))
- {
- this.pointL = point;
- moveKb = 12;
- return 9;
- }
- else if (this.rectangleF13.Contains(point))
- {
- this.pointL = point;
- moveKb = 13;
- return 9;
- }
- else if (this.rectangleF14.Contains(point))
- {
- this.pointL = point;
- moveKb = 14;
- return 9;
- }
- else if (this.rectangleF15.Contains(point))
- {
- this.pointL = point;
- moveKb = 15;
- return 9;
- }
- }
- if (PointInObject(point))
- return 0;
- return -1;
- }
- protected override bool PointInObject(Point point)
- {
- CreateObjects();
- return AreaRegion.IsVisible(point);
- }
- public override bool IntersectsWith(Rectangle rectangle)
- {
- CreateObjects();
- return AreaRegion.IsVisible(rectangle);
- }
- protected virtual void CreateObjects()
- {
- if (AreaPath != null)
- return;
- AreaPath = new GraphicsPath();
- AreaPath.AddRectangle(GetBoundingBox());
- AreaPath.CloseFigure();
- AreaRegion = new Region(AreaPath);
- }
- protected GraphicsPath AreaPath
- {
- get
- {
- return areaPath;
- }
- set
- {
- areaPath = value;
- }
- }
- protected Region AreaRegion
- {
- get
- {
- return areaRegion;
- }
- set
- {
- areaRegion = value;
- }
- }
- protected Pen AreaPen
- {
- get
- {
- return areaPen;
- }
- set
- {
- areaPen = value;
- }
- }
- public override Cursor GetHandleCursor(int handleNumber)
- {
- return handleCursor;
- }
- public override void MoveHandleTo(Point point, int handleNumber)
- {
- if(handleNumber<4)
- {
- this.mouseUpPointChange = true;
- if (handleNumber == 1)
- {
- this.rectangleF1.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF2.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF3.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF4.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF5.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF6.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF7.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF8.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF9.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF10.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF11.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF12.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF13.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF14.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF15.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- }
- pointArray[handleNumber - 1] = point;
- linePoint = new PointF((float)(x0 - radius / 2), (float)y0);
- messagePoint = new PointF((float)(x0 - radius / 4), (float)(y0));
- }
- else if (handleNumber == 8)
- {
- this.mouseUpPointChange = true;
- arrowAngle = BasicCalculationHelper.CalculateAngle(x0, y0, linePoint.X, linePoint.Y, point.X, point.Y);
- linePoint = BasicCalculationHelper.GetAnglePoint(linePoint, new PointF((float)(x0), (float)(y0)), arrowAngle);
- messagePoint = BasicCalculationHelper.GetAnglePoint(messagePoint, new PointF((float)(x0), (float)(y0)), arrowAngle);
- }
- else if(handleNumber == 9)
- {
- if (this.moveKb == 1)
- this.rectangleF1.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 2)
- this.rectangleF2.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 3)
- this.rectangleF3.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 4)
- this.rectangleF4.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 5)
- this.rectangleF5.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 6)
- this.rectangleF6.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 7)
- this.rectangleF7.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 8)
- this.rectangleF8.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 9)
- this.rectangleF9.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 10)
- this.rectangleF10.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 11)
- this.rectangleF11.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 12)
- this.rectangleF12.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 13)
- this.rectangleF13.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 14)
- this.rectangleF14.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 15)
- this.rectangleF15.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- this.pointL = point;
- }
- else
- {
- this.mouseUpPointChange = true;
- float x=0, y=0;
- switch(handleNumber)
- {
- case 4:
- x = rectangle.X;
- y = rectangle.Y;
- break;
- case 5:
- x = rectangle.Right;
- y = rectangle.Y;
- break;
- case 6:
- x = rectangle.Right;
- y = rectangle.Bottom;
- break;
- case 7:
- x = rectangle.X;
- y = rectangle.Bottom;
- break;
- }
-
- if (!this.isPress)
- {
- this.isPress = true;
- lastPoint = new PointF(x, y);
- jangle = 0;
- }
-
- angle = BasicCalculationHelper.CalculateAngle(x0, y0, lastPoint.X, lastPoint.Y, point.X, point.Y);
- jangle += angle;
- lastPoint = point;
- for (int l = 0; l < pointArray.Count; l++)
- {
- pointArray[l] = BasicCalculationHelper.GetAnglePoint(pointArray[l], new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), angle);
- }
- linePoint = BasicCalculationHelper.GetAnglePoint(linePoint, new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), angle);
- messagePoint = BasicCalculationHelper.GetAnglePoint(messagePoint, new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), angle);
- }
- //Invalidate();
- }
- public override void Move(int deltaX, int deltaY)
- {
- for (int i = 0; i < pointArray.Count; i++)
- {
- pointArray[i] = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY));
- }
- linePoint.X += ISurfaceBox.UnscaleScalar(deltaX);
- linePoint.Y += ISurfaceBox.UnscaleScalar(deltaY);
- messagePoint.X += ISurfaceBox.UnscaleScalar(deltaX);
- messagePoint.Y += ISurfaceBox.UnscaleScalar(deltaY);
- this.startPoint = pointArray[0];
- int x = ISurfaceBox.UnscaleScalar(deltaX);
- int y = ISurfaceBox.UnscaleScalar(deltaY);
- pointL.X += x;
- pointL.Y += y;
- this.rectangleF1.Offset(x, y);
- this.rectangleF2.Offset(x, y);
- this.rectangleF3.Offset(x, y);
- this.rectangleF4.Offset(x, y);
- this.rectangleF5.Offset(x, y);
- this.rectangleF6.Offset(x, y);
- this.rectangleF7.Offset(x, y);
- this.rectangleF8.Offset(x, y);
- this.rectangleF9.Offset(x, y);
- this.rectangleF10.Offset(x, y);
- this.rectangleF11.Offset(x, y);
- this.rectangleF12.Offset(x, y);
- this.rectangleF13.Offset(x, y);
- this.rectangleF14.Offset(x, y);
- this.rectangleF15.Offset(x, y);
- Invalidate();
- }
- /// <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;
- }
- }
- /// <summary>
- /// Normalize rectangle
- /// </summary>
- public override void Normalize()
- {
- this.isPress = false;
- rectangle = Annotation.DrawObject.GetNormalizedRectangle(rectangle);
- }
- public override RectangleF GetBoundingBox()
- {
- Rectangle rectangle;
- int minx = 0, maxx = 0, miny = 0, maxy = 0;
- for (int i = 0; i < pointArray.Count; i++)
- {
- if (i == 0)
- {
- minx = maxx = (int)pointArray[i].X;
- miny = maxy = (int)pointArray[i].Y;
- }
- else
- {
- if (pointArray[i].X > maxx) maxx = (int)pointArray[i].X;
- if (pointArray[i].X < minx) minx = (int)pointArray[i].X;
- if (pointArray[i].Y > maxy) maxy = (int)pointArray[i].Y;
- if (pointArray[i].Y < miny) miny = (int)pointArray[i].Y;
- }
- }
- rectangle = new Rectangle(minx, miny, maxx - minx, maxy - miny);
- return rectangle;
- }
- internal void setNextPoint(Point p)
- {
- AddPoint(p);
- }
- public override void DrawTracker(Graphics g)
- {
- if (!Selected)
- return;
- if (pointArray.Count >= 3)
- {
- SolidBrush brush = new SolidBrush(Color.FromArgb(MarkpointAreaColor));
- Pen pen = new Pen(Color.FromArgb(MarkpointLineColor), MarkpointLineWidth);
- for (int i = 1; i <= 8; i++)
- {
- if (i == 9)
- {
- brush = new SolidBrush(Color.Transparent);
- pen = new Pen(Color.Transparent);
- }
- switch (MarkpointStyle)
- {
- case 0:
- g.FillRectangle(brush, GetHandleRectangle(i));
- g.DrawRectangle(pen, GetHandleRectangle(i));
- break;
- case 1:
- g.FillEllipse(brush, GetHandleRectangle(i));
- g.DrawEllipse(pen, GetHandleRectangle(i));
- break;
- case 2:
- g.FillPolygon(brush, GetHandlePoint(i));
- g.DrawPolygon(pen, GetHandlePoint(i));
- break;
- }
- }
- brush.Dispose();
- pen.Dispose();
- RectangleF r = GetBoundingBox();
- //g.DrawRectangle(new Pen(Color.White), r.X, r.Y, r.Width, r.Height);
- }
- }
- public override List<PointF> GetPoints()
- {
- return pointArray;
- }
- public override ParentStyleModel GetStyle()
- {
- return measureCircle;
- }
- }
- }
|