From 6c975e339be02b487c76024e1bef308ef07483be Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 7 Jul 2019 12:52:48 +0300 Subject: Organized brush stop. --- .../Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer') 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 3f28c2cff..8772697b6 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 @@ -1233,8 +1233,8 @@ namespace Tango.MachineStudio.Developer.ViewModels { LogManager.Log(String.Format("BrushStop {0} Dropped on BrushStop {1}", dragged.StopIndex, dropped.StopIndex)); - dragged.SetStopIndex(dropped.StopIndex); - dropped.SetStopIndex(dropped.StopIndex + 1); + dragged.SetStopIndexNoRaise(dropped.StopIndex); + dropped.SetStopIndexNoRaise(dropped.StopIndex + 1); ArrangeBrushStopsIndices(); } @@ -1988,7 +1988,7 @@ namespace Tango.MachineStudio.Developer.ViewModels foreach (var stop in SelectedSegment.BrushStops.OrderBy(x => x.StopIndex)) { - stop.SetStopIndex(index++); + stop.SetStopIndexNoRaise(index++); } if (SelectedSegment.BrushStops.Count > 1) -- cgit v1.3.1 From 30926a8078c75c5d8c4ed39b053f072940c30d9a Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 7 Jul 2019 14:45:14 +0300 Subject: Removed Deffered delete from ObservableEntity. Added Delete for Cascade Delete. --- .../ViewModels/DbTableViewModel.cs | 3 +- .../ViewModels/MainViewVM.cs | 8 +- .../ViewModels/MainViewVM.cs | 2 +- Software/Visual_Studio/Tango.BL/Entities/Cat.cs | 18 ++ .../Tango.BL/Entities/ColorCatalog.cs | 6 +- .../Visual_Studio/Tango.BL/Entities/ColorSpace.cs | 7 + .../Tango.BL/Entities/Configuration.cs | 39 ++- .../Visual_Studio/Tango.BL/Entities/Contact.cs | 4 +- .../Tango.BL/Entities/HardwareVersion.cs | 17 +- Software/Visual_Studio/Tango.BL/Entities/Job.cs | 19 +- .../Visual_Studio/Tango.BL/Entities/Segment.cs | 358 ++++++++++++++------- .../Visual_Studio/Tango.BL/IObservableEntity.cs | 21 +- .../Visual_Studio/Tango.BL/ObservableEntity.cs | 60 +--- 13 files changed, 336 insertions(+), 226 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs index fc762d77d..e343313b4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs @@ -150,7 +150,8 @@ namespace Tango.MachineStudio.DB.ViewModels { try { - await SelectedEntity.DeleteAsync(Adapter.Context); + SelectedEntity.Detach(Adapter.Context); + await Adapter.Context.SaveChangesAsync(); } catch (Exception ex) { 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 8772697b6..3811453cb 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 @@ -2024,8 +2024,8 @@ namespace Tango.MachineStudio.Developer.ViewModels _notification.ShowInfo("A job must contain at least one segment."); return; } - ActiveJob.Segments.Remove(x); - x.DefferedDelete(_activeJobDbContext); + + x.Delete(_activeJobDbContext); }); ArrangeSegmentsIndices(); @@ -2075,8 +2075,7 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log(String.Format("Removing {0} jobs...", SelectedJobs.Count)); SelectedJobs.ToList().ForEach(x => { - SelectedMachine.Jobs.Remove(x); - x.DefferedDelete(_machineDbContext); + x.Delete(_machineDbContext); }); using (_notification.PushTaskItem("Removing selected jobs...")) @@ -2163,7 +2162,6 @@ namespace Tango.MachineStudio.Developer.ViewModels return; } SelectedSegment.BrushStops.Remove(x); - x.DefferedDelete(_activeJobDbContext); }); ArrangeBrushStopsIndices(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs index 735b1e75c..a46d5f456 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs @@ -226,7 +226,7 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels foreach (var userRole in ManagedUser.UsersRoles.Where(x => x.Role == role).ToList()) { - userRole.DefferedDelete(_userContext); + _userContext.UsersRoles.Remove(userRole); } } diff --git a/Software/Visual_Studio/Tango.BL/Entities/Cat.cs b/Software/Visual_Studio/Tango.BL/Entities/Cat.cs index 437de0de4..a3517e0fe 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/Cat.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/Cat.cs @@ -10,16 +10,29 @@ namespace Tango.BL.Entities { public partial class Cat : CatBase { + /// + /// Parses the protobuf calibration data structure from the binary CAT data. + /// + /// public CalibrationData GetCalibrationData() { return CalibrationData.Parser.ParseFrom(Data); } + /// + /// Formats and sets the CAT property. + /// + /// The data. public void PutCalibrationData(CalibrationData data) { Data = data.ToBytes(); } + /// + /// Creates the demo calibration data. + /// + /// Type of the liquid. + /// public static CalibrationData CreateDemoCalibrationData(PMR.ColorLab.LiquidType liquidType) { CalibrationData data = new CalibrationData(); @@ -37,6 +50,11 @@ namespace Tango.BL.Entities return data; } + /// + /// Creates a cloned version of this CAT and assigns it to the specified machine. + /// + /// The machine. + /// public Cat Clone(Machine machine) { var cloned = base.Clone(); diff --git a/Software/Visual_Studio/Tango.BL/Entities/ColorCatalog.cs b/Software/Visual_Studio/Tango.BL/Entities/ColorCatalog.cs index 53a0f2641..17d87ff01 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/ColorCatalog.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/ColorCatalog.cs @@ -11,7 +11,7 @@ namespace Tango.BL.Entities { private Color _color; /// - /// Gets the color. + /// Gets the catalog item RGB as color. /// public Color Color { @@ -19,6 +19,10 @@ namespace Tango.BL.Entities private set { _color = value; RaisePropertyChangedAuto(); } } + /// + /// Raises the property changed event. + /// + /// Name of the property. protected override void RaisePropertyChanged(string propName) { base.RaisePropertyChanged(propName); diff --git a/Software/Visual_Studio/Tango.BL/Entities/ColorSpace.cs b/Software/Visual_Studio/Tango.BL/Entities/ColorSpace.cs index 74024546d..7005dfba3 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/ColorSpace.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/ColorSpace.cs @@ -19,6 +19,9 @@ namespace Tango.BL.Entities } + /// + /// Gets or sets the enum version of the color space. + /// [NotMapped] [JsonIgnore] public ColorSpaces Space @@ -27,6 +30,10 @@ namespace Tango.BL.Entities set { Code = value.ToInt32(); } } + /// + /// Called when the Code has changed. + /// + /// protected override void OnCodeChanged(int code) { base.OnCodeChanged(code); diff --git a/Software/Visual_Studio/Tango.BL/Entities/Configuration.cs b/Software/Visual_Studio/Tango.BL/Entities/Configuration.cs index 15b6946f5..0ff26d450 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/Configuration.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/Configuration.cs @@ -12,6 +12,9 @@ namespace Tango.BL.Entities { public partial class Configuration : ConfigurationBase { + /// + /// Gets a collection of this configuration IDS packs where is 'true'. + /// [NotMapped] [XmlIgnore] [JsonIgnore] @@ -20,6 +23,12 @@ namespace Tango.BL.Entities get { return IdsPacks.Where(x => !x.IsEmpty); } } + /// + /// Gets a collection of this configuration IDS packs where packs are not 'empty' and are supported by the specified . + /// + /// The RML. + /// + /// The specified RML cannot be null. public IEnumerable GetSupportedIdsPacks(Rml rml) { if (rml == null) @@ -30,20 +39,10 @@ namespace Tango.BL.Entities return NoneEmptyIdsPacks.Where(x => rml.LiquidTypesRmls.ToList().Exists(y => y.LiquidType.Guid == x.LiquidType.Guid)).OrderBy(x => x.PackIndex).ToList(); } - public override void DefferedDelete(ObservablesContext context) - { - IdsPacks.ToList().ForEach(x => x.DefferedDelete(context)); - base.DefferedDelete(context); - IdsPacks.Clear(); - } - - public override void Delete(ObservablesContext context) - { - IdsPacks.ToList().ForEach(x => x.DefferedDelete(context)); - base.Delete(context); - IdsPacks.Clear(); - } - + /// + /// Clones configuration and its IDS packs (excluding the dispenser). + /// + /// public override Configuration Clone() { Configuration cloned = base.Clone(); @@ -64,6 +63,18 @@ namespace Tango.BL.Entities return cloned; } + /// + /// Removes this entity and all dependent entities from the specified db context. + /// + /// The context. + public override void Delete(ObservablesContext context) + { + base.Delete(context); + + context.IdsPacks.RemoveRange(IdsPacks); + context.Configurations.Remove(this); + } + /// /// Initializes a new instance of the class. /// diff --git a/Software/Visual_Studio/Tango.BL/Entities/Contact.cs b/Software/Visual_Studio/Tango.BL/Entities/Contact.cs index 285aefec9..50e62bc70 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/Contact.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/Contact.cs @@ -15,11 +15,11 @@ namespace Tango.BL.Entities if (propName == nameof(FirstName) || propName == nameof(LastName)) { - FixNames(); + NormalizeNames(); } } - private void FixNames() + private void NormalizeNames() { if (_firstname != null) { diff --git a/Software/Visual_Studio/Tango.BL/Entities/HardwareVersion.cs b/Software/Visual_Studio/Tango.BL/Entities/HardwareVersion.cs index 98580f244..bc48d280e 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/HardwareVersion.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/HardwareVersion.cs @@ -24,14 +24,17 @@ namespace Tango.BL.Entities public override void Delete(ObservablesContext context) { - HardwareDancers.ToList().ForEach(x => x.DefferedDelete(context)); - HardwareMotors.ToList().ForEach(x => x.DefferedDelete(context)); - HardwarePidControls.ToList().ForEach(x => x.DefferedDelete(context)); - HardwareWinders.ToList().ForEach(x => x.DefferedDelete(context)); - HardwareSpeedSensors.ToList().ForEach(x => x.DefferedDelete(context)); - HardwareBlowers.ToList().ForEach(x => x.DefferedDelete(context)); - HardwareBreakSensors.ToList().ForEach(x => x.DefferedDelete(context)); base.Delete(context); + + context.HardwareDancers.RemoveRange(HardwareDancers); + context.HardwareMotors.RemoveRange(HardwareMotors); + context.HardwarePidControls.RemoveRange(HardwarePidControls); + context.HardwareWinders.RemoveRange(HardwareWinders); + context.HardwareSpeedSensors.RemoveRange(HardwareSpeedSensors); + context.HardwareBlowers.RemoveRange(HardwareBlowers); + context.HardwareBreakSensors.RemoveRange(HardwareBreakSensors); + + context.HardwareVersions.Remove(this); } /// diff --git a/Software/Visual_Studio/Tango.BL/Entities/Job.cs b/Software/Visual_Studio/Tango.BL/Entities/Job.cs index b35681ca5..0780e6787 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/Job.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/Job.cs @@ -334,13 +334,6 @@ namespace Tango.BL.Entities return cloned; } - public override void DefferedDelete(ObservablesContext context) - { - Segments.ToList().ForEach(x => x.DefferedDelete(context)); - Segments.Clear(); - base.DefferedDelete(context); - } - #endregion #region Private Methods @@ -699,6 +692,18 @@ namespace Tango.BL.Entities }); } + /// + /// Removes this entity and all dependent entities from the specified db context. + /// + /// The context. + public override void Delete(ObservablesContext context) + { + base.Delete(context); + + Segments.ToList().ForEach(x => x.Delete(context)); + context.Jobs.Remove(this); + } + #endregion #region Validation diff --git a/Software/Visual_Studio/Tango.BL/Entities/Segment.cs b/Software/Visual_Studio/Tango.BL/Entities/Segment.cs index 64c3dc8a1..56d863299 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/Segment.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/Segment.cs @@ -9,6 +9,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; +using Tango.Core; using Tango.Core.Threading; namespace Tango.BL.Entities @@ -19,72 +20,12 @@ namespace Tango.BL.Entities private LinearGradientBrush _brush; private ActionTimer _brushStopCollectionChangedActionTimer; - public override void Save(ObservablesContext context) - { - for (int i = 0; i < BrushStops.Count; i++) - { - BrushStops[i].StopIndex = i; - } - - base.Save(context); - } - - protected override void RaisePropertyChanged(string propName) - { - base.RaisePropertyChanged(propName); - - if (propName == nameof(Length) && _lastLength != Length) - { - BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged()); - _lastLength = Length; - RaisePropertyChanged(nameof(LengthWithFactor)); - } - - if (propName == nameof(BrushStops)) - { - if (BrushStops != null) - { - BrushStops.CollectionChanged -= BrushStops_CollectionChanged; - BrushStops.CollectionChanged += BrushStops_CollectionChanged; - - foreach (var stop in BrushStops.ToList()) - { - stop.RaiseOffsetChanged(); - } - - RaiseSegmentBrushChanged(); - } - } - } - - private void BrushStops_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - if (_brushStopCollectionChangedActionTimer == null) - { - _brushStopCollectionChangedActionTimer = new ActionTimer(TimeSpan.FromMilliseconds(100)); - } - - _brushStopCollectionChangedActionTimer.ResetReplace(() => - { - foreach (var stop in BrushStops.ToList()) - { - stop.RaiseOffsetChanged(); - } - - if (BrushStops.Count > 0) - { - BrushStops.First().OffsetPercent = 0; - } - if (BrushStops.Count > 1) - { - BrushStops.Last().OffsetPercent = 100; - } - - RaiseSegmentBrushChanged(); - }); - } + #region Properties private TimeSpan _remainingTime; + /// + /// Gets or sets the remaining time for this segment to complete. + /// [NotMapped] [JsonIgnore] public TimeSpan RemainingTime @@ -94,6 +35,9 @@ namespace Tango.BL.Entities } private TimeSpan _estimatedDuration; + /// + /// Gets or sets the estimated duration for this segment to complete. + /// [NotMapped] [JsonIgnore] public TimeSpan EstimatedDuration @@ -103,6 +47,9 @@ namespace Tango.BL.Entities } private double _progress; + /// + /// Gets or sets the segment progress within a running job. + /// [NotMapped] [JsonIgnore] public double Progress @@ -112,6 +59,9 @@ namespace Tango.BL.Entities } private bool _started; + /// + /// Gets or sets a value indicating whether this segment has started. + /// [NotMapped] [JsonIgnore] public bool Started @@ -121,6 +71,9 @@ namespace Tango.BL.Entities } private bool _completed; + /// + /// Gets or sets a value indicating whether this segment has completed. + /// [NotMapped] [JsonIgnore] public bool Completed @@ -129,6 +82,9 @@ namespace Tango.BL.Entities set { _completed = value; RaisePropertyChangedAuto(); } } + /// + /// Gets the segment brush. + /// [NotMapped] [JsonIgnore] public Brush SegmentBrush @@ -140,6 +96,9 @@ namespace Tango.BL.Entities } private bool _isInterSegment; + /// + /// Gets or sets a value indicating whether this segment is an inter segment. + /// [NotMapped] [JsonIgnore] public bool IsInterSegment @@ -148,6 +107,9 @@ namespace Tango.BL.Entities set { _isInterSegment = value; RaisePropertyChangedAuto(); } } + /// + /// Gets a value indicating whether this segment has any out of gamut brush stops. + /// [NotMapped] [JsonIgnore] public bool HasOutOfGamutBrushStop @@ -155,6 +117,9 @@ namespace Tango.BL.Entities get { return BrushStops.Any(x => x.IsOutOfGamut); } } + /// + /// Gets the length of this segment including the job length factor . + /// [NotMapped] [JsonIgnore] public double LengthWithFactor @@ -162,45 +127,99 @@ namespace Tango.BL.Entities get { return Job != null && !IsInterSegment ? (Length + Length * (Job.LengthPercentageFactor / 100)) : Length; } } - internal void RaiseHasOutOfGamutBrushStop() + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + public Segment() : base() { - RaisePropertyChanged(nameof(HasOutOfGamutBrushStop)); + } - public override Segment Clone() - { - Segment cloned = base.Clone(); + #endregion - cloned.BrushStops = BrushStops.Select(x => x.Clone()).ToSynchronizedObservableCollection(); + #region Brush Stops Collection Changed - foreach (var stop in cloned.BrushStops) + private void BrushStops_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (_brushStopCollectionChangedActionTimer == null) { - stop.SegmentGuid = cloned.Guid; - stop.Segment = cloned; + _brushStopCollectionChangedActionTimer = new ActionTimer(TimeSpan.FromMilliseconds(100)); } - return cloned; + _brushStopCollectionChangedActionTimer.ResetReplace(() => + { + foreach (var stop in BrushStops.ToList()) + { + stop.RaiseOffsetChanged(); + } + + if (BrushStops.Count > 0) + { + BrushStops.First().OffsetPercent = 0; + } + if (BrushStops.Count > 1) + { + BrushStops.Last().OffsetPercent = 100; + } + + RaiseSegmentBrushChanged(); + }); } - public Segment Clone(Job job) - { - Segment cloned = base.Clone(); + #endregion - cloned.BrushStops = BrushStops.Select(x => x.Clone(cloned)).ToSynchronizedObservableCollection(); + #region Properties Changed - cloned.Job = job; - cloned.JobGuid = job.Guid; + /// + /// Called when the Length has changed. + /// + /// + protected override void OnLengthChanged(double length) + { + base.OnLengthChanged(length); - return cloned; + if (_lastLength != length) + { + BrushStops.ToList().ForEach(x => x.RaiseOffsetChanged()); + _lastLength = Length; + RaisePropertyChanged(nameof(LengthWithFactor)); + } } - public override void DefferedDelete(ObservablesContext context) + /// + /// Called when the BrushStops has changed. + /// + /// + protected override void OnBrushStopsChanged(SynchronizedObservableCollection brushstops) { - BrushStops.ToList().ForEach(x => x.DefferedDelete(context)); - BrushStops.Clear(); - base.DefferedDelete(context); + base.OnBrushStopsChanged(brushstops); + + if (brushstops != null) + { + brushstops.CollectionChanged -= BrushStops_CollectionChanged; + brushstops.CollectionChanged += BrushStops_CollectionChanged; + + foreach (var stop in brushstops.ToList()) + { + stop.RaiseOffsetChanged(); + } + + RaiseSegmentBrushChanged(); + } } + #endregion + + #region Public Methods + + /// + /// Gets the segment brush. + /// + /// public LinearGradientBrush GetSegmentBrush() { if (_brush == null || _brush.GradientStops.Count != BrushStops.Count) @@ -233,50 +252,26 @@ namespace Tango.BL.Entities } } - public System.Drawing.Brush CreateGdiBrush(int width, int height) - { - if (BrushStops.Count > 1) - { - System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.PointF(0, 0), new System.Drawing.Point(width, height), System.Drawing.Color.Black, System.Drawing.Color.Black); - - System.Drawing.Drawing2D.ColorBlend blend = new System.Drawing.Drawing2D.ColorBlend(); - - List colors = new List(); - List offsets = new List(); - - foreach (var stop in BrushStops.ToList().OrderBy(x => x.OffsetPercent)) - { - colors.Add(stop.Color.ToGdiColor()); - offsets.Add((float)stop.OffsetPercent / 100f); - } - - blend.Colors = colors.ToArray(); - blend.Positions = offsets.ToArray(); - - brush.InterpolationColors = blend; - - return brush; - } - else if (BrushStops.Count == 1) - { - return new System.Drawing.SolidBrush(BrushStops.First().Color.ToGdiColor()); - } - else - { - return System.Drawing.Brushes.Black; - } - } - + /// + /// Raises the property changed event. + /// public void RaiseSegmentBrushChanged() { RaisePropertyChanged(nameof(SegmentBrush)); } + /// + /// Raises the property changed event. + /// public void RaiseLengthWithFactorChanged() { RaisePropertyChanged(nameof(LengthWithFactor)); } + /// + /// Adds a new brush stop to this segment. + /// + /// public BrushStop AddBrushStop() { BrushStop stop = new BrushStop(); @@ -308,26 +303,39 @@ namespace Tango.BL.Entities return stop; } + /// + /// Gets the next segment. + /// + /// public Segment GetNextSegment() { return Job.OrderedSegments.FirstOrDefault(x => x.SegmentIndex > SegmentIndex); } + /// + /// Gets the previous segment. + /// + /// public Segment GetPreviousSegment() { return Job.OrderedSegments.LastOrDefault(x => x.SegmentIndex < SegmentIndex); } + /// + /// Gets the collection of previous segments. + /// + /// public List GetPreviousSegments() { return Job.OrderedSegments.Where(x => x.SegmentIndex < SegmentIndex).ToList(); } /// - /// Gets the duration estimation for this job. + /// Gets the estimated duration for this segment by the specified process parameters. /// /// The process parameters. /// + /// Process parameters dying speed cannot be zero. public TimeSpan GetEstimatedDuration(ProcessParametersTable processParameters) { if (processParameters.DyeingSpeed == 0) @@ -338,11 +346,117 @@ namespace Tango.BL.Entities } /// - /// Initializes a new instance of the class. + /// Creates a GDI version of this segment brush. /// - public Segment() : base() + /// The width. + /// The height. + /// + public System.Drawing.Brush CreateGdiBrush(int width, int height) + { + if (BrushStops.Count > 1) + { + System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new System.Drawing.PointF(0, 0), new System.Drawing.Point(width, height), System.Drawing.Color.Black, System.Drawing.Color.Black); + + System.Drawing.Drawing2D.ColorBlend blend = new System.Drawing.Drawing2D.ColorBlend(); + + List colors = new List(); + List offsets = new List(); + + foreach (var stop in BrushStops.ToList().OrderBy(x => x.OffsetPercent)) + { + colors.Add(stop.Color.ToGdiColor()); + offsets.Add((float)stop.OffsetPercent / 100f); + } + + blend.Colors = colors.ToArray(); + blend.Positions = offsets.ToArray(); + + brush.InterpolationColors = blend; + + return brush; + } + else if (BrushStops.Count == 1) + { + return new System.Drawing.SolidBrush(BrushStops.First().Color.ToGdiColor()); + } + else + { + return System.Drawing.Brushes.Black; + } + } + + #endregion + + #region Internal Methods + + /// + /// Raises the property changed event. + /// + internal void RaiseHasOutOfGamutBrushStop() + { + RaisePropertyChanged(nameof(HasOutOfGamutBrushStop)); + } + + #endregion + + #region Cloning + + /// + /// Clones this segment with its brush stops. + /// + /// + public override Segment Clone() + { + Segment cloned = base.Clone(); + + cloned.BrushStops = BrushStops.Select(x => x.Clone()).ToSynchronizedObservableCollection(); + + foreach (var stop in cloned.BrushStops) + { + stop.SegmentGuid = cloned.Guid; + stop.Segment = cloned; + } + + return cloned; + } + + /// + /// Clones this segment and assigns it to the specified job. + /// + /// The job. + /// + public Segment Clone(Job job) + { + Segment cloned = base.Clone(); + + cloned.BrushStops = BrushStops.Select(x => x.Clone(cloned)).ToSynchronizedObservableCollection(); + + cloned.Job = job; + cloned.JobGuid = job.Guid; + + return cloned; + } + + #endregion + + #region Delete + + /// + /// Removes this entity and all dependent entities from the specified db context. + /// + /// The context. + public override void Delete(ObservablesContext context) { + base.Delete(context); + if (BrushStops != null && BrushStops.Count > 0) + { + context.BrushStops.RemoveRange(BrushStops); + } + + context.Segments.Remove(this); } + + #endregion } } diff --git a/Software/Visual_Studio/Tango.BL/IObservableEntity.cs b/Software/Visual_Studio/Tango.BL/IObservableEntity.cs index 3ebd0435e..244486add 100644 --- a/Software/Visual_Studio/Tango.BL/IObservableEntity.cs +++ b/Software/Visual_Studio/Tango.BL/IObservableEntity.cs @@ -67,21 +67,6 @@ namespace Tango.BL /// Task SaveAsync(ObservablesContext context); - /// - /// Deletes this entity from the database. - /// - void Delete(ObservablesContext context); - - /// - /// Deletes this entity without saving changes to data base. - /// - void DefferedDelete(ObservablesContext context); - - /// - /// Deletes this entity from the database. - /// - Task DeleteAsync(ObservablesContext context); - /// /// Deletes this entity using an SQL statement which will cause the database delete cascade effect. /// @@ -99,5 +84,11 @@ namespace Tango.BL /// Raises the event. /// void RaiseModified(ObservablesContext context, IObservableEntity source, IObservableEntity target); + + /// + /// Removes this entity and all dependent entities from the specified db context. + /// + /// The context. + void Delete(ObservablesContext context); } } diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs index 464e8a743..982b853f9 100644 --- a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs @@ -218,57 +218,6 @@ namespace Tango.BL return context.Entry(this).ReloadAsync(); } - /// - /// Deletes this entity from the database - /// - public virtual void Delete(ObservablesContext context) - { - var delProp = this.GetType().GetProperty("Deleted"); - - if (delProp != null) - { - delProp.SetValue(this, true); - Save(context); - } - else - { - GetDbSet(context).Remove(this as T); - Save(context); - } - } - - /// - /// Deletes this entity without saving changes to data base. - /// - public virtual void DefferedDelete(ObservablesContext context) - { - try - { - GetDbSet(context).Remove(this as T); - } - catch (InvalidOperationException) - { - LogManager.Default.Log( -@"An attempt to deffer delete an entity but was not found on context. -Maybe you have deleted an entity that was no yet inserted into database?", LogCategory.Warning); - } - catch (Exception ex) - { - LogManager.Default.Log(ex); - } - } - - /// - /// Deletes this entity from the database - /// - public Task DeleteAsync(ObservablesContext context) - { - return Task.Factory.StartNew(() => - { - Delete(context); - }); - } - /// /// Gets the database set. /// @@ -381,6 +330,15 @@ Maybe you have deleted an entity that was no yet inserted into database?", LogCa return GetDbContextFromEntity(this); } + /// + /// Removes this entity and all dependent entities from the specified db context. + /// + /// The context. + public virtual void Delete(ObservablesContext context) + { + + } + #endregion #region Serialization -- cgit v1.3.1 From 081d332a0494d309c2762f76f9dc5032a673ea0d Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 7 Jul 2019 15:05:28 +0300 Subject: Removed Object extension methods from global namespace. --- .../ViewModels/MainViewVM.cs | 1 + .../ViewModels/DbTableViewModel.cs | 1 + .../ViewModels/MainViewVM.cs | 1 + .../ViewModels/MainViewVM.cs | 1 + .../Converters/LogItemToMessageConverter.cs | 1 + .../TechItems/ProcessParametersItem.cs | 1 + .../ViewModels/MachineTechViewVM.cs | 1 + .../EventLogging/DefaultEventLogger.cs | 1 + .../TFS/TeamFoundationServiceExtendedClient.cs | 1 + .../Tango.PPC.Jobs/ViewModels/JobsViewVM.cs | 1 + .../ViewModels/MainViewVM.cs | 1 + .../Connection/DefaultMachineProvider.cs | 1 + .../MachineSetup/MachineSetupManager.cs | 1 + .../MachineUpdate/MachineUpdateManager.cs | 1 + .../PPCApplication/DefaultPPCApplicationManager.cs | 1 + .../ViewModels/ExternalBridgeViewVM.cs | 1 + .../ColorConversion/TangoColorConverter.cs | 1 + Software/Visual_Studio/Tango.BL/Entities/Job.cs | 31 +- .../Visual_Studio/Tango.ColorConversion/Class1.cs | 12 + .../Properties/AssemblyInfo.cs | 9 + .../Tango.ColorConversion.csproj | 71 +++++ .../Tango.ColorConversion/packages.config | 4 + .../ExtensionMethods/ObjectExtensions.cs | 333 +++++++++++---------- .../Tango.Emulations/Emulators/MachineEmulator.cs | 1 + .../ExternalBridge/ExternalBridgeService.cs | 1 + .../DefaultGradientGenerationConfiguration.cs | 1 + .../Tango.Integration/Operation/MachineOperator.cs | 1 + .../Tango.Integration/Storage/StorageManager.cs | 1 + .../Converters/DisplayMemberPathConverter.cs | 1 + .../Tango.Touch/Controls/LightTouchDataGrid.cs | 1 + .../Tango.Touch/Controls/TouchAutoComplete.cs | 1 + .../Tango.Touch/Controls/TouchListBox.cs | 1 + .../Tango.Touch/Controls/TouchNativeListBox.cs | 1 + .../Tango.Touch/Controls/TouchNotificationBar.cs | 1 + .../Tango.UnitTesting/Pulse/Pulse_TST.cs | 1 + Software/Visual_Studio/Tango.sln | 54 +++- .../Tango.AlarmParametersGenerator/Program.cs | 1 + .../Tango.EventsTypesGenerator/Program.cs | 1 + 38 files changed, 364 insertions(+), 181 deletions(-) create mode 100644 Software/Visual_Studio/Tango.ColorConversion/Class1.cs create mode 100644 Software/Visual_Studio/Tango.ColorConversion/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Tango.ColorConversion/Tango.ColorConversion.csproj create mode 100644 Software/Visual_Studio/Tango.ColorConversion/packages.config (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs index 88882afdd..3be6bf8e2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorCapture/ViewModels/MainViewVM.cs @@ -20,6 +20,7 @@ using System.Windows.Media.Imaging; using System.Windows.Threading; using Tango.Core; using Tango.Core.Commands; +using Tango.Core.ExtensionMethods; using Tango.Core.Threading; using Tango.CSV; using Tango.Logging; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs index e343313b4..83be6c3b4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/DbTableViewModel.cs @@ -17,6 +17,7 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; using Tango.BL; using Tango.Core.DI; +using Tango.Core.ExtensionMethods; namespace Tango.MachineStudio.DB.ViewModels { 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 3811453cb..b0b6cfcb3 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 @@ -47,6 +47,7 @@ using System.Runtime.ExceptionServices; using Tango.BL.Builders; using Tango.MachineStudio.Common.Navigation; using System.Diagnostics; +using Tango.Core.ExtensionMethods; namespace Tango.MachineStudio.Developer.ViewModels { diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs index 73ba02435..6cc8289f4 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs @@ -12,6 +12,7 @@ using Tango.BL; using Tango.SharedUI.Components; using System.Runtime.CompilerServices; using Tango.MachineStudio.Common; +using Tango.Core.ExtensionMethods; namespace Tango.MachineStudio.HardwareDesigner.ViewModels { diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/LogItemToMessageConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/LogItemToMessageConverter.cs index 7136b22ea..7890d055b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/LogItemToMessageConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/Converters/LogItemToMessageConverter.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; +using Tango.Core.ExtensionMethods; using Tango.Logging; using Tango.PMR.Common; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs index 4aedf8bc7..5e6bffa82 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/ProcessParametersItem.cs @@ -9,6 +9,7 @@ using System.Xml.Serialization; using Tango.BL; using Tango.BL.Entities; using Tango.Core.Commands; +using Tango.Core.ExtensionMethods; using Tango.SharedUI.Helpers; namespace Tango.MachineStudio.Technician.TechItems diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index ab5d2ebb1..1a1832120 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -38,6 +38,7 @@ using RealTimeGraphX; using RealTimeGraphX.DataPoints; using Tango.MachineStudio.Technician.Views; using RealTimeGraphX.WPF; +using Tango.Core.ExtensionMethods; namespace Tango.MachineStudio.Technician.ViewModels { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index 79c032967..11d156292 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -17,6 +17,7 @@ using Tango.MachineStudio.Common.Diagnostics; using Tango.MachineStudio.Common.StudioApplication; using Tango.PMR.Diagnostics; using Tango.Integration.Operation; +using Tango.Core.ExtensionMethods; namespace Tango.MachineStudio.Common.EventLogging { diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs index df831afb9..fba037a6e 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/TFS/TeamFoundationServiceExtendedClient.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Windows; using Tango.BL.Entities; using Tango.Core.DI; +using Tango.Core.ExtensionMethods; using Tango.Core.Helpers; using Tango.Core.IO; using Tango.Integration.Operation; diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs index 9862a4afb..248003b30 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -35,6 +35,7 @@ using Tango.Pulse; using System.Windows.Media.Imaging; using Tango.Touch.Components; using Tango.PPC.Jobs.ViewContracts; +using Tango.Core.ExtensionMethods; namespace Tango.PPC.Jobs.ViewModels { diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs index b413fee0d..8ed512670 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/ViewModels/MainViewVM.cs @@ -13,6 +13,7 @@ using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core.Commands; using Tango.Core.DI; +using Tango.Core.ExtensionMethods; using Tango.PPC.Common; using Tango.PPC.Common.Connection; using Tango.PPC.Common.ExternalBridge; 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 04f64bd9c..7b3d85b75 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Connection/DefaultMachineProvider.cs @@ -20,6 +20,7 @@ using Tango.Transport.Transporters; using Tango.Integration; using Tango.Transport; using System.Threading; +using Tango.Core.ExtensionMethods; namespace Tango.PPC.Common.Connection { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs index 39ff7e54d..05cf15a38 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineSetup/MachineSetupManager.cs @@ -13,6 +13,7 @@ using System.Threading; using System.Threading.Tasks; using Tango.Core; using Tango.Core.DB; +using Tango.Core.ExtensionMethods; using Tango.Core.Helpers; using Tango.Core.IO; using Tango.Integration.Operation; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs index 31b2f5534..64123acca 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/MachineUpdate/MachineUpdateManager.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using Tango.Core; using Tango.Core.DB; +using Tango.Core.ExtensionMethods; using Tango.Core.Helpers; using Tango.Core.IO; using Tango.Integration.Operation; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs index 7aeb6760e..d4adc30a0 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/PPCApplication/DefaultPPCApplicationManager.cs @@ -31,6 +31,7 @@ using Tango.PPC.Common.WatchDog; using Tango.PPC.UI.Dialogs; using Tango.Core.Threading; using Tango.PPC.Common.Messages; +using Tango.Core.ExtensionMethods; namespace Tango.PPC.UI.PPCApplication { diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs index 80a95d1bf..f1127ebfe 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/ExternalBridgeViewVM.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.Core.DI; +using Tango.Core.ExtensionMethods; using Tango.Integration.ExternalBridge; using Tango.PMR.Integration; using Tango.PPC.Common; diff --git a/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs b/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs index d5ec5ab15..e6a305677 100644 --- a/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs +++ b/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Windows.Media; using Tango.BL.Entities; using Tango.BL.Enumerations; +using Tango.Core.ExtensionMethods; using Tango.Logging; using Tango.PMR; using Tango.PMR.ColorLab; diff --git a/Software/Visual_Studio/Tango.BL/Entities/Job.cs b/Software/Visual_Studio/Tango.BL/Entities/Job.cs index 0780e6787..6e6ffcf48 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/Job.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/Job.cs @@ -13,6 +13,7 @@ using System.Windows.Media.Imaging; using Tango.BL.Builders; using Tango.BL.Enumerations; using Tango.Core; +using Tango.Core.ExtensionMethods; using Tango.Logging; using Tango.PMR.Exports; @@ -22,14 +23,26 @@ namespace Tango.BL.Entities { private double _lastLength; + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + public Job() : base() + { + + } + /// /// Initializes a new instance of the class. /// - public Job(DateTime creationDate) + public Job(DateTime creationDate) : this() { CreationDate = creationDate; } + #endregion + #region Events /// @@ -183,6 +196,9 @@ namespace Tango.BL.Entities } private JobDesignations _designation; + /// + /// Gets or sets the designation. + /// [NotMapped] [JsonIgnore] public JobDesignations Designation @@ -191,6 +207,9 @@ namespace Tango.BL.Entities set { _designation = value; RaisePropertyChangedAuto(); } } + /// + /// Gets or sets the state of the job editing. + /// [NotMapped] [JsonIgnore] public EditingStates JobEditingState @@ -478,7 +497,7 @@ namespace Tango.BL.Entities /// public Task GetEstimatedDuration() { - return Task.Factory.StartNew(() => + return Task.Factory.StartNew(() => { var process = GetRecommendedProcessParameters().Result; return GetEstimatedDuration(process); @@ -719,13 +738,5 @@ namespace Tango.BL.Entities } #endregion - - /// - /// Initializes a new instance of the class. - /// - public Job() : base() - { - - } } } diff --git a/Software/Visual_Studio/Tango.ColorConversion/Class1.cs b/Software/Visual_Studio/Tango.ColorConversion/Class1.cs new file mode 100644 index 000000000..b420411b6 --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorConversion/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.ColorConversion +{ + public class Class1 + { + } +} diff --git a/Software/Visual_Studio/Tango.ColorConversion/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Tango.ColorConversion/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..f5e12a622 --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorConversion/Properties/AssemblyInfo.cs @@ -0,0 +1,9 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +[assembly: AssemblyTitle("Tango - Color Conversion Library")] +[assembly: AssemblyVersion("2.0.17.1657")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.ColorConversion/Tango.ColorConversion.csproj b/Software/Visual_Studio/Tango.ColorConversion/Tango.ColorConversion.csproj new file mode 100644 index 000000000..2846ca99a --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorConversion/Tango.ColorConversion.csproj @@ -0,0 +1,71 @@ + + + + + Debug + AnyCPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7} + Library + Properties + Tango.ColorConversion + Tango.ColorConversion + v4.6.1 + 512 + true + + + true + full + false + ..\Build\Core\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + ..\Build\Core\Release\ + TRACE + prompt + 4 + + + + ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + + + + + + + + + + + + + GlobalVersionInfo.cs + + + + + + + + + + {f441feee-322a-4943-b566-110e12fd3b72} + Tango.BL + + + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} + Tango.Core + + + {e4927038-348d-4295-aaf4-861c58cb3943} + Tango.PMR + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.ColorConversion/packages.config b/Software/Visual_Studio/Tango.ColorConversion/packages.config new file mode 100644 index 000000000..fa3c0d58d --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorConversion/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs index ce907b57b..b5e430829 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ObjectExtensions.cs @@ -10,226 +10,229 @@ using System.Threading.Tasks; using Tango.Core.Json; using Tango.Serialization; -/// -/// Contains extension methods. -/// -public static class ObjectExtensions +namespace Tango.Core.ExtensionMethods { - private static bool _jsonSettingsSet; - /// - /// Performs shallow cloning of the object excluding generic properties.. + /// Contains extension methods. /// - /// - /// The object. - /// - public static T ShallowClone(this T obj) + public static class ObjectExtensions { - var cloned = Activator.CreateInstance(); - - foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.SetMethod != null)) + private static bool _jsonSettingsSet; + + /// + /// Performs shallow cloning of the object excluding generic properties.. + /// + /// + /// The object. + /// + public static T ShallowClone(this T obj) { - if (!prop.PropertyType.IsGenericType) + var cloned = Activator.CreateInstance(); + + foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.SetMethod != null)) { - prop.SetValue(cloned, prop.GetValue(obj)); + if (!prop.PropertyType.IsGenericType) + { + prop.SetValue(cloned, prop.GetValue(obj)); + } } - } - return cloned; - } + return cloned; + } - /// - /// Performs a shallow mapping to the specified object excluding generic properties. - /// - /// - /// The source. - /// The destination object. - public static void ShallowCopyTo(this T source, T destination) - { - foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.SetMethod != null)) + /// + /// Performs a shallow mapping to the specified object excluding generic properties. + /// + /// + /// The source. + /// The destination object. + public static void ShallowCopyTo(this T source, T destination) { - if (!prop.PropertyType.IsGenericType) + foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.SetMethod != null)) { - prop.SetValue(destination, prop.GetValue(source)); + if (!prop.PropertyType.IsGenericType) + { + prop.SetValue(destination, prop.GetValue(source)); + } } } - } - /// - /// Maps the object properties values to the destination object. - /// - /// The source. - /// The destination. - public static void MapPrimitivesTo(this object source, object destination) - { - foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive)) + /// + /// Maps the object properties values to the destination object. + /// + /// The source. + /// The destination. + public static void MapPrimitivesTo(this object source, object destination) { - var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); - - if (desProp != null && desProp.PropertyType.IsPrimitive && desProp.SetMethod != null) + foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive)) { - desProp.SetValue(destination, prop.GetValue(source)); + var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); + + if (desProp != null && desProp.PropertyType.IsPrimitive && desProp.SetMethod != null) + { + desProp.SetValue(destination, prop.GetValue(source)); + } } } - } - /// - /// Maps the object properties values to the destination object including strings and without assigning null string values from the source. - /// - /// The source. - /// The destination. - public static void MapPrimitivesWithStringsNoNullsTo(this object source, object destination) - { - foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive || x.PropertyType == typeof(String))) + /// + /// Maps the object properties values to the destination object including strings and without assigning null string values from the source. + /// + /// The source. + /// The destination. + public static void MapPrimitivesWithStringsNoNullsTo(this object source, object destination) { - var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); - - if (desProp != null && (desProp.PropertyType.IsPrimitive || desProp.PropertyType == typeof(String)) && desProp.SetMethod != null) + foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive || x.PropertyType == typeof(String))) { - var value = prop.GetValue(source); + var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); - if (desProp.PropertyType != typeof(String) || !String.IsNullOrEmpty(value as String)) + if (desProp != null && (desProp.PropertyType.IsPrimitive || desProp.PropertyType == typeof(String)) && desProp.SetMethod != null) { - desProp.SetValue(destination, value); + var value = prop.GetValue(source); + + if (desProp.PropertyType != typeof(String) || !String.IsNullOrEmpty(value as String)) + { + desProp.SetValue(destination, value); + } } } } - } - /// - /// Maps the object properties values to the destination object including strings and without assigning null string values from the source. - /// - /// The source. - /// The destination. - public static void MapPrimitivesWithStrings(this object source, object destination) - { - foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive || x.PropertyType == typeof(String))) + /// + /// Maps the object properties values to the destination object including strings and without assigning null string values from the source. + /// + /// The source. + /// The destination. + public static void MapPrimitivesWithStrings(this object source, object destination) { - var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); - - if (desProp != null && (desProp.PropertyType.IsPrimitive || desProp.PropertyType == typeof(String)) && desProp.SetMethod != null) + foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive || x.PropertyType == typeof(String))) { - var value = prop.GetValue(source); + var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); + + if (desProp != null && (desProp.PropertyType.IsPrimitive || desProp.PropertyType == typeof(String)) && desProp.SetMethod != null) + { + var value = prop.GetValue(source); - desProp.SetValue(destination, value); + desProp.SetValue(destination, value); + } } } - } - /// - /// Maps the object properties values to the destination object. - /// - /// The source. - /// The destination. - public static void MapPrimitivesTo(this object source, object destination, Func condition) - { - foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive)) + /// + /// Maps the object properties values to the destination object. + /// + /// The source. + /// The destination. + public static void MapPrimitivesTo(this object source, object destination, Func condition) { - var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); - - if (desProp != null && desProp.PropertyType.IsPrimitive && desProp.SetMethod != null) + foreach (var prop in source.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.PropertyType.IsPrimitive)) { - if (condition(prop)) + var desProp = destination.GetType().GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance); + + if (desProp != null && desProp.PropertyType.IsPrimitive && desProp.SetMethod != null) { - desProp.SetValue(destination, prop.GetValue(source)); + if (condition(prop)) + { + desProp.SetValue(destination, prop.GetValue(source)); + } } } } - } - - /// - /// Serializes the specified object to indented json string. - /// - /// The object. - /// - public static String ToJsonString(this Object obj) - { - if (obj == null) return "null"; - if (!_jsonSettingsSet) + /// + /// Serializes the specified object to indented json string. + /// + /// The object. + /// + public static String ToJsonString(this Object obj) { - JsonConvert.DefaultSettings = (() => - { - var settings = new JsonSerializerSettings(); - settings.Converters.Add(new StringEnumConverter { CamelCaseText = false }); - settings.ContractResolver = new ProtobufContractResolver(); - return settings; - }); - - _jsonSettingsSet = true; - } + if (obj == null) return "null"; - return JsonConvert.SerializeObject(obj, Formatting.Indented); - } + if (!_jsonSettingsSet) + { + JsonConvert.DefaultSettings = (() => + { + var settings = new JsonSerializerSettings(); + settings.Converters.Add(new StringEnumConverter { CamelCaseText = false }); + settings.ContractResolver = new ProtobufContractResolver(); + return settings; + }); - /// - /// Serializes the specified object to indented json string. - /// - /// The object. - /// - public static String ToJsonString(this Object obj, params String[] ignoreProperties) - { - var settings = new JsonSerializerSettings() { ContractResolver = new DynamicContractResolver(ignoreProperties) }; - settings.Converters.Add(new StringEnumConverter { CamelCaseText = false }); - return JsonConvert.SerializeObject(obj, Formatting.Indented, settings); - } + _jsonSettingsSet = true; + } - /// - /// Serializes the specified object to indented json html string. - /// - /// The object. - /// - public static String ToHtmlJsonString(this Object obj, params String[] ignoreProperties) - { - var settings = new JsonSerializerSettings() { ContractResolver = new HtmlContractResolver(ignoreProperties) }; - settings.Converters.Add(new StringEnumConverter { CamelCaseText = false }); - return JsonConvert.SerializeObject(obj, Formatting.Indented, settings); - } + return JsonConvert.SerializeObject(obj, Formatting.Indented); + } - /// - /// Gets the property value by the specified path (e.g DateTime.Date.Days). - /// - /// The object. - /// The property path. - /// - public static Object GetPropertyValueByPath(this object obj, String propertyPath) - { - if (propertyPath != null) + /// + /// Serializes the specified object to indented json string. + /// + /// The object. + /// + public static String ToJsonString(this Object obj, params String[] ignoreProperties) { - if (propertyPath.Contains('.')) - { - string[] Split = propertyPath.Split('.'); - string RemainingProperty = propertyPath.Substring(propertyPath.IndexOf('.') + 1); - return GetPropertyValueByPath(obj.GetType().GetProperty(Split[0]).GetValue(obj, null), RemainingProperty); - } - else - return obj.GetType().GetProperty(propertyPath).GetValue(obj, null); + var settings = new JsonSerializerSettings() { ContractResolver = new DynamicContractResolver(ignoreProperties) }; + settings.Converters.Add(new StringEnumConverter { CamelCaseText = false }); + return JsonConvert.SerializeObject(obj, Formatting.Indented, settings); } - else + + /// + /// Serializes the specified object to indented json html string. + /// + /// The object. + /// + public static String ToHtmlJsonString(this Object obj, params String[] ignoreProperties) { - return obj.ToString(); + var settings = new JsonSerializerSettings() { ContractResolver = new HtmlContractResolver(ignoreProperties) }; + settings.Converters.Add(new StringEnumConverter { CamelCaseText = false }); + return JsonConvert.SerializeObject(obj, Formatting.Indented, settings); } - } - /// - /// Sets the property value by the specified path (e.g DateTime.Date.Days). - /// - /// The object. - /// The property path. - /// - public static void SetPropertyValueByPath(this object obj, String propertyPath, object value) - { - if (propertyPath != null) + /// + /// Gets the property value by the specified path (e.g DateTime.Date.Days). + /// + /// The object. + /// The property path. + /// + public static Object GetPropertyValueByPath(this object obj, String propertyPath) { - if (propertyPath.Contains('.')) + if (propertyPath != null) { - string[] Split = propertyPath.Split('.'); - string RemainingProperty = propertyPath.Substring(propertyPath.IndexOf('.') + 1); - SetPropertyValueByPath(obj.GetType().GetProperty(Split[0]).GetValue(obj, null), RemainingProperty, value); + if (propertyPath.Contains('.')) + { + string[] Split = propertyPath.Split('.'); + string RemainingProperty = propertyPath.Substring(propertyPath.IndexOf('.') + 1); + return GetPropertyValueByPath(obj.GetType().GetProperty(Split[0]).GetValue(obj, null), RemainingProperty); + } + else + return obj.GetType().GetProperty(propertyPath).GetValue(obj, null); } else { - obj.GetType().GetProperty(propertyPath).SetValue(obj, value); + return obj.ToString(); + } + } + + /// + /// Sets the property value by the specified path (e.g DateTime.Date.Days). + /// + /// The object. + /// The property path. + /// + public static void SetPropertyValueByPath(this object obj, String propertyPath, object value) + { + if (propertyPath != null) + { + if (propertyPath.Contains('.')) + { + string[] Split = propertyPath.Split('.'); + string RemainingProperty = propertyPath.Substring(propertyPath.IndexOf('.') + 1); + SetPropertyValueByPath(obj.GetType().GetProperty(Split[0]).GetValue(obj, null), RemainingProperty, value); + } + else + { + obj.GetType().GetProperty(propertyPath).SetValue(obj, value); + } } } } diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index 401123106..61cca98ce 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -30,6 +30,7 @@ using System.IO; using Tango.Integration.Operation; using Tango.PMR.FirmwareUpgrade; using System.Diagnostics; +using Tango.Core.ExtensionMethods; namespace Tango.Emulations.Emulators { diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs index 16a143bbc..410afd7fe 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs @@ -19,6 +19,7 @@ using Tango.PMR.Diagnostics; using Tango.PMR.Debugging; using System.Security.Authentication; using Tango.Settings; +using Tango.Core.ExtensionMethods; namespace Tango.Integration.ExternalBridge { diff --git a/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs index c4a8518ee..59c6441d3 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs @@ -8,6 +8,7 @@ using Tango.BL.ColorConversion; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core; +using Tango.Core.ExtensionMethods; namespace Tango.Integration.Operation { diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 5b6b9b3a6..766448bcc 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -35,6 +35,7 @@ using Tango.Integration.Logging; using Tango.Integration.JobRuns; using Tango.FirmwareUpdateLib.WPF; using Tango.FirmwareUpdateLib; +using Tango.Core.ExtensionMethods; namespace Tango.Integration.Operation { diff --git a/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs b/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs index 623e331d0..7db7433fa 100644 --- a/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs +++ b/Software/Visual_Studio/Tango.Integration/Storage/StorageManager.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core; using Tango.Core.Commands; +using Tango.Core.ExtensionMethods; using Tango.Core.Threading; using Tango.Logging; using Tango.PMR.IO; diff --git a/Software/Visual_Studio/Tango.SharedUI/Converters/DisplayMemberPathConverter.cs b/Software/Visual_Studio/Tango.SharedUI/Converters/DisplayMemberPathConverter.cs index 6e0a75df5..f195afc9c 100644 --- a/Software/Visual_Studio/Tango.SharedUI/Converters/DisplayMemberPathConverter.cs +++ b/Software/Visual_Studio/Tango.SharedUI/Converters/DisplayMemberPathConverter.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; +using Tango.Core.ExtensionMethods; namespace Tango.SharedUI.Converters { diff --git a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs index 60ef8a49e..79e6739af 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/LightTouchDataGrid.cs @@ -17,6 +17,7 @@ using System.Windows.Media; using System.Windows.Media.Animation; using Tango.Core.Commands; using Tango.Core.EventArguments; +using Tango.Core.ExtensionMethods; using Tango.DragAndDrop; using Tango.SharedUI.Helpers; using Tango.Touch.Components; diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchAutoComplete.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchAutoComplete.cs index 4e1ced33b..986cc55f4 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchAutoComplete.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchAutoComplete.cs @@ -16,6 +16,7 @@ using System.Windows.Navigation; using System.Windows.Shapes; using Tango.Core.Commands; using Tango.Core.EventArguments; +using Tango.Core.ExtensionMethods; namespace Tango.Touch.Controls { diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs index 57afcb943..87e7717be 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchListBox.cs @@ -17,6 +17,7 @@ using System.Windows.Navigation; using System.Windows.Shapes; using Tango.Core.Commands; using Tango.Core.EventArguments; +using Tango.Core.ExtensionMethods; namespace Tango.Touch.Controls { diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNativeListBox.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchNativeListBox.cs index aab20778e..f05e98ccc 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchNativeListBox.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNativeListBox.cs @@ -12,6 +12,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.Core.ExtensionMethods; namespace Tango.Touch.Controls { diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs index 0f7468011..9f18ec8d4 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNotificationBar.cs @@ -20,6 +20,7 @@ using System.Windows.Shapes; using System.Windows.Threading; using Tango.Core.Commands; using Tango.Core.EventArguments; +using Tango.Core.ExtensionMethods; namespace Tango.Touch.Controls { diff --git a/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs index c20994198..b643e71ec 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/Pulse/Pulse_TST.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.ExtensionMethods; using Tango.Core.IO; using Tango.Pulse; diff --git a/Software/Visual_Studio/Tango.sln b/Software/Visual_Studio/Tango.sln index 163bff4f1..db1cf4634 100644 --- a/Software/Visual_Studio/Tango.sln +++ b/Software/Visual_Studio/Tango.sln @@ -297,6 +297,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.CoatsCatalogImporter" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.AlarmParametersGenerator", "Utilities\Tango.AlarmParametersGenerator\Tango.AlarmParametersGenerator.csproj", "{CC6D5193-434D-410F-B0F3-BE2017D86FCE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tango.ColorConversion", "Tango.ColorConversion\Tango.ColorConversion.csproj", "{B4FE6485-4161-4B36-BC08-67E0B53D01B7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution AppVeyor|Any CPU = AppVeyor|Any CPU @@ -5285,6 +5287,46 @@ Global {CC6D5193-434D-410F-B0F3-BE2017D86FCE}.Release|x64.Build.0 = Release|Any CPU {CC6D5193-434D-410F-B0F3-BE2017D86FCE}.Release|x86.ActiveCfg = Release|Any CPU {CC6D5193-434D-410F-B0F3-BE2017D86FCE}.Release|x86.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|Any CPU.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|Any CPU.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|ARM.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|ARM.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|ARM64.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|ARM64.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|x64.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|x64.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|x86.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.AppVeyor|x86.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|ARM.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|ARM.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|ARM64.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|x64.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|x64.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|x86.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Debug|x86.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|Any CPU.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|Any CPU.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|ARM.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|ARM.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|ARM64.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|ARM64.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|x64.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|x64.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|x86.ActiveCfg = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.DefaultBuild|x86.Build.0 = Debug|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|Any CPU.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|ARM.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|ARM.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|ARM64.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|ARM64.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|x64.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|x64.Build.0 = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|x86.ActiveCfg = Release|Any CPU + {B4FE6485-4161-4B36-BC08-67E0B53D01B7}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -5382,12 +5424,12 @@ Global {CC6D5193-434D-410F-B0F3-BE2017D86FCE} = {5F6BBAA8-EAD0-4B18-97E5-55B4F56DD760} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - BuildVersion_UseGlobalSettings = False - BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs - BuildVersion_StartDate = 2000/1/1 - BuildVersion_UpdateFileVersion = False - BuildVersion_UpdateAssemblyVersion = True - BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear SolutionGuid = {7986F7F4-A86A-4994-B1B6-0988D7F057B6} + BuildVersion_BuildVersioningStyle = None.None.Increment.DeltaBaseYearDayOfYear + BuildVersion_UpdateAssemblyVersion = True + BuildVersion_UpdateFileVersion = False + BuildVersion_StartDate = 2000/1/1 + BuildVersion_AssemblyInfoFilename = Properties\AssemblyInfo.cs + BuildVersion_UseGlobalSettings = False EndGlobalSection EndGlobal diff --git a/Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs b/Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs index 04d6acb5b..ac31cfb9c 100644 --- a/Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs +++ b/Software/Visual_Studio/Utilities/Tango.AlarmParametersGenerator/Program.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.ExtensionMethods; using Tango.Core.Helpers; using Tango.Documents; using Tango.PMR.Debugging; diff --git a/Software/Visual_Studio/Utilities/Tango.EventsTypesGenerator/Program.cs b/Software/Visual_Studio/Utilities/Tango.EventsTypesGenerator/Program.cs index 6797ac085..20b27d7d5 100644 --- a/Software/Visual_Studio/Utilities/Tango.EventsTypesGenerator/Program.cs +++ b/Software/Visual_Studio/Utilities/Tango.EventsTypesGenerator/Program.cs @@ -10,6 +10,7 @@ using Tango.Core.Helpers; using Tango.Documents; using System.Data.Entity; using System.Collections.ObjectModel; +using Tango.Core.ExtensionMethods; namespace Tango.EventsTypesGenerator { -- cgit v1.3.1 From 077dec37b376400f1705a42355e7396669d00b65 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 7 Jul 2019 17:31:09 +0300 Subject: New ColorConversion project. --- .../Tango.MachineStudio.ColorLab.csproj | 6 +- .../ViewModels/MainViewVM.cs | 12 +- .../Views/MainView.xaml | 2 +- .../Tango.MachineStudio.Developer.csproj | 6 +- .../ViewModels/MainViewVM.cs | 13 +- .../Views/JobView.xaml | 6 +- .../Views/JobView.xaml.cs | 5 + .../Dialogs/AdvancedColorCorrectionViewVM.cs | 1 - .../Dialogs/BasicColorCorrectionViewVM.cs | 2 +- .../Dialogs/FineTuningPaletteViewVM.cs | 9 +- .../Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj | 6 +- .../Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs | 14 +- .../Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | 17 +- .../PPC/Tango.PPC.Common/Models/FineTuneItem.cs | 6 +- .../PPC/Tango.PPC.Common/Tango.PPC.Common.csproj | 6 +- .../PPC/Tango.PPC.UI/Tango.PPC.UI.csproj | 6 +- .../ColorConversion/ColorConversionSuggestion.cs | 55 --- .../ColorConversion/TangoColorConverter.cs | 425 --------------------- .../Visual_Studio/Tango.BL/Entities/BrushStop.cs | 1 - Software/Visual_Studio/Tango.BL/Entities/Job.cs | 68 ++-- .../ColorConversionSuggestionExtensions.cs | 27 -- Software/Visual_Studio/Tango.BL/Tango.BL.csproj | 3 - .../Visual_Studio/Tango.BL/Utils/BrushStopUtils.cs | 89 +++-- .../Visual_Studio/Tango.ColorConversion/Class1.cs | 12 - .../ColorConversionSuggestion.cs | 55 +++ .../Tango.ColorConversion/DefaultColorConverter.cs | 259 +++++++++++++ .../ColorConversionSuggestionExtensions.cs | 27 ++ .../ExtensionMethods/ConversionOutputExtensions.cs | 86 +++++ .../Tango.ColorConversion/IColorConverter.cs | 24 ++ .../Tango.ColorConversion.csproj | 11 +- .../DefaultGradientGenerationConfiguration.cs | 8 +- .../Tango.Integration/Operation/MachineOperator.cs | 13 +- .../Tango.Integration/Tango.Integration.csproj | 6 +- 33 files changed, 634 insertions(+), 652 deletions(-) delete mode 100644 Software/Visual_Studio/Tango.BL/ColorConversion/ColorConversionSuggestion.cs delete mode 100644 Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs delete mode 100644 Software/Visual_Studio/Tango.BL/ExtensionMethods/ColorConversionSuggestionExtensions.cs delete mode 100644 Software/Visual_Studio/Tango.ColorConversion/Class1.cs create mode 100644 Software/Visual_Studio/Tango.ColorConversion/ColorConversionSuggestion.cs create mode 100644 Software/Visual_Studio/Tango.ColorConversion/DefaultColorConverter.cs create mode 100644 Software/Visual_Studio/Tango.ColorConversion/ExtensionMethods/ColorConversionSuggestionExtensions.cs create mode 100644 Software/Visual_Studio/Tango.ColorConversion/ExtensionMethods/ConversionOutputExtensions.cs create mode 100644 Software/Visual_Studio/Tango.ColorConversion/IColorConverter.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj index b1e6c05da..367657cdc 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Tango.MachineStudio.ColorLab.csproj @@ -128,6 +128,10 @@ {40085232-aced-4cbe-945b-90ba8153c151} Tango.BrushPicker + + {b4fe6485-4161-4b36-bc08-67e0b53d01b7} + Tango.ColorConversion + {a2f5af44-29ff-45d6-9d25-ecda5cce88b5} Tango.ColorPicker @@ -192,7 +196,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index f01637b5b..c33ef1f86 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -12,9 +12,9 @@ using System.Threading.Tasks; using System.Windows.Media; using Tango.BL; using Tango.BL.Builders; -using Tango.BL.ColorConversion; using Tango.BL.Entities; using Tango.BL.Enumerations; +using Tango.ColorConversion; using Tango.Core.Commands; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Controls; @@ -402,11 +402,13 @@ namespace Tango.MachineStudio.ColorLab.ViewModels }); } - var output = TangoColorConverter.GetSuggestions(input); + IColorConverter converter = new DefaultColorConverter(); + + var output = converter.Convert(input); IsOutOfGamut = output.OutOfGamut; - HiveSuggestions = TangoColorConverter.CreateHiveSuggestions(output); + HiveSuggestions = output.CreateHiveSuggestions(); } catch (Exception ex) { @@ -604,7 +606,9 @@ namespace Tango.MachineStudio.ColorLab.ViewModels }); } - var output = TangoColorConverter.GetSuggestions(input); + IColorConverter converter = new DefaultColorConverter(); + + var output = converter.Convert(input); TargetColor = new RgbVM() { diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml index b8c786b51..fe4edcb8b 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/Views/MainView.xaml @@ -6,7 +6,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:shapes="clr-namespace:Tango.SharedUI.Shapes;assembly=Tango.SharedUI" xmlns:observables="clr-namespace:Tango.BL.Entities;assembly=Tango.BL" - xmlns:colorConversion="clr-namespace:Tango.BL.ColorConversion;assembly=Tango.BL" + xmlns:colorConversion="clr-namespace:Tango.ColorConversion;assembly=Tango.ColorConversion" xmlns:hive="clr-namespace:Tango.Hive;assembly=Tango.Hive" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index cd00557b1..6e55b6d14 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -208,6 +208,10 @@ {40085232-aced-4cbe-945b-90ba8153c151} Tango.BrushPicker + + {b4fe6485-4161-4b36-bc08-67e0b53d01b7} + Tango.ColorConversion + {a2f5af44-29ff-45d6-9d25-ecda5cce88b5} Tango.ColorPicker @@ -357,7 +361,7 @@ - + \ No newline at end of file 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 b0b6cfcb3..a865cdc8f 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 @@ -38,7 +38,6 @@ using System.Threading; using Tango.SharedUI.Helpers; using Tango.Core.DI; using Tango.MachineStudio.Common; -using Tango.BL.ColorConversion; using Tango.MachineStudio.Logging.ViewModels; using Tango.MachineStudio.Logging.Views; using Tango.AutoComplete.Editors; @@ -48,6 +47,7 @@ using Tango.BL.Builders; using Tango.MachineStudio.Common.Navigation; using System.Diagnostics; using Tango.Core.ExtensionMethods; +using Tango.ColorConversion; namespace Tango.MachineStudio.Developer.ViewModels { @@ -81,6 +81,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private bool _disable_gamut_check; private bool _rml_has_no_cct; private TaskItem _preparingTaskItem; + private IColorConverter _converter; #region Properties @@ -714,6 +715,8 @@ namespace Tango.MachineStudio.Developer.ViewModels /// The notification provider. public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IVideoCaptureProvider videoCaptureProvider, DeveloperNavigationManager navigation, INavigationManager navigationManager, IAuthenticationProvider authentication, IEventLogger eventLogger, ISpeechProvider speech) { + _converter = new DefaultColorConverter(); + CanWork = true; EnableColorConversion = true; @@ -836,7 +839,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { try { - var output = TangoColorConverter.GetSuggestions(stop); + var output = _converter.Convert(stop); stop.Red = output.SingleCoordinates.Red; stop.Green = output.SingleCoordinates.Green; @@ -850,7 +853,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { try { - stop.IsOutOfGamut = TangoColorConverter.IsOutOfGamut(stop); + stop.IsOutOfGamut = _converter.IsOutOfGamut(stop); stop.OutOfGamutChecked = true; } catch { } @@ -871,7 +874,7 @@ namespace Tango.MachineStudio.Developer.ViewModels _hiveOpened = true; try { - HiveSuggestions = TangoColorConverter.CreateHiveSuggestions(TangoColorConverter.GetSuggestions(SelectedBrushStop)); + HiveSuggestions = _converter.Convert(SelectedBrushStop).CreateHiveSuggestions(); } catch (Exception ex) { @@ -912,7 +915,7 @@ namespace Tango.MachineStudio.Developer.ViewModels if (!_color_changed_from_hive && _hiveOpened) { SelectedBrushStop.Corrected = false; - HiveSuggestions = TangoColorConverter.CreateHiveSuggestions(TangoColorConverter.GetSuggestions(SelectedBrushStop)); + HiveSuggestions = _converter.Convert(SelectedBrushStop).CreateHiveSuggestions(); } } 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 95f88d1ea..ad1648642 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 @@ -7,7 +7,7 @@ xmlns:dragAndDrop="clr-namespace:Tango.DragAndDrop;assembly=Tango.DragAndDrop" xmlns:brushPicker="clr-namespace:Tango.BrushPicker;assembly=Tango.BrushPicker" xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls" - xmlns:colorConversion="clr-namespace:Tango.BL.ColorConversion;assembly=Tango.BL" + xmlns:colorConversion="clr-namespace:Tango.ColorConversion;assembly=Tango.ColorConversion" xmlns:hive="clr-namespace:Tango.Hive;assembly=Tango.Hive" xmlns:automation="clr-namespace:Tango.MachineStudio.Common.Automation;assembly=Tango.MachineStudio.Common" xmlns:sys="clr-namespace:System;assembly=mscorlib" @@ -901,10 +901,10 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs index f3af53352..18dc795bd 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/JobView.xaml.cs @@ -312,5 +312,10 @@ namespace Tango.MachineStudio.Developer.Views _vm.OnBrushStopFieldValueChanged(stop); } } + + private void OnBrushStopMouseDown(object sender, MouseButtonEventArgs e) + { + listStops.SelectedItem = (sender as ListBoxItem).DataContext; + } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/AdvancedColorCorrectionViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/AdvancedColorCorrectionViewVM.cs index d9b9a438a..887e62dd7 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/AdvancedColorCorrectionViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/AdvancedColorCorrectionViewVM.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Tango.BL.ColorConversion; using Tango.PMR.ColorLab; using Tango.SharedUI; diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/BasicColorCorrectionViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/BasicColorCorrectionViewVM.cs index 3cfedd3f0..a6ffb57c3 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/BasicColorCorrectionViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/BasicColorCorrectionViewVM.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Tango.BL.ColorConversion; using Tango.BL.Entities; +using Tango.ColorConversion; using Tango.Core.Commands; using Tango.SharedUI; diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/FineTuningPaletteViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/FineTuningPaletteViewVM.cs index 919cd94b2..e9ef45ab5 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/FineTuningPaletteViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Dialogs/FineTuningPaletteViewVM.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Tango.BL.ColorConversion; using Tango.BL.Entities; +using Tango.ColorConversion; using Tango.PPC.Common.Models; using Tango.SharedUI; @@ -18,6 +18,7 @@ namespace Tango.PPC.Jobs.Dialogs { private Job _job; private bool _prevent_change; + private IColorConverter _converter; private List _suggestions; /// @@ -66,6 +67,8 @@ namespace Tango.PPC.Jobs.Dialogs { Suggestions = new List(); HiveSuggestions = new List(); + + _converter = new DefaultColorConverter(); } /// @@ -75,8 +78,8 @@ namespace Tango.PPC.Jobs.Dialogs { if (!_prevent_change) { - Suggestions = TangoColorConverter.CreateTrippletSuggestions(TangoColorConverter.GetSuggestions(_job, SelectedHiveSuggestion.Color)); - SelectedSuggestion = Suggestions[Suggestions.Count / 2]; + Suggestions = _converter.Convert(_job, SelectedHiveSuggestion.Color).CreateTrippletSuggestions(); + SelectedSuggestion = Suggestions.GetCenterSuggestion(); } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj index 4adb1bfb6..74fbc1bdb 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/Tango.PPC.Jobs.csproj @@ -290,6 +290,10 @@ {f441feee-322a-4943-b566-110e12fd3b72} Tango.BL + + {b4fe6485-4161-4b36-bc08-67e0b53d01b7} + Tango.ColorConversion + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core @@ -475,7 +479,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs index b413758c8..847edb52f 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobSummeryViewVM.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Tango.BL; using Tango.BL.Builders; using Tango.BL.Entities; +using Tango.ColorConversion; using Tango.Core.Commands; using Tango.PPC.Common; using Tango.PPC.Common.Messages; @@ -114,12 +115,15 @@ namespace Tango.PPC.Jobs.ViewModels .WithBrushStops() .BuildAsync(); - - try + await Task.Factory.StartNew(() => { - EstimatedDuration = await Job.GetEstimatedDuration(); - } - catch { } + try + { + IColorConverter _converter = new DefaultColorConverter(); + EstimatedDuration = Job.GetEstimatedDuration(_converter.GetRecommendedProcessParameters(Job)); + } + catch { } + }); } } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs index 0d1d2f3cb..fb1f240c5 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs @@ -20,7 +20,6 @@ using Tango.PPC.Jobs.Views; using Tango.BL.Catalogs; using System.Runtime.InteropServices; using System.Threading; -using Tango.BL.ColorConversion; using Tango.SharedUI.Helpers; using Tango.PPC.Common.Navigation; using Tango.PPC.Jobs.NavigationObjects; @@ -37,6 +36,7 @@ using System.Runtime.ExceptionServices; using Tango.Explorer; using Tango.PPC.Storage; using System.IO; +using Tango.ColorConversion; namespace Tango.PPC.Jobs.ViewModels { @@ -54,6 +54,7 @@ namespace Tango.PPC.Jobs.ViewModels private static Dictionary> _jobs_fine_tune_items; private StartPrintingButton _start_printing_btn; private ActionTimer _volumeConversionTimer; + private IColorConverter _converter; #region Properties @@ -351,6 +352,8 @@ namespace Tango.PPC.Jobs.ViewModels /// public JobViewVM() { + _converter = new DefaultColorConverter(); + _volumeConversionTimer = new ActionTimer(TimeSpan.FromMilliseconds(50)); RegisterForMessage(HandleJobSelectedMessage); @@ -857,14 +860,14 @@ namespace Tango.PPC.Jobs.ViewModels LogManager.Log($"Invoking triplet color adjustment dialog for brush stop {brushStop.StopIndex} at segment {brushStop.Segment.SegmentIndex}."); LogManager.Log("Retrieving color conversion suggestions for brush stop..."); - var conversionOutput = TangoColorConverter.GetSuggestions(brushStop); + var conversionOutput = _converter.Convert(brushStop); BasicColorCorrectionViewVM vm = null; vm = await NotificationProvider.ShowDialog(new BasicColorCorrectionViewVM() { InvalidBrushStop = brushStop, - Suggestions = TangoColorConverter.CreateTrippletSuggestions(conversionOutput), + Suggestions = conversionOutput.CreateTrippletSuggestions(), }); if (vm.Result == BasicColorCorrectionViewVM.ColorCorrectionDialogResult.MoreOptions) @@ -873,7 +876,7 @@ namespace Tango.PPC.Jobs.ViewModels vm = await NotificationProvider.ShowDialog(new AdvancedColorCorrectionViewVM() { InvalidBrushStop = brushStop, - Suggestions = TangoColorConverter.CreateHiveSuggestions(conversionOutput), + Suggestions = conversionOutput.CreateHiveSuggestions(), }); } @@ -911,7 +914,7 @@ namespace Tango.PPC.Jobs.ViewModels { try { - var output = TangoColorConverter.GetSuggestions(stop); + var output = _converter.Convert(stop); stop.Red = output.SingleCoordinates.Red; stop.Green = output.SingleCoordinates.Green; @@ -1068,7 +1071,7 @@ namespace Tango.PPC.Jobs.ViewModels foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).DistinctBy(x => x.Color)) { - FineTuneItem item = new FineTuneItem(TangoColorConverter.GetSuggestions(stop)); + FineTuneItem item = new FineTuneItem(_converter.Convert(stop)); item.BrushStops = Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.Color == stop.Color).ToList(); item.SelectedSuggestion = item.Suggestions[item.Suggestions.Count / 2]; item.SelectedChanged += () => StartFineTuningCommand.RaiseCanExecuteChanged(); @@ -1212,7 +1215,7 @@ namespace Tango.PPC.Jobs.ViewModels { try { - stop.IsOutOfGamut = TangoColorConverter.IsOutOfGamut(stop); + stop.IsOutOfGamut = _converter.IsOutOfGamut(stop); stop.OutOfGamutChecked = true; } catch diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Models/FineTuneItem.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Models/FineTuneItem.cs index 7e29d41d2..2eea5c3ce 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Models/FineTuneItem.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Models/FineTuneItem.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Tango.BL.ColorConversion; using Tango.BL.Entities; +using Tango.ColorConversion; using Tango.Core; using Tango.PMR.ColorLab; @@ -88,8 +88,8 @@ namespace Tango.PPC.Common.Models /// The conversion output. public FineTuneItem(ConversionOutput conversionOutput) : this() { - Suggestions = TangoColorConverter.CreateTrippletSuggestions(conversionOutput); - HiveSuggestions = TangoColorConverter.CreateHiveSuggestions(conversionOutput); + Suggestions = conversionOutput.CreateTrippletSuggestions(); + HiveSuggestions = conversionOutput.CreateHiveSuggestions(); } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index a84faf68d..66ddb53bd 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -302,6 +302,10 @@ {f441feee-322a-4943-b566-110e12fd3b72} Tango.BL + + {b4fe6485-4161-4b36-bc08-67e0b53d01b7} + Tango.ColorConversion + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core @@ -380,7 +384,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj index 71fa82504..9b3b58c67 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Tango.PPC.UI.csproj @@ -323,6 +323,10 @@ {f441feee-322a-4943-b566-110e12fd3b72} Tango.BL + + {b4fe6485-4161-4b36-bc08-67e0b53d01b7} + Tango.ColorConversion + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core @@ -534,7 +538,7 @@ del "$(TargetDir)firmware_package.tfp" - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.BL/ColorConversion/ColorConversionSuggestion.cs b/Software/Visual_Studio/Tango.BL/ColorConversion/ColorConversionSuggestion.cs deleted file mode 100644 index 9f58003ce..000000000 --- a/Software/Visual_Studio/Tango.BL/ColorConversion/ColorConversionSuggestion.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Media; -using Tango.Core; -using Tango.PMR.ColorLab; - -namespace Tango.BL.ColorConversion -{ - public class ColorConversionSuggestion : ExtendedObject - { - public Color Color - { - get - { - return Color.FromRgb((byte)Coordinates.Red, (byte)Coordinates.Green, (byte)Coordinates.Blue); - } - } - - public SolidColorBrush Brush - { - get { return new SolidColorBrush(Color); } - } - - private OutputCoordinates _coordinates; - public OutputCoordinates Coordinates - { - get { return _coordinates; } - set { _coordinates = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(Color)); RaisePropertyChanged(nameof(Brush)); } - } - - public int ProcessParametersTableIndex { get; set; } - - public int Column { get; set; } - - public int Row { get; set; } - - public bool DisplayIndices { get; set; } - - public ColorConversionSuggestion() - { - DisplayIndices = false; - } - - public ColorConversionSuggestion(OutputCoordinates coordinates, int row, int column) - { - Coordinates = coordinates; - Row = row; - Column = column; - ProcessParametersTableIndex = coordinates.ProcessParametersTableIndex; - } - } -} diff --git a/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs b/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs deleted file mode 100644 index e6a305677..000000000 --- a/Software/Visual_Studio/Tango.BL/ColorConversion/TangoColorConverter.cs +++ /dev/null @@ -1,425 +0,0 @@ -using Google.Protobuf; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Media; -using Tango.BL.Entities; -using Tango.BL.Enumerations; -using Tango.Core.ExtensionMethods; -using Tango.Logging; -using Tango.PMR; -using Tango.PMR.ColorLab; - -namespace Tango.BL.ColorConversion -{ - public static class TangoColorConverter - { - static class NativeMethods - { - [DllImport("kernel32.dll")] - public static extern IntPtr LoadLibrary(string dllToLoad); - - [DllImport("kernel32.dll")] - public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); - - [DllImport("kernel32.dll")] - public static extern bool FreeLibrary(IntPtr hModule); - } - - private static ConversionOutput Convert(ConversionInput conversionInput) - { - IntPtr pDll = NativeMethods.LoadLibrary(@"Tango.ColorLib.dll"); - IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "Convert"); - NativeMethodDelegate convert = (NativeMethodDelegate)Marshal.GetDelegateForFunctionPointer( - pAddressOfFunctionToCall, - typeof(NativeMethodDelegate)); - - NativePMR nativePMR = new NativePMR(convert); - ConversionOutput output = nativePMR.Invoke(conversionInput); - - bool result = NativeMethods.FreeLibrary(pDll); - - if (output.HasError) - { - throw new ExternalException($"Color Conversion Error: {output.ErrorMessage}!"); - } - - return output; - } - - public static ConversionOutput GetSuggestions(BrushStop brushStop) - { - ConversionInput conversionInput = CreateConversionInput(brushStop); - ConversionOutput output = Convert(conversionInput); - return output; - } - - public static ConversionOutput GetSuggestions(ConversionInput conversionInput) - { - ConversionOutput output = Convert(conversionInput); - return output; - } - - public static ConversionOutput GetSuggestions(Job job, Color color, bool singleMode = false) - { - ConversionInput conversionInput = new ConversionInput(); - - conversionInput.ColorSpace = PMR.ColorLab.ColorSpace.Rgb; - conversionInput.InputCoordinates = new InputCoordinates(); - - conversionInput.InputCoordinates.Red = Math.Max((int)color.R, 0); - conversionInput.InputCoordinates.Green = Math.Max((int)color.G, 0); - conversionInput.InputCoordinates.Blue = Math.Max((int)color.B, 0); - - conversionInput.ThreadL = 92.1815;//brushStop.Segment.Job.Rml.WhitePoint.L; - conversionInput.ThreadA = 2.2555;//brushStop.Segment.Job.Rml.WhitePoint.A; - conversionInput.ThreadB = -10.9325;//brushStop.Segment.Job.Rml.WhitePoint.B; - - conversionInput.SingleMode = singleMode; - - conversionInput.ForwardData = ByteString.CopyFrom(job.Rml.Ccts.FirstOrDefault().ForwardData); - - foreach (var processTable in job.Rml.ProcessParametersTablesGroups.First(x => x.Active).ProcessParametersTables) - { - conversionInput.ProcessRanges.Add(new ProcessRange() - { - MinInkUptake = processTable.MinInkUptake, - MaxInkUptake = processTable.MaxInkUptake, - }); - } - - foreach (var ids_pack in job.Machine.Configuration.GetSupportedIdsPacks(job.Rml)) - { - CalibrationData calibrationData = Cat.CreateDemoCalibrationData((PMR.ColorLab.LiquidType)ids_pack.LiquidType.Code); - - //TODO: Enable Machine Calibration Also.. - - //var machine_cat = ids_pack.LiquidType.Cats.SingleOrDefault(x => x.MachineGuid == machine.Guid && x.RmlGuid == job.RmlGuid); - - //if (machine_cat != null) - //{ - // calibrationData = machine_cat.GetCalibrationData(); - //} - //else - //{ - var rml_cat = job.Rml.LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == ids_pack.LiquidType.Code); - - if (rml_cat != null) - { - calibrationData = rml_cat.GetCalibrationData(); - } - //} - - conversionInput.InputCoordinates.InputLiquids.Add(new InputLiquid() - { - LiquidType = (PMR.ColorLab.LiquidType)ids_pack.LiquidType.Code, - MaxNanoliterPerCentimeter = ids_pack.LiquidType.LiquidTypesRmls.Single(x => x.Rml == job.Rml).MaxNlPerCm, - CalibrationData = calibrationData, - }); - } - - ConversionOutput output = Convert(conversionInput); - - return output; - } - - public static List CreateHiveSuggestions(ConversionOutput conversionOutput) - { - List suggestions = new List(); - - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[1], 0, 1)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[2], 0, 2)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[3], 0, 3)); - - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[5], 1, 0)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[6], 1, 1)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[7], 1, 2)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[8], 1, 3)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[9], 1, 4)); - - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[10], 2, 0)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[11], 2, 1)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[12], 2, 2)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[13], 2, 3)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[14], 2, 4)); - - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[15], 3, 0)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[16], 3, 1)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[17], 3, 2)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[18], 3, 3)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[19], 3, 4)); - - suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[22], 4, 2)); - - return suggestions; - } - - public static List CreateTrippletSuggestions(ConversionOutput conversionOutput) - { - List suggestions = new List(); - - suggestions.Add(new ColorConversionSuggestion(conversionOutput.TripleCoordinates[0], 0, 0)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.TripleCoordinates[1], 0, 0)); - suggestions.Add(new ColorConversionSuggestion(conversionOutput.TripleCoordinates[2], 0, 0)); - - return suggestions; - } - - public static ColorConversionSuggestion CreateSingleSuggestion(ConversionOutput conversionOutput) - { - return new ColorConversionSuggestion(conversionOutput.SingleCoordinates, 0, 0); - } - - public static bool IsOutOfGamut(BrushStop brushStop) - { - return GetSuggestions(brushStop).OutOfGamut; - } - - public static int GetLeastCommonProcessParametersTableIndex(IEnumerable stops) - { - var standard_stops = stops.Where(x => x.BrushColorSpace == Enumerations.ColorSpaces.RGB || x.BrushColorSpace == Enumerations.ColorSpaces.LAB || x.BrushColorSpace == Enumerations.ColorSpaces.CMYK || x.BrushColorSpace == Enumerations.ColorSpaces.Volume); - var color_catalog_stops = stops.Where(x => x.BrushColorSpace != Enumerations.ColorSpaces.RGB && x.BrushColorSpace != Enumerations.ColorSpaces.LAB && x.BrushColorSpace != Enumerations.ColorSpaces.CMYK && x.BrushColorSpace != Enumerations.ColorSpaces.Volume); - - var max_standard = 1; - var max_catalog = 1; - - if (standard_stops.Count() > 0) - { - max_standard = standard_stops.Select(x => GetSuggestions(x)).Select(x => x.SingleCoordinates).Max(x => x.ProcessParametersTableIndex); - } - - if (color_catalog_stops.Where(x => x.ColorCatalog != null).Count() > 0) - { - max_catalog = color_catalog_stops.Where(x => x.ColorCatalog != null).Max(x => x.ColorCatalog.ProcessParametersTableIndex); - } - - if (standard_stops.Count() == 0) - { - return max_catalog; - } - else if (color_catalog_stops.Count() == 0) - { - return max_standard; - } - else - { - return Math.Max(max_standard, max_catalog); - } - } - - private static ConversionInput CreateConversionInput(BrushStop brushStop) - { - ConversionInput conversionInput = new ConversionInput(); - - conversionInput.ColorSpace = (PMR.ColorLab.ColorSpace)brushStop.ColorSpace.Code; - - if (conversionInput.ColorSpace == PMR.ColorLab.ColorSpace.Twine || conversionInput.ColorSpace == PMR.ColorLab.ColorSpace.Coats) - { - conversionInput.ColorSpace = PMR.ColorLab.ColorSpace.Volume; - - if (brushStop.ColorCatalog != null) - { - brushStop.SetVolume(Enumerations.LiquidTypes.Cyan, brushStop.ColorCatalog.Cyan); - brushStop.SetVolume(Enumerations.LiquidTypes.Magenta, brushStop.ColorCatalog.Magenta); - brushStop.SetVolume(Enumerations.LiquidTypes.Yellow, brushStop.ColorCatalog.Yellow); - brushStop.SetVolume(Enumerations.LiquidTypes.Black, brushStop.ColorCatalog.Black); - } - } - - conversionInput.InputCoordinates = new InputCoordinates(); - - conversionInput.SegmentLength = brushStop.Segment.Length; //TODO: for gradient ? - - conversionInput.InputCoordinates.Red = Math.Max(brushStop.Red, 1); - conversionInput.InputCoordinates.Green = Math.Max(brushStop.Green, 1); - conversionInput.InputCoordinates.Blue = Math.Max(brushStop.Blue, 1); - - conversionInput.InputCoordinates.L = brushStop.L; - conversionInput.InputCoordinates.A = brushStop.A; - conversionInput.InputCoordinates.B = brushStop.B; - - conversionInput.InputCoordinates.Cyan = brushStop.Cyan; - conversionInput.InputCoordinates.Magenta = brushStop.Magenta; - conversionInput.InputCoordinates.Yellow = brushStop.Yellow; - conversionInput.InputCoordinates.Key = brushStop.Black; - - conversionInput.ThreadL = 92.1815;//brushStop.Segment.Job.Rml.MediaColor.L; - conversionInput.ThreadA = 2.2555;//brushStop.Segment.Job.Rml.MediaColor.A; - conversionInput.ThreadB = -10.9325;//brushStop.Segment.Job.Rml.MediaColor.B; - - if (brushStop.Segment.Job.Rml.Ccts.Count == 0) - { - throw new InvalidOperationException($"No CCT found for RML {brushStop.Segment.Job.Rml.Name}. Could not create a conversion input."); - } - - conversionInput.ForwardData = ByteString.CopyFrom(brushStop.Segment.Job.Rml.Ccts.FirstOrDefault().ForwardData); - - var machine = brushStop.Segment.Job.Machine; - var job = brushStop.Segment.Job; - - foreach (var processTable in job.Rml.ProcessParametersTablesGroups.First(x => x.Active).ProcessParametersTables) - { - conversionInput.ProcessRanges.Add(new ProcessRange() - { - MinInkUptake = processTable.MinInkUptake, - MaxInkUptake = processTable.MaxInkUptake, - }); - } - - foreach (var ids_pack in machine.Configuration.GetSupportedIdsPacks(job.Rml)) - { - CalibrationData calibrationData = Cat.CreateDemoCalibrationData((PMR.ColorLab.LiquidType)ids_pack.LiquidType.Code); - - //TODO: Enable Machine Calibration Also.. - - //var machine_cat = ids_pack.LiquidType.Cats.SingleOrDefault(x => x.MachineGuid == machine.Guid && x.RmlGuid == job.RmlGuid); - - //if (machine_cat != null) - //{ - // calibrationData = machine_cat.GetCalibrationData(); - //} - //else - //{ - var rml_cat = job.Rml.LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == ids_pack.LiquidType.Code); - - if (rml_cat != null) - { - calibrationData = rml_cat.GetCalibrationData(); - } - //} - - conversionInput.InputCoordinates.InputLiquids.Add(new InputLiquid() - { - LiquidType = (PMR.ColorLab.LiquidType)ids_pack.LiquidType.Code, - MaxNanoliterPerCentimeter = ids_pack.LiquidType.LiquidTypesRmls.Single(x => x.Rml == brushStop.Segment.Job.Rml).MaxNlPerCm, - Volume = brushStop.GetVolume(ids_pack.PackIndex), - CalibrationData = calibrationData, - }); - } - - return conversionInput; - } - - public static void ApplyBrushStopCorrection(BrushStop stop, ProcessParametersTable processTable, ConversionOutput conversionOutput) - { - var output = conversionOutput; - - stop.SetLiquidVolumes(stop.Segment.Job.Machine.Configuration, stop.Segment.Job.Rml, processTable); - - foreach (var outputLiquid in output.SingleCoordinates.OutputLiquids) - { - var liquidVolume = stop.LiquidVolumes.SingleOrDefault(x => x.IdsPack.LiquidType.Code == outputLiquid.LiquidType.ToInt32()); - - if (liquidVolume == null) - { - throw new NullReferenceException("Liquid volume not found for color conversion output liquid '" + outputLiquid.LiquidType + "'."); - } - - liquidVolume.Volume = outputLiquid.Volume; - } - } - - public static List CreateSegmentLinearGradient(Segment segment, ProcessParametersTable processTable, int resolutionCM) - { - List stops = new List(); - - 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); - - BrushStop s = new BrushStop(); - s.Segment = segment; - s.ColorSpace = new Entities.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++; - - stops.Add(s); - } - - var input = CreateConversionInput(stops.First()); - - GradientConversionInput conversionInput = new GradientConversionInput(); - conversionInput.Colors.AddRange(stops.Select(x => new InputRGB() { Red = x.Red, Green = x.Green, Blue = x.Blue })); - conversionInput.DeltaChroma = input.DeltaChroma; - conversionInput.DeltaL = input.DeltaL; - conversionInput.ForwardData = input.ForwardData; - conversionInput.InputLiquids.AddRange(input.InputCoordinates.InputLiquids); - conversionInput.ProcessRanges.AddRange(input.ProcessRanges); - conversionInput.SegmentLength = input.SegmentLength; - conversionInput.ThreadL = input.ThreadL; - conversionInput.ThreadA = input.ThreadA; - conversionInput.ThreadB = input.ThreadB; - - - IntPtr pDll = NativeMethods.LoadLibrary(@"Tango.ColorLib.dll"); - IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "ConvertGradient"); - NativeMethodDelegate convert = (NativeMethodDelegate)Marshal.GetDelegateForFunctionPointer( - pAddressOfFunctionToCall, - typeof(NativeMethodDelegate)); - NativePMR nativePMR = new NativePMR(convert); - GradientConversionOutput output = nativePMR.Invoke(conversionInput); - - bool result = NativeMethods.FreeLibrary(pDll); - - for (int i = 0; i < output.Coordinates.Count; i++) - { - var coords = output.Coordinates[i]; - var stop = stops[i]; - - ConversionOutput o = new ConversionOutput(); - o.SingleCoordinates = coords; - ApplyBrushStopCorrection(stop, processTable, o); - } - - return stops; - } - - private static Color GetRelativeColor(List 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.BL/Entities/BrushStop.cs b/Software/Visual_Studio/Tango.BL/Entities/BrushStop.cs index 8d2db9bb5..7bda5a5e0 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/BrushStop.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/BrushStop.cs @@ -17,7 +17,6 @@ using Google.Protobuf; using System.Runtime.InteropServices; using Tango.PMR; using System.Diagnostics; -using Tango.BL.ColorConversion; using System.Windows.Threading; using System.Timers; using Tango.Core.Threading; diff --git a/Software/Visual_Studio/Tango.BL/Entities/Job.cs b/Software/Visual_Studio/Tango.BL/Entities/Job.cs index 6e6ffcf48..29f9bf439 100644 --- a/Software/Visual_Studio/Tango.BL/Entities/Job.cs +++ b/Software/Visual_Studio/Tango.BL/Entities/Job.cs @@ -491,18 +491,18 @@ namespace Tango.BL.Entities return TimeSpan.FromSeconds((LengthIncludingNumberOfUnits + processParameters.DryerBufferLength) / (processParameters.DyeingSpeed / 100d)); } - /// - /// Gets the duration estimation for this job. - /// - /// - public Task GetEstimatedDuration() - { - return Task.Factory.StartNew(() => - { - var process = GetRecommendedProcessParameters().Result; - return GetEstimatedDuration(process); - }); - } + ///// + ///// Gets the duration estimation for this job. + ///// + ///// + //public Task GetEstimatedDuration() + //{ + // return Task.Factory.StartNew(() => + // { + // var process = GetRecommendedProcessParameters().Result; + // return GetEstimatedDuration(process); + // }); + //} /// /// Translates the job progress to time. @@ -538,28 +538,28 @@ namespace Tango.BL.Entities }; } - public Task GetRecommendedProcessParameters() - { - return Task.Factory.StartNew(() => - { - try - { - int index = ColorConversion.TangoColorConverter.GetLeastCommonProcessParametersTableIndex(Segments.SelectMany(x => x.BrushStops)); - if (index < Rml.GetActiveProcessGroup().ProcessParametersTables.Count) - { - return Rml.GetActiveProcessGroup().ProcessParametersTables[index]; - } - else - { - return Rml.GetActiveProcessGroup().ProcessParametersTables[0]; - } - } - catch (Exception ex) - { - throw new InvalidOperationException("Could not calculate the recommended process parameters for the job.", ex); - } - }); - } + //public Task GetRecommendedProcessParameters() + //{ + // return Task.Factory.StartNew(() => + // { + // try + // { + // int index = ColorConversion.TangoColorConverter.GetLeastCommonProcessParametersTableIndex(Segments.SelectMany(x => x.BrushStops)); + // if (index < Rml.GetActiveProcessGroup().ProcessParametersTables.Count) + // { + // return Rml.GetActiveProcessGroup().ProcessParametersTables[index]; + // } + // else + // { + // return Rml.GetActiveProcessGroup().ProcessParametersTables[0]; + // } + // } + // catch (Exception ex) + // { + // throw new InvalidOperationException("Could not calculate the recommended process parameters for the job.", ex); + // } + // }); + //} public Task ToJobFile() { diff --git a/Software/Visual_Studio/Tango.BL/ExtensionMethods/ColorConversionSuggestionExtensions.cs b/Software/Visual_Studio/Tango.BL/ExtensionMethods/ColorConversionSuggestionExtensions.cs deleted file mode 100644 index 807cfa5dd..000000000 --- a/Software/Visual_Studio/Tango.BL/ExtensionMethods/ColorConversionSuggestionExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.BL.ColorConversion; - -public static class ColorConversionSuggestionExtensions -{ - /// - /// Gets the hive center suggestion. - /// - /// The suggestions. - /// - public static ColorConversionSuggestion GetCenterSuggestion(this IEnumerable suggestions) - { - if (suggestions.Count() == 3) - { - return suggestions.ElementAt(1); - } - else - { - return suggestions.ElementAt(10); - } - } -} - diff --git a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj index bf6e415e1..be88ab930 100644 --- a/Software/Visual_Studio/Tango.BL/Tango.BL.csproj +++ b/Software/Visual_Studio/Tango.BL/Tango.BL.csproj @@ -106,8 +106,6 @@ - - @@ -380,7 +378,6 @@ - diff --git a/Software/Visual_Studio/Tango.BL/Utils/BrushStopUtils.cs b/Software/Visual_Studio/Tango.BL/Utils/BrushStopUtils.cs index 76f928bf3..59dba8ac7 100644 --- a/Software/Visual_Studio/Tango.BL/Utils/BrushStopUtils.cs +++ b/Software/Visual_Studio/Tango.BL/Utils/BrushStopUtils.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; -using Tango.BL.ColorConversion; using Tango.BL.Entities; using Tango.PMR.ColorLab; @@ -12,49 +11,49 @@ namespace Tango.BL.Utils { public class BrushStopUtils { - public static void ApplyConversionOutputLiquids(BrushStop stop, List outputLiquids) - { - foreach (var liquid in outputLiquids) - { - var liquidVolume = stop.LiquidVolumes.SingleOrDefault(x => x.IdsPack.LiquidType.Code == liquid.LiquidType.ToInt32()); - - if (liquidVolume != null) - { - liquidVolume.Volume = liquid.Volume; - } - } - } - - public static void ApplyConversionCoordinates(BrushStop stop, OutputCoordinates coordinates) - { - ApplyConversionOutputLiquids(stop, coordinates.OutputLiquids.ToList()); - - stop.Color = Color.FromRgb((byte)coordinates.Red, (byte)coordinates.Green, (byte)coordinates.Blue); - - stop.IsOutOfGamut = false; - stop.Corrected = true; - } - - public static void ApplyConversionSuggestion(BrushStop stop, ColorConversionSuggestion suggestion) - { - ApplyConversionCoordinates(stop, suggestion.Coordinates); - } - - public static void ApplyColorConversion(BrushStop stop) - { - var conversionOutput = TangoColorConverter.GetSuggestions(stop); - - if (stop.BrushColorSpace == Enumerations.ColorSpaces.RGB || stop.BrushColorSpace == Enumerations.ColorSpaces.LAB) - { - ApplyConversionCoordinates(stop, conversionOutput.SingleCoordinates); - stop.IsOutOfGamut = conversionOutput.OutOfGamut; - } - else if (stop.BrushColorSpace == Enumerations.ColorSpaces.Volume) - { - stop.Color = Color.FromRgb((byte)conversionOutput.SingleCoordinates.Red, (byte)conversionOutput.SingleCoordinates.Green, (byte)conversionOutput.SingleCoordinates.Blue); - stop.IsOutOfGamut = false; - stop.Corrected = true; - } - } + //public static void ApplyConversionOutputLiquids(BrushStop stop, List outputLiquids) + //{ + // foreach (var liquid in outputLiquids) + // { + // var liquidVolume = stop.LiquidVolumes.SingleOrDefault(x => x.IdsPack.LiquidType.Code == liquid.LiquidType.ToInt32()); + + // if (liquidVolume != null) + // { + // liquidVolume.Volume = liquid.Volume; + // } + // } + //} + + //public static void ApplyConversionCoordinates(BrushStop stop, OutputCoordinates coordinates) + //{ + // ApplyConversionOutputLiquids(stop, coordinates.OutputLiquids.ToList()); + + // stop.Color = Color.FromRgb((byte)coordinates.Red, (byte)coordinates.Green, (byte)coordinates.Blue); + + // stop.IsOutOfGamut = false; + // stop.Corrected = true; + //} + + //public static void ApplyConversionSuggestion(BrushStop stop, ColorConversionSuggestion suggestion) + //{ + // ApplyConversionCoordinates(stop, suggestion.Coordinates); + //} + + //public static void ApplyColorConversion(BrushStop stop) + //{ + // var conversionOutput = TangoColorConverter.GetSuggestions(stop); + + // if (stop.BrushColorSpace == Enumerations.ColorSpaces.RGB || stop.BrushColorSpace == Enumerations.ColorSpaces.LAB) + // { + // ApplyConversionCoordinates(stop, conversionOutput.SingleCoordinates); + // stop.IsOutOfGamut = conversionOutput.OutOfGamut; + // } + // else if (stop.BrushColorSpace == Enumerations.ColorSpaces.Volume) + // { + // stop.Color = Color.FromRgb((byte)conversionOutput.SingleCoordinates.Red, (byte)conversionOutput.SingleCoordinates.Green, (byte)conversionOutput.SingleCoordinates.Blue); + // stop.IsOutOfGamut = false; + // stop.Corrected = true; + // } + //} } } diff --git a/Software/Visual_Studio/Tango.ColorConversion/Class1.cs b/Software/Visual_Studio/Tango.ColorConversion/Class1.cs deleted file mode 100644 index b420411b6..000000000 --- a/Software/Visual_Studio/Tango.ColorConversion/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.ColorConversion -{ - public class Class1 - { - } -} diff --git a/Software/Visual_Studio/Tango.ColorConversion/ColorConversionSuggestion.cs b/Software/Visual_Studio/Tango.ColorConversion/ColorConversionSuggestion.cs new file mode 100644 index 000000000..f6dc62785 --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorConversion/ColorConversionSuggestion.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using Tango.Core; +using Tango.PMR.ColorLab; + +namespace Tango.ColorConversion +{ + public class ColorConversionSuggestion : ExtendedObject + { + public Color Color + { + get + { + return Color.FromRgb((byte)Coordinates.Red, (byte)Coordinates.Green, (byte)Coordinates.Blue); + } + } + + public SolidColorBrush Brush + { + get { return new SolidColorBrush(Color); } + } + + private OutputCoordinates _coordinates; + public OutputCoordinates Coordinates + { + get { return _coordinates; } + set { _coordinates = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(Color)); RaisePropertyChanged(nameof(Brush)); } + } + + public int ProcessParametersTableIndex { get; set; } + + public int Column { get; set; } + + public int Row { get; set; } + + public bool DisplayIndices { get; set; } + + public ColorConversionSuggestion() + { + DisplayIndices = false; + } + + public ColorConversionSuggestion(OutputCoordinates coordinates, int row, int column) + { + Coordinates = coordinates; + Row = row; + Column = column; + ProcessParametersTableIndex = coordinates.ProcessParametersTableIndex; + } + } +} diff --git a/Software/Visual_Studio/Tango.ColorConversion/DefaultColorConverter.cs b/Software/Visual_Studio/Tango.ColorConversion/DefaultColorConverter.cs new file mode 100644 index 000000000..0ea0d901f --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorConversion/DefaultColorConverter.cs @@ -0,0 +1,259 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using Tango.BL.Entities; +using Tango.BL; +using Tango.PMR; +using Tango.PMR.ColorLab; +using Tango.BL.Enumerations; +using Google.Protobuf; +using System.Diagnostics; +using Tango.Logging; + +namespace Tango.ColorConversion +{ + public class DefaultColorConverter : IColorConverter + { + static class NativeMethods + { + [DllImport("kernel32.dll")] + public static extern IntPtr LoadLibrary(string dllToLoad); + + [DllImport("kernel32.dll")] + public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); + + [DllImport("kernel32.dll")] + public static extern bool FreeLibrary(IntPtr hModule); + } + + public ConversionOutput Convert(ConversionInput conversionInput) + { + IntPtr pDll = NativeMethods.LoadLibrary(@"Tango.ColorLib.dll"); + IntPtr pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "Convert"); + NativeMethodDelegate convert = (NativeMethodDelegate)Marshal.GetDelegateForFunctionPointer( + pAddressOfFunctionToCall, + typeof(NativeMethodDelegate)); + + NativePMR nativePMR = new NativePMR(convert); + ConversionOutput output = nativePMR.Invoke(conversionInput); + + bool result = NativeMethods.FreeLibrary(pDll); + + if (output.HasError) + { + throw new ExternalException($"Color Conversion Error: {output.ErrorMessage}!"); + } + + return output; + } + + public ConversionOutput Convert(BrushStop stop, Configuration configuration, Rml rml) + { + if (stop == null) + { + throw new ArgumentNullException("Specified brush stop is a null reference."); + } + + if (configuration == null) + { + throw new ArgumentNullException("Specified configuration is a null reference."); + } + + if (rml == null) + { + throw new ArgumentNullException("Specified RML is a null reference."); + } + + if (rml.Ccts == null || rml.Ccts.Count == 0) + { + throw new InvalidOperationException($"No CCT found for RML {rml.Name}. Could not create a conversion input."); + } + + if (rml.ProcessParametersTablesGroups.Count == 0) + { + throw new InvalidOperationException($"No process parameters group for RML {rml.Name}. Could not create a conversion input."); + } + + ConversionInput conversionInput = new ConversionInput(); + + conversionInput.ColorSpace = (PMR.ColorLab.ColorSpace)stop.ColorSpace.Code; + + if (stop.ColorSpace.IsCatalog) + { + conversionInput.ColorSpace = PMR.ColorLab.ColorSpace.Volume; + + if (stop.ColorCatalog != null) + { + stop.SetVolume(LiquidTypes.Cyan, stop.ColorCatalog.Cyan); + stop.SetVolume(LiquidTypes.Magenta, stop.ColorCatalog.Magenta); + stop.SetVolume(LiquidTypes.Yellow, stop.ColorCatalog.Yellow); + stop.SetVolume(LiquidTypes.Black, stop.ColorCatalog.Black); + } + } + + conversionInput.InputCoordinates = new InputCoordinates(); + + conversionInput.InputCoordinates.Red = Math.Max(stop.Red, 1); + conversionInput.InputCoordinates.Green = Math.Max(stop.Green, 1); + conversionInput.InputCoordinates.Blue = Math.Max(stop.Blue, 1); + + conversionInput.InputCoordinates.L = stop.L; + conversionInput.InputCoordinates.A = stop.A; + conversionInput.InputCoordinates.B = stop.B; + + conversionInput.InputCoordinates.Cyan = stop.Cyan; + conversionInput.InputCoordinates.Magenta = stop.Magenta; + conversionInput.InputCoordinates.Yellow = stop.Yellow; + conversionInput.InputCoordinates.Key = stop.Black; + + conversionInput.ThreadL = rml.WhitePointL; + conversionInput.ThreadA = rml.WhitePointA; + conversionInput.ThreadB = rml.WhitePointB; + + conversionInput.ForwardData = ByteString.CopyFrom(rml.Ccts.FirstOrDefault().ForwardData); + + foreach (var processTable in rml.ProcessParametersTablesGroups.First(x => x.Active).ProcessParametersTables) + { + conversionInput.ProcessRanges.Add(new ProcessRange() + { + MinInkUptake = processTable.MinInkUptake, + MaxInkUptake = processTable.MaxInkUptake, + }); + } + + foreach (var ids_pack in configuration.GetSupportedIdsPacks(rml)) + { + CalibrationData calibrationData = Cat.CreateDemoCalibrationData((PMR.ColorLab.LiquidType)ids_pack.LiquidType.Code); + + //TODO: Enable Machine Calibration Also.. + + //var machine_cat = ids_pack.LiquidType.Cats.SingleOrDefault(x => x.MachineGuid == machine.Guid && x.RmlGuid == job.RmlGuid); + + //if (machine_cat != null) + //{ + // calibrationData = machine_cat.GetCalibrationData(); + //} + //else + //{ + var rml_cat = rml.LiquidTypesRmls.SingleOrDefault(x => x.LiquidType.Code == ids_pack.LiquidType.Code); + + if (rml_cat != null) + { + calibrationData = rml_cat.GetCalibrationData(); + } + //} + + conversionInput.InputCoordinates.InputLiquids.Add(new InputLiquid() + { + LiquidType = (PMR.ColorLab.LiquidType)ids_pack.LiquidType.Code, + MaxNanoliterPerCentimeter = ids_pack.LiquidType.LiquidTypesRmls.Single(x => x.Rml == rml).MaxNlPerCm, + Volume = stop.GetVolume(ids_pack.PackIndex), + CalibrationData = calibrationData, + }); + } + + return Convert(conversionInput); + } + + public ConversionOutput Convert(BrushStop stop) + { + if (stop == null) + { + throw new ArgumentNullException("Specified brush stop is a null reference."); + } + + if (stop.Segment == null || stop.Segment.Job == null) + { + throw new ArgumentNullException("The specified brush stop must be a part of a job segment."); + } + + if (stop.Segment.Job.Machine == null || stop.Segment.Job.Machine.Configuration == null) + { + throw new ArgumentNullException("The specified brush stop is associated with a job that is not a part of any machine or the machine does not have any configuration."); + } + + return Convert(stop, stop.Segment.Job.Machine.Configuration, stop.Segment.Job.Rml); + } + + public ConversionOutput Convert(Job job, Color color) + { + if (job == null) + { + throw new ArgumentNullException("Specified job is a null reference."); + } + + if (job.Machine == null) + { + throw new ArgumentNullException("Specified job machine is a null reference."); + } + + if (job.Rml == null) + { + throw new ArgumentNullException("Specified job RML is a null reference."); + } + + BrushStop stop = new BrushStop(); + stop.ColorSpace = new BL.Entities.ColorSpace() + { + Code = ColorSpaces.RGB.ToInt32(), + }; + stop.Color = color; + + return Convert(stop, job.Machine.Configuration, job.Rml); + } + + public bool IsOutOfGamut(BrushStop stop) + { + return Convert(stop).OutOfGamut; + } + + public ProcessParametersTable GetRecommendedProcessParameters(Job job) + { + var stops = job.Segments.SelectMany(x => x.BrushStops).ToList(); + + var standard_stops = stops.Where(x => x.BrushColorSpace == ColorSpaces.RGB || x.BrushColorSpace == ColorSpaces.LAB || x.BrushColorSpace == ColorSpaces.CMYK || x.BrushColorSpace == ColorSpaces.Volume); + var color_catalog_stops = stops.Where(x => x.BrushColorSpace != ColorSpaces.RGB && x.BrushColorSpace != ColorSpaces.LAB && x.BrushColorSpace != ColorSpaces.CMYK && x.BrushColorSpace != ColorSpaces.Volume); + + var max_standard = 1; + var max_catalog = 1; + + if (standard_stops.Count() > 0) + { + max_standard = standard_stops.Select(x => Convert(x)).Select(x => x.SingleCoordinates).Max(x => x.ProcessParametersTableIndex); + } + + if (color_catalog_stops.Where(x => x.ColorCatalog != null).Count() > 0) + { + max_catalog = color_catalog_stops.Where(x => x.ColorCatalog != null).Max(x => x.ColorCatalog.ProcessParametersTableIndex); + } + + int index = 0; + + if (standard_stops.Count() == 0) + { + index = max_catalog; + } + else if (color_catalog_stops.Count() == 0) + { + index = max_standard; + } + else + { + index = Math.Max(max_standard, max_catalog); + } + + var processParameters = job.Rml.GetActiveProcessGroup().ProcessParametersTables.FirstOrDefault(x => x.TableIndex == index); + + if (processParameters == null) + { + processParameters = job.Rml.GetActiveProcessGroup().ProcessParametersTables.FirstOrDefault(); + } + + return processParameters; + } + } +} diff --git a/Software/Visual_Studio/Tango.ColorConversion/ExtensionMethods/ColorConversionSuggestionExtensions.cs b/Software/Visual_Studio/Tango.ColorConversion/ExtensionMethods/ColorConversionSuggestionExtensions.cs new file mode 100644 index 000000000..076890230 --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorConversion/ExtensionMethods/ColorConversionSuggestionExtensions.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.ColorConversion; + +public static class ColorConversionSuggestionExtensions +{ + /// + /// Gets the hive center suggestion. + /// + /// The suggestions. + /// + public static ColorConversionSuggestion GetCenterSuggestion(this IEnumerable suggestions) + { + if (suggestions.Count() == 3) + { + return suggestions.ElementAt(1); + } + else + { + return suggestions.ElementAt(10); + } + } +} + diff --git a/Software/Visual_Studio/Tango.ColorConversion/ExtensionMethods/ConversionOutputExtensions.cs b/Software/Visual_Studio/Tango.ColorConversion/ExtensionMethods/ConversionOutputExtensions.cs new file mode 100644 index 000000000..8d96ce777 --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorConversion/ExtensionMethods/ConversionOutputExtensions.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.Entities; +using Tango.ColorConversion; +using Tango.PMR.ColorLab; + +public static class ConversionOutputExtensions +{ + public static List CreateHiveSuggestions(this ConversionOutput conversionOutput) + { + List suggestions = new List(); + + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[1], 0, 1)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[2], 0, 2)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[3], 0, 3)); + + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[5], 1, 0)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[6], 1, 1)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[7], 1, 2)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[8], 1, 3)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[9], 1, 4)); + + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[10], 2, 0)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[11], 2, 1)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[12], 2, 2)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[13], 2, 3)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[14], 2, 4)); + + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[15], 3, 0)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[16], 3, 1)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[17], 3, 2)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[18], 3, 3)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[19], 3, 4)); + + suggestions.Add(new ColorConversionSuggestion(conversionOutput.HiveCoordinates[22], 4, 2)); + + return suggestions; + } + + public static List CreateTrippletSuggestions(this ConversionOutput conversionOutput) + { + List suggestions = new List(); + + suggestions.Add(new ColorConversionSuggestion(conversionOutput.TripleCoordinates[0], 0, 0)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.TripleCoordinates[1], 0, 0)); + suggestions.Add(new ColorConversionSuggestion(conversionOutput.TripleCoordinates[2], 0, 0)); + + return suggestions; + } + + public static ColorConversionSuggestion CreateSingleSuggestion(this ConversionOutput conversionOutput) + { + return new ColorConversionSuggestion(conversionOutput.SingleCoordinates, 0, 0); + } + + public static void ApplyOnBrushStop(this ConversionOutput conversionOutput, BrushStop stop, ProcessParametersTable processTable) + { + var output = conversionOutput; + + if (stop.LiquidVolumes == null || stop.LiquidVolumes.Count == 0) + { + stop.SetLiquidVolumes(stop.Segment.Job.Machine.Configuration, stop.Segment.Job.Rml, processTable); + } + + stop.Red = conversionOutput.SingleCoordinates.Red; + stop.Green = conversionOutput.SingleCoordinates.Green; + stop.Blue = conversionOutput.SingleCoordinates.Blue; + stop.IsOutOfGamut = conversionOutput.OutOfGamut; + + foreach (var outputLiquid in output.SingleCoordinates.OutputLiquids) + { + var liquidVolume = stop.LiquidVolumes.SingleOrDefault(x => x.IdsPack.LiquidType.Code == outputLiquid.LiquidType.ToInt32()); + + if (liquidVolume == null) + { + throw new NullReferenceException("Liquid volume not found for color conversion output liquid '" + outputLiquid.LiquidType + "'."); + } + + liquidVolume.Volume = outputLiquid.Volume; + } + } +} + diff --git a/Software/Visual_Studio/Tango.ColorConversion/IColorConverter.cs b/Software/Visual_Studio/Tango.ColorConversion/IColorConverter.cs new file mode 100644 index 000000000..00cd79b46 --- /dev/null +++ b/Software/Visual_Studio/Tango.ColorConversion/IColorConverter.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using Tango.BL.Entities; +using Tango.PMR.ColorLab; + +namespace Tango.ColorConversion +{ + /// + /// Represents an RGB/LAB to and from liquid volumes conversion engine. + /// + public interface IColorConverter + { + ConversionOutput Convert(ConversionInput conversionInput); + ConversionOutput Convert(BrushStop stop, Configuration configuration, Rml rml); + ConversionOutput Convert(BrushStop stop); + ConversionOutput Convert(Job job, Color color); + bool IsOutOfGamut(BrushStop stop); + ProcessParametersTable GetRecommendedProcessParameters(Job job); + } +} diff --git a/Software/Visual_Studio/Tango.ColorConversion/Tango.ColorConversion.csproj b/Software/Visual_Studio/Tango.ColorConversion/Tango.ColorConversion.csproj index 2846ca99a..182de5d30 100644 --- a/Software/Visual_Studio/Tango.ColorConversion/Tango.ColorConversion.csproj +++ b/Software/Visual_Studio/Tango.ColorConversion/Tango.ColorConversion.csproj @@ -34,6 +34,7 @@ ..\packages\Google.Protobuf.3.4.1\lib\net45\Google.Protobuf.dll + @@ -47,7 +48,11 @@ GlobalVersionInfo.cs - + + + + + @@ -62,6 +67,10 @@ {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core + + {bc932dbd-7cdb-488c-99e4-f02cf441f55e} + Tango.Logging + {e4927038-348d-4295-aaf4-861c58cb3943} Tango.PMR diff --git a/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs index 59c6441d3..62ac43b40 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/DefaultGradientGenerationConfiguration.cs @@ -4,9 +4,9 @@ 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.ColorConversion; using Tango.Core; using Tango.Core.ExtensionMethods; @@ -91,6 +91,8 @@ namespace Tango.Integration.Operation var refStop = segment.BrushStops.First().Clone(segment); + IColorConverter converter = new DefaultColorConverter(); + for (double cm = 0; cm <= segment.Length; cm += (ResolutionCM / 100d)) { if (aborted) return stops; @@ -100,7 +102,7 @@ namespace Tango.Integration.Operation 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); + var output = converter.Convert(segment.Job, color); BrushStop s = new BrushStop(); s.Segment = segment; @@ -114,7 +116,7 @@ namespace Tango.Integration.Operation s.Blue = color.B; s.StopIndex = stopIndex++; - TangoColorConverter.ApplyBrushStopCorrection(s, processParameters, output); + output.ApplyOnBrushStop(s, processParameters); stops.Add(s); } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 766448bcc..75a85bc4c 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -22,7 +22,6 @@ using Tango.PMR.Hardware; using Google.Protobuf; using Tango.PMR.Connection; using Tango.BL.Enumerations; -using Tango.BL.ColorConversion; using Tango.PMR.Stubs; using System.Threading; using Tango.Integration.Storage; @@ -36,6 +35,7 @@ using Tango.Integration.JobRuns; using Tango.FirmwareUpdateLib.WPF; using Tango.FirmwareUpdateLib; using Tango.Core.ExtensionMethods; +using Tango.ColorConversion; namespace Tango.Integration.Operation { @@ -1159,6 +1159,8 @@ namespace Tango.Integration.Operation /// public Task Print(Job job) { + IColorConverter converter = new DefaultColorConverter(); + var jobSegments = job.OrderedSegments; //Check not brush stop has color space 'Volume'. @@ -1167,9 +1169,6 @@ namespace Tango.Integration.Operation 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 = TangoColorConverter.GetLeastCommonProcessParametersTableIndex(jobSegments.SelectMany(x => x.BrushStops)); - if (job.Rml == null) { throw new NullReferenceException("Job RML is null"); @@ -1182,11 +1181,11 @@ namespace Tango.Integration.Operation throw new NullReferenceException("Could not locate an active process parameters tables group for RML " + job.Rml.Name); } - var processParameters = processGroup.ProcessParametersTables.FirstOrDefault(x => x.TableIndex == processParametersTableIndex); + var processParameters = converter.GetRecommendedProcessParameters(job); if (processParameters == null) { - throw new NullReferenceException("Could not locate process parameters table index " + processParametersTableIndex + " in group " + processGroup.Name + " for RML " + job.Rml.Name); + throw new NullReferenceException("Could not locate any process parameters table in group " + processGroup.Name + " for RML " + job.Rml.Name); } //Perform color correction @@ -1196,7 +1195,7 @@ namespace Tango.Integration.Operation { if (stop.BrushColorSpace == ColorSpaces.RGB || stop.BrushColorSpace == ColorSpaces.LAB) { - var output = TangoColorConverter.GetSuggestions(stop); + var output = converter.Convert(stop); //TODO: Restore this when Mirta conversion is working as expected. //if (suggestions.OutOfGamut) diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index b536b1281..994a0ef2e 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -147,6 +147,10 @@ {f441feee-322a-4943-b566-110e12fd3b72} Tango.BL + + {b4fe6485-4161-4b36-bc08-67e0b53d01b7} + Tango.ColorConversion + {a34ee0f0-649d-41c8-8489-b6f1cc6924ee} Tango.Core @@ -184,7 +188,7 @@ - + \ No newline at end of file -- cgit v1.3.1