M182轴承端盖外观缺陷AOI
kingno
2025-05-26 5a405c7dce20d8c79a733c9c786cc42eb59fe81c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
using Autofac;
using Bro.Common.Base;
using Bro.Common.Factory;
using Bro.Common.Helper;
using Bro.Common.Interface;
using Bro.Common.Model;
using Bro.M135.Common;
using Bro.Process;
using System.ComponentModel;
using System.Drawing.Design;
using System.Drawing.Imaging;
using System.Reflection;
using System.Windows.Forms.Design;
 
namespace Bro.M141.Process
{
    public class M141Config : ProcessConfigBase
    {
        [Category("连续NG报警设置")]
        [Description("连续NG报警总开关。true:开启连续NG报警 false:关闭连续NG报警机制")]
        [DisplayName("连续NG报警总开关")]
        public bool IsEnableContinuousNGAlarm { get; set; } = true;
 
 
        [Category("连续NG报警设置")]
        [Description("连续NG报警设置集合。设置连续NG报警的开关,类型,数量和时间阈值。添加或删除监控需要软件重启生效。")]
        [DisplayName("连续NG报警设置集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<ContinuousNGAlarm>), typeof(UITypeEditor))]
        public List<ContinuousNGAlarm> ContinuousNGAlarmColletion { get; set; } = new List<ContinuousNGAlarm>();
 
 
 
 
 
 
        [Category("点检配置")]
        [Description("点检开关")]
        [DisplayName("点检开关")]
 
        public bool PointState { get; set; } = false;
 
 
        [Category("读码数据")]
        [Description("读码数据")]
        [DisplayName("读码数据")]
 
        public string TmpPath { get; set; }
 
        [Category("读码数据")]
        [Description("读码数据")]
        [DisplayName("读码数据")]
        [TypeConverter(typeof(SimpleCollectionConvert<string>))]
        [Editor(typeof(SimpleCollectionEditor<string>), typeof(UITypeEditor))]
        [EditorBrowsable]
        public List<string> BarcodeDataList { get; set; } = new List<string>();
 
        [Category("工位信息")]
        [Description("工位信息配置集合")]
        [DisplayName("工位信息")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<WorkPositionSet>), typeof(UITypeEditor))]
        public List<WorkPositionSet> WorkPositionCollection { get; set; } = new List<WorkPositionSet>();
 
