83 lines
3.0 KiB
C#
83 lines
3.0 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.View;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace VisionCommon {
|
|
public enum eUnitId {
|
|
None = -1,
|
|
Unit1 = 0, Unit2, Unit3, Unit4, Unit5, Unit6, Unit7, Unit8, Unit9, Unit10,
|
|
Max
|
|
}
|
|
|
|
public class UnitRecipe : ICloneCopy<UnitRecipe> {
|
|
public eUnitId UnitId { get; set; }
|
|
public string UnitName { get; set; }
|
|
public ObservableCollection<SubSysRecipe> SubSysRecipes { get; set; } = new ObservableCollection<SubSysRecipe>();
|
|
|
|
public UnitRecipe() {
|
|
SubSysRecipes.CollectionChanged += SubSysRecipes_CollectionChanged;
|
|
}
|
|
|
|
#region SubSysRecipes CollectionChanged Event
|
|
private void SubSysRecipes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) {
|
|
try {
|
|
var subSysRecipes = sender as ObservableCollection<SubSysRecipe>;
|
|
|
|
if (e.Action == NotifyCollectionChangedAction.Add) {
|
|
var newSubSysReicpe = e.NewItems[0] as SubSysRecipe;
|
|
|
|
if (subSysRecipes == null || subSysRecipes.Count == 0) {
|
|
return;
|
|
}
|
|
else {
|
|
newSubSysReicpe.SubSysId = (eSubSysId)subSysRecipes.Count - 1;
|
|
if (string.IsNullOrEmpty(newSubSysReicpe.SubSysName)) {
|
|
newSubSysReicpe.SubSysName = newSubSysReicpe.SubSysId.ToString();
|
|
}
|
|
}
|
|
}
|
|
else if (e.Action == NotifyCollectionChangedAction.Remove) {
|
|
int index = 0;
|
|
foreach (SubSysRecipe subSysRecipe in subSysRecipes) {
|
|
if (index == (int)eSubSysId.Max) {
|
|
break;
|
|
}
|
|
subSysRecipe.SubSysId = (eSubSysId)index++;
|
|
if (string.IsNullOrEmpty(subSysRecipe.SubSysName) || subSysRecipe.SubSysName.Contains("SubSys")) {
|
|
subSysRecipe.SubSysName = subSysRecipe.SubSysId.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex) {
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public UnitRecipe Clone() {
|
|
return ((ICloneable)this).Clone() as UnitRecipe;
|
|
}
|
|
|
|
object ICloneable.Clone() {
|
|
var cloneObj = new UnitRecipe();
|
|
CopyTo(cloneObj);
|
|
return cloneObj;
|
|
}
|
|
|
|
public void CopyTo(UnitRecipe target) {
|
|
target.UnitId = this.UnitId;
|
|
target.UnitName = this.UnitName;
|
|
target.SubSysRecipes = new ObservableCollection<SubSysRecipe>(
|
|
this.SubSysRecipes.Select(x => x.Clone()).ToList());
|
|
}
|
|
}
|
|
} |