ProductModel.cs 13 KB

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