RobotPoint.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using Newtonsoft.Json;
  2. using Prism.Mvvm;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Linq;
  7. using TeamAAS.Robot.Interfaces;
  8. namespace TeamAAS.Robot.Models.Robot
  9. {
  10. /// <summary>
  11. /// 多机器人的点位信息
  12. /// </summary>
  13. public class RobotPoint : TeamAAS.BindableBase
  14. {
  15. private ObservableCollection<RobotPointStore> _Robots;
  16. /// <summary>
  17. /// 机器人集合
  18. /// </summary>
  19. public ObservableCollection<RobotPointStore> Robots
  20. {
  21. get => _Robots;
  22. set => SetProperty(ref _Robots, value);
  23. }
  24. /// <summary>
  25. /// 增加机器人
  26. /// </summary>
  27. /// <param name="id"></param>
  28. /// <param name="name"></param>
  29. public void AddRobot(Guid id,string name)
  30. {
  31. if (Robots == null)
  32. {
  33. Robots = new ObservableCollection<RobotPointStore>();
  34. }
  35. if (!Robots.Any(r => r.Id == id))
  36. {
  37. Robots.Add(new RobotPointStore(id, name));
  38. }
  39. else
  40. {
  41. throw new Exception("机器人已存在");
  42. }
  43. }
  44. /// <summary>
  45. /// 移除机器人
  46. /// </summary>
  47. /// <param name="id"></param>
  48. /// <exception cref="Exception"></exception>
  49. public void RemoveRobot(Guid id)
  50. {
  51. var robot = Robots.FirstOrDefault(r => r.Id == id);
  52. if (robot != null)
  53. {
  54. Robots.Remove(robot);
  55. }
  56. else
  57. {
  58. throw new Exception("机器人不存在");
  59. }
  60. }
  61. /// <summary>
  62. /// 修改机器人名称
  63. /// </summary>
  64. /// <param name="id"></param>
  65. /// <param name="newName"></param>
  66. /// <exception cref="Exception"></exception>
  67. public void UpdateRobotName(Guid id, string newName)
  68. {
  69. var robot = Robots.FirstOrDefault(r => r.Id == id);
  70. if (robot != null)
  71. {
  72. robot.Name = newName;
  73. }
  74. else
  75. {
  76. throw new Exception("机器人不存在");
  77. }
  78. }
  79. public RobotPoint()
  80. {
  81. Robots = new ObservableCollection<RobotPointStore>();
  82. }
  83. public RobotPoint(RobotInfo[] robotInfos)
  84. {
  85. Robots = new ObservableCollection<RobotPointStore>();
  86. foreach (var info in robotInfos)
  87. {
  88. Robots.Add(new RobotPointStore(info.Id, info.RobotName));
  89. }
  90. }
  91. /// <summary>
  92. /// 深拷贝
  93. /// </summary>
  94. /// <returns>新的 RobotPoint 实例</returns>
  95. public RobotPoint Clone()
  96. {
  97. return JsonConvert.DeserializeObject<RobotPoint>(JsonConvert.SerializeObject(this));
  98. }
  99. }
  100. /// <summary>
  101. /// 机器人点位的容器
  102. /// </summary>
  103. public class RobotPointStore : TeamAAS.BindableBase
  104. {
  105. private Guid _id;
  106. /// <summary>
  107. /// 机器人唯一 Id(可用 GUID 或自定义字符串)
  108. /// </summary>
  109. public Guid Id
  110. {
  111. get => _id;
  112. set => SetProperty(ref _id, value);
  113. }
  114. private string _name;
  115. /// <summary>
  116. /// 机器人名称
  117. /// </summary>
  118. public string Name
  119. {
  120. get => _name;
  121. set => SetProperty(ref _name, value);
  122. }
  123. private ObservableCollection<RPoint> _Points;
  124. /// <summary>
  125. /// 点位集合
  126. /// </summary>
  127. public ObservableCollection<RPoint> Points
  128. {
  129. get { return _Points; }
  130. set { SetProperty(ref _Points, value); }
  131. }
  132. private ObservableCollection<Pallet> _pallets;
  133. /// <summary>
  134. /// 托盘集合
  135. /// </summary>
  136. public ObservableCollection<Pallet> Pallets
  137. {
  138. get => _pallets;
  139. set => SetProperty(ref _pallets, value);
  140. }
  141. public RobotPointStore()
  142. {
  143. Points = new ObservableCollection<RPoint>();
  144. Pallets=new ObservableCollection<Pallet>();
  145. }
  146. public RobotPointStore(Guid id, string name)
  147. {
  148. Id = id;
  149. Name = name;
  150. Points = new ObservableCollection<RPoint>();
  151. Pallets = new ObservableCollection<Pallet>();
  152. for (int i = 0; i < 1000; i++)
  153. {
  154. Points.Add(new RPoint(i));
  155. }
  156. }
  157. }
  158. }