提交
This commit is contained in:
@ -1,19 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using AntdUI;
|
||||
using DH.Commons.Base;
|
||||
using DH.Commons.Enums;
|
||||
using DH.Devices.Vision;
|
||||
using DH.Devices.PLC;
|
||||
using XKRS.CanFly;
|
||||
using static AntdUI.Table;
|
||||
using static System.Windows.Forms.AxHost;
|
||||
using static DH.Commons.Enums.EnumHelper;
|
||||
|
||||
namespace DHSoftware.Views
|
||||
@ -21,9 +14,11 @@ namespace DHSoftware.Views
|
||||
public partial class DetectControl : UserControl
|
||||
{
|
||||
Window window;
|
||||
public DetectControl(Window _window)
|
||||
DetectionConfig detectionConfig;
|
||||
public DetectControl(Window _window,DetectionConfig _detection)
|
||||
{
|
||||
window = _window;
|
||||
detectionConfig = _detection;
|
||||
InitializeComponent();
|
||||
//初始化表格列头
|
||||
InitTableColumns();
|
||||
@ -34,7 +29,7 @@ namespace DHSoftware.Views
|
||||
private void BindEventHandler()
|
||||
{
|
||||
//预处理
|
||||
btnPath.Click += btnPath_Click;
|
||||
btnPrePath.Click += btnPath_Click;
|
||||
btnPreAdd.Click += BtnPreAdd_Click; ;
|
||||
btnPreDelete.Click += BtnPreDelete_Click; ;
|
||||
preTable.CellClick += PreTable_CellClick; ;
|
||||
@ -63,12 +58,11 @@ namespace DHSoftware.Views
|
||||
|
||||
if (e.Record is DetectionLable DetectionLable)
|
||||
{
|
||||
curDetectionLable = DetectionLable;
|
||||
switch (buttontext)
|
||||
{
|
||||
//暂不支持进入整行编辑,只支持指定单元格编辑,推荐使用弹窗或抽屉编辑整行数据
|
||||
case "编辑":
|
||||
var form = new DetectionLableEdit(window, curDetectionLable) { Size = new Size(500, 300) };
|
||||
var form = new DetectionLableEdit(window, DetectionLable) { Size = new Size(500, 300) };
|
||||
AntdUI.Drawer.open(new AntdUI.Drawer.Config(window, form)
|
||||
{
|
||||
OnLoad = () =>
|
||||
@ -84,7 +78,7 @@ namespace DHSoftware.Views
|
||||
case "删除":
|
||||
var result = Modal.open(window, "删除警告!", "确认要删除选择的数据吗?", TType.Warn);
|
||||
if (result == DialogResult.OK)
|
||||
DetectionLableList.Remove(DetectionLable);
|
||||
detectionConfig.DetectionLableList.Remove(DetectionLable);
|
||||
break;
|
||||
|
||||
}
|
||||
@ -98,12 +92,11 @@ namespace DHSoftware.Views
|
||||
|
||||
if (e.Record is SizeTreatParam sizeTreat)
|
||||
{
|
||||
SizeParamLable = sizeTreat;
|
||||
switch (buttontext)
|
||||
{
|
||||
//暂不支持进入整行编辑,只支持指定单元格编辑,推荐使用弹窗或抽屉编辑整行数据
|
||||
case "编辑":
|
||||
var form = new SizeLabelEdit(window, SizeParamLable) { Size = new Size(500, 300) };
|
||||
var form = new SizeLabelEdit(window, sizeTreat) { Size = new Size(500, 300) };
|
||||
AntdUI.Drawer.open(new AntdUI.Drawer.Config(window, form)
|
||||
{
|
||||
OnLoad = () =>
|
||||
@ -119,10 +112,10 @@ namespace DHSoftware.Views
|
||||
case "删除":
|
||||
var result = Modal.open(window, "删除警告!", "确认要删除选择的数据吗?", TType.Warn);
|
||||
if (result == DialogResult.OK)
|
||||
SizeLableList.Remove(sizeTreat);
|
||||
detectionConfig.SizeTreatParamList.Remove(sizeTreat);
|
||||
break;
|
||||
case "进行测量":
|
||||
var sizeType = ((int)SizeParamLable.PreType).ToString();
|
||||
var sizeType = ((int)sizeTreat.PreType).ToString();
|
||||
|
||||
// 根据测量类型打开不同的窗口
|
||||
switch (sizeType)
|
||||
@ -162,7 +155,7 @@ namespace DHSoftware.Views
|
||||
|
||||
private void BtnLableDelete_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (DetectionLableList.Count == 0 || !DetectionLableList.Any(x => x.Selected))
|
||||
if (detectionConfig.DetectionLableList.Count == 0 || !detectionConfig.DetectionLableList.Any(x => x.Selected))
|
||||
{
|
||||
AntdUI.Message.warn(window, "请选择要删除的行!", autoClose: 3);
|
||||
return;
|
||||
@ -172,12 +165,12 @@ namespace DHSoftware.Views
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
// 使用反转for循环删除主列表中选中的项
|
||||
for (int i = DetectionLableList.Count - 1; i >= 0; i--)
|
||||
for (int i = detectionConfig.DetectionLableList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
// 删除选中的主列表项
|
||||
if (DetectionLableList[i].Selected)
|
||||
if (detectionConfig.DetectionLableList[i].Selected)
|
||||
{
|
||||
DetectionLableList.RemoveAt(i);
|
||||
detectionConfig.DetectionLableList.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
// 提示删除完成
|
||||
@ -201,13 +194,13 @@ namespace DHSoftware.Views
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
DetectionLableList.Add(detectionLable);
|
||||
detectionConfig.DetectionLableList.Add(detectionLable);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnSizeDelete_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (SizeLableList.Count == 0 || !SizeLableList.Any(x => x.Selected))
|
||||
if (detectionConfig.SizeTreatParamList.Count == 0 || !detectionConfig.SizeTreatParamList.Any(x => x.Selected))
|
||||
{
|
||||
AntdUI.Message.warn(window, "请选择要删除的行!", autoClose: 3);
|
||||
return;
|
||||
@ -217,12 +210,12 @@ namespace DHSoftware.Views
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
// 使用反转for循环删除主列表中选中的项
|
||||
for (int i = SizeLableList.Count - 1; i >= 0; i--)
|
||||
for (int i = detectionConfig.SizeTreatParamList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
// 删除选中的主列表项
|
||||
if (SizeLableList[i].Selected)
|
||||
if (detectionConfig.SizeTreatParamList[i].Selected)
|
||||
{
|
||||
SizeLableList.RemoveAt(i);
|
||||
detectionConfig.SizeTreatParamList.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
// 提示删除完成
|
||||
@ -251,7 +244,7 @@ namespace DHSoftware.Views
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
SizeLableList.Add(SizeParamLable);
|
||||
detectionConfig.SizeTreatParamList.Add(SizeParamLable);
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,23 +253,20 @@ namespace DHSoftware.Views
|
||||
|
||||
}
|
||||
|
||||
List<RelatedCamera> relatedCameras = new List<RelatedCamera>();
|
||||
private void BtnCorrelatedCamera_Click(object? sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
|
||||
var form = new CorrelatedCameraEdit(window, relatedCameras) { Size = new Size(500, 400) };
|
||||
var form = new CorrelatedCameraEdit(window, detectionConfig.CameraCollects) { Size = new Size(500, 400) };
|
||||
AntdUI.Modal.open(new AntdUI.Modal.Config(window, "", form, TType.None)
|
||||
{
|
||||
BtnHeight = 0,
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
flowPanel1.Controls.Clear();
|
||||
if (relatedCameras.Count > 0)
|
||||
flowCameraPanel.Controls.Clear();
|
||||
if (detectionConfig.CameraCollects.Count > 0)
|
||||
{
|
||||
foreach (var item in relatedCameras)
|
||||
foreach (var item in detectionConfig.CameraCollects)
|
||||
{
|
||||
var control = new AntdUI.Tag()
|
||||
{
|
||||
@ -288,11 +278,11 @@ namespace DHSoftware.Views
|
||||
control.CloseChanged += (sender, e) =>
|
||||
{
|
||||
var tag = sender as Tag;
|
||||
foreach (var item in relatedCameras)
|
||||
foreach (var item in detectionConfig.CameraCollects)
|
||||
{
|
||||
if (item.CameraSourceId.Equals(tag.Text))
|
||||
{
|
||||
relatedCameras.Remove(item);
|
||||
detectionConfig.CameraCollects.Remove(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -301,7 +291,7 @@ namespace DHSoftware.Views
|
||||
};
|
||||
// 通过主窗口设置DPI控制添加控件保持缩放比例
|
||||
window.AutoDpi(control);
|
||||
flowPanel1.Controls.Add(control);
|
||||
flowCameraPanel.Controls.Add(control);
|
||||
control.BringToFront();
|
||||
}
|
||||
}
|
||||
@ -329,7 +319,7 @@ namespace DHSoftware.Views
|
||||
{
|
||||
string filePath = openFileDialog.FileName;
|
||||
|
||||
iptPath2.Text = filePath;
|
||||
iptDetectPath.Text = filePath;
|
||||
|
||||
}
|
||||
}
|
||||
@ -341,12 +331,11 @@ namespace DHSoftware.Views
|
||||
|
||||
if (e.Record is PreTreatParam PreTreat)
|
||||
{
|
||||
curPreOutTreat = PreTreat;
|
||||
switch (buttontext)
|
||||
{
|
||||
//暂不支持进入整行编辑,只支持指定单元格编辑,推荐使用弹窗或抽屉编辑整行数据
|
||||
case "编辑":
|
||||
var form = new PreTreatEdit(window, curPreOutTreat) { Size = new Size(500, 300) };
|
||||
var form = new PreTreatEdit(window, PreTreat) { Size = new Size(500, 300) };
|
||||
AntdUI.Drawer.open(new AntdUI.Drawer.Config(window, form)
|
||||
{
|
||||
OnLoad = () =>
|
||||
@ -362,7 +351,7 @@ namespace DHSoftware.Views
|
||||
case "删除":
|
||||
var result = Modal.open(window, "删除警告!", "确认要删除选择的数据吗?", TType.Warn);
|
||||
if (result == DialogResult.OK)
|
||||
PreOutTreatList.Remove(PreTreat);
|
||||
detectionConfig.OUTPreTreatParams.Remove(PreTreat);
|
||||
break;
|
||||
|
||||
}
|
||||
@ -371,7 +360,7 @@ namespace DHSoftware.Views
|
||||
|
||||
private void BtnOutDelete_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (PreOutTreatList.Count == 0 || !PreOutTreatList.Any(x => x.Selected))
|
||||
if (detectionConfig.OUTPreTreatParams.Count == 0 || !detectionConfig.OUTPreTreatParams.Any(x => x.Selected))
|
||||
{
|
||||
AntdUI.Message.warn(window, "请选择要删除的行!", autoClose: 3);
|
||||
return;
|
||||
@ -381,12 +370,12 @@ namespace DHSoftware.Views
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
// 使用反转for循环删除主列表中选中的项
|
||||
for (int i = PreOutTreatList.Count - 1; i >= 0; i--)
|
||||
for (int i = detectionConfig.OUTPreTreatParams.Count - 1; i >= 0; i--)
|
||||
{
|
||||
// 删除选中的主列表项
|
||||
if (PreOutTreatList[i].Selected)
|
||||
if (detectionConfig.OUTPreTreatParams[i].Selected)
|
||||
{
|
||||
PreOutTreatList.RemoveAt(i);
|
||||
detectionConfig.OUTPreTreatParams.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
// 提示删除完成
|
||||
@ -411,7 +400,7 @@ namespace DHSoftware.Views
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
PreOutTreatList.Add(preParam);
|
||||
detectionConfig.OUTPreTreatParams.Add(preParam);
|
||||
}
|
||||
}
|
||||
|
||||
@ -421,12 +410,11 @@ namespace DHSoftware.Views
|
||||
|
||||
if (e.Record is PreTreatParam PreTreat)
|
||||
{
|
||||
curPreTreat = PreTreat;
|
||||
switch (buttontext)
|
||||
{
|
||||
//暂不支持进入整行编辑,只支持指定单元格编辑,推荐使用弹窗或抽屉编辑整行数据
|
||||
case "编辑":
|
||||
var form = new PreTreatEdit(window, curPreTreat) { Size = new Size(500, 300) };
|
||||
var form = new PreTreatEdit(window, PreTreat) { Size = new Size(500, 300) };
|
||||
AntdUI.Drawer.open(new AntdUI.Drawer.Config(window, form)
|
||||
{
|
||||
OnLoad = () =>
|
||||
@ -442,7 +430,7 @@ namespace DHSoftware.Views
|
||||
case "删除":
|
||||
var result = Modal.open(window, "删除警告!", "确认要删除选择的数据吗?", TType.Warn);
|
||||
if (result == DialogResult.OK)
|
||||
PreTreatList.Remove(PreTreat);
|
||||
detectionConfig.PreTreatParams.Remove(PreTreat);
|
||||
break;
|
||||
|
||||
}
|
||||
@ -457,7 +445,7 @@ namespace DHSoftware.Views
|
||||
|
||||
private void BtnPreDelete_Click(object? sender, EventArgs e)
|
||||
{
|
||||
if (PreTreatList.Count == 0 || !PreTreatList.Any(x => x.Selected))
|
||||
if (detectionConfig.PreTreatParams.Count == 0 || !detectionConfig.PreTreatParams.Any(x => x.Selected))
|
||||
{
|
||||
AntdUI.Message.warn(window, "请选择要删除的行!", autoClose: 3);
|
||||
return;
|
||||
@ -467,12 +455,12 @@ namespace DHSoftware.Views
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
// 使用反转for循环删除主列表中选中的项
|
||||
for (int i = PreTreatList.Count - 1; i >= 0; i--)
|
||||
for (int i = detectionConfig.PreTreatParams.Count - 1; i >= 0; i--)
|
||||
{
|
||||
// 删除选中的主列表项
|
||||
if (PreTreatList[i].Selected)
|
||||
if (detectionConfig.PreTreatParams[i].Selected)
|
||||
{
|
||||
PreTreatList.RemoveAt(i);
|
||||
detectionConfig.PreTreatParams.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
// 提示删除完成
|
||||
@ -496,41 +484,102 @@ namespace DHSoftware.Views
|
||||
});
|
||||
if (form.submit)
|
||||
{
|
||||
PreTreatList.Add(preParam);
|
||||
detectionConfig.PreTreatParams.Add(preParam);
|
||||
}
|
||||
}
|
||||
|
||||
AntList<PreTreatParam> PreTreatList;
|
||||
AntList<PreTreatParam> PreOutTreatList;
|
||||
AntList<DetectionLable> DetectionLableList;
|
||||
AntList<SizeTreatParam> SizeLableList;
|
||||
PreTreatParam curPreTreat;
|
||||
PreTreatParam curPreOutTreat;
|
||||
DetectionLable curDetectionLable;
|
||||
SizeTreatParam SizeParamLable;
|
||||
|
||||
|
||||
private void InitData()
|
||||
{
|
||||
PreTreatList = new AntList<PreTreatParam>();
|
||||
|
||||
preTable.Binding(PreTreatList);
|
||||
|
||||
PreOutTreatList = new AntList<PreTreatParam>();
|
||||
|
||||
PreOutTable.Binding(PreOutTreatList);
|
||||
|
||||
|
||||
foreach (var item in MLModelTypes)
|
||||
stDetectType.Items.Clear();
|
||||
foreach (ModelType value in Enum.GetValues(typeof(ModelType)))
|
||||
{
|
||||
stDetectType.Items.Add(item.Key);
|
||||
stDetectType.Items.Add(value.ToString());
|
||||
}
|
||||
preTable.Binding(detectionConfig.PreTreatParams);
|
||||
PreOutTable.Binding(detectionConfig.OUTPreTreatParams);
|
||||
lableTable.Binding(detectionConfig.DetectionLableList);
|
||||
SizeTable.Binding(detectionConfig.SizeTreatParamList);
|
||||
|
||||
|
||||
if (detectionConfig.PreTreatParams.Count > 0)
|
||||
{
|
||||
foreach (var item in detectionConfig.PreTreatParams)
|
||||
{
|
||||
|
||||
item.CellLinks = new CellLink[] {
|
||||
new CellButton(Guid.NewGuid().ToString(), "编辑", TTypeMini.Primary) ,
|
||||
new CellButton(Guid.NewGuid().ToString(), "删除", TTypeMini.Error)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (detectionConfig.OUTPreTreatParams.Count > 0)
|
||||
{
|
||||
foreach (var item in detectionConfig.OUTPreTreatParams)
|
||||
{
|
||||
|
||||
DetectionLableList = new AntList<DetectionLable>();
|
||||
item.CellLinks = new CellLink[] {
|
||||
new CellButton(Guid.NewGuid().ToString(), "编辑", TTypeMini.Primary) ,
|
||||
new CellButton(Guid.NewGuid().ToString(), "删除", TTypeMini.Error)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
lableTable.Binding(DetectionLableList);
|
||||
if (detectionConfig.DetectionLableList.Count > 0)
|
||||
{
|
||||
foreach (var item in detectionConfig.DetectionLableList)
|
||||
{
|
||||
|
||||
SizeLableList = new AntList<SizeTreatParam>();
|
||||
SizeTable.Binding(SizeLableList);
|
||||
item.CellLinks = new CellLink[] {
|
||||
new CellButton(Guid.NewGuid().ToString(), "编辑", TTypeMini.Primary) ,
|
||||
new CellButton(Guid.NewGuid().ToString(), "删除", TTypeMini.Error)
|
||||
};
|
||||
}
|
||||
}
|
||||
if (detectionConfig.SizeTreatParamList.Count > 0)
|
||||
{
|
||||
foreach (var item in detectionConfig.SizeTreatParamList)
|
||||
{
|
||||
|
||||
item.CellLinks = new CellLink[] {
|
||||
new CellButton(Guid.NewGuid().ToString(), "编辑", TTypeMini.Primary) ,
|
||||
new CellButton(Guid.NewGuid().ToString(), "删除", TTypeMini.Error),
|
||||
new CellButton(Guid.NewGuid().ToString(),"进行测量",TTypeMini.Primary)
|
||||
};
|
||||
}
|
||||
}
|
||||
if (detectionConfig.CameraCollects.Count > 0)
|
||||
{
|
||||
foreach (var item in detectionConfig.CameraCollects)
|
||||
{
|
||||
var control = new AntdUI.Tag()
|
||||
{
|
||||
Font = new System.Drawing.Font("Microsoft YaHei UI", 9F),
|
||||
Size = new Size(90, 42),
|
||||
Text = item.CameraSourceId,
|
||||
CloseIcon = true
|
||||
};
|
||||
window.AutoDpi(control);
|
||||
flowCameraPanel.Controls.Add(control);
|
||||
control.BringToFront();
|
||||
}
|
||||
}
|
||||
//1
|
||||
sthPreStatus.DataBindings.Add("Checked", detectionConfig, "IsPreEnabled", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
iptPrePath.DataBindings.Add("Text", detectionConfig, "HalconAlgorithemPath_Pre", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
|
||||
//2
|
||||
sthDetectStatus.DataBindings.Add("Checked", detectionConfig, "IsEnabled", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
sthStation.DataBindings.Add("Checked", detectionConfig, "IsAddStation", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
stDetectType.DataBindings.Add("Text", detectionConfig, "ModelType",true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
iptConfidence.DataBindings.Add("Text", detectionConfig, "ModelconfThreshold", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
iptDetectPath.DataBindings.Add("Text", detectionConfig, "ModelPath", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
sthOKOriginal.DataBindings.Add("Checked", detectionConfig, "SaveOKOriginal", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
sthNGOriginal.DataBindings.Add("Checked", detectionConfig, "SaveNGOriginal", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
sthOKDetect.DataBindings.Add("Checked", detectionConfig, "SaveOKDetect", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
sthDetectNG.DataBindings.Add("Checked", detectionConfig, "SaveNGDetect", true, DataSourceUpdateMode.OnPropertyChanged);
|
||||
|
||||
}
|
||||
|
||||
@ -590,7 +639,7 @@ namespace DHSoftware.Views
|
||||
{
|
||||
string filePath = openFileDialog.FileName;
|
||||
|
||||
iptPath.Text = filePath;
|
||||
iptPrePath.Text = filePath;
|
||||
|
||||
}
|
||||
}
|
||||
@ -600,31 +649,11 @@ namespace DHSoftware.Views
|
||||
|
||||
|
||||
|
||||
List<KeyValuePair<string, int>> MLModelTypes = GetFilteredEnumDescriptionsAndValues<MLModelType>();
|
||||
List<KeyValuePair<string, int>> SizeEnum = GetFilteredEnumDescriptionsAndValues<SizeEnum>();
|
||||
|
||||
|
||||
private void tabPage2_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static List<KeyValuePair<string, int>> GetFilteredEnumDescriptionsAndValues<T>() where T : Enum
|
||||
{
|
||||
return Enum.GetValues(typeof(T))
|
||||
.Cast<T>()
|
||||
.Select(e =>
|
||||
{
|
||||
// 获取枚举的 Description 属性,如果没有,则使用枚举的名称
|
||||
var description = e.GetType()
|
||||
.GetField(e.ToString())
|
||||
?.GetCustomAttribute<DescriptionAttribute>()
|
||||
?.Description ?? e.ToString();
|
||||
|
||||
// 返回枚举的描述和对应的整数值
|
||||
return new KeyValuePair<string, int>(description, Convert.ToInt32(e));
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user