PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Charts/Shapes/ViewportPolyBezierCurve.cs

#
C# | 98 lines | 78 code | 17 blank | 3 comment | 11 complexity | 6dde02a28464538be99fc98ed906fd88 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Research.DynamicDataDisplay.Charts.Shapes;
  6. using System.Windows.Media;
  7. using System.Windows;
  8. using Microsoft.Research.DynamicDataDisplay;
  9. using Microsoft.Research.DynamicDataDisplay.Charts.NewLine;
  10. namespace Microsoft.Research.DynamicDataDisplay.Charts.Shapes
  11. {
  12. public class ViewportPolyBezierCurve : ViewportPolylineBase
  13. {
  14. /// <summary>
  15. /// Initializes a new instance of the <see cref="ViewportPolyBezierCurve"/> class.
  16. /// </summary>
  17. public ViewportPolyBezierCurve() { }
  18. public PointCollection BezierPoints
  19. {
  20. get { return (PointCollection)GetValue(BezierPointsProperty); }
  21. set { SetValue(BezierPointsProperty, value); }
  22. }
  23. public static readonly DependencyProperty BezierPointsProperty = DependencyProperty.Register(
  24. "BezierPoints",
  25. typeof(PointCollection),
  26. typeof(ViewportPolyBezierCurve),
  27. new FrameworkPropertyMetadata(null, OnPropertyChanged));
  28. private bool buildBezierPoints = true;
  29. public bool BuildBezierPoints
  30. {
  31. get { return buildBezierPoints; }
  32. set { buildBezierPoints = value; }
  33. }
  34. bool updating = false;
  35. protected override void UpdateUIRepresentationCore()
  36. {
  37. if (updating) return;
  38. updating = true;
  39. var transform = Plotter.Viewport.Transform;
  40. PathGeometry geometry = PathGeometry;
  41. PointCollection points = Points;
  42. geometry.Clear();
  43. if (BezierPoints != null)
  44. {
  45. points = BezierPoints;
  46. var screenPoints = points.DataToScreen(transform).ToArray();
  47. PathFigure figure = new PathFigure();
  48. figure.StartPoint = screenPoints[0];
  49. figure.Segments.Add(new PolyBezierSegment(screenPoints.Skip(1), true));
  50. geometry.Figures.Add(figure);
  51. geometry.FillRule = this.FillRule;
  52. }
  53. else if (points == null) { }
  54. else
  55. {
  56. PathFigure figure = new PathFigure();
  57. if (points.Count > 0)
  58. {
  59. Point[] bezierPoints = null;
  60. figure.StartPoint = points[0].DataToScreen(transform);
  61. if (points.Count > 1)
  62. {
  63. Point[] screenPoints = points.DataToScreen(transform).ToArray();
  64. bezierPoints = BezierBuilder.GetBezierPoints(screenPoints).Skip(1).ToArray();
  65. figure.Segments.Add(new PolyBezierSegment(bezierPoints, true));
  66. }
  67. if (bezierPoints != null && buildBezierPoints)
  68. {
  69. Array.Resize(ref bezierPoints, bezierPoints.Length + 1);
  70. Array.Copy(bezierPoints, 0, bezierPoints, 1, bezierPoints.Length - 1);
  71. bezierPoints[0] = figure.StartPoint;
  72. BezierPoints = new PointCollection(bezierPoints.ScreenToData(transform));
  73. }
  74. }
  75. geometry.Figures.Add(figure);
  76. geometry.FillRule = this.FillRule;
  77. }
  78. updating = false;
  79. }
  80. }
  81. }