RobotPoint.cs 5.1 KB

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