From c5cde62cecfdd413e9902b26b30b0d4dfd05a24d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 14 Mar 2019 13:25:32 +0200 Subject: Machine Studio v4.0.10 PPC v1.0.9 --- .../Modules/Tango.MachineStudio.Developer/Views/JobView.xaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index 1057f7c84..9504d5769 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -432,7 +432,7 @@ - + @@ -866,8 +866,8 @@ - - Enable Color Conversion + + Enable Gradient Generation -- cgit v1.3.1 From 73327143a2ac187695bed0ecded52c4d675165c4 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 18 Mar 2019 15:01:20 +0200 Subject: Fixed issue with brush stop duplication on developer module. --- .../Converters/LiquidVolumesToLubricantLiquidVolume.cs | 11 +++++++++-- .../Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | 1 + .../Modules/Tango.MachineStudio.Developer/Views/JobView.xaml | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/LiquidVolumesToLubricantLiquidVolume.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/LiquidVolumesToLubricantLiquidVolume.cs index e59141e7f..5939bfd53 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/LiquidVolumesToLubricantLiquidVolume.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Converters/LiquidVolumesToLubricantLiquidVolume.cs @@ -14,8 +14,15 @@ namespace Tango.MachineStudio.Developer.Converters { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - IEnumerable liquid_volumes = value as IEnumerable; - return liquid_volumes.SingleOrDefault(x => x.IdsPack.IdsPackFormula.Code == IdsPackFormulas.Lubricant.ToInt32()); + if (value != null) + { + IEnumerable liquid_volumes = value as IEnumerable; + return liquid_volumes.SingleOrDefault(x => x.IdsPack.IdsPackFormula.Code == IdsPackFormulas.Lubricant.ToInt32()); + } + else + { + return null; + } } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 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 41f57794a..02431fd98 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 @@ -2179,6 +2179,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { var cloned = stop.Clone(); cloned.StopIndex = SelectedSegment.BrushStops.Max(x => x.StopIndex) + 1; + cloned.SetLiquidVolumes(ActiveJob.Machine.Configuration, SelectedRML, SelectedProcessParametersTable); SelectedSegment.BrushStops.Add(cloned); } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index 9504d5769..c4c831011 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -962,11 +962,11 @@ - + - + -- cgit v1.3.1 From c2945492e7c4d168c36b632d1f28dd8ca569b5ac Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 22 Apr 2019 19:49:09 +0300 Subject: Improved ExternalBridge discovery greatly! Implemented volume gradient generation! --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes Software/DB/TCC/TCC.mdf | Bin 8388608 -> 8388608 bytes Software/DB/TCC/TCC_log.ldf | Bin 8388608 -> 8388608 bytes Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../ViewModels/MainViewVM.cs | 2 +- .../Views/JobView.xaml | 12 +- .../Connection/DefaultMachineProvider.cs | 17 ++- .../PPC/Tango.PPC.Common/PPCSettings.cs | 19 +++ .../Tango.Emulations/Emulators/MachineEmulator.cs | 7 +- .../ExternalBridge/ExternalBridgeScanner.cs | 57 +++++---- .../ExternalBridge/ExternalBridgeService.cs | 2 + .../DefaultGradientGenerationConfiguration.cs | 135 ++++++++++++++++++--- .../Tango.Transport/Discovery/DiscoveredService.cs | 14 ++- .../Discovery/UdpDiscoveryClient.cs | 23 +++- .../Discovery/UdpDiscoveryService.cs | 42 +++++-- .../Tango.Transport/Servers/TcpServer.cs | 5 +- 18 files changed, 273 insertions(+), 62 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 2ad3500d7..84785d8cf 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 64c4734b7..5e10994a1 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/DB/TCC/TCC.mdf b/Software/DB/TCC/TCC.mdf index 430d0c50d..7670a3170 100644 Binary files a/Software/DB/TCC/TCC.mdf and b/Software/DB/TCC/TCC.mdf differ diff --git a/Software/DB/TCC/TCC_log.ldf b/Software/DB/TCC/TCC_log.ldf index 51139d1a5..1cf272342 100644 Binary files a/Software/DB/TCC/TCC_log.ldf and b/Software/DB/TCC/TCC_log.ldf differ diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 84eb6afc9..548dda3df 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 f3b9858f1..550ccbeae 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf 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 db9d9dbae..0299940d3 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 @@ -1386,7 +1386,7 @@ namespace Tango.MachineStudio.Developer.ViewModels InvokeUI(() => { - _notification.ShowError("Job failed. " + ex.Message); + _notification.ShowError("Job failed. " + ex.FlattenMessage()); StopRecordingIfInProgress(); }); }; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index c4c831011..bfa951c3b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -865,9 +865,15 @@ - - - Enable Gradient Generation + + Generate Gradient + + Resolution: + + + + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs index 82d805a70..3ffb6f634 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -79,6 +79,13 @@ namespace Tango.PPC.Common.Connection MachineOperator.UseKeepAlive = true; MachineOperator.EnableDiagnostics = false; MachineOperator.EnableEmbeddedDebugging = false; + + var settings = SettingsManager.Default.GetOrCreate(); + + MachineOperator.JobUploadStrategy = settings.JobUploadStrategy; + + MachineOperator.GradientGenerationConfiguration.IsEnabled = settings.EnableGradientGeneration; + MachineOperator.GradientGenerationConfiguration.ResolutionCM = settings.GradientGenerationResolution; } private async void ConnectionThreadMethod() @@ -125,7 +132,15 @@ namespace Tango.PPC.Common.Connection UsbTransportAdapter adapter = new UsbTransportAdapter(settings.EmbeddedComPort, UsbSerialBaudRates.BR_115200); MachineOperator.Adapter = adapter; MachineOperator.JobHandlingMode = JobHandlerModes.SettingUp; - await MachineOperator.Connect(); + try + { + await MachineOperator.Connect(); + } + catch (Exception) + { + await adapter.Disconnect(); + throw; + } await Task.Delay(1000); await MachineOperator.UploadHardwareConfiguration(Machine.Configuration.HardwareVersion, Machine.Configuration); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index 32181a753..698dbf374 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -5,6 +5,7 @@ using System.ServiceModel; using System.Text; using System.Threading.Tasks; using Tango.Logging; +using Tango.PMR.Printing; using Tango.Settings; using Tango.Web; @@ -81,6 +82,21 @@ namespace Tango.PPC.Common /// public bool EnableTechnicianModeByDefault { get; set; } + /// + /// Gets or sets the job upload strategy. + /// + public JobUploadStrategy JobUploadStrategy { get; set; } + + /// + /// Gets or sets a value indicating whether to enable gradient generation. + /// + public bool EnableGradientGeneration { get; set; } + + /// + /// Gets or sets the gradient generation resolution. + /// + public int GradientGenerationResolution { get; set; } + /// /// Gets the machine service address. /// @@ -95,6 +111,9 @@ namespace Tango.PPC.Common /// public PPCSettings() { + JobUploadStrategy = JobUploadStrategy.JobDescriptionFile; + EnableGradientGeneration = true; + GradientGenerationResolution = 20; MachineScanningTimeoutSeconds = 20; LoggingCategories = new List(); EmbeddedComPort = null; diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index f1d9487ff..7f99c8161 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -29,6 +29,7 @@ using Tango.PMR.IO; using System.IO; using Tango.Integration.Operation; using Tango.PMR.FirmwareUpgrade; +using System.Diagnostics; namespace Tango.Emulations.Emulators { @@ -68,6 +69,7 @@ namespace Tango.Emulations.Emulators private List _valveStates; private JobTicket _current_job_ticket; private String _current_job_resume_token; + private FileUploadRequest _lastFileUploadRequest; #region Properties @@ -1038,7 +1040,7 @@ namespace Tango.Emulations.Emulators response.Items.Add(new PMR.IO.FileInfo() { Attribute = FileAttribute.Directory, - FullPath = replaceSlash ? dir.Replace("\\","/") : dir, + FullPath = replaceSlash ? dir.Replace("\\", "/") : dir, LastModifiedDate = dirInfo.LastWriteTime.DayOfYear, LastModifiedTime = dirInfo.LastWriteTime.Hour, Name = Path.GetFileName(dir), @@ -1143,6 +1145,7 @@ namespace Tango.Emulations.Emulators private void HandleFileUploadRequest(TangoMessage request) { var message = request.Message; + _lastFileUploadRequest = message; Transporter.SendResponse(new FileUploadResponse() { MaxChunkLength = MAX_CHUNK_LENGTH, @@ -1160,6 +1163,8 @@ namespace Tango.Emulations.Emulators { byte[] buffer = message.Buffer.ToByteArray(); fs.Write(buffer, 0, buffer.Length); + + Debug.WriteLine($"Emulator file upload '{_lastFileUploadRequest.Path}' {fs.Length}/{_lastFileUploadRequest.Length} ..."); } Transporter.SendResponse(new FileChunkUploadResponse(), request.Container.Token); diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs index 110895bdd..0b1ac9c0e 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs @@ -32,12 +32,13 @@ namespace Tango.Integration.ExternalBridge private Thread _usbDiscoveryThread; private UdpClient _server; private IntegrationSettings _settings; + private const int DISCOVERY_PORT = 8888; - private ObservableCollection _availableMachines; + private SynchronizedObservableCollection _availableMachines; /// /// Gets the available machines. /// - public ObservableCollection AvailableMachines + public SynchronizedObservableCollection AvailableMachines { get { return _availableMachines; } private set { _availableMachines = value; RaisePropertyChangedAuto(); } @@ -60,7 +61,7 @@ namespace Tango.Integration.ExternalBridge { _settings = SettingsManager.Default.GetOrCreate(); _server = new UdpClient(_settings.ExternalBridgeServiceDiscoveryPort); - AvailableMachines = new ObservableCollection(); + AvailableMachines = new SynchronizedObservableCollection(); } /// @@ -136,42 +137,50 @@ namespace Tango.Integration.ExternalBridge { try { - var ClientEp = new IPEndPoint(IPAddress.Any, 0); + var ClientEp = new IPEndPoint(IPAddress.Any, DISCOVERY_PORT); _server.EnableBroadcast = true; var ClientRequestData = _server.Receive(ref ClientEp); ExternalBridgeUdpDiscoveryPacket packet = ExternalBridgeUdpDiscoveryPacket.Parser.ParseFrom(ClientRequestData); - if (packet.Time == String.Empty || (DateTime.Now - ParseDateTime(packet.Time)).TotalSeconds < 6) + String address = ClientEp.Address.ToString(); + + //validate service existence using TCP connection. + try + { + TcpClient client = new TcpClient(); + client.Connect(address, DISCOVERY_PORT); + client.Dispose(); + } + catch { - if (!AvailableMachines.OfType().ToList().Exists(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == ClientEp.Address.ToString())) + var disconnected_machine = AvailableMachines.OfType().ToList().FirstOrDefault(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == address); + + if (disconnected_machine != null) { - ExternalBridgeTcpClient newMachine = new ExternalBridgeTcpClient(packet.SerialNumber, ClientEp.Address.ToString()); + LogManager.Log("Disconnected machine detected via TCP: " + disconnected_machine.SerialNumber); + AvailableMachines.Remove(disconnected_machine); + } - LogManager.Log("Found a new machine via TCP " + newMachine.SerialNumber); + continue; + } - ThreadsHelper.InvokeUINow(() => - { - AvailableMachines.Insert(1, newMachine); - }); - } + if (!AvailableMachines.OfType().ToList().Exists(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == address)) + { + ExternalBridgeTcpClient newMachine = new ExternalBridgeTcpClient(packet.SerialNumber, address); + + LogManager.Log("Found a new machine via TCP " + newMachine.SerialNumber); + + ThreadsHelper.InvokeUINow(() => + { + AvailableMachines.Insert(1, newMachine); + }); } - //else if (packet.Time != String.Empty && (DateTime.Now - DateTime.Parse(packet.Time)).TotalSeconds > 5) - //{ - // var machine = AvailableMachines.OfType().ToList().FirstOrDefault(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == ClientEp.Address.ToString()); - - // if (machine != null) - // { - // AvailableMachines.Remove(machine); - // } - //} } catch (Exception ex) { LogManager.Log(ex); } - - //Thread.Sleep(1000); } } diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs index 90d8995b0..3f4f8559c 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs @@ -28,6 +28,8 @@ namespace Tango.Integration.ExternalBridge private bool _send_app_logs; private String _app_logs_token; private Dictionary> _messageHandlers; + private const int DISCOVERY_PORT = 8888; + private const int EXTERNAL_BRIDGE_PORT = 1984; #region Events diff --git a/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs index d4cc9ce21..68fd14ac2 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs @@ -16,6 +16,15 @@ namespace Tango.Integration.Operation /// public class DefaultGradientGenerationConfiguration : ExtendedObject, IGradientGenerationConfiguration { + private class CMYK + { + public double C { get; set; } + public double M { get; set; } + public double Y { get; set; } + public double K { get; set; } + public double OffsetPercent { get; set; } + } + private bool _isEnabled; /// /// Gets or sets a value indicating whether to generate the gradient steps. @@ -62,28 +71,64 @@ namespace Tango.Integration.Operation int stopIndex = 1; - for (double cm = 0; cm < segment.Length; cm += (ResolutionCM / 100d)) + var colorSpace = segment.BrushStops.First().BrushColorSpace; + + //validate all brush stops in the segment are the same color space! + if (segment.BrushStops.ToList().Exists(x => x.BrushColorSpace != colorSpace)) + { + throw new ArgumentException("Cannot generate gradient using multiple color spaces on the same segment."); + } + + if (ResolutionCM > segment.Length * 100d) + { + return segment.BrushStops.ToList(); + } + + var refStop = segment.BrushStops.First().Clone(segment); + + 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, true); + if (colorSpace == ColorSpaces.RGB || colorSpace == ColorSpaces.LAB || colorSpace == ColorSpaces.CMYK) + { + var color = GetRelativeRGB(segment.BrushStops.ToList(), offset); + var output = TangoColorConverter.GetSuggestions(segment.Job, color, true); + + 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); + } + else if (colorSpace == ColorSpaces.Volume || colorSpace == ColorSpaces.Twine) + { + var cmyk = GetRelativeCMYK(segment.BrushStops.ToList(), offset); + var stop = refStop.Clone(segment); - 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++; + stop.OffsetPercent = offset * 100d; + stop.OffsetMeters = segment.Length * offset; + stop.StopIndex = stopIndex++; - TangoColorConverter.ApplyBrushStopCorrection(s, processParameters, output); + stop.SetVolume(LiquidTypes.Cyan, cmyk.C); + stop.SetVolume(LiquidTypes.Magenta, cmyk.M); + stop.SetVolume(LiquidTypes.Yellow, cmyk.Y); + stop.SetVolume(LiquidTypes.Black, cmyk.K); - stops.Add(s); + stop.SetLiquidVolumes(job.Machine.Configuration, job.Rml, processParameters); + + stops.Add(stop); + } progress?.Invoke(new PreparingJobProgressEventArgs() { @@ -93,6 +138,9 @@ namespace Tango.Integration.Operation }); } + stops.Last().OffsetPercent = 100; + stops.Last().OffsetMeters = segment.Length; + progress?.Invoke(new PreparingJobProgressEventArgs() { Job = job, @@ -103,7 +151,60 @@ namespace Tango.Integration.Operation return stops; } - private Color GetRelativeColor(List brushStopsCollection, double offset) + private CMYK GetRelativeCMYK(List brushStopsCollection, double offset) + { + BrushStop refStop = brushStopsCollection.First().Clone(); + + brushStopsCollection = brushStopsCollection.Select(x => x.Clone()).ToList(); + brushStopsCollection.ForEach(x => x.OffsetPercent = x.OffsetPercent / 100d); + + var cmykCollection = brushStopsCollection.Select(x => GetCMYK(x)).ToList(); + + var stop = cmykCollection.SingleOrDefault(f => f.OffsetPercent == offset); + if (stop != null) return stop; + + CMYK before = cmykCollection.Where(w => w.OffsetPercent == cmykCollection.Min(m => m.OffsetPercent)).First(); + CMYK after = cmykCollection.Where(w => w.OffsetPercent == cmykCollection.Max(m => m.OffsetPercent)).First(); + + foreach (var gs in cmykCollection) + { + if (gs.OffsetPercent < offset && gs.OffsetPercent > before.OffsetPercent) + { + before = gs; + } + if (gs.OffsetPercent > offset && gs.OffsetPercent < after.OffsetPercent) + { + after = gs; + } + } + + CMYK cmyk = new CMYK(); + + cmyk.C = (float)((offset - before.OffsetPercent) * (after.C - before.C) / (after.OffsetPercent - before.OffsetPercent) + before.C); + cmyk.M = (float)((offset - before.OffsetPercent) * (after.M - before.M) / (after.OffsetPercent - before.OffsetPercent) + before.M); + cmyk.Y = (float)((offset - before.OffsetPercent) * (after.Y - before.Y) / (after.OffsetPercent - before.OffsetPercent) + before.Y); + cmyk.K = (float)((offset - before.OffsetPercent) * (after.K - before.K) / (after.OffsetPercent - before.OffsetPercent) + before.K); + + //cmyk.C *= 100d; + //cmyk.M *= 100d; + //cmyk.Y *= 100d; + //cmyk.K *= 100d; + + return cmyk; + } + + private CMYK GetCMYK(BrushStop stop) + { + CMYK cmyk = new CMYK(); + cmyk.C = stop.GetVolume(LiquidTypes.Cyan); + cmyk.M = stop.GetVolume(LiquidTypes.Magenta); + cmyk.Y = stop.GetVolume(LiquidTypes.Yellow); + cmyk.K = stop.GetVolume(LiquidTypes.Black); + cmyk.OffsetPercent = stop.OffsetPercent; + return cmyk; + } + + private Color GetRelativeRGB(List brushStopsCollection, double offset) { brushStopsCollection = brushStopsCollection.Select(x => x.ShallowClone()).ToList(); brushStopsCollection.ForEach(x => x.OffsetPercent = x.OffsetPercent / 100d); diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs b/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs index 27750492e..94e20a8b4 100644 --- a/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs +++ b/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveredService.cs @@ -14,6 +14,8 @@ namespace Tango.Transport.Discovery /// public class DiscoveredService : EventArgs where DiscoveryMessage : IMessage { + private Func _validateDiscoveryAction; + /// /// Gets or sets the discovery message. /// @@ -35,11 +37,21 @@ namespace Tango.Transport.Discovery /// The address. /// The message. /// The host name. - public DiscoveredService(String address, String hostName, DiscoveryMessage message) + public DiscoveredService(String address, String hostName, DiscoveryMessage message, Func validateDiscoveryAction) { HostName = hostName; Address = address; Message = message; + _validateDiscoveryAction = validateDiscoveryAction; + } + + /// + /// Validates the service existence using a TCP request. + /// + /// + public bool ValidateServiceExistence() + { + return _validateDiscoveryAction(); } } } diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs index 9d043023b..773ba288a 100644 --- a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs +++ b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryClient.cs @@ -88,7 +88,7 @@ namespace Tango.Transport.Discovery { UdpClient udpClient = new UdpClient(Port); udpClient.Client.ReceiveTimeout = (int)Interval.TotalMilliseconds; - var endPoint = new IPEndPoint(IPAddress.Any, 0); + var endPoint = new IPEndPoint(IPAddress.Any, Port); while (IsStarted) { @@ -110,12 +110,29 @@ namespace Tango.Transport.Discovery message = (DiscoveryMessage)parser.ParseFrom(data); var host = Dns.GetHostEntry(endPoint.Address); + string address = endPoint.Address.ToString(); ServiceDiscovered?.Invoke(this, new DiscoveredService( - endPoint.Address.ToString(), + address, host != null ? host.HostName : "Unresolved", - message)); + message + , () => + { + + try + { + TcpClient client = new TcpClient(); + client.Connect(address, Port); + client.Dispose(); + return true; + } + catch + { + return false; + } + + })); } } diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs index 1fa486e68..c37ab7f51 100644 --- a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs +++ b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs @@ -7,7 +7,9 @@ using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using System.Timers; +using Tango.Core; using Tango.PMR.Discovery; +using Tango.Transport.Servers; namespace Tango.Transport.Discovery { @@ -15,9 +17,10 @@ namespace Tango.Transport.Discovery /// Represents UDP discovery service broadcasting a discovery message of type . /// /// - public class UdpDiscoveryService : IDiscoveryService where DiscoveryMessage : IMessage + public class UdpDiscoveryService : ExtendedObject, IDiscoveryService where DiscoveryMessage : IMessage { private Timer _timer; + private TcpServer _tcpValidationServer; /// /// Occurs before broadcasting the discovery message and gives a chance to modify the packet message. @@ -60,6 +63,11 @@ namespace Tango.Transport.Discovery public UdpDiscoveryService(int port) : this() { Port = port; + _tcpValidationServer = new TcpServer(Port); + _tcpValidationServer.ClientConnected += (x, e) => + { + e.Socket.Dispose(); + }; } /// @@ -79,6 +87,8 @@ namespace Tango.Transport.Discovery { if (!IsStarted) { + _tcpValidationServer.Start(); + _timer = new Timer(); _timer.Interval = Interval.TotalMilliseconds; _timer.Elapsed += _timer_Elapsed; @@ -96,6 +106,10 @@ namespace Tango.Transport.Discovery { if (IsStarted) { + _tcpValidationServer.Stop(); + + //Transmit the discovery packet one more time so clients can tell that we have disconnected. + BroadcastDiscoveryPacket(); _timer.Stop(); IsStarted = false; } @@ -108,18 +122,30 @@ namespace Tango.Transport.Discovery /// The instance containing the event data. private void _timer_Elapsed(object sender, ElapsedEventArgs e) { - UdpClient client = new UdpClient(); + BroadcastDiscoveryPacket(); + } + + private void BroadcastDiscoveryPacket() + { + try + { + UdpClient client = new UdpClient(); - IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, Port); + IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, Port); - BeforeBroadcasting?.Invoke(this, CurrentDiscoveryMessage); + BeforeBroadcasting?.Invoke(this, CurrentDiscoveryMessage); - byte[] bytes = CurrentDiscoveryMessage.ToByteArray(); + byte[] bytes = CurrentDiscoveryMessage.ToByteArray(); - client.EnableBroadcast = true; - client.Send(bytes, bytes.Length, endPoint); + client.EnableBroadcast = true; + client.Send(bytes, bytes.Length, endPoint); - client.Close(); + client.Close(); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error broadcasting discovery packet."); + } } } } diff --git a/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs b/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs index d6e2ad1d0..29cc3c7e8 100644 --- a/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs +++ b/Software/Visual_Studio/Tango.Transport/Servers/TcpServer.cs @@ -60,7 +60,7 @@ namespace Tango.Transport.Servers Listener = new TcpListener(System.Net.IPAddress.Any, Port); Listener.Start(); IsStarted = true; - LogManager.Log("Server Started!"); + LogManager.Log($"TCP started on port {Port}."); WaitForConnection(); } } @@ -73,7 +73,7 @@ namespace Tango.Transport.Servers { Listener.Stop(); IsStarted = false; - LogManager.Log("Server Stopped!"); + LogManager.Log($"TCP stopped on port {Port}."); } } @@ -110,7 +110,6 @@ namespace Tango.Transport.Servers protected virtual void OnClientConnected(TcpClient socket) { - LogManager.Log("New client connected."); ClientConnected?.Invoke(this, new ClientConnectedEventArgs(socket)); } -- cgit v1.3.1 From 46f5f70e6055234bce3e9a105ab1ba86248b1713 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 22 Apr 2019 22:46:43 +0300 Subject: Implemented Volume color space gradients. Implemented volume gradients on PPC. Improved job running aspects on PPC. --- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes .../Build/Shortcuts/Machine Studio.lnk | Bin 1581 -> 1516 bytes .../ViewModels/MainViewVM.cs | 30 +++++-- .../Views/JobView.xaml | 2 +- .../Tango.PPC.Jobs/Controls/JobSummeryViewer.xaml | 6 +- .../Tango.PPC.Jobs/ViewModels/JobProgressViewVM.cs | 2 +- .../Tango.PPC.Jobs/Views/JobProgressView.xaml | 2 +- .../PPC/Modules/Tango.PPC.Jobs/Views/JobView.xaml | 8 +- .../Visual_Studio/Tango.BL/Entities/BrushStop.cs | 80 +++++++++--------- .../DefaultGradientGenerationConfiguration.cs | 18 +++- .../Operation/IGradientGenerationConfiguration.cs | 5 ++ .../Tango.Integration/Operation/JobHandler.cs | 2 +- .../Tango.Integration/Operation/MachineOperator.cs | 92 +++++++++++++++++---- 14 files changed, 174 insertions(+), 73 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml') diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index 84785d8cf..87b59afc3 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 5e10994a1..79746966d 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index bd3a3933b..19334a605 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/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 0299940d3..4d8ec954e 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 @@ -966,9 +966,23 @@ namespace Tango.MachineStudio.Developer.ViewModels private void MachineOperator_PreparingJobProgress(object sender, PreparingJobProgressEventArgs e) { - if (_preparingTaskItem != null) + var percent = (e.Progress / e.Total * 100d); + + if (_preparingTaskItem == null && percent == 0) + { + _preparingTaskItem = _notification.PushTaskItem("Preparing job for printing..."); + } + else if (percent == 100) { - _preparingTaskItem.Message = $"Preparing job for printing {(e.Progress / e.Total * 100d).ToString("0.0")}%..."; + _preparingTaskItem.Pop(); + _preparingTaskItem = null; + } + else + { + if (_preparingTaskItem != null) + { + _preparingTaskItem.Message = $"Preparing job for printing {(e.Progress / e.Total * 100d).ToString("0.0")}%..."; + } } } @@ -1327,11 +1341,7 @@ namespace Tango.MachineStudio.Developer.ViewModels if (resumeFunc == null) { - using (var item = _notification.PushTaskItem("Preparing job for printing...")) - { - _preparingTaskItem = item; - JobHandler = await MachineOperator.Print(ActiveJob, SelectedProcessParametersTable); - } + JobHandler = await MachineOperator.Print(ActiveJob, SelectedProcessParametersTable); } else { @@ -1408,6 +1418,12 @@ namespace Tango.MachineStudio.Developer.ViewModels JobHandler.Canceled += (x, y) => { + if (_preparingTaskItem != null) + { + _preparingTaskItem.Pop(); + _preparingTaskItem = null; + } + LogManager.Log(String.Format("Job {0} has been canceled.", RunningJob.Name)); _eventLogger.Log(String.Format("Job {0} has been canceled.", RunningJob.Name)); StopRecordingIfInProgress(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml index bfa951c3b..a5d137e67 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml @@ -1220,7 +1220,7 @@ - +