示例#1
0
        public void LoadConnections(Dictionary <string, UINode> lookup)
        {
            var connections = Node.GetConnections();

            foreach (var con in connections)
            {
                string nid = con.node;
                int    idx = con.index;
                int    odx = con.outIndex;

                UINode on = null;

                if (lookup.TryGetValue(nid, out on))
                {
                    if (idx >= 0 && idx < on.InputNodes.Count)
                    {
                        UINodePoint p = on.InputNodes[idx];
                        //connect

                        if (odx >= 0 && odx < OutputNodes.Count)
                        {
                            OutputNodes[odx].ConnectToNode(p);
                        }
                    }
                    else
                    {
                        //log error
                    }
                }
                else
                {
                    //log error
                }
            }
        }
示例#2
0
        public void ConnectToNode(UINodePoint p, bool loading = false)
        {
            if (p.ParentNode == this)
            {
                return;
            }

            if (p.ParentNode != null)
            {
                p.ParentNode.RemoveNode(p);
            }

            if (!loading)
            {
                if (!CanConnect(p))
                {
                    return;
                }

                if (IsCircular(p))
                {
                    return;
                }

                Output.Add(p.Input);
            }

            NodePath path = new NodePath(graph.ViewPort, this, p, output != null && output.Type == NodeType.Execute);

            paths[p] = path;
            to.Add(p);
            p.ParentNode = this;
        }
示例#3
0
        public void ConnectToNode(UINodePoint p)
        {
            if (!CanConnect(p))
            {
                return;
            }

            if (IsCircular(p))
            {
                return;
            }

            if (p.ParentNode != null)
            {
                p.ParentNode.RemoveNode(p);
            }

            Output.Add(p.Input);

            Path path = new Path();

            path.Stroke          = new SolidColorBrush(Colors.Gray);
            path.StrokeThickness = 2;
            paths[p]             = path;
            to.Add(p);
            p.ParentNode = this;
            UpdatePaths();
            graph.ViewPort.Children.Add(path);
        }
示例#4
0
        public void RemoveNode(UINodePoint p)
        {
            Path path = null;

            if (paths.TryGetValue(p, out path))
            {
                graph.ViewPort.Children.Remove(path);
            }
            TextBlock num = null;

            if (numbers.TryGetValue(p, out num))
            {
                graph.ViewPort.Children.Remove(num);
            }

            paths.Remove(p);

            numbers.Remove(p);

            to.Remove(p);

            if (p.ParentNode == this)
            {
                if (p.Input != null && p.Input.Input != null)
                {
                    p.Input.Input.Remove(p.Input);
                }

                p.ParentNode = null;
            }

            UpdatePaths();
        }
示例#5
0
        public UINode(Node n, UIGraph graph, double ox, double oy, double xs, double xy, double sc = 1)
        {
            InitializeComponent();

            Width  = defaultSize;
            Height = defaultSize;

            Focusable = true;

            InputNodes  = new List <UINodePoint>();
            OutputNodes = new List <UINodePoint>();

            Graph = graph;

            xShift = xs;
            yShift = xy;

            scale = sc;

            Node = n;

            Id = n.Id;

            originX = ox;
            originY = oy;

            Margin = new Thickness(0, 0, 0, 0);

            NodeName.Text = n.Name;

            foreach (NodeOutput op in n.Outputs)
            {
                UINodePoint outpoint = new UINodePoint(this, graph);
                outpoint.Output            = op;
                outpoint.VerticalAlignment = VerticalAlignment.Center;
                OutputNodes.Add(outpoint);
                OutputStack.Children.Add(outpoint);
                outpoint.UpdateColor();
            }

            foreach (NodeInput i in n.Inputs)
            {
                UINodePoint inputpoint = new UINodePoint(this, graph);
                inputpoint.Input             = i;
                inputpoint.VerticalAlignment = VerticalAlignment.Center;
                InputStack.Children.Add(inputpoint);
                InputNodes.Add(inputpoint);
                inputpoint.UpdateColor();
            }

            n.OnUpdate                += N_OnUpdate;
            n.OnNameUpdate            += N_OnNameUpdate;
            n.OnInputAddedToNode      += N_OnInputAddedToNode;
            n.OnInputRemovedFromNode  += N_OnInputRemovedFromNode;
            n.OnOutputAddedToNode     += N_OnOutputAddedToNode;
            n.OnOutputRemovedFromNode += N_OnOutputRemovedFromNode;
            N_OnUpdate(n);
        }
示例#6
0
        private void N_OnInputAddedToNode(Node n, NodeInput inp)
        {
            UINodePoint inputpoint = new UINodePoint(this, Graph);

            inputpoint.Input             = inp;
            inputpoint.VerticalAlignment = VerticalAlignment.Center;
            InputStack.Children.Add(inputpoint);
            InputNodes.Add(inputpoint);
            inputpoint.UpdateColor();

            ResizeHeight();
        }