        [Category("检测配置")]
        [Description("检测配置集合,配置检测的工位,图片索引,相机和检测调用项关系")]
        [DisplayName("检测配置集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<MeasureBind>), typeof(UITypeEditor))]
        public List<MeasureBind> MeasureBindCollection { get; set; } = new List<MeasureBind>();
 
        [Category("检测配置")]
        [Description("标定集合,配置检测的工位,图片索引,相机和检测调用项关系")]
        [DisplayName("标定集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<BDMeasureBind>), typeof(UITypeEditor))]
        public List<BDMeasureBind> BDCollection { get; set; } = new List<BDMeasureBind>();
 
        [Category("检测超时设置")]
        [Description("检测超时设置,获取检测结果时的允许最大等待时间,单位ms")]
        [DisplayName("检测超时时间")]
        public int DetectTimeout { get; set; } = 1000;
 
        [Category("数据库设置")]
        [Description("数据库数据保存天数,超过该天数的数据会被自动删除。设置为0时不执行删除操作")]
        [DisplayName("数据保存天数")]
        public int DBDataTimeLimit { get; set; } = 3;
 
        [Category("数据库设置")]
        [Description("初始化数据库时的缓存队列数量")]
        [DisplayName("初始缓存数量")]
        public int DBBufferListCount { get; set; } = 10;
 
        [Category("检测异常指示")]
        [Description("选择某个Spec,其表示检测过程中异常")]
        [DisplayName("异常指示标准")]
        [TypeConverter(typeof(SpecCodeSelectorConverter))]
        public string CheckErrorSpecCode { get; set; } = "";
 
 
 
 
 
        //[Category("调试使用设置")]
        //[Description("是否允许临时产品启用,使用于不完整流程中临时接收检测数据")]
        //[DisplayName("临时产品开关")]
        //public bool IsAllowTempProduct { get; set; } = false;
 
        [Category("位置度/轮廓度设置")]
        [Description("产品测量点位集合")]
        [DisplayName("产品测量点位集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<ContourPoint>), typeof(UITypeEditor))]
        public List<ContourPoint> MeasurePointCollection { get; set; } = new List<ContourPoint>();
 
        [Category("位置度/轮廓度设置")]
        [Description("检测项配置集合,设置包含组合点位的检测项")]
        [DisplayName("检测项配置集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<MeasureItemBind>), typeof(UITypeEditor))]
        public List<MeasureItemBind> MeasureItemBinds { get; set; } = new List<MeasureItemBind>();
 
        [Category("位置度/轮廓度设置")]
        [DisplayName("轮廓点计算偏移")]
        [Description("计算轮廓点位置时的点位偏移大小,单位mm")]
        public float CountLineShift { get; set; } = 0.5f;
 
        [Category("位置度/轮廓度设置")]
        [DisplayName("测量点补偿值设置")]
        [Description("针对各工位对应产品的各检测项点,做单点补偿处理")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<Product_CheckPointsOffsetList>), typeof(UITypeEditor))]
        public List<Product_CheckPointsOffsetList> Product_PointsOffsetList { get; set; } = new List<Product_CheckPointsOffsetList>();
 
        [Category("MES配置")]
        [Description("MES上传URL地址")]
        [DisplayName("MES上传URL地址")]
        public string MESUploadURL { get; set; }
 
        [Category("MES配置")]
        [Description("true:启用MES上传 false:未启用MES上传")]
        [DisplayName("MES上传开关")]
        public bool IsEnabelMESUpload { get; set; } = false;
 
        [Category("MES配置")]
        [Description("MES上传项目代码,代表Project")]
        [DisplayName("MES站点代码")]
        public string MESProjectCode { get; set; } = "";
 
        [Category("MES配置")]
        [Description("MES上传机器号,代表MachineNumber")]
        [DisplayName("MES机器号")]
        public string MESMachineNum { get; set; } = "";
 
        [Category("MES配置")]
        [Description("MES上传代码和检测项代码的映射关系")]
        [DisplayName("MES上传代码映射关系")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<MESCodeMapping>), typeof(UITypeEditor))]
        public List<MESCodeMapping> MESCodeMappingCollection { get; set; } = new List<MESCodeMapping>();
 
        [Category("MES配置-OEE上传")]
        [Description("OEE数据上传URL地址")]
        [DisplayName("OEE URL")]
        public string OEEDataUploadURL { get; set; } = "";
 
        [Category("MES配置-OEE上传")]
        [Description("true: 启用OEE数据上传 false:禁用OEE数据上传")]
        [DisplayName("OEE数据上传启用标记")]
        public bool IsEnableOEEDataUpload { get; set; } = false;
 
        [Category("MES配置-OEE上传")]
        [Description("OEE配置WorkPlace信息")]
        [DisplayName("OEE_WorkPlace")]
        public string OEEConfig_WorkPlace { get; set; } = "";
 
        [Category("图片显示设置")]
        [Description("背景图片文件路径")]
        [DisplayName("背景图片")]
        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
        public string BackgroundImageFilePath { get; set; }
 
        [Category("图片显示设置")]
        [DisplayName("检测缺陷显示布局")]
        [Description("检测界面缺陷显示布局")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(DefectRectangleIndicatorEditor), typeof(UITypeEditor))]
        public List<DefectRectangleIndicator> DefectIndicatorCollection { get; set; } = new List<DefectRectangleIndicator>();
 
        [Category("表格显示设置")]
        [Description("表格显示产品数据的方式,按行或列显示一个产品的所有数据")]
        [DisplayName("表格显示")]
        public RefreshMode RefreshModeSelect { get; set; } = RefreshMode.行;
 
        [Category("表格显示设置")]
        [Description("表格显示产品数据数量")]
        [DisplayName("表格显示产品数据数量")]
        public int DataViewCount { get; set; } = 100;
 
        [Category("表格显示设置")]
        [Description("表格产品数据刷新的频率,单位us")]
        [DisplayName("表格产品数据刷新频率")]
        public int DataViewRefreshTime { get; set; } = 1000;
 
        [Category("NG和OK图片保存配置")]
        [Description("图片保存目录")]
        [DisplayName("图片保存目录")]
        [Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
        public string NGImageFolder { get; set; } = "";
 
        [ResCategory("NG和OK图片保存配置")]
        [ResDescription("NG图片保存格式")]
        [ResDisplayName("NG图片保存格式")]
        public ImageFormat ImageFormatNG { get; set; } = ImageFormat.Png;
 
        [ResCategory("NG和OK图片保存配置")]
        [ResDescription("OK图片保存格式")]
        [ResDisplayName("OK图片保存格式")]
        public ImageFormat ImageFormatOK { get; set; } = ImageFormat.Png;
 
 
        [ResCategory("压缩图片保存配置")]
        [ResDescription("图片保存格式")]
        [ResDisplayName("图片保存格式")]
        public ImageFormat ImageFormatZip { get; set; } = ImageFormat.Jpeg;
 
        [ResCategory("压缩图片保存配置")]
        [ResDescription("图片保存开关")]
        [ResDisplayName("图片保存开关")]
        public bool SaveStateZip { get; set; } = false;
 
        [ResCategory("压缩图片保存配置")]
        [ResDescription("图片保存开关")]
        [ResDisplayName("保存图片工位集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<PostionnameZip>), typeof(UITypeEditor))]
        public List<PostionnameZip> PositionZip { get; set; } = new List<PostionnameZip>();
 
 
        [ResCategory("压缩图片保存配置")]
        [ResDescription("图片保存路径")]
        [ResDisplayName("图片保存路径")]
        [Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
        public string SavePathZip { get; set; }
 
 
 
        [ResCategory("压缩图片保存配置")]
        [ResDescription("图片保存路径2")]
        [ResDisplayName("图片保存路径2")]
        [Editor(typeof(FoldDialogEditor), typeof(UITypeEditor))]
        public string SavePathZip2 { get; set; }
 
        [Browsable(false)]
        public string CurrPathZip { get; set; }
 
 
 
        [ResCategory("压缩图片保存配置")]
        [ResDescription("图片保存双路径开关")]
        [ResDisplayName("图片保存双路径开关")]
        public bool SaveTwoPathZip { get; set; } = false;
 
 
        [ResCategory("压缩图片保存配置")]
        [ResDescription("双路径保存图片,首路径磁盘剩余空间小于设置值时,改用路径2存图,路径2磁盘满同理")]
        [ResDisplayName("磁盘最小剩余内存%")]
        public int SaveMinPercentZip { get; set; } = 5;
 
 
 
 
 
 
        [ResCategory("压缩图片保存配置")]
        [ResDescription("图片压缩率")]
        [ResDisplayName("图片压缩率")]
        [TypeConverter(typeof(EnumDescriptionConverter<zipZip>))]
        public zipZip SavezipZip { get; set; } = zipZip.zip;
 
 
        [Category("实时数据回传设置")]
        [Description("选择回传实时数据的本地socket服务端")]
        [DisplayName("回传服务端")]
        [TypeConverter(typeof(DeviceIdSelectorConverter<TcpListenerWrap>))]
        public string RealTimeDataServer { get; set; }
 
        [Category("实时数据回传设置")]
        [Description("回传数据的格式和内容设置")]
        [DisplayName("回传数据设置集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<RealTimeAdjustDataModel>), typeof(UITypeEditor))]
        public List<RealTimeAdjustDataModel> RealTimeDataModels { get; set; } = new List<RealTimeAdjustDataModel>();
 
        [Category("产品设置")]
        [DisplayName("产品展示数量上限")]
        [Description("产品展示数量上限,超过该数量的检测记录自动移除")]
        public int MaxProductListAmount { get; set; } = 20;
 
        [Category("心跳配置")]
        [DisplayName("心跳返回值")]
        [Description("心跳返回值")]
        public string Heartstr { get; set; } = "";
 
 
 
        [Category("算法预热设置")]
        [DisplayName("开关")]
        [Description("是否启动算法预热,true启用,false不启用")]
        public bool WarmUp { get; set; } = false;
 
        [Category("算法预热设置")]
        [DisplayName("算法预热集合")]
        [Description("算法预热集合")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<WarmUpOne>), typeof(UITypeEditor))]
        public List<WarmUpOne> WarmUpList { get; set; } = new List<WarmUpOne>();
 
 
 
 
        //[Category("检测相关")]
        //[Description("流程及设备检测标准集合")]
        //[DisplayName("检测标准集合2")]
        //[TypeConverter(typeof(GlobalSpecCollectionCountConverter))]
        //[Editor(typeof(GlobalSpecCollectionEditor), typeof(UITypeEditor))]
        //public List<ISpec> sss { get; set; } = new List<ISpec>();
 
        [Category("统计汇总配置")]
        [Description("汇总界面产品列表最大数量")]
        [DisplayName("产品列表最大数量")]
        public int MaxProductNumForStatistic { get; set; } = 200;
 
 
    }
 
 
 
 
    public enum zipZip
    {
        [ResDescription("1")]
        zip = 10,
        [ResDescription("0.1")]
        zip1 = 1,
        [ResDescription("0.2")]
        zip2 = 2,
        [ResDescription("0.3")]
        zip3 = 3,
        [ResDescription("0.4")]
        zip4 = 4,
        [ResDescription("0.5")]
        zip5 = 5,
        [ResDescription("0.6")]
        zip6 = 6,
        [ResDescription("0.7")]
        zip7 = 7,
        [ResDescription("0.8")]
        zip8 = 8,
        [ResDescription("0.9")]
        zip9 = 9,
    }
 
 
 
 
    public class PostionnameZip : IComplexDisplay
    {
        [Category("工位设置")]
        [DisplayName("工位名称")]
        [Description("工位设置")]
        [TypeConverter(typeof(WorkPositionNameConverter))]
        public string WorkPosition { get; set; }
 
        public string GetDisplayText()
        {
            return $"{WorkPosition}";
        }
    }
 
 
 
 
 
    public class WarmUpOne : IComplexDisplay
    {
        [Category("预热设置")]
        [Description("预热算法文件路径")]
        [DisplayName("预热算法")]
        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
        public string HalconFilePath { get; set; }
 
        [Category("预热设置")]
        [Description("预热图片文件路径")]
        [DisplayName("预热图片")]
        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
        public string PicFilePath { get; set; }
 
        public string GetDisplayText()
        {
            return $"{HalconFilePath}";
        }
    }
 
 
 
 
 
 
 
    public class MESCodeMapping : IComplexDisplay
    {
        [Category("本地检测代码")]
        [Description("本地使用的检测代码")]
        [DisplayName("本地检测代码")]
        [TypeConverter(typeof(SpecCodeSelectorConverter))]
        public string SpcCode { get; set; } = "";
 
        [Category("MES上传代码")]
        [Description("MES上传代码")]
        [DisplayName("MES上传代码")]
        public string MESCode { get; set; } = "";
        public string GetDisplayText()
        {
            return $"本地检测代码:{SpcCode} MES上传代码:{MESCode}";
        }
    }
 
    public enum RefreshMode
    {
        行,
        列,
    }
 
    public class WorkPositionSet : IComplexDisplay
    {
        [Category("交互触发值")]
        [Description("交互触发信息,该交互信息表示当前该工位触发")]
        [DisplayName("交互触发信息")]
        public string TriggerValue { get; set; }
 
        [Category("工位名称")]
        [Description("工位名称")]
        [DisplayName("工位名称")]
        public string PositionName { get; set; }
 
        [Category("启用标志")]
        [Description("启用标志 true:该工位启用  false:该工位未启用")]
        [DisplayName("启用标志")]
        public bool IsEnabled { get; set; } = true;
 
        [Category("顺序设置")]
        [Description("是否是最后工位,最后工位完成时汇总产品数据结果")]
        [DisplayName("是否末工位")]
        public bool IsLastPosition { get; set; } = false;
 
        [Category("反馈清理设置")]
        [Description("true: 发送相机清理信号 false: 不发送相机清理信号")]
        [DisplayName("发送清理信号开关")]
        public bool IsSendClearSingal { get; set; } = false;
 
        [Category("反馈清理设置")]
        [Description("反馈相机清理时发送的文本信息")]
        [DisplayName("反馈清理信息")]
        public string ClearStr { get; set; } = "$,ClearOK";
 
        public string GetDisplayText()
        {
            return $"{(IsEnabled ? "" : "禁用")} 工位 {PositionName} 交互触发值:{TriggerValue}";
        }
    }
 
    public class Product_CheckPointsOffsetList : IComplexDisplay
    {
        [Category("测量点补偿值设置")]
        [DisplayName("输入产品索引")]
        [Description("输入产品索引")]
        public int ProductIndex { get; set; } = 1;
 
        [Category("测量点补偿值设置")]
        [DisplayName("补偿值设置")]
        [Description("补偿值设置")]
        [TypeConverter(typeof(CollectionCountConvert))]
        [Editor(typeof(ComplexCollectionEditor<CheckPointsOffset>), typeof(UITypeEditor))]
        public List<CheckPointsOffset> CheckPointsOffsetList { get; set; } = new List<CheckPointsOffset>();
 
        public string GetDisplayText()
        {
            return $"产品索引:{ProductIndex},选择的补偿点位:{string.Join("、", CheckPointsOffsetList.Select(u => u.ReadyToOffsetMeasurePointName))}";
        }
    }
 
    public class CheckPointsOffset : IComplexDisplay
    {
        [Category("补偿值设置")]
        [DisplayName("选择待补偿的测量点位")]
        [Description("选择待补偿的测量点位")]
        [TypeConverter(typeof(MeasurePointNameSelectorConvertor))]
        public string ReadyToOffsetMeasurePointName { get; set; }
 
        [Category("补偿值设置")]
        [DisplayName("补偿值开关")]
        [Description("补偿值开关")]
        public bool IsOffsetCalculate { get; set; } = false;
 
        [Category("补偿值设置")]
        [DisplayName("补偿值-X")]
        [Description("写入坐标值X的补偿值,正数为加运算,负数为减运算")]
        public double OffsetX { get; set; } = 0;
 
        [Category("补偿值设置")]
        [DisplayName("补偿值-Y")]
        [Description("写入坐标值Y的补偿值,正数为加运算,负数为减运算")]
        public double OffsetY { get; set; } = 0;
        public string GetDisplayText()
        {
            return $"补偿点位:{ReadyToOffsetMeasurePointName},{IsOffsetCalculate.ToString()},X:{OffsetX.ToString()},Y:{OffsetY.ToString()}";
        }
    }
 
    public class MeasureBind : IComplexDisplay, IHalconToolPath
    {
        [Category("索引配置")]
        [DisplayName("工位设置")]
        [Description("设置该检测项对应的工位,一般和触发方法对应的工位匹配")]
        [TypeConverter(typeof(WorkPositionNameConverter))]
        public string WorkPosition { get; set; }
 
        [Category("索引配置")]
        [DisplayName("检测索引")]
        [Description("设置该检测项对应的检测索引,一般指该工位的第几次检测")]
        public int CheckIndex { get; set; }
 
        [Category("索引配置")]
        [DisplayName("图像索引")]
        [Description("应对单次检测项需要多次拍照时,记录图片的索引号,从0开始")]
        public int ImageIndex { get; set; } = 0;
 
        [Category("取像设置")]
        [DisplayName("相机选择")]
        [Description("选择该检测项对应的相机")]
        [TypeConverter(typeof(DeviceIdSelectorConverter<CameraBase>))]
        public string CameraId { get; set; }
 
        [Category("取像设置")]
        [Description("检测取像时的取像配置")]
        [DisplayName("取像配置")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(OperationConfigByCameraEditor), typeof(UITypeEditor))]
        public IOperationConfig SnapshotOpConfig { get; set; } = new CameraOperationConfigBase();
 
        [Category("产品配置")]
        [DisplayName("产品索引")]
        [Description("一次取像可能对应单个产品或多个产品,配置对应的产品索引序号,从1开始")]
        [TypeConverter(typeof(SimpleCollectionConvert<int>))]
        [Editor(typeof(SimpleCollectionEditor<int>), typeof(UITypeEditor))]
        public List<int> ProductIndices { get; set; } = new List<int>();
 
        [Category("产品配置")]
        [DisplayName("是否首工位")]
        [Description("如果是首工位,需要新建产品,否则从数据源中查找产品信息")]
        public bool IsFirstPosition { get; set; } = false;
 
        [Category("产品配置")]
        [DisplayName("支持队列缓存")]
        [Description("true: 寻找产品信息时可以从缓存队列中获取产品信息 false:不可以从缓存队列中获取产品信息,只能从数据库获取产品信息或者新建产品信息")]
        public bool IsEnabelQueryFromQueue { get; set; } = true;
 
        [Category("检测配置")]
        [Description("选择ML设备检测配置")]
        [DisplayName("检测配置")]
        [TypeConverter(typeof(DetectionConverter))]
        public string DetectionId { get; set; }
 
        [Category("检测配置")]
        [Description("从程序自定义检测方法中获取当前检测项")]
        [DisplayName("自定义检测方法")]
        [TypeConverter(typeof(MonitorSetSelectorConverter))]
        public string CustomizedMonitorId { get; set; }
 
        [Category("检测配置")]
        [Description("从程序自定义检测方法中获取当前检测项,该检测项用于多图组合运算时")]
        [DisplayName("自定义组合检测方法")]
        [TypeConverter(typeof(MonitorSetSelectorConverter))]
        public string CustomizedCombineMethodId { get; set; }
 
        [Category("图片保存配置")]
        [Description("NG图片保存开关,true:保存NG图片,false:不保存NG图片")]
        [DisplayName("NG图片保存开关")]
        public bool NGImageSwitch { get; set; } = false;
 
        [Category("图片保存配置")]
        [Description("OK图片保存开关,true:保存OK图片,false:不保存OK图片")]
        [DisplayName("OK图片保存开关")]
        public bool OKImageSwitch { get; set; } = false;
 
 
        [Category("标定配置")]
        [Description("标定开关")]
        [DisplayName("标定开关")]
        public bool Calibration { get; set; } = false;
 
        [Category("标定配置")]
        [Description("标定索引")]
        [DisplayName("标定索引")]
        public int CalibrationIndex { get; set; } = 0;
 
 
 
 
 
 
 
 
        public string GetDisplayText()
        {
            string cameraName = "";
            string detectionName = "未指定";
            string methodName = "未指定";
            string combineMethodName = "未指定";
            using (var scope = GlobalVar.Container.BeginLifetimeScope())
            {
                var deviceList = scope.Resolve<List<IDevice>>();
 
                cameraName = deviceList.FirstOrDefault(u => u.Id == CameraId)?.Name ?? "未指定";
 
                var detection = deviceList.Select(u => u.InitialConfig).Where(u => u is MLInitialConfigBase).SelectMany(u => ((MLInitialConfigBase)u).DetectionConfigs).FirstOrDefault(u => u.Id == DetectionId);
                if (detection != null)
                {
                    detectionName = detection.Name;
                }
 
                if (!string.IsNullOrWhiteSpace(CustomizedMonitorId))
                {
                    var config = scope.Resolve<IProcessConfig>();
                    var curMethod = config.GetAllMonitorSet().FirstOrDefault(u => u.Id == CustomizedMonitorId);
                    if (curMethod != null)
                    {
                        methodName = String.IsNullOrWhiteSpace(curMethod.Name) ? curMethod.MethodDesc : curMethod.Name;
                    }
 
                    curMethod = config.GetAllMonitorSet().FirstOrDefault(u => u.Id == CustomizedCombineMethodId);
                    if (curMethod != null)
                    {
                        combineMethodName = String.IsNullOrWhiteSpace(curMethod.Name) ? curMethod.MethodDesc : curMethod.Name;
                    }
                }
            }
 
            return $"工位{WorkPosition}第{CheckIndex}次检测产品{string.Join(",", ProductIndices.Select(u => u))},ML检测:{detectionName},自定义检测:{methodName},组合检测:{combineMethodName}";
        }
 
        public List<string> GetHalconToolPathList()
        {
            return (SnapshotOpConfig as IHalconToolPath).GetHalconToolPathList();
        }
    }
 
 
    public class BDMeasureBind : IComplexDisplay, IHalconToolPath
    {
        [Category("索引配置")]
        [DisplayName("检测索引")]
        [Description("检测索引,例:0,1,2,3...")]
        public int CheckIndex { get; set; }
 
 
        [Category("取像设置")]
        [DisplayName("相机选择")]
        [Description("选择该检测项对应的相机")]
        [TypeConverter(typeof(DeviceIdSelectorConverter<CameraBase>))]
        public string CameraId { get; set; }
 
        [Category("取像设置")]
        [Description("检测取像时的取像配置")]
        [DisplayName("取像配置")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(OperationConfigByCameraEditor), typeof(UITypeEditor))]
        public IOperationConfig SnapshotOpConfig { get; set; } = new CameraOperationConfigBase();
 
 
        [Category("标定矩阵")]
        [DisplayName("标定矩阵")]
        [Description("标定矩阵具体数据")]
        [TypeConverter(typeof(CollectionCountConvert))]
        public List<double> BDList { get; set; } = new List<double>();
 
        public string GetDisplayText()
        {
            return $"索引{CheckIndex.ToString()},相机{CameraId}";
        }
 
        public List<string> GetHalconToolPathList()
        {
            return (SnapshotOpConfig as IHalconToolPath).GetHalconToolPathList();
        }
    }
    public class ContinuousNGAlarm : IComplexDisplay
    {
        [Category("缺陷类型")]
        [Description("选择需要监控的缺陷类型")]
        [DisplayName("缺陷类型")]
        [TypeConverter(typeof(GlobalDefectNameConverter))]
        public string DefectType { get; set; }
 
        [Category("连续NG报警")]
        [Description("连续NG数量阈值。该缺陷连续NG数量达到或超过该阈值时,发出报警")]
        [DisplayName("连续NG数量阈值")]
        public int ContinuousNumThreshold { get; set; }
 
        [Category("连续NG报警")]
        [Description("连续NG报警类型")]
        [DisplayName("连续NG报警类型")]
        public int ContinuousAlarmType { get; set; } = 1;
 
        [Category("时段报警")]
        [Description("监控时间段。监控该时间段内的缺陷数量,单位:min")]
        [DisplayName("监控时间段")]
        public int TimePeriod { get; set; }
 
        [Category("时段报警")]
        [Description("监控时间段内NG数量阈值。监控时间段内,该缺陷NG数量达到或超过该阈值时,发出报警")]
        [DisplayName("时间内NG数量阈值")]
        public int TimePeriodNumThresold { get; set; }
 
        [Category("时段报警")]
        [Description("时段报警类型")]
        [DisplayName("时段报警类型")]
        public int TimePeriodAlarmType { get; set; } = 2;
 
        [Category("启用设置")]
        [Description("true:启用该缺陷监控报警 false: 不启用该缺陷监控报警")]
        [DisplayName("启用监控")]
        public bool IsEnabled { get; set; } = true;
 
        public string GetDisplayText()
        {
            string display = $"{(IsEnabled ? "" : "已禁用")} 监控{DefectType} ";
 
            if (ContinuousNumThreshold > 0)
            {
                display += $"连续NG{ContinuousNumThreshold}个 ";
            }
 
            if (TimePeriodNumThresold > 0)
            {
                display += $"{TimePeriod}分钟内NG{TimePeriodNumThresold}个 ";
            }
 
            return display;
        }
 
        private class GlobalDefectNameConverter : StringConverter
        {
            public override bool GetStandardValuesExclusive(ITypeDescriptorContext? context)
            {
                return false;
            }
 
            public override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
            {
                return true;
            }
 
            public override StandardValuesCollection? GetStandardValues(ITypeDescriptorContext? context)
            {
                using (var scope = GlobalVar.Container.BeginLifetimeScope())
                {
                    var config = scope.Resolve<IProcessConfig>();
 
                    return new StandardValuesCollection((config as IDefectSwitcher).DefectSwitchCollection.Select(u => u.DefectName).ToList());
                }
            }
        }
 
     
    }
 
 
  
 
 
    public class OperationConfigByCameraEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }
 
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
 
            if (edSvc != null)
            {
                Form form = new Form
                {
                    FormBorderStyle = FormBorderStyle.SizableToolWindow,
                    StartPosition = FormStartPosition.CenterParent,
                    Text = context.PropertyDescriptor.DisplayName + "--" + context.PropertyDescriptor.Description
                };
 
                if (context.Instance is MeasureBind ssa)
                {
                    IDevice camera = null;
                    using (var scope = GlobalVar.Container.BeginLifetimeScope())
                    {
                        var deviceList = scope.Resolve<List<IDevice>>();
                        camera = deviceList.FirstOrDefault(u => u.Id == ssa.CameraId);
                    }
 
                    if (camera != null)
                    {
                        var curCameraTypeAttr = camera.GetType().GetCustomAttribute<DeviceAttribute>();
                        var curOpconfigTypeAttr = value.GetType().GetCustomAttribute<DeviceAttribute>();
 
                        if (curCameraTypeAttr.TypeCode != (curOpconfigTypeAttr?.TypeCode ?? ""))
                        {
                            value = ConfigFactory.GetOperationConfig(curCameraTypeAttr.TypeCode);
                        }
                    }
                }
 
                PropertyGrid pg = new PropertyGrid
                {
                    Dock = DockStyle.Fill,
                    ToolbarVisible = false,
 
                    SelectedObject = value
                };
 
                form.Controls.Add(pg);
 
                form.ShowDialog();
 
                value = pg.SelectedObject;
                return value;
            }
 
            return base.EditValue(context, provider, value);
        }
    }
 
    public class WorkPositionNameConverter : ComboBoxItemTypeConvert
    {
        public override Dictionary<string, string> GetConvertDict(ITypeDescriptorContext context)
        {
            Dictionary<string, string> dict = new Dictionary<string, string>();
 
            using (var scope = GlobalVar.Container.BeginLifetimeScope())
            {
                var config = scope.Resolve<IProcessConfig>();
                if (config is M141Config iConfig)
                {
                    dict = iConfig.WorkPositionCollection.Where(u => u.IsEnabled).ToDictionary(u => u.PositionName, u => u.PositionName);
                }
            }
 
            return dict;
        }
    }
 
    public interface IImageCheckOperationConfig : IOperationConfig
    {
        List<ProductModel> Products { get; set; }
 
        IImageSet ImageSet { get; set; }
 
        string TriggerText { get; set; }
        string TriggerSource { get; set; }
 
        //CheckPoint CheckPoint { get; set; }
 
        string AlgorithemPath { get; set; }
 
        //string AlgorithemPath_CombineViews { get; set; }
 
        List<SpecSelector> SpecCollection { get; set; }
 
        //List<SpecSelector> SpecCollection_CombineViews { get; set; }
 
        //List<CheckPointSelector> CheckPointList { get; set; }
         bool BDstate { get; set; }
         int BDindex { get; set; }
         string ExecuteDevice { get; set; }
 
         int Outindex { get; set; }
        IImageCheckOperationConfig Clone();
 
 
        
    }
 
    [Device("ImageCheck", "图片检测操作配置", EnumHelper.DeviceAttributeType.OperationConfig)]
    public class ImageCheckOperationConfigBase : OperationConfigBase, IHalconToolPath, IImageCheckOperationConfig
    {
        [Browsable(false)]
        public List<ProductModel> Products { get; set; } = new List<ProductModel>();
 
        [Browsable(false)]
        public IImageSet ImageSet { get; set; } = null;
 
        [Browsable(false)]
        public string TriggerText { get; set; } = "";
 
        [Browsable(false)]
        public string TriggerSource { get; set; } = "";
 
        [Category("算法脚本")]
        [Description("当前单张图片算法脚本文件路径")]
        [DisplayName("单图算法脚本")]
        [Editor(typeof(FileDialogEditor), typeof(UITypeEditor))]
        public string AlgorithemPath { get; set; }
 
        [Category("检测标准")]
        [Description("计算检测标准集合")]
        [DisplayName("检测标准集合")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(ComplexCollectionEditor<SpecSelector>), typeof(UITypeEditor))]
        public List<SpecSelector> SpecCollection { get; set; } = new List<SpecSelector>();
 
        [Category("标定配置")]
        [Description("标定开关")]
        [DisplayName("标定开关")]
        public bool BDstate { get; set; } = false;
 
        [Category("标定配置")]
        [Description("标定序号,例如0,1,2,3...")]
        [DisplayName("标定序号")]
        public int BDindex { get; set; } = 0;
 
        [ResCategory("标定配置")]
        [ResDescription("调用设备")]
        [ResDisplayName("调用设备")]
        [TypeConverter(typeof(DeviceIdSelectorConverter<IDevice>))]
        public string ExecuteDevice { get; set; } = "";
 
        [Category("数据输出配置")]
        [Description("配置数据输出时,代表数据输出序号,配置二次进算法时,代表数据量")]
        [DisplayName("数据输出序号")]
        public int Outindex { get; set; } = 0;
 
 
 
        public List<string> GetHalconToolPathList()
        {
            return new List<string>() { AlgorithemPath };
        }
 
 
 
        public virtual IImageCheckOperationConfig Clone()
        {
            ImageCheckOperationConfigBase config = new ImageCheckOperationConfigBase();
 
            config.AlgorithemPath = AlgorithemPath;
            config.SpecCollection = SpecCollection.Select(u => new SpecSelector() { SpecCode = u.SpecCode }).ToList();
            config.Outindex = Outindex;
 
 
            config.BDindex = BDindex;
            config.BDstate = BDstate;
            config.ExecuteDevice = ExecuteDevice;
 
 
            //config.AlgorithemPath_CombineViews = AlgorithemPath_CombineViews;
            //config.SpecCollection_CombineViews = SpecCollection_CombineViews.Select(u => new SpecSelector() { SpecCode = u.SpecCode }).ToList();
 
            //config.CheckPointList = CheckPointList.Select(u => new CheckPointSelector() { PointId = u.PointId }).ToList();
 
            return config;
        }
    }
 
