/// <summary>
            /// Checks if a node can be adopted by this one.
            /// </summary>
            /// <param name="child">The node we want to adopt.</param>
            /// <returns>Returns true if this node can adopt the given child.</returns>
            public bool CanAdoptNode(Node child)
            {
                Connector connector = GetConnector(child.ParentConnector.Identifier);

                if (connector == null)
                {
                    connector = _defaultConnector;
                }

                return(connector != null && connector.AcceptsChildren(1));
            }
Example #2
0
        /// <summary>
        /// Checks if the children of a node can be adopted by this one.
        /// </summary>
        /// <param name="node">The node we want to adopt its children.</param>
        /// <returns>Returns true if this node can adopt the children of the given node.</returns>
        public bool CanAdoptChildren(BaseNode node)
        {
            foreach (Connector connector in node.Connectors)
            {
                if (connector.ChildCount > 0)
                {
                    // Get the connector to adapt those children
                    Connector conn = GetConnector(connector.Identifier);

                    // Check if this connector accepts those children
                    if (conn == null || !conn.AcceptsChildren(connector))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #3
0
        public bool CanAdoptChildren(BaseNode parentNode)
        {
            foreach (Connector parentConn in parentNode.Connectors)
            {
                if (parentConn.ChildCount > 0)
                {
                    // check if we have a connector to adapt those children
                    Connector conn = GetConnector(parentConn.Identifier);

                    if (conn == null)
                    {
                        return(false);
                    }

                    // check if this connector accepts those children
                    if (!conn.AcceptsChildren(parentConn))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Example #4
0
		/// <summary>
		/// Add a new child node.
		/// </summary>
		/// <param name="connector">The connector the node will be added to. Use null for default connector.</param>
		/// <param name="node">The node you want to append.</param>
		/// <param name="index">The index of the new node.</param>
		/// <returns>Returns true if the child could be added.</returns>
		public virtual bool AddChild(Connector connector, Node node, int index)
		{
			Debug.Check(connector !=null && _children.HasConnector(connector));

			if(!connector.AcceptsChildren(1))
				throw new Exception(Resources.ExceptionNodeHasTooManyChildren);

			if(!connector.AddChild(node, index))
				return false;

			node._parent= this;

			BehaviorWasModified();

			return true;
		}