Commit 31cad832 LN

aoi界面调整

1 个父辈 bd2d05c4
...@@ -309,6 +309,12 @@ ...@@ -309,6 +309,12 @@
<Compile Include="projector\FrmScreenTest.Designer.cs"> <Compile Include="projector\FrmScreenTest.Designer.cs">
<DependentUpon>FrmScreenTest.cs</DependentUpon> <DependentUpon>FrmScreenTest.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="workForm\FrmAOICheckN.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="workForm\FrmAOICheckN.Designer.cs">
<DependentUpon>FrmAOICheckN.cs</DependentUpon>
</Compile>
<Compile Include="workForm\FrmAOICheck.cs"> <Compile Include="workForm\FrmAOICheck.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
...@@ -493,6 +499,9 @@ ...@@ -493,6 +499,9 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="workForm\FrmAOICheckN.resx">
<DependentUpon>FrmAOICheckN.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="workForm\FrmAOICheck.resx"> <EmbeddedResource Include="workForm\FrmAOICheck.resx">
<DependentUpon>FrmAOICheck.cs</DependentUpon> <DependentUpon>FrmAOICheck.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
...@@ -573,6 +582,9 @@ ...@@ -573,6 +582,9 @@
</Content> </Content>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Properties\app.manifest" /> <None Include="Properties\app.manifest" />
<Content Include="image\wait.gif">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Properties\en-US.resource"> <Content Include="Properties\en-US.resource">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
......
using Acc.ImageBox;
namespace TSA_V
{
partial class FrmAOICheckN
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.panel1 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.listErrorView = new System.Windows.Forms.ListView();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.修正ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.lblResult = new System.Windows.Forms.Label();
this.btnUpdateImg = new System.Windows.Forms.Button();
this.chbAllShow = new System.Windows.Forms.CheckBox();
this.btnExit = new System.Windows.Forms.Button();
this.btnRun = new System.Windows.Forms.Button();
this.panelImg = new System.Windows.Forms.Panel();
this.picResult = new Acc.ImageBox.AccImageBox();
this.panel3 = new System.Windows.Forms.Panel();
this.picStand = new System.Windows.Forms.PictureBox();
this.timerChangeImg = new System.Windows.Forms.Timer(this.components);
this.panel1.SuspendLayout();
this.panel4.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
this.panelImg.SuspendLayout();
this.panel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picStand)).BeginInit();
this.SuspendLayout();
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// panel1
//
this.panel1.Controls.Add(this.panel4);
this.panel1.Controls.Add(this.panelImg);
this.panel1.Controls.Add(this.panel3);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(1251, 778);
this.panel1.TabIndex = 293;
//
// panel4
//
this.panel4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel4.Controls.Add(this.listErrorView);
this.panel4.Controls.Add(this.lblResult);
this.panel4.Controls.Add(this.btnUpdateImg);
this.panel4.Controls.Add(this.chbAllShow);
this.panel4.Controls.Add(this.btnExit);
this.panel4.Controls.Add(this.btnRun);
this.panel4.Location = new System.Drawing.Point(654, 546);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(592, 226);
this.panel4.TabIndex = 298;
//
// listErrorView
//
this.listErrorView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.listErrorView.ContextMenuStrip = this.contextMenuStrip1;
this.listErrorView.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.listErrorView.HideSelection = false;
this.listErrorView.Location = new System.Drawing.Point(3, 3);
this.listErrorView.MultiSelect = false;
this.listErrorView.Name = "listErrorView";
this.listErrorView.Size = new System.Drawing.Size(586, 138);
this.listErrorView.TabIndex = 299;
this.listErrorView.UseCompatibleStateImageBehavior = false;
this.listErrorView.View = System.Windows.Forms.View.List;
this.listErrorView.SelectedIndexChanged += new System.EventHandler(this.listErrorView_SelectedIndexChanged);
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.修正ToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(101, 26);
//
// 修正ToolStripMenuItem
//
this.修正ToolStripMenuItem.Name = "修正ToolStripMenuItem";
this.修正ToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
this.修正ToolStripMenuItem.Text = "修正";
this.修正ToolStripMenuItem.Click += new System.EventHandler(this.修正ToolStripMenuItem_Click);
//
// lblResult
//
this.lblResult.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.lblResult.Font = new System.Drawing.Font("宋体", 60F, System.Drawing.FontStyle.Bold);
this.lblResult.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
this.lblResult.Location = new System.Drawing.Point(3, 141);
this.lblResult.Name = "lblResult";
this.lblResult.Size = new System.Drawing.Size(124, 85);
this.lblResult.TabIndex = 8;
this.lblResult.Text = "?";
this.lblResult.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnUpdateImg
//
this.btnUpdateImg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnUpdateImg.BackColor = System.Drawing.Color.Transparent;
this.btnUpdateImg.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnUpdateImg.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnUpdateImg.Location = new System.Drawing.Point(210, 174);
this.btnUpdateImg.Name = "btnUpdateImg";
this.btnUpdateImg.Size = new System.Drawing.Size(124, 46);
this.btnUpdateImg.TabIndex = 303;
this.btnUpdateImg.Text = "修正";
this.btnUpdateImg.UseVisualStyleBackColor = false;
this.btnUpdateImg.Visible = false;
this.btnUpdateImg.Click += new System.EventHandler(this.btnUpdateImg_Click);
//
// chbAllShow
//
this.chbAllShow.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.chbAllShow.AutoSize = true;
this.chbAllShow.Checked = true;
this.chbAllShow.CheckState = System.Windows.Forms.CheckState.Checked;
this.chbAllShow.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.chbAllShow.Location = new System.Drawing.Point(133, 188);
this.chbAllShow.Name = "chbAllShow";
this.chbAllShow.Size = new System.Drawing.Size(75, 21);
this.chbAllShow.TabIndex = 302;
this.chbAllShow.Text = "显示所有";
this.chbAllShow.UseVisualStyleBackColor = true;
this.chbAllShow.CheckedChanged += new System.EventHandler(this.chbAllShow_CheckedChanged);
//
// btnExit
//
this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnExit.BackColor = System.Drawing.Color.Transparent;
this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnExit.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnExit.Location = new System.Drawing.Point(462, 174);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(124, 46);
this.btnExit.TabIndex = 293;
this.btnExit.Text = "完成";
this.btnExit.UseVisualStyleBackColor = false;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click_1);
//
// btnRun
//
this.btnRun.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnRun.BackColor = System.Drawing.Color.Transparent;
this.btnRun.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnRun.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnRun.Location = new System.Drawing.Point(336, 174);
this.btnRun.Name = "btnRun";
this.btnRun.Size = new System.Drawing.Size(124, 46);
this.btnRun.TabIndex = 7;
this.btnRun.Text = "执行检测";
this.btnRun.UseVisualStyleBackColor = false;
this.btnRun.Click += new System.EventHandler(this.btnRun_Click);
//
// panelImg
//
this.panelImg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panelImg.AutoScroll = true;
this.panelImg.Controls.Add(this.picResult);
this.panelImg.Location = new System.Drawing.Point(4, 4);
this.panelImg.Name = "panelImg";
this.panelImg.Size = new System.Drawing.Size(644, 768);
this.panelImg.TabIndex = 300;
//
// picResult
//
this.picResult.AllowDoubleClick = true;
this.picResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.picResult.BackColor = System.Drawing.Color.Black;
this.picResult.DragHandleSize = 9;
this.picResult.GridColor = System.Drawing.Color.Black;
this.picResult.GridColorAlternate = System.Drawing.Color.Black;
this.picResult.ImageBorderColor = System.Drawing.SystemColors.ActiveCaptionText;
this.picResult.Location = new System.Drawing.Point(0, 0);
this.picResult.Name = "picResult";
this.picResult.Size = new System.Drawing.Size(644, 758);
this.picResult.TabIndex = 297;
this.picResult.Paint += new System.Windows.Forms.PaintEventHandler(this.picResult_Paint);
this.picResult.DoubleClick += new System.EventHandler(this.picResult_DoubleClick);
//
// panel3
//
this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.panel3.Controls.Add(this.picStand);
this.panel3.Location = new System.Drawing.Point(654, 4);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(592, 539);
this.panel3.TabIndex = 298;
//
// picStand
//
this.picStand.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.picStand.BackColor = System.Drawing.Color.Black;
this.picStand.Location = new System.Drawing.Point(4, 3);
this.picStand.Name = "picStand";
this.picStand.Size = new System.Drawing.Size(585, 533);
this.picStand.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.picStand.TabIndex = 297;
this.picStand.TabStop = false;
this.picStand.Paint += new System.Windows.Forms.PaintEventHandler(this.picStand_Paint);
//
// timerChangeImg
//
this.timerChangeImg.Interval = 1000;
this.timerChangeImg.Tick += new System.EventHandler(this.timerChangeImg_Tick);
//
// FrmAOICheckN
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.ClientSize = new System.Drawing.Size(1251, 778);
this.Controls.Add(this.panel1);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Name = "FrmAOICheckN";
this.Text = "AOI检测";
this.Load += new System.EventHandler(this.FrmCamera_Load);
this.Shown += new System.EventHandler(this.FrmCameraAOI_Shown);
this.panel1.ResumeLayout(false);
this.panel4.ResumeLayout(false);
this.panel4.PerformLayout();
this.contextMenuStrip1.ResumeLayout(false);
this.panelImg.ResumeLayout(false);
this.panel3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.picStand)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Button btnRun;
private System.Windows.Forms.Label lblResult;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.PictureBox picStand;
private System.Windows.Forms.ListView listErrorView;
private System.Windows.Forms.Panel panelImg;
private AccImageBox picResult;
private System.Windows.Forms.CheckBox chbAllShow;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Button btnUpdateImg;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem 修正ToolStripMenuItem;
private System.Windows.Forms.Timer timerChangeImg;
}
}
\ No newline at end of file \ No newline at end of file

