ProductModel.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. namespace TeamAAS_VP.Models
  14. {
  15. [JsonObject(MemberSerialization.OptOut)]
  16. public class ProductModel : BindableBase
  17. {
  18. private Guid _ID;
  19. public Guid ID
  20. {
  21. get { return _ID; }
  22. set { SetProperty(ref _ID, value); }
  23. }
  24. private string _Name;
  25. public string Name
  26. {
  27. get { return _Name; }
  28. set { SetProperty(ref _Name, value); }
  29. }
  30. private int _NumberCode;
  31. public int NumberCode
  32. {
  33. get { return _NumberCode; }
  34. set
  35. {
  36. SetProperty(ref _NumberCode, value);
  37. }
  38. }
  39. private string _Description;
  40. public string Description
  41. {
  42. get { return _Description; }
  43. set { SetProperty(ref _Description, value); }
  44. }
  45. private DateTime _DateTime;
  46. public DateTime DateTime
  47. {
  48. get { return _DateTime; }
  49. set { SetProperty(ref _DateTime, value); }
  50. }
  51. private ObservableCollection<CameraProcedure> _CameraProcedures;
  52. /// <summary>
  53. /// 相机流程集合
  54. /// </summary>
  55. public ObservableCollection<CameraProcedure> CameraProcedures
  56. {
  57. get { return _CameraProcedures; }
  58. set { SetProperty(ref _CameraProcedures, value); }
  59. }
  60. private CameraProcedure _SelectedProcedure;
  61. public CameraProcedure SelectedProcedure
  62. {
  63. get { return _SelectedProcedure; }
  64. set { SetProperty(ref _SelectedProcedure, value); }
  65. }
  66. private RobotPoint _RobotPoint;
  67. /// <summary>
  68. /// 机器人点位表
  69. /// </summary>
  70. public RobotPoint RobotPoint
  71. {
  72. get { return _RobotPoint; }
  73. set { SetProperty(ref _RobotPoint, value); }
  74. }
  75. private int _Speed;
  76. /// <summary>
  77. /// PTP速度
  78. /// </summary>
  79. public int Speed
  80. {
  81. get { return _Speed; }
  82. set { SetProperty(ref _Speed, value); }
  83. }
  84. private int _Accel;
  85. /// <summary>
  86. /// PTP加减速度
  87. /// </summary>
  88. public int Accel
  89. {
  90. get { return _Accel; }
  91. set { SetProperty(ref _Accel, value); }
  92. }
  93. private int _Speeds;
  94. /// <summary>
  95. /// CP速度
  96. /// </summary>
  97. public int Speeds
  98. {
  99. get { return _Speeds; }
  100. set { SetProperty(ref _Speeds, value); }
  101. }
  102. private int _Accels;
  103. /// <summary>
  104. /// CP加减速度
  105. /// </summary>
  106. public int Accels
  107. {
  108. get { return _Accels; }
  109. set { SetProperty(ref _Accels, value); }
  110. }
  111. private bool _Power;
  112. /// <summary>
  113. /// 功率
  114. /// </summary>
  115. public bool Power
  116. {
  117. get { return _Power; }
  118. set { SetProperty(ref _Power, value); }
  119. }
  120. private bool _IsUserUpCamera;
  121. /// <summary>
  122. /// 启用二次定位相机
  123. /// </summary>
  124. public bool IsUserUpCamera
  125. {
  126. get { return _IsUserUpCamera; }
  127. set { SetProperty(ref _IsUserUpCamera, value); }
  128. }
  129. private Guid _FixedUpCamera1ProcedureId;
  130. /// <summary>
  131. /// 固定向上相机1视觉流程ID
  132. /// </summary>
  133. public Guid FixedUpCamera1ProcedureId
  134. {
  135. get { return _FixedUpCamera1ProcedureId; }
  136. set { SetProperty(ref _FixedUpCamera1ProcedureId, value); }
  137. }
  138. private Guid _FixedUpCamera2ProcedureId;
  139. /// <summary>
  140. /// 固定向上相机2视觉流程ID
  141. /// </summary>
  142. public Guid FixedUpCamera2ProcedureId
  143. {
  144. get { return _FixedUpCamera2ProcedureId; }
  145. set { SetProperty(ref _FixedUpCamera2ProcedureId, value); }
  146. }
  147. // 二维码扫码流程ID
  148. private Guid _QrCodeProcedureId;
  149. public Guid QrCodeProcedureId
  150. {
  151. get { return _QrCodeProcedureId; }
  152. set { SetProperty(ref _QrCodeProcedureId, value); }
  153. }
  154. /// <summary>
  155. /// 固定向上的相机模板角度
  156. /// </summary>
  157. private double _FixedUpCameraTempletAngle;
  158. public double FixedUpCameraTempletAngle
  159. {
  160. get { return _FixedUpCameraTempletAngle; }
  161. set { SetProperty(ref _FixedUpCameraTempletAngle, value); }
  162. }
  163. private Guid _FixedDownCamera1ProcedureId;
  164. /// <summary>
  165. /// 固定向下相机取料流程ID
  166. /// </summary>
  167. public Guid FixedDownCamera1ProcedureId
  168. {
  169. get { return _FixedDownCamera1ProcedureId; }
  170. set { SetProperty(ref _FixedDownCamera1ProcedureId, value); }
  171. }
  172. private Guid _FixedDownCamera2ProcedureId;
  173. /// <summary>
  174. /// 固定向下相机取料流程ID
  175. /// </summary>
  176. public Guid FixedDownCamera2ProcedureId
  177. {
  178. get { return _FixedDownCamera2ProcedureId; }
  179. set { SetProperty(ref _FixedDownCamera2ProcedureId, value); }
  180. }
  181. private Guid _MoveDownCamera1LockPhotoProcedureId;
  182. /// <summary>
  183. /// 移动向下相机1锁付拍照流程ID
  184. /// </summary>
  185. public Guid MoveDownCamera1LockPhotoProcedureId
  186. {
  187. get { return _MoveDownCamera1LockPhotoProcedureId; }
  188. set { SetProperty(ref _MoveDownCamera1LockPhotoProcedureId, value); }
  189. }
  190. private Guid _MoveDownCamera2LockPhotoProcedureId;
  191. /// <summary>
  192. /// 移动向下相机2锁付拍照流程ID
  193. /// </summary>
  194. public Guid MoveDownCamera2LockPhotoProcedureId
  195. {
  196. get { return _MoveDownCamera2LockPhotoProcedureId; }
  197. set { SetProperty(ref _MoveDownCamera2LockPhotoProcedureId, value); }
  198. }
  199. private Guid _MoveDownCamer1PickPhotoProcedureId;
  200. /// <summary>
  201. /// 移动向下相机1取料拍照流程ID
  202. /// </summary>
  203. public Guid MoveDownCamer1PickPhotoProcedureId
  204. {
  205. get { return _MoveDownCamer1PickPhotoProcedureId; }
  206. set { SetProperty(ref _MoveDownCamer1PickPhotoProcedureId, value); }
  207. }
  208. private Guid _MoveDownCamer2PickPhotoProcedureId;
  209. /// <summary>
  210. /// 移动向下相机2取料拍照流程ID
  211. /// </summary>
  212. public Guid MoveDownCamer2PickPhotoProcedureId
  213. {
  214. get { return _MoveDownCamer2PickPhotoProcedureId; }
  215. set { SetProperty(ref _MoveDownCamer2PickPhotoProcedureId, value); }
  216. }
  217. private Guid _IndependentCamer1ProductProcedureId;
  218. /// <summary>
  219. /// 独立移动模组相机1产品定位拍照流程ID
  220. /// </summary>
  221. public Guid IndependentCamer1ProductProcedureId
  222. {
  223. get { return _IndependentCamer1ProductProcedureId; }
  224. set { SetProperty(ref _IndependentCamer1ProductProcedureId, value); }
  225. }
  226. private Guid _IndependentCamer2ProductProcedureId;
  227. /// <summary>
  228. /// 独立移动模组相机2产品定位拍照流程ID
  229. /// </summary>
  230. public Guid IndependentCamer2ProductProcedureId
  231. {
  232. get { return _IndependentCamer2ProductProcedureId; }
  233. set { SetProperty(ref _IndependentCamer2ProductProcedureId, value); }
  234. }
  235. private Guid _IndependentCamer3ProductProcedureId;
  236. /// <summary>
  237. /// 独立移动模组相机3产品定位拍照流程ID
  238. /// </summary>
  239. public Guid IndependentCamer3ProductProcedureId
  240. {
  241. get { return _IndependentCamer3ProductProcedureId; }
  242. set { SetProperty(ref _IndependentCamer3ProductProcedureId, value); }
  243. }
  244. private Guid _IndependentCamer4ProductProcedureId;
  245. /// <summary>
  246. /// 独立移动模组相机4产品定位拍照流程ID
  247. /// </summary>
  248. public Guid IndependentCamer4ProductProcedureId
  249. {
  250. get { return _IndependentCamer4ProductProcedureId; }
  251. set { SetProperty(ref _IndependentCamer4ProductProcedureId, value); }
  252. }
  253. private Guid _IndependentCamer1AuxProcedureId;
  254. /// <summary>
  255. /// 独立移动模组相机1辅料定位拍照流程ID
  256. /// </summary>
  257. public Guid IndependentCamer1AuxProcedureId
  258. {
  259. get { return _IndependentCamer1AuxProcedureId; }
  260. set { SetProperty(ref _IndependentCamer1AuxProcedureId, value); }
  261. }
  262. private Guid _IndependentCamer2AuxProcedureId;
  263. /// <summary>
  264. /// 独立移动模组相机2辅料定位拍照流程ID
  265. /// </summary>
  266. public Guid IndependentCamer2AuxProcedureId
  267. {
  268. get { return _IndependentCamer2AuxProcedureId; }
  269. set { SetProperty(ref _IndependentCamer2AuxProcedureId, value); }
  270. }
  271. private Guid _IndependentCamer3AuxProcedureId;
  272. /// <summary>
  273. /// 独立移动模组相机3辅料定位拍照流程ID
  274. /// </summary>
  275. public Guid IndependentCamer3AuxProcedureId
  276. {
  277. get { return _IndependentCamer3AuxProcedureId; }
  278. set { SetProperty(ref _IndependentCamer3AuxProcedureId, value); }
  279. }
  280. private Guid _IndependentCamer4AuxProcedureId;
  281. /// <summary>
  282. /// 独立移动模组相机4辅料定位拍照流程ID
  283. /// </summary>
  284. public Guid IndependentCamer4AuxProcedureId
  285. {
  286. get { return _IndependentCamer4AuxProcedureId; }
  287. set { SetProperty(ref _IndependentCamer4AuxProcedureId, value); }
  288. }
  289. private Guid _IndependentCamer1CheckProcedureId;
  290. /// <summary>
  291. /// 独立移动模组相机1检测任务拍照流程ID
  292. /// </summary>
  293. public Guid IndependentCamer1CheckProcedureId
  294. {
  295. get { return _IndependentCamer1CheckProcedureId; }
  296. set { SetProperty(ref _IndependentCamer1CheckProcedureId, value); }
  297. }
  298. private Guid _IndependentCamer2CheckProcedureId;
  299. /// <summary>
  300. /// 独立移动模组相机2检测任务拍照流程ID
  301. /// </summary>
  302. public Guid IndependentCamer2CheckProcedureId
  303. {
  304. get { return _IndependentCamer2CheckProcedureId; }
  305. set { SetProperty(ref _IndependentCamer2CheckProcedureId, value); }
  306. }
  307. private Guid _IndependentCamer3CheckProcedureId;
  308. /// <summary>
  309. /// 独立移动模组相机3检测任务拍照流程ID
  310. /// </summary>
  311. public Guid IndependentCamer3CheckProcedureId
  312. {
  313. get { return _IndependentCamer3CheckProcedureId; }
  314. set { SetProperty(ref _IndependentCamer3CheckProcedureId, value); }
  315. }
  316. private Guid _IndependentCamer4CheckProcedureId;
  317. /// <summary>
  318. /// 独立移动模组相机4检测任务拍照流程ID
  319. /// </summary>
  320. public Guid IndependentCamer4CheckProcedureId
  321. {
  322. get { return _IndependentCamer4CheckProcedureId; }
  323. set { SetProperty(ref _IndependentCamer4CheckProcedureId, value); }
  324. }
  325. /// <summary>
  326. /// 移动向上的相机模板角度
  327. /// </summary>
  328. private double _MoveDownCamerTempletAngle;
  329. public double MoveDownCamerTempletAngle
  330. {
  331. get { return _MoveDownCamerTempletAngle; }
  332. set { SetProperty(ref _MoveDownCamerTempletAngle, value); }
  333. }
  334. private ObservableCollection<ProductGlobalParam> _GlobalParamListCollection;
  335. /// <summary>
  336. /// 产品全局参数集合
  337. /// </summary>
  338. public ObservableCollection<ProductGlobalParam> GlobalParamListCollection
  339. {
  340. get { return _GlobalParamListCollection; }
  341. set { SetProperty(ref _GlobalParamListCollection, value); }
  342. }
  343. private ObservableCollection<PlcPoint> _PickCameraPoints = new ObservableCollection<PlcPoint>();
  344. /// <summary>
  345. /// 取料拍照点位集合
  346. /// </summary>
  347. public ObservableCollection<PlcPoint> PickCameraPoints
  348. {
  349. get { return _PickCameraPoints; }
  350. set { SetProperty(ref _PickCameraPoints, value); }
  351. }
  352. private ObservableCollection<PlcPoint> _PickPoints = new ObservableCollection<PlcPoint>();
  353. /// <summary>
  354. /// 取料点位参数集合
  355. /// </summary>
  356. public ObservableCollection<PlcPoint> PickPoints
  357. {
  358. get { return _PickPoints; }
  359. set { SetProperty(ref _PickPoints, value); }
  360. }
  361. private ObservableCollection<PlcPoint> _SecPosCameraPoints = new ObservableCollection<PlcPoint>();
  362. /// <summary>
  363. /// 下相机二次定位点位参数集合
  364. /// </summary>
  365. public ObservableCollection<PlcPoint> SecPosCameraPoints
  366. {
  367. get { return _SecPosCameraPoints; }
  368. set { SetProperty(ref _SecPosCameraPoints, value); }
  369. }
  370. private ObservableCollection<PlcPoint> _QrCodePoints = new ObservableCollection<PlcPoint>();
  371. /// <summary>
  372. /// 二维码拍照点位参数集合
  373. /// </summary>
  374. public ObservableCollection<PlcPoint> QrCodePoints
  375. {
  376. get { return _QrCodePoints; }
  377. set { SetProperty(ref _QrCodePoints, value); }
  378. }
  379. private ObservableCollection<PlcPoint> _ScrewCameraPoints = new ObservableCollection<PlcPoint>();
  380. /// <summary>
  381. /// 锁附拍照点位参数集合
  382. /// </summary>
  383. public ObservableCollection<PlcPoint> ScrewCameraPoints
  384. {
  385. get { return _ScrewCameraPoints; }
  386. set { SetProperty(ref _ScrewCameraPoints, value); }
  387. }
  388. private PlcPoint _ScrewCameraLocalPos1= new PlcPoint();
  389. /// <summary>
  390. /// 锁付拍照点1对应的产品坐标系中的点位
  391. /// </summary>
  392. public PlcPoint ScrewCameraLocalPos1
  393. {
  394. get { return _ScrewCameraLocalPos1; }
  395. set { SetProperty(ref _ScrewCameraLocalPos1, value); }
  396. }
  397. private PlcPoint _ScrewCameraLocalPos2 = new PlcPoint();
  398. /// <summary>
  399. /// 锁付拍照点2对应的产品坐标系中的点位
  400. /// </summary>
  401. public PlcPoint ScrewCameraLocalPos2
  402. {
  403. get { return _ScrewCameraLocalPos2; }
  404. set { SetProperty(ref _ScrewCameraLocalPos2, value); }
  405. }
  406. private ObservableCollection<PlcPoint> _ScrewPoints = new ObservableCollection<PlcPoint>();
  407. /// <summary>
  408. /// 锁附点位参数集合
  409. /// </summary>
  410. public ObservableCollection<PlcPoint> ScrewPoints
  411. {
  412. get { return _ScrewPoints; }
  413. set { SetProperty(ref _ScrewPoints, value); }
  414. }
  415. private ObservableCollection<PlcPoint> _CheckCameraPoints = new ObservableCollection<PlcPoint>();
  416. /// <summary>
  417. /// 复检点位参数集合
  418. /// </summary>
  419. public ObservableCollection<PlcPoint> CheckCameraPoints
  420. {
  421. get { return _CheckCameraPoints; }
  422. set { SetProperty(ref _CheckCameraPoints, value); }
  423. }
  424. private ObservableCollection<PlcPoint> _IndependentCamerPoints = new ObservableCollection<PlcPoint>();
  425. /// <summary>
  426. /// 独立移动相机步进坐标系点位
  427. /// </summary>
  428. public ObservableCollection<PlcPoint> IndependentCamerPoints
  429. {
  430. get { return _IndependentCamerPoints; }
  431. set { SetProperty(ref _IndependentCamerPoints, value); }
  432. }
  433. private ObservableCollection<PlcPoint> _RemovePoints = new ObservableCollection<PlcPoint>();
  434. /// <summary>
  435. /// 撕膜点位参数集合
  436. /// </summary>
  437. public ObservableCollection<PlcPoint> RemovePoints
  438. {
  439. get { return _RemovePoints; }
  440. set { SetProperty(ref _RemovePoints, value); }
  441. }
  442. private ObservableCollection<PlcPoint> _PressurePlacePoints = new ObservableCollection<PlcPoint>();
  443. /// <summary>
  444. /// 压力组装点位参数集合
  445. /// </summary>
  446. public ObservableCollection<PlcPoint> PressurePlacePoints
  447. {
  448. get { return _PressurePlacePoints; }
  449. set { SetProperty(ref _PressurePlacePoints, value); }
  450. }
  451. private bool _IsLoad;
  452. /// <summary>
  453. /// 是否已加载
  454. /// </summary>
  455. [JsonIgnore]
  456. public bool IsLoad
  457. {
  458. get { return _IsLoad; }
  459. set { SetProperty(ref _IsLoad, value); }
  460. }
  461. private bool _IsCreate;
  462. /// <summary>
  463. /// 正在创建
  464. /// </summary>
  465. [JsonIgnore]
  466. public bool IsCreate
  467. {
  468. get { return _IsCreate; }
  469. set { SetProperty(ref _IsCreate, value); }
  470. }
  471. /// <summary>
  472. /// 增加相机流程
  473. /// </summary>
  474. /// <param name="cameraProcedure"></param>
  475. /// <exception cref="Exception"></exception>
  476. public void AddCameraProcedure(CameraProcedure cameraProcedure)
  477. {
  478. if (CameraProcedures == null)
  479. {
  480. CameraProcedures = new ObservableCollection<CameraProcedure>();
  481. }
  482. //判断是否已存在相同相机的流程
  483. if (CameraProcedures.Any(cp => cp.ID == cameraProcedure.ID))
  484. {
  485. throw new Exception("已存在相同相机的流程,无法添加重复相机流程!");
  486. }
  487. CameraProcedures.Add(cameraProcedure);
  488. }
  489. /// <summary>
  490. /// 移除相机流程
  491. /// </summary>
  492. /// <param name="id"></param>
  493. public void RemoveCameraProcedure(Guid id)
  494. {
  495. var procedure = CameraProcedures.FirstOrDefault(cp => cp.ID == id);
  496. if (procedure != null)
  497. {
  498. CameraProcedures.Remove(procedure);
  499. }
  500. }
  501. /// <summary>
  502. /// 增加全局参数
  503. /// </summary>
  504. /// <param name="globalParam"></param>
  505. public void AddGlobalParam(ProductGlobalParam globalParam)
  506. {
  507. if (GlobalParamListCollection == null)
  508. {
  509. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>();
  510. }
  511. globalParam.Number= GlobalParamListCollection.Count + 1;
  512. GlobalParamListCollection.Add(globalParam);
  513. }
  514. /// <summary>
  515. /// 移除全局参数
  516. /// </summary>
  517. /// <param name="globalParam"></param>
  518. public void RemoveGlobalParam(ProductGlobalParam globalParam)
  519. {
  520. GlobalParamListCollection.Remove(globalParam);
  521. //重新编号
  522. int number = 1;
  523. //先排序
  524. var sortedList = GlobalParamListCollection.OrderBy(gp => gp.Number).ToList();
  525. foreach (var gp in sortedList)
  526. {
  527. gp.Number = number;
  528. number++;
  529. }
  530. GlobalParamListCollection=new ObservableCollection<ProductGlobalParam>(sortedList);
  531. }
  532. public ProductModel Clone()
  533. {
  534. return new ProductModel
  535. {
  536. ID = this.ID,
  537. Name = this.Name,
  538. NumberCode = this.NumberCode,
  539. Description = this.Description,
  540. DateTime = this.DateTime,
  541. CameraProcedures = new ObservableCollection<CameraProcedure>(this.CameraProcedures.Select(cp => cp.Clone())),
  542. RobotPoint = this.RobotPoint?.Clone(),
  543. Speed = this.Speed,
  544. Accel = this.Accel,
  545. Speeds = this.Speeds,
  546. Accels = this.Accels,
  547. Power = this.Power,
  548. IsUserUpCamera = this.IsUserUpCamera,
  549. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>(this.GlobalParamListCollection.Select(gp => gp.Copy())),
  550. PickCameraPoints = this.PickCameraPoints,
  551. PickPoints = this.PickPoints,
  552. SecPosCameraPoints = this.SecPosCameraPoints,
  553. ScrewCameraPoints = this.ScrewCameraPoints,
  554. ScrewPoints = this.ScrewPoints,
  555. CheckCameraPoints = this.CheckCameraPoints,
  556. IndependentCamerPoints = this.IndependentCamerPoints,
  557. RemovePoints = this.RemovePoints,
  558. PressurePlacePoints = this.PressurePlacePoints,
  559. IsLoad = this.IsLoad,
  560. IsCreate = this.IsCreate,
  561. QrCodePoints = this.QrCodePoints,
  562. };
  563. }
  564. }
  565. }