MeasurePointCenterSize.cs 63 KB

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