private INode Emit(AST a, IGraph to) { String text = a.getText(); int iType = a.Type; String type = parserpackage.GetTypeName(iType); NodeType currentNodeType = GetNodeType(type, to); INode currentNode = to.AddNode(currentNodeType); currentNode.SetAttribute("value", text); if (a.getNumberOfChildren() > 0) { List<AST> l = GetChildren(a); INode previousChild = null; foreach (AST current in l) { INode childNode = Emit(current, to); EdgeType childType = GetEdgeType("child", to); to.AddEdge(childType, currentNode, childNode); if (previousChild != null) { EdgeType nextType = GetEdgeType("next", to); to.AddEdge(nextType, previousChild, childNode); } previousChild = childNode; } } return currentNode; }
private INode Emit(AST a, IGraph to) { String text = a.getText(); int iType = a.Type; String type = parserpackage.GetTypeName(iType); NodeType currentNodeType = GetNodeType(type, to); INode currentNode = to.AddNode(currentNodeType); currentNode.SetAttribute("value", text); if (a.getNumberOfChildren() > 0) { List <AST> l = GetChildren(a); INode previousChild = null; foreach (AST current in l) { INode childNode = Emit(current, to); EdgeType childType = GetEdgeType("child", to); to.AddEdge(childType, currentNode, childNode); if (previousChild != null) { EdgeType nextType = GetEdgeType("next", to); to.AddEdge(nextType, previousChild, childNode); } previousChild = childNode; } } return(currentNode); }
private static void ImportGraph(IGraph graph, XmlDocument doc, XmlElement graphnode) { IGraphModel model = graph.Model; Dictionary <String, INode> nodemap = new Dictionary <string, INode>(); foreach (XmlElement nodeelem in graphnode.GetElementsByTagName("node")) { String nodetype = GetGrGenName(GetTypeName(nodeelem)); NodeType type = model.NodeModel.GetType(nodetype); if (type == null) { throw new Exception("Unknown node type: \"" + nodetype + "\""); } INode node = graph.AddNode(type); ReadAttributes(node, nodeelem); nodemap[nodeelem.GetAttribute("id")] = node; } foreach (XmlElement edgeelem in graphnode.GetElementsByTagName("edge")) { String edgetype = GetGrGenName(GetTypeName(edgeelem)); EdgeType type = model.EdgeModel.GetType(edgetype); if (type == null) { throw new Exception("Unknown edge type: \"" + edgetype + "\""); } INode src = GetNode(edgeelem, "from", nodemap); INode tgt = GetNode(edgeelem, "to", nodemap); IEdge edge = graph.AddEdge(type, src, tgt); ReadAttributes(edge, edgeelem); } }
public static INode AddNode(this IGraph myIGraph, UInt64 myUInt64Id) { if (myIGraph == null) { throw new ArgumentNullException("myIGraph must not be null!"); } return(myIGraph.AddNode(myUInt64Id.ToString())); }
public static INode AddNode(this IGraph myIGraph) { if (myIGraph == null) { throw new ArgumentNullException("myIGraph must not be null!"); } return(myIGraph.AddNode(new Node())); }
/// <summary> /// Executes the algorithm. /// </summary> /// <param name="graph">The graph.</param> /// <exception cref="System.InvalidOperationException">Thrown if graph does not meet special demands required by the graph algorithm.</exception> public void Execute(IGraph <NodeData, EdgeData> graph) { graph.Clear(); this.graph = graph; this.node1 = graph.AddNode(new NodeData(new Point3D(25, 25, 0))); var node2 = graph.AddNode(new NodeData(new Point3D(25, -25, 0))); this.node3 = graph.AddNode(new NodeData(new Point3D(-25, 25, 0))); var node4 = graph.AddNode(new NodeData(new Point3D(-25, -25, 0))); this.graph.AddEdge(this.node1, node4); this.graph.AddEdge(node2, this.node3); this.node1.Move(new Point3D(35, -35, 0), 3000); node4.Move(new Point3D(35, 35, 0), 3000); node2.Move(new Point3D(-35, 35, 0), 3000); this.node3.Move(new Point3D(35, -35, 0), 3000, this.Callback1); }
private void NewAction(object sender, RoutedEventArgs e) { Activity act = new Activity(); act.SetDuration((int)duration.Value); act.SetName(actionName.Text); graph.AddNode(act); actions.Items.Add(LabelFor(act)); Redraw(); }
/// <summary> /// Group of methods and operator overloads that add some (0-...) nodes to the graph, /// AddNode(INode node) only is basic method /// </summary> /// <param name="node"></param> public virtual void AddNode(INode node) { if (node == null) { throw new ArgumentNullException(); } if (_insideGraph == null) { throw new NullReferenceException(); } _insideGraph.AddNode(node.Clone()); }
/// <summary> /// Load nodes from file /// </summary> /// <param name="filePath"></param> public static void LoadNodes(IGraph graph, string filePath) { var reader = new StreamReader(File.OpenRead(filePath)); while (!reader.EndOfStream) { var nodeName = reader.ReadLine(); graph.AddNode(new Node { Name = nodeName }); } }
public static INode AddNode(this IGraph myIGraph, String myId) { if (myIGraph == null) { throw new ArgumentNullException("myIGraph must not be null!"); } if (myId.IsNullOrEmpty()) { throw new ArgumentNullException("myId must not be null or empty!"); } return(myIGraph.AddNode(new Node(myId))); }
public void InsertInGraph(IGraph graph, List <INode> remappedNodes, List <IEdge> remappedEdges) { var nodeGuidMap = new Dictionary <Guid, Guid>(); foreach (var node in GetNodes <INode>()) { var oldGuid = node.guid; var newGuid = node.RewriteGuid(); nodeGuidMap[oldGuid] = newGuid; var drawState = node.drawState; var position = drawState.position; position.x += 30; position.y += 30; drawState.position = position; node.drawState = drawState; remappedNodes.Add(node); graph.AddNode(node); } // only connect edges within pasted elements, discard // external edges. foreach (var edge in edges) { var outputSlot = edge.outputSlot; var inputSlot = edge.inputSlot; Guid remappedOutputNodeGuid; Guid remappedInputNodeGuid; if (nodeGuidMap.TryGetValue(outputSlot.nodeGuid, out remappedOutputNodeGuid) && nodeGuidMap.TryGetValue(inputSlot.nodeGuid, out remappedInputNodeGuid)) { var outputSlotRef = new SlotReference(remappedOutputNodeGuid, outputSlot.slotId); var inputSlotRef = new SlotReference(remappedInputNodeGuid, inputSlot.slotId); remappedEdges.Add(graph.Connect(outputSlotRef, inputSlotRef)); } } m_Nodes.Clear(); m_Edges.Clear(); graph.ValidateGraph(); }
private void ImportGraph(String importFilename) { // First pass: build the nodes and the parent edges given by nesting using (XmlTextReader reader = new XmlTextReader(importFilename)) { while (reader.Read()) // handle root node { if (reader.NodeType != XmlNodeType.Element) { continue; } root = new XMLTree(); if (reader.Name == "xmi:XMI") // if root node is the xmi node we've to read the first level of nodes so we got real graph nodes we can hand down { // relevant for hierarchy but not a real graph node to be created from it root.element = reader.Name; root.elementName = null; root.elementNode = null; root.children = new List <XMLTree>(); while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element) { continue; } // create real graph node from it bool emptyElem = reader.IsEmptyElement; // retard API designer XMLTree rootChild = new XMLTree(); String tagName = reader.Name; rootChild.element = tagName; if (reader.MoveToAttribute("name")) { rootChild.elementName = reader.Value; } INode gnode = graph.AddNode(graph.Model.NodeModel.GetType(GrGenTypeNameFromXmi(tagName))); rootChild.elementNode = gnode; rootChild.children = new List <XMLTree>(); root.children.Add(rootChild); if (reader.MoveToAttribute("xmi:id")) { nodeMap[reader.Value] = gnode; } if (!emptyElem) { ParseNodeFirstPass(reader, rootChild, tagName); // descend and munch subtree } } } else { // create real graph node from it String tagName = reader.Name; root.element = tagName; if (reader.MoveToAttribute("name")) { root.elementName = reader.Value; } INode gnode = graph.AddNode(graph.Model.NodeModel.GetType(GrGenTypeNameFromXmi(tagName))); root.elementNode = gnode; root.children = new List <XMLTree>(); if (reader.MoveToAttribute("xmi:id")) { nodeMap[reader.Value] = gnode; } ParseNodeFirstPass(reader, root, tagName); // descend and munch subtree } } } // Second pass: assign the attributes and edges given by reference attributes using (XmlTextReader reader = new XmlTextReader(importFilename)) { while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element) { continue; } ParseNodeSecondPass(reader, root, reader.Name); } } }
public void AddNode(NetworkNode networkNode) { _networkGraph.AddNode(networkNode.Number); _networkNodes[networkNode.Number] = networkNode; }
private void AddNode() { _graph.AddNode(new Node()); }