Files
VisionEdit/FindLine/FormFindLine.cs

220 lines
7.6 KiB
C#
Raw Normal View History

2019-08-04 21:51:40 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
2019-08-04 21:51:40 +08:00
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CommonMethods;
using HalconDotNet;
using HalconWindow.HalconWindow;
namespace FindLineTool
{
public partial class FormFindLine : Form
{
public FindLine myFindLine = null;
public IToolInfo myToolInfo = null;
public HWindow_Final myHwindow = new HWindow_Final();
/// <summary>
/// 窗体对象实例
/// </summary>
private static FormFindLine _instance;
public static FormFindLine Instance
{
get
{
if(_instance != null)
2019-08-04 21:51:40 +08:00
{
lock (_instance)
2019-08-04 21:51:40 +08:00
{
if (_instance == null)
{
object line = new object();
_instance = new FormFindLine(ref line);
}
return _instance;
}
}
else
{
object line = new object();
_instance = new FormFindLine(ref line);
2019-08-04 21:51:40 +08:00
return _instance;
}
2019-08-04 21:51:40 +08:00
}
}
public FormFindLine(ref object findLine)
{
InitializeComponent();
_instance = this;
myToolInfo = (IToolInfo)findLine;
myFindLine = (FindLine)myToolInfo.tool;
//myFindLine.inputImage = ComGlobalParams.inputImageGlobal; // 暂时直接将图像传递给该工具
2019-08-04 21:51:40 +08:00
myFindLine.DispImage();
2019-08-04 21:51:40 +08:00
}
private void FormFindLine_Load(object sender, EventArgs e)
{
this.panel1.Controls.Add(myHwindow);
myHwindow.Dock = DockStyle.Fill;
InitTool();
}
private void btn_moveCliperRegion_Click(object sender, EventArgs e)
{
myFindLine.UpdateImage();
2019-08-04 21:51:40 +08:00
myFindLine.DrawExpectLine(myHwindow);
}
2019-08-04 21:51:40 +08:00
public void TextBoxMessageDisp(string mes, Color setColor)
{
txbLog.BackColor = setColor;
txbLog.Text = mes;
txbLog.Font = new Font("微软雅黑", 10, FontStyle.Bold);
// CommonMethods.CommonMethods.Delay(2000);
2019-08-04 21:51:40 +08:00
txbLog.BackColor = Color.White;
}
private void btn_runFindLineTool_Click(object sender, EventArgs e)
{
// 更改界面中参数,实时更新类中参数
myFindLine.expectLineStartRow = Convert.ToDouble(tbx_expectLineStartRow.Text.Trim());
myFindLine.expectLineStartCol = Convert.ToDouble(tbx_expectLineStartCol.Text.Trim());
myFindLine.expectLineEndRow = Convert.ToDouble(tbx_expectLineEndRow.Text.Trim());
myFindLine.expectLineEndCol = Convert.ToDouble(tbx_expectLineEndCol.Text.Trim());
// 运行参数
myFindLine.minScore = Convert.ToDouble(tbx_minScore.Text.Trim());
myFindLine.cliperNum = Convert.ToInt16(tbx_caliperNum.Text.Trim());
myFindLine.threshold = Convert.ToInt16(tbx_threshold.Text.Trim());
myFindLine.length = Convert.ToInt16(tbx_caliperLength.Text.Trim());
myFindLine.weidth = Convert.ToInt16(tbx_caliperLength2.Text.Trim());
myFindLine.polarity = cbx_polarity.SelectedItem.ToString() == "从明到暗" ? "negative":"positive";
2019-08-04 21:51:40 +08:00
myFindLine.edgeSelect = cbx_edgeSelect.SelectedItem.ToString();
myFindLine.sigma = Convert.ToDouble(tbx_Sigma.Text.Trim());
// Run
myFindLine.Run(SoftwareRunState.Debug);
2019-08-04 21:51:40 +08:00
}
public void InitTool()
{
this.Text = myToolInfo.toolName;
btn_runFindLineTool.Focus();
Application.DoEvents();
//myFindLine.Run(); //运行一下,使卡尺显示出来
tbx_expectLineStartRow.Text = myFindLine.expectLineStartRow.ToString();
tbx_expectLineStartCol.Text = myFindLine.expectLineStartCol.ToString();
tbx_expectLineEndRow.Text = myFindLine.expectLineEndRow.ToString();
tbx_expectLineEndCol.Text = myFindLine.expectLineEndCol.ToString();
cbx_edgeSelect.Text = myFindLine.edgeSelect;
tbx_minScore.Text = myFindLine.minScore.ToString();
cbx_polarity.Text = myFindLine.polarity == "positive" ? "从暗到明" : "从明到暗";
2019-08-04 21:51:40 +08:00
tbx_caliperNum.Text = myFindLine.cliperNum.ToString();
tbx_caliperLength.Text = myFindLine.length.ToString();
tbx_threshold.Text = myFindLine.threshold.ToString();
tbx_Sigma.Text = myFindLine.sigma.ToString();
tbx_caliperLength2.Text = myFindLine.weidth.ToString();
chBDispRec.Checked = myFindLine.dispRec;
chBDispCross.Checked = myFindLine.dispCross;
2019-08-04 21:51:40 +08:00
}
#region
private void tbx_expectLineStartRow_TextChanged(object sender, EventArgs e)
{
try
{
myFindLine.expectLineStartRow = Convert.ToDouble(tbx_expectLineStartRow.Text.Trim());
}
catch
{
TextBoxMessageDisp("输入了非法字符已自动替换为默认值200", Color.Red);
tbx_expectLineStartRow.Text = "200";
}
}
private void tbx_expectLineStartCol_TextChanged(object sender, EventArgs e)
{
try
{
myFindLine.expectLineStartCol = Convert.ToDouble(tbx_expectLineStartCol.Text.Trim());
}
catch
{
TextBoxMessageDisp("输入了非法字符已自动替换为默认值200", Color.Red);
tbx_expectLineStartCol.Text = "200";
}
}
private void tbx_expectLineEndRow_TextChanged(object sender, EventArgs e)
{
try
{
myFindLine.expectLineEndRow = Convert.ToDouble(tbx_expectLineEndRow.Text.Trim());
}
catch
{
TextBoxMessageDisp("输入了非法字符已自动替换为默认值200", Color.Red);
tbx_expectLineEndRow.Text = "200";
}
}
private void tbx_expectLineEndCol_TextChanged(object sender, EventArgs e)
{
try
{
myFindLine.expectLineEndCol = Convert.ToDouble(tbx_expectLineEndCol.Text.Trim());
}
catch
{
TextBoxMessageDisp("输入了非法字符已自动替换为默认值600", Color.Red);
tbx_expectLineEndCol.Text = "600";
}
}
private void chBDispRec_CheckedChanged(object sender, EventArgs e)
{
if(chBDispRec.Checked)
{
myFindLine.dispRec = true;
}
else
{
myFindLine.dispRec = false;
}
}
private void chBDispCross_CheckedChanged(object sender, EventArgs e)
{
if(chBDispCross.Checked)
{
myFindLine.dispCross = true;
}
else
{
myFindLine.dispCross = false;
}
}
2019-08-04 21:51:40 +08:00
#endregion
private void FormFindLine_FormClosing(object sender, FormClosingEventArgs e)
{
myHwindow.Dispose();
this.Dispose();
this.Dispose();
GC.Collect();
}
2019-08-04 21:51:40 +08:00
}
}