using Bro.Common.Helper; using Bro.UI.Model.Winform; 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 Bro.M071.Process.UI { [MenuNode("M071_PatchInsertMeasurement", "批量生成检测项", 4, "M071Node", true)] public partial class M071_PatchInsertMeasurement : MenuFrmBase { public M071_PatchInsertMeasurement() { InitializeComponent(); } M071Config Config => Process?.IConfig as M071Config; M071Process Process_M071 => Process as M071Process; public override void OnProcessUpdated() { base.OnProcessUpdated(); if (Config == null) return; this.Invoke(new Action(() => { UIHelper.SetCombo(cboMeasureType, Config.MeasureTypeCollection, "Code", "Code"); UIHelper.SetCombo(cboStartKey, new List(Config.KeyNameCollection), "", ""); UIHelper.SetCombo(cboEndKey, new List(Config.KeyNameCollection), "", ""); })); } private async void btnInsertMeasurement_Click(object sender, EventArgs e) { btnInsertMeasurement.Enabled = false; btnInsertMeasurement.Text = "生成中。。。"; string measureType = cboMeasureType.Text; string startKey = cboStartKey.Text; string endKey = cboEndKey.Text; await PatchInsertMeasurement(measureType, startKey, endKey).ContinueWith(t => { MessageBox.Show(t.Result); }); btnInsertMeasurement.Enabled = true; btnInsertMeasurement.Text = "生成检测项"; } private async Task PatchInsertMeasurement(string measureType, string startKey, string endKey) { return await Task.Run(() => { int startIndex = Config.KeyNameCollection.IndexOf(startKey); int endIndex = Config.KeyNameCollection.IndexOf(endKey); KeyLocation startRect = Config.KeyLocationCollection.FirstOrDefault(u => u.Key == startKey); //KeyLocation endRect = Config.KeyLocationCollection.FirstOrDefault(u => u.Key == endKey); if (startRect == null) { return $"未配置{(startRect == null ? startKey : "")}的显示位置"; } if (startIndex > endIndex) { return "起始键不能小于结束键"; } switch (measureType) { case "Slant": { for (int i = startIndex; i <= endIndex; i++) { int curKeyEdge_X = (i - startIndex + 1) * (startRect.KeyRect.Width + startRect.IntervalRect.Width) + startRect.KeyRect.X - startRect.IntervalRect.Width; int lableX = (curKeyEdge_X + curKeyEdge_X - startRect.KeyRect.Width - 25) / 2; int lable_Up_Y = startRect.KeyRect.Y + (startRect.KeyRect.Height - 25) / 2; MeasurementUnit mUnitUp = new MeasurementUnit(); mUnitUp.MeasureType = measureType; mUnitUp.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "All" }); mUnitUp.DisplayLocation = new Rectangle(lableX, lable_Up_Y, 25, 25); Config.MeasurementUnitCollection.Add(mUnitUp); } } break; case "Alignment": { for (int i = startIndex; i < endIndex; i++) { int curKeyEdge_X = (i - startIndex + 1) * (startRect.KeyRect.Width + startRect.IntervalRect.Width) + startRect.KeyRect.X - startRect.IntervalRect.Width; int nextKeyStart_X = curKeyEdge_X + startRect.IntervalRect.Width; int lableX = (curKeyEdge_X + nextKeyStart_X - 25) / 2; int lable_Up_Y = startRect.KeyRect.Y + 4; int lable_Down_y = startRect.KeyRect.Y + startRect.KeyRect.Height - 4 - 12; MeasurementUnit mUnitUp = new MeasurementUnit(); mUnitUp.MeasureType = measureType; mUnitUp.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "Z2" }); mUnitUp.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i + 1], KeyResultId = "Z1" }); mUnitUp.DisplayLocation = new Rectangle(lableX, lable_Up_Y, 25, 12); Config.MeasurementUnitCollection.Add(mUnitUp); MeasurementUnit mUnitDown = new MeasurementUnit(); mUnitDown.MeasureType = measureType; mUnitDown.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "Z4" }); mUnitDown.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i + 1], KeyResultId = "Z3" }); mUnitDown.DisplayLocation = new Rectangle(lableX, lable_Down_y, 25, 12); Config.MeasurementUnitCollection.Add(mUnitDown); } } break; case "RowAlignment": { int start_X = startRect.KeyRect.X + startRect.KeyRect.Width / 3; int end_X = (startRect.KeyRect.Width + startRect.IntervalRect.Width) * (endIndex - startIndex) + startRect.KeyRect.X + startRect.KeyRect.Width * 2 / 3; int lable_Up_Y = startRect.KeyRect.Y - 6; int lable_Down_Y = startRect.KeyRect.Y + startRect.KeyRect.Height - 6; MeasurementUnit mUnitUp = new MeasurementUnit(); mUnitUp.MeasureType = measureType; for (int i = startIndex; i < endIndex; i++) { mUnitUp.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "Z2" }); mUnitUp.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i + 1], KeyResultId = "Z1" }); } mUnitUp.DisplayLocation = new Rectangle(start_X, lable_Up_Y, end_X - start_X, 12); Config.MeasurementUnitCollection.Add(mUnitUp); MeasurementUnit mUnitDown = new MeasurementUnit(); mUnitDown.MeasureType = measureType; for (int i = startIndex; i < endIndex; i++) { mUnitDown.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i], KeyResultId = "Z4" }); mUnitDown.KeyUnitCollection.Add(new KeyUnitBind() { Key = Config.KeyNameCollection[i + 1], KeyResultId = "Z3" }); } mUnitDown.DisplayLocation = new Rectangle(start_X, lable_Down_Y, end_X - start_X, 12); Config.MeasurementUnitCollection.Add(mUnitDown); } break; } return "已批量生成检测项,请到配置界面查看和保存"; }); } } }