123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782 |
- 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 MeasureCenterCenterSize : MeasureDrawObject
- {
- /// <summary>
- /// 点集合
- /// </summary>
- public PointList pointArray;
- /// <summary>
- /// 样式
- /// </summary>
- private MeasureStyleModel.MeasureCenterCenterSize measureCenterCenterSize ;
- /// <summary>
- /// 圆心横坐标
- /// </summary>
- double x0;
- /// <summary>
- /// 圆心纵坐标
- /// </summary>
- double y0;
- /// <summary>
- /// 第二个圆圆心横坐标
- /// </summary>
- double x01;
- /// <summary>
- /// 第二个圆圆心纵坐标
- /// </summary>
- double y01;
- /// <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();
- private RectangleF rectangleF16 = new RectangleF();
- private RectangleF rectangleF17 = 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;
- /// <summary>
- /// 属性绘制点
- /// </summary>
- private PointF rotationPoint;
- /// <summary>
- /// 距离
- /// </summary>
- //private double length = 0.0;
- public MeasureCenterCenterSize(ISurfaceBox surfaceBox) : base(surfaceBox)
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureCenterCenterSize;
- pointArray = new PointList();
- Initialize();
- }
- public MeasureCenterCenterSize(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox)
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureCenterCenterSize;
- this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
- this.unitString = surfaceBox.GetPxPerUnit()[1];
- this.unit = surfaceBox.GetPxPerUnit()[2];
- surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);
- measureCenterCenterSize = this.ISurfaceBox.GetMeasureStyleModel().measureCenterCenterSize;
- pointArray = new PointList();
- if (clone)
- pointArray.Add(new Point(x1, y1));
- Initialize();
- }
- public MeasureCenterCenterSize(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
- {
- this.objectType = DrawClass.Measure;
- this.drawToolType = DrawToolType.MeasureCenterCenterSize;
- this.ISurfaceBox = surfaceBox;
- measureCenterCenterSize = (MeasureStyleModel.MeasureCenterCenterSize)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];
- surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);
- this.configurationFile = true;
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- public override DrawObject Clone()
- {
- MeasureCenterCenterSize drawRectangle = new MeasureCenterCenterSize(ISurfaceBox, (int)pointArray[0].X, (int)pointArray[0].Y, false);
- drawRectangle.objectType = DrawClass.Measure;
- drawRectangle.drawToolType = DrawToolType.MeasureCenterCenterSize;
- 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)
- {
- MeasureCenterCenterSize drawRectangle = new MeasureCenterCenterSize(surfaceBox, this.GetPoints(), this.measureCenterCenterSize, 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.RegistrationMeasurement.Text");
- else
- data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.RegistrationMeasurement.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.PixelDistance))
- data[MeasureAttributes.PixelDistance] = Math.Round(this.length, decimalPlaces);
- else
- data.Add(MeasureAttributes.PixelDistance, Math.Round(this.length, decimalPlaces));
- string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int dic = s.Length - s.IndexOf(".") - 1;
- if (dic < decimalPlaces)
- {
- for (int i = 0; i < decimalPlaces - dic; i++)
- {
- s += "0";
- }
- }
- }
- if (data.ContainsKey(MeasureAttributes.PhysicalDistance))
- data[MeasureAttributes.PhysicalDistance] = s;
- else
- data.Add(MeasureAttributes.PhysicalDistance, s);
- 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));
- 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 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, 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 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 / 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 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)
- {
- drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
- pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
- Color color = Color.FromArgb(this.measureCenterCenterSize.lineColor);
- Pen pen = new Pen(color, PenWidth);
- int penWidth = this.measureCenterCenterSize.lineWidth;
- pen.DashStyle = (DashStyle)this.measureCenterCenterSize.lineStyle;
- pen.Width = penWidth;
- Font textfont = new Font(measureCenterCenterSize.font, measureCenterCenterSize.fontSize);
- Brush textbrush = new SolidBrush(Color.FromArgb(measureCenterCenterSize.textColor));
- Pen linePen = new Pen(Color.FromArgb(measureCenterCenterSize.lineColor), measureCenterCenterSize.lineWidth);
- linePen.DashStyle = (DashStyle)measureCenterCenterSize.lineStyle;
- 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 || HandleCount - 1 == 4)
- {
- if (drawingPropertiesList == null)
- {
- drawingPropertiesList = drawingPropertiesListClone;
- this.configurationFile = true;
- }
- 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)
- {
- g.DrawEllipse(pen, rectangle);
- }
- else
- {
- 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();
- }
- if(HandleCount - 1 == 4)
- g.DrawLine(pen, new PointF((float)x0, (float)y0), pointArray[3]);
- }
- if (HandleCount - 1 == 5)
- {
- if (drawingPropertiesList == null)
- {
- drawingPropertiesList = drawingPropertiesListClone;
- this.configurationFile = true;
- }
- 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)
- {
- g.DrawEllipse(pen, rectangle);
- }
- else
- {
- 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(pen, pointArray[3].X, pointArray[3].Y, pointArray[4].X, pointArray[4].Y);
- }
- if (HandleCount - 1 == 6)
- {
- Matrix mtxSave = g.Transform;
- Matrix matrix = g.Transform;
- for (int i = 0; i < 2; i++)
- {
- if (drawingPropertiesList == null)
- {
- drawingPropertiesList = drawingPropertiesListClone;
- this.configurationFile = true;
- }
- float x1;
- float y1;
- float x2;
- float y2;
- float x3;
- float y3;
- if (i == 0)
- {
- x1 = pointArray[0].X;
- y1 = pointArray[0].Y;
- x2 = pointArray[1].X;
- y2 = pointArray[1].Y;
- x3 = pointArray[2].X;
- y3 = pointArray[2].Y;
- }
- else
- {
- x1 = pointArray[3].X;
- y1 = pointArray[3].Y;
- x2 = pointArray[4].X;
- y2 = pointArray[4].Y;
- x3 = pointArray[5].X;
- y3 = pointArray[5].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;
- double x0 = x1;
- double y0 = y1;
- if (i == 0)
- {
- this.x0 = x1;
- this.y0 = y1;
- }
- else
- {
- this.x01 = x1;
- this.y01 = y1;
- }
- double det = b * c - a * d;
- if (Math.Abs(det) > 0.001)
- {
- //x0,y0为计算得到的原点
- if (i == 0)
- {
- this.x0 = -(d * e - b * f) / det;
- this.y0 = -(a * f - c * e) / det;
- }
- else
- {
- this.x01 = -(d * e - b * f) / det;
- this.y01 = -(a * f - c * e) / det;
- }
- 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)
- {
- g.DrawEllipse(pen, rectangle);
- }
- else
- {
- Matrix mtxSave1 = g.Transform;
- Matrix matrix1 = g.Transform;
- matrix1.RotateAt((float)jangle, new PointF(float.Parse(x0.ToString()), float.Parse(y0.ToString())));
- g.Transform = matrix1;
-
- g.DrawEllipse(pen, rectangle);
- g.Transform = mtxSave1;
- matrix1.Dispose();
- }
- }
- SizeF sizeF1 = new SizeF();
- //计算需要旋转的角度
- angle = BasicCalculationHelper.Angle(new PointF((float)x0, (float)y0), new PointF((float)x01, (float)y01), new PointF((float)x0, (float)y01));
- length = BasicCalculationHelper.GetDistance(new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), new Point(Convert.ToInt32(x01), Convert.ToInt32(y01)), 10);
- // 求线上面三个点
- int offsetValuePoint = measureCenterCenterSize.fontSize + measureCenterCenterSize.fontSize / 2;
- int offsetValue1Point = measureCenterCenterSize.lineWidth * 2 / 3;
- int offsetPoint = offsetValue1Point;
- if (drawingPropertiesList != null)
- {
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelDistance.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDistance.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelRadius.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalRadius.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelDiameter.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDiameter.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterX.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- offsetPoint += offsetValuePoint;
- }
- }
- PointF pointF1;
- PointF pointF2;
- if (angle < 90)
- pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)x0+ offsetPoint + offsetValue1Point, (int)y0), new PointF((float)x0, (float)y0), angle - 90);
- else
- pointF1 = BasicCalculationHelper.GetAnglePoint(new Point((int)x0 + offsetPoint + offsetValue1Point, (int)y0), new PointF((float)x0, (float)y0), angle + 90);
- if (angle < 90)
- pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)x01+ offsetPoint + offsetValue1Point, (int)y01), new PointF((float)x01, (float)y01), angle - 90);
- else
- pointF2 = BasicCalculationHelper.GetAnglePoint(new Point((int)x01 + offsetPoint + offsetValue1Point, (int)y01), new PointF((float)x01, (float)y01), angle + 90);
- PointF pointF3 = new PointF((pointF1.X + pointF2.X) / 2, (pointF1.Y + pointF2.Y) / 2);
- if (measureCenterCenterSize.linePosition == 0)
- this.rotationPoint = pointF1;
- else if (measureCenterCenterSize.linePosition == 1)
- this.rotationPoint = pointF3;
- else if (measureCenterCenterSize.linePosition == 2)
- this.rotationPoint = pointF2;
- else if (measureCenterCenterSize.linePosition == 3)
- this.rotationPoint = new PointF((float)x0, (float)y0);
- else if (measureCenterCenterSize.linePosition == 4)
- this.rotationPoint = new PointF(((float)x0 + (float)x01) / 2, ((float)y0 + (float)y01) / 2);
- else if (measureCenterCenterSize.linePosition == 5)
- this.rotationPoint = new PointF((float)x01, (float)y01);
- // 画布旋转
- if (angle < 90)
- {
- matrix.RotateAt((float)angle, new PointF(this.rotationPoint.X, this.rotationPoint.Y));
- g.Transform = matrix;
- }
- else
- {
- angle = BasicCalculationHelper.Angle(new PointF((float)x01, (float)y01), new PointF((float)x0, (float)y0), new PointF((float)x01, (float)y0));
- matrix.RotateAt((float)angle, new PointF(this.rotationPoint.X, this.rotationPoint.Y));
- g.Transform = matrix;
- }
- if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
- {
- int offsetValue = measureCenterCenterSize.fontSize + measureCenterCenterSize.fontSize / 2;
- int offsetValue1 = measureCenterCenterSize.lineWidth * 2 / 3;
- int offset = offsetValue1;
- this.pointL = new Point((int)this.rotationPoint.X, (int)this.rotationPoint.Y);
- if (drawingPropertiesList != null)
- {
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelDistance.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.length, decimalPlaces) + "px", textfont);
- rectangleF16.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDistance.ToString()))
- {
- string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int 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);
- rectangleF17.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelRadius.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(radius / 2, decimalPlaces) + "px", textfont);
- rectangleF12.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.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(s + this.unit, textfont);
- rectangleF13.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelDiameter.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(radius, decimalPlaces) + "px", textfont);
- rectangleF14.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.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(s + this.unit, textfont);
- rectangleF15.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont);
- rectangleF6.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.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(s + this.unit, textfont);
- rectangleF7.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont);
- rectangleF4.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.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(s + this.unit + "²", textfont);
- rectangleF5.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterX.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.x0, decimalPlaces), textfont);
- rectangleF8.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.y0, decimalPlaces), textfont);
- rectangleF9.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.x0 * unitLength, decimalPlaces), textfont);
- rectangleF10.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.y0 * unitLength, decimalPlaces), textfont);
- rectangleF11.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- sizeF1 = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.RegistrationMeasurement.Text"), textfont);
- rectangleF1.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- sizeF1 = g.MeasureString("" + this.unitString, textfont);
- rectangleF2.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- sizeF1 = g.MeasureString("" + this.unit, textfont);
- rectangleF3.Location = new Point((int)this.rotationPoint.X + offsetValue1 - (int)sizeF1.Width / 2, (int)this.rotationPoint.Y + offset);
- offset += offsetValue;
- }
- }
- }
- if (drawingPropertiesList != null)
- {
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
- {
- sizeF1 = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.RegistrationMeasurement.Text"), textfont);
- rectangleF1.Width = sizeF1.Width;
- rectangleF1.Height = sizeF1.Height;
- g.DrawString("" + PdnResources.GetString("Menu.MeasureAction.RegistrationMeasurement.Text"), textfont, textbrush, rectangleF1);
- }
- else
- {
- rectangleF1 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
- {
- sizeF1 = g.MeasureString("" + this.unitString, textfont);
- rectangleF2.Width = sizeF1.Width;
- rectangleF2.Height = sizeF1.Height;
- g.DrawString("" + this.unitString, textfont, textbrush, rectangleF2);
- }
- else
- {
- rectangleF2 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
- {
- sizeF1 = g.MeasureString("" + this.unit, textfont);
- rectangleF3.Width = sizeF1.Width;
- rectangleF3.Height = sizeF1.Height;
- g.DrawString("" + this.unit, textfont, textbrush, rectangleF3);
- }
- else
- {
- rectangleF3 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont);
- rectangleF4.Width = sizeF1.Width;
- rectangleF4.Height = sizeF1.Height;
- g.DrawString("" + 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(s + this.unit + "²", textfont);
- rectangleF5.Width = sizeF1.Width;
- rectangleF5.Height = sizeF1.Height;
- g.DrawString(s + this.unit + "²", textfont, textbrush, rectangleF5);
- }
- else
- {
- rectangleF5 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont);
- rectangleF6.Width = sizeF1.Width;
- rectangleF6.Height = sizeF1.Height;
- g.DrawString("" + 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(s + this.unit, textfont);
- rectangleF7.Width = sizeF1.Width;
- rectangleF7.Height = sizeF1.Height;
- g.DrawString(s + this.unit, textfont, textbrush, rectangleF7);
- }
- else
- {
- rectangleF7 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterX.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.x0, decimalPlaces), textfont);
- rectangleF8.Width = sizeF1.Width;
- rectangleF8.Height = sizeF1.Height;
- g.DrawString("" + Math.Round(this.x0, decimalPlaces), textfont, textbrush, rectangleF8);
- }
- else
- {
- rectangleF8 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.y0, decimalPlaces), textfont);
- rectangleF9.Width = sizeF1.Width;
- rectangleF9.Height = sizeF1.Height;
- g.DrawString("" + Math.Round(this.y0, decimalPlaces), textfont, textbrush, rectangleF9);
- }
- else
- {
- rectangleF9 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.x0 * unitLength, decimalPlaces), textfont);
- rectangleF10.Width = sizeF1.Width;
- rectangleF10.Height = sizeF1.Height;
- g.DrawString("" + Math.Round(this.x0 * unitLength, decimalPlaces), textfont, textbrush, rectangleF10);
- }
- else
- {
- rectangleF10 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.y0 * unitLength, decimalPlaces), textfont);
- rectangleF11.Width = sizeF1.Width;
- rectangleF11.Height = sizeF1.Height;
- g.DrawString("" + Math.Round(this.y0 * unitLength, decimalPlaces), textfont, textbrush, rectangleF11);
- }
- else
- {
- rectangleF11 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelRadius.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(radius / 2, decimalPlaces) + "px", textfont);
- rectangleF12.Width = sizeF1.Width;
- rectangleF12.Height = sizeF1.Height;
- g.DrawString("" + 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(s + this.unit, textfont);
- rectangleF13.Width = sizeF1.Width;
- rectangleF13.Height = sizeF1.Height;
- g.DrawString(s + this.unit, textfont, textbrush, rectangleF13);
- }
- else
- {
- rectangleF13 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelDiameter.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(radius, decimalPlaces) + "px", textfont);
- rectangleF14.Width = sizeF1.Width;
- rectangleF14.Height = sizeF1.Height;
- g.DrawString("" + 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(s + this.unit, textfont);
- rectangleF15.Width = sizeF1.Width;
- rectangleF15.Height = sizeF1.Height;
- g.DrawString(s + this.unit, textfont, textbrush, rectangleF15);
- }
- else
- {
- rectangleF15 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PixelDistance.ToString()))
- {
- sizeF1 = g.MeasureString("" + Math.Round(this.length, decimalPlaces) + "px", textfont);
- rectangleF16.Width = sizeF1.Width;
- rectangleF16.Height = sizeF1.Height;
- g.DrawString("" + Math.Round(this.length, decimalPlaces) + "px", textfont, textbrush, rectangleF16);
- }
- else
- {
- rectangleF16 = new RectangleF();
- }
- if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDistance.ToString()))
- {
- string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
- if (s.IndexOf(".") == -1)
- {
- for (int i = 0; i < decimalPlaces; i++)
- {
- if (i == 0)
- s += ".";
- s += "0";
- }
- }
- else
- {
- int 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);
- rectangleF17.Width = sizeF1.Width;
- rectangleF17.Height = sizeF1.Height;
- g.DrawString(s + this.unit, textfont, textbrush, rectangleF17);
- }
- else
- {
- rectangleF17 = new RectangleF();
- }
- }
- //还原为原始旋转矩阵
- g.Transform = mtxSave;
- matrix.Dispose();
- g.DrawLine(pen, new PointF((float)x0, (float)y0), new PointF((float)x01, (float)y01));
- }
- 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 = Convert.ToInt32(x0);
- y = Convert.ToInt32(y0);
- break;
- case 5:
- x = pointArray[3].X;
- y = pointArray[3].Y;
- break;
- case 6:
- x = pointArray[4].X;
- y = pointArray[4].Y;
- break;
- case 7:
- x = pointArray[5].X;
- y = pointArray[5].Y;
- break;
- case 8:
- x = Convert.ToInt32(x01);
- y = Convert.ToInt32(y01);
- 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 (GetRectanglePosition(this.rectangleF1, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 1;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF2, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 2;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF3, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 3;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF4, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 4;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF5, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 5;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF6, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 6;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF7, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 7;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF8, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 8;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF9, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 9;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF10, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 10;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF11, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 11;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF12, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 12;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF13, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 13;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF14, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 14;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF15, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 15;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF16, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 16;
- return 9;
- }
- else if (GetRectanglePosition(this.rectangleF17, point, this.rotationPoint, angle))
- {
- this.pointL = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- moveKb = 17;
- 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);
- this.rectangleF16.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- this.rectangleF17.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
- }
- pointArray[handleNumber - 1] = point;
- }
- else if (handleNumber > 4 && handleNumber < 8)
- {
- this.mouseUpPointChange = true;
- pointArray[handleNumber - 2] = point;
- }
- else if(handleNumber == 9)
- {
- point = SetOffsetAfterRotation(point, this.rotationPoint, angle);
- if (this.moveKb == 1)
- this.rectangleF1.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 2)
- this.rectangleF2.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 3)
- this.rectangleF3.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 4)
- this.rectangleF4.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 5)
- this.rectangleF5.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else 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);
- else if (this.moveKb == 16)
- this.rectangleF16.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- else if (this.moveKb == 17)
- this.rectangleF17.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
- this.pointL = point;
- }
- else if(handleNumber == 4)
- {
- this.mouseUpPointChange = true;
- for (int i = 0; i < 3; i++)
- {
- PointF pointF1 = pointArray[i];
- pointF1.X += point.X - (float)x0;
- pointF1.Y += point.Y - (float)y0;
- pointArray[i] = pointF1;
- }
- }
- else if (handleNumber == 8)
- {
- this.mouseUpPointChange = true;
- for (int i = 3; i < 6; i++)
- {
- PointF pointF1 = pointArray[i];
- pointF1.X += point.X - (float)x01;
- pointF1.Y += point.Y - (float)y01;
- pointArray[i] = pointF1;
- }
- }
- }
- public override void Move(int deltaX, int deltaY)
- {
- int x = ISurfaceBox.UnscaleScalar(deltaX);
- int y = ISurfaceBox.UnscaleScalar(deltaY);
- for (int i = 0; i < 6; i++)
- {
- pointArray[i] = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY));
- }
- this.startPoint = pointArray[0];
- pointL.X += x;
- pointL.Y += y;
- this.rectangleF1.Offset(x, y);
- this.rectangleF2.Offset(x, y);
- this.rectangleF3.Offset(x, y);
- this.rectangleF4.Offset(x, y);
- this.rectangleF5.Offset(x, y);
- this.rectangleF6.Offset(x, y);
- this.rectangleF7.Offset(x, y);
- this.rectangleF8.Offset(x, y);
- this.rectangleF9.Offset(x, y);
- this.rectangleF10.Offset(x, y);
- this.rectangleF11.Offset(x, y);
- this.rectangleF12.Offset(x, y);
- this.rectangleF13.Offset(x, y);
- this.rectangleF14.Offset(x, y);
- this.rectangleF15.Offset(x, y);
- this.rectangleF16.Offset(x, y);
- this.rectangleF17.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 >= 6)
- {
- SolidBrush brush = new SolidBrush(Color.Black);
- for (int i = 1; i <= 8; i++)
- {
- if (i == 1) brush = new SolidBrush(Color.Green);
- else if (i == 2) brush = new SolidBrush(Color.Blue);
- else if (i == 3) brush = new SolidBrush(Color.Yellow);
- else if (i == 5) brush = new SolidBrush(Color.Green);
- else if (i == 6) brush = new SolidBrush(Color.Blue);
- else if (i == 7) brush = new SolidBrush(Color.Yellow);
- else if (i == 9) brush = new SolidBrush(Color.Transparent);
- else brush = new SolidBrush(Color.Black);
- g.FillRectangle(brush, GetHandleRectangle(i));
- }
- brush.Dispose();
- RectangleF r = GetBoundingBox();
- }
- }
- public override List<PointF> GetPoints()
- {
- return pointArray;
- }
- public override ParentStyleModel GetStyle()
- {
- return measureCenterCenterSize;
- }
- }
- }
|