using AccAOI.camera;
using AOI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using System.Linq;
using System.Runtime.ExceptionServices;
using Acc.ImageBox;
namespace TSA_V
{
public partial class FrmAOICheckN : FrmBase
{
private string loadImg = @"\image\wait.gif";
private List<ResultBean> ResultList = new List<ResultBean>();
private AOI.AoiProject CurrProject = null;
private DateTime showTime = DateTime.Now;
private DateTime endTime = DateTime.Now;
private bool IsCheck = false;
private bool IsUpdate = false;
/// <summary>
/// 检测结果,0=未知,1=OK,2=NG
/// </summary>
private int CheckResult =0;
private int waitSeconds = 0;
public string defFile { get
{
//return @"G:\1.bmp";
return Application.StartupPath + @"\test (2).bmp";
return Application.StartupPath + @"\test.bmp";
}
set { } }
public FrmAOICheckN(AoiProject currAoi )
{
InitializeComponent();
CurrProject = currAoi;
updateMName = new List<string>();
}
private void FrmCamera_Load(object sender, EventArgs e)
{
btnUpdateImg.Visible = false;
timer1.Start();
//默认显示程序配置的 图片
if (CurrProject == null)
{
this.Close();
return;
}
else
{
string currProjectName = BoardManager.CurrBoard.GetAoiFileName();
//string filePath = Application.StartupPath + @"\config\\AOIConfig" + currProjectName + "bmp";
string extension = Path.GetExtension(currProjectName);
string filename = currProjectName.Replace(extension, ".bmp");
ShowBaseImg(filename,"Base");
}
ShowMsg(ResourceCulture.GetString("{0}秒后自动检测", "{0}秒后自动检测", waitSeconds.ToString()));
修正ToolStripMenuItem.Text = ResourceCulture.GetString("FrmAOICheck_btnUpdateImg_Text", "修正");
this.StartPosition=FormStartPosition.CenterParent;
this.WindowState = FormWindowState.Maximized;
timerChangeImg.Start();
timerChangeImg_Tick(null, null);
// this.picResult.Image = CurrProject.standardImage;
}
private string showMsg = "";
private string showErrMsg = "";
private void ShowMsg(string msg)
{
showMsg = msg;
picResult.Invalidate();
}
private void ShowErrMsg(string msg)
{
showErrMsg = msg;
picResult.Invalidate();
}
private void ShowBaseImg(string filePath,string Text)
{
if (File.Exists(filePath))
{
var bmp = new Bitmap(filePath);
this.picResult.Image= Eyemlib.DeepClone(bmp);
bmp.Dispose();
}
}
private bool isAutoClose = false;
private void UpdateTextResult(Label label, int result)
{
if (result.Equals(0))
{
label.ForeColor = Color.Orange;
label.Text = "?";
}
else if (result.Equals(1))
{
label.Text = "OK";
label.ForeColor = Color.Green;
}
else if (result.Equals(2))
{
label.Text = "NG";
label.ForeColor = Color.Red;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (IsUpdate)
{
}
else
{
btnRun.Visible = !IsCheck;
}
TimeSpan span = DateTime.Now - showTime;
if (!IsCheck)
{
int times = waitSeconds - (int)(span.TotalSeconds);
if (times > 0)
{
if (times <= 1)
{
ShowMsg( ResourceCulture.GetString("开始自动检测", "开始自动检测") + "......");
}else
{
ShowMsg(ResourceCulture.GetString("{0}秒后自动检测", "{0}秒后自动检测", times.ToString()));
}
}
else
{
ShowMsg(ResourceCulture.GetString("开始自动检测", "开始自动检测"));
CheckResult = AoiCheck();
MesUtil.SetAOIResult(CheckResult);
UpdateTextResult(lblResult, CheckResult);
isAutoClose = CheckResult.Equals(1);
}
}
else
{
ShowMsg(ResourceCulture.GetString("请点击完成按钮结束检测", "请点击完成按钮结束检测", 0));
if (isAutoClose)
{
TimeSpan closeSpan = DateTime.Now - endTime;
int times = 3 - (int)(closeSpan.TotalSeconds);
if (times < 0)
{
ShowMsg(ResourceCulture.GetString("{0}秒后自动完成", "{0}秒后自动完成", 0));
this.Close();
}
else
{
ShowMsg(ResourceCulture.GetString("{0}秒后自动完成", "{0}秒后自动完成", times.ToString()));
}
}
}
}
[HandleProcessCorruptedStateExceptions]
private int AoiCheck()
{
GC.Collect(0, GCCollectionMode.Forced);
//GC.Collect();
IsCheck = true;
ShowMsg("");
ShowErrMsg("");
int result = 2;
try
{
if (CurrProject == null)
{
return 0;
}
chbAllShow.Visible = false;
string camera = Setting_NInit.Device_CameraName;
if (camera == "")
{
camera = AccAOI.camera.CameraManager.hikNameList.ToArray().FirstOrDefault();
}
DateTime startTime = DateTime.Now;
LogUtil.info("AOICheck : 开始获取图片");
string theImagePath = "";
using (Bitmap currImage = CameraManager.GetCamerImage(camera))
{
if (currImage == null)
{
string file = defFile;
if (File.Exists(file))
{
theImagePath = file;
}
}
if (currImage != null)
{
if (Setting_NInit.Work_SaveAOIImg)
{
theImagePath = ImageUtilM.SaveImageToFile("AOI", "Source", currImage);
}
else
{
string filePath = Application.StartupPath + @"\image\";
Directory.CreateDirectory(filePath);
string fileName = @"\test.bmp";
string path = Path.GetFullPath(filePath);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
theImagePath = filePath + fileName;
currImage.Save(filePath + fileName, ImageFormat.Bmp);
}
}
}
if (theImagePath != "" && File.Exists(theImagePath))
{
TimeSpan span1 = DateTime.Now - startTime;
LogUtil.info($"AOICheck : 图片获取{theImagePath}完成, {Math.Round(span1.TotalMilliseconds, 1)}ms, 开始check");
var bmp = new Bitmap(theImagePath);
Image TestImage = Eyemlib.DeepClone(bmp);
bmp.Dispose();
//Bitmap bitmap = new Bitmap(currImage);
Image outImage = null;
List<ResultBean> resultBean = CurrProject.CheckAll(TestImage, out outImage);
span1 = DateTime.Now - startTime;
LogUtil.info($"AOICheck : check完成, {Math.Round(span1.TotalMilliseconds, 1)}ms");
ResultList = resultBean;
if (outImage != null)
{
this.picResult.Image = outImage;
if (Setting_NInit.Work_SaveAOIResult)
{
ImageUtilM.SaveImageToFile("AOI", "Result", Eyemlib.DeepClone(outImage));
}
}
else
{
this.picResult.Image = Eyemlib.DeepClone(TestImage);
}
result = 1;
endTime = DateTime.Now;
string ngList = "NG:\r\n";
listErrorView.Items.Clear();
foreach (ResultBean bean in resultBean)
{
if (bean.result.Equals(false))
{
ngList += bean.MethodName + "\r\n";
result = 2;
// break;
listErrorView.Items.Add(GetShowName(bean));
}
else if (chbAllShow.Checked)
{
listErrorView.Items.Add(GetShowName(bean));
}
}
//if (listErrorView.Items.Count > 0)
//{
// listErrorView.Items[0].Selected = true;
//}
chbAllShow.Visible = true;
if (result.Equals(1))
{
ShowErrMsg("");
string resStr= AccAOI.ControlUtil.GetResultsStr(resultBean);
//lblInfo.Visible = true;
LogUtil.info("AOI检测OK:" + resStr);
}
else
{
ShowErrMsg(ngList);
LogUtil.info("AOI检测NG:" + ngList);
}
TestImage.Dispose();
}
else
{
ShowErrMsg(ResourceCulture.GetString("获取相机图片失败", "获取相机图片失败"));
LogUtil.error("AOI检测:获取相机图片失败:" + CameraManager.ErrorMsg);
return 0;
}
chbAllShow.Visible = true;
}
catch (AccessViolationException e)
{
LogUtil.error("检测出错 AccessViolationException 异常 ." + e.ToString());
}
catch (Exception ex)
{
ShowMsg(ResourceCulture.GetString("执行检测失败", "执行检测失败"));
LogUtil.error("检测出错:" + ex.ToString());
}
UpdateResMap(true);
return result;
}
private string GetShowName(ResultBean bean)
{
return (bean.result ? "✔ " : "✘ ") + bean.MethodName;
}
private string GetNameByText(string str)
{
string name= str.Substring(2, str.Length - 2);
return name;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnRun_Click(object sender, EventArgs e)
{
CheckResult = AoiCheck();
MesUtil.SetAOIResult(CheckResult);
UpdateTextResult(lblResult, CheckResult);
if (CheckResult.Equals(1))
{
isAutoClose = true;
}
else
{
isAutoClose = false;
}
}
private void FrmCameraAOI_Shown(object sender, EventArgs e)
{
showTime = DateTime.Now;
}
private void btnExit_Click_1(object sender, EventArgs e)
{
timer1.Stop();
this.Close();
}
private ResultBean selectResultBean = null;
private void listErrorView_SelectedIndexChanged(object sender, EventArgs e)
{
if (listErrorView.SelectedItems != null && listErrorView.SelectedItems.Count > 0)
{
string selName = GetNameByText(listErrorView.SelectedItems[0].Text) ;
List<ResultBean> beans = (from m in ResultList where m.MethodName.Equals(selName) select m).ToList<ResultBean>();
if (beans.Count > 0)
{
ResultBean bean = beans[0];
picStand.Image = bean.standardRoiImage;
//picCurr.Image = ImageManager.DeepClone( bean.currentRoiImage);
picResult.SelectionRegion = bean.roiPath;
//如果结果NG,可以修正
if(!bean.result && (!updateMName.Contains(bean.MethodName)))
{
selectResultBean = bean;
btnUpdateImg.Visible = true;
listErrorView.ContextMenuStrip = this.contextMenuStrip1;
}
else
{
listErrorView.ContextMenuStrip = null;
btnUpdateImg.Visible = false;
}
UpdateResMap(false );
//Graphics g = picResult.CreateGraphics();
//g.DrawPath(new Pen(Color.Orange), bean.roiPath);
//g.Dispose();
}
}
}
private void chbAllShow_CheckedChanged(object sender, EventArgs e)
{
if (ResultList.Count <= 0)
{
return;
}
listErrorView.Items.Clear();
foreach (ResultBean bean in ResultList)
{
if (bean.result.Equals(false))
{
listErrorView.Items.Add(GetShowName(bean));
}
else if (chbAllShow.Checked)
{
listErrorView.Items.Add(GetShowName(bean));
}
}
UpdateResMap(true);
//if (listErrorView.Items.Count > 0)
//{
// listErrorView.Items[0].Selected = true;
//}
//listErrorView_SelectedIndexChanged(null, null);
}
private string getSaveImagePath(string aoiFileName, ResultBean selectResultBean)
{
string path = Path.GetDirectoryName(aoiFileName);
string fileName = Path.GetFileNameWithoutExtension(aoiFileName);
System.Drawing.PointF[] pts = selectResultBean.roiPath.PathPoints;
string pPath = "";
for (int i = 0; i < pts.Length; i++)
{
pPath += (int)pts[i].X + "-" + (int)pts[i].Y + "_";
}
return Path.Combine(path, fileName + @"\" + pPath + @"\");
}
private List<string> updateMName = new List<string>();
private void btnUpdateImg_Click(object sender, EventArgs e)
{
if (selectResultBean == null)
{
return;
}
//if (picCurr.Image == null)
//{
// return;
//}
try
{
DialogResult result = MessageBox.Show(ResourceCulture.GetString("SureUpdateMethod", "确定修正{0}?",
new string[] { selectResultBean.MethodName }), ResourceCulture.GetString("提示"),
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(result != DialogResult.Yes)
{
return;
}
using (Image image = ImageManager.DeepClone(selectResultBean.currentRoiImage))
{
string savePath = getSaveImagePath(BoardManager.CurrBoard.GetAoiFileName(), selectResultBean);
if (!Directory.Exists(savePath))
{
Directory .CreateDirectory(savePath);
}
string imageName = DateTime.Now.ToString("yy-MM-dd-HH-mm-ss-") + DateTime.Now.Millisecond + ".bmp";
image.Save(savePath + imageName, ImageFormat.Bmp);
IsUpdate = true;
btnRun.Visible = true;
btnUpdateImg.Visible = false;
listErrorView.ContextMenuStrip=null;
updateMName.Add(selectResultBean.MethodName);
LogUtil.info($" {BoardManager.CurrBoard} 修正 {selectResultBean.MethodName} 成功,图片保存到:" + savePath + imageName);
}
}
catch (Exception ex)
{
LogUtil.error($" {BoardManager.CurrBoard} 修正 {selectResultBean.MethodName}出错:" + ex.ToString());
}
}
private void 修正ToolStripMenuItem_Click(object sender, EventArgs e)
{
btnUpdateImg_Click(null,null);
}
private void picResult_DoubleClick(object sender, EventArgs e)
{
SaveImg(picResult, "保存图片", "" + DateTime.Now.ToString("MMddHHmmss"));
}
private void SaveImg(ImageBox box, string tittle, string defName)
{
if (box.Image != null)
{
try
{
string DefaultPath = "D:/image";
System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
saveFileDialog.Title = "Save Image";
saveFileDialog.Filter = "(*.bmp)|*.bmp|(*.*)|*.*";
if (!String.IsNullOrEmpty(DefaultPath)&&Directory.Exists(DefaultPath))
{
saveFileDialog.InitialDirectory = DefaultPath;
}
saveFileDialog.FileName = defName;
//openDialog.DefaultExt = "png";
System.Windows.Forms.DialogResult result = saveFileDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
string fileName = saveFileDialog.FileName;
Image image = Eyemlib.DeepClone(box.Image);
image.Save(fileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
private void picResult_Paint(object sender, PaintEventArgs e)
{
if (showMsg != "")
{
e.Graphics.DrawString(showMsg, new Font("Arial ", 9, FontStyle.Regular), Brushes.White, new PointF(5, 5)); // 根据需要调整文字位置
}
if (showErrMsg != "")
{
e.Graphics.DrawString(showErrMsg, new Font("Arial ", 9, FontStyle.Regular), Brushes.Red, new PointF(5, picResult.Height - 20)); // 根据需要调整文字位置
}
}
private int currIndex = 0;
private Dictionary<string,Image> resultM = new Dictionary<string,Image>();
private void UpdateResMap(bool isAll)
{
List<ResultBean> beans = new List<ResultBean>();
resultM = new Dictionary<string, Image>();
if ((!isAll) && listErrorView.SelectedItems != null && listErrorView.SelectedItems.Count > 0)
{
string selName = GetNameByText(listErrorView.SelectedItems[0].Text);
beans = (from m in ResultList where m.MethodName.Equals(selName) select m).ToList<ResultBean>();
}
else
{
beans = (from m in ResultList where m.result == false select m).ToList<ResultBean>();
if (beans.Count <= 0)
{
beans = new List<ResultBean>(ResultList);
}
}
if (beans.Count > 0)
{
foreach (ResultBean bean in beans)
{
picStand.Image = bean.standardRoiImage;
resultM.Add(bean.MethodName+ "-standard", bean.standardRoiImage);
resultM.Add(bean.MethodName + "-current", bean.currentRoiImage);
}
}
currIndex = 0;
}
private Image waitImg = null;
private string lastKey = "";
private void timerChangeImg_Tick(object sender, EventArgs e)
{
if (resultM.Count > 0)
{
if (currIndex >= resultM.Count)
{
currIndex = 0;
}
List<string> keys = new List<string>(resultM.Keys);
string key = keys[currIndex];
this.picStand.Image = resultM[key];
currIndex++;
lastKey = key;
picStand.Invalidate();
}
else if (picStand.Image == null)
{
if (waitImg == null)
{
string file = Application.StartupPath + loadImg;
if (File.Exists(file))
{
waitImg = Image.FromFile(file);
}
}
if (waitImg != null)
{
lastKey = "";
this.picStand.Image = waitImg;
picStand.Invalidate();
}
}
}
private void picStand_Paint(object sender, PaintEventArgs e)
{
if (lastKey != "")
{
e.Graphics.DrawString(lastKey, new Font("Arial ", 9, FontStyle.Regular), Brushes.White, new PointF(5, 5)); // 根据需要调整文字位置
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>109, 17</value>
</metadata>
<metadata name="timerChangeImg.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>273, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>103</value>
</metadata>
</root>
\ No newline at end of file \ No newline at end of file
...@@ -368,7 +368,8 @@ namespace TSA_V ...@@ -368,7 +368,8 @@ namespace TSA_V
IOManager.IOMove(IOManager.Device_Led, IO_VALUE.LOW); IOManager.IOMove(IOManager.Device_Led, IO_VALUE.LOW);
FrmProjectorScreen.instance.ClearPoint(); FrmProjectorScreen.instance.ClearPoint();
//IOManager.IOMove(IOManager.Camera_Led, IO_VALUE.HIGH); //IOManager.IOMove(IOManager.Camera_Led, IO_VALUE.HIGH);
FrmAOICheck frm = new FrmAOICheck(CurrProject); //FrmAOICheck frm = new FrmAOICheck(CurrProject);
FrmAOICheckN frm = new FrmAOICheckN(CurrProject);
frm.ShowDialog(); frm.ShowDialog();
IOManager.IOMove(IOManager.Device_Led, IO_VALUE.HIGH ); IOManager.IOMove(IOManager.Device_Led, IO_VALUE.HIGH );
...@@ -959,7 +960,8 @@ namespace TSA_V ...@@ -959,7 +960,8 @@ namespace TSA_V
PTipSoundProcess.AOIopen = true; PTipSoundProcess.AOIopen = true;
FrmProjectorScreen.instance.ClearPoint(); FrmProjectorScreen.instance.ClearPoint();
// IOManager.IOMove(IOManager.Camera_Led, IO_VALUE.HIGH); // IOManager.IOMove(IOManager.Camera_Led, IO_VALUE.HIGH);
FrmAOICheck frm = new FrmAOICheck(CurrProject); //FrmAOICheck frm = new FrmAOICheck(CurrProject);
FrmAOICheckN frm = new FrmAOICheckN(CurrProject);
frm.defFile = "G:\\组装工作站 AOI\\img\\img\\8.bmp"; frm.defFile = "G:\\组装工作站 AOI\\img\\img\\8.bmp";
frm.ShowDialog(); frm.ShowDialog();
PTipSoundProcess.AOIopen = false; PTipSoundProcess.AOIopen = false;
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!