From 95b4e14bc4e06ffb94199f5ec4e0d2d9bebceeff Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 18 Feb 2018 18:48:16 +0200 Subject: Working on new developer module. --- .../Tango.MachineStudio.DataCapture.csproj | 1 + .../Tango.MachineStudio.DataCapture/app.config | 11 ++ .../Tango.MachineStudio.Developer.csproj | 3 + .../ViewModels/MainViewVM.cs | 151 +++++++++++++++++++-- .../Views/JobView.xaml | 13 +- .../Views/MachineJobSelectionView.xaml | 13 +- .../Tango.MachineStudio.Developer/packages.config | 1 + 7 files changed, 167 insertions(+), 26 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj index 8936a66db..d97f540b1 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/Tango.MachineStudio.DataCapture.csproj @@ -118,6 +118,7 @@ ResXFileCodeGenerator Resources.Designer.cs + SettingsSingleFileGenerator diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config new file mode 100644 index 000000000..cacd4cd77 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DataCapture/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 086d6cd91..eae234a8b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -31,6 +31,9 @@ 4 + + ..\..\..\packages\DeepEqual.1.6.0.0\lib\net40\DeepEqual.dll + ..\..\..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.dll 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 7a1c94504..5c5531063 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 @@ -34,6 +34,8 @@ using Tango.MachineStudio.Common.Video; using Tango.Integration.Services; using Tango.MachineStudio.Developer.Navigation; using System.Data.Entity; +using Tango.MachineStudio.Common.Authentication; +using DeepEqual.Syntax; namespace Tango.MachineStudio.Developer.ViewModels { @@ -52,18 +54,24 @@ namespace Tango.MachineStudio.Developer.ViewModels private ObservablesContext _dbJobContext; private Job _jobFromList; private bool _blockInvalidateCommands; + private IAuthenticationProvider _authentication; #region Properties private ObservableCollection _colorSpaces; - + /// + /// Gets or sets the color spaces. + /// public ObservableCollection ColorSpaces { get { return _colorSpaces; } set { _colorSpaces = value; RaisePropertyChangedAuto(); } } - private ObservableCollection _rmls; + private ObservableCollection _rmls; + /// + /// Gets or sets the RMLS. + /// public ObservableCollection Rmls { get { return _rmls; } @@ -172,6 +180,16 @@ namespace Tango.MachineStudio.Developer.ViewModels } } + private ObservableCollection _selectedJobs; + /// + /// Gets or sets the selected jobs. + /// + public ObservableCollection SelectedJobs + { + get { return _selectedJobs; } + set { _selectedJobs = value; RaisePropertyChangedAuto(); } + } + private Segment _selectedSegment; /// /// Gets or sets the job selected segment. @@ -182,6 +200,16 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _selectedSegment = value; RaisePropertyChangedAuto(); OnSelectedSegmentChanged(); } } + private ObservableCollection _selectedSegments; + /// + /// Gets or sets the selected segments. + /// + public ObservableCollection SelectedSegments + { + get { return _selectedSegments; } + set { _selectedSegments = value; RaisePropertyChangedAuto(); } + } + private BrushStop _selectedBrushStop; /// /// Gets or sets the selected segment selected brush stop. @@ -192,6 +220,16 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _selectedBrushStop = value; RaisePropertyChangedAuto(); } } + private ObservableCollection _selectedBrushStops; + /// + /// Gets or sets the selected brush stops. + /// + public ObservableCollection SelectedBrushStops + { + get { return _selectedBrushStops; } + set { _selectedBrushStops = value; RaisePropertyChangedAuto(); } + } + private Rml _selectedRML; /// /// Gets or sets the selected RML. @@ -457,6 +495,11 @@ namespace Tango.MachineStudio.Developer.ViewModels /// public RelayCommand LoadJobCommand { get; set; } + /// + /// Gets or sets the duplicate job command. + /// + public RelayCommand DuplicateJobCommand { get; set; } + #endregion #region Constructors @@ -482,8 +525,12 @@ namespace Tango.MachineStudio.Developer.ViewModels /// The application manager. /// The notification provider. [PreferredConstructor] - public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IMainView view, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation) : this(view) + public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IMainView view, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, IAuthenticationProvider authentication) : this(view) { + SelectedJobs = new ObservableCollection(); + + _authentication = authentication; + _notification = notificationProvider; _navigation = navigation; ApplicationManager = applicationManager; @@ -509,6 +556,7 @@ namespace Tango.MachineStudio.Developer.ViewModels CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); ExitFullScreenCommand = new RelayCommand(ExitFullScreen); LoadJobCommand = new RelayCommand(LoadJob, () => SelectedJob != null); + DuplicateJobCommand = new RelayCommand(DuplicateJob, () => SelectedJob != null); ToggleCameraCommand = new RelayCommand(ToggleCamera); @@ -547,6 +595,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private void SelectedMachine_Saved(object sender, EventArgs e) { InvalidateLiquidFactorsAndProcessTables(); + SelectedMachine.Reload(); } /// @@ -640,14 +689,43 @@ namespace Tango.MachineStudio.Developer.ViewModels #region Private Methods + private async void DuplicateJob() + { + if (SelectedJobs.Count > 0) + { + 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(); + } + } + } + private async void LoadJob() { if (SelectedJob != null) { + SelectedSegments = new ObservableCollection(); + SelectedBrushStops = new ObservableCollection(); + SelectedRML = null; + SelectedSegment = null; + SelectedGroupHistory = null; + SelectedBrushStop = null; + SelectedProcessParametersTable = null; + RmlProcessParametersTableGroup = null; + using (_notification.PushTaskItem("Loading job details...")) { - await Task.Factory.StartNew(() => - { + //await Task.Factory.StartNew(() => + //{ _blockInvalidateCommands = false; _dbJobContext = ObservablesContext.CreateDefault(); @@ -675,7 +753,7 @@ namespace Tango.MachineStudio.Developer.ViewModels InvalidateRelayCommands(); InvokeUI(() => _navigation.NavigateTo(DeveloperNavigationView.JobView)); - }); + //}); } } } @@ -688,15 +766,45 @@ namespace Tango.MachineStudio.Developer.ViewModels { SelectedJob.LastUpdated = DateTime.UtcNow; SelectedJob.Rml = SelectedRML; - await SelectedJob.SaveAsync(); + 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(); + + foreach (var stop in segment.BrushStops) + { + await stop.Reload(); + } + } } } } private void DiscardJob() { - if (_notification.ShowQuestion("This will discard the current job changes. Are you sue?")) + //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); + + if (jobModified) + { + if (_notification.ShowQuestion("This will discard the current job changes. Are you sue?")) + { + _dbJobContext.Dispose(); + _navigation.NavigateTo(DeveloperNavigationView.MachineJobSelectionView); + } + } + else { _dbJobContext.Dispose(); _navigation.NavigateTo(DeveloperNavigationView.MachineJobSelectionView); @@ -1012,11 +1120,18 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Removes the selected job. /// - private void RemoveJob() + private async void RemoveJob() { if (SelectedMachine != null && SelectedJob != null) { - SelectedMachine.Jobs.Remove(SelectedJob); + if (_notification.ShowQuestion("Are you sure you want to delete the selected jobs?")) + { + SelectedJobs.ToList().ForEach(x => + { + x.DefferedDelete(); + }); + await SelectedMachine.SaveAsync(); + } } } @@ -1027,11 +1142,19 @@ namespace Tango.MachineStudio.Developer.ViewModels { if (SelectedMachine != null) { - SelectedMachine.Jobs.Add(new Job(DateTime.UtcNow) + String jobName = _notification.ShowTextInput("Please provide a job name", "Name"); + + if (!String.IsNullOrWhiteSpace(jobName)) { - Name = "Untitled Job", - CreationDate = DateTime.UtcNow, - }); + Job newJob = new Job(); + newJob.Name = jobName; + newJob.CreationDate = DateTime.UtcNow; + newJob.User = _authentication.CurrentUser; + newJob.Rml = Adapter.Rmls.FirstOrDefault(); + + SelectedJob = newJob; + LoadJob(); + } } } 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 b6455175e..35a30e91e 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 @@ -14,6 +14,7 @@ xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:db="clr-namespace:Tango.MachineStudio.DB.Views.DBViews;assembly=Tango.MachineStudio.DB" xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls;assembly=Tango.MachineStudio.Common" + xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:designer="clr-namespace:Tango.MachineStudio.MachineDesigner.Views;assembly=Tango.MachineStudio.MachineDesigner" xmlns:vm="clr-namespace:Tango.MachineStudio.Developer.ViewModels" xmlns:localConverters="clr-namespace:Tango.MachineStudio.Developer.Converters" @@ -230,7 +231,7 @@