    public class RealTimeAdjustDataModel : IComplexDisplay
    {
        [Category("回传信息")]
        [Description("回传信息的数据头,包含了数据发送指向")]
        [DisplayName("回传信息数据头")]
        public string DataHead { get; set; } = "";
 
        [Category("回传信息")]
        [Description("true: 启用该回传 false:禁用该回传")]
        [DisplayName("启用标志")]
        public bool IsEnabled { get; set; } = true;
 
        [Category("回传信息")]
        [Description("回传信息具体内容,指定哪些点位的哪些坐标数据需要回传")]
        [DisplayName("回传信息数据内容")]
        [TypeConverter(typeof(ComplexObjectConvert))]
        [Editor(typeof(ComplexCollectionEditor<RealTimeAdjustDataDetail>), typeof(UITypeEditor))]
        public List<RealTimeAdjustDataDetail> DataDetails { get; set; } = new List<RealTimeAdjustDataDetail>();
 
        public string GetDisplayText()
        {
            return $"{(IsEnabled ? "" : "已禁用 ")}{DataHead} {string.Join(",", DataDetails.Select(u => u.GetDisplayText()))}";
        }
    }
 
    public class RealTimeAdjustDataDetail : IComplexDisplay
    {
        [Category("点位设置")]
        [Description("选择需要回传的数据点位")]
        [DisplayName("选择点位")]
        [TypeConverter(typeof(MeasurePointNameSelectorConvertor))]
        public string PointName { get; set; }
 
