aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Communication/PMR/EmbeddedParameters/MidTankData.pb-c.h
blob: eb3b93d7b7b1ea077035f6904b5e1ffb4ff354c6 (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
71
72
73
74
75
76
/* Generated by the protocol buffer compiler.  DO NOT EDIT! */
/* Generated from: MidTankData.proto */

#ifndef PROTOBUF_C_MidTankData_2eproto__INCLUDED
#define PROTOBUF_C_MidTankData_2eproto__INCLUDED

#include <protobuf-c/protobuf-c.h>

PROTOBUF_C__BEGIN_DECLS

#if PROTOBUF_C_VERSION_NUMBER < 1003000
# error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers.
#elif 1003000 < PROTOBUF_C_MIN_COMPILER_VERSION
# error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c.
#endif


typedef struct _MidTankData MidTankData;


/* --- enums --- */


/* --- messages --- */

struct  _MidTankData
{
  ProtobufCMessage base;
  protobuf_c_boolean has_midtankid;
  uint32_t midtankid;
  protobuf_c_boolean has_initialoffseta;
  double initialoffseta;
  protobuf_c_boolean has_slopeb;
  double slopeb;
};
#define MID_TANK_DATA__INIT \
 { PROTOBUF_C_MESSAGE_INIT (&mid_tank_data__descriptor) \
    , 0, 0, 0, 0, 0, 0 }


/* MidTankData methods */
void   mid_tank_data__init
                     (MidTankData         *message);
size_t mid_tank_data__get_packed_size
                     (const MidTankData   *message);
size_t mid_tank_data__pack
                     (const MidTankData   *message,
                      uint8_t             *out);
size_t mid_tank_data__pack_to_buffer
                     (const MidTankData   *message,
                      ProtobufCBuffer     *buffer);
MidTankData *
       mid_tank_data__unpack
                     (ProtobufCAllocator  *allocator,
                      size_t               len,
                      const uint8_t       *data);
void   mid_tank_data__free_unpacked
                     (MidTankData *message,
                      ProtobufCAllocator *allocator);
/* --- per-message closures --- */

typedef void (*MidTankData_Closure)
                 (const MidTankData *message,
                  void *closure_data);

/* --- services --- */


/* --- descriptors --- */

extern const ProtobufCMessageDescriptor mid_tank_data__descriptor;

PROTOBUF_C__END_DECLS


#endif  /* PROTOBUF_C_MidTankData_2eproto__INCLUDED */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.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 (_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.AutoInkFillingDisabled));

                if (vm.EnableAutoInkFillingOnExit)
                {
                    try
                    {
                        _notificationProvider.SetGlobalBusyMessage("Enabling auto ink filling...");
                        await _machineProvider.MachineOperator.SendRequest<SetInkAutoFillingModeRequest, SetInkAutoFillingModeResponse>(new SetInkAutoFillingModeRequest()
                        {
                            Disabled = false
                        });
                    }
                    catch (Exception exx)
                    {
                        LogManager.Log(exx, "Error enabling ink filling.");
                        await _notificationProvider.ShowError($"Error enabling auto 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();
                    }
                    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}'.");
            }
        }
    }
}