Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/Shapes/Arrow.cs @ 13398

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

#2283 added GUI and charts; fixed MCTS

File size: 3.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Media;
6using System.Windows;
7using Microsoft.Research.DynamicDataDisplay;
8
9namespace Microsoft.Research.DynamicDataDisplay.Charts.Shapes
10{
11  /// <summary>
12  /// Paints an arrow with start and end points in viewport coordinates.
13  /// </summary>
14  public class Arrow : Segment
15  {
16    /// <summary>
17    /// Initializes a new instance of the <see cref="Arrow"/> class.
18    /// </summary>
19    public Arrow()
20    {
21      Init();
22    }
23
24    /// <summary>
25    /// Initializes a new instance of the <see cref="Arrow"/> class.
26    /// </summary>
27    /// <param name="startPoint">The start point of arrow.</param>
28    /// <param name="endPoint">The end pointof arrow .</param>
29    public Arrow(Point startPoint, Point endPoint)
30      : base(startPoint, endPoint)
31    {
32      Init();
33    }
34
35    private void Init()
36    {
37      geometryGroup.Children.Add(LineGeometry);
38      geometryGroup.Children.Add(leftLineGeometry);
39      geometryGroup.Children.Add(rightLineGeometry);
40    }
41
42    #region ArrowLength property
43
44    /// <summary>
45    /// Gets or sets the length of the arrow.
46    /// </summary>
47    /// <value>The length of the arrow.</value>
48    public double ArrowLength
49    {
50      get { return (double)GetValue(ArrowLengthProperty); }
51      set { SetValue(ArrowLengthProperty, value); }
52    }
53
54    /// <summary>
55    /// Identifies ArrowLength dependency property.
56    /// </summary>
57    public static readonly DependencyProperty ArrowLengthProperty = DependencyProperty.Register(
58      "ArrowLength",
59      typeof(double),
60      typeof(Arrow),
61      new FrameworkPropertyMetadata(0.1, OnPointChanged));
62
63    #endregion
64
65    #region ArrowAngle property
66
67    /// <summary>
68    /// Gets or sets the arrow angle in degrees.
69    /// </summary>
70    /// <value>The arrow angle.</value>
71    public double ArrowAngle
72    {
73      get { return (double)GetValue(ArrowAngleProperty); }
74      set { SetValue(ArrowAngleProperty, value); }
75    }
76
77    /// <summary>
78    /// Identifies ArrowAngle dependency property.
79    /// </summary>
80    public static readonly DependencyProperty ArrowAngleProperty = DependencyProperty.Register(
81      "ArrowAngle",
82      typeof(double),
83      typeof(Arrow),
84      new FrameworkPropertyMetadata(15.0, OnPointChanged));
85
86    #endregion
87
88    protected override void UpdateUIRepresentationCore()
89    {
90      base.UpdateUIRepresentationCore();
91
92      var transform = Plotter.Viewport.Transform;
93
94      Point p1 = StartPoint.DataToScreen(transform);
95      Point p2 = EndPoint.DataToScreen(transform);
96
97      Vector arrowVector = p1 - p2;
98      Vector arrowCapVector = ArrowLength * arrowVector;
99
100      Matrix leftMatrix = Matrix.Identity;
101      leftMatrix.Rotate(ArrowAngle);
102
103      Matrix rightMatrix = Matrix.Identity;
104      rightMatrix.Rotate(-ArrowAngle);
105
106      Vector leftArrowLine = leftMatrix.Transform(arrowCapVector);
107      Vector rightArrowLine = rightMatrix.Transform(arrowCapVector);
108
109      leftLineGeometry.StartPoint = p2;
110      rightLineGeometry.StartPoint = p2;
111
112      leftLineGeometry.EndPoint = p2 + leftArrowLine;
113      rightLineGeometry.EndPoint = p2 + rightArrowLine;
114    }
115
116    private LineGeometry leftLineGeometry = new LineGeometry();
117    private LineGeometry rightLineGeometry = new LineGeometry();
118    private GeometryGroup geometryGroup = new GeometryGroup();
119    protected override Geometry DefiningGeometry
120    {
121      get { return geometryGroup; }
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.