using HalconDotNet;
|
using LB_SmartVision.ProcessRun;
|
using LB_VisionControls;
|
using LB_VisionControls.Forms;
|
using LB_VisionProcesses;
|
using OpenCvSharp.Flann;
|
using OpenVinoSharp;
|
using ReaLTaiizor.Controls;
|
using System;
|
using System.Collections.Concurrent;
|
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;
|
|
namespace LB_SmartVision.Forms.Pages.SettingPage
|
{
|
public partial class CsvSettingControl : UserControl
|
{
|
ConcurrentDictionary<string, ComboBox> dicComboxs = new ConcurrentDictionary<string, ComboBox>();
|
|
public bool IsSelected { get { return ckbSelected.Checked; } }
|
|
public string Title { get { return RunBll.Name; } }
|
|
public List<string> Others { get { return csv.Others; } }
|
|
private CsvSetting csv { get; set; } = new CsvSetting();
|
|
private ProcessRunBll RunBll
|
{
|
get
|
{
|
if (GlobalVar.dicProcesses.ContainsKey(cmbProcess.Text))
|
{
|
return GlobalVar.dicProcesses[cmbProcess.Text];
|
}
|
else
|
{
|
return null;
|
}
|
}
|
}
|
|
public CsvSettingControl(CsvSetting csv = null)
|
{
|
InitializeComponent();
|
|
if (csv == null)
|
csv = new CsvSetting();
|
this.csv = csv;
|
|
cmbProcess.MouseClick += MouseClick;
|
cmbProcess.SelectedIndexChanged += SelectedIndexChanged;
|
|
cmbProcess.Items.Clear();
|
cmbProcess.Items.Add("");
|
cmbProcess.Items.AddRange(GlobalVar.dicProcesses.Keys.ToArray());
|
|
cmbProcess.Text = csv.ProcessName;
|
|
if (csv.Others.Count > 0)
|
{
|
Single perSpace = 100 / csv.Others.Count;
|
|
while (tableLayoutPanel1.ColumnCount - 4 < csv.Others.Count)
|
{
|
tableLayoutPanel1.ColumnCount++;
|
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, perSpace));
|
}
|
|
for (int i = 4; i < tableLayoutPanel1.ColumnCount; i++)
|
{
|
tableLayoutPanel1.ColumnStyles[i].SizeType = SizeType.Percent;
|
tableLayoutPanel1.ColumnStyles[i].Width = perSpace;
|
}
|
|
int index = 0;
|
foreach (var value in csv.Others)
|
{
|
string key = $"cmb{index}";
|
if (!dicComboxs.ContainsKey(key))
|
{
|
ComboBox comboBox = new ComboBox();
|
comboBox.Name = key;
|
comboBox.MouseClick += MouseClick;
|
comboBox.SelectedIndexChanged += SelectedIndexChanged;
|
comboBox.Text = value;
|
comboBox.Dock = DockStyle.Fill;
|
tableLayoutPanel1.Controls.Add(comboBox, index + 4, 0);
|
dicComboxs.TryAdd(key, comboBox);
|
}
|
else
|
{
|
dicComboxs[key].Text = value;
|
}
|
|
index++;
|
}
|
}
|
btnAddMsg.ForeColor = Color.Black;
|
btnDelMsg.ForeColor = Color.Black;
|
// 恢复布局(只触发一次重绘)
|
tableLayoutPanel1.ResumeLayout(false);
|
this.ResumeLayout(false);
|
}
|
|
private void MouseClick(object sender, EventArgs e)
|
{
|
switch ((sender as ComboBox).Name)
|
{
|
case "cmbProcess":
|
cmbProcess.Items.Clear();
|
cmbProcess.Items.Add("");
|
cmbProcess.Items.AddRange(GlobalVar.dicProcesses.Keys.ToArray());
|
break;
|
default:
|
ComboBox comboBox = sender as ComboBox;
|
if (comboBox != null && comboBox.Name.StartsWith("cmb"))
|
{
|
comboBox.Items.Clear();
|
comboBox.Items.Add("");
|
if (RunBll == null)
|
{
|
return;
|
}
|
foreach (var lstOutput in RunBll.dicOutputsMapping)
|
{
|
foreach (var output in lstOutput.Value)
|
{
|
comboBox.Items.Add(output);
|
}
|
}
|
|
foreach (var lstInput in RunBll.dicInputsMapping)
|
{
|
foreach (var tuple in lstInput.Value)
|
{
|
string inputs = tuple.Item1;
|
comboBox.Items.Add(inputs);
|
}
|
}
|
}
|
break;
|
}
|
}
|
|
private void SelectedIndexChanged(object sender, EventArgs e)
|
{
|
switch ((sender as ComboBox).Name)
|
{
|
case "cmbProcess":
|
{
|
csv.ProcessName = cmbProcess.Text;
|
break;
|
}
|
default:
|
{
|
// 更新字典
|
ComboBox comboBox = sender as ComboBox;
|
if (comboBox != null && comboBox.Name.StartsWith("cmb"))
|
{
|
if (int.TryParse(comboBox.Name.Replace("cmb", ""), out int index))
|
{
|
if (index < csv.Others.Count)
|
{
|
csv.Others[index] = comboBox.Text;
|
}
|
else
|
{
|
csv.Others.Add(comboBox.Text);
|
}
|
}
|
}
|
break;
|
}
|
}
|
}
|
|
private void btnAddMsg_Click(object sender, EventArgs e)
|
{
|
csv.Others.Add("");
|
|
this.BeginInvoke(new Action(() =>
|
{
|
try
|
{
|
if (csv.Others.Count > 0)
|
{
|
Single perSpace = 100 / csv.Others.Count;
|
|
while (tableLayoutPanel1.ColumnCount - 4 < csv.Others.Count)
|
{
|
tableLayoutPanel1.ColumnCount++;
|
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, perSpace));
|
}
|
|
for (int i = 4; i < tableLayoutPanel1.ColumnCount; i++)
|
{
|
tableLayoutPanel1.ColumnStyles[i].SizeType = SizeType.Percent;
|
tableLayoutPanel1.ColumnStyles[i].Width = perSpace;
|
}
|
|
int index = 0;
|
foreach (var value in csv.Others)
|
{
|
string key = $"cmb{index}";
|
if (!dicComboxs.ContainsKey(key))
|
{
|
ComboBox comboBox = new ComboBox();
|
comboBox.Name = key;
|
comboBox.MouseClick += MouseClick;
|
comboBox.SelectedIndexChanged += SelectedIndexChanged;
|
comboBox.Text = value;
|
comboBox.Dock = DockStyle.Fill;
|
tableLayoutPanel1.Controls.Add(comboBox, index + 4, 0);
|
dicComboxs.TryAdd(key, comboBox);
|
}
|
else
|
{
|
dicComboxs[key].Text = value;
|
}
|
index++;
|
}
|
}
|
}
|
catch { }
|
}));
|
}
|
|
private void btnDelMsg_Click(object sender, EventArgs e)
|
{
|
if (csv.Others.Count <= 0)
|
{
|
return;
|
}
|
|
if (dicComboxs.TryRemove($"cmb{csv.Others.Count - 1}", out ComboBox cmb))
|
{
|
cmb.MouseClick -= MouseClick;
|
cmb.SelectedIndexChanged -= SelectedIndexChanged;
|
tableLayoutPanel1.Controls.Remove(cmb);
|
csv.Others.RemoveAt(csv.Others.Count - 1);
|
}
|
|
this.BeginInvoke(new Action(() =>
|
{
|
try
|
{
|
if (csv.Others.Count > 0)
|
{
|
Single perSpace = 100 / csv.Others.Count;
|
|
tableLayoutPanel1.ColumnCount--;
|
tableLayoutPanel1.ColumnStyles.RemoveAt(tableLayoutPanel1.ColumnStyles.Count - 1);
|
|
for (int i = 4; i < tableLayoutPanel1.ColumnCount; i++)
|
{
|
tableLayoutPanel1.ColumnStyles[i].SizeType = SizeType.Percent;
|
tableLayoutPanel1.ColumnStyles[i].Width = perSpace;
|
}
|
|
int index = 0;
|
foreach (var value in csv.Others)
|
{
|
string key = $"cmb{index}";
|
if (!dicComboxs.ContainsKey(key))
|
{
|
ComboBox comboBox = new ComboBox();
|
comboBox.Name = key;
|
comboBox.MouseClick += MouseClick;
|
comboBox.SelectedIndexChanged += SelectedIndexChanged;
|
comboBox.Text = value;
|
comboBox.Dock = DockStyle.Fill;
|
tableLayoutPanel1.Controls.Add(comboBox, index + 4, 0);
|
dicComboxs.TryAdd(key, comboBox);
|
}
|
else
|
{
|
dicComboxs[key].Text = value;
|
}
|
index++;
|
}
|
}
|
}
|
catch { }
|
}));
|
}
|
}
|
}
|