MeasureRandSquare.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. using PaintDotNet.Base.SettingModel;
  2. using System;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Windows.Forms;
  6. using PaintDotNet.Annotation.Enum;
  7. using System.Collections.Generic;
  8. using PaintDotNet.Base.CommTool;
  9. using System.Linq;
  10. namespace PaintDotNet.Annotation.Measure
  11. {
  12. /// <summary>
  13. /// 测量->多边形测量->任意正方形
  14. /// </summary>
  15. public class MeasureRandSquare : MeasureDrawObject
  16. {
  17. /// <summary>
  18. /// 标注样式信息model
  19. /// </summary>
  20. public MeasureStyleModel.MeasureRandSquare measureRandSquare;
  21. /// <summary>
  22. /// 坐标点集合
  23. /// </summary>
  24. public List<PointF> pointArray;
  25. /// <summary>
  26. /// 第三个点
  27. /// </summary>
  28. PointF linePoint;
  29. /// <summary>
  30. /// 第四个点
  31. /// </summary>
  32. PointF linePoint1;
  33. /// <summary>
  34. /// 中心点
  35. /// </summary>
  36. PointF centerPoint;
  37. /// <summary>
  38. /// 旋转时的最后一个点记录,用于计算角度
  39. /// </summary>
  40. PointF lastPoint;
  41. /// <summary>
  42. /// 旋转时的标记
  43. /// </summary>
  44. public bool isPress = false;
  45. /// <summary>
  46. /// 重新计算过的外接矩形
  47. /// </summary>
  48. RectangleF largerRect;
  49. /// <summary>
  50. /// 周长
  51. /// </summary>
  52. //private double length = 0.0;
  53. /// <summary>
  54. /// 面积
  55. /// </summary>
  56. private double area = 0.0;
  57. /// <summary>
  58. /// 测量信息矩形定义
  59. /// </summary>
  60. private RectangleF rectangleF1 = new RectangleF();
  61. private RectangleF rectangleF2 = new RectangleF();
  62. private RectangleF rectangleF3 = new RectangleF();
  63. private RectangleF rectangleF4 = new RectangleF();
  64. private RectangleF rectangleF5 = new RectangleF();
  65. private RectangleF rectangleF6 = new RectangleF();
  66. private RectangleF rectangleF7 = new RectangleF();
  67. private RectangleF rectangleF8 = new RectangleF();
  68. private RectangleF rectangleF9 = new RectangleF();
  69. private RectangleF rectangleF10 = new RectangleF();
  70. private RectangleF rectangleF11 = new RectangleF();
  71. /// <summary>
  72. /// 文本上用于拖动的点
  73. /// </summary>
  74. private Point pointL = new Point();
  75. /// <summary>
  76. /// 绘制限制(第一次绘制时)
  77. /// </summary>
  78. public bool pointChange = true;
  79. /// <summary>
  80. /// 区分移动文本
  81. /// </summary>
  82. private int moveKb;
  83. /// <summary>
  84. /// 绘制限制(从配置文件加载)
  85. /// </summary>
  86. public bool configurationFile = false;
  87. /// <summary>
  88. /// 绘制限制(更改属性时)
  89. /// </summary>
  90. private bool SavePointChange;
  91. /// <summary>
  92. /// 绘制属性
  93. /// </summary>
  94. private string[] drawingPropertiesList;
  95. /// <summary>
  96. /// 绘制属性(克隆)
  97. /// </summary>
  98. private string[] drawingPropertiesListClone;
  99. private bool drawing;
  100. /// <summary>
  101. /// 旋转角度
  102. /// </summary>
  103. private double angle;
  104. /// <summary>
  105. /// 绘制点
  106. /// </summary>
  107. private PointF PointF = new PointF();
  108. /// <summary>
  109. /// 是否移动了鼠标
  110. /// </summary>
  111. public bool moved = false;
  112. /// <summary>
  113. /// 限制绘制(绘制中)
  114. /// </summary>
  115. public bool mouseUpPointChange = false;
  116. public MeasureRandSquare(ISurfaceBox surfaceBox, int x1, int y1, int x2, int y2, bool clone) : base()
  117. {
  118. this.objectType = DrawClass.Measure;
  119. this.drawToolType = DrawToolType.MeasureRandSquare;
  120. this.pointArray = new List<PointF>();
  121. this.measureRandSquare = surfaceBox.GetMeasureStyleModel().measureRandSquare;
  122. this.startPoint.X = x1;
  123. this.startPoint.Y = y1;
  124. this.endPoint.X = x2;
  125. this.endPoint.Y = y2;
  126. if (clone)
  127. {
  128. drawing = true;
  129. this.pointArray.Add(this.startPoint);
  130. this.pointArray.Add(this.endPoint);
  131. }
  132. this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
  133. this.unitString = surfaceBox.GetPxPerUnit()[1];
  134. this.unit = surfaceBox.GetPxPerUnit()[2];
  135. surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);
  136. }
  137. /// <summary>
  138. /// 测量属性
  139. /// </summary>
  140. /// <returns></returns>
  141. public override Dictionary<System.Enum, object> GetData()
  142. {
  143. if (data.ContainsKey(MeasureAttributes.MeasureMethod))
  144. data[MeasureAttributes.MeasureMethod] = PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text");
  145. else
  146. data.Add(MeasureAttributes.MeasureMethod, PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"));
  147. if (data.ContainsKey(MeasureAttributes.MeasureUnitCN))
  148. data[MeasureAttributes.MeasureUnitCN] = this.unitString;
  149. else
  150. data.Add(MeasureAttributes.MeasureUnitCN, this.unitString);
  151. if (data.ContainsKey(MeasureAttributes.MeasureUnitEN))
  152. data[MeasureAttributes.MeasureUnitEN] = this.unit;
  153. else
  154. data.Add(MeasureAttributes.MeasureUnitEN, this.unit);
  155. if (data.ContainsKey(MeasureAttributes.PixelStartX))
  156. data[MeasureAttributes.PixelStartX] = startPoint.X;
  157. else
  158. data.Add(MeasureAttributes.PixelStartX, startPoint.X);
  159. if (data.ContainsKey(MeasureAttributes.PixelStartY))
  160. data[MeasureAttributes.PixelStartY] = startPoint.Y;
  161. else
  162. data.Add(MeasureAttributes.PixelStartY, startPoint.Y);
  163. if (data.ContainsKey(MeasureAttributes.PhysicalStartX))
  164. data[MeasureAttributes.PhysicalStartX] = Math.Round(startPoint.X * unitLength, decimalPlaces);
  165. else
  166. data.Add(MeasureAttributes.PhysicalStartX, Math.Round(startPoint.X * unitLength, decimalPlaces));
  167. if (data.ContainsKey(MeasureAttributes.PhysicalStartY))
  168. data[MeasureAttributes.PhysicalStartY] = Math.Round(startPoint.Y * unitLength, decimalPlaces);
  169. else
  170. data.Add(MeasureAttributes.PhysicalStartY, Math.Round(startPoint.Y * unitLength, decimalPlaces));
  171. if (data.ContainsKey(MeasureAttributes.PixelArea))
  172. data[MeasureAttributes.PixelArea] = Math.Round(area, decimalPlaces);
  173. else
  174. data.Add(MeasureAttributes.PixelArea, Math.Round(area, decimalPlaces));
  175. string s = Math.Round(this.area * unitLength, decimalPlaces).ToString();
  176. if (s.IndexOf(".") == -1)
  177. {
  178. for (int i = 0; i < decimalPlaces; i++)
  179. {
  180. if (i == 0)
  181. s += ".";
  182. s += "0";
  183. }
  184. }
  185. else
  186. {
  187. int a = s.Length - s.IndexOf(".") - 1;
  188. if (a < decimalPlaces)
  189. {
  190. for (int i = 0; i < decimalPlaces - a; i++)
  191. {
  192. s += "0";
  193. }
  194. }
  195. }
  196. if (data.ContainsKey(MeasureAttributes.PhysicalArea))
  197. data[MeasureAttributes.PhysicalArea] = s;
  198. else
  199. data.Add(MeasureAttributes.PhysicalArea, s);
  200. if (data.ContainsKey(MeasureAttributes.PixelCircumference))
  201. data[MeasureAttributes.PixelCircumference] = Math.Round(length, decimalPlaces);
  202. else
  203. data.Add(MeasureAttributes.PixelCircumference, Math.Round(length, decimalPlaces));
  204. s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
  205. if (s.IndexOf(".") == -1)
  206. {
  207. for (int i = 0; i < decimalPlaces; i++)
  208. {
  209. if (i == 0)
  210. s += ".";
  211. s += "0";
  212. }
  213. }
  214. else
  215. {
  216. int a = s.Length - s.IndexOf(".") - 1;
  217. if (a < decimalPlaces)
  218. {
  219. for (int i = 0; i < decimalPlaces - a; i++)
  220. {
  221. s += "0";
  222. }
  223. }
  224. }
  225. if (data.ContainsKey(MeasureAttributes.PhysicalCircumference))
  226. data[MeasureAttributes.PhysicalCircumference] = s;
  227. else
  228. data.Add(MeasureAttributes.PhysicalCircumference, s);
  229. return data;
  230. }
  231. public MeasureRandSquare(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
  232. {
  233. this.objectType = DrawClass.Measure;
  234. this.drawToolType = DrawToolType.MeasureRandSquare;
  235. this.ISurfaceBox = surfaceBox;
  236. measureRandSquare = (MeasureStyleModel.MeasureRandSquare)parentStyleModel;
  237. pointArray = DrawRulerHelper.DeepCopyListByReflect(points);
  238. startPoint.X = points[0].X;
  239. startPoint.Y = points[0].Y;
  240. endPoint.X = points[1].X;
  241. endPoint.Y = points[1].Y;
  242. linePoint.X = points[2].X;
  243. linePoint.Y = points[2].Y;
  244. linePoint1.X = points[3].X;
  245. linePoint1.Y = points[3].Y;
  246. CalcOtherRectangle();
  247. CalcCenter();
  248. largerRect = GetBoundingBox();
  249. this.measurementUnit = (MeasurementUnit)System.Enum.Parse(typeof(MeasurementUnit), surfaceBox.GetPxPerUnit()[0]);
  250. this.unitString = surfaceBox.GetPxPerUnit()[1];
  251. this.unit = surfaceBox.GetPxPerUnit()[2];
  252. surfaceBox.getMeasureInfo().TryGetValue(measurementUnit, out unitLength);
  253. this.configurationFile = true;
  254. this.moved = true;
  255. }
  256. /// <summary>
  257. /// Clone this instance
  258. /// </summary>
  259. public override DrawObject Clone()
  260. {
  261. MeasureRandSquare measureRandSquare = new MeasureRandSquare(ISurfaceBox, 0, 0, 0, 1, false);
  262. measureRandSquare.objectType = DrawClass.Measure;
  263. measureRandSquare.drawToolType = DrawToolType.MeasureRandSquare;
  264. measureRandSquare.ISurfaceBox = this.ISurfaceBox;
  265. foreach (PointF p in this.pointArray)
  266. {
  267. measureRandSquare.pointArray.Add(p);
  268. }
  269. measureRandSquare.startPoint = this.startPoint;
  270. measureRandSquare.endPoint = this.endPoint;
  271. measureRandSquare.linePoint = this.linePoint;
  272. measureRandSquare.linePoint1 = this.linePoint1;
  273. if (drawingPropertiesList != null)
  274. measureRandSquare.drawingPropertiesListClone = drawingPropertiesList;
  275. measureRandSquare.moved = true;
  276. FillDrawObjectFields(measureRandSquare);
  277. return measureRandSquare;
  278. }
  279. public override DrawObject Clone(ISurfaceBox surfaceBox)
  280. {
  281. MeasureRandSquare measureRandSquare = new MeasureRandSquare(surfaceBox, this.GetPoints(), this.measureRandSquare, null);
  282. if (drawingPropertiesList != null)
  283. measureRandSquare.drawingPropertiesListClone = drawingPropertiesList;
  284. measureRandSquare.moved = true;
  285. FillDrawObjectFields(measureRandSquare);
  286. return measureRandSquare;
  287. }
  288. public override void Draw(Graphics g)
  289. {
  290. if(this.moved)
  291. {
  292. drawingProperties.TryGetValue(this.drawToolType, out drawingPropertiesList);
  293. if (drawingPropertiesList == null)
  294. {
  295. drawingPropertiesList = drawingPropertiesListClone;
  296. if (!this.drawing)
  297. this.configurationFile = true;
  298. }
  299. pointChangeObject.TryGetValue(this.drawToolType, out SavePointChange);
  300. g.SmoothingMode = SmoothingMode.AntiAlias;
  301. Font textfont = new Font(this.measureRandSquare.font, this.measureRandSquare.fontSize);
  302. Brush textbrush = new SolidBrush(Color.FromArgb(this.measureRandSquare.textColor));
  303. Color color = Color.FromArgb(this.measureRandSquare.lineColor);
  304. Pen pen = new Pen(color, this.measureRandSquare.lineWidth);
  305. //Pen pen = new Pen(color, 1);
  306. pen.DashStyle = (DashStyle)this.measureRandSquare.lineStyle;
  307. Matrix mtxSave = g.Transform;
  308. Matrix matrix = g.Transform;
  309. if (pointArray.Count > 3)
  310. {
  311. SizeF sizeF = new SizeF();
  312. g.DrawLine(pen, pointArray[0].X, pointArray[0].Y, pointArray[2].X, pointArray[2].Y);
  313. g.DrawLine(pen, pointArray[2].X, pointArray[2].Y, pointArray[1].X, pointArray[1].Y);
  314. g.DrawLine(pen, pointArray[1].X, pointArray[1].Y, pointArray[3].X, pointArray[3].Y);
  315. g.DrawLine(pen, pointArray[3].X, pointArray[3].Y, pointArray[0].X, pointArray[0].Y);
  316. // 计算矩形长和宽
  317. double h = BasicCalculationHelper.GetDistance(pointArray[0], pointArray[2], 10);
  318. double w = BasicCalculationHelper.GetDistance(pointArray[0], pointArray[3], 10);
  319. length = (h + w) * 2;
  320. area = h * w;
  321. if (pointArray[0].X < pointArray[1].X && pointArray[0].X < pointArray[2].X && pointArray[0].X < pointArray[3].X)
  322. {
  323. this.PointF = pointArray[0];
  324. //计算需要旋转的角度
  325. angle = BasicCalculationHelper.Angle(pointArray[0], pointArray[2], new PointF(pointArray[0].X, pointArray[2].Y));
  326. // 画布旋转
  327. if (angle < 90)
  328. {
  329. matrix.RotateAt((float)angle, new PointF(pointArray[0].X, pointArray[0].Y));
  330. g.Transform = matrix;
  331. }
  332. else
  333. {
  334. angle = BasicCalculationHelper.Angle(pointArray[2], pointArray[0], new PointF(pointArray[2].X, pointArray[0].Y));
  335. matrix.RotateAt((float)angle, new PointF(pointArray[0].X, pointArray[0].Y));
  336. g.Transform = matrix;
  337. }
  338. }
  339. else if (pointArray[1].X < pointArray[0].X && pointArray[1].X < pointArray[2].X && pointArray[1].X < pointArray[3].X)
  340. {
  341. this.PointF = pointArray[1];
  342. //计算需要旋转的角度
  343. angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[3], new PointF(pointArray[1].X, pointArray[3].Y));
  344. // 画布旋转
  345. if (angle < 90)
  346. {
  347. matrix.RotateAt((float)angle, new PointF(pointArray[1].X, pointArray[1].Y));
  348. g.Transform = matrix;
  349. }
  350. else
  351. {
  352. angle = BasicCalculationHelper.Angle(pointArray[3], pointArray[1], new PointF(pointArray[3].X, pointArray[1].Y));
  353. matrix.RotateAt((float)angle, new PointF(pointArray[1].X, pointArray[1].Y));
  354. g.Transform = matrix;
  355. }
  356. }
  357. else if (pointArray[2].X < pointArray[0].X && pointArray[2].X < pointArray[1].X && pointArray[2].X < pointArray[3].X)
  358. {
  359. this.PointF = pointArray[2];
  360. //计算需要旋转的角度
  361. angle = BasicCalculationHelper.Angle(pointArray[2], pointArray[1], new PointF(pointArray[2].X, pointArray[1].Y));
  362. // 画布旋转
  363. if (angle < 90)
  364. {
  365. matrix.RotateAt((float)angle, new PointF(pointArray[2].X, pointArray[2].Y));
  366. g.Transform = matrix;
  367. }
  368. else
  369. {
  370. angle = BasicCalculationHelper.Angle(pointArray[1], pointArray[2], new PointF(pointArray[1].X, pointArray[2].Y));
  371. matrix.RotateAt((float)angle, new PointF(pointArray[2].X, pointArray[2].Y));
  372. g.Transform = matrix;
  373. }
  374. }
  375. else if (pointArray[3].X < pointArray[0].X && pointArray[3].X < pointArray[1].X && pointArray[3].X < pointArray[2].X)
  376. {
  377. this.PointF = pointArray[3];
  378. //计算需要旋转的角度
  379. angle = BasicCalculationHelper.Angle(pointArray[3], pointArray[0], new PointF(pointArray[3].X, pointArray[0].Y));
  380. // 画布旋转
  381. if (angle < 90)
  382. {
  383. matrix.RotateAt((float)angle, new PointF(pointArray[3].X, pointArray[3].Y));
  384. g.Transform = matrix;
  385. }
  386. else
  387. {
  388. angle = BasicCalculationHelper.Angle(pointArray[0], pointArray[3], new PointF(pointArray[0].X, pointArray[3].Y));
  389. matrix.RotateAt((float)angle, new PointF(pointArray[3].X, pointArray[3].Y));
  390. g.Transform = matrix;
  391. }
  392. }
  393. // 是否绘制
  394. if (this.pointChange || this.SavePointChange || this.mouseUpPointChange || this.mouseUpAttribute)
  395. {
  396. // 属性文本的间隔定义
  397. int offsetValue = measureRandSquare.fontSize + measureRandSquare.fontSize / 2;
  398. int offsetValue1 = measureRandSquare.lineWidth * 2 / 3;
  399. int offset = offsetValue1;
  400. this.pointL = new Point((int)pointArray[0].X, (int)pointArray[0].Y);
  401. if (drawingPropertiesList != null)
  402. {
  403. // 像素周长
  404. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
  405. {
  406. sizeF = g.MeasureString("" + Math.Round(this.length, decimalPlaces) + "px", textfont);
  407. rectangleF10.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  408. offset += offsetValue;
  409. }
  410. // 物理周长
  411. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
  412. {
  413. string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
  414. if (s.IndexOf(".") == -1)
  415. {
  416. for (int i = 0; i < decimalPlaces; i++)
  417. {
  418. if (i == 0)
  419. s += ".";
  420. s += "0";
  421. }
  422. }
  423. else
  424. {
  425. int a = s.Length - s.IndexOf(".") - 1;
  426. if (a < decimalPlaces)
  427. {
  428. for (int i = 0; i < decimalPlaces - a; i++)
  429. {
  430. s += "0";
  431. }
  432. }
  433. }
  434. sizeF = g.MeasureString(s + this.unit, textfont);
  435. rectangleF11.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  436. offset += offsetValue;
  437. }
  438. // 像素面积
  439. if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
  440. {
  441. sizeF = g.MeasureString("" + Math.Round(this.area, decimalPlaces) + "px²", textfont);
  442. rectangleF8.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  443. offset += offsetValue;
  444. }
  445. // 物理面积
  446. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
  447. {
  448. string s = Math.Round(this.area * unitLength, decimalPlaces).ToString();
  449. if (s.IndexOf(".") == -1)
  450. {
  451. for (int i = 0; i < decimalPlaces; i++)
  452. {
  453. if (i == 0)
  454. s += ".";
  455. s += "0";
  456. }
  457. }
  458. else
  459. {
  460. int a = s.Length - s.IndexOf(".") - 1;
  461. if (a < decimalPlaces)
  462. {
  463. for (int i = 0; i < decimalPlaces - a; i++)
  464. {
  465. s += "0";
  466. }
  467. }
  468. }
  469. sizeF = g.MeasureString(s + this.unit + "²", textfont);
  470. rectangleF9.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  471. offset += offsetValue;
  472. }
  473. // 测量方式
  474. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  475. {
  476. sizeF = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"), textfont);
  477. rectangleF1.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  478. offset += offsetValue;
  479. }
  480. // 测量单位(中文)
  481. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  482. {
  483. sizeF = g.MeasureString("" + this.unitString, textfont);
  484. rectangleF2.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  485. offset += offsetValue;
  486. }
  487. // 测量单位(英文)
  488. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  489. {
  490. sizeF = g.MeasureString("" + this.unit, textfont);
  491. rectangleF3.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  492. offset += offsetValue;
  493. }
  494. // 像素起始点X
  495. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
  496. {
  497. sizeF = g.MeasureString("" + startPoint.X, textfont);
  498. rectangleF4.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  499. offset += offsetValue;
  500. }
  501. // 像素起始点Y
  502. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
  503. {
  504. sizeF = g.MeasureString("" + startPoint.Y, textfont);
  505. rectangleF5.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  506. offset += offsetValue;
  507. }
  508. // 物理起始点X
  509. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
  510. {
  511. sizeF = g.MeasureString("" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont);
  512. rectangleF6.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  513. offset += offsetValue;
  514. }
  515. // 物理起始点Y
  516. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
  517. {
  518. sizeF = g.MeasureString("" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont);
  519. rectangleF7.Location = new Point((int)this.PointF.X + offsetValue1 - (int)sizeF.Width / 2, (int)this.PointF.Y + offset);
  520. offset += offsetValue;
  521. }
  522. }
  523. }
  524. if (drawingPropertiesList != null)
  525. {
  526. // 测量方式
  527. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureMethod.ToString()))
  528. {
  529. sizeF = g.MeasureString("" + PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"), textfont);
  530. rectangleF1.Width = sizeF.Width;
  531. rectangleF1.Height = sizeF.Height;
  532. g.DrawString("" + PdnResources.GetString("Menu.MeasureAction.PolygonMeasurement.Text"), textfont, textbrush, rectangleF1);
  533. }
  534. else
  535. {
  536. rectangleF1 = new RectangleF();
  537. }
  538. // 测量单位(中文)
  539. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitCN.ToString()))
  540. {
  541. sizeF = g.MeasureString("" + this.unitString, textfont);
  542. rectangleF2.Width = sizeF.Width;
  543. rectangleF2.Height = sizeF.Height;
  544. g.DrawString("" + this.unitString, textfont, textbrush, rectangleF2);
  545. }
  546. else
  547. {
  548. rectangleF2 = new RectangleF();
  549. }
  550. // 测量单位(英文)
  551. if (drawingPropertiesList.Contains(MeasureAttributes.MeasureUnitEN.ToString()))
  552. {
  553. sizeF = g.MeasureString("" + this.unit, textfont);
  554. rectangleF3.Width = sizeF.Width;
  555. rectangleF3.Height = sizeF.Height;
  556. g.DrawString("" + this.unit, textfont, textbrush, rectangleF3);
  557. }
  558. else
  559. {
  560. rectangleF3 = new RectangleF();
  561. }
  562. // 像素起始点X
  563. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartX.ToString()))
  564. {
  565. sizeF = g.MeasureString("" + startPoint.X, textfont);
  566. rectangleF4.Width = sizeF.Width;
  567. rectangleF4.Height = sizeF.Height;
  568. g.DrawString("" + startPoint.X, textfont, textbrush, rectangleF4);
  569. }
  570. else
  571. {
  572. rectangleF4 = new RectangleF();
  573. }
  574. // 像素起始点Y
  575. if (drawingPropertiesList.Contains(MeasureAttributes.PixelStartY.ToString()))
  576. {
  577. sizeF = g.MeasureString("" + startPoint.Y, textfont);
  578. rectangleF5.Width = sizeF.Width;
  579. rectangleF5.Height = sizeF.Height;
  580. g.DrawString("" + startPoint.Y, textfont, textbrush, rectangleF5);
  581. }
  582. else
  583. {
  584. rectangleF5 = new RectangleF();
  585. }
  586. // 物理起始点X
  587. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartX.ToString()))
  588. {
  589. sizeF = g.MeasureString("" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont);
  590. rectangleF6.Width = sizeF.Width;
  591. rectangleF6.Height = sizeF.Height;
  592. g.DrawString("" + Math.Round(startPoint.X * unitLength, decimalPlaces), textfont, textbrush, rectangleF6);
  593. }
  594. else
  595. {
  596. rectangleF6 = new RectangleF();
  597. }
  598. // 物理起始点Y
  599. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalStartY.ToString()))
  600. {
  601. sizeF = g.MeasureString("" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont);
  602. rectangleF7.Width = sizeF.Width;
  603. rectangleF7.Height = sizeF.Height;
  604. g.DrawString("" + Math.Round(startPoint.Y * unitLength, decimalPlaces), textfont, textbrush, rectangleF7);
  605. }
  606. else
  607. {
  608. rectangleF7 = new RectangleF();
  609. }
  610. // 像素面积
  611. if (drawingPropertiesList.Contains(MeasureAttributes.PixelArea.ToString()))
  612. {
  613. sizeF = g.MeasureString("" + Math.Round(this.area, decimalPlaces) + "px²", textfont);
  614. rectangleF8.Width = sizeF.Width;
  615. rectangleF8.Height = sizeF.Height;
  616. g.DrawString("" + Math.Round(this.area, decimalPlaces) + "px²", textfont, textbrush, rectangleF8);
  617. }
  618. else
  619. {
  620. rectangleF8 = new RectangleF();
  621. }
  622. // 物理面积
  623. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalArea.ToString()))
  624. {
  625. string s = Math.Round(this.area * unitLength, decimalPlaces).ToString();
  626. if (s.IndexOf(".") == -1)
  627. {
  628. for (int i = 0; i < decimalPlaces; i++)
  629. {
  630. if (i == 0)
  631. s += ".";
  632. s += "0";
  633. }
  634. }
  635. else
  636. {
  637. int a = s.Length - s.IndexOf(".") - 1;
  638. if (a < decimalPlaces)
  639. {
  640. for (int i = 0; i < decimalPlaces - a; i++)
  641. {
  642. s += "0";
  643. }
  644. }
  645. }
  646. sizeF = g.MeasureString(s + this.unit + "²", textfont);
  647. rectangleF9.Width = sizeF.Width;
  648. rectangleF9.Height = sizeF.Height;
  649. g.DrawString(s + this.unit + "²", textfont, textbrush, rectangleF9);
  650. }
  651. else
  652. {
  653. rectangleF9 = new RectangleF();
  654. }
  655. // 像素周长
  656. if (drawingPropertiesList.Contains(MeasureAttributes.PixelCircumference.ToString()))
  657. {
  658. sizeF = g.MeasureString("" + Math.Round(this.length, decimalPlaces) + "px", textfont);
  659. rectangleF10.Width = sizeF.Width;
  660. rectangleF10.Height = sizeF.Height;
  661. g.DrawString("" + Math.Round(this.length, decimalPlaces) + "px", textfont, textbrush, rectangleF10);
  662. }
  663. else
  664. {
  665. rectangleF10 = new RectangleF();
  666. }
  667. // 物理周长
  668. if (drawingPropertiesList.Contains(MeasureAttributes.PhysicalCircumference.ToString()))
  669. {
  670. string s = Math.Round(this.length * unitLength, decimalPlaces).ToString();
  671. if (s.IndexOf(".") == -1)
  672. {
  673. for (int i = 0; i < decimalPlaces; i++)
  674. {
  675. if (i == 0)
  676. s += ".";
  677. s += "0";
  678. }
  679. }
  680. else
  681. {
  682. int a = s.Length - s.IndexOf(".") - 1;
  683. if (a < decimalPlaces)
  684. {
  685. for (int i = 0; i < decimalPlaces - a; i++)
  686. {
  687. s += "0";
  688. }
  689. }
  690. }
  691. sizeF = g.MeasureString(s + this.unit, textfont);
  692. rectangleF11.Width = sizeF.Width;
  693. rectangleF11.Height = sizeF.Height;
  694. g.DrawString(s + this.unit, textfont, textbrush, rectangleF11);
  695. }
  696. else
  697. {
  698. rectangleF11 = new RectangleF();
  699. }
  700. //还原为原始旋转矩阵
  701. g.Transform = mtxSave;
  702. }
  703. }
  704. matrix.Dispose();
  705. if (this.configurationFile)
  706. this.pointChange = false;
  707. this.mouseUpAttribute = false;
  708. pointChangeObject.Remove(this.drawToolType);
  709. }
  710. }
  711. /// <summary>
  712. /// 停止绘制时
  713. /// </summary>
  714. /// <param name="up"></param>
  715. public override void MouseUp(bool up)
  716. {
  717. mouseUpPointChange = up;
  718. }
  719. public void CalcCenter()
  720. {
  721. centerPoint = new PointF(rectangle.X + rectangle.Width / 2, rectangle.Y + rectangle.Height / 2);//中心点
  722. }
  723. public override int HandleCount
  724. {
  725. get
  726. {
  727. return 7;
  728. }
  729. }
  730. /// <summary>
  731. /// Get handle pointscroll by 1-based number
  732. /// </summary>
  733. /// <param name="handleNumber"></param>
  734. /// <returns></returns>
  735. public override PointF GetHandle(int handleNumber)
  736. {
  737. float x = 0;
  738. float y = 0;
  739. switch (handleNumber)
  740. {
  741. case 1:
  742. x = (int)pointArray[0].X;
  743. y = (int)pointArray[0].Y;
  744. break;
  745. case 2:
  746. x = (int)pointArray[1].X;
  747. y = (int)pointArray[1].Y;
  748. break;
  749. case 3:
  750. x = largerRect.X;
  751. y = largerRect.Y;
  752. break;
  753. case 4:
  754. x = largerRect.Right;
  755. y = largerRect.Y;
  756. break;
  757. case 5:
  758. x = largerRect.Right;
  759. y = largerRect.Bottom;
  760. break;
  761. case 6:
  762. x = largerRect.X;
  763. y = largerRect.Bottom;
  764. break;
  765. case 7:
  766. x = this.pointL.X;
  767. y = this.pointL.Y;
  768. break;
  769. }
  770. return new PointF(x, y);
  771. }
  772. /// <summary>
  773. /// Hit test.
  774. /// Return value: -1 - no hit
  775. /// 0 - hit anywhere
  776. /// > 1 - handle number
  777. /// </summary>
  778. /// <param name="pointscroll"></param>
  779. /// <returns></returns>
  780. public override int HitTest(Point point)
  781. {
  782. if (Selected)
  783. {
  784. for (int i = 1; i <= HandleCount; i++)
  785. {
  786. if (GetHandleRectangle(i).Contains(point))
  787. return i;
  788. }
  789. if (GetRectanglePosition(this.rectangleF1, point, this.PointF , angle))
  790. {
  791. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  792. moveKb = 1;
  793. return 7;
  794. }
  795. else if (GetRectanglePosition(this.rectangleF2, point, this.PointF , angle))
  796. {
  797. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  798. moveKb = 2;
  799. return 7;
  800. }
  801. else if (GetRectanglePosition(this.rectangleF3, point, this.PointF , angle))
  802. {
  803. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  804. moveKb = 3;
  805. return 7;
  806. }
  807. else if (GetRectanglePosition(this.rectangleF4, point, this.PointF , angle))
  808. {
  809. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  810. moveKb = 4;
  811. return 7;
  812. }
  813. else if (GetRectanglePosition(this.rectangleF5, point, this.PointF , angle))
  814. {
  815. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  816. moveKb = 5;
  817. return 7;
  818. }
  819. else if (GetRectanglePosition(this.rectangleF6, point, this.PointF , angle))
  820. {
  821. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  822. moveKb = 6;
  823. return 7;
  824. }
  825. else if (GetRectanglePosition(this.rectangleF7, point, this.PointF , angle))
  826. {
  827. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  828. moveKb = 7;
  829. return 7;
  830. }
  831. else if (GetRectanglePosition(this.rectangleF8, point, this.PointF , angle))
  832. {
  833. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  834. moveKb = 8;
  835. return 7;
  836. }
  837. else if (GetRectanglePosition(this.rectangleF9, point, this.PointF , angle))
  838. {
  839. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  840. moveKb = 9;
  841. return 7;
  842. }
  843. else if (GetRectanglePosition(this.rectangleF10, point, this.PointF , angle))
  844. {
  845. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  846. moveKb = 10;
  847. return 7;
  848. }
  849. else if (GetRectanglePosition(this.rectangleF11, point, this.PointF , angle))
  850. {
  851. this.pointL = SetOffsetAfterRotation(point, this.PointF , angle);
  852. moveKb = 11;
  853. return 7;
  854. }
  855. }
  856. if (PointInObject(point))
  857. return 0;
  858. return -1;
  859. }
  860. protected override bool PointInObject(Point point)
  861. {
  862. return largerRect.Contains(point);
  863. }
  864. public override bool IntersectsWith(Rectangle rectangle)
  865. {
  866. return largerRect.IntersectsWith(rectangle);
  867. }
  868. public override Cursor GetHandleCursor(int handleNumber)
  869. {
  870. return handleCursor;
  871. }
  872. public override void MoveHandleTo(Point point, int handleNumber)
  873. {
  874. if (handleNumber < 3)
  875. {
  876. this.mouseUpPointChange = true;
  877. switch (handleNumber)
  878. {
  879. case 1:
  880. this.rectangleF1.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  881. this.rectangleF2.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  882. this.rectangleF3.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  883. this.rectangleF4.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  884. this.rectangleF5.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  885. this.rectangleF6.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  886. this.rectangleF7.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  887. this.rectangleF8.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  888. this.rectangleF9.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  889. this.rectangleF10.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  890. this.rectangleF11.Offset(point.X - this.pointArray[0].X, point.Y - this.pointArray[0].Y);
  891. //更新第一个点
  892. startPoint = point;
  893. this.pointArray[0] = startPoint;
  894. //计算第三个点
  895. linePoint.X = (startPoint.X - startPoint.Y + endPoint.X + endPoint.Y) / 2;
  896. linePoint.Y = (startPoint.X + startPoint.Y - endPoint.X + endPoint.Y) / 2;
  897. this.pointArray[2] = linePoint;
  898. //计算第四个点
  899. linePoint1.X = (startPoint.X + startPoint.Y + endPoint.X - endPoint.Y) / 2;
  900. linePoint1.Y = (-(startPoint.X) + startPoint.Y + endPoint.X + endPoint.Y) / 2;
  901. this.pointArray[3] = linePoint1;
  902. break;
  903. case 2:
  904. endPoint = point;
  905. this.pointArray[1] = endPoint;
  906. //计算第三个点
  907. linePoint.X = (startPoint.X - startPoint.Y + endPoint.X + endPoint.Y) / 2;
  908. linePoint.Y = (startPoint.X + startPoint.Y - endPoint.X + endPoint.Y) / 2;
  909. if (this.pointArray.Count == 2)
  910. {
  911. this.pointArray.Add(linePoint);
  912. }
  913. else
  914. {
  915. this.pointArray[2] = linePoint;
  916. }
  917. //计算第四个点
  918. linePoint1.X = (startPoint.X + startPoint.Y + endPoint.X - endPoint.Y) / 2;
  919. linePoint1.Y = (-(startPoint.X) + startPoint.Y + endPoint.X + endPoint.Y) / 2;
  920. if (this.pointArray.Count == 3)
  921. {
  922. this.pointArray.Add(linePoint1);
  923. }
  924. else
  925. {
  926. this.pointArray[3] = linePoint1;
  927. }
  928. break;
  929. }
  930. if(this.pointArray.Count == 4)
  931. {
  932. CalcOtherRectangle();
  933. CalcCenter();
  934. }
  935. }
  936. else
  937. {
  938. float x = 0, y = 0;
  939. switch (handleNumber)
  940. {
  941. case 3:
  942. this.mouseUpPointChange = true;
  943. x = largerRect.X;
  944. y = largerRect.Y;
  945. break;
  946. case 4:
  947. this.mouseUpPointChange = true;
  948. x = largerRect.Right;
  949. y = largerRect.Y;
  950. break;
  951. case 5:
  952. this.mouseUpPointChange = true;
  953. x = largerRect.Right;
  954. y = largerRect.Bottom;
  955. break;
  956. case 6:
  957. this.mouseUpPointChange = true;
  958. x = largerRect.X;
  959. y = largerRect.Bottom;
  960. break;
  961. case 7:
  962. point = SetOffsetAfterRotation(point, this.PointF, angle);
  963. if (this.moveKb == 1)
  964. this.rectangleF1.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  965. else if (this.moveKb == 2)
  966. this.rectangleF2.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  967. else if (this.moveKb == 3)
  968. this.rectangleF3.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  969. else if (this.moveKb == 4)
  970. this.rectangleF4.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  971. else if (this.moveKb == 5)
  972. this.rectangleF5.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  973. else if (this.moveKb == 6)
  974. this.rectangleF6.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  975. else if (this.moveKb == 7)
  976. this.rectangleF7.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  977. else if (this.moveKb == 8)
  978. this.rectangleF8.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  979. else if (this.moveKb == 9)
  980. this.rectangleF9.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  981. else if (this.moveKb == 10)
  982. this.rectangleF10.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  983. else if (this.moveKb == 11)
  984. this.rectangleF11.Offset(point.X - this.pointL.X, point.Y - this.pointL.Y);
  985. this.pointL = point;
  986. break;
  987. }
  988. if(handleNumber != 7)
  989. {
  990. this.mouseUpPointChange = true;
  991. if (!this.isPress)
  992. {
  993. this.isPress = true;
  994. lastPoint = new PointF(x, y);
  995. }
  996. double angle = BasicCalculationHelper.CalculateAngle(centerPoint.X, centerPoint.Y, lastPoint.X, lastPoint.Y, point.X, point.Y);
  997. lastPoint = point;
  998. for (int l = 0; l < pointArray.Count; l++)
  999. {
  1000. pointArray[l] = BasicCalculationHelper.GetAnglePoint(pointArray[l], centerPoint, angle);
  1001. }
  1002. startPoint = BasicCalculationHelper.GetAnglePoint(startPoint, centerPoint, angle);
  1003. endPoint = BasicCalculationHelper.GetAnglePoint(endPoint, centerPoint, angle);
  1004. linePoint = BasicCalculationHelper.GetAnglePoint(linePoint, centerPoint, angle);
  1005. linePoint1 = BasicCalculationHelper.GetAnglePoint(linePoint1, centerPoint, angle);
  1006. CalcOtherRectangle();
  1007. }
  1008. }
  1009. }
  1010. /// <summary>
  1011. /// 计算外接矩形
  1012. /// </summary>
  1013. private void CalcOtherRectangle()
  1014. {
  1015. float[] pointX = new float[] { pointArray[0].X, pointArray[1].X, pointArray[2].X, pointArray[3].X };
  1016. rectangle.X = (int)pointX.Min();
  1017. float[] pointY = new float[] { pointArray[0].Y, pointArray[1].Y, pointArray[2].Y, pointArray[3].Y };
  1018. rectangle.Y = (int)pointY.Min();
  1019. rectangle.Width = (int)Math.Abs(pointX.Max() - pointX.Min());
  1020. rectangle.Height = (int)Math.Abs(pointY.Max() - pointY.Min());
  1021. }
  1022. /// <summary>
  1023. /// 对象移动
  1024. /// </summary>
  1025. /// <param name="deltaX"></param>
  1026. /// <param name="deltaY"></param>
  1027. public override void Move(int deltaX, int deltaY)
  1028. {
  1029. int x = ISurfaceBox.UnscaleScalar(deltaX);
  1030. int y = ISurfaceBox.UnscaleScalar(deltaY);
  1031. startPoint.X += x;
  1032. startPoint.Y += y;
  1033. endPoint.X += x;
  1034. endPoint.Y += y;
  1035. linePoint.X += x;
  1036. linePoint.Y += y;
  1037. linePoint1.X += x;
  1038. linePoint1.Y += y;
  1039. for (int i = 0; i < pointArray.Count; i++)
  1040. {
  1041. pointArray[i] = new PointF(pointArray[i].X + ISurfaceBox.UnscaleScalar(deltaX), pointArray[i].Y + ISurfaceBox.UnscaleScalar(deltaY));
  1042. }
  1043. this.startPoint = pointArray[0];
  1044. pointL.X += x;
  1045. pointL.Y += y;
  1046. this.rectangleF1.Offset(x, y);
  1047. this.rectangleF2.Offset(x, y);
  1048. this.rectangleF3.Offset(x, y);
  1049. this.rectangleF4.Offset(x, y);
  1050. this.rectangleF5.Offset(x, y);
  1051. this.rectangleF6.Offset(x, y);
  1052. this.rectangleF7.Offset(x, y);
  1053. this.rectangleF8.Offset(x, y);
  1054. this.rectangleF9.Offset(x, y);
  1055. this.rectangleF10.Offset(x, y);
  1056. this.rectangleF11.Offset(x, y);
  1057. CalcOtherRectangle();
  1058. CalcCenter();
  1059. }
  1060. public override RectangleF GetBoundingBox()
  1061. {
  1062. RectangleF temp = new RectangleF();
  1063. temp.X = rectangle.X - 10;
  1064. temp.Y = rectangle.Y - 10;
  1065. temp.Width = rectangle.Width + 20;
  1066. temp.Height = rectangle.Height + 20;
  1067. return temp;
  1068. }
  1069. /// <summary>
  1070. /// Draw tracker for selected object
  1071. /// </summary>
  1072. /// <param name="g"></param>
  1073. public override void DrawTracker(Graphics g)
  1074. {
  1075. if (!Selected)
  1076. return;
  1077. if (pointArray.Count >= 4)
  1078. {
  1079. SolidBrush brush = new SolidBrush(Color.Black);
  1080. largerRect = GetBoundingBox();
  1081. for (int i = 1; i <= HandleCount; i++)
  1082. {
  1083. if (i < 3)
  1084. {
  1085. g.FillRectangle(brush, GetHandleRectangle(i));
  1086. }
  1087. else
  1088. {
  1089. brush = new SolidBrush(Color.Red);
  1090. if (i == HandleCount)
  1091. brush = new SolidBrush(Color.Transparent);
  1092. g.FillRectangle(brush, GetHandleRectangle(i));
  1093. }
  1094. }
  1095. brush.Dispose();
  1096. //g.DrawRectangle(new Pen(Color.Black), largerRect.X, largerRect.Y, largerRect.Width, largerRect.Height);
  1097. }
  1098. }
  1099. /// <summary>
  1100. /// 获取点集合
  1101. /// </summary>
  1102. /// <returns></returns>
  1103. public override List<PointF> GetPoints()
  1104. {
  1105. return pointArray;
  1106. }
  1107. /// <summary>
  1108. /// 获取样式
  1109. /// </summary>
  1110. /// <returns></returns>
  1111. public override ParentStyleModel GetStyle()
  1112. {
  1113. return measureRandSquare;
  1114. }
  1115. }
  1116. }