using Newtonsoft.Json; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using TeamAAS_VP.Interfaces; using TeamAAS_VP.Resources.Languages; namespace TeamAAS_VP.Models.Robot { /// /// 多机器人的点位信息 /// public class RobotPoint : BindableBase { private ObservableCollection _Robots; /// /// 机器人集合 /// public ObservableCollection Robots { get => _Robots; set => SetProperty(ref _Robots, value); } /// /// 增加机器人 /// /// /// public void AddRobot(Guid id,string name) { if (Robots == null) { Robots = new ObservableCollection(); } if (!Robots.Any(r => r.Id == id)) { Robots.Add(new RobotPointStore(id, name)); } else { throw new Exception(Lang.机器人已存在); } } /// /// 移除机器人 /// /// /// public void RemoveRobot(Guid id) { var robot = Robots.FirstOrDefault(r => r.Id == id); if (robot != null) { Robots.Remove(robot); } else { throw new Exception(Lang.机器人不存在); } } /// /// 修改机器人名称 /// /// /// /// public void UpdateRobotName(Guid id, string newName) { var robot = Robots.FirstOrDefault(r => r.Id == id); if (robot != null) { robot.Name = newName; } else { throw new Exception(Lang.机器人不存在); } } public RobotPoint() { Robots = new ObservableCollection(); } public RobotPoint(RobotInfo[] robotInfos) { Robots = new ObservableCollection(); foreach (var info in robotInfos) { Robots.Add(new RobotPointStore(info.Id, info.RobotName)); } } /// /// 深拷贝 /// /// 新的 RobotPoint 实例 public RobotPoint Clone() { return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(this)); } } /// /// 机器人点位的容器 /// public class RobotPointStore : BindableBase { private Guid _id; /// /// 机器人唯一 Id(可用 GUID 或自定义字符串) /// public Guid Id { get => _id; set => SetProperty(ref _id, value); } private string _name; /// /// 机器人名称 /// public string Name { get => _name; set => SetProperty(ref _name, value); } private ObservableCollection _Points; /// /// 点位集合 /// public ObservableCollection Points { get { return _Points; } set { SetProperty(ref _Points, value); } } private ObservableCollection _pallets; /// /// 托盘集合 /// public ObservableCollection Pallets { get => _pallets; set => SetProperty(ref _pallets, value); } public RobotPointStore() { Points = new ObservableCollection(); Pallets=new ObservableCollection(); } public RobotPointStore(Guid id, string name) { Id = id; Name = name; Points = new ObservableCollection(); Pallets = new ObservableCollection(); for (int i = 0; i < 1000; i++) { Points.Add(new RPoint(i)); } } } }