zoukankan      html  css  js  c++  java
  • C# 获取VisionPro的CogToolGroup下的所有层次的ICogTool生成工具树

    1、加载模板

    1 tplpath = Application.StartupPath + "\xxx.vpp";
    2             public Cognex.VisionPro.ToolGroup.CogToolGroup toolGroup= (Cognex.VisionPro.ToolGroup.CogToolGroup)Cognex.VisionPro.CogSerializer.LoadObjectFromFile(tplpath);
    View Code

    2、创建根目录

     1 /// <summary>
     2 /// 加载相机模板
     3 /// </summary>
     4  private void LoadCogToolGroup(CogToolGroup tg)
     5  {
     6    toolGroup = tg;
     7    if (toolGroup.Tools.Count > 0)
     8     {
     9         TreeNode node=new TreeNode("相机模板");
    10         trvTpl.Nodes.Add(node);
    11         trvTpl.ExpandAll();
    12 
    13         foreach (ICogTool icCogTool in toolGroup.Tools)
    14         {
    15             GetToolBlockTools(icCogTool, node);
    16         }
    17      }
    18  }
    View Code

    3、递归查找

     1  private void GetToolBlockTools(ICogTool icCogTool,TreeNode tnode)
     2         {
     3             if (icCogTool.GetType().Name == "CogToolBlock")
     4             {
     5                 CogToolBlock c = (CogToolBlock)icCogTool;
     6                 if (icCogTool.Name==tnode.Text)
     7                 {
     8                     TreeNode[] tds = trvTpl.Nodes.Find(icCogTool.Name, true);
     9                     if(tds.Length>0)
    10                         GetToolBlockTools(icCogTool, tds[0]);
    11                 }
    12                 else
    13                 {
    14                     TreeNode node = new TreeNode(icCogTool.Name);
    15                     node.Tag = icCogTool;
    16                     tnode.Nodes.Add(node);
    17                     foreach (ICogTool ict in c.Tools)
    18                     {
    19                         GetToolBlockTools(ict, node);
    20                     }
    21                 }
    22             }
    23             else
    24             {
    25                 TreeNode node = new TreeNode(icCogTool.Name);
    26                 node.Tag = icCogTool;
    27                 tnode.Nodes.Add(node);
    28             }
    29         }
    View Code
  • 相关阅读:
    【Jmeter】分布式并发测试
    【博客迁移】
    设置超出范围有滚动条
    table中td,th不能设置margin
    文字和input对不齐怎么办
    改变radio单选按钮的样式
    transition的用法以及animation的用法
    选择后代元素或点击元素的方法
    如何简单实用hammer
    添加aimate动画
  • 原文地址:https://www.cnblogs.com/BennyHua/p/11170005.html
Copyright © 2011-2022 走看看