private void rebuildConnections(GraphControl graph, Dictionary <string, CConnectionFields> inputs, Dictionary <string, CConnectionFields> outputs) { foreach (String key in inputs.Keys) { CConnectionFields inputFields = inputs[key]; NodeConnection conn = new NodeConnection(); conn.Tag = TagFactory.GetTagObject(inputFields.Tag); conn.Name = inputFields.name; String[] fromNameParts = inputFields.From.Split(':'); String fromNodeName = fromNameParts[0]; String fromItemName = fromNameParts[1]; String[] toNameParts = inputFields.To.Split(':'); String toNodeName = toNameParts[0]; String toItemName = toNameParts[1]; Node fromNode = findNode(graph, fromNodeName); NodeItem fromItem = findItem(fromNode, fromItemName); Node toNode = findNode(graph, toNodeName); NodeItem toItem = findItem(toNode, toItemName); graph.Connect(fromItem.Output, toItem.Input); conn.FromItem = fromItemName; conn.ToItem = toItemName; } foreach (String key in outputs.Keys) { CConnectionFields outputFields = outputs[key]; NodeConnection conn = new NodeConnection(); conn.Tag = TagFactory.GetTagObject(outputFields.Tag); conn.Name = outputFields.name; String[] fromNameParts = outputFields.From.Split(':'); String fromNodeName = fromNameParts[0]; String fromItemName = fromNameParts[1]; String[] toNameParts = outputFields.To.Split(':'); String toNodeName = toNameParts[0]; String toItemName = toNameParts[1]; Node fromNode = findNode(graph, fromNodeName); NodeItem fromItem = findItem(fromNode, fromItemName); Node toNode = findNode(graph, toNodeName); NodeItem toItem = findItem(toNode, toItemName); graph.Connect(fromItem.Output, toItem.Input); conn.FromItem = fromItemName; conn.ToItem = toItemName; } graph.Refresh(); }
public CGraphFields(GraphControl control, ObjectIDGenerator idGen) { Dictionary<String, CNodeItemFields> idFieldMap = new Dictionary<String, CNodeItemFields>(); Dictionary<NodeItem, String> idItemMap = new Dictionary<NodeItem, String>(); bool first = false; id = idGen.GetId(control, out first).ToString(); name = control.Name; Nodes = new List<CNodeFields>(); List<Node> nodes = (List<Node>)control.Nodes; foreach (Node node in nodes) { CNodeFields nFields = new CNodeFields(); nFields.Title = node.Title; nFields.name = getNodeName(node); nFields.Location = node.Location; nFields.Items = new List<CNodeItemFields>(); bool nfirst = false; nFields.id = idGen.GetId(nFields, out nfirst).ToString(); foreach(NodeItem item in node.Items) { CNodeItemFields iFields = new CNodeItemFields(); bool ifirst = false; iFields.id = idGen.GetId(iFields, out ifirst).ToString(); String fName = nFields.name + ":" + (item.Name == null ? iFields.id : item.Name); idFieldMap.Add(fName, iFields); idItemMap.Add(item, fName); iFields.Input = new List<CConnectionFields>(); iFields.Output = new List<CConnectionFields>(); iFields.ItemParts = new List<CItemPartFields>(); iFields.name = fName; iFields.ParentNode = nFields.id; if(item.Tag != null) iFields.Tag = item.Tag.GetType().ToString(); iFields.IOMode = getIOMode(item); iFields.ItemType = item.GetType().ToString(); switch(iFields.ItemType) { case "Graph.Items.NodeTextBoxItem": { NodeTextBoxItem temp = item as NodeTextBoxItem; iFields.Text = temp.Text; } break; case "Graph.Items.NodeLabelItem": { NodeLabelItem temp = item as NodeLabelItem; iFields.Text = temp.Text; } break; case "Graph.Items.NodeCompositeItem": { NodeCompositeItem temp = item as NodeCompositeItem; foreach(ItemPart part in temp.Parts) { CItemPartFields pFields = new CItemPartFields(); bool pfirst = false; pFields.id = idGen.GetId(pFields, out pfirst).ToString(); pFields.name = part.Name; pFields.PartType = part.GetType().ToString(); switch(pFields.PartType) { case "Graph.Items.ItemTextBoxPart": { ItemTextBoxPart tempPart = part as ItemTextBoxPart; pFields.Text = tempPart.Text; } break; default: break; } iFields.ItemParts.Add(pFields); } } break; } nFields.Items.Add(iFields); } foreach(NodeItem item in node.Items) { // now get connection info String iid = idItemMap[item]; if (item.Input.Enabled && item.Input.HasConnection) { foreach (NodeConnection conn in item.Input.Connectors) { CConnectionFields cFields = new CConnectionFields(); bool cfirst = false; cFields.id = idGen.GetId(cFields, out cfirst).ToString(); Node nFrom = conn.From.Node; String fromName = ""; foreach(NodeItem nItem in nFrom.Items) { if(nItem.Name == "NodeName") { if(nItem.GetType().ToString() == "Graph.Items.NodeTextBoxItem") { NodeTextBoxItem i = nItem as NodeTextBoxItem; fromName = i.Text; } if (nItem.GetType().ToString() == "Graph.Items.NodeLabelItem") { NodeLabelItem i = nItem as NodeLabelItem; fromName = i.Text; } } } Node nTo = conn.To.Node; String toName = ""; foreach (NodeItem nItem in nTo.Items) { if (nItem.Name == "NodeName") { if (nItem.GetType().ToString() == "Graph.Items.NodeTextBoxItem") { NodeTextBoxItem i = nItem as NodeTextBoxItem; toName = i.Text; } if (nItem.GetType().ToString() == "Graph.Items.NodeLabelItem") { NodeLabelItem i = nItem as NodeLabelItem; toName = i.Text; } } } if (conn.Tag != null) cFields.Tag = conn.Tag.GetType().ToString(); else if (item.Tag != null) cFields.Tag = item.Tag.GetType().ToString(); cFields.name = (conn.Name == null ? cFields.id : conn.Name); cFields.From = fromName + ":" + conn.From.Item.Name; cFields.To = toName + ":" + conn.To.Item.Name; idFieldMap[iid].Input.Add(cFields); } } if (item.Output.Enabled && item.Output.HasConnection) { foreach (NodeConnection conn in item.Output.Connectors) { CConnectionFields cFields = new CConnectionFields(); bool cfirst = false; cFields.id = idGen.GetId(cFields, out cfirst).ToString(); Node nFrom = conn.From.Node; String fromName = ""; foreach (NodeItem nItem in nFrom.Items) { if (nItem.Name == "NodeName") { if (nItem.GetType().ToString() == "Graph.Items.NodeTextBoxItem") { NodeTextBoxItem i = nItem as NodeTextBoxItem; fromName = i.Text; } if (nItem.GetType().ToString() == "Graph.Items.NodeLabelItem") { NodeLabelItem i = nItem as NodeLabelItem; fromName = i.Text; } } } Node nTo = conn.To.Node; String toName = ""; foreach (NodeItem nItem in nTo.Items) { if (nItem.Name == "NodeName") { if (nItem.GetType().ToString() == "Graph.Items.NodeTextBoxItem") { NodeTextBoxItem i = nItem as NodeTextBoxItem; toName = i.Text; } if (nItem.GetType().ToString() == "Graph.Items.NodeLabelItem") { NodeLabelItem i = nItem as NodeLabelItem; toName = i.Text; } } } if (conn.Tag != null) cFields.Tag = conn.Tag.GetType().ToString(); else if (item.Tag != null) cFields.Tag = item.Tag.GetType().ToString(); cFields.name = (conn.Name == null ? cFields.id : conn.Name); cFields.From = fromName + ":" + conn.From.Item.Name; cFields.To = toName + ":" + conn.To.Item.Name; idFieldMap[iid].Input.Add(cFields); } } } Nodes.Add(nFields); } }