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>
        /// Removes the last input data pin for an array element.
        /// Returns whether one was actually removed.
        /// </summary>
        /// <returns>Whether a pin was removed.</returns>
        public bool RemoveElementPin()
        {
            if (InputDataPins.Count > 0)
            {
                // TODO: Add method for removing pins on Node
                NodeInputDataPin inputDataPin = InputDataPins[InputDataPins.Count - 1];
                GraphUtil.DisconnectInputDataPin(inputDataPin);
                InputDataPins.Remove(inputDataPin);

                return(true);
            }

            return(false);
        }
Exemple #3
0
        public void RemoveReturnType()
        {
            if (this != Method.MainReturnNode)
            {
                throw new InvalidOperationException("Can only remove return types on the main return node.");
            }

            if (InputDataPins.Count > 0)
            {
                NodeInputDataPin idpToRemove = InputDataPins.Last();
                NodeInputTypePin itpToRemove = InputTypePins.Last();

                GraphUtil.DisconnectInputDataPin(idpToRemove);
                GraphUtil.DisconnectInputTypePin(itpToRemove);

                InputDataPins.Remove(idpToRemove);
                InputTypePins.Remove(itpToRemove);
            }
        }
Exemple #4
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]);
            }
        }