From a4f4b3be2917b13667217cf826c21e8bd644a8c4 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 24 Oct 2018 11:38:25 +0300 Subject: Machine Studio v3.5.54 --- .../ColorLabModuleSettings.cs | 15 +++ .../Tango.MachineStudio.ColorLab.csproj | 3 +- .../ViewModels/MainViewVM.cs | 146 +++++++++++++++------ 3 files changed, 120 insertions(+), 44 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ColorLabModuleSettings.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ColorLabModuleSettings.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ColorLabModuleSettings.cs new file mode 100644 index 000000000..e2413f22b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ColorLabModuleSettings.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Settings; + +namespace Tango.MachineStudio.ColorLab +{ + public class ColorLabModuleSettings : SettingsBase + { + public String LastMachineSerialNumber { get; set; } + public String LastRmlGuid { get; set; } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj index 64caa2a1d..080d35f5e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj @@ -72,6 +72,7 @@ GlobalVersionInfo.cs + @@ -195,7 +196,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index d264dd209..58b264d41 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -20,6 +20,7 @@ using Tango.MachineStudio.Common.Controls; using Tango.MachineStudio.Common.Notifications; using Tango.PMR; using Tango.PMR.ColorLab; +using Tango.Settings; using Tango.SharedUI; using Tango.SharedUI.Controls; @@ -283,9 +284,9 @@ namespace Tango.MachineStudio.ColorLab.ViewModels #region Application Ready - public override void OnApplicationReady() + public async override void OnApplicationReady() { - Task.Factory.StartNew(() => + await Task.Factory.StartNew(() => { _dbContext = ObservablesContext.CreateDefault(); @@ -293,6 +294,25 @@ namespace Tango.MachineStudio.ColorLab.ViewModels ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); Rmls = _dbContext.Rmls.ToObservableCollection(); }); + + var settings = SettingsManager.Default.GetOrCreate(); + + try + { + if (settings.LastMachineSerialNumber != null) + { + SelectedMachine = Machines.SingleOrDefault(x => x.SerialNumber == settings.LastMachineSerialNumber); + + if (settings.LastRmlGuid != null) + { + SelectedRML = Rmls.SingleOrDefault(x => x.Guid == settings.LastRmlGuid); + } + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error loading last selected machine or RML."); + } } #endregion @@ -303,48 +323,55 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { Task.Factory.StartNew(() => { - if (LiquidsCalibrationData == null || CCT.ForwardData == null) return; - - ConversionInput input = new ConversionInput(); - input.ColorSpace = SourceColor.IsLab ? PMR.ColorLab.ColorSpace.Lab : PMR.ColorLab.ColorSpace.Rgb; - input.DeltaChroma = DeltaChroma; - input.DeltaL = DeltaL; - input.ForwardData = ByteString.CopyFrom(CCT.ForwardData); - - input.InputCoordinates = new InputCoordinates(); - input.InputCoordinates.Red = (int)SourceColor.Red; - input.InputCoordinates.Green = (int)SourceColor.Green; - input.InputCoordinates.Blue = (int)SourceColor.Blue; - input.InputCoordinates.L = SourceColor.L; - input.InputCoordinates.A = SourceColor.A; - input.InputCoordinates.B = SourceColor.B; - input.ThreadL = 92.1815; //SelectedRML.MediaColor.L; - input.ThreadA = 2.2555; //SelectedRML.MediaColor.A; - input.ThreadB = -10.9325; //SelectedRML.MediaColor.B; - - foreach (var vm in LiquidsCalibrationData) + try { - InputLiquid inputLiquid = new InputLiquid(); + if (LiquidsCalibrationData == null || CCT.ForwardData == null) return; + + ConversionInput input = new ConversionInput(); + input.ColorSpace = SourceColor.IsLab ? PMR.ColorLab.ColorSpace.Lab : PMR.ColorLab.ColorSpace.Rgb; + input.DeltaChroma = DeltaChroma; + input.DeltaL = DeltaL; + input.ForwardData = ByteString.CopyFrom(CCT.ForwardData); + + input.InputCoordinates = new InputCoordinates(); + input.InputCoordinates.Red = (int)SourceColor.Red; + input.InputCoordinates.Green = (int)SourceColor.Green; + input.InputCoordinates.Blue = (int)SourceColor.Blue; + input.InputCoordinates.L = SourceColor.L; + input.InputCoordinates.A = SourceColor.A; + input.InputCoordinates.B = SourceColor.B; + input.ThreadL = 92.1815; //SelectedRML.MediaColor.L; + input.ThreadA = 2.2555; //SelectedRML.MediaColor.A; + input.ThreadB = -10.9325; //SelectedRML.MediaColor.B; + + foreach (var vm in LiquidsCalibrationData) + { + InputLiquid inputLiquid = new InputLiquid(); - //TODO: Use the real calibration data... - //CalibrationData calData = new CalibrationData(); - //calData.LiquidType = (PMR.ColorLab.LiquidType)vm.IdsPack.LiquidType.Code; - //calData.CalibrationPoints.AddRange(vm.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y })); + CalibrationData calData = new CalibrationData(); + calData.LiquidType = (PMR.ColorLab.LiquidType)vm.IdsPack.LiquidType.Code; + calData.CalibrationPoints.AddRange(vm.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y })); - inputLiquid.CalibrationData = Cat.CreateDemoCalibrationData((PMR.ColorLab.LiquidType)vm.LiquidType.Code); + inputLiquid.CalibrationData = calData; - inputLiquid.LiquidType = (PMR.ColorLab.LiquidType)vm.LiquidType.Code; - inputLiquid.MaxNanoliterPerCentimeter = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == vm.LiquidType.Code).MaxNlPerCm; + inputLiquid.LiquidType = (PMR.ColorLab.LiquidType)vm.LiquidType.Code; + inputLiquid.MaxNanoliterPerCentimeter = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == vm.LiquidType.Code).MaxNlPerCm; - input.InputCoordinates.InputLiquids.Add(inputLiquid); - } + input.InputCoordinates.InputLiquids.Add(inputLiquid); + } - var output = TangoColorConverter.GetSuggestions(input); + var output = TangoColorConverter.GetSuggestions(input); - IsOutOfGamut = output.OutOfGamut; + IsOutOfGamut = output.OutOfGamut; - HiveSuggestions = TangoColorConverter.CreateHiveSuggestions(output); + HiveSuggestions = TangoColorConverter.CreateHiveSuggestions(output); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error in color conversion."); + _notification.ShowError($"An error occurred while trying to convert from source color to Volume.\n" + ex.Message); + } }); } @@ -497,7 +524,7 @@ namespace Tango.MachineStudio.ColorLab.ViewModels if (LiquidsCalibrationData == null || _prevent_inverse_conversion) return; //TODO: This is temporary because of out of range volumes. - if (LiquidVolumes.Where(x => x.IdsPack.IdsPackFormula.Code == IdsPackFormulas.StandardColor.ToInt32()).Sum(x => x.Volume) > 200) + if (LiquidVolumes.Where(x => x.IdsPack.IdsPackFormula.Code == IdsPackFormulas.StandardColor.ToInt32()).Sum(x => x.Volume) > 100) { IsVolumesOutOfRange = true; return; @@ -522,13 +549,11 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { InputLiquid inputLiquid = new InputLiquid(); - //TODO: Use the real calibration data... - - //CalibrationData calData = new CalibrationData(); - //calData.LiquidType = (PMR.ColorLab.LiquidType)vm.IdsPack.LiquidType.Code; - //calData.CalibrationPoints.AddRange(vm.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y })); + CalibrationData calData = new CalibrationData(); + calData.LiquidType = (PMR.ColorLab.LiquidType)vm.IdsPack.LiquidType.Code; + calData.CalibrationPoints.AddRange(vm.CalibrationPoints.Select(x => new CalibrationPoint() { X = x.X, Y = x.Y })); - inputLiquid.CalibrationData = Cat.CreateDemoCalibrationData((PMR.ColorLab.LiquidType)vm.LiquidType.Code); + inputLiquid.CalibrationData = calData; inputLiquid.LiquidType = (PMR.ColorLab.LiquidType)vm.LiquidType.Code; inputLiquid.MaxNanoliterPerCentimeter = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == vm.LiquidType.Code).MaxNlPerCm; @@ -549,7 +574,7 @@ namespace Tango.MachineStudio.ColorLab.ViewModels catch (Exception ex) { LogManager.Log(ex, "Error in inversed color conversion!"); - _notification.ShowError("Error in inversed color conversion!"); + _notification.ShowError("An error occurred while trying to convert from Volume to RGB.\n" + ex.Message); } } @@ -563,6 +588,8 @@ namespace Tango.MachineStudio.ColorLab.ViewModels { IsFree = false; + List default_calibration_to_notify = new List(); + await Task.Factory.StartNew(() => { using (_notification.PushTaskItem("Loading RML data...")) @@ -590,6 +617,17 @@ namespace Tango.MachineStudio.ColorLab.ViewModels var calData = cat.GetCalibrationData(); vm.CalibrationPoints = calData.CalibrationPoints.Select(x => new CalibrationDataPointVM(x)).ToObservableCollection(); } + else + { + var liquidTypeRml = LiquidTypesRmls.SingleOrDefault(x => x.LiquidType == idsPack.LiquidType && x.Rml == SelectedRML); + + if (liquidTypeRml != null) + { + default_calibration_to_notify.Add(idsPack); + var calData = liquidTypeRml.GetCalibrationData(); + vm.CalibrationPoints = calData.CalibrationPoints.Select(x => new CalibrationDataPointVM(x)).ToObservableCollection(); + } + } InvokeUINow(() => { @@ -606,9 +644,31 @@ namespace Tango.MachineStudio.ColorLab.ViewModels CCT.Rml = SelectedRML; _isNewCCT = true; } + + var settings = SettingsManager.Default.GetOrCreate(); + settings.LastMachineSerialNumber = SelectedMachine.SerialNumber; + settings.LastRmlGuid = SelectedRML.Guid; + settings.Save(); } }); + + //TODO: not sure is this is really needed.. + + //if (default_calibration_to_notify.Count > 0) + //{ + // String message = "The following calibration tables were loaded from the selected RML default calibration." + Environment.NewLine; + + // foreach (var pack in default_calibration_to_notify) + // { + // message += SelectedRML.Name + " >> " + pack.LiquidType.Name + "." + Environment.NewLine; + // } + + // _notification.ShowWarning(message); + //} + + + IsFree = true; } } -- cgit v1.3.1 From 1e24679bf65e42e5df96113bd1eef371036f0940 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 24 Oct 2018 16:18:39 +0300 Subject: Implemented job resume!! --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 20578304 -> 20578304 bytes Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 15400960 -> 15400960 bytes Software/PMR/Messages/Common/ErrorCode.proto | 12 +- Software/PMR/Messages/Common/MessageType.proto | 4 + .../PMR/Messages/Printing/CurrentJobRequest.proto | 9 + .../PMR/Messages/Printing/CurrentJobResponse.proto | 12 ++ Software/PMR/Messages/Printing/JobTicket.proto | 17 +- .../Printing/ResumeCurrentJobRequest.proto | 9 + .../Printing/ResumeCurrentJobResponse.proto | 12 ++ .../Build/Shortcuts/Machine Emulator.lnk | Bin 1471 -> 1455 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1532 -> 1516 bytes .../Build/Shortcuts/Proto Compiler GUI.lnk | Bin 1464 -> 1448 bytes .../ViewModels/MainViewVM.cs | 51 +++++- .../Navigation/INavigationManager.cs | 2 + .../Modules/DefaultStudioModuleLoader.cs | 5 +- .../Navigation/DefaultNavigationManager.cs | 12 ++ .../Notifications/DefaultNotificationProvider.cs | 38 +++- .../DefaultStudioApplicationManager.cs | 17 +- .../ViewModels/MainViewVM.cs | 2 + .../Tango.MachineStudio.UI/Views/MainView.xaml | 20 ++- .../Editors/AutoCompleteTextBox.cs | 9 +- .../Tango.Emulations/Emulators/MachineEmulator.cs | 88 ++++++++-- .../Operation/IMachineOperator.cs | 10 ++ .../Tango.Integration/Operation/MachineOperator.cs | 141 +++++++++++++++ .../Operation/ResumingJobEventArgs.cs | 26 +++ .../Tango.Integration/Tango.Integration.csproj | 3 +- .../Visual_Studio/Tango.PMR/Common/ErrorCode.cs | 10 +- .../Visual_Studio/Tango.PMR/Common/MessageType.cs | 47 ++--- .../Tango.PMR/Printing/CurrentJobRequest.cs | 131 ++++++++++++++ .../Tango.PMR/Printing/CurrentJobResponse.cs | 195 +++++++++++++++++++++ .../Visual_Studio/Tango.PMR/Printing/JobTicket.cs | 95 ++++++---- .../Tango.PMR/Printing/ResumeCurrentJobRequest.cs | 131 ++++++++++++++ .../Tango.PMR/Printing/ResumeCurrentJobResponse.cs | 195 +++++++++++++++++++++ Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj | 6 +- 36 files changed, 1204 insertions(+), 105 deletions(-) create mode 100644 Software/PMR/Messages/Printing/CurrentJobRequest.proto create mode 100644 Software/PMR/Messages/Printing/CurrentJobResponse.proto create mode 100644 Software/PMR/Messages/Printing/ResumeCurrentJobRequest.proto create mode 100644 Software/PMR/Messages/Printing/ResumeCurrentJobResponse.proto create mode 100644 Software/Visual_Studio/Tango.Integration/Operation/ResumingJobEventArgs.cs create mode 100644 Software/Visual_Studio/Tango.PMR/Printing/CurrentJobRequest.cs create mode 100644 Software/Visual_Studio/Tango.PMR/Printing/CurrentJobResponse.cs create mode 100644 Software/Visual_Studio/Tango.PMR/Printing/ResumeCurrentJobRequest.cs create mode 100644 Software/Visual_Studio/Tango.PMR/Printing/ResumeCurrentJobResponse.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 05382b4cb..35e6fba43 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 34218c424..fb57f7692 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index f14509fff..9383eee3c 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index e3144956b..995b71bf5 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/PMR/Messages/Common/ErrorCode.proto b/Software/PMR/Messages/Common/ErrorCode.proto index 51774e6e9..cbdcfec25 100644 --- a/Software/PMR/Messages/Common/ErrorCode.proto +++ b/Software/PMR/Messages/Common/ErrorCode.proto @@ -24,9 +24,11 @@ enum ErrorCode //Job Failure JOB_UNSPECIFIED_ERROR = 2000; JOB_THREAD_BREAK = 2001; - JOB_WINDER_DANCER_FAIL = 2002; - JOB_POOLER_DANCER_FAIL = 2003; - JOB_FEEDER_DANCER_FAIL = 2004; - JOB_OUT_OF_DYE = 2005; - JOB_OTHER_ALARM = 2006; + JOB_WINDER_DANCER_FAIL = 2002; + JOB_POOLER_DANCER_FAIL = 2003; + JOB_FEEDER_DANCER_FAIL = 2004; + JOB_OUT_OF_DYE = 2005; + JOB_OTHER_ALARM = 2006; + NO_JOB_IN_PROGRESS = 2007; //Occurs when ResumeCurrentJobRequest was called but no job is in progress. + } diff --git a/Software/PMR/Messages/Common/MessageType.proto b/Software/PMR/Messages/Common/MessageType.proto index c19bbc2d8..c9a55552d 100644 --- a/Software/PMR/Messages/Common/MessageType.proto +++ b/Software/PMR/Messages/Common/MessageType.proto @@ -175,6 +175,10 @@ enum MessageType AbortJobResponse = 3003; UploadProcessParametersRequest = 3004; UploadProcessParametersResponse = 3005; + CurrentJobRequest = 3006; + CurrentJobResponse = 3007; + ResumeCurrentJobRequest = 3008; + ResumeCurrentJobResponse = 3009; diff --git a/Software/PMR/Messages/Printing/CurrentJobRequest.proto b/Software/PMR/Messages/Printing/CurrentJobRequest.proto new file mode 100644 index 000000000..1e5f57531 --- /dev/null +++ b/Software/PMR/Messages/Printing/CurrentJobRequest.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package Tango.PMR.Printing; +option java_package = "com.twine.tango.pmr.printing"; + +message CurrentJobRequest +{ + +} \ No newline at end of file diff --git a/Software/PMR/Messages/Printing/CurrentJobResponse.proto b/Software/PMR/Messages/Printing/CurrentJobResponse.proto new file mode 100644 index 000000000..5fe94db13 --- /dev/null +++ b/Software/PMR/Messages/Printing/CurrentJobResponse.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +import "JobTicket.proto"; + +package Tango.PMR.Printing; +option java_package = "com.twine.tango.pmr.printing"; + +message CurrentJobResponse +{ + bool IsJobInProgress = 1; + JobTicket JobTicket = 2; +} \ No newline at end of file diff --git a/Software/PMR/Messages/Printing/JobTicket.proto b/Software/PMR/Messages/Printing/JobTicket.proto index ace279747..9d15d9433 100644 --- a/Software/PMR/Messages/Printing/JobTicket.proto +++ b/Software/PMR/Messages/Printing/JobTicket.proto @@ -10,17 +10,18 @@ option java_package = "com.twine.tango.pmr.printing"; message JobTicket { - string Name = 1; + string guid = 1; + string Name = 2; - bool EnableInterSegment = 2; - double InterSegmentLength = 3; + bool EnableInterSegment = 3; + double InterSegmentLength = 4; - double Length = 4; + double Length = 5; - ProcessParameters ProcessParameters = 5; + ProcessParameters ProcessParameters = 6; - JobWindingMethod WindingMethod = 6; - JobSpool Spool = 7; + JobWindingMethod WindingMethod = 7; + JobSpool Spool = 8; - repeated JobSegment Segments = 8; + repeated JobSegment Segments = 9; } \ No newline at end of file diff --git a/Software/PMR/Messages/Printing/ResumeCurrentJobRequest.proto b/Software/PMR/Messages/Printing/ResumeCurrentJobRequest.proto new file mode 100644 index 000000000..0ab3d7b62 --- /dev/null +++ b/Software/PMR/Messages/Printing/ResumeCurrentJobRequest.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +package Tango.PMR.Printing; +option java_package = "com.twine.tango.pmr.printing"; + +message ResumeCurrentJobRequest +{ + +} \ No newline at end of file diff --git a/Software/PMR/Messages/Printing/ResumeCurrentJobResponse.proto b/Software/PMR/Messages/Printing/ResumeCurrentJobResponse.proto new file mode 100644 index 000000000..08c3ffcca --- /dev/null +++ b/Software/PMR/Messages/Printing/ResumeCurrentJobResponse.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +import "JobStatus.proto"; + +package Tango.PMR.Printing; +option java_package = "com.twine.tango.pmr.printing"; + +message ResumeCurrentJobResponse +{ + JobStatus Status = 1; + bool Canceled = 2; +} \ No newline at end of file diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk index 809dc39a4..0b55f9468 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Emulator.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index aaa476b0b..96378d6e7 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk index 349e9582e..8996e8019 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk and b/Software/Visual_Studio/Build/Shortcuts/Proto Compiler GUI.lnk differ 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 07686165b..efdb8982d 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 @@ -45,6 +45,7 @@ using Tango.AutoComplete.Editors; using System.Data.Entity; using System.Runtime.ExceptionServices; using Tango.BL.Builders; +using Tango.MachineStudio.Common.Navigation; namespace Tango.MachineStudio.Developer.ViewModels { @@ -63,6 +64,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private TimeSpan _runningJobEstimatedDuration; private JobHandler _jobHandler; private DeveloperNavigationManager _navigation; + private INavigationManager _msNavigation; private bool _blockInvalidateCommands; private IAuthenticationProvider _authentication; private ObservablesContext _machineDbContext; @@ -685,7 +687,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// The application manager. /// The notification provider. - public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, IAuthenticationProvider authentication, IEventLogger eventLogger, ISpeechProvider speech) + public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, INavigationManager navigationManager, IAuthenticationProvider authentication, IEventLogger eventLogger, ISpeechProvider speech) { CanWork = true; EnableColorConversion = true; @@ -695,6 +697,7 @@ namespace Tango.MachineStudio.Developer.ViewModels _notification = notificationProvider; _speech = speech; _navigation = navigation; + _msNavigation = navigationManager; ApplicationManager = applicationManager; VideoCaptureProvider = videoCaptureProvider; _eventLogger = eventLogger; @@ -720,11 +723,11 @@ namespace Tango.MachineStudio.Developer.ViewModels RemoveBrushStopCommand = new RelayCommand(RemoveSelectedBrushStops, () => SelectedBrushStop != null && CanWork); SaveJobCommand = new RelayCommand(SaveActiveJob, () => SelectedMachine != null && CanWork); DiscardJobCommand = new RelayCommand(BackToJobs, () => SelectedMachine != null && CanWork); - StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && CanWork && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); + StartJobCommand = new RelayCommand(() => StartJob(), () => ActiveJob != null && CanWork && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); StartJobAndRecordCommand = new RelayCommand(StartJobAndRecord, () => _dataCaptureVM != null && !_dataCaptureVM.Recorder.IsRecording && !_dataCaptureVM.Player.IsPlaying && ActiveJob != null && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning && CanWork); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); - LoadJobCommand = new RelayCommand(LoadSelectedJob, () => SelectedMachineJob != null && CanWork); + LoadJobCommand = new RelayCommand(() => LoadSelectedJob(), () => SelectedMachineJob != null && CanWork); DuplicateJobCommand = new RelayCommand(DuplicateSelectedJobs, () => SelectedMachineJob != null && CanWork); DuplicateSegmentCommand = new RelayCommand(DuplicateSelectedSegments, () => SelectedSegment != null && CanWork); DuplicateBrushStopCommand = new RelayCommand(DuplicateSelectedBrushStops, () => SelectedBrushStop != null && CanWork); @@ -912,6 +915,33 @@ namespace Tango.MachineStudio.Developer.ViewModels MachineOperator.MachineEventsStateProvider.NewEvents -= MachineEventsStateProvider_NewEvents; MachineOperator.MachineEventsStateProvider.NewEvents += MachineEventsStateProvider_NewEvents; + + MachineOperator.ResumingJob -= MachineOperator_ResumingJob; + MachineOperator.ResumingJob += MachineOperator_ResumingJob; + } + } + + private void MachineOperator_ResumingJob(object sender, ResumingJobEventArgs e) + { + if (_notification.ShowQuestion("Machine studio has detected a job in progress. Would you like to try and continue from there you were?")) + { + var job = _machineDbContext.Jobs.SingleOrDefault(x => x.Guid == e.JobGuid); + + if (job != null) + { + _msNavigation.NavigateToModule(); + SelectedMachine = _machineDbContext.Machines.SingleOrDefault(x => x.Guid == job.MachineGuid); + SelectedMachineJob = SelectedMachine.Jobs.SingleOrDefault(x => x.Guid == job.Guid); + LoadSelectedJob(() => + { + StartJob(e.Approve); + }); + } + else + { + LogManager.Log($"Could not resume job. The running job with guid '{e.JobGuid}' was not found."); + _notification.ShowError("Could not resume job. The running job was not found."); + } } } @@ -1205,7 +1235,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Starts the job. /// - private void StartJob() + private void StartJob(Func resumeFunc = null) { LogManager.Log(String.Format("Starting job {0}...", ActiveJob.Name)); if (MachineOperator == null || MachineOperator.State != TransportComponentState.Connected) @@ -1242,7 +1272,14 @@ namespace Tango.MachineStudio.Developer.ViewModels { LogManager.Log("Sending job to machine operator..."); - _jobHandler = MachineOperator.Print(ActiveJob, SelectedProcessParametersTable); + if (resumeFunc == null) + { + _jobHandler = MachineOperator.Print(ActiveJob, SelectedProcessParametersTable); + } + else + { + _jobHandler = resumeFunc(ActiveJob); + } _eventLogger.Log(String.Format("Job '{0}' started...", ActiveJob.Name)); @@ -1573,7 +1610,7 @@ namespace Tango.MachineStudio.Developer.ViewModels /// /// Loads the selected job. /// - private async void LoadSelectedJob() + private async void LoadSelectedJob(Action onCompleted = null) { if (SelectedMachineJob != null) { @@ -1662,6 +1699,8 @@ namespace Tango.MachineStudio.Developer.ViewModels } CanWork = true; + + onCompleted?.Invoke(); } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs index e20940c8d..6bd4d8829 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Navigation/INavigationManager.cs @@ -101,6 +101,8 @@ namespace Tango.MachineStudio.Common.Navigation Task NavigateWithObject(TPass obj, bool pushToHistory = true) where TModule : IStudioModule; + void NavigateToModule() where T : IStudioModule; + /// /// Clears the navigation back history. /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs index 0def3c943..28f56e521 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Modules/DefaultStudioModuleLoader.cs @@ -44,7 +44,10 @@ namespace Tango.MachineStudio.UI.Modules /// The e. private void _authenticationProvider_CurrentUserChanged(object sender, User e) { - LoadModules(); + if (e != null) + { + LoadModules(); + } } private SynchronizedObservableCollection _allModules; diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs index 899ba846e..13ec6161d 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Navigation/DefaultNavigationManager.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Core.Commands; +using Tango.Core.DI; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Modules; using Tango.MachineStudio.Common.Navigation; @@ -384,5 +385,16 @@ namespace Tango.MachineStudio.UI.Navigation RaisePropertyChanged(nameof(CanNavigateBack)); } + + public void NavigateToModule() where T : IStudioModule + { + var loader = TangoIOC.Default.GetInstance(); + var module = loader.UserModules.SingleOrDefault(x => x.GetType() == typeof(T)); + + if (module != null) + { + TangoIOC.Default.GetInstance().StartModule(module); + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs index 6cff1ba17..80509e6c0 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs @@ -11,6 +11,7 @@ using System.Windows.Media; using Tango.Core; using System.Collections.ObjectModel; using Tango.SharedUI; +using System.Collections.Concurrent; namespace Tango.MachineStudio.UI.Notifications { @@ -21,6 +22,8 @@ namespace Tango.MachineStudio.UI.Notifications /// public class DefaultNotificationProvider : ExtendedObject, INotificationProvider { + private int _message_count = 0; + /// /// The view types /// @@ -79,6 +82,8 @@ namespace Tango.MachineStudio.UI.Notifications { MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; + _message_count++; + var result = new MessageBoxWindow() { Owner = Application.Current.MainWindow, @@ -89,7 +94,13 @@ namespace Tango.MachineStudio.UI.Notifications }.ShowDialog(); - MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + _message_count--; + + if (_message_count == 0) + { + MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + } + return result; } @@ -377,8 +388,11 @@ namespace Tango.MachineStudio.UI.Notifications /// The task item. public void PushTaskItem(TaskItem taskItem) { - TaskItems.Add(taskItem); - CurrentTaskItem = taskItem; + InvokeUI(() => + { + TaskItems.Add(taskItem); + CurrentTaskItem = taskItem; + }); } /// @@ -400,14 +414,20 @@ namespace Tango.MachineStudio.UI.Notifications /// The task item. public void PopTaskItem(TaskItem taskItem) { - TaskItems.Remove(taskItem); - - if (TaskItems.Count > 0) + Task.Delay(1000).ContinueWith((x) => { - CurrentTaskItem = TaskItems.Last(); - } + InvokeUI(() => + { + TaskItems.Remove(taskItem); - RaisePropertyChanged(nameof(HasTaskItems)); + if (TaskItems.Count > 0) + { + CurrentTaskItem = TaskItems.Last(); + } + + RaisePropertyChanged(nameof(HasTaskItems)); + }); + }); } /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs index 8be7f486a..3864708fc 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/StudioApplication/DefaultStudioApplicationManager.cs @@ -25,6 +25,7 @@ using Tango.MachineStudio.UI.ViewModels; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.UI.Views; using Tango.Integration.Operation; +using Tango.MachineStudio.UI.Windows; namespace Tango.MachineStudio.UI.StudioApplication { @@ -39,6 +40,7 @@ namespace Tango.MachineStudio.UI.StudioApplication private IStudioModuleLoader _moduleLoader; private INotificationProvider _notification; private List _openedWindows; + private List _notified_view_models; /// /// Initializes a new instance of the class. @@ -50,6 +52,7 @@ namespace Tango.MachineStudio.UI.StudioApplication _navigationManager = navigationManager; _notification = notification; _openedWindows = new List(); + _notified_view_models = new List(); Application.Current.MainWindow.ContentRendered += (_, __) => { @@ -286,6 +289,11 @@ namespace Tango.MachineStudio.UI.StudioApplication window.Closed += (x, y) => { _openedWindows.Remove(window); }; } + public bool IsModuleInNewWindow(IStudioModule module) + { + return _openedWindows.Exists(x => (x as ModuleWindow).ModuleContext.Module == module); + } + /// /// Gets the core libraries version. /// @@ -324,7 +332,14 @@ namespace Tango.MachineStudio.UI.StudioApplication /// public void NotifyApplicationReady() { - TangoIOC.Default.GetAllInstancesByBase().ToList().ForEach(x => x.OnApplicationReady()); + TangoIOC.Default.GetAllInstancesByBase().ToList().ForEach(x => + { + if (!_notified_view_models.Contains(x)) + { + x.OnApplicationReady(); + _notified_view_models.Add(x); + } + }); } /// diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 9b625a6ee..31e297cd1 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -649,6 +649,8 @@ namespace Tango.MachineStudio.UI.ViewModels { IsMenuOpened = false; + if ((_applicationManager as DefaultStudioApplicationManager).IsModuleInNewWindow(module)) return; + if (module != null) { LogManager.Log(String.Format("Starting module '{0}'...", module.Name)); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml index 7edfa50c6..f66e247a9 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -467,7 +467,7 @@ - +