using System.Collections.Generic; namespace AIPractice.Shared.Labels { public enum GroupType { Image = 0, Roi =1, All = 2, } public abstract class LabelGroup : LabelObject { private RootLabel _root; /// /// Gets the group type. /// public GroupType Type { get; set; } /// /// Gets the labels belongs to this group. /// public IReadOnlyList Labels { get; } /// /// Gets or sets the root of this group /// public RootLabel Root { get => _root; set { if (_root != value) { _root = value; foreach(var label in Labels) { label.Root = _root; } } } } protected LabelGroup(string id, string title, GroupType type, IEnumerable labels) : base(id, title) { Type = type; var list = new List(labels); Labels = list; } /// /// Add one label into the group. /// /// The label to be added. and the root label will be assigned to the label. public void AddLabel(ImageLabel label) { var labelList = (List)Labels; if(!labelList.Contains(label)) { labelList.Add(label); label.Root = _root; } } /// /// Remove the lable from the group. /// /// The label to be removed. public void RemoveLabel(ImageLabel label) { var labelList = (List)Labels; if(labelList.Contains(label)) { labelList.Remove(label); } } /// /// Insert one label into the group on given index. /// /// The index to be insert. /// The label to be added. and the root label will be assigned to the label. public void InsertLabel(int index, ImageLabel label) { var labelList = (List)Labels; if (!labelList.Contains(label)) { labelList.Insert(index,label); label.Root = _root; } } } }