Esempio n. 1
0
        private void NodesControl_MouseUp(object sender, MouseEventArgs e)
        {
            if (selectionStart != PointF.Empty)
            {
                var rect = MakeRect(selectionStart, selectionEnd);
                graph.Nodes.ForEach(
                    x => x.IsSelected = rect.Contains(new RectangleF(new PointF(x.X, x.Y), x.GetNodeBounds())));
                selectionStart        = PointF.Empty;
            }

            if (dragSocket != null)
            {
                var nodeWhole =
                    graph.Nodes.OrderBy(x => x.Order).FirstOrDefault(
                        x => new RectangleF(new PointF(x.X, x.Y), x.GetNodeBounds()).Contains(e.Location));
                if (nodeWhole != null)
                {
                    var socket = nodeWhole.GetSockets().FirstOrDefault(x => x.GetBounds().Contains(e.Location));
                    if (socket != null)
                    {
                        if (IsConnectable(dragSocket, socket) && dragSocket.Input != socket.Input)
                        {
                            var nc = new NodeConnection();
                            if (!dragSocket.Input)
                            {
                                nc.OutputNode       = dragSocketNode;
                                nc.OutputSocketName = dragSocket.Name;
                                nc.InputNode        = nodeWhole;
                                nc.InputSocketName  = socket.Name;
                            }
                            else
                            {
                                nc.InputNode        = dragSocketNode;
                                nc.InputSocketName  = dragSocket.Name;
                                nc.OutputNode       = nodeWhole;
                                nc.OutputSocketName = socket.Name;
                            }

                            graph.Connections.RemoveAll(
                                x => x.InputNode == nc.InputNode && x.InputSocketName == nc.InputSocketName);

                            graph.Connections.Add(nc);
                            rebuildConnectionDictionary = true;
                        }
                    }
                }
            }

            dragSocket  = null;
            mdown       = false;
            needRepaint = true;
        }
Esempio n. 2
0
        private bool IsConnectable(SocketVisual a, SocketVisual b)
        {
            var input  = a.Input ? a : b;
            var output = a.Input ? b : a;
            var otype  = Type.GetType(output.Type.FullName.Replace("&", ""), AssemblyResolver, TypeResolver);
            var itype  = Type.GetType(input.Type.FullName.Replace("&", ""), AssemblyResolver, TypeResolver);

            if (otype == null || itype == null)
            {
                return(false);
            }
            var allow = otype == itype || otype.IsSubclassOf(itype);

            return(allow);
        }
Esempio n. 3
0
        internal SocketVisual[] GetSockets()
        {
            if (socketCache != null)
            {
                return(socketCache);
            }

            var   socketList = new List <SocketVisual>();
            float curInputH  = HeaderHeight + ComponentPadding;
            float curOutputH = HeaderHeight + ComponentPadding;

            var NodeWidth = GetNodeBounds().Width;

            foreach (var input in GetInputs())
            {
                var socket = new SocketVisual();
                socket.Type   = null;
                socket.Height = SocketVisual.SocketHeight;
                socket.Name   = input.Name;
                socket.Width  = SocketVisual.SocketHeight;
                socket.X      = X;
                socket.Y      = Y + curInputH;
                socket.Input  = true;

                socketList.Add(socket);

                curInputH += SocketVisual.SocketHeight + ComponentPadding;
            }
            //var ctx = GetNodeContext() as DynamicNodeContext;
            foreach (var output in GetOutputs())
            {
                var socket = new SocketVisual();
                socket.Type   = null;
                socket.Height = SocketVisual.SocketHeight;
                socket.Width  = SocketVisual.SocketHeight;
                socket.X      = X + NodeWidth - SocketVisual.SocketHeight;
                socket.Y      = Y + curOutputH;
                //socket.Value = ctx[socket.Name];
                socketList.Add(socket);

                curOutputH += SocketVisual.SocketHeight + ComponentPadding;
            }

            socketCache = socketList.ToArray();
            return(socketCache);
        }
