using Autofac; using Bro.Common.Base; using Bro.Common.Helper; using Bro.Common.Interface; using Bro.Common.Model; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Bro.M071.Process { public partial class M071Process { [ProcessMethod("OfflineTest", "OfflineTest", "离线测试", InvokeType.TestInvoke)] public ProcessResponse OfflineTest(IOperationConfig opConfig, IDevice invokeDevice, IDevice sourceDevice) { if (opConfig is OfflineTestOpConfig config) { if (config.SnapshotConfigs.Count > 0) { OnMeasureStart?.Invoke(); List measurements = new List(); Config.MeasurementUnitCollection.Where(u => u.IsEnabled).ToList().ForEach(u => { var m = u.Copy(); m.InitialKeyUnitMeasureChanged(); measurements.Add(m); }); var pMeasure = new ProductionMeasurement() { Barcode = $"OfflineTest_{DateTime.Now.ToString("HHmmss")}", Measurements = measurements, StartTime = DateTime.Now, }; lock (productionLock) { var existedProduction = productionList.FirstOrDefault(u => u.Barcode == pMeasure.Barcode); if (existedProduction != null) { productionList.Remove(existedProduction); existedProduction.Dispose(); existedProduction = null; } productionList.Add(pMeasure); } pMeasure.InitialMeasurementsPropertyChanged(); pMeasure.PropertyChanged += MeasureProduction_PropertyChanged; config.SnapshotConfigs.ForEach(s => { ImageSet set = new ImageSet(); set.HImage = new HalconDotNet.HImage(s.OfflineImageFilePath); set.ImageData = JsonConvert.SerializeObject(config.ScanParam); var snapshotConfig = Config.SnapshotPointCollection.FirstOrDefault(u => u.Id == s.SnapshotPointId); RunImageHandle(snapshotConfig.CameraOp.OpConfig, set, snapshotConfig.Id, snapshotConfig.Name, pMeasure.Measurements); }); } } return new ProcessResponse(true); } } [Device("OfflineTest", "离线测试操作配置", EnumHelper.DeviceAttributeType.OperationConfig)] public class OfflineTestOpConfig : OperationConfigBase { [Category("取像设置")] [Description("取像设置")] [TypeConverter(typeof(CollectionCountConvert))] [Editor(typeof(ComplexCollectionEditor), typeof(UITypeEditor))] public List SnapshotConfigs { get; set; } = new List(); //[Category("离线图像目录")] //[Description("离线图片文件目录,目前只支持一级文件目录,该目录包含且仅包含一次完整测试需要的图片")] //[Editor(typeof(FoldDialogEditor),typeof(UITypeEditor))] //public string OfflineImageFolder { get; set; } [Category("扫描图像参数")] [Description("扫描图像参数")] [TypeConverter(typeof(ExpandableObjectConverter))] public LaserScanParam ScanParam { get; set; } = new LaserScanParam(); } public class OfflineSnapshotPoint : IComplexDisplay { [Category("取像点位及配置")] [TypeConverter(typeof(SnapshotPointConverter))] public string SnapshotPointId { get; set; } [Category("离线图像文件")] [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))] public string OfflineImageFilePath { get; set; } public string GetDisplayText() { string snapshotPointName = ""; using (var scope = GlobalVar.Container.BeginLifetimeScope()) { var config = scope.Resolve() as M071Config; if (config != null) { snapshotPointName = config.SnapshotPointCollection.FirstOrDefault(u => u.Id == SnapshotPointId)?.Name; } } if (string.IsNullOrWhiteSpace(snapshotPointName)) { snapshotPointName = "未指定"; } return snapshotPointName; } } }