MeasureVMulParallelLine.cs 59 KB

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