コード例 #1
0
 public void InsertPort(PortView portView, int index)
 {
     if (portView.direction == Direction.Input)
     {
         if (portView.portData.vertical)
         {
             topPortContainer.Insert(index, portView);
         }
         else
         {
             inputContainer.Insert(index, portView);
         }
     }
     else
     {
         if (portView.portData.vertical)
         {
             bottomPortContainer.Insert(index, portView);
         }
         else
         {
             outputContainer.Insert(index, portView);
         }
     }
 }
コード例 #2
0
        public void OnPortConnected(PortView pv, Edge edge)
        {
            // Fix port datas
            if (pv.direction == Direction.Input)
            {
                edge.input = pv;
            }
            else
            {
                edge.output = pv;
            }

            // If the edge is already connected, ignore it
            if (portViews.ContainsKey(edge))
            {
                return;
            }

            portViews[edge] = pv;

            if (pv.GetEdges().Count == 0)
            {
                multiPorts.AddUniqueId(multiPorts.GetUniqueId());
                AddPort();
            }
        }
コード例 #3
0
        public PortView AddPort(FieldInfo fieldInfo, Direction direction, BaseEdgeConnectorListener listener, PortData portData)
        {
            // TODO: hardcoded value
            PortView p = PortView.CreatePV(Orientation.Horizontal, direction, fieldInfo, portData, listener);

            if (p.direction == Direction.Input)
            {
                inputPortViews.Add(p);
                inputContainer.Add(p);
            }
            else
            {
                outputPortViews.Add(p);
                outputContainer.Add(p);
            }

            p.Initialize(this, portData?.displayName);

            List <PortView> ports;

            portsPerFieldName.TryGetValue(p.fieldName, out ports);
            if (ports == null)
            {
                ports = new List <PortView>();
                portsPerFieldName[p.fieldName] = ports;
            }
            ports.Add(p);

            return(p);
        }
コード例 #4
0
        public void RemovePort(PortView p)
        {
            // Remove all connected edges:
            var edgesCopy = p.GetEdges().ToList();

            foreach (var e in edgesCopy)
            {
                owner.Disconnect(e, refreshPorts: false);
            }

            if (p.direction == Direction.Input)
            {
                if (inputPortViews.Remove(p))
                {
                    p.RemoveFromHierarchy();
                }
            }
            else
            {
                if (outputPortViews.Remove(p))
                {
                    p.RemoveFromHierarchy();
                }
            }

            List <PortView> ports;

            portsPerFieldName.TryGetValue(p.fieldName, out ports);
            ports.Remove(p);
        }
コード例 #5
0
        public static PortView CreatePortView(Direction direction, FieldInfo fieldInfo, PortData portData, BaseEdgeConnectorListener edgeConnectorListener)
        {
            var pv = new PortView(direction, fieldInfo, portData, edgeConnectorListener);

            pv.m_EdgeConnector = new BaseEdgeConnector(edgeConnectorListener);
            pv.AddManipulator(pv.m_EdgeConnector);

            // Force picking in the port label to enlarge the edge creation zone
            var portLabel = pv.Q("type");

            if (portLabel != null)
            {
                portLabel.pickingMode    = PickingMode.Position;
                portLabel.style.flexGrow = 1;
            }

            // hide label when the port is vertical
            if (portData.vertical && portLabel != null)
            {
                portLabel.style.display = DisplayStyle.None;
            }

            // Fixup picking mode for vertical top ports
            if (portData.vertical)
            {
                pv.Q("connector").pickingMode = PickingMode.Position;
            }

            return(pv);
        }
コード例 #6
0
        public static PortView CreatePV(Orientation orientation, Direction direction, FieldInfo fieldInfo, PortData portData, BaseEdgeConnectorListener edgeConnectorListener)
        {
            var pv = new PortView(orientation, direction, fieldInfo, portData, edgeConnectorListener);

            pv.m_EdgeConnector = new BaseEdgeConnector(edgeConnectorListener);
            pv.AddManipulator(pv.m_EdgeConnector);

            return(pv);
        }