示例#7
0
 public bool CanConnect(UINodePoint p)
 {
     if (Output == null)
     {
         return(false);
     }
     if (p.Input == null)
     {
         return(false);
     }
     return((Output.Type & p.Input.Type) != 0);
 }
示例#8
0
        public bool IsCircular(UINodePoint p)
        {
            if (p.Node == Node)
            {
                return(true);
            }

            Stack <UINodePoint> stack = new Stack <UINodePoint>();

            stack.Push(p);

            bool circ = false;

            while (stack.Count > 0)
            {
                UINodePoint pt = stack.Pop();

                bool   shouldBreak = false;
                UINode node        = pt.Node;

                foreach (UINodePoint output in node.OutputNodes)
                {
                    if (output != null && output.to != null)
                    {
                        foreach (UINodePoint n in output.to)
                        {
                            if (n.Node == Node)
                            {
                                shouldBreak = true;
                                circ        = true;
                                break;
                            }
                            else
                            {
                                stack.Push(n);
                            }
                        }
                    }

                    if (shouldBreak)
                    {
                        break;
                    }
                }

                if (shouldBreak)
                {
                    break;
                }
            }

            return(circ);
        }
示例#9
0
        private void N_OnOutputAddedToNode(Node n, NodeOutput inp, NodeOutput previous = null)
        {
            UINodePoint outpoint = new UINodePoint(this, Graph);

            outpoint.Output            = inp;
            outpoint.VerticalAlignment = VerticalAlignment.Center;
            OutputNodes.Add(outpoint);
            OutputStack.Children.Add(outpoint);
            outpoint.UpdateColor();

            ResizeHeight();
        }
示例#10
0
        private void N_OnOutputAddedToNode(Node n, NodeOutput inp, NodeOutput previous = null)
        {
            UINodePoint outpoint = new UINodePoint(this, Graph);

            outpoint.Output            = inp;
            outpoint.VerticalAlignment = VerticalAlignment.Center;
            OutputNodes.Add(outpoint);
            OutputStack.Children.Add(outpoint);
            outpoint.UpdateColor();

            if (previous != null)
            {
                foreach (var cinp in inp.To)
                {
                    LoadConnection(cinp.Node.Id);
                }
            }
        }
示例#11
0
        public void ConnectToNode(UINodePoint p, bool loading = false)
        {
            if (!CanConnect(p))
            {
                return;
            }

            if (IsCircular(p))
            {
                return;
            }

            if (p.ParentNode != null)
            {
                p.ParentNode.RemoveNode(p);
            }

            if (!loading)
            {
                Output.Add(p.Input);
            }

            Path path = new Path();


            if (output != null && output.Type == NodeType.Execute)
            {
                TextBlock number = new TextBlock();
                number.HorizontalAlignment = HorizontalAlignment.Left;
                number.VerticalAlignment   = VerticalAlignment.Top;
                number.Foreground          = new SolidColorBrush(Colors.LightGray);
                number.FontSize            = 12;
                numbers[p] = number;
                graph.ViewPort.Children.Add(number);
            }

            path.Stroke          = new SolidColorBrush(Colors.Gray);
            path.StrokeThickness = 2;
            paths[p]             = path;
            to.Add(p);
            p.ParentNode = this;
            UpdatePaths();
            graph.ViewPort.Children.Add(path);
        }
示例#12
0
        public void LoadConnection(string id)
        {
            var connections = Node.GetConnections();

            foreach (var con in connections)
            {
                if (con.node.Equals(id))
                {
                    string nid = con.node;
                    int    idx = con.index;
                    int    odx = con.outIndex;

                    IUIGraphNode on = Graph.GetNode(nid);

                    if (on != null)
                    {
                        if (idx >= 0 && idx < on.InputNodes.Count)
                        {
                            UINodePoint p = on.InputNodes[idx];
                            //connect

                            if (odx >= 0 && odx < OutputNodes.Count)
                            {
                                OutputNodes[odx].ConnectToNode(p, true);
                            }
                        }
                        else
                        {
                            //log error
                            Log.Warn("Failed to connect a node's output to input");
                        }
                    }
                    else
                    {
                        //log error
                        Log.Warn("Node does not exist for connection");
                    }

                    break;
                }
            }
        }
