PatternBrickExporter.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System.Collections.Generic;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4. using DevExpress.XtraPrinting;
  5. using DevExpress.XtraPrinting.BrickExporters;
  6. namespace CustomControls.Pattern
  7. {
  8. /// <summary>
  9. /// 图像绘制
  10. /// </summary>
  11. public class PatternBrickExporter : PanelBrickExporter
  12. {
  13. private PatternBrick PatternBrick => Brick as PatternBrick;
  14. public override void Draw(IGraphics gr, RectangleF rect, RectangleF parentRect)
  15. {
  16. base.Draw(gr, rect, parentRect);
  17. /* 获取控件位置 */
  18. var location = rect.Location;
  19. /* 记录文本控件和控件高度 */
  20. var fontHeigh = PatternBrick.FontHeight;
  21. /* 根据花型坐标绘制连线 */
  22. if (PatternBrick.LeftCodePointFs.Count > 1) { DrawConnectionLine(gr, fontHeigh, location, PatternBrick.LeftCodePointFs); }
  23. if (PatternBrick.MiddleCodePointFs.Count > 1) { DrawConnectionLine(gr, fontHeigh, location, PatternBrick.MiddleCodePointFs); }
  24. if (PatternBrick.SurplusCodePointFs.Count > 1) { DrawConnectionLine(gr, fontHeigh, location, PatternBrick.SurplusCodePointFs); }
  25. if (PatternBrick.RightCodePointFs.Count > 1) { DrawConnectionLine(gr, fontHeigh, location, PatternBrick.RightCodePointFs); }
  26. /* 绘制各个花型间隔线 */
  27. var controlWidth = PatternBrick.FontHeight;
  28. var lowestY = PatternBrick.CountFs.Y;
  29. DrawVerticalLine(gr, new PointF(location.X + 20f, location.Y), new PointF(location.X + 20f, location.Y + lowestY));
  30. List<PointF> pointFs = new List<PointF>();
  31. if (PatternBrick.LeftCodePointFs.Count > 0)
  32. {
  33. var fs = PatternBrick.LeftCodePointFs;
  34. pointFs.Add(fs[fs.Count - 1]);
  35. }
  36. if (PatternBrick.MiddleCodePointFs.Count > 0)
  37. {
  38. var fs = PatternBrick.MiddleCodePointFs;
  39. pointFs.Add(fs[0]);
  40. pointFs.Add(fs[fs.Count - 1]);
  41. /* 绘制循环线 */
  42. var firstX = location.X + fs[0].X;
  43. var firstY = location.Y + lowestY - controlWidth;
  44. var lastX = location.X + fs[fs.Count - 1].X + controlWidth * 2f;
  45. var lastY = location.Y + lowestY - controlWidth;
  46. var firstPointF = new PointF(firstX, firstY);
  47. var lastPointF = new PointF(lastX, lastY);
  48. DrawVerticalLine(gr, firstPointF, lastPointF);
  49. /* 绘制箭头 */
  50. var leftArrowX = firstX + 15f;
  51. var leftArrowY = firstY + 10f;
  52. var rightArrowX = lastX - 15f;
  53. var rightArrowY = lastY - 10f;
  54. var leftPointF = new PointF(leftArrowX, leftArrowY);
  55. var rifhtPointF = new PointF(rightArrowX, rightArrowY);
  56. DrawVerticalLine(gr, firstPointF, leftPointF);
  57. DrawVerticalLine(gr, lastPointF, rifhtPointF);
  58. }
  59. if (PatternBrick.SurplusCodePointFs.Count > 0)
  60. {
  61. var fs = PatternBrick.SurplusCodePointFs;
  62. pointFs.Add(fs[0]);
  63. pointFs.Add(fs[fs.Count - 1]);
  64. }
  65. if (PatternBrick.RightCodePointFs.Count > 0)
  66. {
  67. var fs = PatternBrick.RightCodePointFs;
  68. pointFs.Add(fs[0]);
  69. pointFs.Add(fs[fs.Count - 1]);
  70. }
  71. for (int i = 0; i < pointFs.Count; i += 2)
  72. {
  73. float lineX;
  74. if (i + 1 < pointFs.Count - 1)
  75. {
  76. lineX = location.X + pointFs[i].X + controlWidth + (pointFs[i + 1].X - pointFs[i].X) / 2;
  77. }
  78. else
  79. {
  80. lineX = location.X + pointFs[i].X + controlWidth * 2f;
  81. }
  82. PointF pt1 = new PointF(lineX, location.Y);
  83. PointF pt2 = new PointF(lineX, lowestY);
  84. DrawVerticalLine(gr, pt1, pt2);
  85. }
  86. }
  87. /// <summary>
  88. /// 绘制连接线
  89. /// </summary>
  90. private void DrawConnectionLine(IGraphics gr, float fontHeigh, PointF location, List<PointF> codePointFs)
  91. {
  92. /* 循环绘制连线 */
  93. for (var i = 0; i < codePointFs.Count - 1; i++)
  94. {
  95. /* 设置笔刷 */
  96. var pen = BrickPaint.GetPen(Color.Black, GraphicsUnitConverter.DipToDoc(1f));
  97. /* 根据两个控件的位置高低设置起始位置 */
  98. var location1 = codePointFs[i];
  99. var location2 = codePointFs[i + 1];
  100. var pt1 = new PointF();
  101. var pt2 = new PointF();
  102. if (location1.Y < location2.Y)
  103. {
  104. pt1 = new PointF(location1.X + fontHeigh + location.X, location1.Y + fontHeigh + location.Y);
  105. pt2 = new PointF(location2.X + fontHeigh + location.X, location2.Y + location.Y);
  106. }
  107. else
  108. {
  109. pt1 = new PointF(location1.X + fontHeigh + location.X, location1.Y + location.Y);
  110. pt2 = new PointF(location2.X + fontHeigh + location.X, location2.Y + fontHeigh + location.Y);
  111. }
  112. /* 设置连线平滑 */
  113. gr.SmoothingMode = SmoothingMode.AntiAlias;
  114. gr.DrawLine(pen, pt1, pt2);
  115. }
  116. }
  117. /// <summary>
  118. /// 绘制纵向间隔线
  119. /// </summary>
  120. private void DrawVerticalLine(IGraphics gr, PointF pt1, PointF pt2)
  121. {
  122. /* 设置笔刷 */
  123. var pen = BrickPaint.GetPen(Color.Black, GraphicsUnitConverter.DipToDoc(1f));
  124. /* 设置连线平滑 */
  125. gr.SmoothingMode = SmoothingMode.AntiAlias;
  126. gr.DrawLine(pen, pt1, pt2);
  127. }
  128. }
  129. }