Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Charts/Shapes/Segment.cs @ 12503

Last change on this file since 12503 was 12503, checked in by aballeit, 9 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 System.Windows.Media;
6using System.Windows;
7using System.Windows.Shapes;
8using Microsoft.Research.DynamicDataDisplay;
9
10namespace Microsoft.Research.DynamicDataDisplay.Charts
11{
12  /// <summary>
13  /// Represents a segment with start and end points bound to viewport coordinates.
14  /// </summary>
15  public class Segment : ViewportShape
16  {
17    /// <summary>
18    /// Initializes a new instance of the <see cref="Segment"/> class.
19    /// </summary>
20    public Segment() { }
21
22    /// <summary>
23    /// Initializes a new instance of the <see cref="Segment"/> class.
24    /// </summary>
25    /// <param name="startPoint">The start point of segment.</param>
26    /// <param name="endPoint">The end point of segment.</param>
27    public Segment(Point startPoint, Point endPoint)
28    {
29      StartPoint = startPoint;
30      EndPoint = endPoint;
31    }
32
33    /// <summary>
34    /// Gets or sets the start point of segment.
35    /// </summary>
36    /// <value>The start point.</value>
37    public Point StartPoint
38    {
39      get { return (Point)GetValue(StartPointProperty); }
40      set { SetValue(StartPointProperty, value); }
41    }
42
43    /// <summary>
44    /// Identifies the StartPoint dependency property.
45    /// </summary>
46    public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
47      "StartPoint",
48      typeof(Point),
49      typeof(Segment),
50      new FrameworkPropertyMetadata(new Point(), OnPointChanged));
51
52    protected static void OnPointChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
53    {
54      Segment segment = (Segment)d;
55      segment.UpdateUIRepresentation();
56    }
57
58    protected virtual void OnPointChanged() { }
59
60    /// <summary>
61    /// Gets or sets the end point of segment.
62    /// </summary>
63    /// <value>The end point.</value>
64    public Point EndPoint
65    {
66      get { return (Point)GetValue(EndPointProperty); }
67      set { SetValue(EndPointProperty, value); }
68    }
69
70    /// <summary>
71    /// Identifies the EndPoint dependency property.
72    /// </summary>
73    public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
74      "EndPoint",
75      typeof(Point),
76      typeof(Segment),
77      new FrameworkPropertyMetadata(new Point(), OnPointChanged));
78
79    protected override void UpdateUIRepresentationCore()
80    {
81      if (Plotter == null)
82        return;
83
84      var transform = Plotter.Viewport.Transform;
85
86      Point p1 = StartPoint.DataToScreen(transform);
87      Point p2 = EndPoint.DataToScreen(transform);
88
89      lineGeometry.StartPoint = p1;
90      lineGeometry.EndPoint = p2;
91    }
92
93    LineGeometry lineGeometry = new LineGeometry();
94    protected LineGeometry LineGeometry
95    {
96      get { return lineGeometry; }
97    }
98
99    protected override Geometry DefiningGeometry
100    {
101      get { return lineGeometry; }
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.