Exemplo n.º 1
0
        protected override bool CanBeAdoptedBy(BaseNode parent)
        {
            if (base.CanBeAdoptedBy(parent))
            {
                // check if there is a Method node on the parent path
                while (parent != null)
                {
                    if (parent is Nodes.Method)
                        return true;

                    parent = parent.Parent;
                }

                parent = this.Parent;
                while (parent != null)
                {
                    if (parent is Nodes.Method)
                        return true;

                    parent = parent.Parent;
                }
            }

            return false;
        }
 /// <summary>
 /// Creates a new subitem used to visualise a connected child on the node.
 /// </summary>
 /// <param name="connector">The connector we want to visualise.</param>
 /// <param name="child">The child represented by the subitem. Can be null.</param>
 /// <param name="index">The index of the child in the connector. Also a null child has an index!</param>
 public SubItemConnector(Connector connector, BaseNode child, int index)
     : base(null, null, __font, Brushes.White, Alignment.Right, true)
 {
     _connector = connector;
     _child = child;
     _index = index;
 }
            public override bool AddChild(BaseNode node) {
                // check if we we may add the node
                if (_children.Count >= _maxCount || _isReadOnly)
                { return false; }

                node._parentConnector = this;
                _children.Add(node);
                _connectedChildren.RequiresRebuild();

                if (node is NodeViewData)
                { AddSubItem(node); }

                return true;
            }
            public override bool AddChild(BaseNode node) {
                // check if we can accept the node
                if (_child == null && !_isReadOnly) {
                    node._parentConnector = this;
                    _child = node;
                    _connectedChildren.RequiresRebuild();

                    if (node is NodeViewData)
                    { AddSubItem(node); }

                    return true;
                }

                return false;
            }
