From 8a1e772f025eaf3bfdf17905d9e33c460993e559 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 1 Jul 2019 17:56:49 +0300 Subject: Many bug fixes !!! --- .../Converters/MachineEventToViewConverter.cs | 24 +++++++---- .../Tango.PPC.Events/EventsViews/JobEventView.xaml | 27 +++++++++++++ .../EventsViews/JobEventView.xaml.cs | 28 +++++++++++++ .../Tango.PPC.Events/Tango.PPC.Events.csproj | 9 ++++- .../Tango.PPC.Events/ViewModels/MainViewVM.cs | 6 ++- .../Modules/Tango.PPC.Events/Views/MainView.xaml | 2 +- .../Dialogs/BasicColorCorrectionView.xaml | 25 ++++++++++++ .../Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs | 2 +- .../Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | 47 +++++++++++++++++----- .../Modules/Tango.PPC.Jobs/Views/JobsView.xaml.cs | 30 +++++++------- 10 files changed, 165 insertions(+), 35 deletions(-) create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/JobEventView.xaml create mode 100644 Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/JobEventView.xaml.cs (limited to 'Software/Visual_Studio/PPC/Modules') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Converters/MachineEventToViewConverter.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Converters/MachineEventToViewConverter.cs index b0d00bf9f..47c9e0ddf 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Converters/MachineEventToViewConverter.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Converters/MachineEventToViewConverter.cs @@ -7,30 +7,40 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Data; using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.PPC.Events.EventsViews; namespace Tango.PPC.Events.Converters { public class MachineEventToViewConverter : IValueConverter { - private static List _views = new List(); + private static Dictionary _eventViews = new Dictionary(); + + static MachineEventToViewConverter() + { + _eventViews.Add(EventTypes.JOB_STARTED, typeof(JobEventView)); + _eventViews.Add(EventTypes.JOB_ABORTED, typeof(JobEventView)); + _eventViews.Add(EventTypes.JOB_COMPLETED, typeof(JobEventView)); + _eventViews.Add(EventTypes.JOB_FAILED, typeof(JobEventView)); + } public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { MachinesEvent ev = value as MachinesEvent; + FrameworkElement view = null; if (ev != null) { - FrameworkElement view = _views.SingleOrDefault(x => x.GetType() == typeof(EventsViews.GeneralView)); - - if (view != null) + if (_eventViews.ContainsKey(ev.Type)) { - return view; + view = Activator.CreateInstance(_eventViews[ev.Type]) as FrameworkElement; } else { - view = Activator.CreateInstance(); - return view; + view = Activator.CreateInstance(); } + + return view; } else { diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/JobEventView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/JobEventView.xaml new file mode 100644 index 000000000..d283b08d3 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/JobEventView.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/JobEventView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/JobEventView.xaml.cs new file mode 100644 index 000000000..89faa3a85 --- /dev/null +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/EventsViews/JobEventView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.PPC.Events.EventsViews +{ + /// + /// Interaction logic for JobEventView.xaml + /// + public partial class JobEventView : UserControl + { + public JobEventView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj index e446e3812..e2133e585 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Tango.PPC.Events.csproj @@ -72,6 +72,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -91,6 +95,9 @@ GeneralView.xaml + + JobEventView.xaml + Code @@ -173,7 +180,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs index 997ea70d5..d2a730cd7 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/ViewModels/MainViewVM.cs @@ -97,7 +97,7 @@ namespace Tango.PPC.Events.ViewModels using (var db = ObservablesContext.CreateDefault()) { var last_week = DateTime.UtcNow.AddDays(-7); - HistoryEvents = (await db.MachinesEvents.Where(x => x.MachineGuid == MachineProvider.Machine.Guid && x.DateTime > last_week).Take(100).Include(x => x.EventType).Where(x => (EventTypeNotificationTimes)x.EventType.EventNotificationTime != EventTypeNotificationTimes.None).ToListAsync()).OrderByDescending(x => x.DateTime).ToObservableCollection(); + HistoryEvents = (await db.MachinesEvents.Where(x => x.MachineGuid == MachineProvider.Machine.Guid && x.DateTime > last_week).Take(100).Include(x => x.EventType).Where(x => (EventTypeNotificationTimes)x.EventType.EventNotificationTime != EventTypeNotificationTimes.None || x.EventType.Code == (int)EventTypes.JOB_FAILED || x.EventType.Code == (int)EventTypes.JOB_STARTED || x.EventType.Code == (int)EventTypes.JOB_COMPLETED || x.EventType.Code == (int)EventTypes.JOB_ABORTED).ToListAsync()).OrderByDescending(x => x.DateTime).ToObservableCollection(); } MachineProvider.MachineOperator.StatusChanged += MachineOperator_StatusChanged; @@ -160,6 +160,10 @@ namespace Tango.PPC.Events.ViewModels _notifications.Add(new KeyValuePair(ev.EventType.Type, notificationItem)); } + else if (ev.IsJobProgressEvent()) + { + HistoryEvents.Insert(0, ev); + } }); } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml index f263e4b7b..af42a5576 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Events/Views/MainView.xaml @@ -135,7 +135,7 @@ - + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/BasicColorCorrectionView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/BasicColorCorrectionView.xaml index 9583d0738..4fcccc9e5 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/BasicColorCorrectionView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/BasicColorCorrectionView.xaml @@ -27,10 +27,35 @@ + + + , , + + + + + , + , + + diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs index 1a980fc4a..b413758c8 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs @@ -89,7 +89,7 @@ namespace Tango.PPC.Jobs.ViewModels catch (Exception ex) { LogManager.Log(ex, "Could not start the current job."); - await NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}."); + await NotificationProvider.ShowError($"{ex.Message}"); } } 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 3a777e142..0d1d2f3cb 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 @@ -407,7 +407,7 @@ namespace Tango.PPC.Jobs.ViewModels _check_gamut_thread = new Thread(CheckGamutThreadMethod); _check_gamut_thread.IsBackground = true; - StartSampleDyeCommand = new RelayCommand(StartSampleDye); + StartSampleDyeCommand = new RelayCommand(StartSampleDye, CanStartJob); DyeCommand = new RelayCommand(StartJob, CanStartJob); ApproveSampleCommand = new RelayCommand(ApproveSampleDye); @@ -415,7 +415,7 @@ namespace Tango.PPC.Jobs.ViewModels AnotherSampleCommand = new RelayCommand(DyeAnotherSample); InvokeFineTuningPaletteCommand = new RelayCommand(InvokeFineTuningPalette); ResetFineTuningCommand = new RelayCommand(ResetFineTuning); - StartFineTuningCommand = new RelayCommand(StartFineTuning, () => FineTuneItems.Any(x => x.IsSelected)); + StartFineTuningCommand = new RelayCommand(StartFineTuning, () => FineTuneItems.Any(x => x.IsSelected) && CanStartJob()); RepeatFineTuningCommand = new RelayCommand(RepeatFineTuning); ApproveFineTuningCommand = new RelayCommand(ApproveFineTuning); OpenTwineCatalogCommand = new RelayCommand(OpenTwineCatalog); @@ -463,6 +463,8 @@ namespace Tango.PPC.Jobs.ViewModels Job.RmlChanged -= OnRmlChanged; Job.RmlChanged += OnRmlChanged; + Job.NameChanged -= Job_NameChanged; + Job.NameChanged += Job_NameChanged; Job.ValidateOnPropertyChanged = true; @@ -490,6 +492,7 @@ namespace Tango.PPC.Jobs.ViewModels SegmentsCollectionView = CollectionViewSource.GetDefaultView(Job.Segments); SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); + ResetFineTuning(); _job_to_load = null; } @@ -517,7 +520,11 @@ namespace Tango.PPC.Jobs.ViewModels View.DisplayFineTuning(); } + ValidateBrushStops(); + DyeCommand.RaiseCanExecuteChanged(); + StartSampleDyeCommand.RaiseCanExecuteChanged(); + StartFineTuningCommand.RaiseCanExecuteChanged(); } catch (Exception ex) { @@ -534,6 +541,11 @@ namespace Tango.PPC.Jobs.ViewModels } } + private void Job_NameChanged(object sender, string e) + { + DyeCommand.RaiseCanExecuteChanged(); + } + /// /// Saves the job. /// @@ -564,12 +576,17 @@ namespace Tango.PPC.Jobs.ViewModels Job.LastUpdated = DateTime.UtcNow; Job.JobStatus = BL.Enumerations.JobStatuses.Draft; await _db.SaveChangesAsync(); - RaiseMessage(new JobSavedMessage() { Job = Job }); if (displayNotification) { await NotificationProvider.ShowInfo(String.Format("Job '{0}' saved successfully.", Job.Name)); } + + RaiseMessage(new JobSavedMessage() { Job = Job }); + } + else + { + await NotificationProvider.ShowError($"Error saving job. {Job.ValidationErrors.FirstOrDefault()}"); } } catch (Exception ex) @@ -617,7 +634,7 @@ namespace Tango.PPC.Jobs.ViewModels catch (Exception ex) { LogManager.Log(ex, "Could not start the current job."); - await NotificationProvider.ShowError($"Cannot start job.\n{ex.Message}."); + await NotificationProvider.ShowError($"{ex.Message}."); } } @@ -627,7 +644,7 @@ namespace Tango.PPC.Jobs.ViewModels private bool CanStartJob() { return - Job != null && + Job != null && Job.Validate(_db) && !Job.Segments.SelectMany(x => x.BrushStops).ToList().Exists(x => x.IsOutOfGamut); } @@ -653,6 +670,8 @@ namespace Tango.PPC.Jobs.ViewModels var replacement = CoatsCatalogItems.SingleOrDefault(x => x.Name == stop.ColorCatalog.Name); stop.ColorCatalog = replacement; } + + ResetFineTuning(); } #endregion @@ -748,6 +767,8 @@ namespace Tango.PPC.Jobs.ViewModels _db.Segments.Remove(segment); ArrangeSegmentsIndices(); + + DyeCommand.RaiseCanExecuteChanged(); } } catch (Exception ex) @@ -815,8 +836,9 @@ namespace Tango.PPC.Jobs.ViewModels if (brushStop.Segment.BrushStops.Count > 2) { LogManager.Log($"removing brush stop {brushStop.StopIndex} from segment {brushStop.Segment.SegmentIndex}."); + var segment = brushStop.Segment; _db.BrushStops.Remove(brushStop); - ArrangeBrushStopsIndices(brushStop.Segment); + ArrangeBrushStopsIndices(segment); } else { @@ -946,6 +968,11 @@ namespace Tango.PPC.Jobs.ViewModels } } + private bool ValidateBrushStops() + { + return Job.Segments.SelectMany(x => x.BrushStops).ToList().All(x => x.Validate(_db)); + } + #endregion #region Job Selection Message @@ -979,7 +1006,7 @@ namespace Tango.PPC.Jobs.ViewModels catch (Exception ex) { LogManager.Log(ex, $"Error executing sample dye for job {Job.Name}."); - await NotificationProvider.ShowError("An error occurred while trying to execute the sample dye."); + await NotificationProvider.ShowError(ex.Message); } } @@ -1119,7 +1146,7 @@ namespace Tango.PPC.Jobs.ViewModels catch (Exception ex) { LogManager.Log(ex, "Error executing fine tuning job."); - await NotificationProvider.ShowError("An error occurred while trying to start the fine tuning job."); + await NotificationProvider.ShowError(ex.Message); } } @@ -1177,7 +1204,7 @@ namespace Tango.PPC.Jobs.ViewModels { Thread.Sleep(500); - if (Job != null && IsVisible && (Job.ColorSpace != null && (Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32() || Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.LAB.ToInt32()))) + if (Job != null && Job.Rml.Ccts.Count > 0 && IsVisible && (Job.ColorSpace != null && (Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32() || Job.ColorSpace.Code == BL.Enumerations.ColorSpaces.LAB.ToInt32()))) { var brushStops = Job.Segments.SelectMany(x => x.BrushStops).Where(x => !x.Corrected && !x.OutOfGamutChecked).ToList(); @@ -1199,6 +1226,8 @@ namespace Tango.PPC.Jobs.ViewModels InvokeUI(() => { DyeCommand.RaiseCanExecuteChanged(); + StartSampleDyeCommand.RaiseCanExecuteChanged(); + StartFineTuningCommand.RaiseCanExecuteChanged(); }); } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml.cs index 2653179e1..23785881d 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Views/JobsView.xaml.cs @@ -28,23 +28,23 @@ namespace Tango.PPC.Jobs.Views TangoIOC.Default.Register(this); } - private void TouchNavigationLinks_SelectionChanged(object sender, SelectionChangedEventArgs e) + private async void TouchNavigationLinks_SelectionChanged(object sender, SelectionChangedEventArgs e) { - //if (dataGridJobs != null) - //{ - // await Task.Delay(200); + if (dataGridJobs != null) + { + await Task.Delay(200); - // if (navigationLinks.SelectedIndex == 0) - // { - // dataGridJobs.LayoutRows(false); - // dataGridJobs.ScrollViewer.ScrollToTop(); - // } - // else - // { - // dataGridJobsHistory.LayoutRows(false); - // dataGridJobsHistory.ScrollViewer.ScrollToTop(); - // } - //} + if (navigationLinks.SelectedIndex == 0) + { + dataGridJobs.LayoutRows(false); + dataGridJobs.ScrollViewer.ScrollToTop(); + } + else + { + dataGridJobsHistory.LayoutRows(false); + dataGridJobsHistory.ScrollViewer.ScrollToTop(); + } + } } public void ScrollToTop() -- cgit v1.3.1