12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511 |
- 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 MeasureDiameterCircle : MeasureDrawObject
- {
- /// <summary>
- /// 点集合
- /// </summary>
- public PointList pointArray;
- /// <summary>
- /// 样式
- /// </summary>
- private MeasureStyleModel.MeasureDiameterCircle measureDiameterCircle;
- /// <summary>
- /// 箭头的原点
- /// </summary>
- //Point linePoint;
- /// <summary>
- /// 箭头的终点
- /// </summary>
- //Point lineEndPoint;
- /// <summary>
- /// 文字的原点
- /// </summary>
- Point 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>
- 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;
- private bool drawing;
- /// <summary>
- /// 是否移动了鼠标
- /// </summary>
- public bool moved = false;
- /// <summary>
- /// 限制绘制(绘制中)
- /// </summary>
- public bool mouseUpPointChange = false;
- public MeasureDiameterCircle(ISurfaceBox surfaceBox) : base(surfaceBox)
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureDiameterCircle;
- pointArray = new PointList();
- Initialize();
- }
- public MeasureDiameterCircle(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox)
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureDiameterCircle;
- measureDiameterCircle = this.ISurfaceBox.GetMeasureStyleModel().measureDiameterCircle;
- pointArray = new PointList();
- if (clone)
- {
- drawing = true;
- pointArray.Add(new Point(x1, y1));
- pointArray.Add(new Point(x1 + 1, y1 + 1));
- }
- this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
- this.unitString = surfaceBox.GetPxPerUnit()[1];
- this.unit = surfaceBox.GetPxPerUnit()[2];
-
- Initialize();
- }
- public MeasureDiameterCircle(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base(surfaceBox)
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureDiameterCircle;
- this.ISurfaceBox = surfaceBox;
- measureDiameterCircle = (MeasureStyleModel.MeasureDiameterCircle)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;
- this.moved = true;
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- public override DrawObject Clone()
- {
- MeasureDiameterCircle drawDiameterCircle = new MeasureDiameterCircle(ISurfaceBox, (int)pointArray[0].X, (int)pointArray[0].Y, false);
- drawDiameterCircle.objectType = DrawClass.Measure;
- drawDiameterCircle.drawToolType = DrawToolType.MeasureDiameterCircle;
- drawDiameterCircle.ISurfaceBox = ISurfaceBox;
- foreach (PointF p in this.pointArray)
- {
- drawDiameterCircle.pointArray.Add(p);
- }
- if (drawingPropertiesList != null)
- drawDiameterCircle.drawingPropertiesListClone = drawingPropertiesList;
- drawDiameterCircle.moved = true;
- FillDrawObjectFields(drawDiameterCircle);
- return drawDiameterCircle;
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- public override DrawObject Clone(ISurfaceBox surfaceBox)
- {
- MeasureDiameterCircle drawDiameterCircle = new MeasureDiameterCircle(surfaceBox, this.GetPoints(), this.measureDiameterCircle, null);
- if (drawingPropertiesList != null)
- drawDiameterCircle.drawingPropertiesListClone = drawingPropertiesList;
- drawDiameterCircle.moved = true;
- FillDrawObjectFields(drawDiameterCircle);
- return drawDiameterCircle;
- }
- /// <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 * radius, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelArea, Math.Round(Math.PI * radius * radius, decimalPlaces));
- string s = Math.Round(Math.PI * radius * radius * 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(Math.PI * radius * 2, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelCircumference, Math.Round(Math.PI * radius * 2, decimalPlaces));
- s = Math.Round(Math.PI * radius * 2 * 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);
- 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, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelRadius, 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.PhysicalRadius))
- data[MeasureAttributes.PhysicalRadius] = s;
- else
- data.Add(MeasureAttributes.PhysicalRadius, s);
- if (data.ContainsKey(MeasureAttributes.PixelDiameter))
- data[MeasureAttributes.PixelDiameter] = Math.Round(radius * 2, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelDiameter, 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 a = s.Length - s.IndexOf(".") - 1;
- if (a < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - a; 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)
- {
- if(this.moved)
- {
- string frontStr = string.Empty;
- if (this.measureDiameterCircle.showSuffix)
- {
- frontStr = this.measureDiameterCircle.suffixName;
- }
- if (this.measureDiameterCircle.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.measureDiameterCircle.showAlias)
- {
- frontStr = this.measureDiameterCircle.aliasName + frontStr;
- }
- drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
- pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
- measureDiameterCircle = this.ISurfaceBox.GetMeasureStyleModel().measureDiameterCircle;
- if (pointArray.Count > 1)
- {
- if (drawingPropertiesList == null)
- {
- drawingPropertiesList = drawingPropertiesListClone;
- if (!this.drawing)
- this.configurationFile = true;
- }
- SizeF sizeF1 = new SizeF();
- Color color = Color.FromArgb(this.measureDiameterCircle.lineColor);
- Pen pen = new Pen(color, PenWidth);
- int penWidth = this.measureDiameterCircle.lineWidth;
- pen.DashStyle = (DashStyle)this.measureDiameterCircle.lineStyle;
- pen.Width = penWidth;
- Font textfont = new Font(measureDiameterCircle.font, measureDiameterCircle.fontSize);
- Brush textbrush = new SolidBrush(Color.FromArgb(measureDiameterCircle.textColor));
- Pen linePen = new Pen(Color.FromArgb(measureDiameterCircle.lineColor), measureDiameterCircle.lineWidth);
- linePen.DashStyle = (DashStyle)measureDiameterCircle.lineStyle;
- linePen.StartCap = LineCap.ArrowAnchor;
- linePen.EndCap = LineCap.ArrowAnchor;
- if (this.Selected)
- {
- if (measureDiameterCircle.chooseStyle != null)
- {
- textfont = new Font(measureDiameterCircle.chooseStyle.font, measureDiameterCircle.chooseStyle.fontSize);
- textbrush = new SolidBrush(Color.FromArgb(measureDiameterCircle.chooseStyle.textColor));
- linePen = new Pen(Color.FromArgb(measureDiameterCircle.chooseStyle.lineColor), measureDiameterCircle.chooseStyle.lineWidth);
- linePen.DashStyle = (DashStyle)measureDiameterCircle.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;
- float x = Math.Abs(pointArray[1].X - pointArray[0].X);
- float y = Math.Abs(pointArray[1].Y - pointArray[0].Y);
- radius = (Math.Sqrt(x * x + y * y)) / 2;
- x0 = Convert.ToInt32((pointArray[0].X + pointArray[1].X) / 2);
- y0 = Convert.ToInt32((pointArray[0].Y + pointArray[1].Y) / 2);
- rectangle.X = Convert.ToInt32(x0 - radius);
- rectangle.Y = Convert.ToInt32(y0 - radius);
- rectangle.Width = Convert.ToInt32(radius * 2);
- rectangle.Height = Convert.ToInt32(radius * 2);
- string circleMessage = Math.Round(Math.PI * radius * radius * unitLength, decimalPlaces) + unit + "²\r\n"
- + Math.Round(radius * unitLength, decimalPlaces) + unit + "\r\n" + Math.Round(radius * 2 * 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), Convert.ToInt32(y0));
- //lineEndPoint = new Point(Convert.ToInt32(x0 + radius), Convert.ToInt32(y0));
- messagePoint = new Point(Convert.ToInt32((pointArray[0].X + x0) / 2), Convert.ToInt32((pointArray[0].Y + y0) / 2));
- }
- recMessage.X = messagePoint.X;
- recMessage.Y = messagePoint.Y;
- g.DrawEllipse(pen, rectangle);
- //linePen.DashStyle = DashStyle.DashDot;
- g.DrawLine(linePen, pointArray[0].X, pointArray[0].Y, pointArray[1].X, pointArray[1].Y);
- //linePen.DashStyle = (DashStyle)measureDiameterCircle.lineStyle;
- //linePen.StartCap = LineCap.ArrowAnchor;
- //linePen.EndCap = LineCap.ArrowAnchor;
- //g.DrawLine(linePen, linePoint.X, linePoint.Y, lineEndPoint.X, lineEndPoint.Y);
- //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();
- //linePen.DashStyle = DashStyle.DashDot;
- g.DrawLine(linePen, pointArray[0].X, pointArray[0].Y, pointArray[1].X, pointArray[1].Y);
- //linePen.DashStyle = (DashStyle)measureDiameterCircle.lineStyle;
- //linePen.StartCap = LineCap.ArrowAnchor;
- //linePen.EndCap = LineCap.ArrowAnchor;
- //g.DrawLine(linePen, linePoint.X, linePoint.Y, lineEndPoint.X, lineEndPoint.Y);
- //g.DrawString(circleMessage, textfont, textbrush, recMessage);
- }
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- int offsetValue = measureDiameterCircle.fontSize + measureDiameterCircle.fontSize / 2;
- int offsetValue1 = measureDiameterCircle.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, 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 * 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(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 * 2, 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 * 2 * 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";
- }
- }
- }
- sizeF1 = g.MeasureString(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 * 2, 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 * 2 * 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";
- }
- }
- }
- 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 * radius, 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 * radius * 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";
- }
- }
- }
- 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.pointArray[0].X, 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.pointArray[0].Y, 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.pointArray[0].X * 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.pointArray[0].Y * 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 * radius, decimalPlaces) + "px²", textfont);
- rectangleF4.Width = sizeF1.Width;
- rectangleF4.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(Math.PI * radius * radius, decimalPlaces) + "px²", textfont, textbrush, rectangleF4);
- }
- else
- {
- rectangleF4 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
- {
- string s = Math.Round(Math.PI * radius * radius * 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";
- }
- }
- }
- 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 * 2, decimalPlaces) + "px", textfont);
- rectangleF6.Width = sizeF1.Width;
- rectangleF6.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(Math.PI * radius * 2, decimalPlaces) + "px", textfont, textbrush, rectangleF6);
- }
- else
- {
- rectangleF6 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
- {
- string s = Math.Round(Math.PI * radius * 2 * 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";
- }
- }
- }
- 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.pointArray[0].X, decimalPlaces), textfont);
- rectangleF8.Width = sizeF1.Width;
- rectangleF8.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(this.pointArray[0].X, decimalPlaces), textfont, textbrush, rectangleF8);
- }
- else
- {
- rectangleF8 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.pointArray[0].Y, decimalPlaces), textfont);
- rectangleF9.Width = sizeF1.Width;
- rectangleF9.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(this.pointArray[0].Y, decimalPlaces), textfont, textbrush, rectangleF9);
- }
- else
- {
- rectangleF9 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.pointArray[0].X * unitLength, decimalPlaces), textfont);
- rectangleF10.Width = sizeF1.Width;
- rectangleF10.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(this.pointArray[0].X * unitLength, decimalPlaces), textfont, textbrush, rectangleF10);
- }
- else
- {
- rectangleF10 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(this.pointArray[0].Y * unitLength, decimalPlaces), textfont);
- rectangleF11.Width = sizeF1.Width;
- rectangleF11.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(this.pointArray[0].Y * unitLength, decimalPlaces), textfont, textbrush, rectangleF11);
- }
- else
- {
- rectangleF11 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelRadius.ToString()))
- {
- sizeF1 = g.MeasureString(frontStr + Math.Round(radius, decimalPlaces) + "px", textfont);
- rectangleF12.Width = sizeF1.Width;
- rectangleF12.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(radius, decimalPlaces) + "px", textfont, textbrush, rectangleF12);
- }
- else
- {
- rectangleF12 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalRadius.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);
- 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 * 2, decimalPlaces) + "px", textfont);
- rectangleF14.Width = sizeF1.Width;
- rectangleF14.Height = sizeF1.Height;
- g.DrawString(frontStr + Math.Round(radius * 2, decimalPlaces) + "px", textfont, textbrush, rectangleF14);
- }
- else
- {
- rectangleF14 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDiameter.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 a = s.Length - s.IndexOf(".") - 1;
- if (a < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - a; 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();
- linePen.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 = rectangle.X;
- y = rectangle.Y;
- break;
- case 4:
- x = rectangle.Right;
- y = rectangle.Y;
- break;
- case 5:
- x = rectangle.Right;
- y = rectangle.Bottom;
- break;
- case 6:
- x = rectangle.X;
- y = rectangle.Bottom;
- break;
- case 7:
- x = Convert.ToInt32(x0);
- y = Convert.ToInt32(y0);
- break;
- case 8:
- 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 7;
- }
- else if (this.rectangleF2.Contains(point))
- {
- this.pointL = point;
- moveKb = 2;
- return 7;
- }
- else if (this.rectangleF3.Contains(point))
- {
- this.pointL = point;
- moveKb = 3;
- return 7;
- }
- else if (this.rectangleF4.Contains(point))
- {
- this.pointL = point;
- moveKb = 4;
- return 7;
- }
- else if (this.rectangleF5.Contains(point))
- {
- this.pointL = point;
- moveKb = 5;
- return 7;
- }
- else if (this.rectangleF6.Contains(point))
- {
- this.pointL = point;
- moveKb = 6;
- return 7;
- }
- else if (this.rectangleF7.Contains(point))
- {
- this.pointL = point;
- moveKb = 7;
- return 7;
- }
- else if (this.rectangleF8.Contains(point))
- {
- this.pointL = point;
- moveKb = 8;
- return 7;
- }
- else if (this.rectangleF9.Contains(point))
- {
- this.pointL = point;
- moveKb = 9;
- return 7;
- }
- else if (this.rectangleF10.Contains(point))
- {
- this.pointL = point;
- moveKb = 10;
- return 7;
- }
- else if (this.rectangleF11.Contains(point))
- {
- this.pointL = point;
- moveKb = 11;
- return 7;
- }
- else if (this.rectangleF12.Contains(point))
- {
- this.pointL = point;
- moveKb = 12;
- return 7;
- }
- else if (this.rectangleF13.Contains(point))
- {
- this.pointL = point;
- moveKb = 13;
- return 7;
- }
- else if (this.rectangleF14.Contains(point))
- {
- this.pointL = point;
- moveKb = 14;
- return 7;
- }
- else if (this.rectangleF15.Contains(point))
- {
- this.pointL = point;
- moveKb = 15;
- return 7;
- }
- }
- if (PointInObject(point))
- return 0;
- return -1;
- }
- protected override bool PointInObject(Point point)
- {
- CreateObjects();
- return rectangle.Contains(point);
- }
- public override bool IntersectsWith(Rectangle rectangle)
- {
- CreateObjects();
- return AreaRegion.IsVisible(rectangle);
- }
- protected virtual void CreateObjects()
- {
- if (AreaPath != null)
- return;
- AreaPath = new GraphicsPath();
- AreaPath.AddRectangle(GetBoundingBox());
- AreaPath.CloseFigure();
- AreaRegion = new Region(AreaPath);
- }
- protected GraphicsPath AreaPath
- {
- get
- {
- return areaPath;
- }
- set
- {
- areaPath = value;
- }
- }
- protected Region AreaRegion
- {
- get
- {
- return areaRegion;
- }
- set
- {
- areaRegion = value;
- }
- }
- protected Pen AreaPen
- {
- get
- {
- return areaPen;
- }
- set
- {
- areaPen = value;
- }
- }
- public override Cursor GetHandleCursor(int handleNumber)
- {
- return handleCursor;
- }
- public override void MoveHandleTo(Point point, int handleNumber)
- {
- if(handleNumber == 2)
- {
- this.mouseUpPointChange = true;
- pointArray[handleNumber - 1] = point;
- //linePoint = new Point(Convert.ToInt32(x0 - radius), Convert.ToInt32(y0));
- //lineEndPoint = new Point(Convert.ToInt32(x0 + radius), Convert.ToInt32(y0));
- messagePoint = new Point(Convert.ToInt32((pointArray[0].X + x0) / 2), Convert.ToInt32((pointArray[0].Y + y0)/2));
- }
- //else if (handleNumber == 1)
- //{
- // arrowAngle = BasicCalculationHelper.CalculateAngle(x0, y0, pointArray[0].X, pointArray[0].Y, point.X, point.Y);
- // pointArray[0] = BasicCalculationHelper.GetAnglePoint(pointArray[0], new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), arrowAngle);
- // messagePoint = BasicCalculationHelper.GetAnglePoint(messagePoint, new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), arrowAngle);
- // pointArray[1] = new PointF(Convert.ToInt32(x0 - (pointArray[0].X - x0)), Convert.ToInt32(y0 - (pointArray[0].Y - y0)));
- //}
- else if (handleNumber == 7)
- {
- this.mouseUpPointChange = true;
- }
- else if (handleNumber == 8)
- {
- 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 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);
- x = pointArray[0].X;
- y = pointArray[0].Y;
- break;
- case 3:
- x = rectangle.X;
- y = rectangle.Y;
- break;
- case 4:
- x = rectangle.Right;
- y = rectangle.Y;
- break;
- case 5:
- x = rectangle.Right;
- y = rectangle.Bottom;
- break;
- case 6:
- 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);
- //lineEndPoint.X = Convert.ToInt32(x0 - (linePoint.X - x0));
- //lineEndPoint.Y = Convert.ToInt32(y0 - (linePoint.Y - y0));
- }
- }
- 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);
- //lineEndPoint.X += ISurfaceBox.UnscaleScalar(deltaX);
- //lineEndPoint.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 >= 2)
- {
- SolidBrush brush = new SolidBrush(Color.FromArgb(MarkpointAreaColor));
- Pen pen = new Pen(Color.FromArgb(MarkpointLineColor), MarkpointLineWidth);
- for (int i = 1; i <= 7; i++)
- {
- if (i == 8)
- {
- 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 rectangleF = GetBoundingBox();
- //g.DrawRectangle(new Pen(Color.White), rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height);
- }
- }
- public override List<PointF> GetPoints()
- {
- return pointArray;
- }
- public override ParentStyleModel GetStyle()
- {
- return measureDiameterCircle;
- }
- }
- }
|