Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/Shapes/ViewportPolyBezierCurve.cs @ 12747

Last change on this file since 12747 was 12503, checked in by aballeit, 10 years ago

#2283 added GUI and charts; fixed MCTS

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