using Newtonsoft.Json; using NPOI.Util; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using TeamAAS_VP.Models.PLC; using TeamAAS_VP.Models.Product; using TeamAAS_VP.Models.Robot; using TeamAAS_VP.Resources.Languages; namespace TeamAAS_VP.Models { [JsonObject(MemberSerialization.OptOut)] public class ProductModel : BindableBase { private Guid _ID; public Guid ID { get { return _ID; } set { SetProperty(ref _ID, value); } } private string _Name; public string Name { get { return _Name; } set { SetProperty(ref _Name, value); } } private int _NumberCode; public int NumberCode { get { return _NumberCode; } set { SetProperty(ref _NumberCode, value); } } private string _Description; public string Description { get { return _Description; } set { SetProperty(ref _Description, value); } } private DateTime _DateTime; public DateTime DateTime { get { return _DateTime; } set { SetProperty(ref _DateTime, value); } } private ObservableCollection _CameraProcedures; /// /// 相机流程集合 /// public ObservableCollection CameraProcedures { get { return _CameraProcedures; } set { SetProperty(ref _CameraProcedures, value); } } private CameraProcedure _SelectedProcedure; public CameraProcedure SelectedProcedure { get { return _SelectedProcedure; } set { SetProperty(ref _SelectedProcedure, value); } } private RobotPoint _RobotPoint; /// /// 机器人点位表 /// public RobotPoint RobotPoint { get { return _RobotPoint; } set { SetProperty(ref _RobotPoint, value); } } private int _Speed; /// /// PTP速度 /// public int Speed { get { return _Speed; } set { SetProperty(ref _Speed, value); } } private int _Accel; /// /// PTP加减速度 /// public int Accel { get { return _Accel; } set { SetProperty(ref _Accel, value); } } private int _Speeds; /// /// CP速度 /// public int Speeds { get { return _Speeds; } set { SetProperty(ref _Speeds, value); } } private int _Accels; /// /// CP加减速度 /// public int Accels { get { return _Accels; } set { SetProperty(ref _Accels, value); } } private bool _Power; /// /// 功率 /// public bool Power { get { return _Power; } set { SetProperty(ref _Power, value); } } private bool _IsUserUpCamera; /// /// 启用二次定位相机 /// public bool IsUserUpCamera { get { return _IsUserUpCamera; } set { SetProperty(ref _IsUserUpCamera, value); } } private Guid _FixedUpCamera1ProcedureId; /// /// 固定向上相机1视觉流程ID /// public Guid FixedUpCamera1ProcedureId { get { return _FixedUpCamera1ProcedureId; } set { SetProperty(ref _FixedUpCamera1ProcedureId, value); } } private ProductGlobalParamEx _GlobalParamEx = new ProductGlobalParamEx(); /// /// 全局参数扩展(保压/检测上下限) /// public ProductGlobalParamEx GlobalParamEx { get { return _GlobalParamEx; } set { SetProperty(ref _GlobalParamEx, value); } } private Guid _FixedUpCameraProcedureId; /// /// 相机拍照螺丝复检视觉流程ID /// public Guid FixedUpCameraProcedureId { get { return _FixedUpCameraProcedureId; } set { SetProperty(ref _FixedUpCameraProcedureId, value); } } private Guid _FixedUpCamera2ProcedureId; /// /// 固定向上相机2视觉流程ID /// public Guid FixedUpCamera2ProcedureId { get { return _FixedUpCamera2ProcedureId; } set { SetProperty(ref _FixedUpCamera2ProcedureId, value); } } private Guid _FixedDownCameraProcedureId; /// /// 固定向下相机取料流程ID /// public Guid FixedDownCameraProcedureId { get { return _FixedDownCameraProcedureId; } set { SetProperty(ref _FixedDownCameraProcedureId, value); } } private Guid _MoveDownCameraLockPhotoProcedureId; /// /// 移动向下相机锁付拍照流程ID /// public Guid MoveDownCameraLockPhotoProcedureId { get { return _MoveDownCameraLockPhotoProcedureId; } set { SetProperty(ref _MoveDownCameraLockPhotoProcedureId, value); } } private Guid _FzCameraProcedureId; /// /// 翻转相机流程ID /// public Guid FzCameraProcedureId { get { return _FzCameraProcedureId; } set { SetProperty(ref _FzCameraProcedureId, value); } } // 二维码扫码流程ID private Guid _QrCodeProcedureId; public Guid QrCodeProcedureId { get { return _QrCodeProcedureId; } set { SetProperty(ref _QrCodeProcedureId, value); } } private ObservableCollection _GlobalParamListCollection; /// /// 产品全局参数集合 /// public ObservableCollection GlobalParamListCollection { get { return _GlobalParamListCollection; } set { SetProperty(ref _GlobalParamListCollection, value); } } private ObservableCollection _PickCameraPoints = new ObservableCollection(); /// /// 取料拍照点位集合 /// public ObservableCollection PickCameraPoints { get { return _PickCameraPoints; } set { SetProperty(ref _PickCameraPoints, value); } } private ObservableCollection _PickPoints = new ObservableCollection(); /// /// 取料点位参数集合 /// public ObservableCollection PickPoints { get { return _PickPoints; } set { SetProperty(ref _PickPoints, value); } } private ObservableCollection _SecPosCameraPoints = new ObservableCollection(); /// /// 下相机二次定位点位参数集合 /// public ObservableCollection SecPosCameraPoints { get { return _SecPosCameraPoints; } set { SetProperty(ref _SecPosCameraPoints, value); } } private ObservableCollection _ScrewCameraPoints = new ObservableCollection(); /// /// 锁附拍照点位参数集合 /// public ObservableCollection ScrewCameraPoints { get { return _ScrewCameraPoints; } set { SetProperty(ref _ScrewCameraPoints, value); } } private PlcPoint _ScrewCameraLocalPos1= new PlcPoint(); /// /// 锁付拍照点1对应的产品坐标系中的点位 /// public PlcPoint ScrewCameraLocalPos1 { get { return _ScrewCameraLocalPos1; } set { SetProperty(ref _ScrewCameraLocalPos1, value); } } private PlcPoint _ScrewCameraLocalPos2 = new PlcPoint(); /// /// 锁付拍照点2对应的产品坐标系中的点位 /// public PlcPoint ScrewCameraLocalPos2 { get { return _ScrewCameraLocalPos2; } set { SetProperty(ref _ScrewCameraLocalPos2, value); } } private ObservableCollection _ScrewPoints = new ObservableCollection(); /// /// 锁附点位参数集合 /// public ObservableCollection ScrewPoints { get { return _ScrewPoints; } set { SetProperty(ref _ScrewPoints, value); } } private ObservableCollection _CheckCameraPoints = new ObservableCollection(); /// /// 复检点位参数集合 /// public ObservableCollection CheckCameraPoints { get { return _CheckCameraPoints; } set { SetProperty(ref _CheckCameraPoints, value); } } private ObservableCollection _QrCodePoints = new ObservableCollection(); /// /// 二维码拍照点位参数集合 /// public ObservableCollection QrCodePoints { get { return _QrCodePoints; } set { SetProperty(ref _QrCodePoints, value); } } private bool _IsLoad; /// /// 是否已加载 /// [JsonIgnore] public bool IsLoad { get { return _IsLoad; } set { SetProperty(ref _IsLoad, value); } } private bool _IsCreate; /// /// 正在创建 /// [JsonIgnore] public bool IsCreate { get { return _IsCreate; } set { SetProperty(ref _IsCreate, value); } } /// /// 增加相机流程 /// /// /// public void AddCameraProcedure(CameraProcedure cameraProcedure) { if (CameraProcedures == null) { CameraProcedures = new ObservableCollection(); } //判断是否已存在相同相机的流程 if (CameraProcedures.Any(cp => cp.ID == cameraProcedure.ID)) { throw new Exception(Lang.已存在相同相机的流程无法添加重复相机流程); } CameraProcedures.Add(cameraProcedure); } /// /// 移除相机流程 /// /// public void RemoveCameraProcedure(Guid id) { var procedure = CameraProcedures.FirstOrDefault(cp => cp.ID == id); if (procedure != null) { CameraProcedures.Remove(procedure); } } /// /// 增加全局参数 /// /// public void AddGlobalParam(ProductGlobalParam globalParam) { if (GlobalParamListCollection == null) { GlobalParamListCollection = new ObservableCollection(); } globalParam.Number= GlobalParamListCollection.Count + 1; GlobalParamListCollection.Add(globalParam); } /// /// 移除全局参数 /// /// public void RemoveGlobalParam(ProductGlobalParam globalParam) { GlobalParamListCollection.Remove(globalParam); //重新编号 int number = 1; //先排序 var sortedList = GlobalParamListCollection.OrderBy(gp => gp.Number).ToList(); foreach (var gp in sortedList) { gp.Number = number; number++; } GlobalParamListCollection=new ObservableCollection(sortedList); } public ProductModel Clone() { return new ProductModel { ID = this.ID, Name = this.Name, NumberCode = this.NumberCode, Description = this.Description, DateTime = this.DateTime, CameraProcedures = new ObservableCollection(this.CameraProcedures.Select(cp => cp.Clone())), RobotPoint = this.RobotPoint?.Clone(), Speed = this.Speed, Accel = this.Accel, Speeds = this.Speeds, Accels = this.Accels, Power = this.Power, IsUserUpCamera = this.IsUserUpCamera, GlobalParamListCollection = new ObservableCollection(this.GlobalParamListCollection.Select(gp => gp.Copy())), PickCameraPoints = this.PickCameraPoints, PickPoints = this.PickPoints, SecPosCameraPoints = this.SecPosCameraPoints, ScrewCameraPoints = this.ScrewCameraPoints, ScrewCameraLocalPos1=this.ScrewCameraLocalPos1, ScrewCameraLocalPos2 = this.ScrewCameraLocalPos2, ScrewPoints = this.ScrewPoints, CheckCameraPoints = this.CheckCameraPoints, QrCodePoints=this.QrCodePoints, IsLoad = this.IsLoad, IsCreate = this.IsCreate }; } } }