Exemplo n.º 5
0
        public override bool CanAdopt(BaseNode child)
        {
            if (base.CanAdopt(child))
            {
                return child is Sequence ||
                    child is Selector ||
                    child is Parallel ||
                    child is DecoratorLoop ||
                    child is Action ||
                    child is DecoratorIterator || 
                    child is Behaviac.Design.Nodes.ReferencedBehavior ||
                    child is Behaviac.Design.Nodes.Behavior;
            }

            return false;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns if the given node is the parent of this node and it is its last child.
        /// </summary>
        /// <param name="node">The parent we want to check if this is its last child.</param>
        /// <returns>Returns true if this node is the last child of the given node.</returns>
        public bool IsLastChildOf(BaseNode parent) {
            if (parent == null || parent.Children.Count < 1)
            { return false; }

            return parent.Children[parent.Children.Count - 1] == this;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Checks if this node can by adopted by the given one.
        /// </summary>
        /// <param name="parent">The node which can adopt this one.</param>
        /// <returns>Returns true if this node can by adopted by the given parent.</returns>
        protected virtual bool CanBeAdoptedBy(BaseNode parent) {
            if (parent != null) {
                if (this is Behavior)
                    return true;

                if (this.IsFSM)
                    return (parent.IsFSM || parent.Children.Count == 0);
                else
                    return !parent.IsFSM;
            }

            return false;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Replace the children of this node from the source node.
        /// </summary>

        public void ReplaceChildren(BaseNode source) {
            _children = source._children;
            foreach(BaseNode child in _children) {
                child._parent = this;
            }

            _fsmNodes = source._fsmNodes;
            foreach(BaseNode child in _fsmNodes) {
                child._parent = this;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Returns if any of the node's parents is a given node.
        /// </summary>
        /// <param name="parent">The node we want to check if it is a ancestor of this node.</param>
        /// <returns>Returns true if this node is a descendant of the given node.</returns>
        public bool HasParent(BaseNode parent) {
            if (_parent == null)
            { return false; }

            if (_parent == parent)
            { return true; }

            return _parent.HasParent(parent);
        }
Exemplo n.º 10
0
            /// <summary>
            /// Removes a connector subitem for a child.
            /// </summary>
            /// <param name="child">The child whose connector subitem we want to remove.</param>
            protected void RemoveSubItem(BaseNode child)
            {
                if (!(_connectedChildren.Owner is NodeViewData))
                    throw new Exception(Resources.ExceptionIsNotNodeViewData);

                int firstIndex;
                List<NodeViewData.SubItemConnector> subitems = CollectSubItems(out firstIndex);

                // find the connector subitem for this child...
                for (int i = 0; i < subitems.Count; ++i)
                {
                    NodeViewData.SubItemConnector subitem = subitems[i];

                    // when we found it...
                    if (subitem.Child == child)
                    {
                        // remove the subitem
                        ((NodeViewData)_connectedChildren.Owner).RemoveSubItem(subitem);

                        // if we do not fullfil the minimum count, re add it at the end and clear the child
                        if (subitems.Count - 1 < _minCount)
                        {
                            subitem.Child = null;
                            ((NodeViewData)_connectedChildren.Owner).AddSubItem(subitem, firstIndex + subitems.Count - 1);
                        }

                        // update stored indices on connector subitems
                        RebuildSubItemIndices();

                        return;
                    }
                }

                throw new Exception(Resources.ExceptionSubItemIsNoChild);
            }
Exemplo n.º 11
0
        public virtual bool AddFSMNode(BaseNode node) {
            if (node != null && node.IsFSM) {
                node._parent = this;
                _fsmNodes.Add(node);
                return true;
            }

            return false;
        }
Exemplo n.º 12
0
 /// <summary>
 /// Gets a connector of the node by a child connected to it.
 /// </summary>
 /// <param name="child">The child of the connector we are looking for.</param>
 /// <returns>Returns null if no connector could be found.</returns>
 public Connector GetConnector(BaseNode child)
 {
     return(_children.GetConnector(child));
 }
 /// <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(BaseNode child) {
     Connector connector = (child != null && child.ParentConnector != null) ? GetConnector(child.ParentConnector.Identifier) : null;
     return (connector != null) ? connector.AcceptsChild(child) : false;
 }
Exemplo n.º 14
0
 public virtual Attachments.Attachment CreateStartCondition(BaseNode owner)
 {
     return(null);
 }
Exemplo n.º 15
0
 public virtual bool RemoveFSMNode(BaseNode node)
 {
     Debug.Check(node != null && node.IsFSM);
     return(_fsmNodes.Remove(node));
 }
Exemplo n.º 16
0
 //can only added to the 'Behavior'
 protected override bool CanBeAdoptedBy(BaseNode parent)
 {
     return(base.CanBeAdoptedBy(parent) && (parent is Behavior));
 }
 /// <summary>
 /// Creates a new instance to store all available connectors on an node.
 /// </summary>
 /// <param name="owner">The node this instance belongs to.</param>
 public ConnectedChildren(BaseNode owner)
 {
     _owner = owner;
 }
            /// <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(BaseNode child)
            {
                Connector connector = (child != null && child.ParentConnector != null) ? GetConnector(child.ParentConnector.Identifier) : null;

                return((connector != null) ? connector.AcceptsChild(child) : false);
            }
Exemplo n.º 19
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;
        }
Exemplo n.º 20
0
 /// <summary>
 /// Checks if a new 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 virtual bool CanAdopt(BaseNode child)
 {
     return(child != null && child.CanBeAdoptedBy(this));
 }
Exemplo n.º 21
0
 public override int GetChildIndex(BaseNode node)
 {
     return(_child == node ? 0 : -1);
 }
Exemplo n.º 22
0
 /// <summary>
 /// Checks if an existing 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(BaseNode child)
 {
     return(CanAdopt(child) && _children.CanAdoptNode(child));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Gets the index of a child.
 /// </summary>
 /// <param name="node">The child whose index we want to have.</param>
 /// <returns>Returns -1 if the child could not be found.</returns>
 public abstract int GetChildIndex(BaseNode node);
Exemplo n.º 24
0
 public override bool CanAdopt(BaseNode child)
 {
     return(false);
 }
Exemplo n.º 25
0
 public override Attachment CreateStartCondition(BaseNode owner)
 {
     return Attachment.Create(typeof(PluginBehaviac.Events.StartCondition), owner as Node);
 }
Exemplo n.º 26
0
 public override bool AddChild(BaseNode node, int index)
 {
     // we only have one child, the index does not matter to us
     return(AddChild(node));
 }
Exemplo n.º 27
0
 public virtual bool RemoveFSMNode(BaseNode node) {
     Debug.Check(node != null && node.IsFSM);
     return _fsmNodes.Remove(node);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Adds a child to this connector on a given position.
 /// </summary>
 /// <param name="node">The node we want to add.</param>
 /// <param name="index">The position we want to add the node at.</param>
 /// <returns>Returns false if the connector does not allow any more nodes to be added.</returns>
 public abstract bool AddChild(BaseNode node, int index);
Exemplo n.º 29
0
 /// <summary>
 /// Gets a connector of the node by a child connected to it.
 /// </summary>
 /// <param name="child">The child of the connector we are looking for.</param>
 /// <returns>Returns null if no connector could be found.</returns>
 public Connector GetConnector(BaseNode child) {
     return _children.GetConnector(child);
 }
Exemplo n.º 30
0
 /// <summary>
 /// Adds a child to this connector.
 /// </summary>
 /// <param name="node">The node we want to add.</param>
 /// <returns>Returns false if the connector does not allow any more nodes to be added.</returns>
 public abstract bool AddChild(BaseNode node);
Exemplo n.º 31
0
        /// <summary>
        /// Returns if a given noe is a sibling of this node.
        /// </summary>
        /// <param name="sibling">The assumed sibling we want to check.</param>
        /// <returns>Returns true if the given node is a sibling of this node.</returns>
        public bool IsSibling(BaseNode sibling) {
            if (_parent == null)
            { return false; }

            return _parent.Children.Contains(sibling);
        }
Exemplo n.º 32
0
        private bool AdoptNodeByAncestor(BaseNode target, BaseNode node) {
            if (target != null && target.CanAdopt(node)) {
                target = target.Parent;

                // check if there is a Method node on the parent path
                while (target != null) {
                    if (target is Nodes.Method) {
                        return target.CanAdopt(node);
                    }

                    target = target.Parent;
                }

                return true;
            }

            return false;
        }
Exemplo n.º 33
0
 /// <summary>
 /// Checks if a new 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 virtual bool CanAdopt(BaseNode child) {
     return child != null && child.CanBeAdoptedBy(this);
 }
Exemplo n.º 34
0
 //can only added to the 'Behavior'
 protected override bool CanBeAdoptedBy(BaseNode parent) {
     return base.CanBeAdoptedBy(parent) && (parent is Behavior);
 }
Exemplo n.º 35
0
 /// <summary>
 /// Checks if an existing 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(BaseNode child) {
     return CanAdopt(child) && _children.CanAdoptNode(child);
 }
Exemplo n.º 36
0
 protected override bool CanBeAdoptedBy(BaseNode parent)
 {
     return base.CanBeAdoptedBy(parent) && (parent is SelectorProbability);
 }
Exemplo n.º 37
0
 public virtual Attachments.Attachment CreateStartCondition(BaseNode owner) {
     return null;
 }
Exemplo n.º 38
0
            public override void ClearChildrenInternal()
            {
                _child = null;

                _connectedChildren.RequiresRebuild();
            }
Exemplo n.º 39
0
 protected override bool CanBeAdoptedBy(BaseNode parent)
 {
     return base.CanBeAdoptedBy(parent) && (parent is Behavior) && (parent.IsFSM || (parent.Children.Count == 0)) && (parent.FSMNodes.Count == 0);
 }
Exemplo n.º 40
0
 /// <summary>
 /// Removes a child from this connector.
 /// </summary>
 /// <param name="node">The child we want to remove.</param>
 /// <returns>Returns false if the connector is read-only.</returns>
 public abstract bool RemoveChild(BaseNode node);
Exemplo n.º 41
0
        //can only accept multiple methods or only one other type of node
        public override bool CanAdopt(BaseNode child) {
            if (base.CanAdopt(child)) {
                // 1. the 1st child, to accept it anyway
                if (this.Children.Count == 0) {
                    return true;
                }

                // 2. only accept it if the newly added one is a Method and the existing Children are all Method
                if (child is Nodes.Method) {
                    // insert a Method before a none-method node
                    if (this.Children.Count == 1) {
                        return true;
                    }

                    int count = 0;

                    for (int i = 0; i < this.Children.Count; ++i) {
                        BaseNode c = this.Children[i];
                        bool isMethod = c is Method;

                        if (isMethod) {
                            count++;
                        }
                    }

                    // all children are method, accept any node, (a Method will be automatically added if it is not a method)
                    if (count == this.Children.Count) {
                        return true;
                    }
                }
            }

            return false;
        }
Exemplo n.º 42
0
            /// <summary>
            /// Adds a connector subitem for a given child.
            /// </summary>
            /// <param name="child">The child we want to add a connecor subitem for.</param>
            protected void AddSubItem(BaseNode child)
            {
                if (!(_connectedChildren.Owner is NodeViewData))
                    throw new Exception(Resources.ExceptionIsNotNodeViewData);

                int firstIndex;
                List<NodeViewData.SubItemConnector> subitems = CollectSubItems(out firstIndex);

                // check if there is a connector subitem with child due to the minimum count
                foreach (NodeViewData.SubItemConnector subitem in subitems)
                {
                    if (subitem.Child == null)
                    {
                        // simply reuse the connector subitem
                        subitem.Child = child;
                        return;
                    }
                }

                // add a new connector subitem
                ((NodeViewData)_connectedChildren.Owner).AddSubItem(new NodeViewData.SubItemConnector(this, child, subitems.Count), firstIndex + subitems.Count);
            }
            /// <summary>
            /// Gets a connector by one of its children.
            /// </summary>
            /// <param name="child">The child whose connector we are looking for.</param>
            /// <returns>Returns null if no connector could be found.</returns>
            public Connector GetConnector(BaseNode child) {
                foreach(Connector connector in _connectors) {
                    for (int i = 0; i < connector.ChildCount; ++i) {
                        if (connector.GetChild(i) == child)
                        { return connector; }
                    }
                }

                return null;
            }
Exemplo n.º 44
0
            /// <summary>
            /// Adds a connector subitem for a given child at a given position.
            /// </summary>
            /// <param name="child">The child we want to add a connector subitem for.</param>
            /// <param name="index">The position we want to add the subitem at.</param>
            protected void AddSubItem(BaseNode child, int index)
            {
                if (!(_connectedChildren.Owner is NodeViewData))
                    throw new Exception(Resources.ExceptionIsNotNodeViewData);

                int firstIndex;
                List<NodeViewData.SubItemConnector> subitems = CollectSubItems(out firstIndex);

                // we want to add inside the minimum count it can be that there is a connector subitem which has no child (due to minimum count)
                if (index < _minCount)
                {
                    foreach (NodeViewData.SubItemConnector subitem in subitems)
                    {
                        if (subitem.Child == null)
                        {
                            // if there is a free connector subitem we drop it so we can add a new one for our child
                            ((NodeViewData)_connectedChildren.Owner).RemoveSubItem(subitem);
                            break;
                        }
                    }
                }

                // add a connector subitem for the child
                ((NodeViewData)_connectedChildren.Owner).AddSubItem(new NodeViewData.SubItemConnector(this, child, subitems.Count), firstIndex + index);

                RebuildSubItemIndices();
            }
 /// <summary>
 /// Creates a new instance to store all available connectors on an node.
 /// </summary>
 /// <param name="owner">The node this instance belongs to.</param>
 public ConnectedChildren(BaseNode owner) {
     _owner = owner;
 }
Exemplo n.º 46
0
 /// <summary>
 /// Removes a child from this connector.
 /// </summary>
 /// <param name="node">The child we want to remove.</param>
 /// <returns>Returns false if the connector is read-only.</returns>
 public abstract bool RemoveChild(BaseNode node);