aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/RealTimeGraphEx/DirectXGraphs/RealTimeGraphExDirectXMultiLineScroll.cs
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-01-16 12:17:10 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-01-16 12:17:10 +0200
commit0fda2ba3ff49bdc1ffc6833f658e2164af187008 (patch)
tree6f3a24d0671ebda50debb8511ab40e0bda0a0df0 /Software/Visual_Studio/SideChains/RealTimeGraphEx/DirectXGraphs/RealTimeGraphExDirectXMultiLineScroll.cs
parent28103646681686bf1b58275d5dbccb92d2b26f9f (diff)
downloadTango-0fda2ba3ff49bdc1ffc6833f658e2164af187008.tar.gz
Tango-0fda2ba3ff49bdc1ffc6833f658e2164af187008.zip
Embedded RealTimeGraphEx library to solution.
Added graphs to technician view. Implemented simple sensors data test using Machine Emulator.
Diffstat (limited to 'Software/Visual_Studio/SideChains/RealTimeGraphEx/DirectXGraphs/RealTimeGraphExDirectXMultiLineScroll.cs')
-rw-r--r--Software/Visual_Studio/SideChains/RealTimeGraphEx/DirectXGraphs/RealTimeGraphExDirectXMultiLineScroll.cs266
1 files changed, 266 insertions, 0 deletions
diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/DirectXGraphs/RealTimeGraphExDirectXMultiLineScroll.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/DirectXGraphs/RealTimeGraphExDirectXMultiLineScroll.cs
new file mode 100644
index 000000000..7671272f0
--- /dev/null
+++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/DirectXGraphs/RealTimeGraphExDirectXMultiLineScroll.cs
@@ -0,0 +1,266 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using RealTimeGraphEx.Models;
+using RealTimeGraphEx.DataSeries;
+using RealTimeGraphEx.Controllers;
+using System.Runtime.ExceptionServices;
+using RealTimeGraphEx.DX2D;
+using System.Windows.Controls;
+using System.Windows.Threading;
+
+namespace RealTimeGraphEx.DirectXGraphs
+{
+ public class RealTimeGraphExDirectXMultiLineScroll : RealTimeGraphExMultiBase
+ {
+ #region Cross Thread Fields
+
+ protected Direct2DControl dxGraph;
+ protected List<ConcurrentpointsList> _graphPolygons;
+ protected Brush _stroke;
+ protected Brush _fill;
+ protected bool _fillGraph;
+ protected double _strokeWidth;
+
+ #endregion
+
+ #region Constructors
+
+ public RealTimeGraphExDirectXMultiLineScroll()
+ : base()
+ {
+ _graphPolygons = new List<ConcurrentpointsList>();
+ _graphController = new GraphMultiController();
+ }
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Gets or sets the graph strokes color.
+ /// </summary>
+ public Brush Stroke
+ {
+ get { return (Brush)GetValue(StrokeProperty); }
+ set { SetValue(StrokeProperty, value); }
+ }
+ public static readonly DependencyProperty StrokeProperty =
+ DependencyProperty.Register("Stroke", typeof(Brush), typeof(RealTimeGraphExDirectXMultiLineScroll), new PropertyMetadata(Brushes.Red, new PropertyChangedCallback(CrossModelChanged)));
+
+ /// <summary>
+ /// Gets or sets the graph fill color.
+ /// </summary>
+ public Brush Fill
+ {
+ get { return (Brush)GetValue(FillProperty); }
+ set { SetValue(FillProperty, value); }
+ }
+ public static readonly DependencyProperty FillProperty =
+ DependencyProperty.Register("Fill", typeof(Brush), typeof(RealTimeGraphExDirectXMultiLineScroll), new PropertyMetadata(Brushes.Transparent, new PropertyChangedCallback(CrossModelChanged)));
+
+ /// <summary>
+ /// Gets or sets whether the graph will be rendered using the Fill color property.
+ /// </summary>
+ public bool FillGraph
+ {
+ get { return (bool)GetValue(FillGraphProperty); }
+ set { SetValue(FillGraphProperty, value); }
+ }
+ public static readonly DependencyProperty FillGraphProperty =
+ DependencyProperty.Register("FillGraph", typeof(bool), typeof(RealTimeGraphExDirectXMultiLineScroll), new PropertyMetadata(false, new PropertyChangedCallback(CrossModelChanged)));
+
+ public double StrokeWidth
+ {
+ get { return (double)GetValue(StrokeWidthProperty); }
+ set { SetValue(StrokeWidthProperty, value); }
+ }
+ public static readonly DependencyProperty StrokeWidthProperty =
+ DependencyProperty.Register("StrokeWidth", typeof(double), typeof(RealTimeGraphExDirectXMultiLineScroll), new PropertyMetadata(1.0, new PropertyChangedCallback(CrossModelChanged)));
+
+
+ #endregion
+
+ #region Override Methods
+
+ protected override void Initialize()
+ {
+ base.Initialize();
+
+ dxGraph = new DXGraphSurfaceMultiScroll() { HorizontalAlignment = System.Windows.HorizontalAlignment.Left, VerticalAlignment = System.Windows.VerticalAlignment.Stretch };
+
+ gridMain.Children.Remove(img);
+
+ if (!gridMain.Children.Contains(dxGraph))
+ {
+ gridMain.Children.Add(dxGraph);
+ }
+
+ dxGraph.IsHitTestVisible = false;
+ Grid.SetColumnSpan(dxGraph, 3);
+ }
+
+ protected override void OnControllerChanged()
+ {
+ if (_graphController != null)
+ {
+ _graphController.RegisterMethods(ClearGraph, StartPushThread, SetPaused, ChangeRenderMode, null);
+
+ foreach (var dataSeries in _graphController.DataSeriesCollection)
+ {
+ _graphPolygons.Add(new ConcurrentpointsList());
+ }
+ }
+ }
+
+ protected override void OnSizeChanged(object sender, SizeChangedEventArgs e)
+ {
+ OnSetCrossThreadFields();
+ }
+
+ protected override void OnSetCrossThreadFields()
+ {
+ base.OnSetCrossThreadFields();
+
+ this.Dispatcher.Invoke(() =>
+ {
+ _maxPoints = MaxPoints;
+ _scaleFactor = _width / _maxPoints;
+ _strokeWidth = StrokeWidth;
+ _fill = Fill;
+ _stroke = Stroke;
+ _fillGraph = FillGraph;
+
+ }, System.Windows.Threading.DispatcherPriority.Send);
+ }
+
+ protected override void OnClearGraph()
+ {
+ _graphPolygons.ForEach(x => x.Clear());
+ _graphController.ClearPoints();
+
+ base.OnClearGraph();
+ }
+
+ protected override double ConvertYToImageY(double value)
+ {
+ double valuePrecentage = ((((value - (_minimum - (_strokeWidth / 2))) * 100) / (_maximum - (_minimum - (_strokeWidth / 2)))) * ((_height) - (_strokeWidth / 2))) / 100;
+ return valuePrecentage;
+ }
+
+ protected override double ConvertYToImageYFliped(double value)
+ {
+ double valuePrecentage = ConvertYToImageY(value);
+ valuePrecentage = (_height - (_strokeWidth / 2)) - valuePrecentage; //Flip
+ return valuePrecentage;
+ }
+
+ protected internal override void OnRenderGraph()
+ {
+ if (_graphController != null && _graphController.dataSeriesCollection.Count > 0 && _graphController.TotalPoints > 0 && _width > 1 && _height > 1)
+ {
+ var pointsCollection = _graphController.GetAndClearAllPoints();
+
+ if (!_isPaused)
+ {
+
+ Parallel.For(0, pointsCollection.Count, (i) =>
+ {
+
+ for (int j = 0; j < pointsCollection[(int)i].Count; j++)
+ {
+ double value = pointsCollection[(int)i][j];
+ NormalizeValue(ref value);
+
+ _graphPolygons[i].Add(value);
+ }
+ });
+
+ if (_graphPolygons[0].Count > _maxPoints + _graphController.dataSeriesCollection[0].Points.Count)
+ {
+ Parallel.ForEach(_graphPolygons, (polygon) =>
+ {
+ polygon.RemoveFromStart(polygon.Count - (_maxPoints + _graphController.dataSeriesCollection[0].Points.Count));
+ });
+ }
+ }
+ }
+
+ updateCounter++;
+
+ if (updateCounter >= 1)
+ {
+ updateCounter = 0;
+
+ if (!_disableRendering)
+ {
+ OnDrawVisuals();
+ }
+ }
+ }
+
+ protected override void OnDragging(System.Windows.Controls.Primitives.DragDeltaEventArgs e)
+ {
+ base.OnDragging(e);
+ }
+
+ #endregion
+
+ #region Virtual Methods
+
+ protected virtual void OnDrawVisuals()
+ {
+ if (_graphPolygons[0].Count > 0)
+ {
+ List<SharpDX.Vector2[]> polygonPoints = new List<SharpDX.Vector2[]>();
+ List<SharpDX.Vector2[]> polygonPointsFill = new List<SharpDX.Vector2[]>();
+ List<Brush> strokes = new List<Brush>();
+ List<Brush> fills = new List<Brush>();
+
+ for (int i = 0; i < _graphPolygons.Count; i++)
+ {
+ var polygon = _graphPolygons[i];
+ double scale = _width / (polygon.Count - 1);
+
+ if (polygon.Count > 0 && _graphController.dataSeriesCollection[i].isVisible)
+ {
+ Brush stroke = _graphController.dataSeriesCollection[i].stroke != null ? _graphController.dataSeriesCollection[i].stroke : _stroke;
+ Brush fill = _graphController.dataSeriesCollection[i].fill != null ? _graphController.dataSeriesCollection[i].fill : _fill;
+
+ strokes.Add(stroke);
+ fills.Add(fill);
+
+ polygonPoints.Add(polygon.ToDXPolygonPoints(_offSetX, _offSetY, scale, ConvertYToImageYFliped));
+ polygonPointsFill.Add(polygon.ToDXPolygonPointsFill(_offSetX, _offSetY, _mainWidth, _mainHeight, scale, ConvertYToImageYFliped));
+ }
+ }
+
+ (dxGraph as DXGraphSurfaceMultiScroll).SetProperties(
+ polygonPoints,
+ _fillGraph ? polygonPointsFill : null,
+ strokes,
+ _strokeWidth,
+ _fillGraph,
+ fills,
+ _antialiased);
+
+ dxGraph.EnableRendering();
+ }
+ }
+
+ public virtual List<double> GetCurrentPointsOnGraph(int seriesIndex)
+ {
+ return _graphPolygons[seriesIndex].GetPoints();
+ }
+
+ #endregion
+
+ }
+}