using Cognex.VisionPro.ToolBlock; using Newtonsoft.Json; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using TeamAAS_VP.Enums; using TeamAAS_VP.Models.Feeder; using TeamAAS_VP.Models.Lights; using TeamAAS_VP.Models.Product; namespace TeamAAS_VP.Models { /// /// 流程模型 /// [JsonObject(MemberSerialization.OptOut)] public class ProcedureModel : BindableBase { public Guid Id { get; set; } /// /// 流程名称 /// public string Name { get; set; } public string CameraName { get; set; } /// /// 视觉图像处理模式 /// public VisionModel VisionModel { get; set; } /// /// 触发相机命令 /// public string TriggerCommand { get; set; } /// /// 机器人 /// public Guid RobotId { get; set; } /// /// Feeder /// public Guid FeederId { get; set; } /// /// Camera /// public Guid CameraId { get; set; } /// /// 校准 /// public Guid CalibrationId { get; set; } private ObservableCollection _ProcedureOutputs; /// /// 视觉流程输出集合 /// public ObservableCollection ProcedureOutputs { get { return _ProcedureOutputs; } set { SetProperty(ref _ProcedureOutputs, value); } } private string _OutputSeparator = ";"; /// /// 视觉流程输出项之间的分割符 /// public string OutputSeparator { get { return _OutputSeparator; } set { SetProperty(ref _OutputSeparator, value); } } private FeederWorks _FeederWorks; /// /// Feeder振动集合 /// public FeederWorks FeederWorks { get { return _FeederWorks; } set { SetProperty(ref _FeederWorks, value); } } private FeederStockWorks _FeederStockWorks; /// /// Feeder料仓振动集合 /// public FeederStockWorks FeederStockWorks { get { return _FeederStockWorks; } set { SetProperty(ref _FeederStockWorks, value); } } private double _MinArea; /// /// Blob最小面积 /// public double MinArea { get { return _MinArea; } set { SetProperty(ref _MinArea, value); } } private int _LightValue; /// /// 亮度 /// public int LightValue { get { return _LightValue; } set { SetProperty(ref _LightValue, value); } } private float _ExposureTime; /// /// 相机曝光时间 /// public float ExposureTime { get { return _ExposureTime; } set { SetProperty(ref _ExposureTime, value); } } private float _Gain; /// /// 相机增益 /// public float Gain { get { return _Gain; } set { SetProperty(ref _Gain, value); } } private CogToolBlock _ToolBlock; /// /// 工具组 /// [JsonIgnore] public CogToolBlock ToolBlock { get { return _ToolBlock; } set { SetProperty(ref _ToolBlock, value); } } private ObservableCollection _ToolInfo = new ObservableCollection(); /// /// 工具末端的补偿 /// public ObservableCollection ToolInfo { get { return _ToolInfo; } set { SetProperty(ref _ToolInfo, value); } } private int _WaitPhoto; /// /// 延时拍照时长(ms) /// public int WaitPhoto { get { return _WaitPhoto; } set { SetProperty(ref _WaitPhoto, value); } } private int _WaitFeederStop; /// /// 等待震动盘静止时长(ms) /// public int WaitFeederStop { get { return _WaitFeederStop; } set { SetProperty(ref _WaitFeederStop, value); } } private VibrationModel _VibrationModel; /// /// 振动模式 /// public VibrationModel VibrationModel { get { return _VibrationModel; } set { SetProperty(ref _VibrationModel, value); } } private int _FeederFailLimit; /// /// 拍照失败Feeder振动最大次数 /// public int FeederFailLimit { get { return _FeederFailLimit; } set { SetProperty(ref _FeederFailLimit, value); } } private OutputPointMode _OutputPointMode; /// /// 点位发送的模式 /// public OutputPointMode OutputPointMode { get { return _OutputPointMode; } set { SetProperty(ref _OutputPointMode, value); } } private int _OutputPointCountMax = 100; /// /// 每次发送给机器人的点数最大值 /// public int OutputPointCountMax { get { return _OutputPointCountMax; } set { SetProperty(ref _OutputPointCountMax, value); } } private bool _IsExcludeNearPoint; /// /// 是否剔除本次识别到的物料与上一次识别到的物料位置过近的点 /// public bool IsExcludeNearPoint { get { return _IsExcludeNearPoint; } set { SetProperty(ref _IsExcludeNearPoint, value); } } private double _ExcludeNearPointThreshol = 1; /// /// 物料位置过近阈值 /// public double ExcludeNearPointThreshol { get { return _ExcludeNearPointThreshol; } set { SetProperty(ref _ExcludeNearPointThreshol, value); } } private bool _IsSaveImage; /// /// 保存图像 /// public bool IsSaveImage { get { return _IsSaveImage; } set { SetProperty(ref _IsSaveImage, value); } } private ProcedureSaveImageModel _SaveImageModel; /// /// 存图模式 /// public ProcedureSaveImageModel SaveImageModel { get { return _SaveImageModel; } set { SetProperty(ref _SaveImageModel, value); } } private ProcedureSaveImagePathModel _SaveImagePathModel; /// /// 存图路径模式 /// public ProcedureSaveImagePathModel SaveImagePathModel { get { return _SaveImagePathModel; } set { SetProperty(ref _SaveImagePathModel, value); } } private string _SavePath; /// /// 存图路径 /// public string SavePath { get { return _SavePath; } set { SetProperty(ref _SavePath, value); } } //用户定义的图片文件名格式,例如:{ProductSN}_Daisy_KB Screw _01 _{CameraName}-Locate_{ShotCount}_WhiteRingLight_{Result}_{DateTime:yyyy-MM-dd_HH-mm-ss}.png private string _ImageFileNameFormat; /// /// 用户定义的图片文件名格式,例如:{ProductSN}_Daisy_KB Screw _01 _{CameraName}-Locate_{ShotCount}_WhiteRingLight_{Result}_{DateTime:yyyy-MM-dd_HH-mm-ss}.png /// public string ImageFileNameFormat { get { return _ImageFileNameFormat; } set { SetProperty(ref _ImageFileNameFormat, value); } } private bool _IsCompress; /// /// 是否压缩图片 /// public bool IsCompress { get { return _IsCompress; } set { SetProperty(ref _IsCompress, value); } } private bool _IsDelaySaveImage; /// /// 是否延迟保存图片 /// public bool IsDelaySaveImage { get { return _IsDelaySaveImage; } set { SetProperty(ref _IsDelaySaveImage, value); } } private FeederFrequencyModel _FeederFindFrequency; /// /// Feeder自动寻频配置 /// public FeederFrequencyModel FeederFindFrequency { get { return _FeederFindFrequency; } set { SetProperty(ref _FeederFindFrequency, value); } } private ObservableCollection _UserDefineParameters; /// /// 用户自定义参数 /// public ObservableCollection UserDefineParameters { get { return _UserDefineParameters; } set { SetProperty(ref _UserDefineParameters, value); } } private bool _IsControlLightChannels; /// /// 是否控制光源通道亮灭 /// public bool IsControlLightChannels { get { return _IsControlLightChannels; } set { SetProperty(ref _IsControlLightChannels, value); } } private ObservableCollection _LightChannels; /// /// 光源通道配置集合。每个流程可配置多个光源通道及其默认亮度。 /// public ObservableCollection LightChannels { get { return _LightChannels; } set { SetProperty(ref _LightChannels, value); } } #region 运行时的一些临时记忆 /// /// 最后一次的Blob面积值 /// [JsonIgnore] public double LastBlobArea { get; set; } = 0; /// /// 最后一次运行的点数据 /// [JsonIgnore] public List LastRunPoints { get; set; } = new List(); #endregion public ProcedureModel() { Id = Guid.NewGuid(); ProcedureOutputs = new ObservableCollection(); ToolInfo = new ObservableCollection(); FeederFindFrequency = new FeederFrequencyModel(); UserDefineParameters = new ObservableCollection(); FeederWorks = new FeederWorks(); FeederStockWorks = new FeederStockWorks(); LightChannels = new ObservableCollection(); } public ProcedureModel(string name, string cameraName, Guid cameraId) { Id = Guid.NewGuid(); Name = name; CameraName = cameraName; CameraId = cameraId; ProcedureOutputs = new ObservableCollection(); ToolInfo = new ObservableCollection(); FeederFindFrequency = new FeederFrequencyModel(); UserDefineParameters = new ObservableCollection(); FeederWorks = new FeederWorks(); FeederStockWorks = new FeederStockWorks(); LightChannels = new ObservableCollection(); } public ProcedureModel Clone() { return new ProcedureModel { Id = this.Id, Name = this.Name, CameraName = this.CameraName, VisionModel = this.VisionModel, TriggerCommand = this.TriggerCommand, RobotId = this.RobotId, FeederId = this.FeederId, CameraId = this.CameraId, CalibrationId = this.CalibrationId, ProcedureOutputs = new ObservableCollection(this.ProcedureOutputs.Select(po => po.Copy())), FeederWorks = this.FeederWorks?.Copy(), FeederStockWorks = this.FeederStockWorks?.Copy(), MinArea = this.MinArea, LightValue = this.LightValue, ExposureTime = this.ExposureTime, Gain = this.Gain, // ToolBlock不克隆 ToolInfo = new ObservableCollection(this.ToolInfo.Select(ti => ti.Copy())), WaitPhoto = this.WaitPhoto, WaitFeederStop = this.WaitFeederStop, VibrationModel = this.VibrationModel, FeederFailLimit = this.FeederFailLimit, OutputPointCountMax = this.OutputPointCountMax, IsSaveImage = this.IsSaveImage, SaveImageModel = this.SaveImageModel, SaveImagePathModel = this.SaveImagePathModel, SavePath = this.SavePath, ImageFileNameFormat = this.ImageFileNameFormat, IsCompress = this.IsCompress, IsDelaySaveImage = this.IsDelaySaveImage, FeederFindFrequency = this.FeederFindFrequency?.Copy(), IsExcludeNearPoint = this.IsExcludeNearPoint, ExcludeNearPointThreshol = this.ExcludeNearPointThreshol, OutputPointMode = this.OutputPointMode, OutputSeparator = this.OutputSeparator, UserDefineParameters = new ObservableCollection(this.UserDefineParameters.Select(udp => udp.Copy())), LightChannels = this.LightChannels == null ? new ObservableCollection() : new ObservableCollection(this.LightChannels.Select(ch => new ChannelConfig { Name = ch.Name, Description = ch.Description, LocalIndex = ch.LocalIndex, GlobalIndex = ch.GlobalIndex, DefaultBrightness = ch.DefaultBrightness })), }; } } }