ProductModel.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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. /// <summary>
  148. /// 固定向上的相机模板角度
  149. /// </summary>
  150. private double _FixedUpCameraTempletAngle;
  151. public double FixedUpCameraTempletAngle
  152. {
  153. get { return _FixedUpCameraTempletAngle; }
  154. set { SetProperty(ref _FixedUpCameraTempletAngle, value); }
  155. }
  156. private Guid _FixedDownCamera1ProcedureId;
  157. /// <summary>
  158. /// 固定向下相机取料流程ID
  159. /// </summary>
  160. public Guid FixedDownCamera1ProcedureId
  161. {
  162. get { return _FixedDownCamera1ProcedureId; }
  163. set { SetProperty(ref _FixedDownCamera1ProcedureId, value); }
  164. }
  165. private Guid _FixedDownCamera2ProcedureId;
  166. /// <summary>
  167. /// 固定向下相机取料流程ID
  168. /// </summary>
  169. public Guid FixedDownCamera2ProcedureId
  170. {
  171. get { return _FixedDownCamera2ProcedureId; }
  172. set { SetProperty(ref _FixedDownCamera2ProcedureId, value); }
  173. }
  174. private Guid _MoveDownCamera1LockPhotoProcedureId;
  175. /// <summary>
  176. /// 移动向下相机1锁付拍照流程ID
  177. /// </summary>
  178. public Guid MoveDownCamera1LockPhotoProcedureId
  179. {
  180. get { return _MoveDownCamera1LockPhotoProcedureId; }
  181. set { SetProperty(ref _MoveDownCamera1LockPhotoProcedureId, value); }
  182. }
  183. private Guid _MoveDownCamera2LockPhotoProcedureId;
  184. /// <summary>
  185. /// 移动向下相机2锁付拍照流程ID
  186. /// </summary>
  187. public Guid MoveDownCamera2LockPhotoProcedureId
  188. {
  189. get { return _MoveDownCamera2LockPhotoProcedureId; }
  190. set { SetProperty(ref _MoveDownCamera2LockPhotoProcedureId, value); }
  191. }
  192. private Guid _MoveDownCamer1PickPhotoProcedureId;
  193. /// <summary>
  194. /// 移动向下相机1取料拍照流程ID
  195. /// </summary>
  196. public Guid MoveDownCamer1PickPhotoProcedureId
  197. {
  198. get { return _MoveDownCamer1PickPhotoProcedureId; }
  199. set { SetProperty(ref _MoveDownCamer1PickPhotoProcedureId, value); }
  200. }
  201. private Guid _MoveDownCamer2PickPhotoProcedureId;
  202. /// <summary>
  203. /// 移动向下相机2取料拍照流程ID
  204. /// </summary>
  205. public Guid MoveDownCamer2PickPhotoProcedureId
  206. {
  207. get { return _MoveDownCamer2PickPhotoProcedureId; }
  208. set { SetProperty(ref _MoveDownCamer2PickPhotoProcedureId, value); }
  209. }
  210. private Guid _IndependentCamer1ProductProcedureId;
  211. /// <summary>
  212. /// 独立移动模组相机1产品定位拍照流程ID
  213. /// </summary>
  214. public Guid IndependentCamer1ProductProcedureId
  215. {
  216. get { return _IndependentCamer1ProductProcedureId; }
  217. set { SetProperty(ref _IndependentCamer1ProductProcedureId, value); }
  218. }
  219. private Guid _IndependentCamer2ProductProcedureId;
  220. /// <summary>
  221. /// 独立移动模组相机2产品定位拍照流程ID
  222. /// </summary>
  223. public Guid IndependentCamer2ProductProcedureId
  224. {
  225. get { return _IndependentCamer2ProductProcedureId; }
  226. set { SetProperty(ref _IndependentCamer2ProductProcedureId, value); }
  227. }
  228. private Guid _IndependentCamer3ProductProcedureId;
  229. /// <summary>
  230. /// 独立移动模组相机3产品定位拍照流程ID
  231. /// </summary>
  232. public Guid IndependentCamer3ProductProcedureId
  233. {
  234. get { return _IndependentCamer3ProductProcedureId; }
  235. set { SetProperty(ref _IndependentCamer3ProductProcedureId, value); }
  236. }
  237. private Guid _IndependentCamer4ProductProcedureId;
  238. /// <summary>
  239. /// 独立移动模组相机4产品定位拍照流程ID
  240. /// </summary>
  241. public Guid IndependentCamer4ProductProcedureId
  242. {
  243. get { return _IndependentCamer4ProductProcedureId; }
  244. set { SetProperty(ref _IndependentCamer4ProductProcedureId, value); }
  245. }
  246. private Guid _IndependentCamer1AuxProcedureId;
  247. /// <summary>
  248. /// 独立移动模组相机1辅料定位拍照流程ID
  249. /// </summary>
  250. public Guid IndependentCamer1AuxProcedureId
  251. {
  252. get { return _IndependentCamer1AuxProcedureId; }
  253. set { SetProperty(ref _IndependentCamer1AuxProcedureId, value); }
  254. }
  255. private Guid _IndependentCamer2AuxProcedureId;
  256. /// <summary>
  257. /// 独立移动模组相机2辅料定位拍照流程ID
  258. /// </summary>
  259. public Guid IndependentCamer2AuxProcedureId
  260. {
  261. get { return _IndependentCamer2AuxProcedureId; }
  262. set { SetProperty(ref _IndependentCamer2AuxProcedureId, value); }
  263. }
  264. private Guid _IndependentCamer3AuxProcedureId;
  265. /// <summary>
  266. /// 独立移动模组相机3辅料定位拍照流程ID
  267. /// </summary>
  268. public Guid IndependentCamer3AuxProcedureId
  269. {
  270. get { return _IndependentCamer3AuxProcedureId; }
  271. set { SetProperty(ref _IndependentCamer3AuxProcedureId, value); }
  272. }
  273. private Guid _IndependentCamer4AuxProcedureId;
  274. /// <summary>
  275. /// 独立移动模组相机4辅料定位拍照流程ID
  276. /// </summary>
  277. public Guid IndependentCamer4AuxProcedureId
  278. {
  279. get { return _IndependentCamer2AuxProcedureId; }
  280. set { SetProperty(ref _IndependentCamer4AuxProcedureId, value); }
  281. }
  282. /// <summary>
  283. /// 移动向上的相机模板角度
  284. /// </summary>
  285. private double _MoveDownCamerTempletAngle;
  286. public double MoveDownCamerTempletAngle
  287. {
  288. get { return _MoveDownCamerTempletAngle; }
  289. set { SetProperty(ref _MoveDownCamerTempletAngle, value); }
  290. }
  291. private ObservableCollection<ProductGlobalParam> _GlobalParamListCollection;
  292. /// <summary>
  293. /// 产品全局参数集合
  294. /// </summary>
  295. public ObservableCollection<ProductGlobalParam> GlobalParamListCollection
  296. {
  297. get { return _GlobalParamListCollection; }
  298. set { SetProperty(ref _GlobalParamListCollection, value); }
  299. }
  300. private ObservableCollection<PlcPoint> _PickCameraPoints = new ObservableCollection<PlcPoint>();
  301. /// <summary>
  302. /// 取料拍照点位集合
  303. /// </summary>
  304. public ObservableCollection<PlcPoint> PickCameraPoints
  305. {
  306. get { return _PickCameraPoints; }
  307. set { SetProperty(ref _PickCameraPoints, value); }
  308. }
  309. private ObservableCollection<PlcPoint> _PickPoints = new ObservableCollection<PlcPoint>();
  310. /// <summary>
  311. /// 取料点位参数集合
  312. /// </summary>
  313. public ObservableCollection<PlcPoint> PickPoints
  314. {
  315. get { return _PickPoints; }
  316. set { SetProperty(ref _PickPoints, value); }
  317. }
  318. private ObservableCollection<PlcPoint> _SecPosCameraPoints = new ObservableCollection<PlcPoint>();
  319. /// <summary>
  320. /// 下相机二次定位点位参数集合
  321. /// </summary>
  322. public ObservableCollection<PlcPoint> SecPosCameraPoints
  323. {
  324. get { return _SecPosCameraPoints; }
  325. set { SetProperty(ref _SecPosCameraPoints, value); }
  326. }
  327. private ObservableCollection<PlcPoint> _ScrewCameraPoints = new ObservableCollection<PlcPoint>();
  328. /// <summary>
  329. /// 锁附拍照点位参数集合
  330. /// </summary>
  331. public ObservableCollection<PlcPoint> ScrewCameraPoints
  332. {
  333. get { return _ScrewCameraPoints; }
  334. set { SetProperty(ref _ScrewCameraPoints, value); }
  335. }
  336. private PlcPoint _ScrewCameraLocalPos1= new PlcPoint();
  337. /// <summary>
  338. /// 锁付拍照点1对应的产品坐标系中的点位
  339. /// </summary>
  340. public PlcPoint ScrewCameraLocalPos1
  341. {
  342. get { return _ScrewCameraLocalPos1; }
  343. set { SetProperty(ref _ScrewCameraLocalPos1, value); }
  344. }
  345. private PlcPoint _ScrewCameraLocalPos2 = new PlcPoint();
  346. /// <summary>
  347. /// 锁付拍照点2对应的产品坐标系中的点位
  348. /// </summary>
  349. public PlcPoint ScrewCameraLocalPos2
  350. {
  351. get { return _ScrewCameraLocalPos2; }
  352. set { SetProperty(ref _ScrewCameraLocalPos2, value); }
  353. }
  354. private ObservableCollection<PlcPoint> _ScrewPoints = new ObservableCollection<PlcPoint>();
  355. /// <summary>
  356. /// 锁附点位参数集合
  357. /// </summary>
  358. public ObservableCollection<PlcPoint> ScrewPoints
  359. {
  360. get { return _ScrewPoints; }
  361. set { SetProperty(ref _ScrewPoints, value); }
  362. }
  363. private ObservableCollection<PlcPoint> _CheckCameraPoints = new ObservableCollection<PlcPoint>();
  364. /// <summary>
  365. /// 复检点位参数集合
  366. /// </summary>
  367. public ObservableCollection<PlcPoint> CheckCameraPoints
  368. {
  369. get { return _CheckCameraPoints; }
  370. set { SetProperty(ref _CheckCameraPoints, value); }
  371. }
  372. private ObservableCollection<PlcPoint> _IndependentCamerPoints = new ObservableCollection<PlcPoint>();
  373. /// <summary>
  374. /// 独立移动相机步进坐标系点位
  375. /// </summary>
  376. public ObservableCollection<PlcPoint> IndependentCamerPoints
  377. {
  378. get { return _IndependentCamerPoints; }
  379. set { SetProperty(ref _IndependentCamerPoints, value); }
  380. }
  381. private bool _IsLoad;
  382. /// <summary>
  383. /// 是否已加载
  384. /// </summary>
  385. [JsonIgnore]
  386. public bool IsLoad
  387. {
  388. get { return _IsLoad; }
  389. set { SetProperty(ref _IsLoad, value); }
  390. }
  391. private bool _IsCreate;
  392. /// <summary>
  393. /// 正在创建
  394. /// </summary>
  395. [JsonIgnore]
  396. public bool IsCreate
  397. {
  398. get { return _IsCreate; }
  399. set { SetProperty(ref _IsCreate, value); }
  400. }
  401. /// <summary>
  402. /// 增加相机流程
  403. /// </summary>
  404. /// <param name="cameraProcedure"></param>
  405. /// <exception cref="Exception"></exception>
  406. public void AddCameraProcedure(CameraProcedure cameraProcedure)
  407. {
  408. if (CameraProcedures == null)
  409. {
  410. CameraProcedures = new ObservableCollection<CameraProcedure>();
  411. }
  412. //判断是否已存在相同相机的流程
  413. if (CameraProcedures.Any(cp => cp.ID == cameraProcedure.ID))
  414. {
  415. throw new Exception("已存在相同相机的流程,无法添加重复相机流程!");
  416. }
  417. CameraProcedures.Add(cameraProcedure);
  418. }
  419. /// <summary>
  420. /// 移除相机流程
  421. /// </summary>
  422. /// <param name="id"></param>
  423. public void RemoveCameraProcedure(Guid id)
  424. {
  425. var procedure = CameraProcedures.FirstOrDefault(cp => cp.ID == id);
  426. if (procedure != null)
  427. {
  428. CameraProcedures.Remove(procedure);
  429. }
  430. }
  431. /// <summary>
  432. /// 增加全局参数
  433. /// </summary>
  434. /// <param name="globalParam"></param>
  435. public void AddGlobalParam(ProductGlobalParam globalParam)
  436. {
  437. if (GlobalParamListCollection == null)
  438. {
  439. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>();
  440. }
  441. globalParam.Number= GlobalParamListCollection.Count + 1;
  442. GlobalParamListCollection.Add(globalParam);
  443. }
  444. /// <summary>
  445. /// 移除全局参数
  446. /// </summary>
  447. /// <param name="globalParam"></param>
  448. public void RemoveGlobalParam(ProductGlobalParam globalParam)
  449. {
  450. GlobalParamListCollection.Remove(globalParam);
  451. //重新编号
  452. int number = 1;
  453. //先排序
  454. var sortedList = GlobalParamListCollection.OrderBy(gp => gp.Number).ToList();
  455. foreach (var gp in sortedList)
  456. {
  457. gp.Number = number;
  458. number++;
  459. }
  460. GlobalParamListCollection=new ObservableCollection<ProductGlobalParam>(sortedList);
  461. }
  462. public ProductModel Clone()
  463. {
  464. return new ProductModel
  465. {
  466. ID = this.ID,
  467. Name = this.Name,
  468. NumberCode = this.NumberCode,
  469. Description = this.Description,
  470. DateTime = this.DateTime,
  471. CameraProcedures = new ObservableCollection<CameraProcedure>(this.CameraProcedures.Select(cp => cp.Clone())),
  472. RobotPoint = this.RobotPoint?.Clone(),
  473. Speed = this.Speed,
  474. Accel = this.Accel,
  475. Speeds = this.Speeds,
  476. Accels = this.Accels,
  477. Power = this.Power,
  478. IsUserUpCamera = this.IsUserUpCamera,
  479. GlobalParamListCollection = new ObservableCollection<ProductGlobalParam>(this.GlobalParamListCollection.Select(gp => gp.Copy())),
  480. PickCameraPoints = this.PickCameraPoints,
  481. PickPoints = this.PickPoints,
  482. SecPosCameraPoints = this.SecPosCameraPoints,
  483. ScrewCameraPoints = this.ScrewCameraPoints,
  484. ScrewPoints = this.ScrewPoints,
  485. CheckCameraPoints = this.CheckCameraPoints,
  486. IsLoad = this.IsLoad,
  487. IsCreate = this.IsCreate
  488. };
  489. }
  490. }
  491. }