ProductModel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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.PLC;
  11. using TeamAAS_VP.Models.Product;
  12. using TeamAAS_VP.Models.Robot;
  13. using TeamAAS_VP.Resources.Languages;
  14. namespace TeamAAS_VP.Models
  15. {
  16. [JsonObject(MemberSerialization.OptOut)]
  17. public class ProductModel : BindableBase
  18. {
  19. private Guid _ID;
  20. public Guid ID
  21. {
  22. get { return _ID; }
  23. set { SetProperty(ref _ID, value); }
  24. }
  25. private string _Name;
  26. public string Name
  27. {
  28. get { return _Name; }
  29. set { SetProperty(ref _Name, value); }
  30. }
  31. private int _NumberCode;
  32. public int NumberCode
  33. {
  34. get { return _NumberCode; }
  35. set
  36. {
  37. SetProperty(ref _NumberCode, value);
  38. }
  39. }
  40. private string _Description;
  41. public string Description
  42. {
  43. get { return _Description; }
  44. set { SetProperty(ref _Description, value); }
  45. }
  46. private DateTime _DateTime;
  47. public DateTime DateTime
  48. {
  49. get { return _DateTime; }
  50. set { SetProperty(ref _DateTime, value); }
  51. }
  52. private ObservableCollection<CameraProcedure> _CameraProcedures;
  53. /// <summary>
  54. /// 相机流程集合
  55. /// </summary>
  56. public ObservableCollection<CameraProcedure> CameraProcedures
  57. {
  58. get { return _CameraProcedures; }
  59. set { SetProperty(ref _CameraProcedures, value); }
  60. }
  61. private CameraProcedure _SelectedProcedure;
  62. public CameraProcedure SelectedProcedure
  63. {
  64. get { return _SelectedProcedure; }
  65. set { SetProperty(ref _SelectedProcedure, value); }
  66. }
  67. private RobotPoint _RobotPoint;
  68. /// <summary>
  69. /// 机器人点位表
  70. /// </summary>
  71. public RobotPoint RobotPoint
  72. {
  73. get { return _RobotPoint; }
  74. set { SetProperty(ref _RobotPoint, value); }
  75. }
  76. private int _Speed;
  77. /// <summary>
  78. /// PTP速度
  79. /// </summary>
  80. public int Speed
  81. {
  82. get { return _Speed; }
  83. set { SetProperty(ref _Speed, value); }
  84. }
  85. private int _Accel;
  86. /// <summary>
  87. /// PTP加减速度
  88. /// </summary>
  89. public int Accel
  90. {
  91. get { return _Accel; }
  92. set { SetProperty(ref _Accel, value); }
  93. }
  94. private int _Speeds;
  95. /// <summary>
  96. /// CP速度
  97. /// </summary>
  98. public int Speeds
  99. {
  100. get { return _Speeds; }
  101. set { SetProperty(ref _Speeds, value); }
  102. }
  103. private int _Accels;
  104. /// <summary>
  105. /// CP加减速度
  106. /// </summary>
  107. public int Accels
  108. {
  109. get { return _Accels; }
  110. set { SetProperty(ref _Accels, value); }
  111. }
  112. private bool _Power;
  113. /// <summary>
  114. /// 功率
  115. /// </summary>
  116. public bool Power
  117. {
  118. get { return _Power; }
  119. set { SetProperty(ref _Power, value); }
  120. }
  121. private bool _IsUserUpCamera;
  122. /// <summary>
  123. /// 启用二次定位相机
  124. /// </summary>
  125. public bool IsUserUpCamera
  126. {
  127. get { return _IsUserUpCamera; }
  128. set { SetProperty(ref _IsUserUpCamera, value); }
  129. }
  130. private Guid _FixedUpCamera1ProcedureId;
  131. /// <summary>
  132. /// 固定向上相机1视觉流程ID
  133. /// </summary>
  134. public Guid FixedUpCamera1ProcedureId
  135. {
  136. get { return _FixedUpCamera1ProcedureId; }
  137. set { SetProperty(ref _FixedUpCamera1ProcedureId, value); }
  138. }
  139. private Guid _FixedUpCamera2ProcedureId;
  140. /// <summary>
  141. /// 固定向上相机2视觉流程ID
  142. /// </summary>
  143. public Guid FixedUpCamera2ProcedureId
  144. {
  145. get { return _FixedUpCamera2ProcedureId; }
  146. set { SetProperty(ref _FixedUpCamera2ProcedureId, value); }
  147. }
  148. private Guid _FixedDownCameraProcedureId;
  149. /// <summary>
  150. /// 固定向下相机取料流程ID
  151. /// </summary>
  152. public Guid FixedDownCameraProcedureId
  153. {
  154. get { return _FixedDownCameraProcedureId; }
  155. set { SetProperty(ref _FixedDownCameraProcedureId, value); }
  156. }
  157. private Guid _MoveDownCameraLockPhotoProcedureId;
  158. /// <summary>
  159. /// 移动向下相机锁付拍照流程ID
  160. /// </summary>
  161. public Guid MoveDownCameraLockPhotoProcedureId
  162. {
  163. get { return _MoveDownCameraLockPhotoProcedureId; }
  164. set { SetProperty(ref _MoveDownCameraLockPhotoProcedureId, value); }
  165. }
  166. private ObservableCollection<ProductGlobalParam> _GlobalParamListCollection;
  167. /// <summary>
  168. /// 产品全局参数集合
  169. /// </summary>
  170. public ObservableCollection<ProductGlobalParam> GlobalParamListCollection
  171. {
  172. get { return _GlobalParamListCollection; }
  173. set { SetProperty(ref _GlobalParamListCollection, value); }
  174. }
  175. private ObservableCollection<PlcPoint> _PickCameraPoints = new ObservableCollection<PlcPoint>();
  176. /// <summary>
  177. /// 取料拍照点位集合
  178. /// </summary>
  179. public ObservableCollection<PlcPoint> PickCameraPoints
  180. {
  181. get { return _PickCameraPoints; }
  182. set { SetProperty(ref _PickCameraPoints, value); }
  183. }
  184. private ObservableCollection<PlcPoint> _PickPoints = new ObservableCollection<PlcPoint>();
  185. /// <summary>
  186. /// 取料点位参数集合
  187. /// </summary>
  188. public ObservableCollection<PlcPoint> PickPoints
  189. {
  190. get { return _PickPoints; }
  191. set { SetProperty(ref _PickPoints, value); }
  192. }
  193. private ObservableCollection<PlcPoint> _SecPosCameraPoints = new ObservableCollection<PlcPoint>();
  194. /// <summary>
  195. /// 下相机二次定位点位参数集合
  196. /// </summary>
  197. public ObservableCollection<PlcPoint> SecPosCameraPoints
  198. {
  199. get { return _SecPosCameraPoints; }
  200. set { SetProperty(ref _SecPosCameraPoints, value); }
  201. }
  202. private ObservableCollection<PlcPoint> _ScrewCameraPoints = new ObservableCollection<PlcPoint>();
  203. /// <summary>
  204. /// 锁附拍照点位参数集合
  205. /// </summary>
  206. public ObservableCollection<PlcPoint> ScrewCameraPoints
  207. {
  208. get { return _ScrewCameraPoints; }
  209. set { SetProperty(ref _ScrewCameraPoints, value); }
  210. }
  211. private PlcPoint _ScrewCameraLocalPos1= new PlcPoint();
  212. /// <summary>
  213. /// 锁付拍照点1对应的产品坐标系中的点位
  214. /// </summary>
  215. public PlcPoint ScrewCameraLocalPos1
  216. {
  217. get { return _ScrewCameraLocalPos1; }
  218. set { SetProperty(ref _ScrewCameraLocalPos1, value); }
  219. }
  220. private PlcPoint _ScrewCameraLocalPos2 = new PlcPoint();
  221. /// <summary>
  222. /// 锁付拍照点2对应的产品坐标系中的点位
  223. /// </summary>
  224. public PlcPoint ScrewCameraLocalPos2
  225. {
  226. get { return _ScrewCameraLocalPos2; }
  227. set { SetProperty(ref _ScrewCameraLocalPos2, value); }
  228. }
  229. private ObservableCollection<PlcPoint> _ScrewPoints = new ObservableCollection<PlcPoint>();
  230. /// <summary>
  231. /// 锁附点位参数集合
  232. /// </summary>
  233. public ObservableCollection<PlcPoint> ScrewPoints
  234. {
  235. get { return _ScrewPoints; }
  236. set { SetProperty(ref _ScrewPoints, value); }
  237. }
  238. private ObservableCollection<PlcPoint> _CheckCameraPoints = new ObservableCollection<PlcPoint>();
  239. /// <summary>
  240. /// 复检点位参数集合
  241. /// </summary>
  242. public ObservableCollection<PlcPoint> CheckCameraPoints
  243. {
  244. get { return _CheckCameraPoints; }
  245. set { SetProperty(ref _CheckCameraPoints, value); }
  246. }
  247. private ObservableCollection<PlcPoint> _QrCodePoints = new ObservableCollection<PlcPoint>();
  248. /// <summary>
  249. /// 二维码拍照点位参数集合
  250. /// </summary>
  251. public ObservableCollection<PlcPoint> QrCodePoints
  252. {
  253. get { return _QrCodePoints; }
  254. set { SetProperty(ref _QrCodePoints, value); }
  255. }
  256. private bool _IsLoad;
  257. /// <summary>
  258. /// 是否已加载
  259. /// </summary>
  260. [JsonIgnore]
  261. public bool IsLoad
  262. {
  263. get { return _IsLoad; }
  264. set { SetProperty(ref _IsLoad, value); }
  265. }
  266. private bool _IsCreate;
  267. /// <summary>
  268. /// 正在创建
  269. /// </summary>
  270. [JsonIgnore]
  271. public bool IsCreate
  272. {
  273. get { return _IsCreate; }
  274. set { SetProperty(ref _IsCreate, value); }
  275. }
  276. /// <summary>
  277. /// 增加相机流程
  278. /// </summary>
  279. /// <param name="cameraProcedure"></param>
  280. /// <exception cref="Exception"></exception>
  281. public void AddCameraProcedure(CameraProcedure cameraProcedure)
  282. {
  283. if (CameraProcedures == null)
  284. {
  285. CameraProcedures = new ObservableCollection<CameraProcedure>();
  286. }
  287. //判断是否已存在相同相机的流程
  288. if (CameraProcedures.Any(cp => cp.ID == cameraProcedure.ID))
  289. {
  290. throw new Exception(Lang.已存在相同相机的流程无法添加重复相机流程);
  291. }
  292. CameraProcedures.Add(cameraProcedure);
  293. }
  294. /// <summary>
  295. /// 移除相机流程
  296. /// </summary>
  297. /// <param name="id"></param>
  298. public void RemoveCameraProcedure(Guid id)
  299. {
  300. var procedure = CameraProcedures.FirstOrDefault(cp => cp.ID == id);
  301. if (procedure != null)
  302. {
  303. CameraProcedures.Remove(procedure);
  304. }
  305. }
  306. /// <summary>
  307. /// 增加全局参数
  308. /// </summary>
  309. /// <param name="globalParam"></param>
  310. public void AddGlobalParam(ProductGlobalParam globalParam)
  311. {
  312. if (GlobalParamListCollection == null)
  313. {
  314. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>();
  315. }
  316. globalParam.Number= GlobalParamListCollection.Count + 1;
  317. GlobalParamListCollection.Add(globalParam);
  318. }
  319. /// <summary>
  320. /// 移除全局参数
  321. /// </summary>
  322. /// <param name="globalParam"></param>
  323. public void RemoveGlobalParam(ProductGlobalParam globalParam)
  324. {
  325. GlobalParamListCollection.Remove(globalParam);
  326. //重新编号
  327. int number = 1;
  328. //先排序
  329. var sortedList = GlobalParamListCollection.OrderBy(gp => gp.Number).ToList();
  330. foreach (var gp in sortedList)
  331. {
  332. gp.Number = number;
  333. number++;
  334. }
  335. GlobalParamListCollection=new ObservableCollection<ProductGlobalParam>(sortedList);
  336. }
  337. public ProductModel Clone()
  338. {
  339. return new ProductModel
  340. {
  341. ID = this.ID,
  342. Name = this.Name,
  343. NumberCode = this.NumberCode,
  344. Description = this.Description,
  345. DateTime = this.DateTime,
  346. CameraProcedures = new ObservableCollection<CameraProcedure>(this.CameraProcedures.Select(cp => cp.Clone())),
  347. RobotPoint = this.RobotPoint?.Clone(),
  348. Speed = this.Speed,
  349. Accel = this.Accel,
  350. Speeds = this.Speeds,
  351. Accels = this.Accels,
  352. Power = this.Power,
  353. IsUserUpCamera = this.IsUserUpCamera,
  354. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>(this.GlobalParamListCollection.Select(gp => gp.Copy())),
  355. PickCameraPoints = this.PickCameraPoints,
  356. PickPoints = this.PickPoints,
  357. SecPosCameraPoints = this.SecPosCameraPoints,
  358. ScrewCameraPoints = this.ScrewCameraPoints,
  359. ScrewPoints = this.ScrewPoints,
  360. CheckCameraPoints = this.CheckCameraPoints,
  361. IsLoad = this.IsLoad,
  362. IsCreate = this.IsCreate
  363. };
  364. }
  365. }
  366. }