public void UpdatePortView(PortData data)
        {
            if (data.displayType != null)
            {
                base.portType = data.displayType;
                portType      = data.displayType;
                visualClass   = "Port_" + portType.Name;
            }
            if (!String.IsNullOrEmpty(data.displayName))
            {
                base.portName = data.displayName;
            }

            portData = data;

            // Update the edge in case the port color have changed
            schedule.Execute(() => {
                foreach (var edge in edges)
                {
                    edge.UpdateEdgeControl();
                    edge.MarkDirtyRepaint();
                }
            }).ExecuteLater(50);             // Hummm

            UpdatePortSize();
        }
        protected PortView(Direction direction, FieldInfo fieldInfo, PortData portData, BaseEdgeConnectorListener edgeConnectorListener)
            : base(portData.vertical ? Orientation.Vertical : Orientation.Horizontal, direction, Capacity.Multi, portData.displayType ?? fieldInfo.FieldType)
        {
            this.fieldInfo = fieldInfo;
            this.listener  = edgeConnectorListener;
            this.portType  = portData.displayType ?? fieldInfo.FieldType;
            this.portData  = portData;
            this.portName  = fieldName;

            styleSheets.Add(Resources.Load <StyleSheet>(portStyle));

            UpdatePortSize();

            var userPortStyle = Resources.Load <StyleSheet>(userPortStyleFile);

            if (userPortStyle != null)
            {
                styleSheets.Add(userPortStyle);
            }

            if (portData.vertical)
            {
                AddToClassList("Vertical");
            }

            this.tooltip = portData.tooltip;
        }
Пример #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="owner">owner node</param>
        /// <param name="fieldName">the C# property name</param>
        /// <param name="portData">Data of the port</param>
        public NodePort(BaseNode owner, string fieldName, PortData portData)
        {
            this.fieldName = fieldName;
            this.owner     = owner;
            this.portData  = portData;

            fieldInfo = owner.GetType().GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            customPortIOMethod = CustomPortIO.GetCustomPortMethod(owner.GetType(), fieldName);
        }
Пример #4
0
 /// <summary>
 /// Add a port
 /// </summary>
 /// <param name="input">is input port</param>
 /// <param name="fieldName">C# field name</param>
 /// <param name="portData">Data of the port</param>
 public void AddPort(bool input, string fieldName, PortData portData)
 {
     if (input)
     {
         inputPorts.Add(new NodePort(this, fieldName, portData));
     }
     else
     {
         outputPorts.Add(new NodePort(this, fieldName, portData));
     }
 }
Пример #5
0
        protected PortView(Direction direction, FieldInfo fieldInfo, PortData portData, BaseEdgeConnectorListener edgeConnectorListener)
            : base(portData.vertical ? Orientation.Vertical : Orientation.Horizontal, direction, Capacity.Multi, portData.displayType ?? fieldInfo.FieldType)
        {
            this.fieldInfo = fieldInfo;
            this.listener  = edgeConnectorListener;
            this.portType  = portData.displayType ?? fieldInfo.FieldType;
            this.portData  = portData;
            this.portName  = fieldName;

            styleSheets.Add(Resources.Load <StyleSheet>(portStyle));

            //绘制端口Icon
            if (portData.showPortIcon)
            {
                VisualElement portIcon;
                if (string.IsNullOrEmpty(portData.portIconName))
                {
                    portIcon = new VisualElement()
                    {
                        name = $"PortViewIcon_{this.portType.Name}"
                    };
                }
                else
                {
                    portIcon = new VisualElement()
                    {
                        name = $"PortViewIcon_{portData.portIconName}"
                    };
                }
                this.Insert(1, portIcon);
            }

            UpdatePortSize();

            var userPortStyle = Resources.Load <StyleSheet>(userPortStyleFile);

            if (userPortStyle != null)
            {
                styleSheets.Add(userPortStyle);
            }

            if (portData.vertical)
            {
                AddToClassList("Vertical");
            }

            this.tooltip = portData.tooltip;
        }
