更改运行方式,添加两种模式Debug和Release模式对在界面点击运行和在工具中运行进行区分

This commit is contained in:
liu.wenjie
2019-08-13 20:45:04 +08:00
parent a4993a95fa
commit e2de1d384f
124 changed files with 137 additions and 95 deletions

Binary file not shown.

View File

@@ -118,6 +118,9 @@ namespace CaliperTool
public ToolRunStatu toolRunStatu { get; set; } = ToolRunStatu.Not_Run;
public SoftwareRunState softwareRunState { get; set; } = SoftwareRunState.Debug;
public void DispImage()
{
if (inputImage != null)
@@ -174,13 +177,16 @@ namespace CaliperTool
DispImage();
}
public void Run()
public void Run(SoftwareRunState softwareRunState)
{
HTuple HMeasureHandle = new HTuple();
HTuple resultRow, resultCol;
if (inputImage == null)
{
FormCaliper.Instance.TextBoxMessageDisp("图像为空", System.Drawing.Color.Red);
if(softwareRunState == SoftwareRunState.Debug)
{
FormCaliper.Instance.TextBoxMessageDisp("图像为空", System.Drawing.Color.Red);
}
toolRunStatu = ToolRunStatu.Not_Input_Image;
return;
}
@@ -217,18 +223,25 @@ namespace CaliperTool
}
//把点显示出来
HOperatorSet.GenCrossContourXld(out crossDisp, ResulttRow, ResultCol, new HTuple(12), new HTuple(0));
DispMainWindow(FormCaliper.Instance.myHwindow);
HOperatorSet.GenCrossContourXld(out crossDisp, ResulttRow, ResultCol, new HTuple(60), new HTuple(0));
if(softwareRunState == SoftwareRunState.Debug)
{
DispMainWindow(FormCaliper.Instance.myHwindow);
FormCaliper.Instance.tbx_resultStartRow.Text = ResulttRow.ToString();
FormCaliper.Instance.tbx_resultStartCol.Text = ResultCol.ToString();
FormCaliper.Instance.TextBoxMessageDisp("运行成功", System.Drawing.Color.Green);
}
// 参数传递
ParamsTrans();
FormCaliper.Instance.tbx_resultStartRow.Text = ResulttRow.ToString();
FormCaliper.Instance.tbx_resultStartCol.Text = ResultCol.ToString();
FormCaliper.Instance.TextBoxMessageDisp("运行成功", System.Drawing.Color.Green);
toolRunStatu = ToolRunStatu.Succeed;
}
catch (Exception ex)
{
FormCaliper.Instance.TextBoxMessageDisp("工具运行异常" + ex.Message, System.Drawing.Color.Red);
toolRunStatu = ToolRunStatu.Not_Succeed;
if (softwareRunState == SoftwareRunState.Debug)
{
FormCaliper.Instance.TextBoxMessageDisp("工具运行异常" + ex.Message, System.Drawing.Color.Red);
}
}
finally
{
@@ -243,9 +256,13 @@ namespace CaliperTool
/// </summary>
private void ParamsTrans()
{
FormCaliper.Instance.myToolInfo.toolOutput.Clear();
FormCaliper.Instance.myToolInfo.toolOutput.Add(new ToolIO("outputCenterRow", ResulttRow, DataType.IntValue));
FormCaliper.Instance.myToolInfo.toolOutput.Add(new ToolIO("outputCenterColumn", ResultCol, DataType.IntValue));
if(FormCaliper.Instance.myToolInfo != null)
{
FormCaliper.Instance.myToolInfo.toolOutput.Clear();
FormCaliper.Instance.myToolInfo.toolOutput.Add(new ToolIO("outputCenterRow", ResulttRow, DataType.IntValue));
FormCaliper.Instance.myToolInfo.toolOutput.Add(new ToolIO("outputCenterColumn", ResultCol, DataType.IntValue));
}
}
public void DispMainWindow(HWindow_Final window)
@@ -258,7 +275,7 @@ namespace CaliperTool
// 显示交点
if (dispCross)
{
window.DispObj(crossDisp, "orange");
window.DispObj(crossDisp, "yellow");
}
//显示找到的线
// window.DispObj(LineDisp, "green");

View File

@@ -19,14 +19,14 @@ namespace CaliperTool
public IToolInfo myToolInfo = null;
public HWindow_Final myHwindow = new HWindow_Final();
private static FormCaliper _instance;
private static FormCaliper _instance = null;
public FormCaliper(ref object caliper)
{
InitializeComponent();
myToolInfo = (IToolInfo)caliper;
myCaliper = (Caliper)myToolInfo.tool;
_instance = this;
myCaliper.DispImage();
}
public static FormCaliper Instance
{
@@ -86,7 +86,7 @@ namespace CaliperTool
txbLog.BackColor = setColor;
txbLog.Text = mes;
txbLog.Font = new Font("微软雅黑", 10, FontStyle.Bold);
CommonMethods.CommonMethods.Delay(2000);
//CommonMethods.CommonMethods.Delay(2000);
txbLog.BackColor = Color.White;
}
@@ -98,12 +98,12 @@ namespace CaliperTool
myCaliper.expectAngle = Convert.ToDouble(tbx_expectPhi.Text.Trim());
// 运行参数
myCaliper.threshold = Convert.ToInt16(tbx_threshold.Text.Trim());
myCaliper.length1 = Convert.ToInt16(tbx_caliperLength1.Text.Trim());
myCaliper.length2 = Convert.ToInt16(tbx_caliperLength2.Text.Trim());
myCaliper.length1 = Convert.ToDouble(tbx_caliperLength1.Text.Trim());
myCaliper.length2 = Convert.ToDouble(tbx_caliperLength2.Text.Trim());
myCaliper.polarity = cbx_polarity.SelectedItem.ToString() == "从明到暗" ? "negative" : "positive";
myCaliper.edgeSelect = cbx_edgeSelect.SelectedItem.ToString();
myCaliper.sigma = Convert.ToDouble(tbx_Sigma.Text.Trim());
myCaliper.Run();
myCaliper.Run(SoftwareRunState.Debug);
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -55,6 +55,12 @@ namespace CommonMethods
Pose,
}
public enum SoftwareRunState
{
Debug,
Release
}
public enum ToolRunStatu
{
Not_Run,

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -187,10 +187,18 @@ namespace FindLineTool
}
set { _angle = value; }
}
/// <summary>
/// 输入图像
/// </summary>
public HObject inputImage { get; set; } = null;
/// <summary>
/// 工具运行结果
/// </summary>
public ToolRunStatu toolRunStatu { get; set; } = ToolRunStatu.Not_Run;
/// <summary>
/// 软件运行状态
/// </summary>
public SoftwareRunState softwareRunState { get; set; } = SoftwareRunState.Debug;
public void DispImage()
{
if(inputImage != null)
@@ -205,7 +213,7 @@ namespace FindLineTool
DispImage();
}
public void Run()
public void Run(SoftwareRunState softwareRunState)
{
HTuple homMat2DArrow = null;
HObject arrow = null, arrowTrans = null;
@@ -213,7 +221,10 @@ namespace FindLineTool
if (inputImage == null)
{
FormFindLine.Instance.TextBoxMessageDisp("图像为空", System.Drawing.Color.Red);
if(softwareRunState == SoftwareRunState.Debug)
{
FormFindLine.Instance.TextBoxMessageDisp("图像为空", System.Drawing.Color.Red);
}
toolRunStatu = ToolRunStatu.Not_Input_Image;
return;
}
@@ -304,20 +315,24 @@ namespace FindLineTool
Point end = new Point() { Row = ResultLineEndRow, Col = ResultLineEndCol };
resultLine = new Line() { StartPoint = start, EndPoint = end };
}
DispMainWindow(FormFindLine.Instance.myHwindow);
HOperatorSet.AngleLx(ResultLineStartRow, ResultLineStartCol, ResultLineEndRow, ResultLineEndCol, out _angle);
if (softwareRunState == SoftwareRunState.Debug)
{
DispMainWindow(FormFindLine.Instance.myHwindow);
FormFindLine.Instance.tbx_resultStartRow.Text = ResultLineStartRow.ToString();
FormFindLine.Instance.tbx_resultStartCol.Text = ResultLineEndCol.ToString();
FormFindLine.Instance.tbx_resultEndRow.Text = ResultLineEndRow.ToString();
FormFindLine.Instance.tbx_resultEndCol.Text = ResultLineEndCol.ToString();
FormFindLine.Instance.TextBoxMessageDisp("运行成功", System.Drawing.Color.Green);
}
HOperatorSet.ClearMetrologyModel(handleID);
// 参数传递
ParamsTrans();
FormFindLine.Instance.tbx_resultStartRow.Text = ResultLineStartRow.ToString();
FormFindLine.Instance.tbx_resultStartCol.Text = ResultLineEndCol.ToString();
FormFindLine.Instance.tbx_resultEndRow.Text = ResultLineEndRow.ToString();
FormFindLine.Instance.tbx_resultEndCol.Text = ResultLineEndCol.ToString();
FormFindLine.Instance.TextBoxMessageDisp("运行成功", System.Drawing.Color.Green);
toolRunStatu = ToolRunStatu.Succeed;
}
catch (Exception ex)
{
toolRunStatu = ToolRunStatu.Not_Succeed;
FormFindLine.Instance.TextBoxMessageDisp("工具运行异常" + ex.Message, System.Drawing.Color.Red);
}
finally
@@ -352,7 +367,7 @@ namespace FindLineTool
FormFindLine.Instance.tbx_expectLineEndCol.Text = expectLineEndCol.TupleString("10.3f");
myHwindow.DrawModel = false;
Run();
Run(SoftwareRunState.Debug);
}
catch (Exception ex)
{

View File

@@ -80,7 +80,7 @@ namespace FindLineTool
txbLog.BackColor = setColor;
txbLog.Text = mes;
txbLog.Font = new Font("微软雅黑", 10, FontStyle.Bold);
CommonMethods.CommonMethods.Delay(2000);
// CommonMethods.CommonMethods.Delay(2000);
txbLog.BackColor = Color.White;
}
@@ -101,7 +101,7 @@ namespace FindLineTool
myFindLine.edgeSelect = cbx_edgeSelect.SelectedItem.ToString();
myFindLine.sigma = Convert.ToDouble(tbx_Sigma.Text.Trim());
// Run
myFindLine.Run();
myFindLine.Run(SoftwareRunState.Debug);
}
public void InitTool()

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -91,7 +91,7 @@ namespace HalconTool
{
}
myHalconTool.DispImage();
myHalconTool.Run(SoftwareRunState.Debug);
ParamsTrans();
}

