ProductModel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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 ProductGlobalParamEx _GlobalParamEx = new ProductGlobalParamEx();
  140. /// <summary>
  141. /// 全局参数扩展(保压/检测上下限)
  142. /// </summary>
  143. public ProductGlobalParamEx GlobalParamEx
  144. {
  145. get { return _GlobalParamEx; }
  146. set { SetProperty(ref _GlobalParamEx, value); }
  147. }
  148. private Guid _FixedUpCamera2ProcedureId;
  149. /// <summary>
  150. /// 固定向上相机2视觉流程ID
  151. /// </summary>
  152. public Guid FixedUpCamera2ProcedureId
  153. {
  154. get { return _FixedUpCamera2ProcedureId; }
  155. set { SetProperty(ref _FixedUpCamera2ProcedureId, value); }
  156. }
  157. private Guid _FixedDownCameraProcedureId;
  158. /// <summary>
  159. /// 固定向下相机取料流程ID
  160. /// </summary>
  161. public Guid FixedDownCameraProcedureId
  162. {
  163. get { return _FixedDownCameraProcedureId; }
  164. set { SetProperty(ref _FixedDownCameraProcedureId, value); }
  165. }
  166. private Guid _MoveDownCameraLockPhotoProcedureId;
  167. /// <summary>
  168. /// 移动向下相机锁付拍照流程ID
  169. /// </summary>
  170. public Guid MoveDownCameraLockPhotoProcedureId
  171. {
  172. get { return _MoveDownCameraLockPhotoProcedureId; }
  173. set { SetProperty(ref _MoveDownCameraLockPhotoProcedureId, value); }
  174. }
  175. private Guid _FzCameraProcedureId;
  176. /// <summary>
  177. /// 翻转相机流程ID
  178. /// </summary>
  179. public Guid FzCameraProcedureId
  180. {
  181. get { return _FzCameraProcedureId; }
  182. set { SetProperty(ref _FzCameraProcedureId, value); }
  183. }
  184. // 二维码扫码流程ID
  185. private Guid _QrCodeProcedureId;
  186. public Guid QrCodeProcedureId
  187. {
  188. get { return _QrCodeProcedureId; }
  189. set { SetProperty(ref _QrCodeProcedureId, value); }
  190. }
  191. private Guid _FixedCamera1Procedure;
  192. public Guid FixedCamera1Procedure
  193. {
  194. get { return _FixedCamera1Procedure; }
  195. set { SetProperty(ref _FixedCamera1Procedure, value); }
  196. }
  197. private Guid _FixedCamera2Procedure;
  198. public Guid FixedCamera2Procedure
  199. {
  200. get { return _FixedCamera2Procedure; }
  201. set { SetProperty(ref _FixedCamera2Procedure, value); }
  202. }
  203. private ObservableCollection<ProductGlobalParam> _GlobalParamListCollection;
  204. /// <summary>
  205. /// 产品全局参数集合
  206. /// </summary>
  207. public ObservableCollection<ProductGlobalParam> GlobalParamListCollection
  208. {
  209. get { return _GlobalParamListCollection; }
  210. set { SetProperty(ref _GlobalParamListCollection, value); }
  211. }
  212. private ObservableCollection<PlcPoint> _PickCameraPoints = new ObservableCollection<PlcPoint>();
  213. /// <summary>
  214. /// 取料拍照点位集合
  215. /// </summary>
  216. public ObservableCollection<PlcPoint> PickCameraPoints
  217. {
  218. get { return _PickCameraPoints; }
  219. set { SetProperty(ref _PickCameraPoints, value); }
  220. }
  221. private ObservableCollection<PlcPoint> _PickPoints = new ObservableCollection<PlcPoint>();
  222. /// <summary>
  223. /// 取料点位参数集合
  224. /// </summary>
  225. public ObservableCollection<PlcPoint> PickPoints
  226. {
  227. get { return _PickPoints; }
  228. set { SetProperty(ref _PickPoints, value); }
  229. }
  230. private ObservableCollection<PlcPoint> _SecPosCameraPoints = new ObservableCollection<PlcPoint>();
  231. /// <summary>
  232. /// 下相机二次定位点位参数集合
  233. /// </summary>
  234. public ObservableCollection<PlcPoint> SecPosCameraPoints
  235. {
  236. get { return _SecPosCameraPoints; }
  237. set { SetProperty(ref _SecPosCameraPoints, value); }
  238. }
  239. private ObservableCollection<PlcPoint> _ScrewCameraPoints = new ObservableCollection<PlcPoint>();
  240. /// <summary>
  241. /// 锁附拍照点位参数集合
  242. /// </summary>
  243. public ObservableCollection<PlcPoint> ScrewCameraPoints
  244. {
  245. get { return _ScrewCameraPoints; }
  246. set { SetProperty(ref _ScrewCameraPoints, value); }
  247. }
  248. private PlcPoint _ScrewCameraLocalPos1= new PlcPoint();
  249. /// <summary>
  250. /// 锁付拍照点1对应的产品坐标系中的点位
  251. /// </summary>
  252. public PlcPoint ScrewCameraLocalPos1
  253. {
  254. get { return _ScrewCameraLocalPos1; }
  255. set { SetProperty(ref _ScrewCameraLocalPos1, value); }
  256. }
  257. private PlcPoint _ScrewCameraLocalPos2 = new PlcPoint();
  258. /// <summary>
  259. /// 锁付拍照点2对应的产品坐标系中的点位
  260. /// </summary>
  261. public PlcPoint ScrewCameraLocalPos2
  262. {
  263. get { return _ScrewCameraLocalPos2; }
  264. set { SetProperty(ref _ScrewCameraLocalPos2, value); }
  265. }
  266. private ObservableCollection<PlcPoint> _ScrewPoints = new ObservableCollection<PlcPoint>();
  267. /// <summary>
  268. /// 锁附点位参数集合
  269. /// </summary>
  270. public ObservableCollection<PlcPoint> ScrewPoints
  271. {
  272. get { return _ScrewPoints; }
  273. set { SetProperty(ref _ScrewPoints, value); }
  274. }
  275. private ObservableCollection<PlcPoint> _CheckCameraPoints = new ObservableCollection<PlcPoint>();
  276. /// <summary>
  277. /// 复检点位参数集合
  278. /// </summary>
  279. public ObservableCollection<PlcPoint> CheckCameraPoints
  280. {
  281. get { return _CheckCameraPoints; }
  282. set { SetProperty(ref _CheckCameraPoints, value); }
  283. }
  284. private ObservableCollection<PlcPoint> _QrCodePoints = new ObservableCollection<PlcPoint>();
  285. /// <summary>
  286. /// 二维码拍照点位参数集合
  287. /// </summary>
  288. public ObservableCollection<PlcPoint> QrCodePoints
  289. {
  290. get { return _QrCodePoints; }
  291. set { SetProperty(ref _QrCodePoints, value); }
  292. }
  293. private ObservableCollection<PlcPoint> _HotMeltPoints = new ObservableCollection<PlcPoint>();
  294. /// <summary>
  295. /// 二维码拍照点位参数集合
  296. /// </summary>
  297. public ObservableCollection<PlcPoint> HotMeltPoints
  298. {
  299. get { return _HotMeltPoints; }
  300. set { SetProperty(ref _HotMeltPoints, value); }
  301. }
  302. private ObservableCollection<PlcPoint> _HotMeltPoints1 = new ObservableCollection<PlcPoint>();
  303. /// <summary>
  304. /// 二维码拍照点位参数集合
  305. /// </summary>
  306. public ObservableCollection<PlcPoint> HotMeltPoints1
  307. {
  308. get { return _HotMeltPoints1; }
  309. set { SetProperty(ref _HotMeltPoints1, value); }
  310. }
  311. private bool _IsLoad;
  312. /// <summary>
  313. /// 是否已加载
  314. /// </summary>
  315. [JsonIgnore]
  316. public bool IsLoad
  317. {
  318. get { return _IsLoad; }
  319. set { SetProperty(ref _IsLoad, value); }
  320. }
  321. private bool _IsCreate;
  322. /// <summary>
  323. /// 正在创建
  324. /// </summary>
  325. [JsonIgnore]
  326. public bool IsCreate
  327. {
  328. get { return _IsCreate; }
  329. set { SetProperty(ref _IsCreate, value); }
  330. }
  331. /// <summary>
  332. /// 增加相机流程
  333. /// </summary>
  334. /// <param name="cameraProcedure"></param>
  335. /// <exception cref="Exception"></exception>
  336. public void AddCameraProcedure(CameraProcedure cameraProcedure)
  337. {
  338. if (CameraProcedures == null)
  339. {
  340. CameraProcedures = new ObservableCollection<CameraProcedure>();
  341. }
  342. //判断是否已存在相同相机的流程
  343. if (CameraProcedures.Any(cp => cp.ID == cameraProcedure.ID))
  344. {
  345. throw new Exception(Lang.已存在相同相机的流程无法添加重复相机流程);
  346. }
  347. CameraProcedures.Add(cameraProcedure);
  348. }
  349. /// <summary>
  350. /// 移除相机流程
  351. /// </summary>
  352. /// <param name="id"></param>
  353. public void RemoveCameraProcedure(Guid id)
  354. {
  355. var procedure = CameraProcedures.FirstOrDefault(cp => cp.ID == id);
  356. if (procedure != null)
  357. {
  358. CameraProcedures.Remove(procedure);
  359. }
  360. }
  361. /// <summary>
  362. /// 增加全局参数
  363. /// </summary>
  364. /// <param name="globalParam"></param>
  365. public void AddGlobalParam(ProductGlobalParam globalParam)
  366. {
  367. if (GlobalParamListCollection == null)
  368. {
  369. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>();
  370. }
  371. globalParam.Number= GlobalParamListCollection.Count + 1;
  372. GlobalParamListCollection.Add(globalParam);
  373. }
  374. /// <summary>
  375. /// 移除全局参数
  376. /// </summary>
  377. /// <param name="globalParam"></param>
  378. public void RemoveGlobalParam(ProductGlobalParam globalParam)
  379. {
  380. GlobalParamListCollection.Remove(globalParam);
  381. //重新编号
  382. int number = 1;
  383. //先排序
  384. var sortedList = GlobalParamListCollection.OrderBy(gp => gp.Number).ToList();
  385. foreach (var gp in sortedList)
  386. {
  387. gp.Number = number;
  388. number++;
  389. }
  390. GlobalParamListCollection=new ObservableCollection<ProductGlobalParam>(sortedList);
  391. }
  392. public ProductModel Clone()
  393. {
  394. return new ProductModel
  395. {
  396. ID = this.ID,
  397. Name = this.Name,
  398. NumberCode = this.NumberCode,
  399. Description = this.Description,
  400. DateTime = this.DateTime,
  401. CameraProcedures = new ObservableCollection<CameraProcedure>(this.CameraProcedures.Select(cp => cp.Clone())),
  402. RobotPoint = this.RobotPoint?.Clone(),
  403. Speed = this.Speed,
  404. Accel = this.Accel,
  405. Speeds = this.Speeds,
  406. Accels = this.Accels,
  407. Power = this.Power,
  408. IsUserUpCamera = this.IsUserUpCamera,
  409. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>(this.GlobalParamListCollection.Select(gp => gp.Copy())),
  410. PickCameraPoints = this.PickCameraPoints,
  411. PickPoints = this.PickPoints,
  412. SecPosCameraPoints = this.SecPosCameraPoints,
  413. ScrewCameraPoints = this.ScrewCameraPoints,
  414. ScrewCameraLocalPos1=this.ScrewCameraLocalPos1,
  415. ScrewCameraLocalPos2 = this.ScrewCameraLocalPos2,
  416. ScrewPoints = this.ScrewPoints,
  417. CheckCameraPoints = this.CheckCameraPoints,
  418. QrCodePoints=this.QrCodePoints,
  419. IsLoad = this.IsLoad,
  420. IsCreate = this.IsCreate
  421. };
  422. }
  423. }
  424. }