diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-01-16 12:17:10 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-01-16 12:17:10 +0200 |
| commit | 0fda2ba3ff49bdc1ffc6833f658e2164af187008 (patch) | |
| tree | 6f3a24d0671ebda50debb8511ab40e0bda0a0df0 /Software/Visual_Studio/SideChains/RealTimeGraphEx/FastGraphs | |
| parent | 28103646681686bf1b58275d5dbccb92d2b26f9f (diff) | |
| download | Tango-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/FastGraphs')
10 files changed, 1853 insertions, 0 deletions
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); + } + + /// <summary> + /// Draw the actual polygon on the image. + /// </summary> + /// <param name="bmp"></param> + 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 + + /// <summary> + /// Gets or sets the graph marker color. + /// </summary> + 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))); + + /// <summary> + /// Gets or sets whether to display the marker on the graph. + /// </summary> + 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))); + + /// <summary> + /// Gets or sets a value indicating whether to enable the MarkerPosition property to be updated. (Affects performance). + /// </summary> + 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))); + + /// <summary> + /// Gets the current marker position on the graph. + /// </summary> + 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 +{ + /// <summary> + /// Represents a real-time graph with a single scrollable line. + /// </summary> + 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<double> _markers; + + #endregion + + #region Properties + + /// <summary> + /// Gets or sets the maximum vectorsCollection to display on the graph (default 1000, affects performance). + /// </summary> + 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))); + + + /// <summary> + /// Gets or sets the graph fill color. + /// </summary> + 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))); + + /// <summary> + /// Gets or sets the graph fill color. + /// </summary> + 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))); + + /// <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(RealTimeGraphExLineScroll), new PropertyMetadata(false, new PropertyChangedCallback(CrossModelChanged))); + + + /// <summary> + /// Gets or sets the IDataSeries used to push data vectorsCollection to the graph. + /// </summary> + 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<double>(); + } + + #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() + { + + } + + /// <summary> + /// Calculate the scaling factor for the current graph width. + /// </summary> + /// <returns></returns> + protected virtual double GetPolygonScaleFactor() + { + return _width / (graphPolygon.Count - 1); + } + + /// <summary> + /// Draw the actual polygon on the image. + /// </summary> + /// <param name="bmp"></param> + [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 + + + /// <summary> + /// Gets or sets the graph marker color. + /// </summary> + 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))); + + /// <summary> + /// Gets or sets whether to display the marker on the graph. + /// </summary> + 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<ConcurrentpointsList> _graphPolygons; + protected Color _stroke; + protected Color _fill; + protected bool _fillGraph; + protected List<double> _markers; + + #endregion + + #region Constructors + + public RealTimeGraphExMultiLineScroll() + : base() + { + _graphPolygons = new List<ConcurrentpointsList>(); + _graphController = new GraphMultiController(); + _markers = new List<double>(); + } + + #endregion + + #region Properties + + /// <summary> + /// Gets or sets the graph strokes color. + /// </summary> + 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))); + + /// <summary> + /// Gets or sets the graph fill color. + /// </summary> + 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))); + + /// <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(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<double> 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 + + /// <summary> + /// Gets or sets the graph marker color. + /// </summary> + 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))); + + /// <summary> + /// Gets or sets whether to display the marker on the graph. + /// </summary> + 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 + + /// <summary> + /// Set the cross thread fields. + /// </summary> + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + + _minimum = _maximum * -1; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + /// <summary> + /// Draw the actual polygon on the image. + /// </summary> + /// <param name="bmp"></param> + 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 +{ + /// <summary> + /// Represents a real-time graph with a single scrollable wave form. + /// </summary> + public class RealTimeGraphExWaveScroll : RealTimeGraphExLineScroll + { + #region Constructors + + public RealTimeGraphExWaveScroll() + : base() + { + + } + + #endregion + + #region Override Methods + + /// <summary> + /// Set the cross thread fields. + /// </summary> + protected override void OnSetCrossThreadFields() + { + base.OnSetCrossThreadFields(); + + this.Dispatcher.Invoke(() => + { + + _minimum = _maximum * -1; + + }, System.Windows.Threading.DispatcherPriority.Send); + } + + /// <summary> + /// Draw the actual polygon on the image. + /// </summary> + /// <param name="bmp"></param> + 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, + } +} |
