CommonHelper.cs 28 KB

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