コード例 #7
0
        void AddPort()
        {
            PortView pv = node.AddPort(fieldInfo, direction, listener, isMultiple, name);

            // We force the AddPort in the BaseNode class because the port list is not updated except at the construction of the class
            node.nodeTarget.AddPort(direction == Direction.Input, pv.fieldName);

            pv.OnConnected    += OnPortConnected;
            pv.OnDisconnected += OnPortDisconnected;
        }
コード例 #8
0
 public void InsertPort(PortView portView, int index)
 {
     if (portView.direction == Direction.Input)
     {
         inputContainer.Insert(index, portView);
     }
     else
     {
         outputContainer.Insert(index, portView);
     }
 }
コード例 #9
0
        public void RemovePort(PortView p)
        {
            if (p.direction == Direction.Input)
            {
                inputPorts.Remove(p);
                inputContainer.Remove(p);
            }
            else
            {
                outputPorts.Remove(p);
                outputContainer.Remove(p);
            }

            portsPerFieldName.Remove(p.fieldName);
        }
コード例 #10
0
        public static List <PortDescription> GetEdgeCreationNodeMenuEntry(PortView portView)
        {
            return(nodeCreatePortDescription.Where(n => {
                if (portView.direction == Direction.Input && n.isInput || portView.direction == Direction.Output && !n.isInput)
                {
                    return false;
                }

                if (!BaseGraph.TypesAreConnectable(n.portType, portView.portType))
                {
                    return false;
                }

                return true;
            }).ToList());
        }
コード例 #11
0
        public void Initialize(BaseGraphView graphView, EditorWindow window, EdgeView edgeFilter = null)
        {
            this.graphView      = graphView;
            this.window         = window;
            this.edgeFilter     = edgeFilter;
            this.inputPortView  = edgeFilter?.input as PortView;
            this.outputPortView = edgeFilter?.output as PortView;

            // Transparent icon to trick search window into indenting items
            if (icon == null)
            {
                icon = new Texture2D(1, 1);
            }
            icon.SetPixel(0, 0, new Color(0, 0, 0, 0));
            icon.Apply();
        }
コード例 #12
0
        public RelayNodeView AddRelayNode(PortView inputPort, PortView outputPort, Vector2 position)
        {
            var relayNode = BaseNode.CreateFromType <RelayNode>(position);
            var view      = AddNode(relayNode) as RelayNodeView;

            if (outputPort != null)
            {
                Connect(view.inputPortViews[0], outputPort);
            }
            if (inputPort != null)
            {
                Connect(inputPort, view.outputPortViews[0]);
            }

            return(view);
        }
コード例 #13
0
        public void OnPortDisconnected(PortView pv, Edge edge)
        {
            if (pv.GetEdges().Count == 0)
            {
                if ((edge as EdgeView).isConnected && portViews.ContainsKey(edge))
                {
                    var portToRemove = portViews[edge];

                    node.RemovePort(portToRemove);

                    node.nodeTarget.RemovePort(direction == Direction.Input, portToRemove.fieldName);

                    portViews.Remove(edge);
                    multiPorts.RemoveUniqueId(0);
                }
            }
        }
コード例 #14
0
        public PortView AddPort(FieldInfo fieldInfo, Direction direction, BaseEdgeConnectorListener listener, PortData portData)
        {
            PortView p = CreatePortView(direction, fieldInfo, portData, listener);

            if (p.direction == Direction.Input)
            {
                inputPortViews.Add(p);

                if (portData.vertical)
                {
                    topPortContainer.Add(p);
                }
                else
                {
                    inputContainer.Add(p);
                }
            }
            else
            {
                outputPortViews.Add(p);

                if (portData.vertical)
                {
                    bottomPortContainer.Add(p);
                }
                else
                {
                    outputContainer.Add(p);
                }
            }

            p.Initialize(this, portData?.displayName);

            List <PortView> ports;

            portsPerFieldName.TryGetValue(p.fieldName, out ports);
            if (ports == null)
            {
                ports = new List <PortView>();
                portsPerFieldName[p.fieldName] = ports;
            }
            ports.Add(p);

            return(p);
        }
