ProductModel.cs 13 KB

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