        [Category("点位设置")]
        [Description("选择数据点位的X坐标或者Y坐标")]
        [DisplayName("选择坐标")]
        public ContourEdge EdgeSelect { get; set; } = ContourEdge.X;
 
        [Category("检测项设置")]
        [Description("选择需要回传的SPC检测项数据")]
        [DisplayName("选择检测项")]
        [TypeConverter(typeof(SpecCodeSelectorConverter))]
        public string SpecCode { get; set; }
 
        [Category("检测项设置")]
        [Description("设置需要回传的SPC检测项数据的后缀,方便识别区分")]
        [DisplayName("检测项后缀")]
        public string SpecAfter { get; set; } = "";
 
        [Category("数据范围")]
        [Description("数据最小值,小于该数值认为数据非法,不做回传,避免误导")]
        [DisplayName("数据最小值")]
        public double ValidRangeMin { get; set; } = -999;
 
        [Category("数据范围")]
        [Description("数据最大值,大于该数值认为数据非法,不做回传,避免误导")]
        [DisplayName("数据最大值")]
        public double ValidRangeMax { get; set; } = 999;
 
        public string GetDisplayText()
        {
            string desc = "未指定";
 
            if (string.IsNullOrWhiteSpace(PointName))
            {
                if (!string.IsNullOrWhiteSpace(SpecCode))
                {
                    desc = $"{SpecCode}{SpecAfter}";
                }
            }
            else
            {
                desc = $"{PointName}-{EdgeSelect.ToString()}";
            }
 
            return desc;
        }
    }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
}