ProductModel.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using Newtonsoft.Json;
  2. using NPOI.Util;
  3. using Prism.Mvvm;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using TeamAAS_VP.Models.Product;
  11. using TeamAAS_VP.Models.Robot;
  12. namespace TeamAAS_VP.Models
  13. {
  14. [JsonObject(MemberSerialization.OptOut)]
  15. public class ProductModel : BindableBase
  16. {
  17. private Guid _ID;
  18. public Guid ID
  19. {
  20. get { return _ID; }
  21. set { SetProperty(ref _ID, value); }
  22. }
  23. private string _Name;
  24. public string Name
  25. {
  26. get { return _Name; }
  27. set { SetProperty(ref _Name, value); }
  28. }
  29. private int _NumberCode;
  30. public int NumberCode
  31. {
  32. get { return _NumberCode; }
  33. set
  34. {
  35. SetProperty(ref _NumberCode, value);
  36. }
  37. }
  38. private string _Description;
  39. public string Description
  40. {
  41. get { return _Description; }
  42. set { SetProperty(ref _Description, value); }
  43. }
  44. private DateTime _DateTime;
  45. public DateTime DateTime
  46. {
  47. get { return _DateTime; }
  48. set { SetProperty(ref _DateTime, value); }
  49. }
  50. private ObservableCollection<CameraProcedure> _CameraProcedures;
  51. /// <summary>
  52. /// 相机流程集合
  53. /// </summary>
  54. public ObservableCollection<CameraProcedure> CameraProcedures
  55. {
  56. get { return _CameraProcedures; }
  57. set { SetProperty(ref _CameraProcedures, value); }
  58. }
  59. private CameraProcedure _SelectedProcedure;
  60. public CameraProcedure SelectedProcedure
  61. {
  62. get { return _SelectedProcedure; }
  63. set { SetProperty(ref _SelectedProcedure, value); }
  64. }
  65. private RobotPoint _RobotPoint;
  66. /// <summary>
  67. /// 机器人点位表
  68. /// </summary>
  69. public RobotPoint RobotPoint
  70. {
  71. get { return _RobotPoint; }
  72. set { SetProperty(ref _RobotPoint, value); }
  73. }
  74. private int _Speed;
  75. /// <summary>
  76. /// PTP速度
  77. /// </summary>
  78. public int Speed
  79. {
  80. get { return _Speed; }
  81. set { SetProperty(ref _Speed, value); }
  82. }
  83. private int _Accel;
  84. /// <summary>
  85. /// PTP加减速度
  86. /// </summary>
  87. public int Accel
  88. {
  89. get { return _Accel; }
  90. set { SetProperty(ref _Accel, value); }
  91. }
  92. private int _Speeds;
  93. /// <summary>
  94. /// CP速度
  95. /// </summary>
  96. public int Speeds
  97. {
  98. get { return _Speeds; }
  99. set { SetProperty(ref _Speeds, value); }
  100. }
  101. private int _Accels;
  102. /// <summary>
  103. /// CP加减速度
  104. /// </summary>
  105. public int Accels
  106. {
  107. get { return _Accels; }
  108. set { SetProperty(ref _Accels, value); }
  109. }
  110. private bool _Power;
  111. /// <summary>
  112. /// 功率
  113. /// </summary>
  114. public bool Power
  115. {
  116. get { return _Power; }
  117. set { SetProperty(ref _Power, value); }
  118. }
  119. private bool _IsUserUpCamera;
  120. /// <summary>
  121. /// 启用二次定位相机
  122. /// </summary>
  123. public bool IsUserUpCamera
  124. {
  125. get { return _IsUserUpCamera; }
  126. set { SetProperty(ref _IsUserUpCamera, value); }
  127. }
  128. private ObservableCollection<ProductGlobalParam> _GlobalParamListCollection;
  129. /// <summary>
  130. /// 产品全局参数集合
  131. /// </summary>
  132. public ObservableCollection<ProductGlobalParam> GlobalParamListCollection
  133. {
  134. get { return _GlobalParamListCollection; }
  135. set { SetProperty(ref _GlobalParamListCollection, value); }
  136. }
  137. private bool _IsLoad;
  138. /// <summary>
  139. /// 是否已加载
  140. /// </summary>
  141. [JsonIgnore]
  142. public bool IsLoad
  143. {
  144. get { return _IsLoad; }
  145. set { SetProperty(ref _IsLoad, value); }
  146. }
  147. private bool _IsCreate;
  148. /// <summary>
  149. /// 正在创建
  150. /// </summary>
  151. [JsonIgnore]
  152. public bool IsCreate
  153. {
  154. get { return _IsCreate; }
  155. set { SetProperty(ref _IsCreate, value); }
  156. }
  157. /// <summary>
  158. /// 增加相机流程
  159. /// </summary>
  160. /// <param name="cameraProcedure"></param>
  161. /// <exception cref="Exception"></exception>
  162. public void AddCameraProcedure(CameraProcedure cameraProcedure)
  163. {
  164. if (CameraProcedures == null)
  165. {
  166. CameraProcedures = new ObservableCollection<CameraProcedure>();
  167. }
  168. //判断是否已存在相同相机的流程
  169. if (CameraProcedures.Any(cp => cp.ID == cameraProcedure.ID))
  170. {
  171. throw new Exception("已存在相同相机的流程,无法添加重复相机流程!");
  172. }
  173. CameraProcedures.Add(cameraProcedure);
  174. }
  175. /// <summary>
  176. /// 移除相机流程
  177. /// </summary>
  178. /// <param name="id"></param>
  179. public void RemoveCameraProcedure(Guid id)
  180. {
  181. var procedure = CameraProcedures.FirstOrDefault(cp => cp.ID == id);
  182. if (procedure != null)
  183. {
  184. CameraProcedures.Remove(procedure);
  185. }
  186. }
  187. /// <summary>
  188. /// 增加全局参数
  189. /// </summary>
  190. /// <param name="globalParam"></param>
  191. public void AddGlobalParam(ProductGlobalParam globalParam)
  192. {
  193. if (GlobalParamListCollection == null)
  194. {
  195. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>();
  196. }
  197. globalParam.Number= GlobalParamListCollection.Count + 1;
  198. GlobalParamListCollection.Add(globalParam);
  199. }
  200. /// <summary>
  201. /// 移除全局参数
  202. /// </summary>
  203. /// <param name="globalParam"></param>
  204. public void RemoveGlobalParam(ProductGlobalParam globalParam)
  205. {
  206. GlobalParamListCollection.Remove(globalParam);
  207. //重新编号
  208. int number = 1;
  209. //先排序
  210. var sortedList = GlobalParamListCollection.OrderBy(gp => gp.Number).ToList();
  211. foreach (var gp in sortedList)
  212. {
  213. gp.Number = number;
  214. number++;
  215. }
  216. GlobalParamListCollection=new ObservableCollection<ProductGlobalParam>(sortedList);
  217. }
  218. public ProductModel Clone()
  219. {
  220. return new ProductModel
  221. {
  222. ID = this.ID,
  223. Name = this.Name,
  224. NumberCode = this.NumberCode,
  225. Description = this.Description,
  226. DateTime = this.DateTime,
  227. CameraProcedures = new ObservableCollection<CameraProcedure>(this.CameraProcedures.Select(cp => cp.Clone())),
  228. RobotPoint = this.RobotPoint?.Clone(),
  229. Speed = this.Speed,
  230. Accel = this.Accel,
  231. Speeds = this.Speeds,
  232. Accels = this.Accels,
  233. Power = this.Power,
  234. IsUserUpCamera = this.IsUserUpCamera,
  235. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>(this.GlobalParamListCollection.Select(gp => gp.Copy())),
  236. IsLoad = this.IsLoad,
  237. IsCreate = this.IsCreate
  238. };
  239. }
  240. }
  241. }