using ColorMine.ColorSpaces; using LiteDB; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using Tango.Core; namespace Tango.PPC.Jobs.Models { public class TrialsLogModel: ExtendedObject { #region Properties [BsonIgnore] public String JobRunGuid { get; set; } private int _trialNumber; public int TrialNumber { get { return _trialNumber; } set { _trialNumber = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(Trial)); } } [BsonIgnore] public string Trial { get { if(TrialNumber == 0) return "T"; return TrialNumber.ToString(); } } //LAB private double? _l; public double? L { get { return _l; } set { _l = value; RaisePropertyChanged(nameof(LAB)); OnLABChanged();} } private double? _a; public double? A { get { return _a; } set { _a = value; RaisePropertyChanged(nameof(LAB)); OnLABChanged(); } } private double? _b; public double? B { get { return _b; } set { _b = value; RaisePropertyChanged(nameof(LAB)); OnLABChanged(); } } public double VectorCorrectionL { get; set; } public double VectorCorrectionA { get; set; } public double VectorCorrectionB { get; set; } public double LightnessOffset { get; set; } public double ChromaOffset { get; set; } public double HueOffset { get; set; } public bool IsManualCorrection { get; set; } //LCH private double _LCH_C; public double LCH_C { get { return _LCH_C; } set { _LCH_C = value; //RaisePropertyChanged(nameof(LAB)); } } private double _h; public double H { get { return _h; } set { _h = value; //RaisePropertyChanged(nameof(LAB)); } } public double dL { get; set; } public double dC { get; set; } public double dH { get; set; } public bool CorrectOnlyHue { get; set; } public double SuggestionL { get; set; } public double SuggestionA { get; set; } public double SuggestionB { get; set; } public double C { get; set; } public double M { get; set; } public double Y { get; set; } public double K { get; set; } [BsonIgnore] public string CMYK { get { return String.Format("{0:0.##},{1:0.##},{2:0.##},{3:0.##}", C, M, Y, K); } } public double NewSuggestionL { get; set; } public double NewSuggestionA { get; set; } public double NewSuggestionB { get; set; } private DateTime _date; public DateTime Date { get { return _date; } set { _date = value; RaisePropertyChangedAuto(); } } private double? _deltaE; public double? DeltaE { get { return _deltaE; } set { _deltaE = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(DeltaEDisplay)); } } public string DeltaEDisplay { get { if (DeltaE == null) return ""; // if (IsBest) // return String.Format($"{DeltaE:0.##} Best"); return String.Format($"{DeltaE:0.##}"); } } private bool _IsActiveTrial; [BsonIgnore] public bool IsActiveTrial { get { return _IsActiveTrial; } set { _IsActiveTrial = value; RaisePropertyChangedAuto(); } } [BsonIgnore] public string LAB { get { if(!ValidationLAB()) return ""; return String.Format("{0:0.##},{1:0.##},{2:0.##}", L, A, B); } } private bool _istested; public bool IsTested { get { return _istested; } set { _istested = value; if (_istested) { IsSelectionEnable = true; } } } private bool _isBest; public bool IsBest { get { return _isBest; } set { _isBest = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(DeltaEDisplay));} } private bool _isSelectionEnable; [BsonIgnore] public bool IsSelectionEnable { get { return _isSelectionEnable; } set { _isSelectionEnable = value; RaisePropertyChangedAuto(); } } [BsonIgnore] public System.Windows.Media.Color SuggestedColor { get { Lab lab = new Lab() { L = NewSuggestionL, A = NewSuggestionA, B = NewSuggestionB }; //Cmyk cmyk = new Cmyk { C = C, M = M, Y = Y, K = K}; IRgb RGB = lab.ToRgb(); //IRgb RGB = cmyk.ToRgb(); return Color.FromRgb((byte)RGB.R, (byte)RGB.G, (byte)RGB.B); } } #endregion public TrialsLogModel(int trial, double c, double m, double y, double k) { TrialNumber = trial; IsActiveTrial = false; C = c; M = m; Y = y; K = k; L = A = B = null; Date = DateTime.UtcNow; RaisePropertyChanged(nameof(CMYK)); IsTested = false; IsSelectionEnable = true; IsBest = false; } #region Methods private bool ValidationLAB() { if (L == null || L < 0 || L > 100 || A == null || A < -128 || A > 127 || B == null || B < -128 || B > 127) return false; return true; } private void OnLABChanged() { if (ValidationLAB()) { ; } } #endregion } }