MeasureHMulParallelLine.cs 60 KB

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