MeasureMulVLine.cs 60 KB

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