MeasureLine.cs 54 KB

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