ProductModel.cs 14 KB

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