From 80c023fa734d7788e155d4f311ab16220aa80650 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 31 Jan 2018 13:30:15 +0200 Subject: Job Brush working nicely. --- .../Converters/SegmentToBrushConverter.cs | 48 +++++++++++ .../Converters/SegmentToBrushConverterMulti.cs | 53 ++++++++++++ .../Tango.MachineStudio.Developer.csproj | 2 + .../ViewModels/MainViewVM.cs | 67 ++++++++++++++- .../Views/MainView.xaml | 97 ++++++++++++++++------ .../Views/MainView.xaml.cs | 37 ++++++++- 6 files changed, 278 insertions(+), 26 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs new file mode 100644 index 000000000..8aef260ff --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs @@ -0,0 +1,48 @@ +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 System.Windows.Media; +using Tango.Integration.Observables; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class SegmentToBrushConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + try + { + Segment segment = value as Segment; + + GradientStopCollection stops = new GradientStopCollection(); + + foreach (var stop in segment.BrushStops) + { + stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); + } + + LinearGradientBrush brush = new LinearGradientBrush(); + brush.StartPoint = new Point(0,0); + brush.EndPoint = new Point(1, 0); + + brush.GradientStops = stops; + + return brush; + } + catch + { + return null; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs new file mode 100644 index 000000000..0248fd730 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs @@ -0,0 +1,53 @@ +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 System.Windows.Media; +using Tango.Integration.Observables; + +namespace Tango.MachineStudio.Developer.Converters +{ + public class SegmentToBrushConverterMulti : IMultiValueConverter + { + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + try + { + Segment segment = values[0] as Segment; + + if (segment != null) + { + GradientStopCollection stops = new GradientStopCollection(); + + foreach (var stop in segment.BrushStops) + { + stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); + } + + LinearGradientBrush brush = new LinearGradientBrush(); + brush.StartPoint = new Point(0, 0); + brush.EndPoint = new Point(1, 0); + + brush.GradientStops = stops; + + return brush; + } + + return null; + } + catch + { + return null; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} 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 7d6712318..3a753dedc 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 @@ -79,6 +79,8 @@ + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index f6ddc9d19..7afb099db 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -76,7 +76,8 @@ namespace Tango.MachineStudio.Developer.ViewModels public ProcessParametersTablesGroup RmlProcessParametersTableGroup { get { return _rmlProcessParametersTablesGroup; } - set { _rmlProcessParametersTablesGroup = value; RaisePropertyChangedAuto(); } + set + { _rmlProcessParametersTablesGroup = value; RaisePropertyChangedAuto(); OnProcessParametersTableGroupChanged(); } } private ObservableCollection _groupsHistory; @@ -100,6 +101,16 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _selectedGroupHistory = value; RaisePropertyChangedAuto(); OnSelectedGroupHistoryChanged(); } } + private ProcessParametersTable _selectedProcessParametersTable; + /// + /// Gets or sets the selected process parameters table. + /// + public ProcessParametersTable SelectedProcessParametersTable + { + get { return _selectedProcessParametersTable; } + set { _selectedProcessParametersTable = value; RaisePropertyChangedAuto(); } + } + private Job _selectedJob; /// /// Gets or sets the selected machine job. @@ -181,6 +192,16 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _graphs = value; RaisePropertyChangedAuto(); } } + private TimeSpan _estimatedDuration; + /// + /// Gets or sets the estimated duration for the selected job. + /// + public TimeSpan EstimatedDuration + { + get { return _estimatedDuration; } + set { _estimatedDuration = value; RaisePropertyChangedAuto(); } + } + #endregion #region Commands @@ -297,10 +318,37 @@ namespace Tango.MachineStudio.Developer.ViewModels InvalidateLiquidFactorsAndProcessTables(); } + private void SelectedJob_LengthChanged(object sender, EventArgs e) + { + UpdateEstimatedDuration(); + } + + private void SelectedProcessParametersTable_DyeingSpeedChanged(object sender, EventArgs e) + { + UpdateEstimatedDuration(); + } + #endregion #region Virtual Methods + /// + /// Called when the process parameters table group has been changed + /// + /// + private void OnProcessParametersTableGroupChanged() + { + if (RmlProcessParametersTableGroup != null && RmlProcessParametersTableGroup.ProcessParametersTables.Count > 0) + { + SelectedProcessParametersTable = RmlProcessParametersTableGroup.ProcessParametersTables.First(); + + SelectedProcessParametersTable.DyeingSpeedChanged -= SelectedProcessParametersTable_DyeingSpeedChanged; + SelectedProcessParametersTable.DyeingSpeedChanged += SelectedProcessParametersTable_DyeingSpeedChanged; + } + + UpdateEstimatedDuration(); + } + /// /// Called when the selected segment has been changed /// @@ -321,6 +369,11 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SelectedJob != null) { SelectedSegment = SelectedJob.Segments.FirstOrDefault(); + + SelectedJob.LengthChanged -= SelectedJob_LengthChanged; + SelectedJob.LengthChanged += SelectedJob_LengthChanged; + + UpdateEstimatedDuration(); } } @@ -347,6 +400,14 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Private Methods + private void UpdateEstimatedDuration() + { + if (SelectedJob != null && SelectedProcessParametersTable != null) + { + EstimatedDuration = TimeSpan.FromSeconds(SelectedJob.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); + } + } + private void SetSegmentBrushStopsLiquidVolumes(Segment segment) { if (!DesignMode) @@ -475,7 +536,10 @@ namespace Tango.MachineStudio.Developer.ViewModels { Segment seg = new Segment(); seg.Name = "Untitled Segment"; + seg.Length = 1; SelectedJob.Segments.Add(seg); + SelectedSegment = seg; + AddBrushStop(); } } @@ -526,6 +590,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { var stop = new BrushStop(); stop.ColorSpace = Adapter.ColorSpaces.FirstOrDefault(); + stop.Color = Colors.Black; stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML); SelectedSegment.BrushStops.Add(stop); } 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 e0786a1ba..0c3cd62b5 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 @@ -40,6 +40,8 @@ + + @@ -232,15 +234,34 @@ - - + + + + + - - + + - + + + + @@ -305,8 +326,8 @@ - - + + @@ -448,7 +469,7 @@ - + @@ -549,7 +570,7 @@ Length - + @@ -952,7 +973,7 @@ ESTIMATED DURATION: - 00:00:00 + @@ -969,12 +990,12 @@ - - - + + + - + @@ -990,22 +1011,50 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 c76cf657f..143280e66 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 @@ -16,6 +16,7 @@ using Tango.Integration.Observables; using Tango.DragAndDrop; using Tango.MachineStudio.Developer.Converters; using Tango.MachineStudio.Developer.ViewModels; +using System.Windows.Threading; namespace Tango.MachineStudio.Developer.Views { @@ -25,6 +26,7 @@ namespace Tango.MachineStudio.Developer.Views public partial class MainView : UserControl { private MainViewVM _vm; + private DispatcherTimer _jobBrushTimer; public DraggingSurface DraggingSurface { @@ -46,6 +48,40 @@ namespace Tango.MachineStudio.Developer.Views chkGraphs.Checked += (x, y) => { graphRowDefinition.Height = new GridLength(440, GridUnitType.Pixel); }; chkGraphs.Unchecked += (x, y) => { graphRowDefinition.Height = new GridLength(80, GridUnitType.Pixel); }; + + _jobBrushTimer = new DispatcherTimer(); + _jobBrushTimer.Interval = TimeSpan.FromSeconds(1); + _jobBrushTimer.Tick += _jobBrushTimer_Tick; + _jobBrushTimer.Start(); + } + + private void _jobBrushTimer_Tick(object sender, EventArgs e) + { + if (_vm != null && _vm.SelectedJob != null) + { + List segments = new List(); + foreach (var s in _vm.SelectedJob.Segments) + { + segments.Add(s); + + if (_vm.SelectedJob.EnableInterSegment && _vm.SelectedJob.Segments.IndexOf(s) != _vm.SelectedJob.Segments.Count - 1) + { + segments.Add(new Segment() + { + Length = _vm.SelectedJob.InterSegmentLength, + BrushStops = new System.Collections.ObjectModel.ObservableCollection() + { + new BrushStop() + { + Color = Colors.White, + } + }, + }); + } + } + + jobBrushList.ItemsSource = segments; + } } private void OnDropAvailableSensor(object sender, DropEventArgs e) @@ -73,7 +109,6 @@ namespace Tango.MachineStudio.Developer.Views SegmentToGradientStopsConverter converter = new SegmentToGradientStopsConverter(); GradientStopCollection stops = converter.Convert(_vm.SelectedSegment, null, null, null) as GradientStopCollection; gradientBrush.GradientStops = stops; - jobBrushList.UpdateLayout(); } else { -- cgit v1.3.1