using LB_VisionProcesses.Alogrithms; 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; namespace LB_VisionProcesses.Processes { /// /// 轮胎计数工具编辑器 /// public partial class TyreCounterProcessEdit : TAlgorithmEdit { DataTable DataTableInputs = new DataTable(); DataTable DataTableOutputs = new DataTable(); public TyreCounterProcessEdit(TyreCounterProcess subject = null) { InitializeComponent(); if (subject == null) subject = new TyreCounterProcess(); this.Subject = subject; } private void TyreCounterProcessEdit_Load(object sender, EventArgs e) { LoadParas(); } /// /// 加载参数 /// public override void LoadParas() { if (Subject is TyreCounterProcess counter) { // 加载配置参数 numericUpDownImagesPerTyre.Value = counter.ImagesPerTyre; comboBoxJudgeRule.SelectedItem = counter.JudgeRule.ToString(); checkBoxAutoReset.Checked = counter.AutoReset; // 加载统计信息 UpdateStatistics(); // 绑定输入参数 DataTableInputs.Columns.Add("Key", typeof(string)); DataTableInputs.Columns.Add("Value", typeof(object)); DataTableInputs.Rows.Clear(); var inputs = new Dictionary { { "ImagesPerTyre", counter.ImagesPerTyre }, { "JudgeRule", counter.JudgeRule.ToString() }, { "AutoReset", counter.AutoReset } }; foreach (var item in inputs) DataTableInputs.Rows.Add(item.Key, item.Value); dataGridInputs.DataSource = DataTableInputs; // 绑定输出参数 DataTableOutputs.Columns.Add("Key", typeof(string)); DataTableOutputs.Columns.Add("Value", typeof(object)); DataTableOutputs.Rows.Clear(); var outputs = new Dictionary { { "CurrentTyreID", counter.CurrentTyreID }, { "CurrentImageIndex", counter.CurrentImageIndex }, { "IsTyreComplete", counter.IsTyreComplete }, { "TyreResult", counter.TyreResult }, { "TyreTotal", counter.TyreTotal }, { "TyreOK", counter.TyreOK }, { "TyreNG", counter.TyreNG }, { "TyreRateOK", counter.TyreRateOK } }; foreach (var item in outputs) DataTableOutputs.Rows.Add(item.Key, item.Value); dataGridOutputs.DataSource = DataTableOutputs; // 设置状态栏 lblResult.Text = $"结果: {(counter.Result ? "OK" : "NG")}"; lblResult.ForeColor = counter.Result ? Color.LightGreen : Color.LightCoral; lblMsg.Text = counter.Msg; } } /// /// 更新统计信息显示 /// private void UpdateStatistics() { if (Subject is TyreCounterProcess counter) { txtCurrentTyreID.Text = counter.CurrentTyreID.ToString(); txtCurrentImageIndex.Text = $"{counter.CurrentImageIndex}/{counter.ImagesPerTyre}"; txtTyreTotal.Text = counter.TyreTotal.ToString(); txtTyreOK.Text = counter.TyreOK.ToString(); txtTyreNG.Text = counter.TyreNG.ToString(); txtTyreRateOK.Text = $"{counter.TyreRateOK:F2}%"; } } /// /// 更新输入参数 /// public override void UpdataInputs() { if (Subject is TyreCounterProcess counter) { counter.ImagesPerTyre = (int)numericUpDownImagesPerTyre.Value; counter.JudgeRule = (TyreJudgeRule)Enum.Parse(typeof(TyreJudgeRule), comboBoxJudgeRule.SelectedItem?.ToString() ?? "AnyNG"); counter.AutoReset = checkBoxAutoReset.Checked; // 更新输入参数表 Subject.Params.Inputs["ImagesPerTyre"] = counter.ImagesPerTyre; Subject.Params.Inputs["JudgeRule"] = counter.JudgeRule.ToString(); Subject.Params.Inputs["AutoReset"] = counter.AutoReset; } } private void btnSave_Click(object sender, EventArgs e) { UpdataInputs(); lblMsg.Text = "参数已保存"; lblMsg.ForeColor = Color.LightGreen; } private void btnReset_Click(object sender, EventArgs e) { if (Subject is TyreCounterProcess counter) { counter.ResetTyreCount(); UpdateStatistics(); LoadParas(); lblMsg.Text = "计数器已重置"; lblMsg.ForeColor = Color.LightGreen; } } private void btnRun_Click(object sender, EventArgs e) { UpdataInputs(); Subject.Run(); UpdateStatistics(); LoadParas(); lblResult.Text = $"结果: {(Subject.Result ? "OK" : "NG")}"; lblResult.ForeColor = Subject.Result ? Color.LightGreen : Color.LightCoral; lblMsg.Text = Subject.Msg; } } }