コード例 #1
0
ファイル: CGraphManager.cs プロジェクト: John3/T3DConvoEdit
        private void rebuildGraph(GraphControl graph)
        {
            Dictionary <String, CConnectionFields> inputs  = new Dictionary <String, CConnectionFields>();
            Dictionary <String, CConnectionFields> outputs = new Dictionary <String, CConnectionFields>();

            foreach (CNodeFields node in m_graphFields.Nodes)
            {
                m_idNameMap.Add(node.id, node.name);
                Node n = new Node(node.Title);
                n.Location = node.Location;
                foreach (CNodeItemFields item in node.Items)
                {
                    String name = "";
                    if (item.name != null)
                    {
                        name = item.name.Split(':')[1];
                    }
                    if (item.Input != null)
                    {
                        foreach (CConnectionFields conn in item.Input)
                        {
                            if (!inputs.ContainsKey(conn.id))
                            {
                                inputs.Add(conn.id, conn);
                            }
                        }
                    }
                    if (item.Output != null)
                    {
                        foreach (CConnectionFields conn in item.Output)
                        {
                            if (!outputs.ContainsKey(conn.id))
                            {
                                outputs.Add(conn.id, conn);
                            }
                        }
                    }
                    switch (item.ItemType)
                    {
                    case "Graph.Items.NodeCompositeItem":
                    {
                        NodeCompositeItem temp = new NodeCompositeItem(item.IOMode);
                        temp.Name = name;
                        foreach (CItemPartFields part in item.ItemParts)
                        {
                            switch (part.PartType)
                            {
                            case "Graph.Items.ItemTextBoxPart":
                            {
                                ItemTextBoxPart p = new ItemTextBoxPart(part.Text);
                                p.Name = part.name;
                                temp.AddPart(p);
                            }
                            break;

                            default:
                            {
                            }
                            break;
                            }
                        }
                        if (item.Tag != null)
                        {
                            temp.Tag = TagFactory.GetTagObject(item.Tag);
                        }
                        if (temp.Name.Contains("button_"))
                        {
                            temp.Clicked += m_parentForm.GetConvMouseHandler();
                        }
                        m_itemMap.Add(item.id, temp);
                        m_idNameMap.Add(item.id, name);
                        n.AddItem(temp);
                    }
                    break;

                    case "Graph.Items.NodeTextBoxItem":
                    {
                        NodeTextBoxItem temp = new NodeTextBoxItem(item.Text, item.IOMode);
                        temp.Name = name;
                        if (item.Tag != null)
                        {
                            temp.Tag = TagFactory.GetTagObject(item.Tag);
                        }
                        m_itemMap.Add(item.id, temp);
                        m_idNameMap.Add(item.id, name);
                        n.AddItem(temp);
                    }
                    break;

                    case "Graph.Items.NodeLabelItem":
                    {
                        NodeLabelItem temp = new NodeLabelItem(item.Text, item.IOMode);
                        temp.Name = name;
                        if (item.Tag != null)
                        {
                            temp.Tag = TagFactory.GetTagObject(item.Tag);
                        }
                        m_itemMap.Add(item.id, temp);
                        m_idNameMap.Add(item.id, name);
                        if (temp.Name == "EditNodeItem")
                        {
                            temp.Clicked += m_parentForm.GetEditMouseHandler();
                        }
                        n.AddItem(temp);
                    }
                    break;

                    default:
                    {
                        //NodeItem temp = new NodeItem(item.IOMode);
                    }
                    break;
                    }
                }
                graph.AddNode(n);
            }
            rebuildConnections(graph, inputs, outputs);
        }