From 8feeef663f8984c609cb3aa530d09ffcffda5709 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 19 Feb 2018 17:17:25 +0200 Subject: Working on new developer module... --- .../Converters/BrushStopToOffsetLimitConverter.cs | 4 +- .../Converters/BrushStopToOffsetValueConverter.cs | 4 +- .../Converters/SegmentToBrushConverter.cs | 2 +- .../Converters/SegmentToBrushConverterMulti.cs | 2 +- .../Converters/SegmentToGradientStopsConverter.cs | 2 +- .../SegmentToGradientStopsConverterMulti.cs | 2 +- .../ViewModels/MainViewVM.cs | 488 +++++++++++++++------ .../Views/JobView.xaml | 87 +--- .../Views/JobView.xaml.cs | 13 +- .../Views/MachineJobSelectionView.xaml | 5 +- .../Views/MainView.xaml.cs | 8 +- .../Views/MachineView.xaml | 6 +- .../Resources/MaterialDesign.xaml | 87 +++- .../Tango.MachineStudio.Common.csproj | 4 + 14 files changed, 483 insertions(+), 231 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetLimitConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetLimitConverter.cs index 62d678888..96c44a5a0 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetLimitConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetLimitConverter.cs @@ -22,11 +22,11 @@ namespace Tango.MachineStudio.Developer.Converters if (stop != null && segment != null) { - if (segment.BrushStops.IndexOf(stop) == segment.BrushStops.Count - 1) + if (stop.IsLast) { return 100d; } - else if (segment.BrushStops.IndexOf(stop) == 0) + else if (stop.IsFirst) { return 0d; } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs index d8ac744a9..d78ef0c8e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/BrushStopToOffsetValueConverter.cs @@ -20,11 +20,11 @@ namespace Tango.MachineStudio.Developer.Converters if (stop != null && segment != null) { - if (segment.BrushStops.IndexOf(stop) == segment.BrushStops.Count - 1) + if (stop.IsLast) { return 100d; } - else if (segment.BrushStops.IndexOf(stop) == 0) + else if (stop.IsFirst) { return 0d; } 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 index 8aef260ff..1ac498070 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverter.cs @@ -21,7 +21,7 @@ namespace Tango.MachineStudio.Developer.Converters GradientStopCollection stops = new GradientStopCollection(); - foreach (var stop in segment.BrushStops) + foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex)) { stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); } 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 index 0248fd730..41c1dd4df 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToBrushConverterMulti.cs @@ -23,7 +23,7 @@ namespace Tango.MachineStudio.Developer.Converters { GradientStopCollection stops = new GradientStopCollection(); - foreach (var stop in segment.BrushStops) + foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex)) { stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs index 37908c940..f28a0b594 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverter.cs @@ -20,7 +20,7 @@ namespace Tango.MachineStudio.Developer.Converters GradientStopCollection stops = new GradientStopCollection(); - foreach (var stop in segment.BrushStops) + foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex)) { stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverterMulti.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverterMulti.cs index 68ff95a9c..c50fbb06c 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverterMulti.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/SegmentToGradientStopsConverterMulti.cs @@ -22,7 +22,7 @@ namespace Tango.MachineStudio.Developer.Converters { GradientStopCollection stops = new GradientStopCollection(); - foreach (var stop in segment.BrushStops) + foreach (var stop in segment.BrushStops.OrderBy(x => x.StopIndex)) { stops.Add(new GradientStop(stop.Color, stop.OffsetPercent / 100d)); } 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 5c5531063..c8a6aa89f 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 @@ -36,6 +36,8 @@ using Tango.MachineStudio.Developer.Navigation; using System.Data.Entity; using Tango.MachineStudio.Common.Authentication; using DeepEqual.Syntax; +using System.ComponentModel; +using System.Windows.Data; namespace Tango.MachineStudio.Developer.ViewModels { @@ -45,6 +47,8 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public class MainViewVM : ViewModel, IShutdownRequestBlocker { + private static object _syncLock = new object(); + private INotificationProvider _notification; private TimeSpan _runningJobEstimatedDuration; private Dictionary _controllers; @@ -52,9 +56,9 @@ namespace Tango.MachineStudio.Developer.ViewModels private JobHandler _jobHandler; private DeveloperNavigationManager _navigation; private ObservablesContext _dbJobContext; - private Job _jobFromList; private bool _blockInvalidateCommands; private IAuthenticationProvider _authentication; + private ObservablesContext _machineDBContext; #region Properties @@ -103,7 +107,7 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _selectedMachine = value; - OnMachineChanged(); + OnSelectedMachineChanged(); RaisePropertyChangedAuto(); InvalidateRelayCommands(); @@ -136,6 +140,21 @@ namespace Tango.MachineStudio.Developer.ViewModels { _rmlProcessParametersTablesGroup = value; RaisePropertyChangedAuto(); OnProcessParametersTableGroupChanged(); } } + public void OnDropSegment(Segment dragged, Segment dropped) + { + dragged.SegmentIndex = dropped.SegmentIndex; + dropped.SegmentIndex++; + + int index = 1; + + foreach (var segment in ActiveJob.Segments.OrderBy(x => x.SegmentIndex)) + { + segment.SegmentIndex = index++; + } + + SegmentsCollectionView.Refresh(); + } + private ObservableCollection _groupsHistory; /// /// Gets or sets the RML process parameters groups history. @@ -166,20 +185,31 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _selectedProcessParametersTable = value; RaisePropertyChangedAuto(); OnSelectedParametersTableChanged(); } } - private Job _selectedJob; + private Job _activeJob; /// /// Gets or sets the selected machine job. /// - public Job SelectedJob + public Job ActiveJob { - get { return _selectedJob; } + get { return _activeJob; } set { - _selectedJob = value; + _activeJob = value; RaisePropertyChangedAuto(); + OnActiveJobChanged(); } } + private Job _selectedMachineJob; + /// + /// Gets or sets the selected machine job. + /// + public Job SelectedMachineJob + { + get { return _selectedMachineJob; } + set { _selectedMachineJob = value; RaisePropertyChangedAuto(); } + } + private ObservableCollection _selectedJobs; /// /// Gets or sets the selected jobs. @@ -396,6 +426,52 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _runningJobSegments = value; RaisePropertyChangedAuto(); } } + private ICollectionView _jobsCollectionView; + /// + /// Gets or sets the jobs collection view. + /// + public ICollectionView JobsCollectionView + { + get { return _jobsCollectionView; } + set + { + _jobsCollectionView = value; + BindingOperations.EnableCollectionSynchronization(_jobsCollectionView, _syncLock); + + RaisePropertyChangedAuto(); + } + } + + private ICollectionView _segmentsCollectionView; + /// + /// Gets or sets the segments collection view. + /// + public ICollectionView SegmentsCollectionView + { + get { return _segmentsCollectionView; } + set + { + _segmentsCollectionView = value; + BindingOperations.EnableCollectionSynchronization(_segmentsCollectionView, _syncLock); + RaisePropertyChangedAuto(); + } + } + + private ICollectionView _brushStopsCollectionView; + /// + /// Gets or sets the brush stops collection view. + /// + public ICollectionView BrushStopsCollectionView + { + get { return _brushStopsCollectionView; } + set + { + _brushStopsCollectionView = value; + BindingOperations.EnableCollectionSynchronization(_brushStopsCollectionView, _syncLock); + RaisePropertyChangedAuto(); + } + } + #endregion #region Commands @@ -500,6 +576,16 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public RelayCommand DuplicateJobCommand { get; set; } + /// + /// Gets or sets the duplicate segment command. + /// + public RelayCommand DuplicateSegmentCommand { get; set; } + + /// + /// Gets or sets the duplicate brush stop command. + /// + public RelayCommand DuplicateBrushStopCommand { get; set; } + #endregion #region Constructors @@ -527,6 +613,8 @@ namespace Tango.MachineStudio.Developer.ViewModels [PreferredConstructor] public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IMainView view, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, IAuthenticationProvider authentication) : this(view) { + _machineDBContext = ObservablesContext.CreateDefault(); + SelectedJobs = new ObservableCollection(); _authentication = authentication; @@ -543,20 +631,22 @@ namespace Tango.MachineStudio.Developer.ViewModels ToggleSideBarCommand = new RelayCommand(() => IsSideBarOpened = !IsSideBarOpened); SaveProcessParametersCommand = new RelayCommand(SaveProcessParameters, () => SelectedRML != null && SelectedRML.ProcessParametersTablesGroups.Count > 0); SaveLiquidFactorsCommand = new RelayCommand(SaveLiquidFactors, () => SelectedRML != null); - AddSegmentCommand = new RelayCommand(AddSegment, () => SelectedJob != null); - RemoveSegmentCommand = new RelayCommand(RemoveSegment, () => SelectedSegment != null); + AddSegmentCommand = new RelayCommand(AddSegment, () => ActiveJob != null); + RemoveSegmentCommand = new RelayCommand(RemoveSelectedSegments, () => SelectedSegment != null); AddJobCommand = new RelayCommand(AddJob, () => SelectedMachine != null); - RemoveJobCommand = new RelayCommand(RemoveJob, () => SelectedJob != null); + RemoveJobCommand = new RelayCommand(RemoveSelectedJobs, () => SelectedMachineJob != null); AddBrushStopCommand = new RelayCommand(AddBrushStop, () => SelectedSegment != null); - RemoveBrushStopCommand = new RelayCommand(RemoveBrushStop, () => SelectedBrushStop != null); + RemoveBrushStopCommand = new RelayCommand(RemoveSelectedBrushStops, () => SelectedBrushStop != null); SaveJobCommand = new RelayCommand(SaveJob, () => SelectedMachine != null); DiscardJobCommand = new RelayCommand(DiscardJob, () => SelectedMachine != null); - StartJobCommand = new RelayCommand(StartJob, () => SelectedJob != null && !IsJobRunning); + StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); ExitFullScreenCommand = new RelayCommand(ExitFullScreen); - LoadJobCommand = new RelayCommand(LoadJob, () => SelectedJob != null); - DuplicateJobCommand = new RelayCommand(DuplicateJob, () => SelectedJob != null); + LoadJobCommand = new RelayCommand(LoadJob, () => SelectedMachineJob != null); + DuplicateJobCommand = new RelayCommand(DuplicateSelectedJobs, () => SelectedMachineJob != null); + DuplicateSegmentCommand = new RelayCommand(DuplicateSelectedSegments, () => SelectedSegment != null); + DuplicateBrushStopCommand = new RelayCommand(DuplicateSelectedBrushStops, () => SelectedBrushStop != null); ToggleCameraCommand = new RelayCommand(ToggleCamera); @@ -595,7 +685,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private void SelectedMachine_Saved(object sender, EventArgs e) { InvalidateLiquidFactorsAndProcessTables(); - SelectedMachine.Reload(); + SelectedMachine.Reload(_machineDBContext); } /// @@ -603,7 +693,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// The source of the event. /// The instance containing the event data. - private void SelectedJob_LengthChanged(object sender, EventArgs e) + private void ActiveJob_LengthChanged(object sender, EventArgs e) { UpdateEstimatedDuration(); } @@ -639,6 +729,8 @@ namespace Tango.MachineStudio.Developer.ViewModels } SetSegmentBrushStopsLiquidVolumes(SelectedSegment); + + UpdateEstimatedDuration(); } /// @@ -663,6 +755,9 @@ namespace Tango.MachineStudio.Developer.ViewModels { SetSegmentBrushStopsLiquidVolumes(SelectedSegment); SelectedBrushStop = SelectedSegment.BrushStops.FirstOrDefault(); + + BrushStopsCollectionView = CollectionViewSource.GetDefaultView(SelectedSegment.BrushStops); + BrushStopsCollectionView.SortDescriptions.Add(new SortDescription(nameof(BrushStop.StopIndex), ListSortDirection.Ascending)); } } @@ -680,38 +775,45 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Called when the machine has been changed /// - protected virtual void OnMachineChanged() + protected virtual void OnSelectedMachineChanged() { - InvalidateLiquidFactorsAndProcessTables(); + if (SelectedMachine != null) + { + ReloadMachine(); + JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); + JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); + InvalidateLiquidFactorsAndProcessTables(); + } + } + + private void ReloadMachine() + { + _machineDBContext.Dispose(); + _machineDBContext = ObservablesContext.CreateDefault(); + _machineDBContext.Configuration.LazyLoadingEnabled = true; + _selectedMachine = _machineDBContext.Machines.SingleOrDefault(x => x.Guid == _selectedMachine.Guid); + RaisePropertyChanged(nameof(SelectedMachine)); + + JobsCollectionView = CollectionViewSource.GetDefaultView(SelectedMachine.Jobs); + JobsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Job.LastUpdated), ListSortDirection.Descending)); } #endregion #region Private Methods - private async void DuplicateJob() + private void OnActiveJobChanged() { - if (SelectedJobs.Count > 0) + if (ActiveJob != null) { - using (_notification.PushTaskItem("Cloning selected jobs...")) - { - int index = SelectedMachine.Jobs.Max(x => x.JobIndex); - - foreach (var job in SelectedJobs) - { - var cloned = job.Clone(); - cloned.JobIndex = ++index; - SelectedMachine.Jobs.Add(cloned); - } - - await SelectedMachine.SaveAsync(); - } + SegmentsCollectionView = CollectionViewSource.GetDefaultView(ActiveJob.Segments); + SegmentsCollectionView.SortDescriptions.Add(new SortDescription(nameof(Segment.SegmentIndex), ListSortDirection.Ascending)); } } - private async void LoadJob() + private void LoadJob() { - if (SelectedJob != null) + if (SelectedMachineJob != null) { SelectedSegments = new ObservableCollection(); SelectedBrushStops = new ObservableCollection(); @@ -726,33 +828,34 @@ namespace Tango.MachineStudio.Developer.ViewModels { //await Task.Factory.StartNew(() => //{ - _blockInvalidateCommands = false; + _blockInvalidateCommands = false; + + _dbJobContext = ObservablesContext.CreateDefault(); + _dbJobContext.Configuration.LazyLoadingEnabled = true; - _dbJobContext = ObservablesContext.CreateDefault(); - _dbJobContext.Configuration.LazyLoadingEnabled = true; + ColorSpaces = _dbJobContext.ColorSpaces.ToObservableCollection(); + Rmls = _dbJobContext.Rmls.ToObservableCollection(); - ColorSpaces = _dbJobContext.ColorSpaces.ToObservableCollection(); - Rmls = _dbJobContext.Rmls.ToObservableCollection(); + _activeJob = _dbJobContext.Jobs.SingleOrDefault(x => x.Guid == SelectedMachineJob.Guid); - _jobFromList = SelectedJob; - _selectedJob = _dbJobContext.Jobs.SingleOrDefault(x => x.Guid == SelectedJob.Guid); - _selectedRML = SelectedJob.Rml; + _selectedRML = ActiveJob.Rml; - _selectedSegment = SelectedJob.Segments.FirstOrDefault(); + _selectedSegment = ActiveJob.Segments.FirstOrDefault(); - SelectedJob.LengthChanged -= SelectedJob_LengthChanged; - SelectedJob.LengthChanged += SelectedJob_LengthChanged; + ActiveJob.LengthChanged -= ActiveJob_LengthChanged; + ActiveJob.LengthChanged += ActiveJob_LengthChanged; - SelectedJob = _selectedJob; - SelectedRML = _selectedRML; - SelectedSegment = _selectedSegment; + ActiveJob = _activeJob; - UpdateEstimatedDuration(); + SelectedRML = _selectedRML; + SelectedSegment = _selectedSegment; - _blockInvalidateCommands = false; - InvalidateRelayCommands(); + UpdateEstimatedDuration(); - InvokeUI(() => _navigation.NavigateTo(DeveloperNavigationView.JobView)); + _blockInvalidateCommands = false; + InvalidateRelayCommands(); + + InvokeUI(() => _navigation.NavigateTo(DeveloperNavigationView.JobView)); //}); } } @@ -760,45 +863,27 @@ namespace Tango.MachineStudio.Developer.ViewModels private async void SaveJob() { - if (SelectedJob != null) + if (ActiveJob != null) { using (_notification.PushTaskItem("Saving job to database...")) { - SelectedJob.LastUpdated = DateTime.UtcNow; - SelectedJob.Rml = SelectedRML; - await SelectedJob.SaveAsync(_dbJobContext); - _jobFromList = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SelectedJob.Guid); - await _jobFromList.Reload(); - - foreach (var segment in _jobFromList.Segments) - { - await segment.Reload(); + ActiveJob.LastUpdated = DateTime.UtcNow; + ActiveJob.Rml = SelectedRML; - foreach (var stop in segment.BrushStops) - { - await stop.Reload(); - } - } + await ActiveJob.SaveAsync(_dbJobContext); + ReloadMachine(); + SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == ActiveJob.Guid); } } } private void DiscardJob() { - //bool jobModified = !SelectedJob.WithDeepEqual(_jobFromList) - // .IgnoreSourceProperty(x => x.Machine) - // .IgnoreSourceProperty(x => x.JobRuns) - // .IgnoreSourceProperty(x => x.Parameters) - // .IgnoreSourceProperty(x => x.Rml) - // .IgnoreSourceProperty(x => x.User) - // .IgnoreSourceProperty(x => x.Segments) - // .Compare(); - - bool jobModified = !SelectedJob.CompareUsingJson(_jobFromList); + bool jobModified = !ActiveJob.CompareUsingJson(SelectedMachineJob); if (jobModified) { - if (_notification.ShowQuestion("This will discard the current job changes. Are you sue?")) + if (_notification.ShowQuestion("This will discard the current job changes. Are you sure?")) { _dbJobContext.Dispose(); _navigation.NavigateTo(DeveloperNavigationView.MachineJobSelectionView); @@ -914,14 +999,14 @@ namespace Tango.MachineStudio.Developer.ViewModels IsJobCompleted = false; IsJobRunning = true; ShowJobStatus = true; - RunningJob = SelectedJob; + RunningJob = ActiveJob; _runningJobEstimatedDuration = EstimatedDuration; RunningJobSegments = CreateRunningJobEffectiveSegments(RunningJob); _navigation.NavigateTo(DeveloperNavigationView.RunningJobView); - _jobHandler = MachineOperator.Print(SelectedJob, SelectedProcessParametersTable); + _jobHandler = MachineOperator.Print(ActiveJob, SelectedProcessParametersTable); _jobHandler.StatusReceived += (x, status) => { @@ -973,9 +1058,9 @@ namespace Tango.MachineStudio.Developer.ViewModels private void UpdateEstimatedDuration() { - if (SelectedJob != null && SelectedProcessParametersTable != null && SelectedProcessParametersTable.DyeingSpeed > 0) + if (ActiveJob != null && SelectedProcessParametersTable != null && SelectedProcessParametersTable.DyeingSpeed > 0) { - EstimatedDuration = TimeSpan.FromSeconds(SelectedJob.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); + EstimatedDuration = TimeSpan.FromSeconds(ActiveJob.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); } } @@ -1090,14 +1175,93 @@ namespace Tango.MachineStudio.Developer.ViewModels } } + private List CreateRunningJobEffectiveSegments(Job job) + { + List segments = new List(); + foreach (var s in job.Segments) + { + s.Completed = false; + s.Started = false; + segments.Add(s); + + if (job.EnableInterSegment && job.Segments.IndexOf(s) != job.Segments.Count - 1) + { + segments.Add(new Segment() + { + Length = job.InterSegmentLength, + BrushStops = new System.Collections.ObjectModel.ObservableCollection() + { + new BrushStop() + { + Color = Colors.White, + } + }, + Started = false, + Completed = false + }); + } + } + + return segments; + } + + #endregion + + #region Add / Remove / Duplicate Jobs, Segments & Brush Stops + + private void ArrangeSegmentsIndices() + { + int index = 1; + + foreach (var segment in ActiveJob.Segments.OrderBy(x => x.SegmentIndex)) + { + segment.SegmentIndex = index++; + } + + SegmentsCollectionView.Refresh(); + } + + private void ArrangeBrushStopsIndices() + { + int index = 0; + + foreach (var stop in SelectedSegment.BrushStops.OrderBy(x => x.StopIndex)) + { + stop.SetStopIndex(index++); + } + + if (SelectedSegment.BrushStops.Count > 1) + { + SelectedSegment.BrushStops.OrderBy(x => x.StopIndex).First().OffsetPercent = 0; + SelectedSegment.BrushStops.OrderBy(x => x.StopIndex).Last().OffsetPercent = 100; + } + + foreach (var stop in SelectedSegment.BrushStops.OrderBy(x => x.StopIndex)) + { + stop.RaiseStopIndex(); + stop.RaiseOffsetChanged(); + } + + BrushStopsCollectionView.Refresh(); + } + /// - /// Removes the selected segment. + /// Removes the selected segments. /// - private void RemoveSegment() + private void RemoveSelectedSegments() { - if (SelectedJob != null && SelectedSegment != null) + if (ActiveJob != null && SelectedSegment != null) { - SelectedJob.Segments.Remove(SelectedSegment); + if (_notification.ShowQuestion("Are you sure you want to delete the selected segments?")) + { + SelectedSegments.ToList().ForEach(x => + { + ActiveJob.Segments.Remove(x); + x.DefferedDelete(_dbJobContext); + }); + + ArrangeSegmentsIndices(); + } } } @@ -1106,31 +1270,46 @@ namespace Tango.MachineStudio.Developer.ViewModels /// private void AddSegment() { - if (SelectedJob != null) + if (ActiveJob != null) { Segment seg = new Segment(); seg.Name = "Untitled Segment"; - seg.Length = 1; - SelectedJob.Segments.Add(seg); + seg.Length = 10; + + if (ActiveJob.Segments.Count > 0) + { + seg.SegmentIndex = ActiveJob.Segments.Max(x => x.SegmentIndex) + 1; + } + else + { + seg.SegmentIndex = 1; + } + ActiveJob.Segments.Add(seg); SelectedSegment = seg; AddBrushStop(); + ArrangeSegmentsIndices(); } } /// - /// Removes the selected job. + /// Removes the selected jobs. /// - private async void RemoveJob() + private async void RemoveSelectedJobs() { - if (SelectedMachine != null && SelectedJob != null) + if (SelectedMachine != null && SelectedMachineJob != null) { if (_notification.ShowQuestion("Are you sure you want to delete the selected jobs?")) { SelectedJobs.ToList().ForEach(x => { - x.DefferedDelete(); + SelectedMachine.Jobs.Remove(x); + x.DefferedDelete(_machineDBContext); }); - await SelectedMachine.SaveAsync(); + + using (_notification.PushTaskItem("Removing selected jobs...")) + { + await SelectedMachine.SaveAsync(_machineDBContext); + } } } } @@ -1138,7 +1317,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Adds a new job to the selected machine. /// - private void AddJob() + private async void AddJob() { if (SelectedMachine != null) { @@ -1151,9 +1330,14 @@ namespace Tango.MachineStudio.Developer.ViewModels newJob.CreationDate = DateTime.UtcNow; newJob.User = _authentication.CurrentUser; newJob.Rml = Adapter.Rmls.FirstOrDefault(); + newJob.WindingMethod = Adapter.WindingMethods.FirstOrDefault(); + newJob.Machine = SelectedMachine; - SelectedJob = newJob; + SelectedMachine.Jobs.Add(newJob); + await SelectedMachine.SaveAsync(_machineDBContext); + SelectedMachineJob = newJob; LoadJob(); + AddSegment(); } } } @@ -1161,18 +1345,20 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Removes the selected brush stop. /// - private void RemoveBrushStop() + private void RemoveSelectedBrushStops() { if (SelectedBrushStop != null && SelectedSegment != null) { - SelectedSegment.BrushStops.Remove(SelectedBrushStop); - - if (SelectedSegment.BrushStops.Count > 1) + if (_notification.ShowQuestion("Are you sure you want to delete the selected colors?")) { - SelectedSegment.BrushStops.Last().OffsetPercent = 100; - } + SelectedBrushStops.ToList().ForEach(x => + { + SelectedSegment.BrushStops.Remove(x); + x.DefferedDelete(_dbJobContext); + }); - SelectedSegment.BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged()); + ArrangeBrushStopsIndices(); + } } } @@ -1184,44 +1370,78 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SelectedSegment != null) { var stop = new BrushStop(); + + if (SelectedSegment.BrushStops.Count > 0) + { + stop.StopIndex = SelectedSegment.BrushStops.Max(x => x.StopIndex) + 1; + } + else + { + stop.StopIndex = 0; + } + stop.OffsetPercent = 100; stop.Segment = SelectedSegment; - stop.ColorSpace = Adapter.ColorSpaces.FirstOrDefault(); + stop.ColorSpace = _dbJobContext.ColorSpaces.FirstOrDefault(); stop.Color = Colors.Black; stop.SetLiquidVolumes(SelectedMachine.Configuration, SelectedRML, SelectedProcessParametersTable); SelectedSegment.BrushStops.Add(stop); SelectedSegment.BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged()); + ArrangeBrushStopsIndices(); } } - private List CreateRunningJobEffectiveSegments(Job job) + /// + /// Duplicates the selected brush stops. + /// + private void DuplicateSelectedBrushStops() { - List segments = new List(); - foreach (var s in job.Segments) + foreach (var stop in SelectedBrushStops.OrderBy(x => x.StopIndex)) { - s.Completed = false; - s.Started = false; - segments.Add(s); + var cloned = stop.Clone(); + cloned.StopIndex = SelectedSegment.BrushStops.Max(x => x.StopIndex) + 1; + SelectedSegment.BrushStops.Add(cloned); + } - if (job.EnableInterSegment && job.Segments.IndexOf(s) != job.Segments.Count - 1) + ArrangeBrushStopsIndices(); + } + + /// + /// Duplicates the selected segments. + /// + private void DuplicateSelectedSegments() + { + foreach (var segment in SelectedSegments.OrderBy(x => x.SegmentIndex)) + { + var cloned = segment.Clone(); + cloned.SegmentIndex = ActiveJob.Segments.Max(x => x.SegmentIndex) + 1; + ActiveJob.Segments.Add(cloned); + } + + ArrangeSegmentsIndices(); + } + + /// + /// Duplicates the selected jobs. + /// + private async void DuplicateSelectedJobs() + { + if (SelectedMachineJob != null) + { + using (_notification.PushTaskItem("Cloning selected jobs...")) { - segments.Add(new Segment() + int index = SelectedMachine.Jobs.Max(x => x.JobIndex); + + foreach (var job in SelectedJobs) { - Length = job.InterSegmentLength, - BrushStops = new System.Collections.ObjectModel.ObservableCollection() - { - new BrushStop() - { - Color = Colors.White, - } - }, - Started = false, - Completed = false - }); + var cloned = job.Clone(); + cloned.JobIndex = ++index; + SelectedMachine.Jobs.Add(cloned); + } + + await SelectedMachine.SaveAsync(_machineDBContext); } } - - return segments; } #endregion @@ -1311,17 +1531,9 @@ namespace Tango.MachineStudio.Developer.ViewModels /// The dropped stop. public void OnDropBrushStop(BrushStop draggedStop, BrushStop droppedStop) { - SelectedSegment.BrushStops.Swap(draggedStop, droppedStop); - - int tmpIndex = draggedStop.StopIndex; - draggedStop.StopIndex = droppedStop.StopIndex; - droppedStop.StopIndex = tmpIndex; - - if (SelectedSegment.BrushStops.Count > 1) - { - SelectedSegment.BrushStops.First().OffsetPercent = 0; - SelectedSegment.BrushStops.Last().OffsetPercent = 100; - } + draggedStop.SetStopIndex(droppedStop.StopIndex); + droppedStop.SetStopIndex(droppedStop.StopIndex + 1); + ArrangeBrushStopsIndices(); } /// @@ -1354,7 +1566,7 @@ namespace Tango.MachineStudio.Developer.ViewModels } SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedMachineGuid = SelectedMachine != null ? SelectedMachine.Guid : null; - SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid = SelectedJob != null ? SelectedJob.Guid : null; + SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid = ActiveJob != null ? ActiveJob.Guid : null; return Task.FromResult(true); } @@ -1374,7 +1586,7 @@ namespace Tango.MachineStudio.Developer.ViewModels if (SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid != null && SelectedMachine != null) { - SelectedJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); + ActiveJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == SettingsManager.Default.MachineStudio.DeveloperModule.LastSelectedJobGuid); } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index 35a30e91e..cf7af21d9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -75,39 +75,6 @@ Transparent - - - - - - + # @@ -333,13 +287,12 @@ - - + + - @@ -378,11 +331,11 @@ - + - + @@ -394,7 +347,7 @@ Name - + @@ -404,7 +357,7 @@ Winding Method - + @@ -415,8 +368,8 @@ Inter Segment - - + + @@ -428,7 +381,7 @@ Lubrication - + @@ -441,7 +394,7 @@ - + @@ -619,7 +572,7 @@ - + - + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 7e0ef2eb5..cd4fc1aeb 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -185,6 +185,10 @@ {38197109-8610-4d3f-92b9-16d48df94d7c} Tango.DAL.Remote + + {b112d89a-a106-41ae-a0c1-4abc84c477f5} + Tango.DragAndDrop + {de2f2b86-025b-4f26-83a4-38bd48224ed5} Tango.Editors -- cgit v1.3.1