Пример #6
0
        public void UpdatePortView(PortData data)
        {
            if (data.displayType != null)
            {
                base.portType = data.displayType;
                portType      = data.displayType;
                visualClass   = "Port_" + portType.Name;
            }
            if (!String.IsNullOrEmpty(data.displayName))
            {
                base.portName = data.displayName;
            }

            portData = data;

            UpdatePortSize();
        }
Пример #7
0
        /// <summary>
        /// Add a port
        /// </summary>
        /// <param name="input">is input port</param>
        /// <param name="fieldName">C# field name</param>
        /// <param name="portData">Data of the port</param>
        public void AddPort(bool input, string fieldName, PortData portData)
        {
            // Fixup port data info if needed:
            if (portData.displayType == null)
            {
                portData.displayType = nodeFields[fieldName].info.FieldType;
            }

            if (input)
            {
                inputPorts.Add(new NodePort(this, fieldName, portData));
            }
            else
            {
                outputPorts.Add(new NodePort(this, fieldName, portData));
            }
        }
Пример #8
0
        PortView(Orientation orientation, Direction direction, FieldInfo fieldInfo, PortData portData, BaseEdgeConnectorListener edgeConnectorListener)
            : base(orientation, direction, Capacity.Multi, portData.displayType ?? fieldInfo.FieldType)
        {
            this.fieldInfo = fieldInfo;
            this.listener  = edgeConnectorListener;
            this.portType  = portData.displayType ?? fieldInfo.FieldType;
            this.portData  = portData;
            this.portName  = fieldName;

            styleSheets.Add(Resources.Load <StyleSheet>(portStyle));

            UpdatePortSize();

            var userPortStyle = Resources.Load <StyleSheet>(userPortStyleFile);

            if (userPortStyle != null)
            {
                styleSheets.Add(userPortStyle);
            }
        }
Пример #9
0
        public void UpdateEdgeSize()
        {
            if (input == null && output == null)
            {
                return;
            }

            PortData inputPortData  = (input as PortView)?.portData;
            PortData outputPortData = (output as PortView)?.portData;

            for (int i = 1; i < 20; i++)
            {
                RemoveFromClassList($"edge_{i}");
            }
            int maxPortSize = Mathf.Max(inputPortData?.sizeInPixel ?? 0, outputPortData?.sizeInPixel ?? 0);

            if (maxPortSize > 0)
            {
                AddToClassList($"edge_{Mathf.Max(1, maxPortSize - 6)}");
            }
        }
Пример #10
0
        public PortView(Orientation orientation, Direction direction, FieldInfo fieldInfo, PortData portData, EdgeConnectorListener edgeConnectorListener)
            : base(orientation, direction, Capacity.Multi, portData.displayType ?? fieldInfo.FieldType)
        {
            styleSheets.Add(Resources.Load <StyleSheet>(portStyle));

            var userPortStyle = Resources.Load <StyleSheet>(userPortStyleFile);

            if (userPortStyle != null)
            {
                styleSheets.Add(userPortStyle);
            }

            this.m_EdgeConnector = new EdgeConnector <EdgeView>(edgeConnectorListener);
            this.AddManipulator(m_EdgeConnector);

            this.fieldInfo = fieldInfo;
            this.listener  = edgeConnectorListener;
            this.portType  = portData.displayType ?? fieldInfo.FieldType;
            this.portData  = portData;
            this.portName  = fieldName;
        }
Пример #11
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);
        }
        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);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
0
 protected virtual PortView CreatePortView(Direction direction, FieldInfo fieldInfo, PortData portData, BaseEdgeConnectorListener listener)
 => PortView.CreatePortView(direction, fieldInfo, portData, listener);
Пример #16
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);
        }
Пример #17
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="owner">owner node</param>
 /// <param name="fieldName">the C# property name</param>
 /// <param name="portData">Data of the port</param>
 public NodePort(BaseNode owner, string fieldName, PortData portData) : this(owner, owner, fieldName, portData)
 {
 }