RobotPoint.cs 4.6 KB

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