Connection_Line.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Newtonsoft.Json;
  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.Controls;
  9. using System.Windows.Media;
  10. using System.Windows.Shapes;
  11. namespace FlowChartModule.绘制模块
  12. {
  13. public class Connection_Line
  14. {
  15. PathGeometry pathGeometry = new PathGeometry();
  16. PathFigure pathFigure = new PathFigure();
  17. BezierSegment bezierSegment = new BezierSegment();
  18. public BezierCurveModel curveModel = new BezierCurveModel();
  19. [JsonIgnore]
  20. public Path path = new Path();
  21. private Element startelement=null;
  22. private Element endelement=null;
  23. [JsonIgnore]
  24. public Element Startelement { get => startelement; set => startelement = value; }
  25. [JsonIgnore]
  26. public Element Endelement { get => endelement; set => endelement = value ; }
  27. public Connection_Line(Canvas canvas)
  28. {
  29. }
  30. public void Drewbezier(Canvas canvas)
  31. {
  32. // 绘制贝塞尔曲线
  33. path.Stroke = Brushes.Blue;
  34. path.StrokeThickness = 2;
  35. pathFigure.StartPoint = curveModel.StartPoint;
  36. bezierSegment.Point1 = curveModel.ControlPoint1;
  37. bezierSegment.Point2 = curveModel.ControlPoint2;
  38. bezierSegment.Point3 = curveModel.EndPoint;
  39. pathFigure.Segments.Add(bezierSegment);
  40. pathGeometry.Figures.Add(pathFigure);
  41. path.Data = pathGeometry;
  42. path.Tag = canvas.Children.Count;
  43. canvas.Children.Add(path);
  44. }
  45. public void DrewbezierRef(Canvas canvas)
  46. {
  47. // 绘制贝塞尔曲线
  48. canvas.Children.Remove(path);
  49. pathGeometry = new PathGeometry();
  50. pathFigure = new PathFigure();
  51. bezierSegment = new BezierSegment();
  52. path.Stroke = Brushes.Blue;
  53. path.StrokeThickness = 2;
  54. pathFigure.StartPoint = curveModel.StartPoint;
  55. bezierSegment.Point1 = curveModel.ControlPoint1;
  56. bezierSegment.Point2 = curveModel.ControlPoint2;
  57. bezierSegment.Point3 = curveModel.EndPoint;
  58. pathFigure.Segments.Add(bezierSegment);
  59. pathGeometry.Figures.Add(pathFigure);
  60. path.Data = pathGeometry;
  61. path.Tag = canvas.Children.Count;
  62. canvas.Children.Add(path);
  63. }
  64. }
  65. }