MeasurePointEdgeSize.cs 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. using PaintDotNet.Annotation.Enum;
  2. using PaintDotNet.Base.SettingModel;
  3. using PaintDotNet.Base.CommTool;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. using System.Linq;
  9. using System.Windows.Forms;
  10. namespace PaintDotNet.Annotation.Measure
  11. {
  12. using PointList = List<PointF>;
  13. /// <summary>
  14. /// 测量->圆->点到圆距离
  15. /// </summary>
  16. public class MeasurePointEdgeSize : MeasureDrawObject
  17. {
  18. /// <summary>
  19. /// 点集合
  20. /// </summary>
  21. public PointList pointArray;
  22. /// <summary>
  23. /// 样式
  24. /// </summary>
  25. private MeasureStyleModel.MeasurePointEdgeSize measurePointEdgeSize;
  26. /// <summary>
  27. /// 圆心横坐标
  28. /// </summary>
  29. double x0;
  30. /// <summary>
  31. /// 圆心纵坐标
  32. /// </summary>
  33. double y0;
  34. /// <summary>
  35. /// 直径
  36. /// </summary>
  37. double radius = 0;
  38. /// <summary>
  39. /// 直线与圆心的交点
  40. /// </summary>
  41. Point distantPoint;
  42. /// <summary>
  43. /// 距离
  44. /// </summary>
  45. //private double length = 0.0;
  46. private GraphicsPath areaPath = null;
  47. private Pen areaPen = null;
  48. private Region areaRegion = null;
  49. /// <summary>
  50. /// 测量信息矩形定义
  51. /// </summary>
  52. private RectangleF rectangleF1 = new RectangleF();
  53. private RectangleF rectangleF2 = new RectangleF();
  54. private RectangleF rectangleF3 = new RectangleF();
  55. private RectangleF rectangleF4 = new RectangleF();
  56. private RectangleF rectangleF5 = new RectangleF();
  57. private RectangleF rectangleF6 = new RectangleF();
  58. private RectangleF rectangleF7 = new RectangleF();
  59. private RectangleF rectangleF8 = new RectangleF();
  60. private RectangleF rectangleF9 = new RectangleF();
  61. private RectangleF rectangleF10 = new RectangleF();
  62. private RectangleF rectangleF11 = new RectangleF();
  63. private RectangleF rectangleF12 = new RectangleF();
  64. private RectangleF rectangleF13 = new RectangleF();
  65. private RectangleF rectangleF14 = new RectangleF();
  66. private RectangleF rectangleF15 = new RectangleF();
  67. private RectangleF rectangleF16 = new RectangleF();
  68. private RectangleF rectangleF17 = new RectangleF();
  69. /// <summary>
  70. /// 文本上用于拖动的点
  71. /// </summary>
  72. private Point pointL = new Point();
  73. /// <summary>
  74. /// 绘制限制(第一次绘制时)
  75. /// </summary>
  76. public bool pointChange = true;
  77. /// <summary>
  78. /// 区分移动文本
  79. /// </summary>
  80. private int moveKb;
  81. /// <summary>
  82. /// 绘制限制(从配置文件加载)
  83. /// </summary>
  84. public bool configurationFile = false;
  85. /// <summary>
  86. /// 绘制限制(更改属性时)
  87. /// </summary>
  88. private bool SavePointChange;
  89. /// <summary>
  90. /// 绘制属性
  91. /// </summary>
  92. private string[] drawingPropertiesList;
  93. /// <summary>
  94. /// 绘制属性(克隆)
  95. /// </summary>
  96. private string[] drawingPropertiesListClone;
  97. /// <summary>
  98. /// 限制绘制(绘制中)
  99. /// </summary>
  100. public bool mouseUpPointChange = false;
  101. public MeasurePointEdgeSize(ISurfaceBox surfaceBox) : base(surfaceBox)
  102. {
  103. this.objectType = DrawClass.Measure;
  104. this.drawToolType = DrawToolType.MeasurePointEdgeSize;
  105. pointArray = new PointList();
  106. Initialize();
  107. }
  108. public MeasurePointEdgeSize(ISurfaceBox surfaceBox, int x1, int y1, bool clone) : base(surfaceBox)
  109. {
  110. this.objectType = DrawClass.Measure;
  111. this.drawToolType = DrawToolType.MeasurePointEdgeSize;
  112. measurePointEdgeSize = this.ISurfaceBox.GetMeasureStyleModel().measurePointEdgeSize;
  113. pointArray = new PointList();
  114. if (clone)
  115. pointArray.Add(new Point(x1, y1));
  116. this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
  117. this.unitString = surfaceBox.GetPxPerUnit()[1];
  118. this.unit = surfaceBox.GetPxPerUnit()[2];
  119. surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);
  120. Initialize();
  121. }
  122. public MeasurePointEdgeSize(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base(surfaceBox)
  123. {
  124. this.objectType = DrawClass.Measure;
  125. this.drawToolType = DrawToolType.MeasurePointEdgeSize;
  126. this.ISurfaceBox = surfaceBox;
  127. measurePointEdgeSize = (MeasureStyleModel.MeasurePointEdgeSize)parentStyleModel;
  128. pointArray = DrawRulerHelper.DeepCopyListByReflect(points);
  129. startPoint = points[0];
  130. this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
  131. this.unitString = surfaceBox.GetPxPerUnit()[1];
  132. this.unit = surfaceBox.GetPxPerUnit()[2];
  133. surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);
  134. this.configurationFile = true;
  135. }
  136. /// <summary>
  137. /// Clone this instance
  138. /// </summary>
  139. public override DrawObject Clone()
  140. {
  141. MeasurePointEdgeSize drawPointEdgeSize = new MeasurePointEdgeSize(ISurfaceBox, (int)pointArray[0].X, (int)pointArray[0].Y, false);
  142. drawPointEdgeSize.ISurfaceBox = ISurfaceBox;
  143. foreach (PointF p in this.pointArray)
  144. {
  145. drawPointEdgeSize.pointArray.Add(p);
  146. }
  147. if (drawingPropertiesList != null)
  148. drawPointEdgeSize.drawingPropertiesListClone = drawingPropertiesList;
  149. FillDrawObjectFields(drawPointEdgeSize);
  150. return drawPointEdgeSize;
  151. }
  152. public override DrawObject Clone(ISurfaceBox surfaceBox)
  153. {
  154. MeasurePointEdgeSize drawPointEdgeSize = new MeasurePointEdgeSize(surfaceBox, this.GetPoints(), this.measurePointEdgeSize, null);
  155. if (drawingPropertiesList != null)
  156. drawPointEdgeSize.drawingPropertiesListClone = drawingPropertiesList;
  157. FillDrawObjectFields(drawPointEdgeSize);
  158. return drawPointEdgeSize;
  159. }
  160. /// <summary>
  161. /// 测量属性
  162. /// </summary>
  163. /// <returns></returns>
  164. public override Dictionary<System.Enum, object> GetData()
  165. {
  166. if (data.ContainsKey(MeasureAttributes.MeasureMethod))
  167. data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text");
  168. else
  169. data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"));
  170. if (data.ContainsKey(MeasureAttributes.MeasureUnitCN))
  171. data[MeasureAttributes.MeasureUnitCN] = this.unitString;
  172. else
  173. data.Add(MeasureAttributes.MeasureUnitCN, this.unitString);
  174. if (data.ContainsKey(MeasureAttributes.MeasureUnitEN))
  175. data[MeasureAttributes.MeasureUnitEN] = this.unit;
  176. else
  177. data.Add(MeasureAttributes.MeasureUnitEN, this.unit);
  178. if (data.ContainsKey(MeasureAttributes.PixelDistance))
  179. data[MeasureAttributes.PixelDistance] = Math.Round(this.length, decimalPlaces);
  180. else
  181. data.Add(MeasureAttributes.PixelDistance, Math.Round(this.length, decimalPlaces));
  182. string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
  183. if (s.IndexOf(".") == -1)
  184. {
  185. for (int i = 0; i < decimalPlaces; i++)
  186. {
  187. if (i == 0)
  188. s += ".";
  189. s += "0";
  190. }
  191. }
  192. else
  193. {
  194. int a = s.Length - s.IndexOf(".") - 1;
  195. if (a < decimalPlaces)
  196. {
  197. for (int i = 0; i < decimalPlaces - a; i++)
  198. {
  199. s += "0";
  200. }
  201. }
  202. }
  203. if (data.ContainsKey(MeasureAttributes.PhysicalDistance))
  204. data[MeasureAttributes.PhysicalDistance] = s;
  205. else
  206. data.Add(MeasureAttributes.PhysicalDistance, s);
  207. if (data.ContainsKey(MeasureAttributes.PixelArea))
  208. data[MeasureAttributes.PixelArea] = Math.Round(Math.PI * radius / 2 * radius / 2, decimalPlaces);
  209. else
  210. data.Add(MeasureAttributes.PixelArea, Math.Round(Math.PI * radius / 2 * radius / 2, decimalPlaces));
  211. s = Math.Round(Math.PI * radius / 2 * radius / 2 * unitLength, decimalPlaces).ToString();
  212. if (s.IndexOf(".") == -1)
  213. {
  214. for (int i = 0; i < decimalPlaces; i++)
  215. {
  216. if (i == 0)
  217. s += ".";
  218. s += "0";
  219. }
  220. }
  221. else
  222. {
  223. int a = s.Length - s.IndexOf(".") - 1;
  224. if (a < decimalPlaces)
  225. {
  226. for (int i = 0; i < decimalPlaces - a; i++)
  227. {
  228. s += "0";
  229. }
  230. }
  231. }
  232. if (data.ContainsKey(MeasureAttributes.PhysicalArea))
  233. data[MeasureAttributes.PhysicalArea] = s;
  234. else
  235. data.Add(MeasureAttributes.PhysicalArea, s);
  236. if (data.ContainsKey(MeasureAttributes.PixelCircumference))
  237. data[MeasureAttributes.PixelCircumference] = Math.Round(Math.PI * radius , decimalPlaces);
  238. else
  239. data.Add(MeasureAttributes.PixelCircumference, Math.Round(Math.PI * radius, decimalPlaces));
  240. s = Math.Round(Math.PI * radius * unitLength, decimalPlaces).ToString();
  241. if (s.IndexOf(".") == -1)
  242. {
  243. for (int i = 0; i < decimalPlaces; i++)
  244. {
  245. if (i == 0)
  246. s += ".";
  247. s += "0";
  248. }
  249. }
  250. else
  251. {
  252. int a = s.Length - s.IndexOf(".") - 1;
  253. if (a < decimalPlaces)
  254. {
  255. for (int i = 0; i < decimalPlaces - a; i++)
  256. {
  257. s += "0";
  258. }
  259. }
  260. }
  261. if (data.ContainsKey(MeasureAttributes.PhysicalCircumference))
  262. data[MeasureAttributes.PhysicalCircumference] = s;
  263. else
  264. data.Add(MeasureAttributes.PhysicalCircumference, s);
  265. if (data.ContainsKey(MeasureAttributes.PixelCenterX))
  266. data[MeasureAttributes.PixelCenterX] = Math.Round(this.x0, decimalPlaces);
  267. else
  268. data.Add(MeasureAttributes.PixelCenterX, Math.Round(this.x0, decimalPlaces));
  269. if (data.ContainsKey(MeasureAttributes.PixelCenterY))
  270. data[MeasureAttributes.PixelCenterY] = Math.Round(this.y0, decimalPlaces);
  271. else
  272. data.Add(MeasureAttributes.PixelCenterY, Math.Round(this.y0, decimalPlaces));
  273. if (data.ContainsKey(MeasureAttributes.PhysicalCenterX))
  274. data[MeasureAttributes.PhysicalCenterX] = Math.Round(this.x0 * unitLength, decimalPlaces);
  275. else
  276. data.Add(MeasureAttributes.PhysicalCenterX, Math.Round(this.x0 * unitLength, decimalPlaces));
  277. if (data.ContainsKey(MeasureAttributes.PhysicalCenterY))
  278. data[MeasureAttributes.PhysicalCenterY] = Math.Round(this.y0 * unitLength, decimalPlaces);
  279. else
  280. data.Add(MeasureAttributes.PhysicalCenterY, Math.Round(this.y0 * unitLength, decimalPlaces));
  281. if (data.ContainsKey(MeasureAttributes.PixelRadius))
  282. data[MeasureAttributes.PixelRadius] = Math.Round(radius / 2, decimalPlaces);
  283. else
  284. data.Add(MeasureAttributes.PixelRadius, Math.Round(radius / 2, decimalPlaces));
  285. s = Math.Round(radius / 2 * unitLength, decimalPlaces).ToString();
  286. if (s.IndexOf(".") == -1)
  287. {
  288. for (int i = 0; i < decimalPlaces; i++)
  289. {
  290. if (i == 0)
  291. s += ".";
  292. s += "0";
  293. }
  294. }
  295. else
  296. {
  297. int a = s.Length - s.IndexOf(".") - 1;
  298. if (a < decimalPlaces)
  299. {
  300. for (int i = 0; i < decimalPlaces - a; i++)
  301. {
  302. s += "0";
  303. }
  304. }
  305. }
  306. if (data.ContainsKey(MeasureAttributes.PhysicalRadius))
  307. data[MeasureAttributes.PhysicalRadius] = s;
  308. else
  309. data.Add(MeasureAttributes.PhysicalRadius, s);
  310. if (data.ContainsKey(MeasureAttributes.PixelDiameter))
  311. data[MeasureAttributes.PixelDiameter] = Math.Round(radius, decimalPlaces);
  312. else
  313. data.Add(MeasureAttributes.PixelDiameter, Math.Round(radius, decimalPlaces));
  314. s = Math.Round(radius * unitLength, decimalPlaces).ToString();
  315. if (s.IndexOf(".") == -1)
  316. {
  317. for (int i = 0; i < decimalPlaces; i++)
  318. {
  319. if (i == 0)
  320. s += ".";
  321. s += "0";
  322. }
  323. }
  324. else
  325. {
  326. int a = s.Length - s.IndexOf(".") - 1;
  327. if (a < decimalPlaces)
  328. {
  329. for (int i = 0; i < decimalPlaces - a; i++)
  330. {
  331. s += "0";
  332. }
  333. }
  334. }
  335. if (data.ContainsKey(MeasureAttributes.PhysicalDiameter))
  336. data[MeasureAttributes.PhysicalDiameter] = s;
  337. else
  338. data.Add(MeasureAttributes.PhysicalDiameter, s);
  339. return data;
  340. }
  341. public override void Draw(Graphics g)
  342. {
  343. drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
  344. pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
  345. Color color = Color.FromArgb(this.measurePointEdgeSize.lineColor);
  346. Pen pen = new Pen(color, PenWidth);
  347. int penWidth = this.measurePointEdgeSize.lineWidth;
  348. pen.DashStyle = (DashStyle)this.measurePointEdgeSize.lineStyle;
  349. pen.Width = penWidth;
  350. Font textfont = new Font(measurePointEdgeSize.font, measurePointEdgeSize.fontSize);
  351. Brush textbrush = new SolidBrush(Color.FromArgb(measurePointEdgeSize.textColor));
  352. Pen linePen = new Pen(Color.FromArgb(measurePointEdgeSize.lineColor), measurePointEdgeSize.lineWidth);
  353. linePen.DashStyle = (DashStyle)measurePointEdgeSize.lineStyle;
  354. g.SmoothingMode = SmoothingMode.AntiAlias;
  355. if (HandleCount - 1 == 2) {
  356. g.DrawLine(linePen, pointArray[0].X, pointArray[0].Y, pointArray[1].X, pointArray[1].Y);
  357. }
  358. if (HandleCount - 1 > 2)
  359. {
  360. float x1 = pointArray[0].X;
  361. float y1 = pointArray[0].Y;
  362. float x2 = pointArray[1].X;
  363. float y2 = pointArray[1].Y;
  364. float x3 = pointArray[2].X;
  365. float y3 = pointArray[2].Y;
  366. double a = x1 - x2;
  367. double b = y1 - y2;
  368. double c = x1 - x3;
  369. double d = y1 - y3;
  370. double e = ((x1 * x1 - x2 * x2) + (y1 * y1 - y2 * y2)) / 2.0;
  371. double f = ((x1 * x1 - x3 * x3) + (y1 * y1 - y3 * y3)) / 2.0;
  372. x0 = x1;
  373. y0 = y1;
  374. double det = b * c - a * d;
  375. if (Math.Abs(det) > 0.001)
  376. {
  377. //x0,y0为计算得到的原点
  378. x0 = -(d * e - b * f) / det;
  379. y0 = -(a * f - c * e) / det;
  380. radius = Math.Round(Math.Sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) * 2, 2);
  381. }
  382. rectangle.X = Convert.ToInt32(x0 - radius / 2);
  383. rectangle.Y = Convert.ToInt32(y0 - radius / 2);
  384. rectangle.Width = Convert.ToInt32(radius);
  385. rectangle.Height = Convert.ToInt32(radius);
  386. g.DrawEllipse(pen, rectangle);
  387. if (HandleCount - 1 == 4)
  388. {
  389. if (drawingPropertiesList == null)
  390. {
  391. drawingPropertiesList = drawingPropertiesListClone;
  392. this.configurationFile = true;
  393. }
  394. SizeF sizeF1 = new SizeF();
  395. double towPointDistance = BasicCalculationHelper.GetDistance(new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), new PointF(pointArray[3].X, pointArray[3].Y), 2);
  396. double edgeSize = Math.Abs(towPointDistance - (radius / 2));
  397. double arrowAngle = BasicCalculationHelper.CalculateAngle(x0, y0, x0 - radius / 2, y0, pointArray[3].X, pointArray[3].Y);
  398. if (pointArray[3].X - x0 >= 0 && pointArray[3].Y - y0 <= 0)
  399. {
  400. arrowAngle = arrowAngle + 180;
  401. }
  402. if (pointArray[3].X - x0 >= 0 && pointArray[3].Y - y0 >= 0)
  403. {
  404. arrowAngle = arrowAngle - 180;
  405. }
  406. //Console.WriteLine("当前角度为:" + arrowAngle);
  407. distantPoint = BasicCalculationHelper.GetAnglePoint(new Point(Convert.ToInt32(x0 - radius / 2), Convert.ToInt32(y0)), new Point(Convert.ToInt32(x0), Convert.ToInt32(y0)), arrowAngle);
  408. //if (pointArray[3].X - x0 < 0)
  409. //{
  410. // distantPoint.X = Convert.ToInt32((x0 - Math.Sqrt((radius / 2) * (radius / 2) / (1 + ((y0 - pointArray[3].Y) / (x0 - pointArray[3].X)) * ((y0 - pointArray[3].Y) / (x0 - pointArray[3].X))))));
  411. // distantPoint.Y = Convert.ToInt32((pointArray[3].Y + (distantPoint.X - pointArray[3].X) * (y0 - pointArray[3].Y) / (x0 - pointArray[3].X)));
  412. //}
  413. //else
  414. //{
  415. // distantPoint.X = Convert.ToInt32((x0 + Math.Sqrt((radius / 2) * (radius / 2) / (1 + ((y0 - pointArray[3].Y) / (x0 - pointArray[3].X)) * ((y0 - pointArray[3].Y) / (x0 - pointArray[3].X))))));
  416. // distantPoint.Y = Convert.ToInt32((pointArray[3].Y + (distantPoint.X - pointArray[3].X) * (y0 - pointArray[3].Y) / (x0 - pointArray[3].X)));
  417. //}
  418. g.DrawLine(linePen, pointArray[3].X, pointArray[3].Y, distantPoint.X, distantPoint.Y);
  419. //g.DrawString(Math.Round(edgeSize * unitLength, decimalPlaces) + unit, textfont, textbrush, float.Parse(((distantPoint.X + pointArray[3].X) / 2).ToString()), float.Parse(((distantPoint.Y + pointArray[3].Y) / 2).ToString()));
  420. this.length = edgeSize;
  421. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  422. {
  423. int offsetValue = measurePointEdgeSize.fontSize + measurePointEdgeSize.fontSize / 2;
  424. int offsetValue1 = measurePointEdgeSize.lineWidth * 2 / 3;
  425. int offset = offsetValue1;
  426. this.pointL = new Point((int)pointArray[0].X, (int)pointArray[0].Y);
  427. if (drawingPropertiesList != null)
  428. {
  429. if (drawingPropertiesList.Contains(MeasureAttributes.PixelDistance.ToString()))
  430. {
  431. sizeF1 = g.MeasureString("" + Math.Round(this.length, decimalPlaces) + "px", textfont);
  432. rectangleF16.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  433. offset += offsetValue;
  434. }
  435. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDistance.ToString()))
  436. {
  437. string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
  438. if (s.IndexOf(".") == -1)
  439. {
  440. for (int i = 0; i < decimalPlaces; i++)
  441. {
  442. if (i == 0)
  443. s += ".";
  444. s += "0";
  445. }
  446. }
  447. else
  448. {
  449. int dic = s.Length - s.IndexOf(".") - 1;
  450. if (dic < decimalPlaces)
  451. {
  452. for (int i = 0; i < decimalPlaces - dic; i++)
  453. {
  454. s += "0";
  455. }
  456. }
  457. }
  458. sizeF1 = g.MeasureString(s + this.unit, textfont);
  459. rectangleF17.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  460. offset += offsetValue;
  461. }
  462. if (drawingPropertiesList.Contains(MeasureAttributes.PixelRadius.ToString()))
  463. {
  464. sizeF1 = g.MeasureString("" + Math.Round(radius / 2, decimalPlaces) + "px", textfont);
  465. rectangleF12.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  466. offset += offsetValue;
  467. }
  468. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalRadius.ToString()))
  469. {
  470. string s = Math.Round(radius / 2 * unitLength, decimalPlaces).ToString();
  471. if (s.IndexOf(".") == -1)
  472. {
  473. for (int i = 0; i < decimalPlaces; i++)
  474. {
  475. if (i == 0)
  476. s += ".";
  477. s += "0";
  478. }
  479. }
  480. else
  481. {
  482. int dic = s.Length - s.IndexOf(".") - 1;
  483. if (dic < decimalPlaces)
  484. {
  485. for (int i = 0; i < decimalPlaces - dic; i++)
  486. {
  487. s += "0";
  488. }
  489. }
  490. }
  491. sizeF1 = g.MeasureString(s + this.unit, textfont);
  492. rectangleF13.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  493. offset += offsetValue;
  494. }
  495. if (drawingPropertiesList.Contains(MeasureAttributes.PixelDiameter.ToString()))
  496. {
  497. sizeF1 = g.MeasureString("" + Math.Round(radius, decimalPlaces) + "px", textfont);
  498. rectangleF14.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  499. offset += offsetValue;
  500. }
  501. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDiameter.ToString()))
  502. {
  503. string s = Math.Round(radius * unitLength, decimalPlaces).ToString();
  504. if (s.IndexOf(".") == -1)
  505. {
  506. for (int i = 0; i < decimalPlaces; i++)
  507. {
  508. if (i == 0)
  509. s += ".";
  510. s += "0";
  511. }
  512. }
  513. else
  514. {
  515. int dic = s.Length - s.IndexOf(".") - 1;
  516. if (dic < decimalPlaces)
  517. {
  518. for (int i = 0; i < decimalPlaces - dic; i++)
  519. {
  520. s += "0";
  521. }
  522. }
  523. }
  524. sizeF1 = g.MeasureString(s + this.unit, textfont);
  525. rectangleF15.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  526. offset += offsetValue;
  527. }
  528. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
  529. {
  530. sizeF1 = g.MeasureString("" + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont);
  531. rectangleF6.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  532. offset += offsetValue;
  533. }
  534. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
  535. {
  536. string s = Math.Round(Math.PI * radius * unitLength, decimalPlaces).ToString();
  537. if (s.IndexOf(".") == -1)
  538. {
  539. for (int i = 0; i < decimalPlaces; i++)
  540. {
  541. if (i == 0)
  542. s += ".";
  543. s += "0";
  544. }
  545. }
  546. else
  547. {
  548. int dic = s.Length - s.IndexOf(".") - 1;
  549. if (dic < decimalPlaces)
  550. {
  551. for (int i = 0; i < decimalPlaces - dic; i++)
  552. {
  553. s += "0";
  554. }
  555. }
  556. }
  557. sizeF1 = g.MeasureString(s + this.unit, textfont);
  558. rectangleF7.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  559. offset += offsetValue;
  560. }
  561. if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
  562. {
  563. sizeF1 = g.MeasureString("" + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont);
  564. rectangleF4.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  565. offset += offsetValue;
  566. }
  567. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
  568. {
  569. string s = Math.Round(Math.PI * (radius / 2) * (radius / 2) * unitLength, decimalPlaces).ToString();
  570. if (s.IndexOf(".") == -1)
  571. {
  572. for (int i = 0; i < decimalPlaces; i++)
  573. {
  574. if (i == 0)
  575. s += ".";
  576. s += "0";
  577. }
  578. }
  579. else
  580. {
  581. int dic = s.Length - s.IndexOf(".") - 1;
  582. if (dic < decimalPlaces)
  583. {
  584. for (int i = 0; i < decimalPlaces - dic; i++)
  585. {
  586. s += "0";
  587. }
  588. }
  589. }
  590. sizeF1 = g.MeasureString(s + this.unit + "²", textfont);
  591. rectangleF5.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  592. offset += offsetValue;
  593. }
  594. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterX.ToString()))
  595. {
  596. sizeF1 = g.MeasureString("" + Math.Round(this.x0, decimalPlaces), textfont);
  597. rectangleF8.Width = sizeF1.Width;
  598. rectangleF8.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  599. offset += offsetValue;
  600. }
  601. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString()))
  602. {
  603. sizeF1 = g.MeasureString("" + Math.Round(this.y0, decimalPlaces), textfont);
  604. rectangleF9.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  605. offset += offsetValue;
  606. }
  607. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString()))
  608. {
  609. sizeF1 = g.MeasureString("" + Math.Round(this.x0 * unitLength, decimalPlaces), textfont);
  610. rectangleF10.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  611. offset += offsetValue;
  612. }
  613. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString()))
  614. {
  615. sizeF1 = g.MeasureString("" + Math.Round(this.y0 * unitLength, decimalPlaces), textfont);
  616. rectangleF11.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  617. offset += offsetValue;
  618. }
  619. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  620. {
  621. sizeF1 = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"), textfont);
  622. rectangleF1.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  623. offset += offsetValue;
  624. }
  625. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  626. {
  627. sizeF1 = g.MeasureString("" + this.unitString, textfont);
  628. rectangleF2.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  629. offset += offsetValue;
  630. }
  631. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  632. {
  633. sizeF1 = g.MeasureString("" + this.unit, textfont);
  634. rectangleF3.Location = new Point((int)pointArray[0].X + offsetValue1 - (int)sizeF1.Width / 2, (int)pointArray[0].Y + offset);
  635. offset += offsetValue;
  636. }
  637. }
  638. }
  639. if (drawingPropertiesList != null)
  640. {
  641. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  642. {
  643. sizeF1 = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"), textfont);
  644. rectangleF1.Width = sizeF1.Width;
  645. rectangleF1.Height = sizeF1.Height;
  646. g.DrawString("" + PdnResources.GetString("Menu.MeasureAction.CircularMeasurement.Text"), textfont, textbrush, rectangleF1);
  647. }
  648. else
  649. {
  650. rectangleF1 = new RectangleF();
  651. }
  652. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  653. {
  654. sizeF1 = g.MeasureString("" + this.unitString, textfont);
  655. rectangleF2.Width = sizeF1.Width;
  656. rectangleF2.Height = sizeF1.Height;
  657. g.DrawString("" + this.unitString, textfont, textbrush, rectangleF2);
  658. }
  659. else
  660. {
  661. rectangleF2 = new RectangleF();
  662. }
  663. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  664. {
  665. sizeF1 = g.MeasureString("" + this.unit, textfont);
  666. rectangleF3.Width = sizeF1.Width;
  667. rectangleF3.Height = sizeF1.Height;
  668. g.DrawString("" + this.unit, textfont, textbrush, rectangleF3);
  669. }
  670. else
  671. {
  672. rectangleF3 = new RectangleF();
  673. }
  674. if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
  675. {
  676. sizeF1 = g.MeasureString("" + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont);
  677. rectangleF4.Width = sizeF1.Width;
  678. rectangleF4.Height = sizeF1.Height;
  679. g.DrawString("" + Math.Round(Math.PI * (radius / 2) * (radius / 2), decimalPlaces) + "px²", textfont, textbrush, rectangleF4);
  680. }
  681. else
  682. {
  683. rectangleF4 = new RectangleF();
  684. }
  685. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
  686. {
  687. string s = Math.Round(Math.PI * (radius / 2) * (radius / 2) * unitLength, decimalPlaces).ToString();
  688. if (s.IndexOf(".") == -1)
  689. {
  690. for (int i = 0; i < decimalPlaces; i++)
  691. {
  692. if (i == 0)
  693. s += ".";
  694. s += "0";
  695. }
  696. }
  697. else
  698. {
  699. int dic = s.Length - s.IndexOf(".") - 1;
  700. if (dic < decimalPlaces)
  701. {
  702. for (int i = 0; i < decimalPlaces - dic; i++)
  703. {
  704. s += "0";
  705. }
  706. }
  707. }
  708. sizeF1 = g.MeasureString(s + this.unit + "²", textfont);
  709. rectangleF5.Width = sizeF1.Width;
  710. rectangleF5.Height = sizeF1.Height;
  711. g.DrawString(s + this.unit + "²", textfont, textbrush, rectangleF5);
  712. }
  713. else
  714. {
  715. rectangleF5 = new RectangleF();
  716. }
  717. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
  718. {
  719. sizeF1 = g.MeasureString("" + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont);
  720. rectangleF6.Width = sizeF1.Width;
  721. rectangleF6.Height = sizeF1.Height;
  722. g.DrawString("" + Math.Round(Math.PI * radius, decimalPlaces) + "px", textfont, textbrush, rectangleF6);
  723. }
  724. else
  725. {
  726. rectangleF6 = new RectangleF();
  727. }
  728. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
  729. {
  730. string s = Math.Round(Math.PI * radius * unitLength, decimalPlaces).ToString();
  731. if (s.IndexOf(".") == -1)
  732. {
  733. for (int i = 0; i < decimalPlaces; i++)
  734. {
  735. if (i == 0)
  736. s += ".";
  737. s += "0";
  738. }
  739. }
  740. else
  741. {
  742. int dic = s.Length - s.IndexOf(".") - 1;
  743. if (dic < decimalPlaces)
  744. {
  745. for (int i = 0; i < decimalPlaces - dic; i++)
  746. {
  747. s += "0";
  748. }
  749. }
  750. }
  751. sizeF1 = g.MeasureString(s + this.unit, textfont);
  752. rectangleF7.Width = sizeF1.Width;
  753. rectangleF7.Height = sizeF1.Height;
  754. g.DrawString(s + this.unit, textfont, textbrush, rectangleF7);
  755. }
  756. else
  757. {
  758. rectangleF7 = new RectangleF();
  759. }
  760. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterX.ToString()))
  761. {
  762. sizeF1 = g.MeasureString("" + Math.Round(this.x0, decimalPlaces), textfont);
  763. rectangleF8.Width = sizeF1.Width;
  764. rectangleF8.Height = sizeF1.Height;
  765. g.DrawString("" + Math.Round(this.x0, decimalPlaces), textfont, textbrush, rectangleF8);
  766. }
  767. else
  768. {
  769. rectangleF8 = new RectangleF();
  770. }
  771. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCenterY.ToString()))
  772. {
  773. sizeF1 = g.MeasureString("" + Math.Round(this.y0, decimalPlaces), textfont);
  774. rectangleF9.Width = sizeF1.Width;
  775. rectangleF9.Height = sizeF1.Height;
  776. g.DrawString("" + Math.Round(this.y0, decimalPlaces), textfont, textbrush, rectangleF9);
  777. }
  778. else
  779. {
  780. rectangleF9 = new RectangleF();
  781. }
  782. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterX.ToString()))
  783. {
  784. sizeF1 = g.MeasureString("" + Math.Round(this.x0 * unitLength, decimalPlaces), textfont);
  785. rectangleF10.Width = sizeF1.Width;
  786. rectangleF10.Height = sizeF1.Height;
  787. g.DrawString("" + Math.Round(this.x0 * unitLength, decimalPlaces), textfont, textbrush, rectangleF10);
  788. }
  789. else
  790. {
  791. rectangleF10 = new RectangleF();
  792. }
  793. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCenterY.ToString()))
  794. {
  795. sizeF1 = g.MeasureString("" + Math.Round(this.y0 * unitLength, decimalPlaces), textfont);
  796. rectangleF11.Width = sizeF1.Width;
  797. rectangleF11.Height = sizeF1.Height;
  798. g.DrawString("" + Math.Round(this.y0 * unitLength, decimalPlaces), textfont, textbrush, rectangleF11);
  799. }
  800. else
  801. {
  802. rectangleF11 = new RectangleF();
  803. }
  804. if (drawingPropertiesList.Contains(MeasureAttributes.PixelRadius.ToString()))
  805. {
  806. sizeF1 = g.MeasureString("" + Math.Round(radius / 2, decimalPlaces) + "px", textfont);
  807. rectangleF12.Width = sizeF1.Width;
  808. rectangleF12.Height = sizeF1.Height;
  809. g.DrawString("" + Math.Round(radius / 2, decimalPlaces) + "px", textfont, textbrush, rectangleF12);
  810. }
  811. else
  812. {
  813. rectangleF12 = new RectangleF();
  814. }
  815. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalRadius.ToString()))
  816. {
  817. string s = Math.Round(radius / 2 * unitLength, decimalPlaces).ToString();
  818. if (s.IndexOf(".") == -1)
  819. {
  820. for (int i = 0; i < decimalPlaces; i++)
  821. {
  822. if (i == 0)
  823. s += ".";
  824. s += "0";
  825. }
  826. }
  827. else
  828. {
  829. int dic = s.Length - s.IndexOf(".") - 1;
  830. if (dic < decimalPlaces)
  831. {
  832. for (int i = 0; i < decimalPlaces - dic; i++)
  833. {
  834. s += "0";
  835. }
  836. }
  837. }
  838. sizeF1 = g.MeasureString(s + this.unit, textfont);
  839. rectangleF13.Width = sizeF1.Width;
  840. rectangleF13.Height = sizeF1.Height;
  841. g.DrawString(s + this.unit, textfont, textbrush, rectangleF13);
  842. }
  843. else
  844. {
  845. rectangleF13 = new RectangleF();
  846. }
  847. if (drawingPropertiesList.Contains(MeasureAttributes.PixelDiameter.ToString()))
  848. {
  849. sizeF1 = g.MeasureString("" + Math.Round(radius, decimalPlaces) + "px", textfont);
  850. rectangleF14.Width = sizeF1.Width;
  851. rectangleF14.Height = sizeF1.Height;
  852. g.DrawString("" + Math.Round(radius, decimalPlaces) + "px", textfont, textbrush, rectangleF14);
  853. }
  854. else
  855. {
  856. rectangleF14 = new RectangleF();
  857. }
  858. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDiameter.ToString()))
  859. {
  860. string s = Math.Round(radius * unitLength, decimalPlaces).ToString();
  861. if (s.IndexOf(".") == -1)
  862. {
  863. for (int i = 0; i < decimalPlaces; i++)
  864. {
  865. if (i == 0)
  866. s += ".";
  867. s += "0";
  868. }
  869. }
  870. else
  871. {
  872. int dic = s.Length - s.IndexOf(".") - 1;
  873. if (dic < decimalPlaces)
  874. {
  875. for (int i = 0; i < decimalPlaces - dic; i++)
  876. {
  877. s += "0";
  878. }
  879. }
  880. }
  881. sizeF1 = g.MeasureString(s + this.unit, textfont);
  882. rectangleF15.Width = sizeF1.Width;
  883. rectangleF15.Height = sizeF1.Height;
  884. g.DrawString(s + this.unit, textfont, textbrush, rectangleF15);
  885. }
  886. else
  887. {
  888. rectangleF15 = new RectangleF();
  889. }
  890. if (drawingPropertiesList.Contains(MeasureAttributes.PixelDistance.ToString()))
  891. {
  892. sizeF1 = g.MeasureString("" + Math.Round(this.length, decimalPlaces) + "px", textfont);
  893. rectangleF16.Width = sizeF1.Width;
  894. rectangleF16.Height = sizeF1.Height;
  895. g.DrawString("" + Math.Round(this.length, decimalPlaces) + "px", textfont, textbrush, rectangleF16);
  896. }
  897. else
  898. {
  899. rectangleF16 = new RectangleF();
  900. }
  901. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalDistance.ToString()))
  902. {
  903. string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
  904. if (s.IndexOf(".") == -1)
  905. {
  906. for (int i = 0; i < decimalPlaces; i++)
  907. {
  908. if (i == 0)
  909. s += ".";
  910. s += "0";
  911. }
  912. }
  913. else
  914. {
  915. int dic = s.Length - s.IndexOf(".") - 1;
  916. if (dic < decimalPlaces)
  917. {
  918. for (int i = 0; i < decimalPlaces - dic; i++)
  919. {
  920. s += "0";
  921. }
  922. }
  923. }
  924. sizeF1 = g.MeasureString(s + this.unit, textfont);
  925. rectangleF17.Width = sizeF1.Width;
  926. rectangleF17.Height = sizeF1.Height;
  927. g.DrawString(s + this.unit, textfont, textbrush, rectangleF17);
  928. }
  929. else
  930. {
  931. rectangleF17 = new RectangleF();
  932. }
  933. }
  934. }
  935. }
  936. pen.Dispose();
  937. linePen.Dispose();
  938. if (this.configurationFile)
  939. this.pointChange = false;
  940. this.mouseUpAttribute = false;
  941. pointChangeObject.Remove(this.drawToolType);
  942. }
  943. /// <summary>
  944. /// 停止绘制时
  945. /// </summary>
  946. /// <param name="up"></param>
  947. public override void MouseUp(bool up)
  948. {
  949. mouseUpPointChange = up;
  950. }
  951. public void AddPoint(Point point)
  952. {
  953. pointArray.Add(point);
  954. }
  955. public override int HandleCount
  956. {
  957. get
  958. {
  959. return pointArray.Count + 1;
  960. }
  961. }
  962. /// <summary>
  963. /// Get handle pointscroll by 1-based number
  964. /// </summary>
  965. /// <param name="handleNumber"></param>
  966. /// <returns></returns>
  967. public override PointF GetHandle(int handleNumber)
  968. {
  969. float x = 0;
  970. float y = 0;
  971. switch (handleNumber)
  972. {
  973. case 1:
  974. x = pointArray[0].X;
  975. y = pointArray[0].Y;
  976. break;
  977. case 2:
  978. x = pointArray[1].X;
  979. y = pointArray[1].Y;
  980. break;
  981. case 3:
  982. x = pointArray[2].X;
  983. y = pointArray[2].Y;
  984. break;
  985. case 4:
  986. x = pointArray[3].X;
  987. y = pointArray[3].Y;
  988. break;
  989. case 5:
  990. x = distantPoint.X;
  991. y = distantPoint.Y;
  992. break;
  993. case 6:
  994. x = Convert.ToInt32(x0);
  995. y = Convert.ToInt32(y0);
  996. break;
  997. case 7:
  998. x = this.pointL.X;
  999. y = this.pointL.Y;
  1000. break;
  1001. }
  1002. return new PointF(x, y);
  1003. }
  1004. /// <summary>
  1005. /// Hit test.
  1006. /// Return value: -1 - no hit
  1007. /// 0 - hit anywhere
  1008. /// > 1 - handle number
  1009. /// </summary>
  1010. /// <param name="pointscroll"></param>
  1011. /// <returns></returns>
  1012. public override int HitTest(Point point)
  1013. {
  1014. if (Selected)
  1015. {
  1016. for (int i = 1; i <= 6; i++)
  1017. {
  1018. if (GetHandleRectangle(i).Contains(point))
  1019. return i;
  1020. }
  1021. if (this.rectangleF1.Contains(point))
  1022. {
  1023. this.pointL = point;
  1024. moveKb = 1;
  1025. return 7;
  1026. }
  1027. else if (this.rectangleF2.Contains(point))
  1028. {
  1029. this.pointL = point;
  1030. moveKb = 2;
  1031. return 7;
  1032. }
  1033. else if (this.rectangleF3.Contains(point))
  1034. {
  1035. this.pointL = point;
  1036. moveKb = 3;
  1037. return 7;
  1038. }
  1039. else if (this.rectangleF4.Contains(point))
  1040. {
  1041. this.pointL = point;
  1042. moveKb = 4;
  1043. return 7;
  1044. }
  1045. else if (this.rectangleF5.Contains(point))
  1046. {
  1047. this.pointL = point;
  1048. moveKb = 5;
  1049. return 7;
  1050. }
  1051. else if (this.rectangleF6.Contains(point))
  1052. {
  1053. this.pointL = point;
  1054. moveKb = 6;
  1055. return 7;
  1056. }
  1057. else if (this.rectangleF7.Contains(point))
  1058. {
  1059. this.pointL = point;
  1060. moveKb = 7;
  1061. return 7;
  1062. }
  1063. else if (this.rectangleF8.Contains(point))
  1064. {
  1065. this.pointL = point;
  1066. moveKb = 8;
  1067. return 7;
  1068. }
  1069. else if (this.rectangleF9.Contains(point))
  1070. {
  1071. this.pointL = point;
  1072. moveKb = 9;
  1073. return 7;
  1074. }
  1075. else if (this.rectangleF10.Contains(point))
  1076. {
  1077. this.pointL = point;
  1078. moveKb = 10;
  1079. return 7;
  1080. }
  1081. else if (this.rectangleF11.Contains(point))
  1082. {
  1083. this.pointL = point;
  1084. moveKb = 11;
  1085. return 7;
  1086. }
  1087. else if (this.rectangleF12.Contains(point))
  1088. {
  1089. this.pointL = point;
  1090. moveKb = 12;
  1091. return 7;
  1092. }
  1093. else if (this.rectangleF13.Contains(point))
  1094. {
  1095. this.pointL = point;
  1096. moveKb = 13;
  1097. return 7;
  1098. }
  1099. else if (this.rectangleF14.Contains(point))
  1100. {
  1101. this.pointL = point;
  1102. moveKb = 14;
  1103. return 7;
  1104. }
  1105. else if (this.rectangleF15.Contains(point))
  1106. {
  1107. this.pointL = point;
  1108. moveKb = 15;
  1109. return 7;
  1110. }
  1111. else if (this.rectangleF16.Contains(point))
  1112. {
  1113. this.pointL = point;
  1114. moveKb = 16;
  1115. return 7;
  1116. }
  1117. else if (this.rectangleF17.Contains(point))
  1118. {
  1119. this.pointL = point;
  1120. moveKb = 17;
  1121. return 7;
  1122. }
  1123. }
  1124. if (PointInObject(point))
  1125. return 0;
  1126. return -1;
  1127. }
  1128. protected override bool PointInObject(Point point)
  1129. {
  1130. CreateObjects();
  1131. return rectangle.Contains(point);
  1132. }
  1133. public override bool IntersectsWith(Rectangle rectangle)
  1134. {
  1135. CreateObjects();
  1136. return AreaRegion.IsVisible(rectangle);
  1137. }
  1138. protected virtual void CreateObjects()
  1139. {
  1140. if (AreaPath != null)
  1141. return;
  1142. AreaPath = new GraphicsPath();
  1143. AreaPath.AddRectangle(GetBoundingBox());
  1144. AreaPath.CloseFigure();
  1145. AreaRegion = new Region(AreaPath);
  1146. }
  1147. protected GraphicsPath AreaPath
  1148. {
  1149. get
  1150. {
  1151. return areaPath;
  1152. }
  1153. set
  1154. {
  1155. areaPath = value;
  1156. }
  1157. }
  1158. protected Region AreaRegion
  1159. {
  1160. get
  1161. {
  1162. return areaRegion;
  1163. }
  1164. set
  1165. {
  1166. areaRegion = value;
  1167. }
  1168. }
  1169. protected Pen AreaPen
  1170. {
  1171. get
  1172. {
  1173. return areaPen;
  1174. }
  1175. set
  1176. {
  1177. areaPen = value;
  1178. }
  1179. }
  1180. public override Cursor GetHandleCursor(int handleNumber)
  1181. {
  1182. return handleCursor;
  1183. }
  1184. public override void MoveHandleTo(Point point, int handleNumber)
  1185. {
  1186. if(handleNumber < 5)
  1187. {
  1188. this.mouseUpPointChange = true;
  1189. if (handleNumber == 1)
  1190. {
  1191. this.rectangleF1.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1192. this.rectangleF2.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1193. this.rectangleF3.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1194. this.rectangleF4.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1195. this.rectangleF5.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1196. this.rectangleF6.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1197. this.rectangleF7.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1198. this.rectangleF8.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1199. this.rectangleF9.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1200. this.rectangleF10.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1201. this.rectangleF11.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1202. this.rectangleF12.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1203. this.rectangleF13.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1204. this.rectangleF14.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1205. this.rectangleF15.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1206. this.rectangleF16.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1207. this.rectangleF17.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  1208. }
  1209. pointArray[handleNumber - 1] = point;
  1210. }
  1211. else if (handleNumber == 7)
  1212. {
  1213. if (this.moveKb == 1)
  1214. this.rectangleF1.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1215. else if (this.moveKb == 2)
  1216. this.rectangleF2.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1217. else if (this.moveKb == 3)
  1218. this.rectangleF3.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1219. else if (this.moveKb == 4)
  1220. this.rectangleF4.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1221. else if (this.moveKb == 5)
  1222. this.rectangleF5.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1223. else if (this.moveKb == 6)
  1224. this.rectangleF6.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1225. else if (this.moveKb == 7)
  1226. this.rectangleF7.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1227. else if (this.moveKb == 8)
  1228. this.rectangleF8.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1229. else if (this.moveKb == 9)
  1230. this.rectangleF9.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1231. else if (this.moveKb == 10)
  1232. this.rectangleF10.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1233. else if (this.moveKb == 11)
  1234. this.rectangleF11.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1235. else if (this.moveKb == 12)
  1236. this.rectangleF12.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1237. else if (this.moveKb == 13)
  1238. this.rectangleF13.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1239. else if (this.moveKb == 14)
  1240. this.rectangleF14.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1241. else if (this.moveKb == 15)
  1242. this.rectangleF15.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1243. else if (this.moveKb == 16)
  1244. this.rectangleF16.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1245. else if (this.moveKb == 17)
  1246. this.rectangleF17.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  1247. this.pointL = point;
  1248. }
  1249. }
  1250. public override void Move(int deltaX, int deltaY)
  1251. {
  1252. for (int i = 0; i < pointArray.Count; i++)
  1253. {
  1254. pointArray[i] = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY));
  1255. }
  1256. this.startPoint = pointArray[0];
  1257. int x = ISurfaceBox.UnscaleScalar(deltaX);
  1258. int y = ISurfaceBox.UnscaleScalar(deltaY);
  1259. pointL.X += x;
  1260. pointL.Y += y;
  1261. this.rectangleF1.Offset(x, y);
  1262. this.rectangleF2.Offset(x, y);
  1263. this.rectangleF3.Offset(x, y);
  1264. this.rectangleF4.Offset(x, y);
  1265. this.rectangleF5.Offset(x, y);
  1266. this.rectangleF6.Offset(x, y);
  1267. this.rectangleF7.Offset(x, y);
  1268. this.rectangleF8.Offset(x, y);
  1269. this.rectangleF9.Offset(x, y);
  1270. this.rectangleF10.Offset(x, y);
  1271. this.rectangleF11.Offset(x, y);
  1272. this.rectangleF12.Offset(x, y);
  1273. this.rectangleF13.Offset(x, y);
  1274. this.rectangleF14.Offset(x, y);
  1275. this.rectangleF15.Offset(x, y);
  1276. this.rectangleF16.Offset(x, y);
  1277. this.rectangleF17.Offset(x, y);
  1278. Invalidate();
  1279. }
  1280. /// <summary>
  1281. /// Invalidate object.
  1282. /// When object is invalidated, path used for hit test
  1283. /// is released and should be created again.
  1284. /// </summary>
  1285. protected void Invalidate()
  1286. {
  1287. if (AreaPath != null)
  1288. {
  1289. AreaPath.Dispose();
  1290. AreaPath = null;
  1291. }
  1292. if (AreaPen != null)
  1293. {
  1294. AreaPen.Dispose();
  1295. AreaPen = null;
  1296. }
  1297. if (AreaRegion != null)
  1298. {
  1299. AreaRegion.Dispose();
  1300. AreaRegion = null;
  1301. }
  1302. }
  1303. /// <summary>
  1304. /// Normalize rectangle
  1305. /// </summary>
  1306. public override void Normalize()
  1307. {
  1308. rectangle = Annotation.DrawObject.GetNormalizedRectangle(rectangle);
  1309. }
  1310. public override RectangleF GetBoundingBox()
  1311. {
  1312. Rectangle rectangle;
  1313. int minx = 0, maxx = 0, miny = 0, maxy = 0;
  1314. for (int i = 0; i < pointArray.Count; i++)
  1315. {
  1316. if (i == 0)
  1317. {
  1318. minx = maxx = (int)pointArray[i].X;
  1319. miny = maxy = (int)pointArray[i].Y;
  1320. }
  1321. else
  1322. {
  1323. if (pointArray[i].X > maxx) maxx = (int)pointArray[i].X;
  1324. if (pointArray[i].X < minx) minx = (int)pointArray[i].X;
  1325. if (pointArray[i].Y > maxy) maxy = (int)pointArray[i].Y;
  1326. if (pointArray[i].Y < miny) miny = (int)pointArray[i].Y;
  1327. }
  1328. }
  1329. rectangle = new Rectangle(minx, miny, maxx - minx, maxy - miny);
  1330. return rectangle;
  1331. }
  1332. internal void setNextPoint(Point p)
  1333. {
  1334. AddPoint(p);
  1335. }
  1336. public override void DrawTracker(Graphics g)
  1337. {
  1338. if (!Selected)
  1339. return;
  1340. if (pointArray.Count >= 4)
  1341. {
  1342. SolidBrush brush = new SolidBrush(Color.Black);
  1343. for (int i = 1; i <= 6; i++)
  1344. {
  1345. if (i == 1) brush = new SolidBrush(Color.Green);
  1346. else if (i == 2) brush = new SolidBrush(Color.Blue);
  1347. else if (i == 3) brush = new SolidBrush(Color.Yellow);
  1348. else if (i == 7) brush = new SolidBrush(Color.Transparent);
  1349. else brush = new SolidBrush(Color.Black);
  1350. g.FillRectangle(brush, GetHandleRectangle(i));
  1351. }
  1352. brush.Dispose();
  1353. RectangleF r = GetBoundingBox();
  1354. //g.DrawRectangle(new Pen(Color.White), r.X, r.Y, r.Width, r.Height);
  1355. }
  1356. }
  1357. public override List<PointF> GetPoints()
  1358. {
  1359. return pointArray;
  1360. }
  1361. public override ParentStyleModel GetStyle()
  1362. {
  1363. return measurePointEdgeSize;
  1364. }
  1365. }
  1366. }