Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
            }
        }