FindLineToolRun.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * ==============================================================================
  3. *
  4. * Filename: FindLineToolRun
  5. * Description:
  6. *
  7. * Version: 1.0
  8. * Created: 2021/2/25 16:23:29
  9. *
  10. * Author: liu.wenjie
  11. *
  12. * ==============================================================================
  13. */
  14. using CommonMethods;
  15. using CommonMethods.Interface;
  16. using FormLib;
  17. using HalconDotNet;
  18. using Logger;
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Drawing;
  22. using System.Linq;
  23. using System.Text;
  24. using System.Text.RegularExpressions;
  25. using System.Threading.Tasks;
  26. using System.Windows.Forms;
  27. using ToolLib.VisionJob;
  28. using static DataStruct.DataStructClass;
  29. namespace FindLineTool
  30. {
  31. public class FindLineRun : IToolRun
  32. {
  33. public void ToolRun(string jobName, int toolIndex, int inputItemNum, TreeNode selectNode, List<IToolInfo> L_toolList, IVisionJob runJob, Form myHalconWindowForm)
  34. {
  35. FindLine myFindLine = (FindLine)L_toolList[toolIndex].tool;
  36. VisionJob myJob = (VisionJob)runJob;
  37. for (int j = 0; j < inputItemNum; j++)
  38. {
  39. if (L_toolList[toolIndex].GetInput(L_toolList[toolIndex].toolInput[j].IOName).value == null)
  40. {
  41. // 仅当无输入图像时,将工具置为错误
  42. if (L_toolList[toolIndex].toolInput[j].IOName == "InputImage")
  43. {
  44. selectNode.ForeColor = Color.Red;
  45. LoggerClass.WriteLog(L_toolList[toolIndex].toolName + " 无输入图像", MsgLevel.Exception);
  46. myFindLine.runMessage = "无输入图像";
  47. }
  48. }
  49. else
  50. {
  51. string sourceFrom = L_toolList[toolIndex].GetInput(L_toolList[toolIndex].toolInput[j].IOName).value.ToString();
  52. string sourceToolName = Regex.Split(sourceFrom, "->")[0];
  53. sourceToolName = sourceToolName.Substring(3, Regex.Split(sourceFrom, "->")[0].Length - 3);
  54. string toolItem = Regex.Split(sourceFrom, "->")[1];
  55. switch (L_toolList[toolIndex].toolInput[j].IOName)
  56. {
  57. case "InputImage":
  58. myFindLine.inputImage = myJob.GetToolInfoByToolName(sourceToolName).GetOutput(toolItem).value as HObject;
  59. break;
  60. case "InputPos":
  61. myFindLine.inputPoseHomMat2D = myJob.GetToolInfoByToolName(sourceToolName).GetOutput(toolItem).value as HTuple;
  62. break;
  63. default:
  64. break;
  65. }
  66. }
  67. }
  68. myFindLine.Run(SoftwareRunState.Release);
  69. if (myFindLine.toolRunStatu != ToolRunStatu.Succeed)
  70. {
  71. myJob.FormLogDisp($"{L_toolList[toolIndex].toolName} 运行失败,失败原因:{myFindLine.runMessage}", Color.Red, selectNode, Logger.MsgLevel.Exception);
  72. }
  73. else
  74. {
  75. myJob.FormLogDisp($"{L_toolList[toolIndex].toolName} 运行成功,{myFindLine.runTime}", Color.Green, selectNode);
  76. myFindLine.DispMainWindow(((FormImageWindow)myHalconWindowForm).myHWindow);
  77. }
  78. L_toolList[toolIndex].toolRunStatu = myFindLine.toolRunStatu;
  79. }
  80. }
  81. }