Ejemplo n.º 1
0
        private NodeSocket GetSocket(Type forType)
        {
            var socket = new NodeSocket();

            SetValidType(socket, forType);
            return(socket);
        }
Ejemplo n.º 2
0
        private Point SnapIfPossible(Point rootRelativePoint)
        {
            snappedSocket = null;
            var nearestNode = root.GetNearestNode(rootRelativePoint);

            if (null == nearestNode)
            {
                return(rootRelativePoint);
            }

            var nearestConnector = dragType == DragEndPoint.Input
                ? nearestNode.GetNearestFreeOutputSocket(rootRelativePoint, null == outputSocket ? null : Node.GetValidType(outputSocket))
                : nearestNode.GetNearestFreeInputSocket(rootRelativePoint, null == inputSocket ? null : Node.GetValidType(inputSocket));

            if (null == nearestConnector)
            {
                return(rootRelativePoint);
            }

            var distance = (rootRelativePoint - nearestConnector.Position).Length;

            if (distance <= SnapDistance)
            {
                if (dragType == DragEndPoint.Input && !nearestNode.QueryCanConnectOutput(OutputNode) ||
                    dragType == DragEndPoint.Output && !nearestNode.QueryCanConnectInput(InputNode))
                {
                    return(rootRelativePoint);
                }

                snappedSocket = nearestConnector;
                return(nearestConnector.Position);
            }
            return(rootRelativePoint);
        }
Ejemplo n.º 3
0
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            base.OnMouseUp(e);
            var type = dragType;

            dragType = DragEndPoint.Unknown;
            ReleaseMouseCapture();
            if (null != snappedSocket)
            {
                if (DragEndPoint.Input == type)
                {
                    ConnectInputEndPoint(snappedSocket);
                }
                else
                {
                    ConnectOutputEndPoint(snappedSocket);
                }
            }
            if (null == inputSocket || null == outputSocket)
            {
                Delete();
            }
            snappedSocket = null;
            e.Handled     = true;
        }
Ejemplo n.º 4
0
 private void Connect(NodeSocket from, IConnectable to)
 {
     if (!InputSockets.Contains(from) && !OutputSockets.Contains(from))
     {
         return;
     }
     from.Connect(to);
 }
Ejemplo n.º 5
0
 public SocketType GetSocketType(NodeSocket socket)
 {
     if (InputSockets.Contains(socket))
     {
         return(SocketType.Input);
     }
     return(OutputSockets.Contains(socket) ? SocketType.Output : SocketType.Unknown);
 }
Ejemplo n.º 6
0
 public void ConnectOutputEndPoint(NodeSocket to)
 {
     outputSocket = to;
     OutputNode   = to.Node;
     OnConnected(to);
     UpdateStopPoint();
     if (null == inputSocket)
     {
         StartPoint = StopPoint;
     }
     UpdateCentrePoints();
 }
Ejemplo n.º 7
0
        private void AddInputSocket()
        {
            if (!CanAutoAddInputs || GetFreeInputSocket() != null)
            {
                return;
            }
            var socket = new NodeSocket();

            if (null != contentNode && contentNode.Inputs != null)
            {
                SetValidType(socket, contentNode.Inputs.LastOrDefault());
            }
            SubscribeInputSocket(socket);
            InputSockets.Add(socket);
        }
Ejemplo n.º 8
0
        private Point SnapIfPossible(Point rootRelativePoint)
        {
            snappedSocket = null;
            var nearestNode = root.GetNearestNode(rootRelativePoint);
            if (null == nearestNode) return rootRelativePoint;

            var nearestConnector = dragType == DragEndPoint.Input
                ? nearestNode.GetNearestFreeOutputSocket(rootRelativePoint, null == outputSocket ? null : Node.GetValidType(outputSocket))
                : nearestNode.GetNearestFreeInputSocket(rootRelativePoint, null == inputSocket ? null : Node.GetValidType(inputSocket));
            if (null == nearestConnector) return rootRelativePoint;

            var distance = (rootRelativePoint - nearestConnector.Position).Length;
            if (distance <= SnapDistance)
            {
                if (dragType == DragEndPoint.Input && !nearestNode.QueryCanConnectOutput(OutputNode) ||
                    dragType == DragEndPoint.Output && !nearestNode.QueryCanConnectInput(InputNode))
                    return rootRelativePoint;

                snappedSocket = nearestConnector;
                return nearestConnector.Position;
            }
            return rootRelativePoint;
        }
Ejemplo n.º 9
0
 protected override void OnMouseUp(MouseButtonEventArgs e)
 {
     base.OnMouseUp(e);
     var type = dragType;
     dragType = DragEndPoint.Unknown;
     ReleaseMouseCapture();
     if (null != snappedSocket)
     {
         if (DragEndPoint.Input == type)
             ConnectInputEndPoint(snappedSocket);
         else
             ConnectOutputEndPoint(snappedSocket);
     }
     if (null == inputSocket || null == outputSocket)
         Delete();
     snappedSocket = null;
     e.Handled = true;
 }
Ejemplo n.º 10
0
 public SocketType GetSocketType(NodeSocket socket)
 {
     if (InputSockets.Contains(socket))
         return SocketType.Input;
     return OutputSockets.Contains(socket) ? SocketType.Output : SocketType.Unknown;
 }
Ejemplo n.º 11
0
 private void AddInputSocket()
 {
     if (!CanAutoAddInputs || GetFreeInputSocket() != null) return;
     var socket = new NodeSocket();
     if (null != contentNode && contentNode.Inputs != null)
         SetValidType(socket, contentNode.Inputs.LastOrDefault());
     SubscribeInputSocket(socket);
     InputSockets.Add(socket);
 }
Ejemplo n.º 12
0
 public static void SetValidType(NodeSocket element, Type value)
 {
     element.SetValue(ValidTypeProperty, value);
 }
Ejemplo n.º 13
0
 public static Type GetValidType(NodeSocket element)
 {
     return((Type)element.GetValue(ValidTypeProperty));
 }
Ejemplo n.º 14
0
 private static bool IsCompatible(NodeSocket socket, Type type)
 {
     return(null == type || GetValidType(socket) == type);
 }
Ejemplo n.º 15
0
 private static bool IsSocketFree(NodeSocket socket)
 {
     return !socket.IsConnected;
 }
Ejemplo n.º 16
0
 private static bool IsCompatible(NodeSocket socket, Type type)
 {
     return (null == type || GetValidType(socket) == type);
 }
Ejemplo n.º 17
0
 private static bool IsSocketFree(NodeSocket socket)
 {
     return(!socket.IsConnected);
 }
Ejemplo n.º 18
0
 private NodeSocket GetSocket(Type forType)
 {
     var socket = new NodeSocket();
     SetValidType(socket, forType);
     return socket;
 }
Ejemplo n.º 19
0
 public void ConnectOutputEndPoint(NodeSocket to)
 {
     outputSocket = to;
     OutputNode = to.Node;
     OnConnected(to);
     UpdateStopPoint();
     if (null == inputSocket)
         StartPoint = StopPoint;
     UpdateCentrePoints();
 }
Ejemplo n.º 20
0
 public static Type GetValidType(NodeSocket element)
 {
     return (Type)element.GetValue(ValidTypeProperty);
 }
Ejemplo n.º 21
0
 public static void SetValidType(NodeSocket element, Type value)
 {
     element.SetValue(ValidTypeProperty, value);
 }
Ejemplo n.º 22
0
 private void Connect(NodeSocket from, IConnectable to)
 {
     if (!InputSockets.Contains(from) && !OutputSockets.Contains(from)) return;
     from.Connect(to);
 }