Exemplo n.º 1
0
        /// <summary>
        /// Represents a single node on a graph of interconnected nodes
        /// </summary>
        /// <param name="nodeType">The class of the node being implemented</param>
        /// <param name="manager">The parent manager of the node</param>
        public GraphNode(Type nodeType, NodeGraphManager manager)
        {
            GraphManager = manager;

            NodeInputs  = new List <InputPin>();
            NodeOutputs = new List <OutputPin>();

            NodeType = nodeType;

            // Extract information about the node
            FieldInfo[] fields = NodeType.GetFields();

            // Set input pins
            foreach (FieldInfo field in fields)
            {
                Attribute[] attributes = field.GetCustomAttributes().ToArray();

                foreach (Attribute attribute in attributes)
                {
                    if (attribute.GetType() == typeof(ExposedInput))
                    {
                        InputPin input = new InputPin(field.FieldType, this);
                        NodeInputs.Add(input);
                    }
                }
            }

            // Set output pins
            foreach (FieldInfo field in fields)
            {
                Attribute[] attributes = field.GetCustomAttributes().ToArray();

                foreach (Attribute attribute in attributes)
                {
                    if (attribute.GetType() == typeof(ExposedOutput))
                    {
                        OutputPin output = new OutputPin(field.FieldType, this);
                        NodeOutputs.Add(output);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a new connection between two pins
        /// </summary>
        /// <param name="outputPin">The output pin that will provide a value</param>
        /// <param name="targetPin">The input pin the will receive the input</param>
        public void AddConnection(OutputPin outputPin, InputPin targetPin)
        {
            // Make sure we only have one connection per input
            foreach (PinConnection connection in Connections)
            {
                if (connection.InputPin == targetPin)
                {
                    throw new Exception("InputPin already has a connection.");
                }
            }

            Connections.Add(new PinConnection(outputPin, targetPin));

            // Add the connected nodes to our model if we need to
            if ((nodeNetwork.Contains(outputPin.Parent) == false) && (outputPin.Parent != null))
            {
                nodeNetwork.Add(outputPin.Parent);
            }

            if (nodeNetwork.Contains(targetPin.Parent) == false)
            {
                nodeNetwork.Add(targetPin.Parent);
            }
        }
Exemplo n.º 3
0
 public PinConnection(OutputPin outputPin, InputPin inputPin)
 {
     OutputPin = outputPin;
     InputPin  = inputPin;
 }