From 0fda2ba3ff49bdc1ffc6833f658e2164af187008 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 16 Jan 2018 12:17:10 +0200 Subject: Embedded RealTimeGraphEx library to solution. Added graphs to technician view. Implemented simple sensors data test using Machine Emulator. --- .../FastGraphs/RealTimeGraphExEllipseScroll.cs | 122 +++++++++ .../FastGraphs/RealTimeGraphExLineErase.cs | 257 ++++++++++++++++++ .../FastGraphs/RealTimeGraphExLineScroll.cs | 251 ++++++++++++++++++ .../FastGraphs/RealTimeGraphExMultiLineErase.cs | 233 +++++++++++++++++ .../FastGraphs/RealTimeGraphExMultiLineScroll.cs | 267 +++++++++++++++++++ .../FastGraphs/RealTimeGraphExShapeErase.cs | 287 +++++++++++++++++++++ .../FastGraphs/RealTimeGraphExShapeScroll.cs | 276 ++++++++++++++++++++ .../FastGraphs/RealTimeGraphExWaveErase.cs | 79 ++++++ .../FastGraphs/RealTimeGraphExWaveScroll.cs | 66 +++++ .../RealTimeGraphEx/FastGraphs/ShapeTypeEnum.cs | 15 ++ 10 files changed, 1853 insertions(+) create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExEllipseScroll.cs create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineErase.cs create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineScroll.cs create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExMultiLineErase.cs create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExMultiLineScroll.cs create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExShapeErase.cs create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExShapeScroll.cs create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExWaveErase.cs create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExWaveScroll.cs create mode 100644 Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/ShapeTypeEnum.cs (limited to 'Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs') diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExEllipseScroll.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExEllipseScroll.cs new file mode 100644 index 000000000..cfd9d54c5 --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExEllipseScroll.cs @@ -0,0 +1,122 @@ +using System; +using System.Collections.Generic; +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.Enums; + +namespace RealTimeGraphEx.FastGraphs +{ + public class RealTimeGraphExEllipseScroll : RealTimeGraphExLineScroll + { + #region Cross Thread Fields + + protected OpacityTypeEnum _opacityAnimationType; + protected int _ellipseXRadius; + protected int _ellipseYRadius; + + #endregion + + #region Constructors + + public RealTimeGraphExEllipseScroll() + : base() + { + + } + + #endregion + + #region Properties + + public OpacityTypeEnum OpacityAnimationType + { + get { return (OpacityTypeEnum)GetValue(OpacityAnimationTypeProperty); } + set { SetValue(OpacityAnimationTypeProperty, value); } + } + public static readonly DependencyProperty OpacityAnimationTypeProperty = + DependencyProperty.Register("OpacityAnimationType", typeof(OpacityTypeEnum), typeof(RealTimeGraphExEllipseScroll), new PropertyMetadata(OpacityTypeEnum.None, new PropertyChangedCallback(CrossModelChanged))); + + + + public int EllipseXRadius + { + get { return (int)GetValue(EllipseXRadiusProperty); } + set { SetValue(EllipseXRadiusProperty, value); } + } + public static readonly DependencyProperty EllipseXRadiusProperty = + DependencyProperty.Register("EllipseXRadius", typeof(int), typeof(RealTimeGraphExEllipseScroll), new PropertyMetadata(5)); + + + + public int EllipseYRadius + { + get { return (int)GetValue(EllipseYRadiusProperty); } + set { SetValue(EllipseYRadiusProperty, value); } + } + public static readonly DependencyProperty EllipseYRadiusProperty = + DependencyProperty.Register("EllipseYRadius", typeof(int), typeof(RealTimeGraphExEllipseScroll), new PropertyMetadata(5)); + + + + + #endregion + + #region Override Methods + + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + + _opacityAnimationType = OpacityAnimationType; + _ellipseXRadius = EllipseXRadius; + _ellipseYRadius = EllipseYRadius; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + /// + /// Draw the actual polygon on the image. + /// + /// + protected override void OnDrawVisuals(WriteableBitmap bmp) + { + Color stroke = _graphController.dataSeries.GetStrokeColor() != null ? _graphController.dataSeries.GetStrokeColor().Value : _stroke; + Color fill = _graphController.dataSeries.GetFillColor() != null ? _graphController.dataSeries.GetFillColor().Value : _fill; + + double scale = GetPolygonScaleFactor(); + + for (int i = 0; i < graphPolygon.Count; i++) + { + var point = graphPolygon[i]; + + Color processedLineColor = stroke; + Color processedFillColor = fill; + + if (_opacityAnimationType == OpacityTypeEnum.FadeOut) + { + byte opacity = (byte)((((i) * 100 / _maxPoints) * 255) / 100); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + + if (_fillGraph) + { + bmp.FillEllipseCentered((int)(i * scale), (int)ConvertYToImageYFliped(point), _ellipseXRadius, _ellipseYRadius, processedFillColor); + } + + bmp.DrawEllipseCentered((int)(i * scale), (int)ConvertYToImageYFliped(point), _ellipseXRadius, _ellipseYRadius, processedLineColor); + } + } + + #endregion + } +} diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineErase.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineErase.cs new file mode 100644 index 000000000..f1902e662 --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineErase.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +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; + +namespace RealTimeGraphEx.FastGraphs +{ + public class RealTimeGraphExLineErase : RealTimeGraphExLineScroll, INotifyPropertyChanged + { + #region Cross Thread Fields + + protected Color _markerColor; + protected bool _showMarker; + protected bool _endReached; + protected int _currentReplaceIndex; + protected bool _enableMarkerPosition; + protected double lastVirtualValue; + protected int lastMaxPoints; + + #endregion + + #region Properties + + /// + /// Gets or sets the graph marker color. + /// + public Color MarkerColor + { + get { return (Color)GetValue(MarkerColorProperty); } + set { SetValue(MarkerColorProperty, value); } + } + public static readonly DependencyProperty MarkerColorProperty = + DependencyProperty.Register("MarkerBrush", typeof(Color), typeof(RealTimeGraphExLineErase), new PropertyMetadata(Colors.Red, new PropertyChangedCallback(CrossModelChanged))); + + /// + /// Gets or sets whether to display the marker on the graph. + /// + public bool ShowMarker + { + get { return (bool)GetValue(ShowMarkerProperty); } + set { SetValue(ShowMarkerProperty, value); } + } + public static readonly DependencyProperty ShowMarkerProperty = + DependencyProperty.Register("ShowMarker", typeof(bool), typeof(RealTimeGraphExLineErase), new PropertyMetadata(true, new PropertyChangedCallback(CrossModelChanged))); + + /// + /// Gets or sets a value indicating whether to enable the MarkerPosition property to be updated. (Affects performance). + /// + public bool EnableMarkerPosition + { + get { return (bool)GetValue(EnableMarkerPositionProperty); } + set { SetValue(EnableMarkerPositionProperty, value); } + } + public static readonly DependencyProperty EnableMarkerPositionProperty = + DependencyProperty.Register("EnableMarkerPosition", typeof(bool), typeof(RealTimeGraphExLineErase), new PropertyMetadata(false, new PropertyChangedCallback(CrossModelChanged))); + + /// + /// Gets the current marker position on the graph. + /// + private Point markerPosition; + public Point MarkerPosition + { + private get { return markerPosition; } + set { markerPosition = value; RaisePropertyChanged("MarkerPosition"); } + } + + #endregion + + #region Constructors + + public RealTimeGraphExLineErase() + : base() + { + + } + + #endregion + + #region Override Method + + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + _markerColor = MarkerColor; + _showMarker = ShowMarker; + _enableMarkerPosition = EnableMarkerPosition; + + if (lastMaxPoints > _maxPoints && graphPolygon.Count > (lastMaxPoints - _maxPoints)) + { + graphPolygon.RemoveFromStart(lastMaxPoints - _maxPoints); + } + + lastMaxPoints = _maxPoints; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + protected internal override void OnRenderGraph() + { + if (_graphController != null && _graphController.dataSeries != null && _graphController.dataSeries.Points != null && _graphController.dataSeries.Points.Count > 0 && _width > 1 && _height > 1) + { + var points = _graphController.dataSeries.Points.GetAndClearAllPoints(); + + if (!_isPaused) + { + + for (int i = 0; i < points.Count; i++) //Match + { + double value = points[i]; + NormalizeValue(ref value); + lastVirtualValue = value; + + if (graphPolygon.Count > _maxPoints) + { + graphPolygon.Replace(value, _currentReplaceIndex++); + + for (int k = 0; k < _markers.Count; k++) + { + if (_markers[k] == _currentReplaceIndex) + { + _markers.RemoveAt(k); + k--; + } + } + } + else + { + graphPolygon.Add(value); + } + + xValueCounter += _scaleFactor; + + if (_currentReplaceIndex == graphPolygon.Count - 1) + { + xValueCounter = 0; + _currentReplaceIndex = 0; + } + } + } + + updateCounter++; + + if (updateCounter >= 1) + { + updateCounter = 0; + + if (!_disableRendering) + { + WriteableBitmap bmp = BitmapFactory.New((int)_mainWidth, (int)_mainHeight); + bmp.Clear(Colors.Transparent); + + OnDrawVisuals(bmp); + + bmp.Freeze(); + + img.Dispatcher.BeginInvoke(new Action(() => + { + img.Source = bmp; + }), System.Windows.Threading.DispatcherPriority.Send); + } + } + } + } + + protected override void OnDrawVisuals(WriteableBitmap bmp) + { + if (_graphController == null) return; + + Color stroke = _graphController.dataSeries.GetStrokeColor() != null ? _graphController.dataSeries.GetStrokeColor().Value : _stroke; + Color fill = _graphController.dataSeries.GetFillColor() != null ? _graphController.dataSeries.GetFillColor().Value : _fill; + double scale = GetPolygonScaleFactor(); + double currentWidth = _endReached ? _width : xValueCounter; + + + if (_fillGraph) //Fill Graph + { + bmp.FillPolygon(graphPolygon.ToPolygonPointsFill(_offSetX, _offSetY, _mainWidth, _mainHeight, scale, ConvertYToImageYFliped), fill); + } + + DrawPolyline(bmp, graphPolygon.ToPolygonPoints(_offSetX, _offSetY, scale, ConvertYToImageYFliped), stroke); + + + //Draw marker + if (_showMarker) + { + if (_currentReplaceIndex > 0) + { + try + { + + double x = (((_currentReplaceIndex - 1) * scale) + _offSetX); + bmp.DrawLine((int)x, 0, (int)x, (int)_mainHeight, _markerColor); + } + catch + { + Debug.WriteLine("[RealTimeGraphExLineErase] [OnDrawVisuals] Error on drawing marker!"); + } + } + } + + for (int j = 0; j < _markers.Count; j++) + { + int x = (int)(((_markers[j] - 1) * scale) + _offSetX); + bmp.DrawLine(x, 0, x, (int)_mainHeight, Colors.Silver); + } + + if (_enableMarkerPosition) + { + MarkerPosition = new Point((_currentReplaceIndex * scale) + _offSetX, ConvertYToImageYFliped(lastVirtualValue) + _offSetY); + } + } + + protected override void OnClearGraph() + { + base.OnClearGraph(); + + _currentReplaceIndex = 0; + _endReached = false; + MarkerPosition = new Point(0, 0); + } + + protected override void OnPushMarker() + { + if (_currentReplaceIndex != 0) + { + _markers.Add(_currentReplaceIndex); + } + } + + #endregion + + #region INotifyPropertyChanged Members + + public event PropertyChangedEventHandler PropertyChanged; + + public void RaisePropertyChanged(String propName) + { + this.Dispatcher.Invoke(() => + { + + if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propName)); + + }); + } + + #endregion + } +} diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineScroll.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineScroll.cs new file mode 100644 index 000000000..216683d39 --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineScroll.cs @@ -0,0 +1,251 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Threading; +using RealTimeGraphEx.Models; +using RealTimeGraphEx.DataSeries; +using RealTimeGraphEx.Controllers; +using System.Runtime.ExceptionServices; + +namespace RealTimeGraphEx.FastGraphs +{ + /// + /// Represents a real-time graph with a single scrollable line. + /// + public class RealTimeGraphExLineScroll : RealTimeGraphExBase + { + #region Protected Fields + + protected ConcurrentpointsList graphPolygon; + protected int updateCounter; + + #endregion + + #region Cross Thread Fields + + protected GraphController _graphController; + protected int _maxPoints; + protected double _scaleFactor; + protected Color _stroke; + protected Color _fill; + protected bool _fillGraph; + protected List _markers; + + #endregion + + #region Properties + + /// + /// Gets or sets the maximum vectorsCollection to display on the graph (default 1000, affects performance). + /// + public int MaxPoints + { + get { return (int)GetValue(MaxPointsProperty); } + set { SetValue(MaxPointsProperty, value); } + } + public static readonly DependencyProperty MaxPointsProperty = + DependencyProperty.Register("MaxPoints", typeof(int), typeof(RealTimeGraphExLineScroll), new PropertyMetadata(1000, new PropertyChangedCallback(CrossModelChanged))); + + + /// + /// Gets or sets the graph fill color. + /// + public Color Stroke + { + get { return (Color)GetValue(StrokeProperty); } + set { SetValue(StrokeProperty, value); } + } + public static readonly DependencyProperty StrokeProperty = + DependencyProperty.Register("Stroke", typeof(Color), typeof(RealTimeGraphExLineScroll), new PropertyMetadata(Colors.Black, new PropertyChangedCallback(CrossModelChanged))); + + /// + /// Gets or sets the graph fill color. + /// + public Color Fill + { + get { return (Color)GetValue(FillProperty); } + set { SetValue(FillProperty, value); } + } + public static readonly DependencyProperty FillProperty = + DependencyProperty.Register("Fill", typeof(Color), typeof(RealTimeGraphExLineScroll), new PropertyMetadata(Colors.Gray, new PropertyChangedCallback(CrossModelChanged))); + + /// + /// Gets or sets whether the graph will be rendered using the Fill color property. + /// + public bool FillGraph + { + get { return (bool)GetValue(FillGraphProperty); } + set { SetValue(FillGraphProperty, value); } + } + public static readonly DependencyProperty FillGraphProperty = + DependencyProperty.Register("FillGraph", typeof(bool), typeof(RealTimeGraphExLineScroll), new PropertyMetadata(false, new PropertyChangedCallback(CrossModelChanged))); + + + /// + /// Gets or sets the IDataSeries used to push data vectorsCollection to the graph. + /// + public GraphController Controller + { + get { return (GraphController)GetValue(ControllerProperty); } + set { SetValue(ControllerProperty, value); } + } + public static readonly DependencyProperty ControllerProperty = + DependencyProperty.Register("Controller", typeof(GraphController), typeof(RealTimeGraphExLineScroll), new PropertyMetadata(null, new PropertyChangedCallback(GraphControllerChanged))); + private static void GraphControllerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var control = d as RealTimeGraphExLineScroll; + + if (control.Controller != null) + { + control.Controller.RegisterMethods(control.ClearGraph, control.StartPushThread, control.SetPaused, control.ChangeRenderMode, control.OnPushMarker); + control._graphController = control.Controller; + } + } + + #endregion + + #region Constructors + + public RealTimeGraphExLineScroll() + : base() + { + graphPolygon = new ConcurrentpointsList(); + _markers = new List(); + } + + #endregion + + #region Override Methods + + protected override void OnSizeChanged(object sender, SizeChangedEventArgs e) + { + OnSetCrossThreadFields(); + } + + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + _maxPoints = MaxPoints; + _scaleFactor = _width / _maxPoints; + _graphController = Controller; + _stroke = Stroke; + _fillGraph = FillGraph; + _fill = Fill; + + }, DispatcherPriority.Send); + } + + protected override void OnClearGraph() + { + base.OnClearGraph(); + _graphController.dataSeries.ClearPoints(); + graphPolygon.Clear(); + } + + protected internal override void OnRenderGraph() + { + if (_graphController != null && _graphController.dataSeries.Points != null && _graphController.dataSeries.Points.Count > 0 && _width > 1 && _height > 1) + { + var points = _graphController.dataSeries.Points.GetAndClearAllPoints(); + + if (!_isPaused) + { + + for (int i = 0; i < points.Count; i++) + { + double value = points[i]; + NormalizeValue(ref value); + + graphPolygon.Add(value); + + xValueCounter += _scaleFactor; + } + + if (graphPolygon.Count > _maxPoints + 1) + { + xValueCounter -= (_scaleFactor * (graphPolygon.Count - (_maxPoints + 1))); + graphPolygon.RemoveFromStart(graphPolygon.Count - (_maxPoints + 1)); + } + } + + updateCounter++; + + if (updateCounter >= 1) + { + updateCounter = 0; + + if (!_disableRendering) + { + WriteableBitmap bmp = BitmapFactory.New((int)_mainWidth, (int)_mainHeight); + bmp.Clear(Colors.Transparent); + + OnDrawVisuals(bmp); + + bmp.Freeze(); + + img.Dispatcher.BeginInvoke(new Action(() => + { + img.Source = bmp; + }), System.Windows.Threading.DispatcherPriority.Send); + } + } + } + } + + protected override void OnZoomingComplete(Point transformOrigin, double scaleX, double scaleY) + { + base.OnZoomingComplete(transformOrigin, scaleX, scaleY); + } + + #endregion + + #region Virtual Methods + + protected virtual void OnPushMarker() + { + + } + + /// + /// Calculate the scaling factor for the current graph width. + /// + /// + protected virtual double GetPolygonScaleFactor() + { + return _width / (graphPolygon.Count - 1); + } + + /// + /// Draw the actual polygon on the image. + /// + /// + [HandleProcessCorruptedStateExceptions] + protected virtual void OnDrawVisuals(WriteableBitmap bmp) + { + Color stroke = _graphController.dataSeries.GetStrokeColor() != null ? _graphController.dataSeries.GetStrokeColor().Value : _stroke; + Color fill = _graphController.dataSeries.GetFillColor() != null ? _graphController.dataSeries.GetFillColor().Value : _fill; + + double scale = GetPolygonScaleFactor(); + + OnBeforeRenderingVisuals(bmp, scale); + + if (_fillGraph) //Fill Graph + { + bmp.FillPolygon(graphPolygon.ToPolygonPointsFill(_offSetX, _offSetY, _mainWidth, _mainHeight, scale, ConvertYToImageYFliped), fill); + } + + DrawPolyline(bmp, graphPolygon.ToPolygonPoints(_offSetX, _offSetY, scale, ConvertYToImageYFliped), stroke); + + OnAfterRenderingVisuals(bmp, scale); + } + #endregion + } +} diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExMultiLineErase.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExMultiLineErase.cs new file mode 100644 index 000000000..fd5f27e99 --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExMultiLineErase.cs @@ -0,0 +1,233 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.ExceptionServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace RealTimeGraphEx.FastGraphs +{ + public class RealTimeGraphExMultiLineErase : RealTimeGraphExMultiLineScroll + { + + #region Cross Thread Fields + + protected Color _markerColor; + protected bool _showMarker; + protected bool _endReached; + protected int _currentReplaceIndex; + + #endregion + + #region Constructors + + public RealTimeGraphExMultiLineErase() + : base() + { + + } + + #endregion + + #region Properties + + + /// + /// Gets or sets the graph marker color. + /// + public Color MarkerColor + { + get { return (Color)GetValue(MarkerColorProperty); } + set { SetValue(MarkerColorProperty, value); } + } + public static readonly DependencyProperty MarkerColorProperty = + DependencyProperty.Register("MarkerBrush", typeof(Color), typeof(RealTimeGraphExMultiLineErase), new PropertyMetadata(Colors.Red, new PropertyChangedCallback(CrossModelChanged))); + + /// + /// Gets or sets whether to display the marker on the graph. + /// + public bool ShowMarker + { + get { return (bool)GetValue(ShowMarkerProperty); } + set { SetValue(ShowMarkerProperty, value); } + } + public static readonly DependencyProperty ShowMarkerProperty = + DependencyProperty.Register("ShowMarker", typeof(bool), typeof(RealTimeGraphExMultiLineErase), new PropertyMetadata(true, new PropertyChangedCallback(CrossModelChanged))); + + + #endregion + + #region Override Methods + + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + + _markerColor = MarkerColor; + _showMarker = ShowMarker; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + protected override void OnClearGraph() + { + base.OnClearGraph(); + + _currentReplaceIndex = 0; + _endReached = false; + } + + 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) + { + + for (int i = 0; i < pointsCollection[0].Count; i++) + { + if (xValueCounter <= _width) + { + if (!_endReached) + { + for (int j = 0; j < pointsCollection.Count; j++) + { + double value = pointsCollection[j][i]; + NormalizeValue(ref value); + + _graphPolygons[j].Add(value); + } + + xValueCounter += _scaleFactor; + } + else + { + for (int j = 0; j < pointsCollection.Count; j++) + { + double value = pointsCollection[j][i]; + NormalizeValue(ref value); + + _graphPolygons[j].Replace(value, _currentReplaceIndex); + + if (j == pointsCollection.Count - 1) + { + _currentReplaceIndex++; + + for (int k = 0; k < _markers.Count; k++) + { + if (_markers[k] == _currentReplaceIndex) + { + _markers.RemoveAt(k); + k--; + } + } + } + } + + xValueCounter += _scaleFactor; + + if (_currentReplaceIndex > _graphPolygons[0].Count - 1) + { + xValueCounter = 0; + _currentReplaceIndex = 0; + } + } + } + else + { + _endReached = true; + xValueCounter = 0; + + + for (int j = 0; j < pointsCollection.Count; j++) + { + double value = pointsCollection[j][i]; + NormalizeValue(ref value); + _graphPolygons[j].Replace(value, _currentReplaceIndex); + + if (j == pointsCollection.Count - 1) + { + _currentReplaceIndex++; + } + } + + xValueCounter += _scaleFactor; + } + } + + } + + + updateCounter++; + + if (updateCounter >= 1) + { + updateCounter = 0; + + if (!_disableRendering) + { + WriteableBitmap bmp = BitmapFactory.New((int)_mainWidth, (int)_mainHeight); + bmp.Clear(Colors.Transparent); + + OnDrawVisuals(bmp); + + bmp.Freeze(); + + img.Dispatcher.BeginInvoke(new Action(() => + { + img.Source = bmp; + }), System.Windows.Threading.DispatcherPriority.Send); + } + } + } + } + + protected override void OnPushMarker() + { + if (_currentReplaceIndex != 0) + { + _markers.Add(_currentReplaceIndex); + } + } + + [HandleProcessCorruptedStateExceptions] + protected override void OnDrawVisuals(WriteableBitmap bmp) + { + if (_graphController == null) return; + + base.OnDrawVisuals(bmp); + + var polygon = _graphPolygons[0]; + double scale = _width / polygon.Count; + + //Draw marker + if (_showMarker) + { + if (_currentReplaceIndex > 0) + { + try + { + double x = ((_currentReplaceIndex * scale) + _offSetX); + + bmp.DrawLine((int)x, 0, (int)x, (int)_mainHeight, _markerColor); + } + catch + { + Debug.WriteLine("[RealTimeGraphExMultiLineErase] [OnDrawVisuals] Error on drawing marker!"); + } + } + } + } + + #endregion + } +} diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExMultiLineScroll.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExMultiLineScroll.cs new file mode 100644 index 000000000..2f911a6c4 --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExMultiLineScroll.cs @@ -0,0 +1,267 @@ +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; + +namespace RealTimeGraphEx.FastGraphs +{ + public class RealTimeGraphExMultiLineScroll : RealTimeGraphExMultiBase + { + private GraphMultiController _lastController; + + #region Cross Thread Fields + + protected List _graphPolygons; + protected Color _stroke; + protected Color _fill; + protected bool _fillGraph; + protected List _markers; + + #endregion + + #region Constructors + + public RealTimeGraphExMultiLineScroll() + : base() + { + _graphPolygons = new List(); + _graphController = new GraphMultiController(); + _markers = new List(); + } + + #endregion + + #region Properties + + /// + /// Gets or sets the graph strokes color. + /// + public Color Stroke + { + get { return (Color)GetValue(StrokeProperty); } + set { SetValue(StrokeProperty, value); } + } + public static readonly DependencyProperty StrokeProperty = + DependencyProperty.Register("Stroke", typeof(Color), typeof(RealTimeGraphExMultiLineScroll), new PropertyMetadata(Colors.Black, new PropertyChangedCallback(CrossModelChanged))); + + /// + /// Gets or sets the graph fill color. + /// + public Color Fill + { + get { return (Color)GetValue(FillProperty); } + set { SetValue(FillProperty, value); } + } + public static readonly DependencyProperty FillProperty = + DependencyProperty.Register("Fill", typeof(Color), typeof(RealTimeGraphExMultiLineScroll), new PropertyMetadata(Colors.Transparent, new PropertyChangedCallback(CrossModelChanged))); + + /// + /// Gets or sets whether the graph will be rendered using the Fill color property. + /// + public bool FillGraph + { + get { return (bool)GetValue(FillGraphProperty); } + set { SetValue(FillGraphProperty, value); } + } + public static readonly DependencyProperty FillGraphProperty = + DependencyProperty.Register("FillGraph", typeof(bool), typeof(RealTimeGraphExMultiLineScroll), new PropertyMetadata(false, new PropertyChangedCallback(CrossModelChanged))); + + #endregion + + #region Override Methods + + protected override void OnControllerChanged() + { + if (_graphController != null) + { + if (_lastController != _graphController) + { + _graphPolygons.Clear(); + + _graphController.RegisterMethods(ClearGraph, StartPushThread, SetPaused, ChangeRenderMode, OnPushMarker); + + foreach (var dataSeries in _graphController.DataSeriesCollection) + { + _graphPolygons.Add(new ConcurrentpointsList()); + } + + + _lastController = _graphController; + } + } + } + + protected override void OnSizeChanged(object sender, SizeChangedEventArgs e) + { + OnSetCrossThreadFields(); + } + + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + _maxPoints = MaxPoints; + _scaleFactor = _width / _maxPoints; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + protected override void OnClearGraph() + { + _graphPolygons.ForEach(x => x.Clear()); + _graphController.ClearPoints(); + + base.OnClearGraph(); + } + + 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) => + { + double seriesCounter = xValueCounter; + + for (int j = 0; j < pointsCollection[(int)i].Count; j++) + { + double value = pointsCollection[(int)i][j]; + NormalizeValue(ref value); + + _graphPolygons[i].Add(value); + seriesCounter += _scaleFactor; + } + + }); + + xValueCounter += (pointsCollection[0].Count * _scaleFactor); + + if (_graphPolygons[0].Count > _maxPoints + _graphController.dataSeriesCollection[0].Points.Count) + { + xValueCounter -= (_scaleFactor * (_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) + { + WriteableBitmap bmp = BitmapFactory.New((int)_mainWidth, (int)_mainHeight); + bmp.Clear(Colors.Transparent); + + OnDrawVisuals(bmp); + + bmp.Freeze(); + + img.Dispatcher.BeginInvoke(new Action(() => + { + img.Source = bmp; + }), System.Windows.Threading.DispatcherPriority.Send); + } + } + } + } + + protected override void OnZoomingComplete(Point transformOrigin, double scaleX, double scaleY) + { + base.OnZoomingComplete(transformOrigin, scaleX, scaleY); + + if (IsPaused) + { + WriteableBitmap bmp = BitmapFactory.New((int)_width, (int)_height); + bmp.Clear(Colors.Transparent); + + OnDrawVisuals(bmp); + + bmp.Freeze(); + + img.Dispatcher.BeginInvoke(new Action(() => + { + img.Source = bmp; + }), System.Windows.Threading.DispatcherPriority.Send); + } + } + + protected override void OnDragging(System.Windows.Controls.Primitives.DragDeltaEventArgs e) + { + base.OnDragging(e); + } + + #endregion + + #region Virtual Methods + + [HandleProcessCorruptedStateExceptions] + protected virtual void OnDrawVisuals(WriteableBitmap bmp) + { + for (int i = 0; i < _graphPolygons.Count; i++) + { + Color stroke = _graphController.dataSeriesCollection[i].GetStrokeColor() != null ? _graphController.dataSeriesCollection[i].GetStrokeColor().Value : _stroke; + Color? fill = _graphController.dataSeriesCollection[i].GetFillColor(); + _fillGraph = fill != Colors.Transparent && fill != null; + + var polygon = _graphPolygons[i]; + double scale = _width / (polygon.Count - 1); + + if (polygon.Count > 0) + { + if (_fillGraph && _graphController.dataSeriesCollection[i].isVisible) //Fill Graph + { + bmp.FillPolygon(polygon.ToPolygonPointsFill(_offSetX, _offSetY, _width, _height, scale, ConvertYToImageYFliped), fill.Value); + } + + if (_graphController.dataSeriesCollection[i].isVisible) + { + DrawPolyline(bmp, polygon.ToPolygonPoints(_offSetX, _offSetY, scale, ConvertYToImageYFliped), stroke); + } + } + + + for (int j = 0; j < _markers.Count; j++) + { + int x = (int)((_markers[j] * scale) + _offSetX); + bmp.DrawLine(x, 0, x, (int)_mainHeight, Colors.Silver); + } + } + } + + public virtual List GetCurrentPointsOnGraph(int seriesIndex) + { + return _graphPolygons[seriesIndex].GetPoints(); + } + + protected virtual void OnPushMarker() + { + + } + + #endregion + + } +} diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExShapeErase.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExShapeErase.cs new file mode 100644 index 000000000..0268b08c1 --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExShapeErase.cs @@ -0,0 +1,287 @@ +using System; +using System.Collections.Generic; +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.Enums; + +namespace RealTimeGraphEx.FastGraphs +{ + public class RealTimeGraphExShapeErase : RealTimeGraphExShapeScroll + { + #region Cross Thread Fields + + protected Color _markerColor; + protected bool _showMarker; + protected bool _endReached; + protected int _currentReplaceIndex; + + #endregion + + #region Properties + + /// + /// Gets or sets the graph marker color. + /// + public Color MarkerColor + { + get { return (Color)GetValue(MarkerColorProperty); } + set { SetValue(MarkerColorProperty, value); } + } + public static readonly DependencyProperty MarkerColorProperty = + DependencyProperty.Register("MarkerBrush", typeof(Color), typeof(RealTimeGraphExShapeErase), new PropertyMetadata(Colors.Red, new PropertyChangedCallback(CrossModelChanged))); + + /// + /// Gets or sets whether to display the marker on the graph. + /// + public bool ShowMarker + { + get { return (bool)GetValue(ShowMarkerProperty); } + set { SetValue(ShowMarkerProperty, value); } + } + public static readonly DependencyProperty ShowMarkerProperty = + DependencyProperty.Register("ShowMarker", typeof(bool), typeof(RealTimeGraphExShapeErase), new PropertyMetadata(true, new PropertyChangedCallback(CrossModelChanged))); + + #endregion + + #region Constructors + + public RealTimeGraphExShapeErase() + : base() + { + + } + + #endregion + + #region Override Method + + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + _markerColor = MarkerColor; + _showMarker = ShowMarker; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + protected override void OnClearGraph() + { + base.OnClearGraph(); + + _currentReplaceIndex = 0; + _endReached = false; + } + + protected internal override void OnRenderGraph() + { + if (_graphController != null && _graphController.dataSeries.Points != null && _graphController.dataSeries.Points.Count > 0 && _width > 1 && _height > 1) + { + for (int i = 0; i < _graphController.dataSeries.Points.Count; i++) + { + double value = _graphController.dataSeries.Points[i]; + NormalizeValue(ref value); + double valuePrecentage = ConvertYToImageYFliped(value); + + if (xValueCounter <= _width) + { + if (!_endReached) + { + graphColumns.Add((int)xValueCounter, (int)valuePrecentage, (int)xValueCounter + _shapeWidth, (int)(_maximum - valuePrecentage), (int)value); + xValueCounter += (_shapeWidth + _shapeGap + 1); + currentColumnIndex = graphColumns.TotalColumns - 1; + } + else + { + currentColumnIndex = _currentReplaceIndex; + graphColumns.Replace((int)xValueCounter, (int)valuePrecentage, (int)xValueCounter + _shapeWidth, (int)(_maximum - valuePrecentage), (int)value, _currentReplaceIndex++); + xValueCounter += (_shapeWidth + _shapeGap + 1); + + if (xValueCounter > _width) + { + xValueCounter = 0; + _currentReplaceIndex = 0; + } + } + } + else + { + _endReached = true; + xValueCounter = 0; + currentColumnIndex = 0; + currentColumnIndex = currentColumnIndex = graphColumns.TotalColumns - 1; + graphColumns.Replace((int)xValueCounter, (int)valuePrecentage, (int)xValueCounter + _shapeWidth, (int)(_maximum - valuePrecentage), (int)value, _currentReplaceIndex++); + xValueCounter += (_shapeWidth + _shapeGap + 1); + } + } + + updateCounter++; + + if (updateCounter >= 1 && !_isPaused) + { + updateCounter = 0; + + if (!_disableRendering) + { + WriteableBitmap bmp = BitmapFactory.New((int)_width, (int)_height); + bmp.Clear(Colors.Transparent); + + Color lineColor = _graphController.dataSeries.GetStrokeColor() != null ? _graphController.dataSeries.GetStrokeColor().Value : _stroke; + Color fillColor = _graphController.dataSeries.GetFillColor() != null ? _graphController.dataSeries.GetFillColor().Value : _fill; + + int right = graphColumns.TotalColumns - currentColumnIndex; + double r_opacity = right > 0 ? 255 / right : 255; + double l_opacity = currentColumnIndex > 0 ? 255 / currentColumnIndex : 255; + + for (int i = 0; i < graphColumns.TotalColumns; i++) + { + var rec = graphColumns.Columns[i]; + Color processedLineColor = lineColor; + Color processedFillColor = fillColor; + + switch (_shapeType) + { + case ShapeTypeEnum.Column: + #region Column + + int calculatedOpacity = 255; + if (_opacityAnimationType == OpacityTypeEnum.FadeOut) + { + byte opacity = (byte)((((rec.X) * 100 / _width) * 255) / 100); + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + else if (_opacityAnimationType == OpacityTypeEnum.CrossFade) + { + if (i < currentColumnIndex && currentColumnIndex > 0) + { + calculatedOpacity = (int)((i + 1) * l_opacity); + } + else + { + calculatedOpacity = (int)(((right) - Math.Abs(currentColumnIndex - (i))) * r_opacity); + } + + byte opacity = (byte)(calculatedOpacity); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + + if (_fillGraph) + { + bmp.FillRectangle(rec.X, rec.Y, rec.Right, rec.Bottom, processedFillColor); + bmp.DrawRectangle(rec.X, rec.Y, rec.Right, rec.Bottom, processedLineColor); + } + else + { + bmp.DrawRectangle(rec.X, rec.Y, rec.Right, rec.Bottom, processedLineColor); + } + #endregion + break; + case ShapeTypeEnum.Circle: + #region Circle + calculatedOpacity = 255; + + if (_opacityAnimationType == OpacityTypeEnum.FadeOut) + { + byte opacity = (byte)((((rec.X) * 100 / _width) * 255) / 100); + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + else if (_opacityAnimationType == OpacityTypeEnum.CrossFade) + { + if (i < currentColumnIndex && currentColumnIndex > 0) + { + calculatedOpacity = (int)((i + 1) * l_opacity); + } + else + { + calculatedOpacity = (int)(((right) - Math.Abs(currentColumnIndex - (i))) * r_opacity); + } + + byte opacity = (byte)(calculatedOpacity); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + + if (_fillGraph) + { + bmp.FillEllipseCentered(rec.X, rec.Y, _shapeWidth, _shapeWidth, processedFillColor); + bmp.DrawEllipseCentered(rec.X, rec.Y, _shapeWidth, _shapeWidth, processedLineColor); + } + else + { + bmp.DrawEllipseCentered(rec.X, rec.Y, _shapeWidth, _shapeWidth, processedLineColor); + } + #endregion + break; + case ShapeTypeEnum.Rectangle: + #region Rectangle + calculatedOpacity = 255; + + if (_opacityAnimationType == OpacityTypeEnum.FadeOut) + { + byte opacity = (byte)((((rec.X) * 100 / _width) * 255) / 100); + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + else if (_opacityAnimationType == OpacityTypeEnum.CrossFade) + { + if (i < currentColumnIndex && currentColumnIndex > 0) + { + calculatedOpacity = (int)((i + 1) * l_opacity); + } + else + { + calculatedOpacity = (int)(((right) - Math.Abs(currentColumnIndex - (i))) * r_opacity); + } + + byte opacity = (byte)(calculatedOpacity); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + + if (_fillGraph) + { + bmp.FillRectangle(rec.X, rec.Y, rec.X + _shapeWidth, rec.Y + _shapeWidth, processedFillColor); + bmp.DrawRectangle(rec.X, rec.Y, rec.X + _shapeWidth, rec.Y + _shapeWidth, processedLineColor); + } + else + { + bmp.DrawRectangle(rec.X, rec.Y, rec.X + _shapeWidth, rec.Y + _shapeWidth, processedLineColor); + } + #endregion + break; + } + + } + + if (_showMarker) + { + bmp.DrawLine((int)(xValueCounter), 0, (int)(xValueCounter), (int)_height, _markerColor); + } + + bmp.Freeze(); + + img.Dispatcher.BeginInvoke(new Action(() => + { + img.Source = bmp; + }), System.Windows.Threading.DispatcherPriority.Send); + } + } + } + } + + #endregion + } +} diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExShapeScroll.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExShapeScroll.cs new file mode 100644 index 000000000..b75fefa35 --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExShapeScroll.cs @@ -0,0 +1,276 @@ +using System; +using System.Collections.Generic; +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 RealTimeGraphEx.Enums; + +namespace RealTimeGraphEx.FastGraphs +{ + public class RealTimeGraphExShapeScroll : RealTimeGraphExLineScroll + { + #region Cross Thread Fields + + protected ShapeTypeEnum _shapeType; + protected int _shapeWidth; + protected int _shapeGap; + protected OpacityTypeEnum _opacityAnimationType; + protected RealTimeGraphColumnsCollection graphColumns; + protected int currentColumnIndex; + + #endregion + + #region Properties + + public ShapeTypeEnum ShapeType + { + get { return (ShapeTypeEnum)GetValue(ShapeTypeProperty); } + set { SetValue(ShapeTypeProperty, value); } + } + public static readonly DependencyProperty ShapeTypeProperty = + DependencyProperty.Register("ShapeType", typeof(ShapeTypeEnum), typeof(RealTimeGraphExShapeScroll), new PropertyMetadata(ShapeTypeEnum.Column, new PropertyChangedCallback(CrossModelChanged))); + + public int ShapeWidth + { + get { return (int)GetValue(ShapeWidthProperty); } + set { SetValue(ShapeWidthProperty, value); } + } + public static readonly DependencyProperty ShapeWidthProperty = + DependencyProperty.Register("ShapeWidth", typeof(int), typeof(RealTimeGraphExShapeScroll), new PropertyMetadata(5, new PropertyChangedCallback(CrossModelChanged))); + + public int ShapeGap + { + get { return (int)GetValue(ShapeGapProperty); } + set { SetValue(ShapeGapProperty, value); } + } + public static readonly DependencyProperty ShapeGapProperty = + DependencyProperty.Register("ShapeGap", typeof(int), typeof(RealTimeGraphExShapeScroll), new PropertyMetadata(1, new PropertyChangedCallback(CrossModelChanged))); + + public OpacityTypeEnum OpacityAnimationType + { + get { return (OpacityTypeEnum)GetValue(OpacityAnimationTypeProperty); } + set { SetValue(OpacityAnimationTypeProperty, value); } + } + public static readonly DependencyProperty OpacityAnimationTypeProperty = + DependencyProperty.Register("OpacityAnimationType", typeof(OpacityTypeEnum), typeof(RealTimeGraphExShapeScroll), new PropertyMetadata(OpacityTypeEnum.None, new PropertyChangedCallback(CrossModelChanged))); + + #endregion + + #region Constructors + + public RealTimeGraphExShapeScroll() + : base() + { + graphColumns = new RealTimeGraphColumnsCollection(); + _graphController = new GraphController(); + } + + #endregion + + #region Override Methods + + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + _shapeType = ShapeType; + _shapeWidth = ShapeWidth; + _shapeGap = ShapeGap; + _opacityAnimationType = OpacityAnimationType; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + protected override void OnClearGraph() + { + graphColumns.ClearColumns(); + currentColumnIndex = 0; + updateCounter = 0; + + base.OnClearGraph(); + } + + protected internal override void OnRenderGraph() + { + if (_graphController != null && _graphController.dataSeries.Points != null && _graphController.dataSeries.Points.Count > 0 && _width > 1 && _height > 1) + { + for (int i = 0; i < _graphController.dataSeries.Points.Count; i++) + { + double value = _graphController.dataSeries.Points[i]; + NormalizeValue(ref value); + double valuePrecentage = ConvertYToImageYFliped(value); + + graphColumns.Add((int)xValueCounter, (int)valuePrecentage, (int)xValueCounter + _shapeWidth, (int)(_maximum - valuePrecentage), (int)value); + xValueCounter += (_shapeWidth + _shapeGap + 1); + + if (xValueCounter > _width) + { + xValueCounter -= (_shapeWidth + _shapeGap + 1); + graphColumns.RemoveFromStart(1); + } + } + + updateCounter++; + + if (updateCounter >= 1 && !_isPaused) + { + updateCounter = 0; + if (!_disableRendering) + { + WriteableBitmap bmp = BitmapFactory.New((int)_width, (int)_height); + bmp.Clear(Colors.Transparent); + + Color lineColor = _graphController.dataSeries.GetStrokeColor() != null ? _graphController.dataSeries.GetStrokeColor().Value : _stroke; + Color fillColor = _graphController.dataSeries.GetFillColor() != null ? _graphController.dataSeries.GetFillColor().Value : _fill; + + int right = graphColumns.TotalColumns - currentColumnIndex; + double r_opacity = right > 0 ? 255 / right : 255; + double l_opacity = currentColumnIndex > 0 ? 255 / currentColumnIndex : 255; + + for (int i = 0; i < graphColumns.TotalColumns; i++) + { + var rec = graphColumns.Columns[i]; + Color processedLineColor = lineColor; + Color processedFillColor = fillColor; + int calculatedOpacity = 255; + + switch (_shapeType) + { + case ShapeTypeEnum.Column: + #region Column + if (_opacityAnimationType == OpacityTypeEnum.FadeOut) + { + byte opacity = (byte)((((rec.X) * 100 / _width) * 255) / 100); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + else if (_opacityAnimationType == OpacityTypeEnum.CrossFade) + { + if (i < currentColumnIndex && currentColumnIndex > 0) + { + calculatedOpacity = (int)((i + 1) * l_opacity); + } + else + { + calculatedOpacity = (int)(((right) - Math.Abs(currentColumnIndex - (i))) * r_opacity); + } + + byte opacity = (byte)(calculatedOpacity); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + + + if (_fillGraph) + { + bmp.FillRectangle(rec.X, rec.Y, rec.Right, rec.Bottom, processedFillColor); + bmp.DrawRectangle(rec.X, rec.Y, rec.Right, rec.Bottom, processedLineColor); + } + else + { + bmp.DrawRectangle(rec.X, rec.Y, rec.Right, rec.Bottom, processedLineColor); + } + #endregion + break; + case ShapeTypeEnum.Circle: + #region Circle + if (_opacityAnimationType == OpacityTypeEnum.FadeOut) + { + byte opacity = (byte)((((rec.X) * 100 / _width) * 255) / 100); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + else if (_opacityAnimationType == OpacityTypeEnum.CrossFade) + { + if (i < currentColumnIndex && currentColumnIndex > 0) + { + calculatedOpacity = (int)((i + 1) * l_opacity); + } + else + { + calculatedOpacity = (int)(((right) - Math.Abs(currentColumnIndex - (i))) * r_opacity); + } + + byte opacity = (byte)(calculatedOpacity); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + + if (_fillGraph) + { + bmp.FillEllipseCentered(rec.X, rec.Y, _shapeWidth, _shapeWidth, processedFillColor); + bmp.DrawEllipseCentered(rec.X, rec.Y, _shapeWidth, _shapeWidth, processedLineColor); + } + else + { + bmp.DrawEllipseCentered(rec.X, rec.Y, _shapeWidth, _shapeWidth, processedLineColor); + } + #endregion + break; + case ShapeTypeEnum.Rectangle: + #region Rectangle + if (_opacityAnimationType == OpacityTypeEnum.FadeOut) + { + byte opacity = (byte)((((rec.X) * 100 / _width) * 255) / 100); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + else if (_opacityAnimationType == OpacityTypeEnum.CrossFade) + { + if (i < currentColumnIndex && currentColumnIndex > 0) + { + calculatedOpacity = (int)((i + 1) * l_opacity); + } + else + { + calculatedOpacity = (int)(((right) - Math.Abs(currentColumnIndex - (i))) * r_opacity); + } + + byte opacity = (byte)(calculatedOpacity); + + processedLineColor.A = opacity; + processedFillColor.A = opacity; + } + + if (_fillGraph) + { + bmp.FillRectangle(rec.X, rec.Y, rec.X + _shapeWidth, rec.Y + _shapeWidth, processedFillColor); + bmp.DrawRectangle(rec.X, rec.Y, rec.X + _shapeWidth, rec.Y + _shapeWidth, processedLineColor); + } + else + { + bmp.DrawRectangle(rec.X, rec.Y, rec.X + _shapeWidth, rec.Y + _shapeWidth, processedLineColor); + } + #endregion + break; + } + + } + + bmp.Freeze(); + + img.Dispatcher.BeginInvoke(new Action(() => + { + img.Source = bmp; + }), System.Windows.Threading.DispatcherPriority.Send); + } + } + } + } + + #endregion + } +} diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExWaveErase.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExWaveErase.cs new file mode 100644 index 000000000..06ef8ffa0 --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExWaveErase.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace RealTimeGraphEx.FastGraphs +{ + public class RealTimeGraphExWaveErase : RealTimeGraphExLineErase + { + #region Constructors + + public RealTimeGraphExWaveErase() + : base() + { + + } + + #endregion + + #region Override Methods + + /// + /// Set the cross thread fields. + /// + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + + _minimum = _maximum * -1; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + /// + /// Draw the actual polygon on the image. + /// + /// + protected override void OnDrawVisuals(WriteableBitmap bmp) + { + Color stroke = _graphController.dataSeries.GetStrokeColor() != null ? _graphController.dataSeries.GetStrokeColor().Value : _stroke; + Color fill = _graphController.dataSeries.GetFillColor() != null ? _graphController.dataSeries.GetFillColor().Value : _fill; + double scale = GetPolygonScaleFactor(); + double currentWidth = _endReached ? _width : xValueCounter; + + + if (_fillGraph) //Fill Graph + { + bmp.FillPolygon(graphPolygon.ToPolygonPointsWaveFill(_offSetX, _offSetY, _width, _height, scale, ConvertYToImageYFliped), fill); + } + + DrawPolyline(bmp, graphPolygon.ToPolygonPoints(_offSetX, _offSetY, scale, ConvertYToImageYFliped), stroke); + DrawPolyline(bmp, graphPolygon.ToPolygonPointsReflection(_offSetX, _offSetY, _height, scale, ConvertYToImageYFliped), stroke); + + //Draw marker + if (_showMarker) + { + if (_currentReplaceIndex > 0) + { + double x = ((_currentReplaceIndex * scale) + _offSetX); + bmp.DrawLine((int)x, 0, (int)x, (int)_mainHeight, _markerColor); + } + } + + if (_enableMarkerPosition) + { + MarkerPosition = new Point((_currentReplaceIndex * scale) + _offSetX, ConvertYToImageYFliped(lastVirtualValue) + _offSetY); + } + } + + #endregion + } +} diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExWaveScroll.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExWaveScroll.cs new file mode 100644 index 000000000..52e9e2095 --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExWaveScroll.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace RealTimeGraphEx.FastGraphs +{ + /// + /// Represents a real-time graph with a single scrollable wave form. + /// + public class RealTimeGraphExWaveScroll : RealTimeGraphExLineScroll + { + #region Constructors + + public RealTimeGraphExWaveScroll() + : base() + { + + } + + #endregion + + #region Override Methods + + /// + /// Set the cross thread fields. + /// + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + + _minimum = _maximum * -1; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + /// + /// Draw the actual polygon on the image. + /// + /// + protected override void OnDrawVisuals(WriteableBitmap bmp) + { + Color stroke = _graphController.dataSeries.GetStrokeColor() != null ? _graphController.dataSeries.GetStrokeColor().Value : _stroke; + Color fill = _graphController.dataSeries.GetFillColor() != null ? _graphController.dataSeries.GetFillColor().Value : _fill; + + double scale = GetPolygonScaleFactor(); + + if (_fillGraph) //Fill Graph + { + bmp.FillPolygon(graphPolygon.ToPolygonPointsWaveFill(_offSetX, _offSetY, _width, _height, scale, ConvertYToImageYFliped), fill); + } + + DrawPolyline(bmp, graphPolygon.ToPolygonPoints(_offSetX, _offSetY, scale, ConvertYToImageYFliped), stroke); + DrawPolyline(bmp, graphPolygon.ToPolygonPointsReflection(_offSetX, _offSetY, _height, scale, ConvertYToImageYFliped), stroke); + } + + #endregion + } +} diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/ShapeTypeEnum.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/ShapeTypeEnum.cs new file mode 100644 index 000000000..7e270c9cf --- /dev/null +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/ShapeTypeEnum.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace RealTimeGraphEx.FastGraphs +{ + public enum ShapeTypeEnum + { + Column, + Rectangle, + Circle, + } +} -- cgit v1.3.1 From d36a5ab7115ec53405622e4437cd3f8f615d515d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 24 Jan 2018 19:32:14 +0200 Subject: Added support for multi sensor frame on developer module graph. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 8388608 -> 8388608 bytes .../ViewModels/MainViewVM.cs | 44 +++++++-- .../Controls/IRealTimeGraph.cs | 48 +++++++++ .../Controls/RealTimeGraphControl.xaml | 2 +- .../Controls/RealTimeGraphControl.xaml.cs | 15 ++- .../Controls/RealTimeGraphMultiControl.xaml | 95 ++++++++++++++++++ .../Controls/RealTimeGraphMultiControl.xaml.cs | 107 +++++++++++++++++++++ .../Resources/MaterialDesign.xaml | 40 ++++++++ .../Tango.MachineStudio.Common.csproj | 8 ++ .../FastGraphs/RealTimeGraphExLineScroll.cs | 12 --- .../RealTimeGraphEx/RealTimeGraphExBase.cs | 11 +++ .../RealTimeGraphEx/RealTimeGraphExMultiBase.cs | 12 --- .../Tango.Core/Helpers/ColorHelper.cs | 11 +++ 14 files changed, 370 insertions(+), 35 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/IRealTimeGraph.cs create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml.cs (limited to 'Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 27da03f9b..875b88771 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index bdff96627..3a65c84fa 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 590474f9d..dc3ba0ec5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -1,10 +1,13 @@ using GalaSoft.MvvmLight.Ioc; +using RealTimeGraphEx.Controllers; +using RealTimeGraphEx.DataSeries; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Media; using Tango.Core.Commands; using Tango.DAL.Observables; using Tango.MachineStudio.Common.Controls; @@ -124,11 +127,11 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _availableSensors = value; RaisePropertyChangedAuto(); } } - private ObservableCollection _graphs; + private ObservableCollection _graphs; /// /// Gets or sets the collection of displayed graph controls. /// - public ObservableCollection Graphs + public ObservableCollection Graphs { get { return _graphs; } set { _graphs = value; RaisePropertyChangedAuto(); } @@ -180,7 +183,7 @@ namespace Tango.MachineStudio.Developer.ViewModels AvailableSensors = Adapter.Sensors.ToObservableCollection(); } - Graphs = new ObservableCollection(); + Graphs = new ObservableCollection(); } /// @@ -338,16 +341,39 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (Graphs.Count < 8) { - RealTimeGraphControl graphControl = new RealTimeGraphControl(); + IRealTimeGraph graphControl = null; + + if (!sensor.MultiChannel) + { + graphControl = new RealTimeGraphControl(); + } + else + { + graphControl = new RealTimeGraphMultiControl(); + GraphMultiController controller = new GraphMultiController(); + + for (int i = 0; i < sensor.ChannelCount; i++) + { + controller.AddSeries(new DataYSeries() + { + Name = sensor.Description.First().ToString() + (i + 1), + UseFillAndStroke = true, + Stroke = new SolidColorBrush(Core.Helpers.ColorHelper.GetRandomColor()) + }); + } + + graphControl.Controller = controller; + } + graphControl.Tag = sensor; graphControl.SensorName = sensor.Description; graphControl.SensorUnits = sensor.Units; - graphControl.Graph.Minimum = sensor.Min; - graphControl.Graph.Maximum = sensor.Max; - graphControl.Graph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(sensor.PointsPerFrame); + graphControl.InnerGraph.Minimum = sensor.Min; + graphControl.InnerGraph.Maximum = sensor.Max; + graphControl.InnerGraph.MaxPoints = Common.Helpers.GraphsHelper.GetMaxPoints(sensor.PointsPerFrame); graphControl.GraphRemoveButtonPressed += (sender, __) => { - RemoveGraph(sender as RealTimeGraphControl); + RemoveGraph(sender as IRealTimeGraph); }; Graphs.Add(graphControl); AvailableSensors.Remove(sensor); @@ -362,7 +388,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// Removes the graph. /// /// The graph. - public void RemoveGraph(RealTimeGraphControl graph) + public void RemoveGraph(IRealTimeGraph graph) { Graphs.Remove(graph); AvailableSensors.Insert(0, graph.Tag as Sensor); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/IRealTimeGraph.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/IRealTimeGraph.cs new file mode 100644 index 000000000..5ca930c91 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/IRealTimeGraph.cs @@ -0,0 +1,48 @@ +using RealTimeGraphEx; +using RealTimeGraphEx.Controllers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Common.Controls +{ + public interface IRealTimeGraph + { + /// + /// Gets or sets the name of the sensor. + /// + String SensorName { get; set; } + + /// + /// Gets or sets the tag. + /// + Object Tag { get; set; } + + /// + /// Gets or sets the sensor units. + /// + String SensorUnits { get; set; } + + /// + /// Occurs when the graph remove button has been pressed. + /// + event EventHandler GraphRemoveButtonPressed; + + /// + /// Occurs when the graph full screen button has been pressed. + /// + event EventHandler GraphFullScreenButtonPressed; + + /// + /// Gets or sets the inner real-time graph control. + /// + RealTimeGraphExBase InnerGraph { get; set; } + + /// + /// Gets or sets the inner graph controller. + /// + GraphControllerBase Controller { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml index 687bc6030..449cea493 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml @@ -67,7 +67,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml.cs index 6396ab91a..359e52823 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphControl.xaml.cs @@ -14,13 +14,15 @@ using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using RealTimeGraphEx; +using RealTimeGraphEx.Controllers; namespace Tango.MachineStudio.Common.Controls { /// /// Interaction logic for RealTimeGraphControl.xaml /// - public partial class RealTimeGraphControl : UserControl + public partial class RealTimeGraphControl : UserControl, IRealTimeGraph { #region Properties @@ -46,6 +48,15 @@ namespace Tango.MachineStudio.Common.Controls public static readonly DependencyProperty SensorUnitsProperty = DependencyProperty.Register("SensorUnits", typeof(String), typeof(RealTimeGraphControl), new PropertyMetadata(null)); + /// + /// Gets or sets the inner real-time graph control. + /// + public RealTimeGraphExBase InnerGraph { get; set; } + + /// + /// Gets or sets the inner graph controller. + /// + public GraphControllerBase Controller { get; set; } #endregion @@ -59,6 +70,8 @@ namespace Tango.MachineStudio.Common.Controls public RealTimeGraphControl() { InitializeComponent(); + InnerGraph = Graph; + Controller = new GraphController(); } private void OnGraphFullScreen(object sender, RoutedEventArgs e) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml new file mode 100644 index 000000000..23573e574 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml.cs new file mode 100644 index 000000000..5cb69b786 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/RealTimeGraphMultiControl.xaml.cs @@ -0,0 +1,107 @@ +using RealTimeGraphEx; +using RealTimeGraphEx.Controllers; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.Common.Controls +{ + /// + /// Interaction logic for RealTimeGraphControl.xaml + /// + public partial class RealTimeGraphMultiControl : UserControl , IRealTimeGraph + { + #region Properties + + /// + /// Gets or sets the name of the sensor. + /// + public String SensorName + { + get { return (String)GetValue(SensorNameProperty); } + set { SetValue(SensorNameProperty, value); } + } + public static readonly DependencyProperty SensorNameProperty = + DependencyProperty.Register("SensorName", typeof(String), typeof(RealTimeGraphMultiControl), new PropertyMetadata(null)); + + /// + /// Gets or sets the sensor units. + /// + public String SensorUnits + { + get { return (String)GetValue(SensorUnitsProperty); } + set { SetValue(SensorUnitsProperty, value); } + } + public static readonly DependencyProperty SensorUnitsProperty = + DependencyProperty.Register("SensorUnits", typeof(String), typeof(RealTimeGraphMultiControl), new PropertyMetadata(null)); + + /// + /// Gets or sets the inner real-time graph control. + /// + public RealTimeGraphExBase InnerGraph { get; set; } + + /// + /// Gets or sets the inner graph controller. + /// + public GraphControllerBase Controller { get; set; } + + #endregion + + #region Events + + public event EventHandler GraphRemoveButtonPressed; + public event EventHandler GraphFullScreenButtonPressed; + + #endregion + + public RealTimeGraphMultiControl() + { + InitializeComponent(); + InnerGraph = Graph; + Controller = new GraphMultiController(); + } + + private void OnGraphFullScreen(object sender, RoutedEventArgs e) + { + GraphFullScreenButtonPressed?.Invoke(this, new EventArgs()); + } + + private void Graph_MouseEnter(object sender, MouseEventArgs e) + { + Grid mainGrid = sender as Grid; + var headerGrid = mainGrid.Children.OfType().ToList().First(); + ThicknessAnimation ani = new ThicknessAnimation(); + ani.To = new Thickness(0, 0, 0, 0); + ani.Duration = TimeSpan.FromSeconds(0.2); + headerGrid.BeginAnimation(Grid.MarginProperty, ani); + } + + private void Graph_MouseLeave(object sender, MouseEventArgs e) + { + Grid mainGrid = sender as Grid; + var headerGrid = mainGrid.Children.OfType().ToList().First(); + ThicknessAnimation ani = new ThicknessAnimation(); + ani.To = new Thickness(0, -35, 0, 0); + ani.Duration = TimeSpan.FromSeconds(0.2); + headerGrid.BeginAnimation(Grid.MarginProperty, ani); + } + + private void OnGraphRemove(object sender, RoutedEventArgs e) + { + GraphRemoveButtonPressed?.Invoke(this, new EventArgs()); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml index cc18c31c5..8c5464930 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml @@ -267,6 +267,46 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index b89ec2e09..bc7f00d58 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -71,6 +71,10 @@ + + + RealTimeGraphMultiControl.xaml + RealTimeGraphControl.xaml @@ -103,6 +107,10 @@ + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineScroll.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineScroll.cs index 216683d39..a2260030c 100644 --- a/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineScroll.cs +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs/RealTimeGraphExLineScroll.cs @@ -40,18 +40,6 @@ namespace RealTimeGraphEx.FastGraphs #region Properties - /// - /// Gets or sets the maximum vectorsCollection to display on the graph (default 1000, affects performance). - /// - public int MaxPoints - { - get { return (int)GetValue(MaxPointsProperty); } - set { SetValue(MaxPointsProperty, value); } - } - public static readonly DependencyProperty MaxPointsProperty = - DependencyProperty.Register("MaxPoints", typeof(int), typeof(RealTimeGraphExLineScroll), new PropertyMetadata(1000, new PropertyChangedCallback(CrossModelChanged))); - - /// /// Gets or sets the graph fill color. /// diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/RealTimeGraphExBase.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/RealTimeGraphExBase.cs index cf8d6c0fe..c1ed37474 100644 --- a/Software/Visual_Studio/SideChains/RealTimeGraphEx/RealTimeGraphExBase.cs +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/RealTimeGraphExBase.cs @@ -349,6 +349,17 @@ namespace RealTimeGraphEx public static readonly DependencyProperty ZoomDirectionProperty = DependencyProperty.Register("ZoomDirection", typeof(ZoomDirectionEnum), typeof(RealTimeGraphExBase), new PropertyMetadata(ZoomDirectionEnum.Both)); + /// + /// Gets or sets the maximum points to display on the graph (default 1000). + /// + public int MaxPoints + { + get { return (int)GetValue(MaxPointsProperty); } + set { SetValue(MaxPointsProperty, value); } + } + public static readonly DependencyProperty MaxPointsProperty = + DependencyProperty.Register("MaxPoints", typeof(int), typeof(RealTimeGraphExBase), new PropertyMetadata(1000, new PropertyChangedCallback(CrossModelChanged))); + #endregion #region Cross Thread Fields diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/RealTimeGraphExMultiBase.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/RealTimeGraphExMultiBase.cs index d9edc478e..108ff4ea3 100644 --- a/Software/Visual_Studio/SideChains/RealTimeGraphEx/RealTimeGraphExMultiBase.cs +++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/RealTimeGraphExMultiBase.cs @@ -22,18 +22,6 @@ namespace RealTimeGraphEx #region Properties - /// - /// Gets or sets the maximum points to display on the graph (default 1000). - /// - public int MaxPoints - { - get { return (int)GetValue(MaxPointsProperty); } - set { SetValue(MaxPointsProperty, value); } - } - public static readonly DependencyProperty MaxPointsProperty = - DependencyProperty.Register("MaxPoints", typeof(int), typeof(RealTimeGraphExMultiBase), new PropertyMetadata(1000, new PropertyChangedCallback(CrossModelChanged))); - - /// /// Gets or sets the collection of data series to display on the graph. /// diff --git a/Software/Visual_Studio/Tango.Core/Helpers/ColorHelper.cs b/Software/Visual_Studio/Tango.Core/Helpers/ColorHelper.cs index c5ebc7474..3d0532985 100644 --- a/Software/Visual_Studio/Tango.Core/Helpers/ColorHelper.cs +++ b/Software/Visual_Studio/Tango.Core/Helpers/ColorHelper.cs @@ -12,6 +12,8 @@ namespace Tango.Core.Helpers /// public static class ColorHelper { + private static Random rnd = new Random(); + /// /// Converts the specified color to integer. /// @@ -36,5 +38,14 @@ namespace Tango.Core.Helpers byte b = (byte)(integer >> 0); return Color.FromArgb(a, r, g, b); } + + /// + /// Returns a random color. + /// + /// + public static Color GetRandomColor() + { + return Color.FromRgb((byte)rnd.Next(256), (byte)rnd.Next(256), (byte)rnd.Next(256)); + } } } -- cgit v1.3.1