MeasureDiameterCircle.cs 64 KB

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