[12503] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary;
|
---|
| 6 | using System.Windows.Media;
|
---|
| 7 | using System.Diagnostics.Contracts;
|
---|
| 8 | using System.Windows.Shapes;
|
---|
| 9 |
|
---|
| 10 | namespace Microsoft.Research.DynamicDataDisplay.Charts
|
---|
| 11 | {
|
---|
| 12 | /// <summary>
|
---|
| 13 | /// This is a class for displaying some debug visuals on the plotter;
|
---|
| 14 | /// </summary>
|
---|
| 15 | public class VisualDebug : IPlotterElement
|
---|
| 16 | {
|
---|
| 17 | private Plotter2D plotter;
|
---|
| 18 | private static readonly ViewportHostPanel panel = new ViewportHostPanel();
|
---|
| 19 | private static readonly VisualDebug current = new VisualDebug();
|
---|
| 20 | private static readonly Dictionary<string, object> objects = new Dictionary<string, object>();
|
---|
| 21 |
|
---|
| 22 | public static void DrawRectangle(string name, DataRect bounds, Brush stroke = null, Brush fill = null, double strokeThickness = 1.0)
|
---|
| 23 | {
|
---|
| 24 | Contract.Assert(name != null);
|
---|
| 25 |
|
---|
| 26 | if (stroke == null)
|
---|
| 27 | stroke = Brushes.Blue;
|
---|
| 28 |
|
---|
| 29 | Rectangle rect;
|
---|
| 30 | if (objects.ContainsKey(name))
|
---|
| 31 | rect = (Rectangle)objects[name];
|
---|
| 32 | else
|
---|
| 33 | {
|
---|
| 34 | rect = new Rectangle();
|
---|
| 35 | objects.Add(name, rect);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | rect.Stroke = stroke;
|
---|
| 39 | rect.StrokeThickness = strokeThickness;
|
---|
| 40 | rect.Fill = fill;
|
---|
| 41 |
|
---|
| 42 | ViewportPanel.SetViewportBounds(rect, bounds);
|
---|
| 43 |
|
---|
| 44 | if (rect.Parent == null)
|
---|
| 45 | panel.Children.Add(rect);
|
---|
| 46 |
|
---|
| 47 | EnsurePanelAdded();
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | private static void EnsurePanelAdded()
|
---|
| 51 | {
|
---|
| 52 | if (Plotter.Current == null)
|
---|
| 53 | return;
|
---|
| 54 | if (panel.Parent != null)
|
---|
| 55 | return;
|
---|
| 56 |
|
---|
| 57 | Plotter.Current.Children.Add(panel);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | #region IPlotterElement Members
|
---|
| 61 |
|
---|
| 62 | public void OnPlotterAttached(Plotter plotter)
|
---|
| 63 | {
|
---|
| 64 | this.plotter = (Plotter2D)plotter;
|
---|
| 65 | plotter.Dispatcher.BeginInvoke(() =>
|
---|
| 66 | {
|
---|
| 67 | plotter.Children.Add(panel);
|
---|
| 68 | });
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | public void OnPlotterDetaching(Plotter plotter)
|
---|
| 72 | {
|
---|
| 73 | plotter.Dispatcher.BeginInvoke(() =>
|
---|
| 74 | {
|
---|
| 75 | plotter.Children.Remove(panel);
|
---|
| 76 | });
|
---|
| 77 |
|
---|
| 78 | this.plotter = null;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public Plotter Plotter
|
---|
| 82 | {
|
---|
| 83 | get { return plotter; }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | #endregion
|
---|
| 87 | }
|
---|
| 88 | }
|
---|