View File

@@ -81,32 +81,16 @@ namespace HalconTool
/// 读取单张图像或批量读取文件夹图像工作模式
/// </summary>
internal WorkMode workMode = WorkMode.ReadMultImage;
public ToolRunStatu toolRunStatu { get; set; } = ToolRunStatu.Not_Run;
public ToolRunStatu toolRunStatu
{
get
{
throw new NotImplementedException();
}
public HObject inputImage { get; set; } = null;
set
{
throw new NotImplementedException();
}
}
public HObject inputImage
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
/// <summary>
/// 运行模式
/// </summary>
public SoftwareRunState softwareRunState { get; set; } = SoftwareRunState.Debug;
public bool ReadImage(out string filePath)
{
@@ -124,8 +108,9 @@ namespace HalconTool
return true;
}
public void Run()
public void Run(SoftwareRunState softwareState)
{
softwareRunState = softwareState;
DispImage();
}
@@ -149,13 +134,18 @@ namespace HalconTool
}
catch
{
FormHalconTool.Instance.txbLog.Text = "图像文件异常或路径不合法";
CommonMethods.CommonMethods.Delay(1000);
if(softwareRunState == SoftwareRunState.Debug)
{
FormHalconTool.Instance.txbLog.Text = "图像文件异常或路径不合法";
}
return;
}
if (outputImage != null)
{
FormHalconTool.Instance.myHwindow.HobjectToHimage(outputImage);
if (softwareRunState == SoftwareRunState.Debug)
{
FormHalconTool.Instance.myHwindow.HobjectToHimage(outputImage);
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -10,8 +10,9 @@ namespace ToolBase
{
public interface IToolBase
{
SoftwareRunState softwareRunState { get; set; }
ToolRunStatu toolRunStatu { get; set; }
void Run();
void Run(SoftwareRunState softwareRunState);
HObject inputImage { get; set; }
void DispImage();
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -686,7 +686,7 @@ namespace VisionEdit
#region halconTool
case ToolType.HalconTool:
HalconTool.HalconTool myHalconTool = (HalconTool.HalconTool)L_toolList[i].tool;
myHalconTool.Run();
myHalconTool.Run(SoftwareRunState.Release);
if(myHalconTool.outputImage == null)
{
FormLogDisp(L_toolList[i].toolName + " 运行失败", Color.Red, treeNode);
@@ -717,61 +717,74 @@ namespace VisionEdit
sourceToolName = sourceToolName.Substring(3, Regex.Split(sourceFrom, " . ")[0].Length - 3);
string toolItem = Regex.Split(sourceFrom, " . ")[1];
myFindLine.inputImage = GetToolInfoByToolName(GlobalParams.myVisionJob.JobName, sourceToolName).GetOutput(toolItem).value as HObject;
// myFindLine.Run();
}
if(myFindLine.resultLine != null)
{
myFindLine.DispMainWindow(myFormImageWindow.myHWindow);
FormLogDisp(L_toolList[i].toolName + " 运行成功", Color.Green, treeNode);
}
else
{
FormLogDisp(L_toolList[i].toolName + " 运行失败", Color.Red, treeNode);
}
}
}
myFindLine.Run(SoftwareRunState.Release);
if (myFindLine.toolRunStatu == ToolRunStatu.Succeed)
{
myFindLine.DispMainWindow(myFormImageWindow.myHWindow);
FormLogDisp(L_toolList[i].toolName + " 运行成功", Color.Green, treeNode);
}
else
{
FormLogDisp(L_toolList[i].toolName + " 运行失败", Color.Red, treeNode);
}
break;
#endregion
case ToolType.Caliper:
Caliper myCaliper = (Caliper)L_toolList[i].tool;
if(L_toolList[i].FormTool == null)
{
FormLogDisp(L_toolList[i].toolName + " 运行失败", Color.Red, treeNode);
continue;
}
//if(L_toolList[i].FormTool == null)
//{
// FormLogDisp(L_toolList[i].toolName + " 运行失败", Color.Red, treeNode);
// continue;
//}
for (int j = 0; j < inputItemNum; j++)
{
if (L_toolList[i].toolInput[j].IOName == "inputImage" && L_toolList[i].GetInput(L_toolList[i].toolInput[j].IOName).value == null)
if (L_toolList[i].toolInput[j].IOName == "InputImage" && L_toolList[i].GetInput(L_toolList[i].toolInput[j].IOName).value == null)
{
treeNode.ForeColor = Color.Red;
myFormLog.ShowLog(L_toolList[i].toolName + " 无输入图像");
break;
}
else
{
string sourceFrom = L_toolList[i].GetInput(L_toolList[i].toolInput[j].IOName).value.ToString();
if (L_toolList[i].toolInput[j].IOName == "InputImage")
if(L_toolList[i].GetInput(L_toolList[i].toolInput[j].IOName).value != null)
{
string sourceFrom = L_toolList[i].GetInput(L_toolList[i].toolInput[j].IOName).value.ToString();
string sourceToolName = Regex.Split(sourceFrom, " . ")[0];
sourceToolName = sourceToolName.Substring(3, Regex.Split(sourceFrom, " . ")[0].Length - 3);
string toolItem = Regex.Split(sourceFrom, " . ")[1];
myCaliper.inputImage = GetToolInfoByToolName(GlobalParams.myVisionJob.JobName, sourceToolName).GetOutput(toolItem).value as HObject;
myCaliper.Run();
}
if (myCaliper.ResulttRow != null)
{
myCaliper.DispMainWindow(myFormImageWindow.myHWindow);
FormLogDisp(L_toolList[i].toolName + " 运行成功", Color.Green, treeNode);
}
else
{
FormLogDisp(L_toolList[i].toolName + " 运行失败", Color.Red, treeNode);
if (L_toolList[i].toolInput[j].IOName == "InputImage")
{
myCaliper.inputImage = GetToolInfoByToolName(GlobalParams.myVisionJob.JobName, sourceToolName).GetOutput(toolItem).value as HObject;
}
if(L_toolList[i].toolInput[j].IOName == "inputCenterRow")
{
myCaliper.expectRecStartRow = GetToolInfoByToolName(GlobalParams.myVisionJob.JobName, sourceToolName).GetOutput(toolItem).value as HTuple;
}
if (L_toolList[i].toolInput[j].IOName == "inputCenterCol")
{
myCaliper.expectRecStartColumn = GetToolInfoByToolName(GlobalParams.myVisionJob.JobName, sourceToolName).GetOutput(toolItem).value as HTuple;
}
if (L_toolList[i].toolInput[j].IOName == "inputPhi")
{
myCaliper.expectAngle = GetToolInfoByToolName(GlobalParams.myVisionJob.JobName, sourceToolName).GetOutput(toolItem).value as HTuple;
}
}
}
}
myCaliper.Run(SoftwareRunState.Release);
if (myCaliper.toolRunStatu == ToolRunStatu.Succeed)
{
myCaliper.DispMainWindow(myFormImageWindow.myHWindow);
FormLogDisp(L_toolList[i].toolName + " 运行成功", Color.Green, treeNode);
}
else
{
FormLogDisp(L_toolList[i].toolName + " 运行失败", Color.Red, treeNode);
}
break;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More