138 lines
5.0 KiB
C#
Raw Normal View History

2025-03-18 14:19:33 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AntdUI;
2025-03-21 08:51:20 +08:00
using DH.Commons.Base;
2025-03-18 14:19:33 +08:00
using DH.Commons.Enums;
2025-03-22 16:16:34 +08:00
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using Window = AntdUI.Window;
2025-03-18 14:19:33 +08:00
namespace DHSoftware.Views
{
public partial class CameraControl : UserControl
{
Window window;
CameraBase CameraBase;
2025-03-22 16:16:34 +08:00
public CameraControl(Window _window, CameraBase cameraBase)
2025-03-18 14:19:33 +08:00
{
2025-03-22 16:16:34 +08:00
window = _window;
2025-03-18 14:19:33 +08:00
CameraBase = cameraBase;
InitializeComponent();
2025-03-22 16:16:34 +08:00
sltCamType.TextChanged += SltCamTpye_TextChanged;
2025-03-18 14:19:33 +08:00
InitData();
BindData();
}
2025-03-22 16:16:34 +08:00
private void SltCamTpye_TextChanged(object? sender, EventArgs e)
{
if (sender is Select slt && !string.IsNullOrEmpty(slt.Text))
{
// 将文本转换为枚举值
if (Enum.TryParse<EnumCamType>(slt.Text, out var plcType))
{
switch (plcType)
{
case EnumCamType.Do3think:
case EnumCamType.hik:
break;
default:
break;
}
}
else
{
}
}
}
2025-03-18 14:19:33 +08:00
private void SltAcquisitionMode_SelectedIndexChanged(object sender, IntEventArgs e)
{
switch (e.Value)
{
case (int)CameraAcquisitionMode.:
sltTriggerMode.Enabled = false;
break;
case (int)CameraAcquisitionMode.:
sltTriggerMode.Enabled = true;
break;
2025-03-22 16:16:34 +08:00
default:
2025-03-18 14:19:33 +08:00
break;
}
}
private void BindData()
{
2025-03-21 08:51:20 +08:00
2025-03-22 16:16:34 +08:00
sltCamType.DataBindings.Add("Text", CameraBase, "CamType", true, DataSourceUpdateMode.OnPropertyChanged, "");
sthPic.DataBindings.Add(nameof(sthPic.Checked), CameraBase, nameof(CameraBase.IsSavePicEnabled),
2025-03-21 08:51:20 +08:00
true, DataSourceUpdateMode.OnPropertyChanged);
2025-03-22 16:16:34 +08:00
sthAllPic.DataBindings.Add(nameof(sthAllPic.Checked), CameraBase, nameof(CameraBase.IsAllPicEnabled),
true, DataSourceUpdateMode.OnPropertyChanged);
2025-03-18 14:19:33 +08:00
// 启用状态绑定
swhEnable.DataBindings.Add(nameof(swhEnable.Checked), CameraBase, nameof(CameraBase.IsEnabled),
true, DataSourceUpdateMode.OnPropertyChanged);
// 曝光时间绑定假设iptExposure是NumericUpDown
iptExposure.DataBindings.Add(nameof(iptExposure.Value), CameraBase, nameof(CameraBase.Exposure),
true, DataSourceUpdateMode.OnPropertyChanged, 0M, "N2");
// 增益绑定
iptGain.DataBindings.Add(nameof(iptGain.Value), CameraBase, nameof(CameraBase.Gain),
true, DataSourceUpdateMode.OnPropertyChanged, 0M, "N2");
// 旋转角度绑定
iptRevolve.DataBindings.Add(nameof(iptRevolve.Value), CameraBase, nameof(CameraBase.RotateImage),
true, DataSourceUpdateMode.OnPropertyChanged, 0M, "N2");
// ROI坐标绑定
iptROIX.DataBindings.Add(nameof(iptROIX.Value), CameraBase, nameof(CameraBase.ROIX));
iptROIY.DataBindings.Add(nameof(iptROIY.Value), CameraBase, nameof(CameraBase.ROIY));
iptROIW.DataBindings.Add(nameof(iptROIW.Value), CameraBase, nameof(CameraBase.ROIW));
iptROIH.DataBindings.Add(nameof(iptROIH.Value), CameraBase, nameof(CameraBase.ROIH));
// 采集模式下拉框处理
sltAcquisitionMode.SelectedIndexChanged += (s, e) =>
{
CameraBase.IsContinueMode = sltAcquisitionMode.SelectedIndex == 0;
};
// 触发模式下拉框处理
sltTriggerMode.SelectedIndexChanged += (s, e) =>
{
CameraBase.IsHardwareTrigger = sltTriggerMode.SelectedIndex == 1;
};
}
private void InitData()
{
2025-03-22 16:16:34 +08:00
// 获取枚举字段名列表(原描述改为字段名)
sltCamType.Items.Clear();
foreach (EnumCamType value in Enum.GetValues(typeof(EnumCamType)))
{
sltCamType.Items.Add(value.ToString());
}
2025-03-18 14:19:33 +08:00
// 初始化下拉框选项
sltAcquisitionMode.Items.AddRange(new[] { "连续模式", "触发模式" });
sltTriggerMode.Items.AddRange(new[] { "软触发", "硬触发" });
// 设置初始选择
sltAcquisitionMode.SelectedIndex = CameraBase.IsContinueMode ? 0 : 1;
sltTriggerMode.SelectedIndex = CameraBase.IsHardwareTrigger ? 1 : 0;
}
2025-03-22 16:16:34 +08:00
2025-03-18 14:19:33 +08:00
}
}