Files
VisionEdit/FindLine/FindLineToolRun.cs

82 lines
3.3 KiB
C#
Raw Normal View History

/*
2021-03-17 16:08:13 +08:00
* ==============================================================================
*
* Filename: FindLineToolRun
* Description:
*
* Version: 1.0
* Created: 2021/2/25 16:23:29
*
* Author: liu.wenjie
*
* ==============================================================================
*/
using CommonMethods;
using CommonMethods.Interface;
using FormLib;
using HalconDotNet;
using Logger;
2021-03-17 16:08:13 +08:00
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using ToolLib.VisionJob;
using static DataStruct.DataStruct;
2021-03-17 16:08:13 +08:00
namespace FindLineTool
{
public class FindLineRun : IToolRun
{
public void ToolRun(string jobName, int toolIndex, int inputItemNum, TreeNode selectNode, List<IToolInfo> L_toolList)
{
FindLine myFindLine = (FindLine)L_toolList[toolIndex].tool;
VisionJob myJob = VisionJobParams.pVisionProject.Project[jobName];
for (int j = 0; j < inputItemNum; j++)
{
if (L_toolList[toolIndex].GetInput(L_toolList[toolIndex].toolInput[j].IOName).value == null)
{
// 仅当无输入图像时,将工具置为错误
if (L_toolList[toolIndex].toolInput[j].IOName == "InputImage")
{
selectNode.ForeColor = Color.Red;
LoggerClass.WriteLog(L_toolList[toolIndex].toolName + " 无输入图像", MsgLevel.Exception);
myFindLine.runMessage = "无输入图像";
}
2021-03-17 16:08:13 +08:00
}
else
{
string sourceFrom = L_toolList[toolIndex].GetInput(L_toolList[toolIndex].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];
switch (L_toolList[toolIndex].toolInput[j].IOName)
2021-03-17 16:08:13 +08:00
{
case "InputImage":
myFindLine.inputImage = myJob.GetToolInfoByToolName(sourceToolName).GetOutput(toolItem).value as HObject;
break;
case "InputPos":
myFindLine.inputPose = myJob.GetToolInfoByToolName(sourceToolName).GetOutput(toolItem).value as PosXYU;
break;
default:
break;
2021-03-17 16:08:13 +08:00
}
}
}
myFindLine.Run(SoftwareRunState.Release);
if (myFindLine.toolRunStatu != ToolRunStatu.Succeed)
2021-03-17 16:08:13 +08:00
{
myJob.FormLogDisp($"{L_toolList[toolIndex].toolName} 运行失败,失败原因:{myFindLine.runMessage}", Color.Red, selectNode, Logger.MsgLevel.Exception);
2021-03-17 16:08:13 +08:00
}
else
{
myJob.FormLogDisp($"{L_toolList[toolIndex].toolName} 运行成功,{myFindLine.runTime}", Color.Green, selectNode);
myFindLine.DispMainWindow(FormImageWindow.Instance.myHWindow.DispHWindow);
2021-03-17 16:08:13 +08:00
}
}
}
}