aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Rendering/TextLayer.cs
blob: 3f4b8299be88d1135723c325c47e6dc8dbb723a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace Tango.Scripting.Editors.Rendering
{
	/// <summary>
	/// The control that contains the text.
	/// 
	/// This control is used to allow other UIElements to be placed inside the TextView but
	/// behind the text.
	/// The text rendering process (VisualLine creation) is controlled by the TextView, this
	/// class simply displays the created Visual Lines.
	/// </summary>
	/// <remarks>
	/// This class does not contain any input handling and is invisible to hit testing. Input
	/// is handled by the TextView.
	/// This allows UIElements that are displayed behind the text, but still can react to mouse input.
	/// </remarks>
	sealed class TextLayer : Layer
	{
		/// <summary>
		/// the index of the text layer in the layers collection
		/// </summary>
		internal int index;
		
		public TextLayer(TextView textView) : base(textView, KnownLayer.Text)
		{
		}
		
		List<VisualLineDrawingVisual> visuals = new List<VisualLineDrawingVisual>();
		
		internal void SetVisualLines(ICollection<VisualLine> visualLines)
		{
			foreach (VisualLineDrawingVisual v in visuals) {
				if (v.VisualLine.IsDisposed)
					RemoveVisualChild(v);
			}
			visuals.Clear();
			foreach (VisualLine newLine in visualLines) {
				VisualLineDrawingVisual v = newLine.Render();
				if (!v.IsAdded) {
					AddVisualChild(v);
					v.IsAdded = true;
				}
				visuals.Add(v);
			}
			InvalidateArrange();
		}
		
		protected override int VisualChildrenCount {
			get { return visuals.Count; }
		}
		
		protected override Visual GetVisualChild(int index)
		{
			return visuals[index];
		}
		
		protected override void ArrangeCore(Rect finalRect)
		{
			textView.ArrangeTextLayer(visuals);
		}
	}
}
ystem.Threading.Tasks; using Tango.BL; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core; using Tango.Core.DI; using Tango.Integration.Operation; using Tango.PMR.MachineStatus; using Tango.PPC.Common; using Tango.PPC.Common.Connection; using Tango.PPC.Common.Messages; using Tango.PPC.Common.Models; using Tango.PPC.Common.Navigation; using Tango.PPC.Common.Notifications; using Tango.PPC.Common.Printing; using Tango.PPC.Jobs.Messages; using Tango.PPC.UI.Dialogs; using Tango.Settings; namespace Tango.PPC.UI.Printing { /// <summary> /// Represents a printing manager capable of executing jobs, changing job statuses according to completion stage and generating sample and fine tuning jobs. /// </summary> /// <seealso cref="Tango.Core.ExtendedObject" /> /// <seealso cref="Tango.PPC.Common.Printing.IPrintingManager" /> public class DefaultPrintingManager : ExtendedObject, IPrintingManager { private IMachineProvider _machineProvider; private INotificationProvider _notificationProvider; private PPCSettings _settings; /// <summary> /// Initializes a new instance of the <see cref="DefaultPrintingManager"/> class. /// </summary> /// <param name="machineProvider">The machine provider.</param> public DefaultPrintingManager(IMachineProvider machineProvider, INotificationProvider notificationProvider) { _machineProvider = machineProvider; _notificationProvider = notificationProvider; _settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); } /// <summary> /// Prints the specified job. /// When the job is complete the job status will change according to the completion stage. /// </summary> /// <param name="job">The job.</param> /// <param name="context">The context.</param> /// <returns></returns> public async Task<JobHandler> Print(Job job, ObservablesContext context) { ThrowIfJobInvalid(job); JobHandler handler = null; #if STUBPRINT handler = await _machineProvider.MachineOperator.PrintStub(job); #else try { if (job.Designation == JobDesignations.Default && _settings.EnableSpoolReplacementDialog && !_machineProvider.MachineOperator.IsSpoolReplaced) { if (!(await _notificationProvider.ShowDialog(new SpoolReplaceViewVM())).DialogResult) { throw new OperationCanceledException(); } } _notificationProvider.SetGlobalBusyMessage("Processing job..."); //Apply additional job configuration... AdditionalJobConfiguration config = new AdditionalJobConfiguration(); config.UseColorConversion = true; config.UseLightInks = true; config.UseLubricantVolume = true; var settings = SettingsManager.Default.GetOrCreate<PPCSettings>(); var rmlLubrication = settings.LubricationLevels.FirstOrDefault(x => x.RmlGuid == job.RmlGuid); if (rmlLubrication != null) { config.LubricationVolume = (int)rmlLubrication.LubricationLevel; } var spoolTypeGuid = settings.SpoolTypeGuid; var spoolType = await context.SpoolTypes.FirstOrDefaultAsync(x => x.Guid == spoolTypeGuid); if (spoolType == null) { spoolType = await context.SpoolTypes.FirstOrDefaultAsync(x => x.Code == (int)BL.Enumerations.SpoolTypes.StandardSpool); } job.SpoolType = spoolType; handler = await _machineProvider.MachineOperator.Print(job, config); _notificationProvider.ReleaseGlobalBusyMessage(); } catch (InsufficientLiquidQuantityException ex) { _notificationProvider.ReleaseGlobalBusyMessage(); LogManager.Log(ex); var vm = await _notificationProvider.ShowDialog(new InsufficientLiquidQuantityViewVM(ex, _machineProvider.MachineOperator.MachineStatus.AutoInkFillingEnabled)); if (vm.StartAutoInkFillingOnExit) { try { _notificationProvider.SetGlobalBusyMessage("Starting ink filling..."); await _machineProvider.MachineOperator.SendRequest<InitiateInkFillingRequest, InitiateInkFillingResponse>(new InitiateInkFillingRequest()); } catch (Exception exx) { LogManager.Log(exx, "Error starting ink filling."); await _notificationProvider.ShowError($"Error starting ink filling.\n{ex.Message}"); } finally { _notificationProvider.ReleaseGlobalBusyMessage(); } } throw ex; } catch (Exception ex) { _notificationProvider.ReleaseGlobalBusyMessage(); LogManager.Log(ex); throw ex; } #endif handler.Completed += async (x, e) => { try { job.JobStatus = JobStatuses.Completed; if (!context.IsDisposed) { await context.SaveChangesAsync(); RaiseJobSaved(job); } else { using (var newContext = ObservablesContext.CreateDefault()) { var newJob = newContext.Jobs.SingleOrDefault(y => y.Guid == job.Guid); if (newJob != null) { newJob.JobStatus = JobStatuses.Completed; await newContext.SaveChangesAsync(); RaiseJobSaved(job); } } } } catch (Exception ex) { LogManager.Log(ex, "Error occurred after job printing completed."); } }; handler.Canceled += (x, e) => { try { //No change in status ! //await context.SaveChangesAsync(); RaiseJobSaved(job); } catch (Exception ex) { LogManager.Log(ex, "Error occurred after job printing completed."); } }; handler.Failed += async (x, e) => { try { job.JobStatus = JobStatuses.Disrupted; if (!context.IsDisposed) { await context.SaveChangesAsync(); } else { using (var newContext = ObservablesContext.CreateDefault()) { var newJob = newContext.Jobs.SingleOrDefault(y => y.Guid == job.Guid); if (newJob != null) { newJob.JobStatus = JobStatuses.Disrupted; await newContext.SaveChangesAsync(); } } } RaiseJobSaved(job); } catch (Exception ex) { LogManager.Log(ex, "Error occurred after job printing completed."); } }; return handler; } /// <summary> /// Creates a sample dye job from the specified job and prints it. /// When the sample dye job is complete, the job sample dye status will change. /// </summary> /// <param name="job">The job.</param> /// <param name="context">The context.</param> /// <returns></returns> public async Task<JobHandler> PrintSample(Job job, ObservablesContext context) { ThrowIfJobInvalid(job); LogManager.Log("Cloning job..."); Job sampleDyeJob = job.Clone(); sampleDyeJob.Guid = job.Guid; sampleDyeJob.Designation = BL.Enumerations.JobDesignations.SampleDye; sampleDyeJob.Name = job.Name; if (job.JobType == BL.Enumerations.JobTypes.Embroidery) { sampleDyeJob.NumberOfUnits = job.SampleUnitsOrMeters; } else { sampleDyeJob.NumberOfUnits = 1; foreach (var segment in sampleDyeJob.OrderedSegments) { segment.Length = job.SampleUnitsOrMeters; } } context.SaveChanges(); RaiseJobSaved(job); LogManager.Log("Executing sample dye job..."); var handler = await _machineProvider.MachineOperator.Print(sampleDyeJob); handler.Completed += async (x, e) => { try { job.JobEditingState = BL.Enumerations.EditingStates.SampleDye; job.JobSampleDyeStatus = BL.Enumerations.SampleDyeStatuses.PendingApproval; await context.SaveChangesAsync(); } catch (Exception ex) { LogManager.Log(ex, "Error occurred after sample dye printing completed."); } }; return handler; } /// <summary> /// Creates a fine tuning job from the specified job and fine tune items. /// When the fine tuning job is complete, the job fine tuning status will change. /// </summary> /// <param name="job">The job.</param> /// <param name="context">The context.</param> /// <param name="fineTuneItems">The fine tune items.</param> /// <returns></returns> public async Task<JobHandler> PrintFineTuning(Job job, ObservablesContext context, IEnumerable<FineTuneItem> fineTuneItems) { ThrowIfJobInvalid(job); LogManager.Log("Cloning job..."); Job fineTuneJob = job.Clone(); fineTuneJob.NumberOfUnits = 1; fineTuneJob.Designation = BL.Enumerations.JobDesignations.FineTuning; fineTuneJob.Guid = job.Guid; fineTuneJob.Name = job.Name; fineTuneJob.Segments.Clear(); foreach (var suggestion in fineTuneItems.Where(x => x.IsSelected).SelectMany(x => x.Suggestions)) { var segment = fineTuneJob.AddSolidSegment(suggestion.Color); } var handler = await _machineProvider.MachineOperator.Print(fineTuneJob); handler.Completed += async (x, e) => { try { job.JobEditingState = BL.Enumerations.EditingStates.FineTuning; job.JobFineTuningStatus = BL.Enumerations.FineTuningStatuses.PendingApproval; await context.SaveChangesAsync(); } catch (Exception ex) { LogManager.Log(ex, "Error occurred after fine tunning job completed."); } }; return handler; } /// <summary> /// Raises the job saved messenger message. /// </summary> /// <param name="job">The job.</param> private void RaiseJobSaved(Job job) { TangoMessenger.Default.Send(new JobSavedMessage() { Job = job }); } private void ThrowIfJobInvalid(Job job) { if (job.Segments.SelectMany(x => x.BrushStops).Any(x => x.IsOutOfGamut)) { throw new InvalidOperationException("Error starting job. Color is out of range."); } if (job.Segments.SelectMany(x => x.BrushStops).Any(x => x.IsLiquidVolumesOutOfRange)) { throw new InvalidOperationException("Error starting job. Total ink volume is out of range."); } if (job.Segments.SelectMany(x => x.BrushStops).Any(x => x.BrushColorSpace == ColorSpaces.Catalog && x.ColorCatalogsItem == null && !x.IsTransparent && !x.IsWhite)) { throw new InvalidOperationException("Error starting job. Please select a catalog color."); } if (job.Rml.Cct == null) { throw new InvalidOperationException($"Error starting job. No color table found for thread '{job.Rml.Name}'."); } } } }