public List <IAllocatable> GetIAChildrenForIAllocatable(IAllocatable parentIA) { GraphNode parentNode = parentIA as GraphNode; List <IAllocatable> nodeList = new List <IAllocatable>(); if (GraphNodes.Contains(parentNode)) { if (ParentToChildrenMap.ContainsKey(parentNode)) { nodeList = ParentToChildrenMap[parentNode].Cast <IAllocatable>().ToList(); } } else { throw new InvalidOperationException("Graph does not contain node specified!"); } //add AtomicRITE List <IAllocatable> aRiteList = new List <IAllocatable>(); foreach (AtomicRITE aR in parentNode.ResidualAtomicRITEs) { IAllocatable aIA = aR as IAllocatable; aRiteList.Add(aIA); } return(nodeList.Union(aRiteList).ToList()); }
protected void LoadGraphUI() { foreach (Node n in Graph.Nodes) { UINode unode = new UINode(n, this, n.ViewOriginX, n.ViewOriginY, XShift, YShift, Scale); unode.HorizontalAlignment = HorizontalAlignment.Left; unode.VerticalAlignment = VerticalAlignment.Top; ViewPort.Children.Add(unode); GraphNodes.Add(unode); lookup[n.Id] = unode; } Task.Delay(250).ContinueWith((Task t) => { App.Current.Dispatcher.Invoke(() => { //foreach uinode connect up foreach (UINode n in GraphNodes) { n.LoadConnections(lookup); } Graph.ReadOnly = ReadOnly; }); }); }
public void Release() { if (UINodeParameters.Instance != null) { UINodeParameters.Instance.ClearView(); } foreach (UINode n in GraphNodes) { ViewPort.Children.Remove(n); } lookup.Clear(); GraphNodes.Clear(); if (Graph != null) { Graph.OnGraphUpdated -= Graph_OnGraphUpdated; Graph.Dispose(); Graph = null; } if (Original != null) { Original.Dispose(); Original = null; } ViewPort.Children.Clear(); }
/// <summary> /// Helper for Undo Redo system. Does not trigger new undo added to stack /// </summary> /// <param name="id"></param> /// <returns></returns> public Tuple <string, Point, List <Tuple <string, List <NodeOutputConnection> > > > RemoveNode(string id) { var n = GraphNodes.Find(m => m.Id.Equals(id)); Tuple <string, Point, List <Tuple <string, List <NodeOutputConnection> > > > result = null; if (n != null) { result = new Tuple <string, Point, List <Tuple <string, List <NodeOutputConnection> > > >(n.Node.GetJson(), n.Origin, n.Node.GetParentsConnections()); //to remove connections but not to remove from graph n.DisposeNoRemove(); GraphNodes.Remove(n); ViewPort.Children.Remove(n); lookup.Remove(n.Id); //remove from underlying graph Graph.Remove(n.Node); Modified = true; } return(result); }
protected void AddNode(string type, Point p) { Node n = null; UINode unode = null; n = Graph.CreateNode(type); if (n != null) { if (n is GraphInstanceNode) { GraphInstanceNode gn = (GraphInstanceNode)n; gn.Load(type); } Modified = true; n.ViewOriginX = p.X; n.ViewOriginY = p.Y; Graph.Add(n); unode = new UINode(n, this, p.X, p.Y, XShift, YShift, Scale); unode.HorizontalAlignment = HorizontalAlignment.Left; unode.VerticalAlignment = VerticalAlignment.Top; lookup[n.Id] = unode; ViewPort.Children.Add(unode); GraphNodes.Add(unode); UndoRedoManager.AddUndo(new UndoCreateNode(Id, unode.Id, this)); } }
/// <summary> /// Helper for Undeo Redo System. Does not trigger new undo added to stack. /// </summary> /// <param name="json"></param> /// <param name="p"></param> /// <returns></returns> public UINode AddNodeFromJson(string json, Point p) { try { Node.NodeData nd = JsonConvert.DeserializeObject <Node.NodeData>(json); if (nd == null) { return(null); } Node n = null; UINode unode = null; n = Graph.CreateNode(nd.type); if (n != null) { if (n is GraphInstanceNode) { GraphInstanceNode gn = (GraphInstanceNode)n; gn.Load(nd.type); } n.Id = nd.id; n.Width = nd.width; n.Height = nd.height; Graph.Add(n); n.FromJson(Graph.NodeLookup, json); unode = new UINode(n, this, p.X, p.Y, XShift, YShift, Scale); unode.HorizontalAlignment = HorizontalAlignment.Left; unode.VerticalAlignment = VerticalAlignment.Top; lookup[n.Id] = unode; ViewPort.Children.Add(unode); GraphNodes.Add(unode); Modified = true; Task.Delay(250).ContinueWith(t => { unode.LoadConnections(lookup); }); } return(unode); } catch (Exception e) { Console.WriteLine(e.StackTrace); } return(null); }
public void Run() { GraphNodes.ForEach(s => s.Visited = false); foreach (var v in GraphNodes) { if (!v.Visited) { Visit(v); } } }
/// <summary> /// real lookup is required as the nodes added from json /// from a paste command will have new ids /// but will need to lookup the old ids /// to reconnect any that may have been connected when pasted /// </summary> /// <param name="json"></param> /// <param name="realLookup"></param> /// <returns></returns> protected UINode AddNodeFromJson(string json, Dictionary <string, Node> realLookup) { try { Node.NodeData nd = JsonConvert.DeserializeObject <Node.NodeData>(json); if (nd == null) { return(null); } Node n = null; UINode unode = null; n = Graph.CreateNode(nd.type); if (n != null) { if (n is GraphInstanceNode) { GraphInstanceNode gn = (GraphInstanceNode)n; gn.Load(nd.type); } realLookup[nd.id] = n; Graph.Add(n); unode = new UINode(n, this, 0, 0, XShift, YShift, Scale); unode.HorizontalAlignment = HorizontalAlignment.Left; unode.VerticalAlignment = VerticalAlignment.Top; lookup[n.Id] = unode; ViewPort.Children.Add(unode); GraphNodes.Add(unode); UndoRedoManager.AddUndo(new UndoCreateNode(Id, unode.Id, this)); Modified = true; } return(unode); } catch (Exception e) { Console.WriteLine(e.StackTrace); return(null); } }
public void RemoveNode(UINode n) { string json = n.Node.GetJson(); Point p = n.Origin; UndoRedoManager.AddUndo(new UndoDeleteNode(Id, json, p, n.Node.GetParentsConnections(), this)); GraphNodes.Remove(n); ViewPort.Children.Remove(n); lookup.Remove(n.Id); //remove from underlying graph Graph.Remove(n.Node); Modified = true; }
public void ClearView() { //reset viewport etc XShift = 0; YShift = 0; Scale = 1; foreach (UINode n in GraphNodes) { ViewPort.Children.Remove(n); } lookup.Clear(); GraphNodes.Clear(); ViewPort.Children.Clear(); }
//public abstract List<GraphNode> GetChildrenForNode(GraphNode parentNode); public List <GraphNode> GetChildrenForNode(GraphNode parentNode) { if (GraphNodes.Contains(parentNode)) { if (ParentToChildrenMap.ContainsKey(parentNode)) { return(ParentToChildrenMap[parentNode]); } else { return(new List <GraphNode>());//throw new InvalidOperationException("Node does not have any children!"); } } else { throw new InvalidOperationException("Graph does not contain node specified!"); } }
private void CalculatePositions() { if (GraphNodes == null) { return; } var nodes = GraphNodes.ToArray(); try { CalculateNodes(nodes); CalculateEdges(nodes); } catch (Exception ex) { s_Logger.ErrorFormat("Error while calculating graph: {0}", ex); } }
public void Add_A_Node_to_Graph() { //Arrange var graph = new Graph(); //Act GraphNodes result = graph.AddNode("Piper"); //Assert - we needed five asserts to make sure that it absolutely was correct Assert.NotEmpty(graph.Nodes); Assert.Equal(1, graph.Count); Assert.NotNull(result); Assert.Equal("Piper", result.Value); Assert.Contains(result, graph.Nodes); //Assert.Empty(result.Neighbors); //Assert.Empty(graph.GetNeighbors(result)); }
protected void LoadGraphUI() { if (Graph is FunctionGraph) { FunctionGraph fg = (FunctionGraph)Graph; OutputRequirementsLabel.Text = "Required Output Node Type: " + fg.ExpectedOutput.ToString(); } else { OutputRequirementsLabel.Text = ""; } foreach (Node n in Graph.Nodes) { UINode unode = new UINode(n, this, n.ViewOriginX, n.ViewOriginY, XShift, YShift, Scale); unode.HorizontalAlignment = HorizontalAlignment.Left; unode.VerticalAlignment = VerticalAlignment.Top; ViewPort.Children.Add(unode); GraphNodes.Add(unode); lookup[n.Id] = unode; } Task.Delay(250).ContinueWith((Task t) => { App.Current.Dispatcher.Invoke(() => { //foreach uinode connect up foreach (UINode n in GraphNodes) { n.LoadConnections(lookup); } Graph.ReadOnly = ReadOnly; }); }); }
public WPF.Control createGraphNode(string methodSignature) { if (GraphNodes.hasKey(methodSignature)) { return(GraphNodes[methodSignature]); } var graphNode = GraphViewer.newInThread <WPF.Label>(); var iMethod = AstData.iMethod_withSignature(methodSignature); if (iMethod != null) { //this.GraphModeRightPanels[0].clear(); //GraphViewer = this.GraphModeRightPanels[0].add_Graph(); graphNode.set_Content(iMethod.Name); //graphNode.set_Tag(iMethod); WPF_Controls_ExtensionMethods_Control.color(graphNode, "Black"); // direct call throws compile error -> graphNode.color("Black"); } else { WPF_Controls_ExtensionMethods_Control.color(graphNode, "Red"); graphNode.set_Content(methodSignature); } if (UseStarAsNodeText) { graphNode.set_Content("*"); } graphNode.set_Tag(methodSignature); graphNode.onMouseDoubleClick <string, WPF.Label>( (signature) => { addCallerAndCalleesToGraphNode(graphNode, signature); }); GraphNodes.add(methodSignature, graphNode); return(graphNode); }
public void Run() { _queue = new Queue <GraphNode>(); var first = GraphNodes.FirstOrDefault(); first.Visited = true; _queue.Enqueue(first); while (_queue.Count != 0) { var item = _queue.Dequeue(); Results.Add(item.Data); foreach (var vertex in item.Edges) { if (!vertex.Visited) { vertex.Visited = true; _queue.Enqueue(vertex); } } } }
public void Reset() { GraphNodes.Clear(); GraphLinks.Clear(); }