aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-01-16 12:17:10 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-01-16 12:17:10 +0200
commit0fda2ba3ff49bdc1ffc6833f658e2164af187008 (patch)
tree6f3a24d0671ebda50debb8511ab40e0bda0a0df0 /Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods
parent28103646681686bf1b58275d5dbccb92d2b26f9f (diff)
downloadTango-0fda2ba3ff49bdc1ffc6833f658e2164af187008.tar.gz
Tango-0fda2ba3ff49bdc1ffc6833f658e2164af187008.zip
Embedded RealTimeGraphEx library to solution.
Added graphs to technician view. Implemented simple sensors data test using Machine Emulator.
Diffstat (limited to 'Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods')
-rw-r--r--Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/BrushExtensions.cs72
-rw-r--r--Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/ColorExtensions.cs18
-rw-r--r--Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/RenderTargetExtensions.cs83
3 files changed, 173 insertions, 0 deletions
diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/BrushExtensions.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/BrushExtensions.cs
new file mode 100644
index 000000000..9a474427a
--- /dev/null
+++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/BrushExtensions.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media;
+
+namespace RealTimeGraphEx.ExtensionMethods
+{
+ public static class BrushExtensions
+ {
+ public static SharpDX.Direct2D1.Brush ToDxBrush(this Brush brush, SharpDX.Direct2D1.RenderTarget renderTarget)
+ {
+ if (brush == null) return null;
+
+ if (brush.GetType() == typeof(SolidColorBrush))
+ {
+ return new SharpDX.Direct2D1.SolidColorBrush(renderTarget, new SharpDX.Color4((brush as SolidColorBrush).Color.ToRgba()), new SharpDX.Direct2D1.BrushProperties() { Opacity = (float)brush.Opacity });
+ }
+ else if (brush.GetType() == typeof(LinearGradientBrush))
+ {
+ var linear = brush as LinearGradientBrush;
+ var startPoint = new SharpDX.Vector2((float)linear.StartPoint.X, (float)linear.StartPoint.Y);
+ var endPoint = new SharpDX.Vector2((float)linear.EndPoint.X, (float)linear.EndPoint.Y);
+ SharpDX.Direct2D1.GradientStop[] stops = new SharpDX.Direct2D1.GradientStop[linear.GradientStops.Count];
+
+ for (int i = 0; i < linear.GradientStops.Count; i++)
+ {
+ stops[i] = new SharpDX.Direct2D1.GradientStop();
+ stops[i].Color = new SharpDX.Color4(linear.GradientStops[i].Color.ToRgba());
+ stops[i].Position = (float)linear.GradientStops[i].Offset;
+ }
+
+ var dxBrush = new SharpDX.Direct2D1.LinearGradientBrush(
+ renderTarget,
+ new SharpDX.Direct2D1.LinearGradientBrushProperties()
+ {
+ StartPoint = startPoint,
+ EndPoint = endPoint,
+ },
+ new SharpDX.Direct2D1.GradientStopCollection(renderTarget, stops));
+
+ return dxBrush;
+
+ // var linearGradientBrush = new SharpDX.Direct2D1.LinearGradientBrush(renderTarget, new SharpDX.Direct2D1.LinearGradientBrushProperties()
+ // {
+ // StartPoint = new SharpDX.Vector2(50, 0),
+ // EndPoint = new SharpDX.Vector2(450, 0),
+ // },
+ //new SharpDX.Direct2D1.GradientStopCollection(renderTarget, new SharpDX.Direct2D1.GradientStop[]
+ // {
+ // new SharpDX.Direct2D1.GradientStop()
+ // {
+ // Color = SharpDX.Color.Blue,
+ // Position = 0,
+ // },
+ // new SharpDX.Direct2D1.GradientStop()
+ // {
+ // Color = SharpDX.Color.Green,
+ // Position = 1,
+ // }
+ // }));
+
+ // return linearGradientBrush;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+}
diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/ColorExtensions.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/ColorExtensions.cs
new file mode 100644
index 000000000..989ff8fa9
--- /dev/null
+++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/ColorExtensions.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media;
+
+namespace RealTimeGraphEx.ExtensionMethods
+{
+ public static class ColorExtensions
+ {
+ public static int ToRgba(this Color color)
+ {
+ byte[] bytes = new byte[] { color.R, color.G, color.B, color.A };
+ return BitConverter.ToInt32(bytes, 0);
+ }
+ }
+}
diff --git a/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/RenderTargetExtensions.cs b/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/RenderTargetExtensions.cs
new file mode 100644
index 000000000..fcedc6083
--- /dev/null
+++ b/Software/Visual_Studio/SideChains/RealTimeGraphEx/ExtensionMethods/RenderTargetExtensions.cs
@@ -0,0 +1,83 @@
+using SharpDX;
+using SharpDX.Direct2D1;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RealTimeGraphEx.ExtensionMethods
+{
+ public static class RenderTargetExtensions
+ {
+ public static void DrawPolygon(this RenderTarget target, SharpDX.Direct2D1.Factory factory, Brush stroke, double strokeWidth, Vector2[] vectors)
+ {
+ PathGeometry geo = new PathGeometry(factory);
+ GeometrySink sink1;
+ sink1 = geo.Open();
+ sink1.BeginFigure(vectors[0], new FigureBegin());
+ sink1.AddLines(vectors);
+ sink1.EndFigure(new FigureEnd());
+ sink1.Close();
+
+ target.DrawGeometry(geo, stroke, (float)strokeWidth);
+
+ vectors = null;
+ geo.Dispose();
+ sink1.Dispose();
+ stroke.Dispose();
+ }
+
+ public static void DrawMultiPolygon(this RenderTarget target, SharpDX.Direct2D1.Factory factory, List<Brush> strokes, double strokeWidth, List<Vector2[]> vectorsCollection)
+ {
+ List<PathGeometry> geos = new List<PathGeometry>();
+ List<GeometrySink> sinks = new List<GeometrySink>();
+
+ foreach (var vectors in vectorsCollection)
+ {
+ var geo = new PathGeometry(factory);
+ GeometrySink sink1;
+ sink1 = geo.Open();
+ sink1.BeginFigure(vectors[0], new FigureBegin());
+ sink1.AddLines(vectors);
+ sink1.EndFigure(new FigureEnd());
+ sink1.Close();
+
+ geos.Add(geo);
+ sinks.Add(sink1);
+ }
+
+ for (int i = 0; i < geos.Count; i++)
+ {
+ target.DrawGeometry(geos[i], strokes[i], (float)strokeWidth);
+ }
+
+ vectorsCollection = null;
+
+ for (int i = 0; i < strokes.Count; i++)
+ {
+ geos[i].Dispose();
+ sinks[i].Dispose();
+ strokes[i].Dispose();
+ }
+ }
+
+ public static void FillPolygon(this RenderTarget target, SharpDX.Direct2D1.Factory factory, Brush fill, Vector2[] vectors)
+ {
+ PathGeometry geo = new PathGeometry(factory);
+ GeometrySink sink1;
+ sink1 = geo.Open();
+ sink1.BeginFigure(vectors[0], new FigureBegin());
+ sink1.AddLines(vectors);
+ sink1.EndFigure(new FigureEnd());
+ sink1.Close();
+
+ target.FillGeometry(geo, fill);
+
+ vectors = null;
+ geo.Dispose();
+ sink1.Dispose();
+ fill.Dispose();
+ }
+ }
+}