Esempio n. 4
0
        private void NodesControl_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                selectionStart = PointF.Empty;

                Focus();

                if ((ModifierKeys & Keys.Shift) != Keys.Shift)
                {
                    graph.Nodes.ForEach(x => x.IsSelected = false);
                }

                var node =
                    graph.Nodes.OrderBy(x => x.Order).FirstOrDefault(
                        x => new RectangleF(new PointF(x.X, x.Y), x.GetHeaderSize()).Contains(e.Location));

                if (node != null && !mdown)
                {
                    node.IsSelected = true;

                    node.Order = graph.Nodes.Min(x => x.Order) - 1;
                    if (node.CustomEditor != null)
                    {
                        node.CustomEditor.BringToFront();
                    }
                    mdown    = true;
                    lastmpos = PointToScreen(e.Location);

                    Refresh();
                }
                if (node == null && !mdown)
                {
                    var nodeWhole =
                        graph.Nodes.OrderBy(x => x.Order).FirstOrDefault(
                            x => new RectangleF(new PointF(x.X, x.Y), x.GetNodeBounds()).Contains(e.Location));
                    if (nodeWhole != null)
                    {
                        node = nodeWhole;
                        var socket = nodeWhole.GetSockets().FirstOrDefault(x => x.GetBounds().Contains(e.Location));
                        if (socket != null)
                        {
                            if ((ModifierKeys & Keys.Control) == Keys.Control)
                            {
                                var connection =
                                    graph.Connections.FirstOrDefault(
                                        x => x.InputNode == nodeWhole && x.InputSocketName == socket.Name);

                                if (connection != null)
                                {
                                    dragSocket =
                                        connection.OutputNode.GetSockets()
                                        .FirstOrDefault(x => x.Name == connection.OutputSocketName);
                                    dragSocketNode = connection.OutputNode;
                                }
                                else
                                {
                                    connection =
                                        graph.Connections.FirstOrDefault(
                                            x => x.OutputNode == nodeWhole && x.OutputSocketName == socket.Name);

                                    if (connection != null)
                                    {
                                        dragSocket =
                                            connection.InputNode.GetSockets()
                                            .FirstOrDefault(x => x.Name == connection.InputSocketName);
                                        dragSocketNode = connection.InputNode;
                                    }
                                }

                                graph.Connections.Remove(connection);
                                rebuildConnectionDictionary = true;
                            }
                            else
                            {
                                dragSocket     = socket;
                                dragSocketNode = nodeWhole;
                            }
                            dragConnectionBegin = e.Location;
                            dragConnectionEnd   = e.Location;
                            mdown    = true;
                            lastmpos = PointToScreen(e.Location);
                        }
                    }
                    else
                    {
                        selectionStart = selectionEnd = e.Location;
                    }
                }
                if (node != null)
                {
                    OnNodeContextSelected(node.GetNodeContext());
                }
            }

            needRepaint = true;
        }
        internal SocketVisual[] GetSockets()
        {
            if (socketCache != null)
            {
                return(socketCache);
            }

            var   socketList = new List <SocketVisual>();
            float curInputH  = HeaderHeight + ComponentPadding;
            float curOutputH = HeaderHeight + ComponentPadding;

            var NodeWidth = GetNodeBounds().Width;

            if (Callable)
            {
                if (!ExecInit)
                {
                    socketList.Add(new SocketVisual()
                    {
                        Height          = SocketVisual.SocketHeight,
                        Name            = "Enter",
                        Type            = typeof(ExecutionPath),
                        IsMainExecution = true,
                        Width           = SocketVisual.SocketHeight,
                        X     = X,
                        Y     = Y + curInputH,
                        Input = true
                    });
                }
                socketList.Add(new SocketVisual()
                {
                    Height          = SocketVisual.SocketHeight,
                    Name            = "Exit",
                    IsMainExecution = true,
                    Type            = typeof(ExecutionPath),
                    Width           = SocketVisual.SocketHeight,
                    X = X + NodeWidth - SocketVisual.SocketHeight,
                    Y = Y + curOutputH
                });
                curOutputH += SocketVisual.SocketHeight + ComponentPadding;
                curInputH  += SocketVisual.SocketHeight + ComponentPadding;
            }

            foreach (var input in GetInputs())
            {
                var socket = new SocketVisual();
                socket.Type   = input.ParameterType;
                socket.Height = SocketVisual.SocketHeight;
                socket.Name   = input.Name;
                socket.Width  = SocketVisual.SocketHeight;
                socket.X      = X;
                socket.Y      = Y + curInputH;
                socket.Input  = true;

                socketList.Add(socket);

                curInputH += SocketVisual.SocketHeight + ComponentPadding;
            }
            var ctx = GetNodeContext() as DynamicNodeContext;

            foreach (var output in GetOutputs())
            {
                var socket = new SocketVisual();
                socket.Type   = output.ParameterType;
                socket.Height = SocketVisual.SocketHeight;
                socket.Name   = output.Name;
                socket.Width  = SocketVisual.SocketHeight;
                socket.X      = X + NodeWidth - SocketVisual.SocketHeight;
                socket.Y      = Y + curOutputH;
                socket.Value  = ctx[socket.Name];
                socketList.Add(socket);

                curOutputH += SocketVisual.SocketHeight + ComponentPadding;
            }

            socketCache = socketList.ToArray();
            return(socketCache);
        }