From 0fdbc932838bb6e007cfa8a0079d1880c800ed81 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 28 Dec 2020 00:44:38 +0200 Subject: Removed length from job viewer. Improved FastTextBlock. Improved PPC segments loading ability from ~40 to ~150. --- .../Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml | 31 +- .../Controls/JobSummeryViewer.xaml.cs | 12 + .../Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | 8 + .../Tango.PPC.Jobs/Views/JobSummeryView.xaml | 2 +- .../PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml | 474 ++++++++++----------- .../Tango.SharedUI/Components/LazyBinding.cs | 160 +++++++ .../Tango.SharedUI/Controls/FastTextBlock.cs | 18 + .../Tango.SharedUI/Tango.SharedUI.csproj | 3 +- .../Controls/LightTouchScrollViewer.xaml | 4 +- .../Tango.Touch/Controls/TouchComboBox.xaml | 4 +- .../Tango.Touch/Controls/TouchNumericTextBox.cs | 4 +- .../Tango.Touch/Controls/TouchNumericTextBox.xaml | 3 +- .../TouchVirtualizedContentReplaceControl.cs | 188 ++++++++ .../TouchVirtualizedContentReplaceControl.xaml | 15 + .../Visual_Studio/Tango.Touch/Tango.Touch.csproj | 7 +- .../Visual_Studio/Tango.Touch/Themes/Generic.xaml | 1 + 16 files changed, 671 insertions(+), 263 deletions(-) create mode 100644 Software/Visual_Studio/Tango.SharedUI/Components/LazyBinding.cs create mode 100644 Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentReplaceControl.cs create mode 100644 Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentReplaceControl.xaml (limited to 'Software/Visual_Studio') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml index afe331145..bd0bbfd11 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml @@ -3,11 +3,12 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:enumerations="clr-namespace:Tango.BL.Enumerations;assembly=Tango.BL" xmlns:entities="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" xmlns:local="clr-namespace:Tango.PPC.Jobs.Controls" mc:Ignorable="d" - d:DesignHeight="60" d:DesignWidth="500" Height="38" d:DataContext="{d:DesignInstance Type=entities:Job, IsDesignTimeCreatable=False}" x:Name="control"> + d:DesignHeight="60" d:DesignWidth="500" Height="38" x:Name="control"> @@ -20,7 +21,7 @@ - + @@ -31,15 +32,15 @@ - + - - - - - - + + + + @@ -66,11 +68,8 @@ - - - - + @@ -81,7 +80,7 @@ - + @@ -104,7 +103,7 @@ - + @@ -114,7 +113,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml.cs index 1c0b90f91..c977e71d0 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml.cs @@ -23,6 +23,18 @@ namespace Tango.PPC.Jobs.Controls /// public partial class JobSummeryViewer : UserControl { + + /// + /// Gets or sets the job. + /// + public Job Job + { + get { return (Job)GetValue(JobProperty); } + set { SetValue(JobProperty, value); } + } + public static readonly DependencyProperty JobProperty = + DependencyProperty.Register("Job", typeof(Job), typeof(JobSummeryViewer), new PropertyMetadata(null)); + /// /// Maybe not necessary! /// diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs index e8af7c957..cfac759dd 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs @@ -422,6 +422,14 @@ namespace Tango.PPC.Jobs.ViewModels if (_db != null) { + if (Job != null) + { + foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).ToList()) + { + stop.ColorSpaceChanged -= Stop_ColorSpaceChanged; + } + } + Rmls.ForEach(x => x.Cct = null); Rmls = null; _db.Dispose(); diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobSummeryView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobSummeryView.xaml index 4785805a6..ddda98df9 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobSummeryView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobSummeryView.xaml @@ -92,7 +92,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml index 467c3f72b..c1472793a 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml @@ -51,7 +51,7 @@ - + @@ -118,11 +118,11 @@ - - - - - - - - - - - - - - - - - - - + - - - - - - - - Segment # - - - + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - + + - + - + - - - - - + + + + + + + - - - - - - + + + + - + + - - - - - - + + + + + + + + - ADD COLOR + ADD COLOR + + - - + + - - - + + + @@ -465,11 +466,6 @@ - - - - - @@ -706,7 +702,11 @@ - + + + + + diff --git a/Software/Visual_Studio/Tango.SharedUI/Components/LazyBinding.cs b/Software/Visual_Studio/Tango.SharedUI/Components/LazyBinding.cs new file mode 100644 index 000000000..e8e22d182 --- /dev/null +++ b/Software/Visual_Studio/Tango.SharedUI/Components/LazyBinding.cs @@ -0,0 +1,160 @@ +using System; +using System.ComponentModel; +using System.Globalization; +using System.Windows; +using System.Windows.Data; +using System.Windows.Markup; + +namespace Tango.SharedUI.Components +{ + [MarkupExtensionReturnType(typeof(object))] + public class LazyBindingExtension : MarkupExtension + { + public LazyBindingExtension() + { } + + public LazyBindingExtension(PropertyPath path) : this() + { + Path = path; + } + + #region Properties + + public IValueConverter Converter { get; set; } + [TypeConverter(typeof(CultureInfoIetfLanguageTagConverter))] + public CultureInfo ConverterCulture { get; set; } + public object ConverterParamter { get; set; } + public string ElementName { get; set; } + [ConstructorArgument("path")] + public PropertyPath Path { get; set; } + public RelativeSource RelativeSource { get; set; } + public object Source { get; set; } + public UpdateSourceTrigger UpdateSourceTrigger { get; set; } + public bool ValidatesOnDataErrors { get; set; } + public bool ValidatesOnExceptions { get; set; } + public bool ValidatesOnNotifyDataErrors { get; set; } + + private Binding binding; + private UIElement bindingTarget; + private DependencyProperty bindingTargetProperty; + + #endregion + + #region Init + + public override object ProvideValue(IServiceProvider serviceProvider) + { + var valueProvider = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget; + if (valueProvider != null) + { + bindingTarget = valueProvider.TargetObject as UIElement; + + if (bindingTarget == null) + { + throw new NotSupportedException($"Target '{valueProvider.TargetObject}' is not valid for a LazyBinding. The LazyBinding target must be a UIElement."); + } + + bindingTargetProperty = valueProvider.TargetProperty as DependencyProperty; + + if (bindingTargetProperty == null) + { + throw new NotSupportedException($"The property '{valueProvider.TargetProperty}' is not valid for a LazyBinding. The LazyBinding target property must be a DependencyProperty."); + } + + binding = new Binding + { + Path = Path, + Converter = Converter, + ConverterCulture = ConverterCulture, + ConverterParameter = ConverterParamter + }; + + if (ElementName != null) + { + binding.ElementName = ElementName; + } + + if (RelativeSource != null) + { + binding.RelativeSource = RelativeSource; + } + + if (Source != null) + { + binding.Source = Source; + } + + binding.UpdateSourceTrigger = UpdateSourceTrigger; + binding.ValidatesOnDataErrors = ValidatesOnDataErrors; + binding.ValidatesOnExceptions = ValidatesOnExceptions; + binding.ValidatesOnNotifyDataErrors = ValidatesOnNotifyDataErrors; + + return SetBinding(); + } + + return null; + } + + public object SetBinding() + { + bindingTarget.IsVisibleChanged += UiElement_IsVisibleChanged; + + updateBinding(); + + return bindingTarget.GetValue(bindingTargetProperty); + } + + #endregion + + #region Event Handlers + + private void UiElement_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) + { + updateBinding(); + } + + #endregion + + #region Update Binding + + private void updateBinding() + { + if (bindingTarget.IsVisible) + { + ConsolidateBinding(); + } + else + { + ClearBinding(); + } + } + + private bool _isBind; + + private void ConsolidateBinding() + { + if (_isBind) + { + return; + } + + _isBind = true; + + BindingOperations.SetBinding(bindingTarget, bindingTargetProperty, binding); + } + + private void ClearBinding() + { + if (!_isBind) + { + return; + } + + BindingOperations.ClearBinding(bindingTarget, bindingTargetProperty); + + _isBind = false; + } + + #endregion + } +} diff --git a/Software/Visual_Studio/Tango.SharedUI/Controls/FastTextBlock.cs b/Software/Visual_Studio/Tango.SharedUI/Controls/FastTextBlock.cs index 141fa6e27..07005a0f4 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Controls/FastTextBlock.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Controls/FastTextBlock.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Globalization; using System.Linq; using System.Text; @@ -30,6 +31,23 @@ namespace Tango.SharedUI.Controls public FastTextBlock() { Loaded += FastTextBlock_Loaded; + + DependencyPropertyDescriptor fontFamilyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(FastTextBlock.FontFamilyProperty, typeof(FastTextBlock)); + fontFamilyPropertyDescriptor.AddValueChanged(this, OnPropertyChangedInit); + + DependencyPropertyDescriptor fontSizePropertyDescriptor = DependencyPropertyDescriptor.FromProperty(FastTextBlock.FontSizeProperty, typeof(FastTextBlock)); + fontSizePropertyDescriptor.AddValueChanged(this, OnPropertyChangedInit); + + DependencyPropertyDescriptor fontWeightPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(FastTextBlock.FontWeightProperty, typeof(FastTextBlock)); + fontWeightPropertyDescriptor.AddValueChanged(this, OnPropertyChangedInit); + + DependencyPropertyDescriptor ForegroundPropertyDescriptor = DependencyPropertyDescriptor.FromProperty(FastTextBlock.ForegroundProperty, typeof(FastTextBlock)); + ForegroundPropertyDescriptor.AddValueChanged(this, OnPropertyChangedInit); + } + + private void OnPropertyChangedInit(object sender, EventArgs e) + { + Init(); } private void FastTextBlock_Loaded(object sender, RoutedEventArgs e) diff --git a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj index e4dc72746..5d9592a26 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj +++ b/Software/Visual_Studio/Tango.SharedUI/Tango.SharedUI.csproj @@ -67,6 +67,7 @@ + @@ -261,7 +262,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.xaml b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.xaml index 7cc38666e..e0e8f485c 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.xaml +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchScrollViewer.xaml @@ -25,9 +25,9 @@ - + diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.xaml index 738fe6a3c..83163fcd8 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.xaml +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchComboBox.xaml @@ -31,7 +31,7 @@ - diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentReplaceControl.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentReplaceControl.cs new file mode 100644 index 000000000..802d3f538 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentReplaceControl.cs @@ -0,0 +1,188 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Markup; +using System.Windows.Shapes; +using System.Windows.Threading; +using Tango.Core.Threading; + +namespace Tango.Touch.Controls +{ + [ContentProperty(nameof(Content))] + public class TouchVirtualizedContentReplaceControl : Control + { + private LightTouchScrollViewer _scrollViewer; + private Border _innerBorder; + private ActionTimer _updateTimer; + private Point _location; + private bool _loaded; + private Image _replaceContent; + private FrameworkElement _element; + private INameScopeDictionary _parentNameScope; + + public DataTemplate Content + { + get { return (DataTemplate)GetValue(ContentProperty); } + set { SetValue(ContentProperty, value); } + } + public static readonly DependencyProperty ContentProperty = + DependencyProperty.Register("Content", typeof(DataTemplate), typeof(TouchVirtualizedContentReplaceControl), new PropertyMetadata(null)); + + public bool CanMovePosition + { + get { return (bool)GetValue(CanMovePositionProperty); } + set { SetValue(CanMovePositionProperty, value); } + } + public static readonly DependencyProperty CanMovePositionProperty = + DependencyProperty.Register("CanMovePosition", typeof(bool), typeof(TouchVirtualizedContentReplaceControl), new PropertyMetadata(false)); + + public LightTouchDataGrid DataGrid + { + get { return (LightTouchDataGrid)GetValue(DataGridProperty); } + set { SetValue(DataGridProperty, value); } + } + public static readonly DependencyProperty DataGridProperty = + DependencyProperty.Register("DataGrid", typeof(LightTouchDataGrid), typeof(TouchVirtualizedContentReplaceControl), new PropertyMetadata(null)); + + public bool Disconnect + { + get { return (bool)GetValue(DisconnectProperty); } + set { SetValue(DisconnectProperty, value); } + } + public static readonly DependencyProperty DisconnectProperty = + DependencyProperty.Register("Disconnect", typeof(bool), typeof(TouchVirtualizedContentReplaceControl), new PropertyMetadata(true)); + + static TouchVirtualizedContentReplaceControl() + { + DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchVirtualizedContentReplaceControl), new FrameworkPropertyMetadata(typeof(TouchVirtualizedContentReplaceControl))); + } + + public TouchVirtualizedContentReplaceControl() + { + _replaceContent = new Image(); + _updateTimer = new ActionTimer(TimeSpan.FromMilliseconds(100)); + Loaded += TouchVirtualizedContentControl_Loaded; + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + _innerBorder = GetTemplateChild("PART_innerBorder") as Border; + _innerBorder.Child = _replaceContent; + } + + private void TouchVirtualizedContentControl_Loaded(object sender, System.Windows.RoutedEventArgs e) + { + _scrollViewer = this.FindAncestor(); + _scrollViewer.Scrolling += _scrollViewer_Scrolling; + + _parentNameScope = NameScope.GetNameScope(this.FindAncestor()) as INameScopeDictionary; + + if (DataGrid != null) + { + DataGrid.SortingChanged += DataGrid_SortingChanged; + DataGrid.FilterChanged += DataGrid_FilterChanged; + } + + _location = this.TranslatePoint(new Point(0, 0), _scrollViewer.GetContentGrid()); + + _scrollViewer.GetContentGrid().SizeChanged += TouchVirtualizedContentControl_SizeChanged; + + ApplyVirtualization(); + _loaded = true; + } + + private void DataGrid_FilterChanged(object sender, EventArgs e) + { + InvalidateVirtualization(); + } + + private void DataGrid_SortingChanged(object sender, EventArgs e) + { + InvalidateVirtualization(); + } + + private void TouchVirtualizedContentControl_SizeChanged(object sender, SizeChangedEventArgs e) + { + InvalidateVirtualization(); + } + + private void _scrollViewer_Scrolling(object sender, DoubleValueChangedEventArgs e) + { + if (_loaded) + { + ApplyVirtualization(); + } + } + + private void InvalidateVirtualization() + { + _updateTimer.ResetReplace(() => + { + Dispatcher.Invoke(new Action(() => + { + _location = this.TranslatePoint(new Point(0, 0), _scrollViewer.GetContentGrid()); + ApplyVirtualization(); + })); + }); + } + + private void ApplyVirtualization() + { + if (!Disconnect && _element != null) + { + _updateTimer.Dispose(); + return; + } + + var _border_viewport = _scrollViewer.GetViewportBorder(); + + if (CanMovePosition) + { + _location = this.TranslatePoint(new Point(0, 0), _scrollViewer.GetContentGrid()); + } + + Rect bounds = new Rect(_location.X, _location.Y, ActualWidth, ActualHeight); + Rect rect = new Rect(0.0, _scrollViewer.GetScrollPosition(), _border_viewport.ActualWidth, _border_viewport.ActualHeight); + + if (_innerBorder != null) + { + if (bounds.IntersectsWith(rect)) + { + if (Disconnect || _element == null) + { + if (_innerBorder.Child == _replaceContent || _element == null) + { + _element = Content.LoadContent() as FrameworkElement; + + if (_parentNameScope != null) + { + NameScope.SetNameScope(_element, _parentNameScope); + } + + _innerBorder.Child = _element; + _innerBorder.Height = double.NaN; + } + } + } + else + { + if (Disconnect) + { + if (_innerBorder.Child == _element) + { + double height = _element != null ? _element.ActualHeight : MinHeight; + _innerBorder.Child = _replaceContent; + _innerBorder.Height = height; + } + } + } + } + } + } +} diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentReplaceControl.xaml b/Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentReplaceControl.xaml new file mode 100644 index 000000000..c7fe39b76 --- /dev/null +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchVirtualizedContentReplaceControl.xaml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj index 7dd560a48..8575548c4 100644 --- a/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj +++ b/Software/Visual_Studio/Tango.Touch/Tango.Touch.csproj @@ -101,6 +101,7 @@ + @@ -277,6 +278,10 @@ Designer MSBuild:Compile + + MSBuild:Compile + Designer + Designer MSBuild:Compile @@ -422,7 +427,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml index ed0f289b0..47403f56b 100644 --- a/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml +++ b/Software/Visual_Studio/Tango.Touch/Themes/Generic.xaml @@ -46,6 +46,7 @@ + -- cgit v1.3.1