From 7e8ff4c3ca798d426eb6f381c5312a747f1bb800 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 28 Jan 2018 19:40:35 +0200 Subject: Implemented all color spaces on segment brushes (simple conversion). Embedded ColorMine library as a SideChain. --- .../Converters/BrushStopCMYKToColorConverter.cs | 53 +++++ .../Converters/BrushStopLabToColorConverter.cs | 52 +++++ .../Converters/BrushStopToColorConverter.cs | 44 ++++ .../Tango.MachineStudio.Developer.csproj | 11 + .../Views/MainView.xaml | 229 ++++++++++++++++++--- .../Views/MainView.xaml.cs | 3 + 6 files changed, 361 insertions(+), 31 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopCMYKToColorConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopLabToColorConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToColorConverter.cs (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopCMYKToColorConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopCMYKToColorConverter.cs new file mode 100644 index 000000000..e21da8fbc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopCMYKToColorConverter.cs @@ -0,0 +1,53 @@ +using ColorMine.ColorSpaces; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; +using Tango.DAL.Observables; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class BrushStopCMYKToColorConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + try + { + Cmyk cmyk = new Cmyk(); + + cmyk.C = System.Convert.ToDouble(values[0]) / 100d; + cmyk.M = System.Convert.ToDouble(values[1]) / 100d; + cmyk.Y = System.Convert.ToDouble(values[2]) / 100d; + cmyk.K = System.Convert.ToDouble(values[3]) / 100d; + + IRgb rgb = cmyk.ToRgb(); + + return Color.FromRgb((byte)rgb.R, (byte)rgb.G, (byte)rgb.B); + } + catch + { + return null; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + try + { + Color color = (Color)value; + Rgb rgb = new Rgb(color.R, color.G, color.B); + Cmyk cmyk = rgb.To(); + + return new object[] { cmyk.C * 100, cmyk.M * 100, cmyk.Y * 100, cmyk.K * 100 }; + } + catch + { + return null; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopLabToColorConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopLabToColorConverter.cs new file mode 100644 index 000000000..6c6d7959e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopLabToColorConverter.cs @@ -0,0 +1,52 @@ +using ColorMine.ColorSpaces; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; +using Tango.DAL.Observables; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class BrushStopLabToColorConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + try + { + Lab lab = new Lab(); + + lab.L = System.Convert.ToDouble(values[0]); + lab.A = System.Convert.ToDouble(values[1]); + lab.B = System.Convert.ToDouble(values[2]); + + IRgb rgb = lab.ToRgb(); + + return Color.FromRgb((byte)rgb.R, (byte)rgb.G, (byte)rgb.B); + } + catch + { + return null; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + try + { + Color color = (Color)value; + Rgb rgb = new Rgb(color.R, color.G, color.B); + Lab cmyk = rgb.To(); + + return new object[] { cmyk.L, cmyk.A, cmyk.B }; + } + catch + { + return null; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToColorConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToColorConverter.cs new file mode 100644 index 000000000..5db8d03c0 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToColorConverter.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; +using System.Windows.Media; +using Tango.DAL.Observables; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class BrushStopToColorConverter : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + try + { + double r = System.Convert.ToDouble(values[0]); + double g = System.Convert.ToDouble(values[1]); + double b = System.Convert.ToDouble(values[2]); + + return Color.FromRgb((byte)r, (byte)g, (byte)b); + } + catch + { + return null; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + try + { + Color color = (Color)value; + return new object[] { color.R, color.G, color.B }; + } + catch + { + return null; + } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index dc3f9947a..2bbd57b86 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -71,6 +71,9 @@ + + + @@ -117,10 +120,18 @@ + + {37e4ceab-b54b-451f-b535-04cf7da9c459} + ColorMine + {b9ae25d6-be35-492f-9079-21a7f3e6f7cc} RealTimeGraphEx + + {a2f5af44-29ff-45d6-9d25-ecda5cce88b5} + Tango.ColorPicker + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index e7aa85fb8..73c00fea8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -7,6 +7,7 @@ xmlns:global="clr-namespace:Tango.MachineStudio.Developer" xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" + xmlns:colorPicker="clr-namespace:Tango;assembly=Tango.ColorPicker" xmlns:db="clr-namespace:Tango.MachineStudio.DB.Views.DBViews;assembly=Tango.MachineStudio.DB" xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls;assembly=Tango.MachineStudio.Common" xmlns:designer="clr-namespace:Tango.MachineStudio.MachineDesigner.Views;assembly=Tango.MachineStudio.MachineDesigner" @@ -22,7 +23,7 @@ @@ -31,6 +32,9 @@ + + + @@ -291,7 +295,7 @@ - + @@ -311,10 +315,10 @@ - - @@ -488,10 +492,10 @@ - - @@ -527,31 +531,189 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + @@ -772,6 +934,11 @@ + + + + Show Graphs + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs index 9eeff4975..c4e853433 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml.cs @@ -42,6 +42,9 @@ namespace Tango.MachineStudio.Developer.Views { _vm = DataContext as MainViewVM; }; + + chkGraphs.Checked += (x, y) => { graphRowDefinition.Height = new GridLength(161, GridUnitType.Star); }; + chkGraphs.Unchecked += (x, y) => { graphRowDefinition.Height = new GridLength(80, GridUnitType.Pixel); }; } private void OnDropAvailableSensor(object sender, DropEventArgs e) -- cgit v1.3.1