using Bro.Common.Base;
|
using Bro.Common.Helper;
|
using Bro.Common.Interface;
|
using Bro.UI.Model.Winform;
|
using HalconDotNet;
|
using Sunny.UI;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Drawing.Imaging;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
|
namespace Bro.M141.Process.UI
|
{
|
//[MenuNode("点检配置", "点检配置", 8, Common.Helper.EnumHelper.TopMenu.SystemInfo, MenuNodeType.Form)]
|
public partial class FormInspectionSetting : MenuFormBase
|
{
|
M141Process prM141Process => Process as M141Process;
|
M141Config M141Config => Process.IConfig as M141Config;
|
InspectionConfig InspectionConfig => prM141Process.InspectionConfig;
|
|
List<string> _allDefects = new List<string>();
|
|
public FormInspectionSetting()
|
{
|
InitializeComponent();
|
|
flpDefects.Padding = new System.Windows.Forms.Padding(10, 10, 0, 0);
|
flpDefects.AutoScroll = true;
|
flpDefects.VerticalScroll.Visible = true;
|
flpDefects.SizeChanged += FlpDefects_SizeChanged;
|
}
|
|
|
|
|
public override void OnProcessUpdated()
|
{
|
base.OnProcessUpdated();
|
|
this.Invoke(() =>
|
{
|
flpDefects.Controls.Clear();
|
var allSpecs = M141Config.GetSpecList();
|
|
_allDefects = M141Config.DefectSwitchCollection.Where(u => u.IsEnable && allSpecs.All(s => s.Code != u.DefectName)).Select(u => u.DefectName).OrderBy(u => u).ToList();
|
//var allPositionSet = M084Config.PositionSetCollection.Select(u => u.PositionNum).ToList();
|
//var allPositionSet2 = M084Config.PositionSetCollection.Select(u => u.PositionNum2).ToList();
|
|
LoadPositionSetCtrls(_allDefects, M141Config.WorkPositionCollection);
|
|
//M084Config.DefectSwitchCollection.Where(u => u.IsEnable && allSpecs.All(s => s.Code != u.DefectName)).ForEach(u =>
|
//{
|
// var existed = InspectionConfig.CheckDefectNames.FirstOrDefault(t => t.DefectName == u.DefectName);
|
// bool isChecked = existed != null;
|
// if (existed == null)
|
// {
|
// existed = new DefectPositionSet()
|
// {
|
// PositionNum = 1,
|
// DefectName = u.DefectName,
|
// };
|
// }
|
|
// CtrlDefectPositionSet ctrlPset = new CtrlDefectPositionSet(existed, isChecked, allPositionSet);
|
// flpDefects.Controls.Add(ctrlPset);
|
//});
|
|
lblLastSpotCheck.Text = InspectionConfig.LastInspectTime == null ? "无历史点检记录" : $"上次点检时间:{InspectionConfig.LastInspectTime.Value.ToString("yyyy-MM-dd HH:mm:ss")}";
|
|
pgInspectionConfig.SelectedObject = InspectionConfig;
|
});
|
}
|
|
private void LoadPositionSetCtrls(List<string> allDefects, List<WorkPositionSet> allPositionSet)
|
{
|
flpDefects.Controls.Clear();
|
|
allPositionSet.ForEach(u =>
|
{
|
for (int i = 1; i <= 2; i++)
|
{
|
var positionDefects = InspectionConfig.CheckDefectNames.Where(d => d.PositionNum == u.PositionName && d.ProduceIndex == i.ToString()).ToList();
|
CtrlDefectsInPosition ctrl = new CtrlDefectsInPosition(_allDefects, u.PositionName, positionDefects, i.ToString());
|
flpDefects.Controls.Add(ctrl);
|
}
|
});
|
|
FlpDefects_SizeChanged(null, null);
|
}
|
|
|
private void FlpDefects_SizeChanged(object? sender, EventArgs e)
|
{
|
foreach (Control c in flpDefects.Controls)
|
{
|
c.Width = flpDefects.Width - 30;
|
}
|
}
|
|
|
public HImage ConvertHObjectToHImage(HObject obj)
|
{
|
HOperatorSet.CountChannels(obj, out HTuple channels);
|
|
HImage img = new HImage();
|
if (channels.I == 1)
|
{
|
HTuple pointer, type, width, height;
|
HOperatorSet.GetImagePointer1(obj, out pointer, out type, out width, out height);
|
|
//img.GenImage1Extern(type, width, height, pointer, IntPtr.Zero);
|
img.GenImage1(type, width, height, pointer);
|
}
|
else
|
{
|
HTuple pRed, pGreen, pBlue, type, width, height;
|
HOperatorSet.GetImagePointer3(obj, out pRed, out pGreen, out pBlue, out type, out width, out height);
|
|
img.GenImage3(type, width, height, pRed, pGreen, pBlue);
|
}
|
|
return img;
|
}
|
|
private void btnSave_Click(object sender, EventArgs e)
|
{
|
|
//HObject image = new HObject();
|
//HObject zoomImage = new HObject();
|
|
//// 读取图像
|
//HOperatorSet.ReadImage(out image, "C:\\Users\\饶俊\\Desktop\\1111.png");
|
|
//// 调用zoom_image_factor算子
|
//HOperatorSet.ZoomImageFactor(image, out zoomImage, 0.5, 0.5, "constant");
|
|
////HOperatorSet.Threshold(zoomImage, out HObject Regions, 0, 255);
|
////HOperatorSet.GrayFeatures(Regions, image, "mean", out HTuple grayValue);
|
|
|
//// 打印灰度值
|
////MessageBox.Show( grayValue.D.ToString());
|
//HImage a= ConvertHObjectToHImage(zoomImage);
|
//var bitmap = a.ConvertHImageToBitmap();
|
//bitmap.Save("C:\\Users\\饶俊\\Desktop\\222.png", ImageFormat.Png);
|
|
//return;
|
|
|
|
|
List<DefectPositionSet> defectNames = new List<DefectPositionSet>();
|
|
foreach (Control c in flpDefects.Controls)
|
{
|
if (c is CtrlDefectsInPosition cc)
|
{
|
var defects = cc.GetPositionDefects();
|
defectNames.AddRange(defects);
|
}
|
}
|
|
|
|
|
|
//if (defectNames.Count == 0)
|
//{
|
// MessageBox.Show("未选择点检缺陷信息", "保存点检配置提示");
|
// return;
|
//}
|
|
InspectionConfig.CheckDefectNames = defectNames;
|
|
if (prM141Process.SaveInspectionConfig(out string error))
|
{
|
MessageBox.Show("点检配置信息保存成功!");
|
}
|
else
|
{
|
MessageBox.Show($"点检配置信息保存失败\r\n{error}");
|
}
|
}
|
|
//private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
|
//{
|
// foreach (Control c in flpDefects.Controls)
|
// {
|
// if (c is CtrlDefectPositionSet chk)
|
// {
|
// chk.SetChecked(chkSelectAll.Checked);
|
// }
|
// }
|
//}
|
}
|
}
|