ArrowHelper.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. using ComPDFKit.PDFAnnotation;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Media;
  9. namespace PDF_Master.Helper
  10. {
  11. public class ArrowHelper
  12. {
  13. /// <summary>
  14. /// 是否有开始箭头
  15. /// </summary>
  16. public bool HasStartArrow
  17. {
  18. get
  19. {
  20. if (StartSharp != C_LINE_TYPE.LINETYPE_UNKNOWN && StartSharp != C_LINE_TYPE.LINETYPE_NONE)
  21. {
  22. return true;
  23. }
  24. return false;
  25. }
  26. }
  27. /// <summary>
  28. /// 开始箭头是否封闭
  29. /// </summary>
  30. public bool IsStartClosed
  31. {
  32. get
  33. {
  34. if (StartSharp == C_LINE_TYPE.LINETYPE_CLOSEDARROW || StartSharp == C_LINE_TYPE.LINETYPE_RCLOSEDARROW || StartSharp == C_LINE_TYPE.LINETYPE_DIAMOND)
  35. {
  36. return true;
  37. }
  38. return false;
  39. }
  40. }
  41. /// <summary>
  42. /// 是否有结束箭头
  43. /// </summary>
  44. public bool HasEndArrow
  45. {
  46. get
  47. {
  48. if (EndSharp != C_LINE_TYPE.LINETYPE_UNKNOWN && EndSharp != C_LINE_TYPE.LINETYPE_NONE)
  49. {
  50. return true;
  51. }
  52. return false;
  53. }
  54. }
  55. /// <summary>
  56. /// 结束箭头是否封闭
  57. /// </summary>
  58. public bool IsEndClosed
  59. {
  60. get
  61. {
  62. if(EndSharp==C_LINE_TYPE.LINETYPE_CLOSEDARROW || EndSharp==C_LINE_TYPE.LINETYPE_RCLOSEDARROW || EndSharp == C_LINE_TYPE.LINETYPE_DIAMOND)
  63. {
  64. return true;
  65. }
  66. return false;
  67. }
  68. }
  69. /// <summary>
  70. /// 箭头角度
  71. /// </summary>
  72. public uint ArrowAngle { get; set; }
  73. /// <summary>
  74. /// 箭头长度
  75. /// </summary>
  76. public uint ArrowLength { get; set; }
  77. /// <summary>
  78. /// 起始点
  79. /// </summary>
  80. public Point? LineStart { get; set; }
  81. /// <summary>
  82. /// 结束点
  83. /// </summary>
  84. public Point? LineEnd { get; set; }
  85. /// <summary>
  86. /// 线段路径
  87. /// </summary>
  88. public PathGeometry Body { get; set; }
  89. /// <summary>
  90. /// 开始箭头形状
  91. /// </summary>
  92. public C_LINE_TYPE StartSharp { get; set; }
  93. /// <summary>
  94. /// 结束箭头形状
  95. /// </summary>
  96. public C_LINE_TYPE EndSharp { get; set; }
  97. /// <summary>
  98. /// 箭头帮助类
  99. /// </summary>
  100. public ArrowHelper()
  101. {
  102. Body = new PathGeometry();
  103. ArrowLength = 12;
  104. ArrowAngle = 60;
  105. }
  106. protected PathFigure CreateLineBody()
  107. {
  108. if (LineStart != null && LineEnd != null)
  109. {
  110. PathFigure lineFigure = new PathFigure();
  111. // lineFigure.IsClosed = true;
  112. lineFigure.StartPoint = (Point)LineStart;
  113. LineSegment linePath = new LineSegment();
  114. linePath.Point = (Point)LineEnd;
  115. //linePath.IsSmoothJoin = true;
  116. //linePath.IsStroked = true;
  117. lineFigure.Segments.Add(linePath);
  118. return lineFigure;
  119. }
  120. return null;
  121. }
  122. protected PathFigure CreateStartArrow()
  123. {
  124. switch (StartSharp)
  125. {
  126. case C_LINE_TYPE.LINETYPE_NONE:
  127. case C_LINE_TYPE.LINETYPE_UNKNOWN:
  128. break;
  129. case C_LINE_TYPE.LINETYPE_ARROW:
  130. case C_LINE_TYPE.LINETYPE_CLOSEDARROW:
  131. return CreateStartOpenArrow();
  132. case C_LINE_TYPE.LINETYPE_ROPENARROW:
  133. case C_LINE_TYPE.LINETYPE_RCLOSEDARROW:
  134. return CreateStartReverseArrow();
  135. case C_LINE_TYPE.LINETYPE_BUTT:
  136. return CreateStartButtArrow();
  137. case C_LINE_TYPE.LINETYPE_DIAMOND:
  138. return CreateStartDiamondArrow();
  139. case C_LINE_TYPE.LINETYPE_CIRCLE:
  140. return CreateStartRoundArrow();
  141. case C_LINE_TYPE.LINETYPE_SQUARE:
  142. return CreateStartSquareArrow();
  143. case C_LINE_TYPE.LINETYPE_SLASH:
  144. return CreateStartSlashArrow();
  145. default:
  146. break;
  147. }
  148. return null;
  149. }
  150. protected virtual PathFigure CreateEndArrow()
  151. {
  152. switch (EndSharp)
  153. {
  154. case C_LINE_TYPE.LINETYPE_NONE:
  155. case C_LINE_TYPE.LINETYPE_UNKNOWN:
  156. break;
  157. case C_LINE_TYPE.LINETYPE_ARROW:
  158. case C_LINE_TYPE.LINETYPE_CLOSEDARROW:
  159. return CreateEndOpenArrow();
  160. case C_LINE_TYPE.LINETYPE_ROPENARROW:
  161. case C_LINE_TYPE.LINETYPE_RCLOSEDARROW:
  162. return CreateEndReverseArrow();
  163. case C_LINE_TYPE.LINETYPE_BUTT:
  164. return CreateEndButtArrow();
  165. case C_LINE_TYPE.LINETYPE_DIAMOND:
  166. return CreateEndDiamondArrow();
  167. case C_LINE_TYPE.LINETYPE_CIRCLE:
  168. return CreateEndRoundArrow();
  169. case C_LINE_TYPE.LINETYPE_SQUARE:
  170. return CreateEndSquareArrow();
  171. case C_LINE_TYPE.LINETYPE_SLASH:
  172. return CreateEndSlashArrow();
  173. default:
  174. break;
  175. }
  176. return null;
  177. }
  178. /// <summary>
  179. /// 创建箭头路径
  180. /// </summary>
  181. /// <returns></returns>
  182. public PathGeometry BuildArrowBody()
  183. {
  184. Body.Figures.Clear();
  185. PathFigure lineBody = CreateLineBody();
  186. if (lineBody != null)
  187. {
  188. Body.Figures.Add(lineBody);
  189. PathFigure arrowFigure = CreateStartArrow();
  190. if (arrowFigure != null)
  191. {
  192. Body.Figures.Add(arrowFigure);
  193. }
  194. arrowFigure = CreateEndArrow();
  195. if (arrowFigure != null)
  196. {
  197. Body.Figures.Add(arrowFigure);
  198. }
  199. }
  200. return Body;
  201. }
  202. /// <summary>
  203. /// 绘制开始箭头
  204. /// </summary>
  205. /// <returns></returns>
  206. private PathFigure CreateStartOpenArrow()
  207. {
  208. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
  209. {
  210. return null;
  211. }
  212. PathFigure arrowFigure = new PathFigure();
  213. PolyLineSegment arrowSegment = new PolyLineSegment();
  214. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  215. lineVector.Normalize();
  216. lineVector *= ArrowLength;
  217. Matrix rotateMatrix = new Matrix();
  218. rotateMatrix.Rotate(ArrowAngle / 2);
  219. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  220. arrowSegment.Points.Add((Point)LineStart);
  221. rotateMatrix.Rotate(-ArrowAngle);
  222. arrowSegment.Points.Add((Point)LineStart + (lineVector * rotateMatrix));
  223. arrowFigure.Segments.Add(arrowSegment);
  224. arrowFigure.IsClosed = IsStartClosed;
  225. arrowFigure.IsFilled = IsStartClosed;
  226. return arrowFigure;
  227. }
  228. /// <summary>
  229. /// 绘制结束箭头
  230. /// </summary>
  231. /// <returns></returns>
  232. private PathFigure CreateEndOpenArrow()
  233. {
  234. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
  235. {
  236. return null;
  237. }
  238. PathFigure arrowFigure = new PathFigure();
  239. PolyLineSegment arrowSegment = new PolyLineSegment();
  240. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  241. lineVector.Normalize();
  242. lineVector *= ArrowLength;
  243. Matrix rotateMatrix = new Matrix();
  244. rotateMatrix.Rotate(ArrowAngle / 2);
  245. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  246. arrowSegment.Points.Add((Point)LineEnd);
  247. rotateMatrix.Rotate(-ArrowAngle);
  248. arrowSegment.Points.Add((Point)LineEnd + (lineVector * rotateMatrix));
  249. arrowFigure.Segments.Add(arrowSegment);
  250. arrowFigure.IsClosed = IsEndClosed;
  251. arrowFigure.IsFilled = IsEndClosed;
  252. return arrowFigure;
  253. }
  254. /// <summary>
  255. /// 绘制开始箭头(逆向)
  256. /// </summary>
  257. /// <returns></returns>
  258. private PathFigure CreateStartReverseArrow()
  259. {
  260. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
  261. {
  262. return null;
  263. }
  264. PathFigure arrowFigure = new PathFigure();
  265. PolyLineSegment arrowSegment = new PolyLineSegment();
  266. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  267. lineVector.Normalize();
  268. lineVector *= ArrowLength;
  269. Matrix rotateMatrix = new Matrix();
  270. rotateMatrix.Rotate(ArrowAngle / 2);
  271. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  272. arrowSegment.Points.Add((Point)LineStart);
  273. rotateMatrix.Rotate(-ArrowAngle);
  274. arrowSegment.Points.Add((Point)LineStart + (lineVector * rotateMatrix));
  275. arrowFigure.Segments.Add(arrowSegment);
  276. arrowFigure.IsClosed = IsStartClosed;
  277. arrowFigure.IsFilled = IsStartClosed;
  278. return arrowFigure;
  279. }
  280. /// <summary>
  281. /// 绘制结束箭头(逆向)
  282. /// </summary>
  283. /// <returns></returns>
  284. private PathFigure CreateEndReverseArrow()
  285. {
  286. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null || ArrowAngle == 0)
  287. {
  288. return null;
  289. }
  290. PathFigure arrowFigure = new PathFigure();
  291. PolyLineSegment arrowSegment = new PolyLineSegment();
  292. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  293. lineVector.Normalize();
  294. lineVector *= ArrowLength;
  295. Matrix rotateMatrix = new Matrix();
  296. rotateMatrix.Rotate(ArrowAngle / 2);
  297. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  298. arrowSegment.Points.Add((Point)LineEnd);
  299. rotateMatrix.Rotate(-ArrowAngle);
  300. arrowSegment.Points.Add((Point)LineEnd + (lineVector * rotateMatrix));
  301. arrowFigure.Segments.Add(arrowSegment);
  302. arrowFigure.IsClosed = IsEndClosed;
  303. arrowFigure.IsFilled = IsEndClosed;
  304. return arrowFigure;
  305. }
  306. /// <summary>
  307. /// 绘制开始平头
  308. /// </summary>
  309. /// <returns></returns>
  310. private PathFigure CreateStartButtArrow()
  311. {
  312. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  313. {
  314. return null;
  315. }
  316. PathFigure arrowFigure = new PathFigure();
  317. LineSegment buttSegment = new LineSegment();
  318. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  319. lineVector.Normalize();
  320. lineVector *= ArrowLength;
  321. Matrix rotateMatrix = new Matrix();
  322. rotateMatrix.Rotate(90);
  323. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  324. rotateMatrix.Rotate(-180);
  325. buttSegment.Point = ((Point)LineStart + (lineVector * rotateMatrix));
  326. arrowFigure.Segments.Add(buttSegment);
  327. return arrowFigure;
  328. }
  329. /// <summary>
  330. /// 绘制结束平头
  331. /// </summary>
  332. /// <returns></returns>
  333. private PathFigure CreateEndButtArrow()
  334. {
  335. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  336. {
  337. return null;
  338. }
  339. PathFigure arrowFigure = new PathFigure();
  340. LineSegment buttSegment = new LineSegment();
  341. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  342. lineVector.Normalize();
  343. lineVector *= ArrowLength;
  344. Matrix rotateMatrix = new Matrix();
  345. rotateMatrix.Rotate(90);
  346. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  347. rotateMatrix.Rotate(-180);
  348. buttSegment.Point = ((Point)LineEnd + (lineVector * rotateMatrix));
  349. arrowFigure.Segments.Add(buttSegment);
  350. return arrowFigure;
  351. }
  352. /// <summary>
  353. /// 绘制开始菱形
  354. /// </summary>
  355. /// <returns></returns>
  356. private PathFigure CreateStartDiamondArrow()
  357. {
  358. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  359. {
  360. return null;
  361. }
  362. PathFigure arrowFigure = new PathFigure();
  363. PolyLineSegment arrowSegment = new PolyLineSegment();
  364. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  365. lineVector.Normalize();
  366. lineVector *= ArrowLength;
  367. Matrix rotateMatrix = new Matrix();
  368. rotateMatrix.Rotate(45);
  369. Point cornerTop = (Point)LineStart + (lineVector * rotateMatrix);
  370. Vector turnVector = cornerTop - (Point)LineStart;
  371. turnVector.Normalize();
  372. turnVector *= ArrowLength;
  373. Matrix turnMatrix = new Matrix();
  374. turnMatrix.Rotate(-90);
  375. Point awayPoint = cornerTop + (turnVector * turnMatrix);
  376. rotateMatrix = new Matrix();
  377. rotateMatrix.Rotate(-45);
  378. Point cornerDown = (Point)LineStart + (lineVector * rotateMatrix);
  379. arrowFigure.StartPoint = (Point)LineStart;
  380. arrowSegment.Points.Add(cornerTop);
  381. arrowSegment.Points.Add(awayPoint);
  382. arrowSegment.Points.Add(cornerDown);
  383. arrowSegment.Points.Add((Point)LineStart);
  384. arrowFigure.Segments.Add(arrowSegment);
  385. arrowFigure.IsClosed = IsStartClosed;
  386. arrowFigure.IsFilled = IsStartClosed;
  387. return arrowFigure;
  388. }
  389. /// <summary>
  390. /// 绘制结束菱形
  391. /// </summary>
  392. /// <returns></returns>
  393. private PathFigure CreateEndDiamondArrow()
  394. {
  395. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  396. {
  397. return null;
  398. }
  399. PathFigure arrowFigure = new PathFigure();
  400. PolyLineSegment arrowSegment = new PolyLineSegment();
  401. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  402. lineVector.Normalize();
  403. lineVector *= ArrowLength;
  404. Matrix rotateMatrix = new Matrix();
  405. rotateMatrix.Rotate(45);
  406. Point cornerTop = (Point)LineEnd + (lineVector * rotateMatrix);
  407. Vector turnVector = cornerTop - (Point)LineEnd;
  408. turnVector.Normalize();
  409. turnVector *= ArrowLength;
  410. Matrix turnMatrix = new Matrix();
  411. turnMatrix.Rotate(-90);
  412. Point awayPoint = cornerTop + (turnVector * turnMatrix);
  413. rotateMatrix = new Matrix();
  414. rotateMatrix.Rotate(-45);
  415. Point cornerDown = (Point)LineEnd + (lineVector * rotateMatrix);
  416. arrowFigure.StartPoint = (Point)LineEnd;
  417. arrowSegment.Points.Add(cornerTop);
  418. arrowSegment.Points.Add(awayPoint);
  419. arrowSegment.Points.Add(cornerDown);
  420. arrowSegment.Points.Add((Point)LineEnd);
  421. arrowFigure.Segments.Add(arrowSegment);
  422. arrowFigure.IsClosed = IsEndClosed;
  423. arrowFigure.IsFilled = IsEndClosed;
  424. return arrowFigure;
  425. }
  426. /// <summary>
  427. /// 绘制开始圆形
  428. /// </summary>
  429. /// <returns></returns>
  430. private PathFigure CreateStartRoundArrow()
  431. {
  432. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  433. {
  434. return null;
  435. }
  436. PathFigure arrowFigure = new PathFigure();
  437. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  438. lineVector.Normalize();
  439. lineVector *= ArrowLength;
  440. Matrix rotateMatrix = new Matrix();
  441. rotateMatrix.Rotate(180);
  442. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  443. ArcSegment circleSegment = new ArcSegment();
  444. circleSegment.Point = (Point)LineStart;
  445. circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
  446. arrowFigure.Segments.Add(circleSegment);
  447. circleSegment = new ArcSegment();
  448. circleSegment.Point = (Point)arrowFigure.StartPoint;
  449. circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
  450. arrowFigure.Segments.Add(circleSegment);
  451. return arrowFigure;
  452. }
  453. /// <summary>
  454. /// 绘制结束圆形
  455. /// </summary>
  456. /// <returns></returns>
  457. private PathFigure CreateEndRoundArrow()
  458. {
  459. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  460. {
  461. return null;
  462. }
  463. PathFigure arrowFigure = new PathFigure();
  464. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  465. lineVector.Normalize();
  466. lineVector *= ArrowLength;
  467. Matrix rotateMatrix = new Matrix();
  468. rotateMatrix.Rotate(180);
  469. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  470. ArcSegment circleSegment = new ArcSegment();
  471. circleSegment.Point = (Point)LineEnd;
  472. circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
  473. arrowFigure.Segments.Add(circleSegment);
  474. circleSegment = new ArcSegment();
  475. circleSegment.Point = (Point)arrowFigure.StartPoint;
  476. circleSegment.Size = new Size(ArrowLength / 2, ArrowLength / 2);
  477. arrowFigure.Segments.Add(circleSegment);
  478. return arrowFigure;
  479. }
  480. /// <summary>
  481. /// 绘制开始方形
  482. /// </summary>
  483. /// <returns></returns>
  484. private PathFigure CreateStartSquareArrow()
  485. {
  486. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  487. {
  488. return null;
  489. }
  490. PathFigure arrowFigure = new PathFigure();
  491. PolyLineSegment squreSegment = new PolyLineSegment();
  492. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  493. lineVector.Normalize();
  494. lineVector *= (ArrowLength / 2);
  495. Matrix rotateMatrix = new Matrix();
  496. rotateMatrix.Rotate(90);
  497. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  498. rotateMatrix.Rotate(-180);
  499. Point pointCorner = (Point)LineStart + (lineVector * rotateMatrix);
  500. squreSegment.Points.Add(pointCorner);
  501. Vector moveVector = arrowFigure.StartPoint - pointCorner;
  502. moveVector.Normalize();
  503. moveVector *= (ArrowLength);
  504. rotateMatrix = new Matrix();
  505. rotateMatrix.Rotate(90);
  506. squreSegment.Points.Add(pointCorner + (moveVector * rotateMatrix));
  507. squreSegment.Points.Add(arrowFigure.StartPoint + (moveVector * rotateMatrix));
  508. squreSegment.Points.Add(arrowFigure.StartPoint);
  509. squreSegment.Points.Add((Point)LineStart);
  510. arrowFigure.Segments.Add(squreSegment);
  511. return arrowFigure;
  512. }
  513. /// <summary>
  514. /// 绘制结束方形
  515. /// </summary>
  516. /// <returns></returns>
  517. private PathFigure CreateEndSquareArrow()
  518. {
  519. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  520. {
  521. return null;
  522. }
  523. PathFigure arrowFigure = new PathFigure();
  524. PolyLineSegment squreSegment = new PolyLineSegment();
  525. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  526. lineVector.Normalize();
  527. lineVector *= (ArrowLength / 2);
  528. Matrix rotateMatrix = new Matrix();
  529. rotateMatrix.Rotate(90);
  530. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  531. rotateMatrix.Rotate(-180);
  532. Point pointCorner = (Point)LineEnd + (lineVector * rotateMatrix);
  533. squreSegment.Points.Add(pointCorner);
  534. Vector moveVector = arrowFigure.StartPoint - pointCorner;
  535. moveVector.Normalize();
  536. moveVector *= (ArrowLength);
  537. rotateMatrix = new Matrix();
  538. rotateMatrix.Rotate(90);
  539. squreSegment.Points.Add(pointCorner + (moveVector * rotateMatrix));
  540. squreSegment.Points.Add(arrowFigure.StartPoint + (moveVector * rotateMatrix));
  541. squreSegment.Points.Add(arrowFigure.StartPoint);
  542. squreSegment.Points.Add((Point)LineEnd);
  543. arrowFigure.Segments.Add(squreSegment);
  544. return arrowFigure;
  545. }
  546. /// <summary>
  547. /// 绘制开始斜线
  548. /// </summary>
  549. /// <returns></returns>
  550. private PathFigure CreateStartSlashArrow()
  551. {
  552. if (ArrowLength == 0 || !HasStartArrow || LineStart == null || LineEnd == null)
  553. {
  554. return null;
  555. }
  556. PathFigure arrowFigure = new PathFigure();
  557. LineSegment buttSegment = new LineSegment();
  558. Vector lineVector = (Point)LineStart - (Point)LineEnd;
  559. lineVector.Normalize();
  560. lineVector *= ArrowLength;
  561. Matrix rotateMatrix = new Matrix();
  562. rotateMatrix.Rotate(45);
  563. arrowFigure.StartPoint = (Point)LineStart + (lineVector * rotateMatrix);
  564. rotateMatrix.Rotate(-180);
  565. buttSegment.Point = ((Point)LineStart + (lineVector * rotateMatrix));
  566. arrowFigure.Segments.Add(buttSegment);
  567. return arrowFigure;
  568. }
  569. /// <summary>
  570. /// 绘制结束斜线
  571. /// </summary>
  572. /// <returns></returns>
  573. private PathFigure CreateEndSlashArrow()
  574. {
  575. if (ArrowLength == 0 || !HasEndArrow || LineStart == null || LineEnd == null)
  576. {
  577. return null;
  578. }
  579. PathFigure arrowFigure = new PathFigure();
  580. LineSegment buttSegment = new LineSegment();
  581. Vector lineVector = (Point)LineEnd - (Point)LineStart;
  582. lineVector.Normalize();
  583. lineVector *= ArrowLength;
  584. Matrix rotateMatrix = new Matrix();
  585. rotateMatrix.Rotate(45);
  586. arrowFigure.StartPoint = (Point)LineEnd + (lineVector * rotateMatrix);
  587. rotateMatrix.Rotate(-180);
  588. buttSegment.Point = ((Point)LineEnd + (lineVector * rotateMatrix));
  589. arrowFigure.Segments.Add(buttSegment);
  590. return arrowFigure;
  591. }
  592. }
  593. }