MeasureOuterCircle.cs 60 KB

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