diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-14 14:56:16 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-06-14 14:56:16 +0300 |
| commit | 099cb04861e293cf675d8b5216448a766eef7954 (patch) | |
| tree | 29c9cd2cb877e8b44d51dbc1b755c9a81cf300b9 /Software/Visual_Studio | |
| parent | 03959e785f635697fcdf0f99aad9454fafbf4e2e (diff) | |
| download | Tango-099cb04861e293cf675d8b5216448a766eef7954.tar.gz Tango-099cb04861e293cf675d8b5216448a766eef7954.zip | |
Implemented new fast job pie chart rendering using GDI!
Diffstat (limited to 'Software/Visual_Studio')
14 files changed, 156 insertions, 6 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj index 3d8fe79c7..004ee9bdf 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj @@ -45,6 +45,7 @@ </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> + <Reference Include="System.Drawing" /> <Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <HintPath>..\..\..\packages\Expression.Blend.Sdk.1.0.2\lib\net45\System.Windows.Interactivity.dll</HintPath> </Reference> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Converters/JobToPieImageConverter.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Converters/JobToPieImageConverter.cs new file mode 100644 index 000000000..cc11fd427 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Converters/JobToPieImageConverter.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using Tango.BL.Entities; + +namespace Tango.PPC.Jobs.Converters +{ + public class JobToPieImageConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + Job job = value as Job; + + if (job != null) + { + String[] param = parameter.ToString().Split(','); + double width = double.Parse(param[0]); + double height = double.Parse(param[1]); + return job.CreateSegmentsPie(width, height); + } + + return null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj index 0f5a698d0..23af09c6a 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj @@ -85,6 +85,7 @@ <Compile Include="..\..\..\Versioning\PPCVersionInfo.cs"> <Link>PPCVersionInfo.cs</Link> </Compile> + <Compile Include="Converters\JobToPieImageConverter.cs" /> <Compile Include="JobsModule.cs" /> <Compile Include="Properties\AssemblyInfo.cs"> <SubType>Code</SubType> diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml index d540ae726..56c444fb7 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml @@ -6,7 +6,7 @@ xmlns:local="clr-namespace:Tango.PPC.Jobs.Views" xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" xmlns:keyboard="clr-namespace:Tango.Touch.Keyboard;assembly=Tango.Touch" - xmlns:converters="clr-namespace:Tango.PPC.Common.Converters;assembly=Tango.PPC.Common" + xmlns:converters="clr-namespace:Tango.PPC.Jobs.Converters" xmlns:touch="clr-namespace:Tango.Touch.Controls;assembly=Tango.Touch" xmlns:touchComponents="clr-namespace:Tango.Touch.Components;assembly=Tango.Touch" xmlns:fa="http://schemas.fontawesome.io/icons/" @@ -20,9 +20,10 @@ d:DesignHeight="1280" d:DesignWidth="800" d:DataContext="{d:DesignInstance Type=vm:JobsViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.JobsViewVM}"> <UserControl.Resources> - <converters:SegmentsToPieConverter x:Key="SegmentsToPieConverter" /> + <converters:JobToPieImageConverter x:Key="JobToPieImageConverter" /> <sharedConverters:DateTimeUTCToShortDateConverter x:Key="DateTimeUTCToShortDateConverter" /> <sharedConverters:EnumToDescriptionConverter x:Key="EnumToDescriptionConverter" /> + </UserControl.Resources> <Grid Background="{StaticResource TangoMidBackgroundBrush}"> @@ -93,7 +94,7 @@ <touch:LightTouchDataGridColumn Header="Colors" SortMember="Segments.Count" Width="85"> <touch:LightTouchDataGridColumn.CellTemplate> <DataTemplate> - <ContentControl IsHitTestVisible="False" Content="{Binding Segments,Converter={StaticResource SegmentsToPieConverter}}" Width="23" Height="23" HorizontalAlignment="Left"></ContentControl> + <Image Stretch="Fill" IsHitTestVisible="False" Source="{Binding Converter={StaticResource JobToPieImageConverter},ConverterParameter='25,25'}" Width="25" Height="25" HorizontalAlignment="Left"></Image> </DataTemplate> </touch:LightTouchDataGridColumn.CellTemplate> </touch:LightTouchDataGridColumn> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 348f7ed26..9393d0612 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -121,7 +121,6 @@ <SubType>Designer</SubType> </Page> <Compile Include="Application\IPPCApplicationManager.cs" /> - <Compile Include="Authentication\DefaultAuthenticationProvider.cs" /> <Compile Include="Authentication\IAuthenticationProvider.cs" /> <Compile Include="Controls\MultiPieChart.xaml.cs"> <DependentUpon>MultiPieChart.xaml</DependentUpon> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs index f49beb32d..8a60caf6d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Authentication/DefaultAuthenticationProvider.cs @@ -6,8 +6,9 @@ using System.Threading.Tasks; using Tango.BL; using Tango.BL.Entities; using Tango.Core; +using Tango.PPC.Common.Authentication; -namespace Tango.PPC.Common.Authentication +namespace Tango.PPC.UI.Authentication { public class DefaultAuthenticationProvider : ExtendedObject, IAuthenticationProvider { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 8d7a35301..fb0e35618 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -92,6 +92,7 @@ <Compile Include="..\..\Versioning\PPCVersionInfo.cs"> <Link>PPCVersionInfo.cs</Link> </Compile> + <Compile Include="Authentication\DefaultAuthenticationProvider.cs" /> <Compile Include="Modules\DefaultStudioModuleLoader.cs" /> <Compile Include="Navigation\DefaultNavigationManager.cs" /> <Compile Include="Notifications\DefaultNotificationProvider.cs" /> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs index b3f2268e4..486392c95 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModelLocator.cs @@ -10,6 +10,7 @@ using Tango.PPC.Common.EventLogging; using Tango.PPC.Common.Modules; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; +using Tango.PPC.UI.Authentication; using Tango.PPC.UI.Modules; using Tango.PPC.UI.Navigation; using Tango.PPC.UI.Notifications; diff --git a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs index daaae5845..c250f3c44 100644 --- a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs +++ b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Job.cs @@ -2,9 +2,11 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; +using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Media.Imaging; using Tango.BL.Enumerations; namespace Tango.BL.Entities @@ -136,7 +138,7 @@ namespace Tango.BL.Entities cloned.CreationDate = DateTime.UtcNow; cloned.LastRun = null; cloned.Segments = Segments.Select(x => x.Clone(cloned)).ToObservableCollection(); - + return cloned; } @@ -149,5 +151,36 @@ namespace Tango.BL.Entities } #endregion + + #region Public Methods + + public BitmapSource CreateSegmentsPie(double width, double height) + { + Bitmap bmp = new Bitmap((int)width, (int)height); + + using (Graphics g = Graphics.FromImage(bmp)) + { + g.Clear(Color.Transparent); + g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; + g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; + g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; + + int fromAngle = -90; + double totalLength = Segments.Sum(x => x.Length); //Excluding inter segment. + + foreach (var segment in Segments.OrderBy(x => x.SegmentIndex)) + { + int toAngle = (int)((segment.Length / totalLength) * 360d); + g.FillPie(segment.CreateGdiBrush(bmp.Width - 2, bmp.Height - 2), new Rectangle(0, 0, bmp.Width - 2, bmp.Height - 2), fromAngle, toAngle); + fromAngle += toAngle; + } + } + + var source = bmp.ToBitmapSource(); + bmp.Dispose(); + return source; + } + + #endregion } } diff --git a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Segment.cs b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Segment.cs index 4a25f0e32..2c08cbf37 100644 --- a/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Segment.cs +++ b/Software/Visual_Studio/Tango.BL/EntitiesExtensions/Segment.cs @@ -106,5 +106,39 @@ namespace Tango.BL.Entities return brush; } + + public System.Drawing.Brush CreateGdiBrush(int width, int height) + { + if (BrushStops.Count > 1) + { + System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.PointF(0, 0), new System.Drawing.Point(width, height), System.Drawing.Color.Black, System.Drawing.Color.Black); + + System.Drawing.Drawing2D.ColorBlend blend = new System.Drawing.Drawing2D.ColorBlend(); + + List<System.Drawing.Color> colors = new List<System.Drawing.Color>(); + List<float> offsets = new List<float>(); + + foreach (var stop in BrushStops.OrderBy(x => x.OffsetPercent)) + { + colors.Add(stop.Color.ToGdiColor()); + offsets.Add((float)stop.OffsetPercent / 100f); + } + + blend.Colors = colors.ToArray(); + blend.Positions = offsets.ToArray(); + + brush.InterpolationColors = blend; + + return brush; + } + else if (BrushStops.Count == 1) + { + return new System.Drawing.SolidBrush(BrushStops.First().Color.ToGdiColor()); + } + else + { + return System.Drawing.Brushes.Black; + } + } } } diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index f116e5106..ccc549a7c 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -63,6 +63,7 @@ <HintPath>..\packages\System.Data.SQLite.Linq.1.0.108.0\lib\net46\System.Data.SQLite.Linq.dll</HintPath> <Private>True</Private> </Reference> + <Reference Include="System.Drawing" /> <Reference Include="System.Xml" /> <Reference Include="Microsoft.CSharp" /> <Reference Include="System.Core" /> diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/BitmapSourceExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/BitmapSourceExtensions.cs index 11844df36..b9e5eba1b 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/BitmapSourceExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/BitmapSourceExtensions.cs @@ -239,4 +239,25 @@ public static class BitmapSourceExtensions var bm = new FormatConvertedBitmap(bitmapsource, format, null, 0); return bm; } + + /// <summary> + /// Converts this GDI bitmap to WPF BitmapSource. + /// </summary> + /// <param name="bitmap">The bitmap.</param> + /// <returns></returns> + public static BitmapSource ToBitmapSource(this System.Drawing.Bitmap bitmap) + { + var bitmapData = bitmap.LockBits( +new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), + System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + + var bitmapSource = BitmapSource.Create( + bitmapData.Width, bitmapData.Height, 96, 96, System.Windows.Media.PixelFormats.Bgra32, null, + bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride); + + bitmap.UnlockBits(bitmapData); + + bitmapSource.Freeze(); + return bitmapSource; + } } diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ColorExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ColorExtensions.cs new file mode 100644 index 000000000..686bc834e --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ColorExtensions.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; + +public static class ColorExtensions +{ + /// <summary> + /// Converts this WPF color to GDI color. + /// </summary> + /// <param name="color">The color.</param> + /// <returns></returns> + public static System.Drawing.Color ToGdiColor(this Color color) + { + return System.Drawing.Color.FromArgb(color.R, color.G, color.B); + } +} + diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 76ed595fa..eee82d1b7 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -74,6 +74,7 @@ <Compile Include="ExtendedObject.cs" /> <Compile Include="ExtensionMethods\BitmapExtensions.cs" /> <Compile Include="ExtensionMethods\BitmapSourceExtensions.cs" /> + <Compile Include="ExtensionMethods\ColorExtensions.cs" /> <Compile Include="ExtensionMethods\DateTimeExtensions.cs" /> <Compile Include="ExtensionMethods\DependencyObjectExtensions.cs" /> <Compile Include="ExtensionMethods\EnumExtensions.cs" /> |