コード例 #15
0
        public static PortView CreatePV(Orientation orientation, Direction direction, FieldInfo fieldInfo, PortData portData, BaseEdgeConnectorListener edgeConnectorListener)
        {
            var pv = new PortView(orientation, direction, fieldInfo, portData, edgeConnectorListener);

            pv.m_EdgeConnector = new BaseEdgeConnector(edgeConnectorListener);
            pv.AddManipulator(pv.m_EdgeConnector);

            // Force picking in the port label to enlarge the edge creation zone
            var portLabel = pv.Q("type");

            if (portLabel != null)
            {
                portLabel.pickingMode    = PickingMode.Position;
                portLabel.style.flexGrow = 1;
            }

            return(pv);
        }
コード例 #16
0
        public PortView AddPort(FieldInfo fieldInfo, Direction direction, EdgeConnectorListener listener, bool isMultiple = false, string name = null)
        {
            // TODO: hardcoded value
            PortView p = new PortView(Orientation.Horizontal, direction, fieldInfo, listener);

            if (p.direction == Direction.Input)
            {
                inputPorts.Add(p);
                inputContainer.Add(p);
            }
            else
            {
                outputPorts.Add(p);
                outputContainer.Add(p);
            }

            p.Initialize(this, isMultiple, name);

            portsPerFieldName[p.fieldName] = p;

            return(p);
        }
コード例 #17
0
        public static IEnumerable <PortDescription> GetEdgeCreationNodeMenuEntry(PortView portView, BaseGraph graph = null)
        {
            foreach (var description in genericNodes.nodeCreatePortDescription)
            {
                if (!IsPortCompatible(description))
                {
                    continue;
                }

                yield return(description);
            }

            if (graph != null && specificNodeDescriptions.TryGetValue(graph, out var specificNodes))
            {
                foreach (var description in specificNodes.nodeCreatePortDescription)
                {
                    if (!IsPortCompatible(description))
                    {
                        continue;
                    }
                    yield return(description);
                }
            }

            bool IsPortCompatible(PortDescription description)
            {
                if (portView.direction == Direction.Input && description.isInput || portView.direction == Direction.Output && !description.isInput)
                {
                    return(false);
                }

                if (!BaseGraph.TypesAreConnectable(description.portType, portView.portType))
                {
                    return(false);
                }

                return(true);
            }
        }
コード例 #18
0
        public bool Connect(PortView inputPortView, PortView outputPortView, bool autoDisconnectInputs = true)
        {
            var inputPort  = inputPortView.owner.nodeTarget.GetPort(inputPortView.fieldName, inputPortView.portData.identifier);
            var outputPort = outputPortView.owner.nodeTarget.GetPort(outputPortView.fieldName, outputPortView.portData.identifier);

            // Checks that the node we are connecting still exists
            if (inputPortView.owner.parent == null || outputPortView.owner.parent == null)
            {
                return(false);
            }

            var newEdge = SerializableEdge.CreateNewEdge(graph, inputPort, outputPort);

            var edgeView = new EdgeView()
            {
                userData = newEdge,
                input    = inputPortView,
                output   = outputPortView,
            };

            return(Connect(edgeView));
        }
コード例 #19
0
 public virtual void OnPortDisconnected(PortView port)
 {
 }
コード例 #20
0
 protected virtual PortView CreatePortView(Direction direction, FieldInfo fieldInfo, PortData portData, BaseEdgeConnectorListener listener)
 => PortView.CreatePortView(direction, fieldInfo, portData, listener);
コード例 #21
0
 public void OnPortDisconnected(PortView port)
 {
     onPortDisconnected?.Invoke(port);
 }
コード例 #22
0
 internal void OnPortDisconnected(PortView port)
 {
     onPortDisconnected?.Invoke(port);
 }