示例#13
0
        public void RemoveNode(UINodePoint p, bool removeFromGraph = true)
        {
            NodePath path = null;

            if (paths.TryGetValue(p, out path))
            {
                path.Dispose();
            }

            paths.Remove(p);
            to.Remove(p);

            if (p.ParentNode == this)
            {
                if (p.Input != null && p.Input.Reference != null && removeFromGraph)
                {
                    p.Input.Reference.Remove(p.Input);
                }

                p.ParentNode = null;
            }
        }
示例#14
0
        public void LoadConnection(string id)
        {
            var connections = Node.GetConnections();

            foreach (var con in connections)
            {
                if (con.node.Equals(id))
                {
                    string nid = con.node;
                    int    idx = con.index;
                    int    odx = con.outIndex;

                    UINode on = Graph.GetNode(nid);

                    if (on != null)
                    {
                        if (idx >= 0 && idx < on.InputNodes.Count)
                        {
                            UINodePoint p = on.InputNodes[idx];
                            //connect

                            if (odx >= 0 && odx < OutputNodes.Count)
                            {
                                OutputNodes[odx].ConnectToNode(p);
                            }
                        }
                        else
                        {
                            //log error
                        }
                    }
                    else
                    {
                        //log error
                    }
                }
            }
        }
示例#15
0
        private void N_OnInputAddedToNode(Node n, NodeInput inp, NodeInput previous = null)
        {
            //need to take into account previous
            //aka we are just replacing the previous one
            UINodePoint previousNodePoint       = null;
            UINodePoint previousNodePointParent = null;

            if (previous != null)
            {
                previousNodePoint = InputNodes.Find(m => m.Input == previous);
            }

            if (previousNodePoint != null)
            {
                previousNodePointParent = previousNodePoint.ParentNode;
            }

            UINodePoint inputpoint = new UINodePoint(this, Graph);

            inputpoint.Input             = inp;
            inputpoint.VerticalAlignment = VerticalAlignment.Center;
            InputStack.Children.Add(inputpoint);
            InputNodes.Add(inputpoint);
            inputpoint.UpdateColor();

            //try and reconnect previous parent node to it graphically
            if (previousNodePointParent != null)
            {
                previousNodePointParent.ConnectToNode(inputpoint, true);
            }

            if (previous != null)
            {
                N_OnInputRemovedFromNode(n, previous);
            }

            ResizeHeight();
        }
示例#16
0
        public void RemoveNode(UINodePoint p)
        {
            Path path = null;

            if (paths.TryGetValue(p, out path))
            {
                graph.ViewPort.Children.Remove(path);
            }

            paths.Remove(p);

            to.Remove(p);

            if (p.ParentNode == this)
            {
                if (p.Input != null && p.Input.Input != null)
                {
                    p.Input.Input.Remove(p.Input);
                }

                p.ParentNode = null;
            }
        }
示例#17
0
        public void LoadConnections(Dictionary <string, IUIGraphNode> lookup)
        {
            var connections = Node.GetConnections();

            foreach (var con in connections)
            {
                string nid = con.node;
                int    idx = con.index;
                int    odx = con.outIndex;

                IUIGraphNode on = null;

                if (lookup.TryGetValue(nid, out on))
                {
                    if (idx >= 0 && idx < on.InputNodes.Count)
                    {
                        UINodePoint p = on.InputNodes[idx];
                        //connect

                        if (odx >= 0 && odx < OutputNodes.Count)
                        {
                            OutputNodes[odx].ConnectToNode(p, true);
                        }
                    }
                    else
                    {
                        //log error
                        Log.Warn("Failed to connect a node's output to input");
                    }
                }
                else
                {
                    //log error
                    Log.Warn("Node does not exist for connection");
                }
            }
        }
