Exemple #1
0
        /// <summary>
        /// Updates the input data pins of this node to match the given list of types.
        /// Keeps old pins connected to what they were connected to if they still exist.
        /// </summary>
        /// <param name="returnTypes">List of specifiers for types this node should have as data inputs.</param>
        public void SetReturnTypes(IEnumerable <BaseType> returnTypes)
        {
            Dictionary <int, NodeOutputDataPin> oldConnections = new Dictionary <int, NodeOutputDataPin>();

            foreach (NodeInputDataPin pin in InputDataPins)
            {
                // Remember pins with same type as before
                int i = InputDataPins.IndexOf(pin);
                if (i < returnTypes.Count() && pin.PinType == returnTypes.ElementAt(i) &&
                    pin.IncomingPin != null)
                {
                    oldConnections.Add(i, pin.IncomingPin);
                }

                GraphUtil.DisconnectInputDataPin(pin);
            }

            InputDataPins.Clear();

            foreach (TypeSpecifier returnType in returnTypes)
            {
                AddInputDataPin(returnType.ShortName, returnType);
            }

            foreach (var oldConn in oldConnections)
            {
                GraphUtil.ConnectDataPins(oldConn.Value, InputDataPins[oldConn.Key]);
            }
        }
Exemple #2
0
        /// <summary>
        /// Sets the data pin types to the same as the main nodes' data pin types.
        /// </summary>
        private void ReplicateMainNodeInputTypes()
        {
            if (this == Method.MainReturnNode)
            {
                return;
            }

            // Get new return types
            NodeInputDataPin[] mainInputPins = Method.MainReturnNode.InputDataPins.ToArray();

            var oldConnections = new Dictionary <int, NodeOutputDataPin>();

            // Remember pins with same type as before
            foreach (NodeInputDataPin pin in InputDataPins)
            {
                int i = InputDataPins.IndexOf(pin);
                if (i < mainInputPins.Length && pin.IncomingPin != null)
                {
                    oldConnections.Add(i, pin.IncomingPin);
                }

                GraphUtil.DisconnectInputDataPin(pin);
            }

            InputDataPins.Clear();

            foreach (NodeInputDataPin mainInputPin in mainInputPins)
            {
                AddInputDataPin(mainInputPin.Name, mainInputPin.PinType.Value);
            }

            // Restore old connections
            foreach (var oldConn in oldConnections)
            {
                GraphUtil.ConnectDataPins(oldConn.Value, InputDataPins[oldConn.Key]);
            }
        }