Пример #1
0
        /// <summary>
        /// 恢复工具之间的关系和连线
        /// </summary>
        private void ReCoverJob(VisionJob myJob)
        {
            //反序列化各工具
            myJob.D_itemAndSource.Clear();
            for (int i = 0; i < myJob.L_toolList.Count; i++)
            {
                TreeNode node = myJob.GetJobTree().Nodes.Add(myJob.L_toolList[i].toolName);
                for (int j = 0; j < myJob.L_toolList[i].toolInput.Count; j++)
                {
                    TreeNode treeNode;
                    //因为OutputBox只有源,所以此处特殊处理
                    if (myJob.L_toolList[i].toolType != ToolType.Output)
                    {
                        treeNode = node.Nodes.Add("<--" + myJob.L_toolList[i].toolInput[j].IOName + myJob.L_toolList[i].toolInput[j].value);
                    }
                    else
                    {
                        treeNode = node.Nodes.Add("<--" + myJob.L_toolList[i].toolInput[j].IOName);
                    }

                    treeNode.Tag       = myJob.L_toolList[i].toolInput[j].ioType;
                    treeNode.ForeColor = Color.DarkMagenta;

                    //解析需要连线的节点对
                    if (treeNode.ToString().Contains("《-"))
                    {
                        string   toolNodeText   = Regex.Split(myJob.L_toolList[i].toolInput[j].value.ToString(), "->")[0].Substring(3);
                        string   a              = myJob.L_toolList[i].toolInput[j].value.ToString();
                        string   toolIONodeText = "-->" + Regex.Split(myJob.L_toolList[i].toolInput[j].value.ToString(), "->")[1];
                        TreeNode bbb            = myJob.GetToolIONodeByNodeText(toolNodeText, toolIONodeText);
                        myJob.D_itemAndSource.Add(treeNode, myJob.GetToolIONodeByNodeText(toolNodeText, toolIONodeText));
                    }
                    if (myJob.L_toolList[i].toolType == ToolType.Output)
                    {
                        string   toolNodeText   = Regex.Split(treeNode.Text, "->")[0].Substring(3);
                        string   toolIONodeText = Regex.Split(treeNode.Text, "->")[1];
                        TreeNode aaa            = myJob.GetToolIONodeByNodeText(toolNodeText, "-->" + toolIONodeText);
                        myJob.D_itemAndSource.Add(treeNode, myJob.GetToolIONodeByNodeText(toolNodeText, "-->" + toolIONodeText));
                    }
                }
                for (int k = 0; k < myJob.L_toolList[i].toolOutput.Count; k++)
                {
                    TreeNode treeNode = node.Nodes.Add("-->" + myJob.L_toolList[i].toolOutput[k].IOName);

                    treeNode.Tag       = myJob.L_toolList[i].toolOutput[k].ioType;
                    treeNode.ForeColor = Color.Blue;
                }
            }

            // UpdateJobTreeIcon(job.jobName);

            //默认选中第一个节点
            //if (tvw_job.Nodes.Count > 0)
            //    tvw_job.SelectedNode = tvw_job.Nodes[0];
        }
Пример #2
0
        public void InitJob(VisionJob myJob)
        {
            if (myJob.L_toolList.Count > 0)
            {
                ReCoverJob(myJob);
            }
            myJob.GetJobTree().Dock      = DockStyle.Fill;
            myJob.GetJobTree().ImageList = FormToolBox.Instance.imageListTool;
            myJob.GetJobTree().Font      = new Font("微软雅黑", 9, FontStyle.Bold);

            myJob.GetJobTree().Scrollable = true;
            myJob.GetJobTree().ItemHeight = 20;
            myJob.GetJobTree().ShowLines  = false;
            myJob.GetJobTree().AllowDrop  = true;
            //myTreeView.ImageList = Job.imageList;

            // 在窗体UI出现变化时,更新画线
            myJob.GetJobTree().AfterSelect  += myJob.tvw_job_AfterSelect;
            myJob.GetJobTree().ChangeUICues += myJob.MyJobTreeView_ChangeUICues;
            FormJobManage.Instance.SizeChanged += myJob.tbc_jobs_SelectedIndexChanged;
            //节点间拖拽
            myJob.GetJobTree().ItemDrag  += new ItemDragEventHandler(myJob.TvwJob_ItemDrag);
            myJob.GetJobTree().DragEnter += new DragEventHandler(myJob.TvwJob_DragEnter);
            myJob.GetJobTree().DragDrop  += new DragEventHandler(myJob.TvwJob_DragDrop);

            //以下事件为画线事件
            myJob.GetJobTree().MouseMove     += myJob.DrawLineWithoutRefresh;
            myJob.GetJobTree().AfterExpand   += myJob.Draw_Line;
            myJob.GetJobTree().AfterCollapse += myJob.Draw_Line;
            // 在流程节点上操作时
            myJob.GetJobTree().MouseDoubleClick += TreeViewJob_DoubleClick;;
            myJob.GetJobTree().MouseClick       += myJob.tvw_job_MouseClick;
            Application.DoEvents();
            if (myJob.GetJobTree().Nodes.Count > 0)
            {
                //默认选中第一个工具节点
                myJob.GetJobTree().SelectedNode = myJob.GetJobTree().Nodes[0];
            }
            //展开已默认添加的工具的输入输出项
            myJob.GetJobTree().ExpandAll();
        }