diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-19 17:17:25 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-02-19 17:17:25 +0200 |
| commit | 8feeef663f8984c609cb3aa530d09ffcffda5709 (patch) | |
| tree | 6b69a7a62ea1234ba5b16948dd3781078834a973 /Software/Visual_Studio/MachineStudio | |
| parent | 95b4e14bc4e06ffb94199f5ec4e0d2d9bebceeff (diff) | |
| download | Tango-8feeef663f8984c609cb3aa530d09ffcffda5709.tar.gz Tango-8feeef663f8984c609cb3aa530d09ffcffda5709.zip | |
Working on new developer module...
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
14 files changed, 483 insertions, 231 deletions
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 /// <seealso cref="Tango.SharedUI.ViewModel" /> public class MainViewVM : ViewModel<IMainView>, IShutdownRequestBlocker { + private static object _syncLock = new object(); + private INotificationProvider _notification; private TimeSpan _runningJobEstimatedDuration; private Dictionary<String, GraphControllerBase> _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<ProcessParametersTablesGroup> _groupsHistory; /// <summary> /// 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; /// <summary> /// Gets or sets the selected machine job. /// </summary> - public Job SelectedJob + public Job ActiveJob { - get { return _selectedJob; } + get { return _activeJob; } set { - _selectedJob = value; + _activeJob = value; RaisePropertyChangedAuto(); + OnActiveJobChanged(); } } + private Job _selectedMachineJob; + /// <summary> + /// Gets or sets the selected machine job. + /// </summary> + public Job SelectedMachineJob + { + get { return _selectedMachineJob; } + set { _selectedMachineJob = value; RaisePropertyChangedAuto(); } + } + private ObservableCollection<Job> _selectedJobs; /// <summary> /// Gets or sets the selected jobs. @@ -396,6 +426,52 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _runningJobSegments = value; RaisePropertyChangedAuto(); } } + private ICollectionView _jobsCollectionView; + /// <summary> + /// Gets or sets the jobs collection view. + /// </summary> + public ICollectionView JobsCollectionView + { + get { return _jobsCollectionView; } + set + { + _jobsCollectionView = value; + BindingOperations.EnableCollectionSynchronization(_jobsCollectionView, _syncLock); + + RaisePropertyChangedAuto(); + } + } + + private ICollectionView _segmentsCollectionView; + /// <summary> + /// Gets or sets the segments collection view. + /// </summary> + public ICollectionView SegmentsCollectionView + { + get { return _segmentsCollectionView; } + set + { + _segmentsCollectionView = value; + BindingOperations.EnableCollectionSynchronization(_segmentsCollectionView, _syncLock); + RaisePropertyChangedAuto(); + } + } + + private ICollectionView _brushStopsCollectionView; + /// <summary> + /// Gets or sets the brush stops collection view. + /// </summary> + 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 /// </summary> public RelayCommand DuplicateJobCommand { get; set; } + /// <summary> + /// Gets or sets the duplicate segment command. + /// </summary> + public RelayCommand DuplicateSegmentCommand { get; set; } + + /// <summary> + /// Gets or sets the duplicate brush stop command. + /// </summary> + 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<Job>(); _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<CaptureDevice>(ToggleCamera); @@ -595,7 +685,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private void SelectedMachine_Saved(object sender, EventArgs e) { InvalidateLiquidFactorsAndProcessTables(); - SelectedMachine.Reload(); + SelectedMachine.Reload(_machineDBContext); } /// <summary> @@ -603,7 +693,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> - 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(); } /// <summary> @@ -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 /// <summary> /// Called when the machine has been changed /// </summary> - 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<Segment>(); SelectedBrushStops = new ObservableCollection<BrushStop>(); @@ -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<Segment> CreateRunningJobEffectiveSegments(Job job) + { + List<Segment> segments = new List<Segment>(); + 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<BrushStop>() + { + 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(); + } + /// <summary> - /// Removes the selected segment. + /// Removes the selected segments. /// </summary> - 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 /// </summary> 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(); } } /// <summary> - /// Removes the selected job. + /// Removes the selected jobs. /// </summary> - 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 /// <summary> /// Adds a new job to the selected machine. /// </summary> - 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 /// <summary> /// Removes the selected brush stop. /// </summary> - 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<Segment> CreateRunningJobEffectiveSegments(Job job) + /// <summary> + /// Duplicates the selected brush stops. + /// </summary> + private void DuplicateSelectedBrushStops() { - List<Segment> segments = new List<Segment>(); - 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(); + } + + /// <summary> + /// Duplicates the selected segments. + /// </summary> + 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(); + } + + /// <summary> + /// Duplicates the selected jobs. + /// </summary> + 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<BrushStop>() - { - 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 /// <param name="droppedStop">The dropped stop.</param> 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(); } /// <summary> @@ -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 @@ <Color x:Key="dummyColor">Transparent</Color> - <Style x:Key="droppableGrid" TargetType="Grid"> - <Setter Property="RenderTransform"> - <Setter.Value> - <ScaleTransform ScaleX="1" ScaleY="1"></ScaleTransform> - </Setter.Value> - </Setter> - <Setter Property="RenderTransformOrigin" Value="0.5,0.5"></Setter> - <Setter Property="Background" Value="Transparent"></Setter> - <Setter Property="dragAndDrop:DragAndDropService.Droppable" Value="True"></Setter> - <Setter Property="dragAndDrop:DragAndDropService.DraggingSurface" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}"></Setter> - <Style.Triggers> - <Trigger Property="dragAndDrop:DragAndDropService.IsDraggableOver" Value="True"> - <Setter Property="Opacity" Value="0.5"></Setter> - <Trigger.EnterActions> - <BeginStoryboard> - <Storyboard> - <DoubleAnimation To="0.95" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleX"></DoubleAnimation> - <DoubleAnimation To="0.95" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleY"></DoubleAnimation> - </Storyboard> - </BeginStoryboard> - </Trigger.EnterActions> - <Trigger.ExitActions> - <BeginStoryboard> - <Storyboard> - <DoubleAnimation To="1" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleX"></DoubleAnimation> - <DoubleAnimation To="1" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleY"></DoubleAnimation> - </Storyboard> - </BeginStoryboard> - </Trigger.ExitActions> - </Trigger> - </Style.Triggers> - </Style> - <Style x:Key="brushStopBorder" TargetType="Border"> <Setter Property="RenderTransform"> <Setter.Value> @@ -142,18 +109,6 @@ </Style.Triggers> </Style> - <Style x:Key="draggableGrid" TargetType="Grid"> - <Setter Property="RenderTransform"> - <Setter.Value> - <ScaleTransform ScaleX="1" ScaleY="1"></ScaleTransform> - </Setter.Value> - </Setter> - <Setter Property="RenderTransformOrigin" Value="0.5,0.5"></Setter> - <Setter Property="Background" Value="Transparent"></Setter> - <Setter Property="dragAndDrop:DragAndDropService.Draggable" Value="True"></Setter> - <Setter Property="dragAndDrop:DragAndDropService.DraggingSurface" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}"></Setter> - </Style> - <Style TargetType="Border" x:Key="JobFieldBorder"> <Setter Property="BorderBrush" Value="#A5A4A4"></Setter> <Setter Property="BorderThickness" Value="0 0 1 1"></Setter> @@ -281,7 +236,7 @@ </StackPanel> </Border> - <controls:MultiSelectListBox Style="{StaticResource {x:Type ListBox}}" SelectionMode="Extended" SelectionChanged="ListBox_SelectionChanged" ItemsSource="{Binding SelectedJob.Segments}" SelectedItem="{Binding SelectedSegment}" SelectedItemsList="{Binding SelectedSegments,Mode=TwoWay}" HorizontalContentAlignment="Stretch"> + <controls:MultiSelectListBox Style="{StaticResource {x:Type ListBox}}" SelectionMode="Extended" SelectionChanged="ListBox_SelectionChanged" ItemsSource="{Binding SegmentsCollectionView}" SelectedItem="{Binding SelectedSegment}" SelectedItemsList="{Binding SelectedSegments,Mode=TwoWay}" HorizontalContentAlignment="Stretch"> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem" BasedOn="{StaticResource basicListBoxItem}"> @@ -289,8 +244,8 @@ </ListBox.ItemContainerStyle> <ListBox.ItemTemplate> <DataTemplate> - <Grid Margin="5 10"> - <Polygon Points="40,0 290,0 290,100 0,100 0,30" StrokeThickness="0.2"> + <Grid Margin="5 10" Style="{StaticResource draggableDroppableGrid}" dragAndDrop:DragAndDropService.Drop="OnSegmentDrop"> + <Polygon Points="40,0 290,0 290,100 0,100 0,30" StrokeThickness="0.2" IsHitTestVisible="False"> <Polygon.Effect> <DropShadowEffect Opacity="0.5" /> </Polygon.Effect> @@ -321,8 +276,7 @@ </Style> </Polygon.Style> </Polygon> - <Border Height="100" Padding="5"> - + <Border Height="100" Padding="5" IsHitTestVisible="False"> <Grid> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16" FontStyle="Italic"> <Run>#</Run> @@ -333,13 +287,12 @@ <Rectangle.Fill> <MultiBinding Converter="{StaticResource SegmentToBrushConverterMulti}"> <Binding Path="."></Binding> - <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedJob"></Binding> - <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedJob.Length"></Binding> + <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.ActiveJob"></Binding> + <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.ActiveJob.Length"></Binding> <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedBrushStop.Color"></Binding> </MultiBinding> </Rectangle.Fill> </Rectangle> - </Grid> </Border> @@ -378,11 +331,11 @@ <Grid> <StackPanel Orientation="Horizontal" Margin="10"> <Image Source="../Images/rgb.png" Width="24"></Image> - <TextBlock Margin="5 0 0 0" Text="{Binding SelectedJob.Name,FallbackValue='UNSET'}" FontSize="16" FontWeight="SemiBold" VerticalAlignment="Center"></TextBlock> + <TextBlock Margin="5 0 0 0" Text="{Binding ActiveJob.Name,FallbackValue='UNSET'}" FontSize="16" FontWeight="SemiBold" VerticalAlignment="Center"></TextBlock> </StackPanel> <StackPanel Orientation="Horizontal" Margin="0 5 0 0" HorizontalAlignment="Right"> - <TextBlock Margin="0 0 5 0" Text="{Binding SelectedJob.CreationDate,FallbackValue='UNSET'}" FontSize="12" Foreground="Gray" FontStyle="Italic" VerticalAlignment="Center"></TextBlock> + <TextBlock Margin="0 0 5 0" Text="{Binding ActiveJob.CreationDate,FallbackValue='UNSET'}" FontSize="12" Foreground="Gray" FontStyle="Italic" VerticalAlignment="Center"></TextBlock> <Image Source="../Images/calendar.png" Width="16"></Image> </StackPanel> </Grid> @@ -394,7 +347,7 @@ <Image Source="../Images/name.png" Width="32"></Image> <TextBlock VerticalAlignment="Center" Margin="5 0 0 0" FontSize="10">Name</TextBlock> </StackPanel> - <TextBox Margin="0 3 0 0" Width="100" HorizontalAlignment="Left" Text="{Binding SelectedJob.Name,UpdateSourceTrigger=PropertyChanged}"></TextBox> + <TextBox Margin="0 3 0 0" Width="100" HorizontalAlignment="Left" Text="{Binding ActiveJob.Name,UpdateSourceTrigger=PropertyChanged}"></TextBox> </StackPanel> </Border> @@ -404,7 +357,7 @@ <Image Source="../Images/wind.png" Width="32"></Image> <TextBlock VerticalAlignment="Center" Margin="5 0 0 0" FontSize="10">Winding Method</TextBlock> </StackPanel> - <ComboBox Width="90" HorizontalAlignment="Left" ItemsSource="{Binding Adapter.WindingMethods}" SelectedItem="{Binding SelectedJob.WindingMethod}" DisplayMemberPath="Name" ></ComboBox> + <ComboBox Width="90" HorizontalAlignment="Left" ItemsSource="{Binding Adapter.WindingMethods}" SelectedItem="{Binding ActiveJob.WindingMethod}" DisplayMemberPath="Name" ></ComboBox> </StackPanel> </Border> @@ -415,8 +368,8 @@ <TextBlock VerticalAlignment="Center" Margin="5 0 0 0" FontSize="10">Inter Segment</TextBlock> </StackPanel> <DockPanel LastChildFill="True"> - <ToggleButton Margin="10 0 25 0" DockPanel.Dock="Right" VerticalAlignment="Bottom" HorizontalAlignment="Right" IsChecked="{Binding SelectedJob.EnableInterSegment}"></ToggleButton> - <mahapps:NumericUpDown Width="70" HorizontalAlignment="Left" StringFormat="{}{0:N1} m" FontFamily="{StaticResource digital-7}" IsEnabled="{Binding SelectedJob.EnableInterSegment}" Margin="0 2 0 0" HideUpDownButtons="True" Minimum="0" Maximum="10000" InterceptArrowKeys="True" Background="Transparent" BorderThickness="0 0 0 1" BorderBrush="DimGray" InterceptMouseWheel="True" HasDecimals="True" HorizontalContentAlignment="Left" Value="{Binding SelectedJob.InterSegmentLength,Mode=TwoWay}"></mahapps:NumericUpDown> + <ToggleButton Margin="10 0 25 0" DockPanel.Dock="Right" VerticalAlignment="Bottom" HorizontalAlignment="Right" IsChecked="{Binding ActiveJob.EnableInterSegment}"></ToggleButton> + <mahapps:NumericUpDown Width="70" HorizontalAlignment="Left" StringFormat="{}{0:N1} m" FontFamily="{StaticResource digital-7}" IsEnabled="{Binding ActiveJob.EnableInterSegment}" Margin="0 2 0 0" HideUpDownButtons="True" Minimum="0" Maximum="10000" InterceptArrowKeys="True" Background="Transparent" BorderThickness="0 0 0 1" BorderBrush="DimGray" InterceptMouseWheel="True" HasDecimals="True" HorizontalContentAlignment="Left" Value="{Binding ActiveJob.InterSegmentLength,Mode=TwoWay}"></mahapps:NumericUpDown> </DockPanel> </StackPanel> </Border> @@ -428,7 +381,7 @@ <TextBlock VerticalAlignment="Center" Margin="5 0 0 0" FontSize="10">Lubrication</TextBlock> </StackPanel> <DockPanel LastChildFill="True" Margin="0 10 30 0"> - <ToggleButton DockPanel.Dock="Right" VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding SelectedJob.EnableLubrication}"></ToggleButton> + <ToggleButton DockPanel.Dock="Right" VerticalAlignment="Center" HorizontalAlignment="Center" IsChecked="{Binding ActiveJob.EnableLubrication}"></ToggleButton> </DockPanel> </StackPanel> </Border> @@ -441,7 +394,7 @@ </StackPanel> <Border BorderThickness="0" BorderBrush="Silver" CornerRadius="5" Margin="0 0 5 5"> - <TextBox Padding="5 0 0 0" FontStyle="Italic" Background="Transparent" Style="{x:Null}" BorderThickness="0" Margin="5" Height="40" Text="{Binding SelectedJob.Description}" VerticalAlignment="Stretch" materialDesign:HintAssist.Hint="Enter description" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"></TextBox> + <TextBox Padding="5 0 0 0" FontStyle="Italic" Background="Transparent" Style="{x:Null}" BorderThickness="0" Margin="5" Height="40" Text="{Binding ActiveJob.Description}" VerticalAlignment="Stretch" materialDesign:HintAssist.Hint="Enter description" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"></TextBox> </Border> </StackPanel> </Border> @@ -619,7 +572,7 @@ </Rectangle> </Grid> <Grid Margin="0 10 10 0"> - <controls:MultiSelectListBox SelectionMode="Extended" Style="{x:Null}" Background="Transparent" ScrollViewer.CanContentScroll="False" BorderThickness="0" ItemsSource="{Binding SelectedSegment.BrushStops}" SelectedItem="{Binding SelectedBrushStop}" SelectedItemsList="{Binding SelectedBrushStops,Mode=TwoWay}" HorizontalContentAlignment="Stretch"> + <controls:MultiSelectListBox SelectionMode="Extended" Style="{x:Null}" Background="Transparent" ScrollViewer.CanContentScroll="False" BorderThickness="0" ItemsSource="{Binding BrushStopsCollectionView}" SelectedItem="{Binding SelectedBrushStop}" SelectedItemsList="{Binding SelectedBrushStops,Mode=TwoWay}" HorizontalContentAlignment="Stretch"> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem" BasedOn="{StaticResource basicListBoxItem}"> @@ -1097,8 +1050,8 @@ <Grid> <Grid.Width> <MultiBinding Converter="{StaticResource SegmentLengthToWidthConverter}"> - <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedJob"></Binding> - <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedJob.Length"></Binding> + <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.ActiveJob"></Binding> + <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.ActiveJob.Length"></Binding> <Binding RelativeSource="{RelativeSource AncestorType=ItemsControl}" Path="ActualWidth"></Binding> <Binding Path="Length"></Binding> </MultiBinding> @@ -1107,8 +1060,8 @@ <Rectangle.Fill> <MultiBinding Converter="{StaticResource SegmentToBrushConverterMulti}"> <Binding Path="."></Binding> - <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedJob"></Binding> - <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedJob.Length"></Binding> + <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.ActiveJob"></Binding> + <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.ActiveJob.Length"></Binding> <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedBrushStop.Color"></Binding> </MultiBinding> </Rectangle.Fill> @@ -1142,7 +1095,7 @@ <StackPanel Margin="0 -5 -20 0" HorizontalAlignment="Right"> <TextBlock FontSize="12" Foreground="Black"> - <Run Text="{Binding SelectedJob.Length,Mode=OneWay}"></Run> + <Run Text="{Binding ActiveJob.Length,Mode=OneWay}"></Run> <Run Foreground="Gray" FontSize="10" Text="m"></Run> </TextBlock> <materialDesign:PackIcon HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" Kind="FlagCheckered" Width="16" Height="16" Foreground="DimGray"> diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs index a030cf885..41886357b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs @@ -55,18 +55,18 @@ namespace Tango.MachineStudio.Developer.Views private void _jobBrushTimer_Tick(object sender, EventArgs e) { - if (_vm != null && _vm.SelectedJob != null) + if (_vm != null && _vm.ActiveJob != null) { List<Segment> segments = new List<Segment>(); - foreach (var s in _vm.SelectedJob.Segments) + foreach (var s in _vm.ActiveJob.Segments) { segments.Add(s); - if (_vm.SelectedJob.EnableInterSegment && _vm.SelectedJob.Segments.IndexOf(s) != _vm.SelectedJob.Segments.Count - 1) + if (_vm.ActiveJob.EnableInterSegment && _vm.ActiveJob.Segments.IndexOf(s) != _vm.ActiveJob.Segments.Count - 1) { segments.Add(new Segment() { - Length = _vm.SelectedJob.InterSegmentLength, + Length = _vm.ActiveJob.InterSegmentLength, BrushStops = new System.Collections.ObjectModel.ObservableCollection<BrushStop>() { new BrushStop() @@ -136,5 +136,10 @@ namespace Tango.MachineStudio.Developer.Views { e.Handled = true; } + + private void OnSegmentDrop(object sender, DropEventArgs e) + { + _vm.OnDropSegment(e.Draggable.DataContext as Segment, e.Droppable.DataContext as Segment); + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml index b8d423026..8881e4f57 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MachineJobSelectionView.xaml @@ -116,7 +116,7 @@ </Grid> <Grid Margin="0 20 0 0"> - <controls:MultiSelectDataGrid Style="{StaticResource {x:Type DataGrid}}" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeColumns="True" CanUserSortColumns="True" AutoGenerateColumns="False" Background="Transparent" ItemsSource="{Binding SelectedMachine.Jobs}" SelectedItem="{Binding SelectedJob}" SelectedItemsList="{Binding SelectedJobs,Mode=TwoWay}"> + <controls:MultiSelectDataGrid Style="{StaticResource {x:Type DataGrid}}" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeColumns="True" CanUserSortColumns="True" AutoGenerateColumns="False" Background="Transparent" ItemsSource="{Binding JobsCollectionView}" SelectedItem="{Binding SelectedMachineJob}" SelectedItemsList="{Binding SelectedJobs,Mode=TwoWay}"> <DataGrid.CellStyle> <Style TargetType="DataGridCell" BasedOn="{StaticResource {x:Type DataGridCell}}"> <Setter Property="BorderThickness" Value="0"/> @@ -180,9 +180,6 @@ <Border.Background> <MultiBinding Converter="{StaticResource SegmentToBrushConverterMulti}"> <Binding Path="."></Binding> - <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedJob"></Binding> - <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedJob.Length"></Binding> - <Binding RelativeSource="{RelativeSource AncestorType=UserControl}" Path="DataContext.SelectedBrushStop.Color"></Binding> </MultiBinding> </Border.Background> </Border> 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 e52a686bc..2bd36e449 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 @@ -77,18 +77,18 @@ namespace Tango.MachineStudio.Developer.Views private void _jobBrushTimer_Tick(object sender, EventArgs e) { - if (_vm != null && _vm.SelectedJob != null) + if (_vm != null && _vm.ActiveJob != null) { List<Segment> segments = new List<Segment>(); - foreach (var s in _vm.SelectedJob.Segments) + foreach (var s in _vm.ActiveJob.Segments) { segments.Add(s); - if (_vm.SelectedJob.EnableInterSegment && _vm.SelectedJob.Segments.IndexOf(s) != _vm.SelectedJob.Segments.Count - 1) + if (_vm.ActiveJob.EnableInterSegment && _vm.ActiveJob.Segments.IndexOf(s) != _vm.ActiveJob.Segments.Count - 1) { segments.Add(new Segment() { - Length = _vm.SelectedJob.InterSegmentLength, + Length = _vm.ActiveJob.InterSegmentLength, BrushStops = new System.Collections.ObjectModel.ObservableCollection<BrushStop>() { new BrushStop() diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml index 691fa6987..4d75651f7 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml @@ -81,16 +81,16 @@ <Rectangle Stroke="Gray" VerticalAlignment="Top" StrokeThickness="1" StrokeDashArray="5" RenderTransformOrigin="0.5,0.5"/> </Grid> - <Button Command="{Binding AddIdsCommand}" Style="{StaticResource MaterialDesignFlatButton}" Height="24" Width="24" Padding="0" Canvas.Left="402" Canvas.Top="253"> + <Button Style="{StaticResource MaterialDesignFlatButton}" Height="24" Width="24" Padding="0" Canvas.Left="402" Canvas.Top="253"> <materialDesign:PackIcon Kind="Plus" Width="24" Height="24"></materialDesign:PackIcon> </Button> - <Button Command="{Binding RemoveIdsCommand}" Style="{StaticResource MaterialDesignFlatButton}" Height="24" Width="24" Padding="0" Canvas.Left="430" Canvas.Top="252"> + <Button Style="{StaticResource MaterialDesignFlatButton}" Height="24" Width="24" Padding="0" Canvas.Left="430" Canvas.Top="252"> <materialDesign:PackIcon Kind="Minus" Width="24" Height="24"></materialDesign:PackIcon> </Button> <Grid x:Name="gridIds" Width="310" Height="195" Canvas.Top="314" Canvas.Left="420"> - <ListBox ItemsSource="{Binding Configuration.IdsPacks}" SelectedItem="{Binding SelectedIds}" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> + <ListBox ItemsSource="{Binding Configuration.IdsPacks}" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListBox.ItemContainerStyle> <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}"> <Setter Property="Padding" Value="0"></Setter> diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml index 9c7a869b7..ca0685f3c 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Resources/MaterialDesign.xaml @@ -1,8 +1,9 @@ <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf" + xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf" xmlns:editors="clr-namespace:Tango.AutoComplete.Editors;assembly=Tango.AutoComplete" - xmlns:sys="clr-namespace:System;assembly=mscorlib" + xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" + xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:Tango.MachineStudio.Common.Resources"> <ResourceDictionary.MergedDictionaries> <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! --> @@ -392,7 +393,87 @@ </Style> - + <!--Drag & Drop--> + <Style x:Key="draggableGrid" TargetType="Grid"> + <Setter Property="RenderTransform"> + <Setter.Value> + <ScaleTransform ScaleX="1" ScaleY="1"></ScaleTransform> + </Setter.Value> + </Setter> + <Setter Property="RenderTransformOrigin" Value="0.5,0.5"></Setter> + <Setter Property="Background" Value="Transparent"></Setter> + <Setter Property="dragAndDrop:DragAndDropService.Draggable" Value="True"></Setter> + <Setter Property="dragAndDrop:DragAndDropService.DraggingSurface" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}"></Setter> + </Style> + + <Style x:Key="droppableGrid" TargetType="Grid"> + <Setter Property="RenderTransform"> + <Setter.Value> + <ScaleTransform ScaleX="1" ScaleY="1"></ScaleTransform> + </Setter.Value> + </Setter> + <Setter Property="RenderTransformOrigin" Value="0.5,0.5"></Setter> + <Setter Property="Background" Value="Transparent"></Setter> + <Setter Property="dragAndDrop:DragAndDropService.Droppable" Value="True"></Setter> + <Setter Property="dragAndDrop:DragAndDropService.DraggingSurface" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}"></Setter> + <Style.Triggers> + <Trigger Property="dragAndDrop:DragAndDropService.IsDraggableOver" Value="True"> + <Setter Property="Opacity" Value="0.5"></Setter> + <Trigger.EnterActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation To="0.95" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleX"></DoubleAnimation> + <DoubleAnimation To="0.95" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleY"></DoubleAnimation> + </Storyboard> + </BeginStoryboard> + </Trigger.EnterActions> + <Trigger.ExitActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation To="1" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleX"></DoubleAnimation> + <DoubleAnimation To="1" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleY"></DoubleAnimation> + </Storyboard> + </BeginStoryboard> + </Trigger.ExitActions> + </Trigger> + </Style.Triggers> + </Style> + + <Style x:Key="draggableDroppableGrid" TargetType="Grid"> + <Setter Property="RenderTransform"> + <Setter.Value> + <ScaleTransform ScaleX="1" ScaleY="1"></ScaleTransform> + </Setter.Value> + </Setter> + <Setter Property="RenderTransformOrigin" Value="0.5,0.5"></Setter> + <Setter Property="Background" Value="Transparent"></Setter> + <Setter Property="dragAndDrop:DragAndDropService.Draggable" Value="True"></Setter> + <Setter Property="dragAndDrop:DragAndDropService.Droppable" Value="True"></Setter> + <Setter Property="dragAndDrop:DragAndDropService.DraggingSurface" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DraggingSurface}"></Setter> + <Style.Triggers> + <Trigger Property="dragAndDrop:DragAndDropService.IsDraggableOver" Value="True"> + <Setter Property="Opacity" Value="0.5"></Setter> + <Trigger.EnterActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation To="0.95" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleX"></DoubleAnimation> + <DoubleAnimation To="0.95" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleY"></DoubleAnimation> + </Storyboard> + </BeginStoryboard> + </Trigger.EnterActions> + <Trigger.ExitActions> + <BeginStoryboard> + <Storyboard> + <DoubleAnimation To="1" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleX"></DoubleAnimation> + <DoubleAnimation To="1" Duration="00:00:0.2" Storyboard.TargetProperty="RenderTransform.ScaleY"></DoubleAnimation> + </Storyboard> + </BeginStoryboard> + </Trigger.ExitActions> + </Trigger> + </Style.Triggers> + </Style> + <!--Drag & Drop--> + <!--Extensions--> </ResourceDictionary> 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 @@ <Project>{38197109-8610-4d3f-92b9-16d48df94d7c}</Project> <Name>Tango.DAL.Remote</Name> </ProjectReference> + <ProjectReference Include="..\..\Tango.DragAndDrop\Tango.DragAndDrop.csproj"> + <Project>{b112d89a-a106-41ae-a0c1-4abc84c477f5}</Project> + <Name>Tango.DragAndDrop</Name> + </ProjectReference> <ProjectReference Include="..\..\Tango.Editors\Tango.Editors.csproj"> <Project>{de2f2b86-025b-4f26-83a4-38bd48224ed5}</Project> <Name>Tango.Editors</Name> |
