diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-03-14 13:25:32 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-03-14 13:25:32 +0200 |
| commit | c5cde62cecfdd413e9902b26b30b0d4dfd05a24d (patch) | |
| tree | bc6cd0fc62c13bc65bcb1eeebfac4f5d6112f7ae /Software/Visual_Studio/Tango.Integration | |
| parent | 81d88a18ac614604befb041a81781ab33eb08067 (diff) | |
| download | Tango-c5cde62cecfdd413e9902b26b30b0d4dfd05a24d.tar.gz Tango-c5cde62cecfdd413e9902b26b30b0d4dfd05a24d.zip | |
Machine Studio v4.0.10
PPC v1.0.9
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration')
7 files changed, 529 insertions, 276 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs index c4f559c58..4cdd372f5 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs @@ -283,6 +283,12 @@ namespace Tango.Integration.ExternalBridge { if (IsInSession) { + if (container.Type == MessageType.ExternalBridgeLoginRequest) + { + SendErrorResponse(new AuthenticationException("Machine is already in session."), container.Token); + return; + } + if (_messageHandlers.ContainsKey(container.Type)) { try diff --git a/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs new file mode 100644 index 000000000..2f531a95f --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using Tango.BL.ColorConversion; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.Core; + +namespace Tango.Integration.Operation +{ + /// <summary> + /// Represents the default <see cref="IMachineOperator"/> gradient steps generation configuration. + /// </summary> + public class DefaultGradientGenerationConfiguration : ExtendedObject, IGradientGenerationConfiguration + { + private bool _isEnabled; + /// <summary> + /// Gets or sets a value indicating whether to generate the gradient steps. + /// </summary> + public bool IsEnabled + { + get { return _isEnabled; } + set { _isEnabled = value; RaisePropertyChangedAuto(); } + } + + private int _resolutionCM; + /// <summary> + /// Gets or sets the gradient steps resolution in centimeters. + /// </summary> + public int ResolutionCM + { + get { return _resolutionCM; } + set { _resolutionCM = value; RaisePropertyChangedAuto(); } + } + + /// <summary> + /// Initializes a new instance of the <see cref="DefaultGradientGenerationConfiguration"/> class. + /// </summary> + public DefaultGradientGenerationConfiguration() + { + ResolutionCM = 10; + } + + /// <summary> + /// Creates a collection of brush stops representing the required gradient steps. + /// </summary> + /// <param name="segment">The segment.</param> + /// <param name="processParameters">The process parameters.</param> + /// <param name="progress">Progress callback.</param> + /// <returns></returns> + public List<BrushStop> Generate(Segment segment, ProcessParametersTable processParameters, Action<PreparingJobProgressEventArgs> progress = null) + { + List<BrushStop> stops = new List<BrushStop>(); + + int stopIndex = 1; + + for (double cm = 0; cm < segment.Length; cm += (ResolutionCM / 100d)) + { + double offset = (double)cm / segment.Length; + + var color = GetRelativeColor(segment.BrushStops.ToList(), offset); + var output = TangoColorConverter.GetSuggestions(segment.Job, color); + + BrushStop s = new BrushStop(); + s.Segment = segment; + s.ColorSpace = new ColorSpace(); + s.ColorSpace.Code = ColorSpaces.RGB.ToInt32(); + s.Corrected = true; + s.OffsetPercent = offset * 100d; + s.OffsetMeters = segment.Length * offset; + s.Red = color.R; + s.Green = color.G; + s.Blue = color.B; + s.StopIndex = stopIndex++; + + TangoColorConverter.ApplyBrushStopCorrection(s, processParameters, output); + + stops.Add(s); + + progress?.Invoke(new PreparingJobProgressEventArgs() + { + Job = segment.Job, + Total = segment.Length, + Progress = cm, + }); + } + + progress?.Invoke(new PreparingJobProgressEventArgs() + { + Job = segment.Job, + Total = segment.Length, + Progress = segment.Length, + }); + + return stops; + } + + private Color GetRelativeColor(List<BrushStop> brushStopsCollection, double offset) + { + brushStopsCollection = brushStopsCollection.Select(x => x.ShallowClone()).ToList(); + brushStopsCollection.ForEach(x => x.OffsetPercent = x.OffsetPercent / 100d); + + var point = brushStopsCollection.SingleOrDefault(f => f.OffsetPercent == offset); + if (point != null) return point.Color; + + BrushStop before = brushStopsCollection.Where(w => w.OffsetPercent == brushStopsCollection.Min(m => m.OffsetPercent)).First(); + BrushStop after = brushStopsCollection.Where(w => w.OffsetPercent == brushStopsCollection.Max(m => m.OffsetPercent)).First(); + + foreach (var gs in brushStopsCollection) + { + if (gs.OffsetPercent < offset && gs.OffsetPercent > before.OffsetPercent) + { + before = gs; + } + if (gs.OffsetPercent > offset && gs.OffsetPercent < after.OffsetPercent) + { + after = gs; + } + } + + var color = new Color(); + + color.ScA = (float)((offset - before.OffsetPercent) * (after.Color.ScA - before.Color.ScA) / (after.OffsetPercent - before.OffsetPercent) + before.Color.ScA); + color.ScR = (float)((offset - before.OffsetPercent) * (after.Color.ScR - before.Color.ScR) / (after.OffsetPercent - before.OffsetPercent) + before.Color.ScR); + color.ScG = (float)((offset - before.OffsetPercent) * (after.Color.ScG - before.Color.ScG) / (after.OffsetPercent - before.OffsetPercent) + before.Color.ScG); + color.ScB = (float)((offset - before.OffsetPercent) * (after.Color.ScB - before.Color.ScB) / (after.OffsetPercent - before.OffsetPercent) + before.Color.ScB); + + return color; + } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IGradientGenerationConfiguration.cs b/Software/Visual_Studio/Tango.Integration/Operation/IGradientGenerationConfiguration.cs new file mode 100644 index 000000000..238d80d61 --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/IGradientGenerationConfiguration.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; + +namespace Tango.Integration.Operation +{ + /// <summary> + /// Represents a <see cref="IMachineOperator"/> gradient steps generation configuration. + /// </summary> + public interface IGradientGenerationConfiguration + { + /// <summary> + /// Gets or sets a value indicating whether to generate the gradient steps. + /// </summary> + bool IsEnabled { get; set; } + + /// <summary> + /// Gets or sets the gradient steps resolution in centimeters. + /// </summary> + int ResolutionCM { get; set; } + + /// <summary> + /// Creates a collection of brush stops representing the required gradient steps. + /// </summary> + /// <param name="segment">The segment.</param> + /// <param name="processParameters">The process parameters.</param> + /// <param name="progress">Progress callback.</param> + /// <returns></returns> + List<BrushStop> Generate(Segment segment, ProcessParametersTable processParameters, Action<PreparingJobProgressEventArgs> progress = null); + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index 992323c6d..a5534a063 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -61,6 +61,11 @@ namespace Tango.Integration.Operation RunningJobStatus RunningJobStatus { get; } /// <summary> + /// Gets or sets the gradients generation configuration. + /// </summary> + IGradientGenerationConfiguration GradientGenerationConfiguration { get; set; } + + /// <summary> /// Gets a value indicating whether this instance is printing. /// </summary> bool IsPrinting { get; } @@ -76,6 +81,11 @@ namespace Tango.Integration.Operation event EventHandler<MachineStatuses> StatusChanged; /// <summary> + /// Reports about the job printing preparation progress. + /// </summary> + event EventHandler<PreparingJobProgressEventArgs> PreparingJobProgress; + + /// <summary> /// Occurs when a printing process has started. /// </summary> event EventHandler<PrintingEventArgs> PrintingStarted; @@ -192,7 +202,7 @@ namespace Tango.Integration.Operation /// </summary> /// <param name="job">The job.</param> /// <returns></returns> - JobHandler Print(Job job); + Task<JobHandler> Print(Job job); /// <summary> /// Executes a print stub for emulating a full job. @@ -201,7 +211,7 @@ namespace Tango.Integration.Operation /// </summary> /// <param name="job">The job.</param> /// <returns></returns> - JobHandler PrintStub(Job job); + Task<JobHandler> PrintStub(Job job); /// <summary> /// Prints the specified job using the specified job parameters. @@ -209,7 +219,7 @@ namespace Tango.Integration.Operation /// <param name="job">The job.</param> /// <param name="processParameters">Process parameters table</param> /// <returns></returns> - JobHandler Print(Job job, ProcessParametersTable processParameters); + Task<JobHandler> Print(Job job, ProcessParametersTable processParameters); /// <summary> /// Uploads the specified process parameters to the embedded device. diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 520b06626..ba9d21451 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -88,6 +88,7 @@ namespace Tango.Integration.Operation EnableJobResume = true; LogEmbeddedDebuggingToFile = true; FirmwareUpgradeMode = FirmwareUpgradeModes.DFU | FirmwareUpgradeModes.TFP_PACKAGE; + GradientGenerationConfiguration = new DefaultGradientGenerationConfiguration(); } /// <summary> @@ -144,6 +145,11 @@ namespace Tango.Integration.Operation public event EventHandler<IMessage> ResponseReceived; /// <summary> + /// Reports about the job printing preparation progress. + /// </summary> + public event EventHandler<PreparingJobProgressEventArgs> PreparingJobProgress; + + /// <summary> /// Occurs when a printing process has started. /// </summary> public event EventHandler<PrintingEventArgs> PrintingStarted; @@ -378,6 +384,16 @@ namespace Tango.Integration.Operation set { _deviceInformation = value; RaisePropertyChangedAuto(); } } + private IGradientGenerationConfiguration _gradientGenerationConfiguration; + /// <summary> + /// Gets or sets the gradients generation configuration. + /// </summary> + public IGradientGenerationConfiguration GradientGenerationConfiguration + { + get { return _gradientGenerationConfiguration; } + set { _gradientGenerationConfiguration = value; RaisePropertyChangedAuto(); } + } + #endregion #region Virtual Methods @@ -933,7 +949,17 @@ namespace Tango.Integration.Operation jobSegment.Length = segment.LengthWithFactor; jobSegment.Name = segment.Name; - foreach (var stop in segment.BrushStops) + var stops = segment.BrushStops.ToList(); + + if (GradientGenerationConfiguration != null && GradientGenerationConfiguration.IsEnabled) + { + GradientGenerationConfiguration.Generate(segment, processParameters, (e) => + { + PreparingJobProgress?.Invoke(this, e); + }); + } + + foreach (var stop in stops) { JobBrushStop jobStop = new JobBrushStop(); jobStop.Index = stop.StopIndex; @@ -1073,7 +1099,7 @@ namespace Tango.Integration.Operation /// </summary> /// <param name="job">The job.</param> /// <returns></returns> - public JobHandler Print(Job job) + public Task<JobHandler> Print(Job job) { //Check not brush stop has color space 'Volume'. if (job.Segments.SelectMany(x => x.BrushStops).ToList().Exists(x => x.ColorSpace.Code == ColorSpaces.Volume.ToInt32())) @@ -1217,181 +1243,185 @@ namespace Tango.Integration.Operation /// <param name="job">The job.</param> /// <param name="processParameters">Process parameters table</param> /// <returns></returns> - public JobHandler Print(Job job, ProcessParametersTable processParameters) + public Task<JobHandler> Print(Job job, ProcessParametersTable processParameters) { - if (Status != MachineStatuses.ReadyToDye) + return Task.Factory.StartNew(() => { - throw new InvalidOperationException("Could not print while status = " + Status); - } + if (Status != MachineStatuses.ReadyToDye) + { + throw new InvalidOperationException("Could not print while status = " + Status); + } - RunningJob = null; - RunningJobStatus = null; + RunningJob = null; + RunningJobStatus = null; - var originalJob = job; + var originalJob = job; - CurrentProcessParameters = processParameters; + CurrentProcessParameters = processParameters; - JobRequest request = new JobRequest(); + JobRequest request = new JobRequest(); - if (job.NumberOfUnits < 1) - { - job.NumberOfUnits = 1; - } + if (job.NumberOfUnits < 1) + { + job.NumberOfUnits = 1; + } - job = job.Clone(); + job = job.Clone(); - int max = job.OrderedSegments.Last().SegmentIndex; + int max = job.OrderedSegments.Last().SegmentIndex; - var segments = job.OrderedSegments.ToList(); + var segments = job.OrderedSegments.ToList(); - for (int i = 0; i < job.NumberOfUnits - 1; i++) - { - foreach (var s in segments) + for (int i = 0; i < job.NumberOfUnits - 1; i++) { - var cloned = s.Clone(job); - cloned.SegmentIndex = max++; - job.Segments.Add(cloned); + foreach (var s in segments) + { + var cloned = s.Clone(job); + cloned.SegmentIndex = max++; + job.Segments.Add(cloned); + } } - } - JobTicket ticket = new JobTicket(); - ticket.Guid = originalJob.Guid; - ticket.EnableInterSegment = job.EnableInterSegment; - ticket.InterSegmentLength = job.InterSegmentLength; - ticket.EnableLubrication = job.EnableLubrication; - ticket.Length = job.Length; - ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code; - ticket.Spool = new JobSpool(); + JobTicket ticket = new JobTicket(); + ticket.Guid = originalJob.Guid; + ticket.EnableInterSegment = job.EnableInterSegment; + ticket.InterSegmentLength = job.InterSegmentLength; + ticket.EnableLubrication = job.EnableLubrication; + ticket.Length = job.Length; + ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code; + ticket.Spool = new JobSpool(); - job.SpoolType.MapPrimitivesTo(ticket.Spool); + job.SpoolType.MapPrimitivesTo(ticket.Spool); - var spool = job.Machine.Spools.SingleOrDefault(x => x.SpoolType == job.SpoolType); + var spool = job.Machine.Spools.SingleOrDefault(x => x.SpoolType == job.SpoolType); - if (spool == null) - { - throw new InvalidOperationException("Job spool type is not registered with this machine."); - } - else - { - spool.MapPrimitivesTo(ticket.Spool); - } + if (spool == null) + { + throw new InvalidOperationException("Job spool type is not registered with this machine."); + } + else + { + spool.MapPrimitivesTo(ticket.Spool); + } - ticket.Spool.JobSpoolType = (JobSpoolType)job.SpoolType.Code; + ticket.Spool.JobSpoolType = (JobSpoolType)job.SpoolType.Code; - ProcessParameters process = new ProcessParameters(); - processParameters.MapPrimitivesTo(process); - ticket.ProcessParameters = process; + ProcessParameters process = new ProcessParameters(); + processParameters.MapPrimitivesTo(process); + ticket.ProcessParameters = process; - foreach (var segment in job.OrderedSegments) - { - ticket.Segments.Add(CreatePMRJobSegment(segment, job, processParameters)); - } + foreach (var segment in job.OrderedSegments) + { + ticket.Segments.Add(CreatePMRJobSegment(segment, job, processParameters)); + } - request.JobTicket = ticket.Clone(); + request.JobTicket = ticket.Clone(); - JobHandler handler = null; + JobHandler handler = null; - handler = new JobHandler(async () => - { - try - { - var result = await SendRequest<AbortJobRequest, AbortJobResponse>(new AbortJobRequest()); - PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseCanceled(); - } - catch (Exception ex) + handler = new JobHandler(async () => { - LogManager.Log(ex, "Failed to cancel job."); - } - }, originalJob, ticket, processParameters, JobHandlingMode); + try + { + var result = await SendRequest<AbortJobRequest, AbortJobResponse>(new AbortJobRequest()); + PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseCanceled(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Failed to cancel job."); + } + }, originalJob, ticket, processParameters, JobHandlingMode); - handler.StatusChanged += (x, s) => - { - RunningJobStatus = s; - }; + handler.StatusChanged += (x, s) => + { + RunningJobStatus = s; + }; - if (!job.IsAllSegmentsPerSpool) - { - ContinueSingleSpoolJob(job.OrderedSegments.First(), job, processParameters, handler); - return handler; - } + if (!job.IsAllSegmentsPerSpool) + { + ContinueSingleSpoolJob(job.OrderedSegments.First(), job, processParameters, handler); + return handler; + } - request.JobTicket.UploadStrategy = JobUploadStrategy; + request.JobTicket.UploadStrategy = JobUploadStrategy; - ThreadFactory.StartNew(async () => - { - if (JobUploadStrategy == JobUploadStrategy.JobDescriptionFile) + ThreadFactory.StartNew(async () => { - request.JobTicket.Segments.Clear(); - - JobDescriptionFile jobDescriptionFile = new JobDescriptionFile(ticket.Segments); - MemoryStream ms = jobDescriptionFile.ToStream(); + if (JobUploadStrategy == JobUploadStrategy.JobDescriptionFile) + { + request.JobTicket.Segments.Clear(); - var storage = CreateStorageManager(); + JobDescriptionFile jobDescriptionFile = new JobDescriptionFile(ticket.Segments); + MemoryStream ms = jobDescriptionFile.ToStream(); - var storageInfo = await storage.GetStorageDrive(); - var root_folder = await storage.GetRootFolder(); + var storage = CreateStorageManager(); - var existing_item = root_folder.Items.SingleOrDefault(x => x.Name == JOB_DESCRIPTION_FILE_NAME); - if (existing_item != null) - { - await storage.DeleteItem(existing_item); - } + var storageInfo = await storage.GetStorageDrive(); + var root_folder = await storage.GetRootFolder(); - String job_file_path = Path.Combine(storageInfo.Root, JOB_DESCRIPTION_FILE_NAME); + var existing_item = root_folder.Items.SingleOrDefault(x => x.Name == JOB_DESCRIPTION_FILE_NAME); + if (existing_item != null) + { + await storage.DeleteItem(existing_item); + } - await storage.UploadFileSync(job_file_path, ms); + String job_file_path = Path.Combine(storageInfo.Root, JOB_DESCRIPTION_FILE_NAME); - ms.Dispose(); + await storage.UploadFileSync(job_file_path, ms); - request.JobTicket.JobDescriptionFile = job_file_path; - } + ms.Dispose(); - LogRequestSent(request); - bool responseLogged = false; + request.JobTicket.JobDescriptionFile = job_file_path; + } - Status = MachineStatuses.Printing; - RunningJob = originalJob; - PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + LogRequestSent(request); + bool responseLogged = false; - SendContinuousRequest<JobRequest, JobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) => - { - handler.RaiseStatusReceived(response.Message.Status); + Status = MachineStatuses.Printing; + RunningJob = originalJob; + PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - if (!responseLogged) + SendContinuousRequest<JobRequest, JobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) => { - responseLogged = true; - LogResponseReceived(response.Message); - } - }, (ex) => - { - if (!(ex is ContinuousResponseAbortedException)) + handler.RaiseStatusReceived(response.Message.Status); + + if (!responseLogged) + { + responseLogged = true; + LogResponseReceived(response.Message); + } + }, (ex) => { - Status = MachineStatuses.ReadyToDye; + if (!(ex is ContinuousResponseAbortedException)) + { + Status = MachineStatuses.ReadyToDye; - if (!handler.IsCanceled) + if (!handler.IsCanceled) + { + PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseFailed(ex); + LogRequestFailed(request, ex); + } + } + else { - PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseFailed(ex); - LogRequestFailed(request, ex); + Status = MachineStatuses.ReadyToDye; } - } - else + }, () => { Status = MachineStatuses.ReadyToDye; - } - }, () => - { - Status = MachineStatuses.ReadyToDye; - PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseCompleted(); + PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseCompleted(); + }); }); - }); - return handler; + return handler; + + }); } /// <summary> @@ -1415,204 +1445,209 @@ namespace Tango.Integration.Operation /// or /// Liquid volume not found for color conversion output liquid '" + outputLiquid.LiquidType + "'. /// </exception> - public JobHandler PrintStub(Job job) + public Task<JobHandler> PrintStub(Job job) { - //Check not brush stop has color space 'Volume'. - if (job.Segments.SelectMany(x => x.BrushStops).ToList().Exists(x => x.ColorSpace.Code == ColorSpaces.Volume.ToInt32())) + return Task.Factory.StartNew<JobHandler>(() => { - throw new InvalidOperationException("Cannot print a brush stop with volume color space when process parameters table has not been specified."); - } - //Get least common process parameters table index. - int processParametersTableIndex = 0; + //Check not brush stop has color space 'Volume'. + if (job.Segments.SelectMany(x => x.BrushStops).ToList().Exists(x => x.ColorSpace.Code == ColorSpaces.Volume.ToInt32())) + { + throw new InvalidOperationException("Cannot print a brush stop with volume color space when process parameters table has not been specified."); + } - if (job.Rml == null) - { - throw new NullReferenceException("Job RML is null"); - } + //Get least common process parameters table index. + int processParametersTableIndex = 0; - var processGroup = job.Rml.ProcessParametersTablesGroups.FirstOrDefault(x => x.Active); + if (job.Rml == null) + { + throw new NullReferenceException("Job RML is null"); + } - if (processGroup == null) - { - throw new NullReferenceException("Could not locate an active process parameters tables group for RML " + job.Rml.Name); - } + var processGroup = job.Rml.ProcessParametersTablesGroups.FirstOrDefault(x => x.Active); - var processParameters = processGroup.ProcessParametersTables.FirstOrDefault(x => x.TableIndex == processParametersTableIndex); + if (processGroup == null) + { + throw new NullReferenceException("Could not locate an active process parameters tables group for RML " + job.Rml.Name); + } - if (processParameters == null) - { - throw new NullReferenceException("Could not locate process parameters table index " + processParametersTableIndex + " in group " + processGroup.Name + " for RML " + job.Rml.Name); - } + var processParameters = processGroup.ProcessParametersTables.FirstOrDefault(x => x.TableIndex == processParametersTableIndex); - //Perform color correction - foreach (var stop in job.Segments.SelectMany(x => x.BrushStops)) - { - if (stop.LiquidVolumes == null) + if (processParameters == null) { - stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); + throw new NullReferenceException("Could not locate process parameters table index " + processParametersTableIndex + " in group " + processGroup.Name + " for RML " + job.Rml.Name); } - foreach (var liquidVolume in stop.LiquidVolumes) + //Perform color correction + foreach (var stop in job.Segments.SelectMany(x => x.BrushStops)) { - liquidVolume.Volume = 10; + if (stop.LiquidVolumes == null) + { + stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); + } + + foreach (var liquidVolume in stop.LiquidVolumes) + { + liquidVolume.Volume = 10; + } } - } - if (Status != MachineStatuses.ReadyToDye) - { - throw new InvalidOperationException("Could not print while status = " + Status); - } + if (Status != MachineStatuses.ReadyToDye) + { + throw new InvalidOperationException("Could not print while status = " + Status); + } - RunningJob = null; - RunningJobStatus = null; + RunningJob = null; + RunningJobStatus = null; - var originalJob = job; + var originalJob = job; - CurrentProcessParameters = processParameters; + CurrentProcessParameters = processParameters; - StubJobRequest request = new StubJobRequest(); + StubJobRequest request = new StubJobRequest(); - if (job.NumberOfUnits < 1) - { - job.NumberOfUnits = 1; - } + if (job.NumberOfUnits < 1) + { + job.NumberOfUnits = 1; + } - job = job.Clone(); + job = job.Clone(); - var segments = job.OrderedSegments.ToList(); + var segments = job.OrderedSegments.ToList(); - for (int i = 0; i < job.NumberOfUnits - 1; i++) - { - foreach (var s in segments) + for (int i = 0; i < job.NumberOfUnits - 1; i++) { - job.Segments.Add(s); + foreach (var s in segments) + { + job.Segments.Add(s); + } } - } - - JobTicket ticket = new JobTicket(); - ticket.Guid = originalJob.Guid; - ticket.EnableInterSegment = job.EnableInterSegment; - ticket.InterSegmentLength = job.InterSegmentLength; - ticket.Length = job.Length; - ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code; - ticket.Spool = new JobSpool(); - job.SpoolType.MapPrimitivesTo(ticket.Spool); - ticket.Spool.JobSpoolType = (JobSpoolType)job.SpoolType.Code; + JobTicket ticket = new JobTicket(); + ticket.Guid = originalJob.Guid; + ticket.EnableInterSegment = job.EnableInterSegment; + ticket.InterSegmentLength = job.InterSegmentLength; + ticket.Length = job.Length; + ticket.WindingMethod = (JobWindingMethod)job.WindingMethod.Code; + ticket.Spool = new JobSpool(); - ProcessParameters process = new ProcessParameters(); - processParameters.MapPrimitivesTo(process); - ticket.ProcessParameters = process; + job.SpoolType.MapPrimitivesTo(ticket.Spool); + ticket.Spool.JobSpoolType = (JobSpoolType)job.SpoolType.Code; - foreach (var segment in job.OrderedSegments) - { - JobSegment jobSegment = new JobSegment(); - jobSegment.Length = segment.LengthWithFactor; - jobSegment.Name = segment.Name; + ProcessParameters process = new ProcessParameters(); + processParameters.MapPrimitivesTo(process); + ticket.ProcessParameters = process; - foreach (var stop in segment.BrushStops) + foreach (var segment in job.OrderedSegments) { - JobBrushStop jobStop = new JobBrushStop(); - jobStop.Index = stop.StopIndex; - jobStop.OffsetPercent = stop.OffsetPercent; - jobStop.OffsetMeters = stop.OffsetMeters; + JobSegment jobSegment = new JobSegment(); + jobSegment.Length = segment.LengthWithFactor; + jobSegment.Name = segment.Name; - if (stop.LiquidVolumes == null) + foreach (var stop in segment.BrushStops) { - stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); - } + JobBrushStop jobStop = new JobBrushStop(); + jobStop.Index = stop.StopIndex; + jobStop.OffsetPercent = stop.OffsetPercent; + jobStop.OffsetMeters = stop.OffsetMeters; - foreach (var liquidVolume in stop.LiquidVolumes) - { - JobDispenser dispenser = new JobDispenser(); - dispenser.Index = liquidVolume.IdsPack.PackIndex; - dispenser.Volume = liquidVolume.Volume; - dispenser.DispenserLiquidType = (DispenserLiquidType)liquidVolume.IdsPack.LiquidType.Code; - dispenser.DispenserStepDivision = (DispenserStepDivision)liquidVolume.DispenserStepDivision; + if (stop.LiquidVolumes == null) + { + stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); + } - dispenser.NanoliterPerPulse = liquidVolume.IdsPack.Dispenser.NlPerPulse; + foreach (var liquidVolume in stop.LiquidVolumes) + { + JobDispenser dispenser = new JobDispenser(); + dispenser.Index = liquidVolume.IdsPack.PackIndex; + dispenser.Volume = liquidVolume.Volume; + dispenser.DispenserLiquidType = (DispenserLiquidType)liquidVolume.IdsPack.LiquidType.Code; + dispenser.DispenserStepDivision = (DispenserStepDivision)liquidVolume.DispenserStepDivision; + + dispenser.NanoliterPerPulse = liquidVolume.IdsPack.Dispenser.NlPerPulse; - dispenser.LiquidMaxNanoliterPerCentimeter = liquidVolume.LiquidMaxNanoliterPerCentimeter; - dispenser.NanoliterPerCentimeter = liquidVolume.NanoliterPerCentimeter; - dispenser.NanolitterPerSecond = liquidVolume.NanoliterPerSecond; - dispenser.PulsePerSecond = liquidVolume.PulsePerSecond; + dispenser.LiquidMaxNanoliterPerCentimeter = liquidVolume.LiquidMaxNanoliterPerCentimeter; + dispenser.NanoliterPerCentimeter = liquidVolume.NanoliterPerCentimeter; + dispenser.NanolitterPerSecond = liquidVolume.NanoliterPerSecond; + dispenser.PulsePerSecond = liquidVolume.PulsePerSecond; - jobStop.Dispensers.Add(dispenser); + jobStop.Dispensers.Add(dispenser); + } + + jobSegment.BrushStops.Add(jobStop); } - jobSegment.BrushStops.Add(jobStop); + ticket.Segments.Add(jobSegment); } - ticket.Segments.Add(jobSegment); - } + request.JobTicket = ticket; - request.JobTicket = ticket; - - JobHandler handler = null; + JobHandler handler = null; - handler = new JobHandler(async () => - { - try + handler = new JobHandler(async () => { - var result = await SendRequest<StubAbortJobRequest, StubAbortJobResponse>(new StubAbortJobRequest()); - PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseCanceled(); - } - catch (Exception ex) - { - LogManager.Log(ex, "Failed to cancel job."); - } - }, originalJob, ticket, processParameters, JobHandlingMode); - - handler.StatusChanged += (x, s) => - { - RunningJobStatus = s; - }; + try + { + var result = await SendRequest<StubAbortJobRequest, StubAbortJobResponse>(new StubAbortJobRequest()); + PrintingAborted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseCanceled(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Failed to cancel job."); + } + }, originalJob, ticket, processParameters, JobHandlingMode); - LogRequestSent(request); - bool responseLogged = false; + handler.StatusChanged += (x, s) => + { + RunningJobStatus = s; + }; - SendContinuousRequest<StubJobRequest, StubJobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) => - { - handler.RaiseStatusReceived(response.Message.Status); + LogRequestSent(request); + bool responseLogged = false; - if (!responseLogged) + SendContinuousRequest<StubJobRequest, StubJobResponse>(request, null, TimeSpan.FromSeconds(2)).Subscribe((response) => { - responseLogged = true; - Status = MachineStatuses.Printing; - RunningJob = originalJob; - PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - LogResponseReceived(response.Message); - } - }, (ex) => - { - if (!(ex is ContinuousResponseAbortedException)) + handler.RaiseStatusReceived(response.Message.Status); + + if (!responseLogged) + { + responseLogged = true; + Status = MachineStatuses.Printing; + RunningJob = originalJob; + PrintingStarted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + LogResponseReceived(response.Message); + } + }, (ex) => { - Status = MachineStatuses.ReadyToDye; + if (!(ex is ContinuousResponseAbortedException)) + { + Status = MachineStatuses.ReadyToDye; - if (!handler.IsCanceled) + if (!handler.IsCanceled) + { + PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseFailed(ex); + LogRequestFailed(request, ex); + } + } + else { - PrintingFailed?.Invoke(this, new PrintingFailedEventArgs(handler, originalJob, ex)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseFailed(ex); - LogRequestFailed(request, ex); + Status = MachineStatuses.ReadyToDye; } - } - else + }, () => { Status = MachineStatuses.ReadyToDye; - } - }, () => - { - Status = MachineStatuses.ReadyToDye; - PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); - handler.RaiseCompleted(); - }); + PrintingCompleted?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + PrintingEnded?.Invoke(this, new PrintingEventArgs(handler, originalJob)); + handler.RaiseCompleted(); + }); + + return handler; - return handler; + }); } /// <summary> diff --git a/Software/Visual_Studio/Tango.Integration/Operation/PreparingJobProgressEventArgs.cs b/Software/Visual_Studio/Tango.Integration/Operation/PreparingJobProgressEventArgs.cs new file mode 100644 index 000000000..7c53fd7fb --- /dev/null +++ b/Software/Visual_Studio/Tango.Integration/Operation/PreparingJobProgressEventArgs.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; + +namespace Tango.Integration.Operation +{ + /// <summary> + /// Represents the <see cref="IMachineOperator.PreparingJobProgress"/> event arguments. + /// </summary> + /// <seealso cref="System.EventArgs" /> + public class PreparingJobProgressEventArgs : EventArgs + { + /// <summary> + /// Gets or sets the job. + /// </summary> + public Job Job { get; set; } + + /// <summary> + /// Gets or sets the progress. + /// </summary> + public double Progress { get; set; } + + /// <summary> + /// Gets or sets the total progress. + /// </summary> + public double Total { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index 8d6d43c02..7bea3eccb 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -92,7 +92,10 @@ <Compile Include="Logging\EmbeddedLogFileParser.cs" /> <Compile Include="Operation\DefaultMachineEventsStateProvider.cs" /> <Compile Include="Logging\EmbeddedLogItem.cs" /> + <Compile Include="Operation\DefaultGradientGenerationConfiguration.cs" /> + <Compile Include="Operation\IGradientGenerationConfiguration.cs" /> <Compile Include="Operation\JobDescriptionFile.cs" /> + <Compile Include="Operation\PreparingJobProgressEventArgs.cs" /> <Compile Include="Operation\SpoolChangeRequiredEventArgs.cs" /> <Compile Include="Upgrade\FirmwareUpgradeHandler.cs" /> <Compile Include="Upgrade\FirmwareUpgradeModes.cs" /> @@ -176,7 +179,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file |
