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)); } }
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; }); }); }
/// <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); }
/// <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); } }
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; }); }); }