2025-03-16 13:14:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using AntdUI;
|
2025-03-21 08:51:20 +08:00
|
|
|
|
using DH.Commons.Base;
|
2025-03-16 13:14:05 +08:00
|
|
|
|
using DH.Devices.Vision;
|
|
|
|
|
|
|
|
|
|
namespace DHSoftware.Views
|
|
|
|
|
{
|
|
|
|
|
public partial class CorrelatedCameraEdit : UserControl
|
|
|
|
|
{
|
|
|
|
|
List<KeyValuePair<string, int>> resultStates = GetFilteredEnumDescriptionsAndValuesres<ResultState>();
|
|
|
|
|
|
|
|
|
|
// 获取枚举的描述和对应的值,只筛选出 OK 和 NG
|
|
|
|
|
public static List<KeyValuePair<string, int>> GetFilteredEnumDescriptionsAndValuesres<T>() where T : Enum
|
|
|
|
|
{
|
|
|
|
|
return Enum.GetValues(typeof(T))
|
|
|
|
|
.Cast<T>()
|
|
|
|
|
/* .Where(e => e.Equals(ResultState.OK) || e.Equals(ResultState.DetectNG))*/ // 只保留 OK 和 NG
|
|
|
|
|
.Select(e =>
|
|
|
|
|
{
|
|
|
|
|
// 通过反射获取 DescriptionAttribute 描述,如果没有描述,则使用枚举项名称
|
|
|
|
|
var description = e.GetType()
|
|
|
|
|
.GetField(e.ToString())
|
|
|
|
|
?.GetCustomAttribute<DescriptionAttribute>()
|
|
|
|
|
?.Description ?? e.ToString(); // 如果没有 DescriptionAttribute,则使用枚举名称
|
|
|
|
|
|
|
|
|
|
// 返回描述和值的键值对
|
|
|
|
|
return new KeyValuePair<string, int>(description, Convert.ToInt32(e));
|
|
|
|
|
})
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
private AntdUI.Window window;
|
|
|
|
|
private List<RelatedCamera> Cameras;
|
|
|
|
|
public bool submit;
|
|
|
|
|
public CorrelatedCameraEdit(AntdUI.Window _window, List<RelatedCamera> cameras)
|
|
|
|
|
{
|
|
|
|
|
this.window = _window;
|
|
|
|
|
Cameras = cameras;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
//设置默认值
|
|
|
|
|
InitData();
|
|
|
|
|
// 绑定事件
|
|
|
|
|
BindEventHandler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BindEventHandler()
|
|
|
|
|
{
|
|
|
|
|
button_ok.Click += Button_ok_Click;
|
|
|
|
|
button_cancel.Click += Button_cancel_Click;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Button_cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
submit = false;
|
|
|
|
|
this.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Button_ok_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (flowPanel1.Controls.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
Cameras.Clear();
|
|
|
|
|
foreach (Control control in flowPanel1.Controls)
|
|
|
|
|
{
|
|
|
|
|
if (control is AntdUI.Checkbox checkbox)
|
|
|
|
|
{
|
|
|
|
|
// 操作 CheckBox
|
|
|
|
|
bool isChecked = checkbox.Checked;
|
|
|
|
|
if (isChecked)
|
|
|
|
|
{
|
|
|
|
|
string name = checkbox.Text;
|
|
|
|
|
RelatedCamera relatedCamera = new RelatedCamera(name);
|
|
|
|
|
Cameras.Add(relatedCamera);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
submit = true;
|
|
|
|
|
this.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitData()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < 15; i++)
|
|
|
|
|
{
|
|
|
|
|
string name = $"Cam{i}";
|
|
|
|
|
var control = new AntdUI.Checkbox()
|
|
|
|
|
{
|
|
|
|
|
AutoCheck = true,
|
|
|
|
|
Font = new System.Drawing.Font("Microsoft YaHei UI", 9F),
|
|
|
|
|
Size = new Size(90, 42),
|
|
|
|
|
Text = name,
|
2025-03-24 15:20:33 +08:00
|
|
|
|
ForeColor = Color.FromArgb(61, 94, 218)
|
2025-03-16 13:14:05 +08:00
|
|
|
|
};
|
|
|
|
|
foreach (var item in Cameras)
|
|
|
|
|
{
|
|
|
|
|
if (item.CameraSourceId.Equals(name))
|
|
|
|
|
{
|
|
|
|
|
control.Checked = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 通过主窗口设置DPI控制添加控件保持缩放比例
|
|
|
|
|
window.AutoDpi(control);
|
|
|
|
|
flowPanel1.Controls.Add(control);
|
|
|
|
|
control.BringToFront();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CorrelatedCameraEdit_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|