示例#18
0
        private void UpdateConnectionPreview()
        {
            if (UINodePoint.SelectOrigin != null)
            {
                //catch for when the node is removed and layout update is still triggered
                try
                {
                    UINodePoint origin = UINodePoint.SelectOrigin;
                    UINodePoint dest   = UINodePoint.SelectOver;

                    Point r1 = new Point();

                    if (origin.Output != null)
                    {
                        r1 = origin.TransformToAncestor(ViewPort).Transform(new Point(origin.ActualWidth, 8f));
                    }
                    else if (origin.Input != null)
                    {
                        r1 = origin.TransformToAncestor(ViewPort).Transform(new Point(0f, 8f));
                    }

                    Point r2 = Mouse.GetPosition(ViewPort);

                    if (dest != null)
                    {
                        if (origin.Output != null)
                        {
                            r2 = dest.TransformToAncestor(ViewPort).Transform(new Point(dest.ActualWidth, 8f));
                        }
                        else if (origin.Input != null)
                        {
                            r2 = dest.TransformToAncestor(ViewPort).Transform(new Point(0f, 8f));
                        }
                    }

                    Path path = ConnectionPathPreview;

                    double dy = r2.Y - r1.Y;

                    Point mid = new Point((r2.X + r1.X) * 0.5f, (r2.Y + r1.Y) * 0.5f + dy * 0.5f);

                    if (path != null)
                    {
                        if (path.Data == null)
                        {
                            path.VerticalAlignment   = VerticalAlignment.Top;
                            path.HorizontalAlignment = HorizontalAlignment.Left;
                            PathGeometry p  = new PathGeometry();
                            PathFigure   pf = new PathFigure();
                            pf.IsClosed   = false;
                            pf.StartPoint = r1;

                            BezierSegment seg = new BezierSegment(r1, mid, r2, true);
                            pf.Segments.Add(seg);
                            p.Figures.Add(pf);
                            path.Data = p;
                        }
                        else
                        {
                            PathGeometry p  = (PathGeometry)path.Data;
                            PathFigure   pf = p.Figures[0];
                            pf.StartPoint = r1;
                            BezierSegment seg = (BezierSegment)pf.Segments[0];
                            seg.Point1 = r1;
                            seg.Point2 = mid;
                            seg.Point3 = r2;
                        }
                    }

                    ConnectionPathPreview = path;

                    if (dest != null)
                    {
                        r2 = dest.TransformToAncestor(ViewPort).Transform(new Point());
                    }
                    else
                    {
                        r2.X -= 8;
                        r2.Y -= 8;
                    }

                    Canvas.SetLeft(ConnectionPointPreview, r2.X);
                    Canvas.SetTop(ConnectionPointPreview, r2.Y);
                }
                catch { }
            }
        }
示例#19
0
 public bool IsCircular(UINodePoint p)
 {
     return(p.Node == Node);
 }
示例#20
0
 public int GetOutIndex(UINodePoint p)
 {
     return(to.IndexOf(p));
 }
示例#21
0
        public UINode(Node n, UIGraph graph, double ox, double oy, double xs, double xy, double sc = 1)
        {
            InitializeComponent();

            Focusable = true;

            InputNodes  = new List <UINodePoint>();
            OutputNodes = new List <UINodePoint>();

            Graph = graph;

            xShift = xs;
            yShift = xy;

            scale = sc;

            Node = n;

            Id = n.Id;

            originX = ox;
            originY = oy;

            NodeName.Text = n.Name;

            for (int i = 0; i < n.Outputs.Count; i++)
            {
                NodeOutput  op       = n.Outputs[i];
                UINodePoint outpoint = new UINodePoint(this, graph);
                outpoint.Output            = op;
                outpoint.VerticalAlignment = VerticalAlignment.Center;
                OutputNodes.Add(outpoint);
                OutputStack.Children.Add(outpoint);
            }

            for (int i = 0; i < n.Inputs.Count; i++)
            {
                NodeInput   inp        = n.Inputs[i];
                UINodePoint inputpoint = new UINodePoint(this, graph);
                inputpoint.Input             = inp;
                inputpoint.VerticalAlignment = VerticalAlignment.Center;
                InputStack.Children.Add(inputpoint);
                InputNodes.Add(inputpoint);
            }

            n.OnNameUpdate            += N_OnNameUpdate;
            n.OnInputAddedToNode      += N_OnInputAddedToNode;
            n.OnInputRemovedFromNode  += N_OnInputRemovedFromNode;
            n.OnOutputAddedToNode     += N_OnOutputAddedToNode;
            n.OnOutputRemovedFromNode += N_OnOutputRemovedFromNode;
            n.OnDescriptionChanged    += N_OnDescriptionChanged;

            if (n is MathNode)
            {
                DescPreview.Visibility = Visibility.Visible;
                Desc.Text = n.GetDescription();
                LoadIcon();
            }

            if (graph.Graph is FunctionGraph)
            {
                FunctionGraph f = graph.Graph as FunctionGraph;
                f.OnOutputSet += F_OnOutputSet;

                if (n == f.OutputNode)
                {
                    OutputIcon.Visibility  = Visibility.Visible;
                    DescPreview.Background = HighlightBrush;
                }
                else
                {
                    DescPreview.Background = DefaultBrush;
                    OutputIcon.Visibility  = Visibility.Collapsed;
                }

                if (n == f.Execute)
                {
                    InputIcon.Visibility = Visibility.Visible;
                }
                else
                {
                    InputIcon.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                if (n is OutputNode)
                {
                    OutputIcon.Visibility = Visibility.Visible;
                }
                else
                {
                    OutputIcon.Visibility = Visibility.Collapsed;
                }

                if (n is InputNode)
                {
                    InputIcon.Visibility = Visibility.Visible;
                }
                else
                {
                    InputIcon.Visibility = Visibility.Collapsed;
                }
            }
        }