163 lines
4.8 KiB
C#
163 lines
4.8 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
|
|
namespace VisionCommon {
|
|
public class LightRecipe : ICloneCopy<LightRecipe> {
|
|
public eLightId LightId { get; set; } = eLightId.LIGHT1;
|
|
public LightInfo LightInfo { get; set; } = new LightInfo();
|
|
|
|
public LightRecipe Clone() {
|
|
return ((ICloneable)this).Clone() as LightRecipe;
|
|
}
|
|
|
|
object ICloneable.Clone() {
|
|
var cloneObj = new LightRecipe();
|
|
CopyTo(cloneObj);
|
|
return cloneObj;
|
|
}
|
|
|
|
public void CopyTo(LightRecipe target) {
|
|
target.LightId = this.LightId;
|
|
target.LightInfo = this.LightInfo.Clone();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 하드웨어 조명 컨트롤러마다 고유하게 지정
|
|
/// </summary>
|
|
public enum eLightId {
|
|
None = -1,
|
|
LIGHT1, LIGHT2, LIGHT3, LIGHT4, LIGHT5, LIGHT6, LIGHT7, LIGHT8, LIGHT9, LIGHT10,
|
|
Max
|
|
}
|
|
|
|
public class LightInfo {
|
|
public List<LightParam> LightParams { get; set; } = new List<LightParam>();
|
|
|
|
public LightInfo Clone() {
|
|
return new LightInfo() {
|
|
LightParams = this.LightParams.Select(x => x.Clone()).ToList()
|
|
};
|
|
}
|
|
|
|
public static bool HasChannel(List<LightParam> lightParams, int ch) {
|
|
foreach (LightParam lightParam in lightParams) {
|
|
if (lightParam.Ch == ch) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public override bool Equals(object obj) {
|
|
var lightInfo = obj as LightInfo;
|
|
if (lightInfo is null) {
|
|
return false;
|
|
}
|
|
|
|
if (ReferenceEquals(this, lightInfo)) {
|
|
return true;
|
|
}
|
|
|
|
if (LightParams.Count != lightInfo.LightParams.Count) {
|
|
return false;
|
|
}
|
|
|
|
var thisLightParams = LightParams.OrderBy(lp => lp.Ch).ToList();
|
|
var lightParams = lightInfo.LightParams.OrderBy(lp => lp.Ch).ToList();
|
|
|
|
for (int i = 0; i < thisLightParams.Count; i++) {
|
|
if (!thisLightParams[i].Equals(lightParams[i])) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override int GetHashCode() {
|
|
if (0 < LightParams.Count) {
|
|
int hashCode = LightParams[0].GetHashCode();
|
|
for (int i = 1; i < LightParams.Count; i++) {
|
|
hashCode ^= LightParams[i].GetHashCode();
|
|
}
|
|
return hashCode;
|
|
}
|
|
return base.GetHashCode();
|
|
}
|
|
|
|
public override string ToString() {
|
|
string str = string.Empty;
|
|
foreach (var lp in LightParams) {
|
|
str += $"{lp}\n";
|
|
}
|
|
return str;
|
|
}
|
|
}
|
|
|
|
public class LightParam {
|
|
public eLightId LightId { get; set; } = eLightId.LIGHT1;
|
|
public int Ch { get; set; } = 1;
|
|
public int Level { get; set; } = 80;
|
|
public bool OnOff { get; set; } = true;
|
|
|
|
public override bool Equals(object obj) {
|
|
var lightParam = obj as LightParam;
|
|
if (lightParam is null) {
|
|
return false;
|
|
}
|
|
|
|
if (ReferenceEquals(this, lightParam)) {
|
|
return true;
|
|
}
|
|
|
|
return (LightId == lightParam.LightId) && (Ch == lightParam.Ch) && (Level == lightParam.Level) && (OnOff == lightParam.OnOff);
|
|
}
|
|
|
|
public override int GetHashCode() {
|
|
return LightId.GetHashCode() ^ Ch.GetHashCode() ^ Level.GetHashCode() ^ OnOff.GetHashCode();
|
|
}
|
|
|
|
public override string ToString() {
|
|
return $"Id : {LightId}, Ch : {Ch}, Level : {Level}, OnOff : {OnOff}";
|
|
}
|
|
|
|
public LightParam Clone() {
|
|
return new LightParam() {
|
|
LightId = this.LightId,
|
|
Ch = this.Ch,
|
|
Level = this.Level,
|
|
OnOff = this.OnOff,
|
|
};
|
|
}
|
|
}
|
|
|
|
public class LightIndex {
|
|
public eLightId LightId { get; set; }
|
|
public int Ch { get; set; }
|
|
|
|
public override int GetHashCode() {
|
|
return LightId.GetHashCode() ^ Ch.GetHashCode();
|
|
}
|
|
|
|
public override bool Equals(object obj) {
|
|
LightIndex other = obj as LightIndex;
|
|
return other != null && other.LightId == this.LightId && other.Ch == this.Ch;
|
|
}
|
|
|
|
public LightIndex Clone() {
|
|
return new LightIndex() {
|
|
LightId = this.LightId,
|
|
Ch = this.Ch
|
|
};
|
|
}
|
|
}
|
|
}
|