Esempio n. 1
0
        protected virtual bool TransferAction(LBAction _other, LBActionTransitTypes _transit, LBActionTransitDirection _dir)
        {
            if (_dir == LBActionTransitDirection.In)             // transition from _other to this (IN this)
            {
                if (!this.CanTransferAction(_other, _transit, LBActionTransitDirection.In))
                {
                    return(false);
                }

                if (_other is LBTransitiveAction)
                {
                    LBTransitiveAction other = (LBTransitiveAction)_other;

                    if (other.CanTransferAction(this, _transit, LBActionTransitDirection.Out))
                    {
                        other.Deactivate(this, _transit);
                        this.Activate(other, _transit);

                        return(true);
                    }
                }
                else
                {
                    if (_other.CanDeactivateAction())                      // here we are deactivating with an external call
                    {
                        _other.DeactivateAction();
                        this.Activate(_other, _transit);

                        return(true);
                    }
                }
            }
            else             // transition from this to _other (OUT of this)
            {
                if (!this.CanTransferAction(_other, _transit, LBActionTransitDirection.Out))
                {
                    return(false);
                }

                if (_other is LBTransitiveAction)
                {
                    LBTransitiveAction other = (LBTransitiveAction)_other;

                    if (other.CanTransferAction(this, _transit, LBActionTransitDirection.In))
                    {
                        other.Activate(this, _transit);
                        this.Deactivate(other, _transit);

                        return(true);
                    }
                }
                else
                {
                    if (_other.CanActivateAction())                      // here we are activating with an external call
                    {
                        _other.ActivateAction();
                        this.Deactivate(_other, _transit);

                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        protected virtual bool TransferMultiAction(LBAction[] _others, LBActionTransitTypes _transit, LBActionTransitDirection _dir)
        {
            int  i;
            bool b;

            b = false;

            if (_dir == LBActionTransitDirection.In)             // transition from _other to this (IN this)
            {
                for (i = 0; i < _others.Length; i++)
                {
                    if (!this.CanTransferAction(_others [i], _transit, LBActionTransitDirection.In))
                    {
                        return(false);
                    }

                    if (_others [i] is LBTransitiveAction)
                    {
                        LBTransitiveAction other = (LBTransitiveAction)(_others [i]);

                        if (other.CanTransferAction(this, _transit, LBActionTransitDirection.Out))
                        {
                            other.Deactivate(this, _transit);
                            //this.Activate (other, _transit);
                            b = true;

                            //return true;
                        }
                    }
                    else
                    {
                        if (_others [i].CanDeactivateAction())                          // here we are deactivating with an external call
                        {
                            _others [i].DeactivateAction();
                            ///this.Activate (_others[i], _transit);
                            b = true;

                            //return true;
                        }
                    }
                }

                if (b == true)
                {
                    this.Activate(_others, _transit);
                    return(true);
                }
            }
            else             // transition from this to _other (OUT of this)
            {
                for (i = 0; i < _others.Length; i++)
                {
                    if (!this.CanTransferAction(_others [i], _transit, LBActionTransitDirection.Out))
                    {
                        return(false);
                    }

                    if (_others [i] is LBTransitiveAction)
                    {
                        LBTransitiveAction other = (LBTransitiveAction)(_others [i]);

                        if (other.CanTransferAction(this, _transit, LBActionTransitDirection.In))
                        {
                            other.Activate(this, _transit);
                            //this.Deactivate (other, _transit);
                            b = true;

                            //return true;
                        }
                    }
                    else
                    {
                        if (_others [i].CanActivateAction())                          // here we are activating with an external call
                        {
                            _others [i].ActivateAction();
                            //this.Deactivate (_other, _transit);
                            b = true;

                            //return true;
                        }
                    }
                }

                if (b == true)
                {
                    this.Deactivate(_others, _transit);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 3
0
        protected virtual bool CanTransferAction(LBAction _other, LBActionTransitTypes _transit, LBActionTransitDirection _dir)
        {
            if (_dir == LBActionTransitDirection.In)
            {
                if (!base.CanActivateAction(true))                  // if we cannot activate
                {
                    return(false);
                }
            }
            else
            {
                if (!base.CanDeactivateAction(true))                  // if we cannot deactivate
                {
                    return(false);
                }
            }

            if (_dir == LBActionTransitDirection.In)        // trying to transit from _other to this (IN this)
            {
                if (!HasInputConn(_other))                  // if we don't have this action connected (doesn't matter switch or interrupt)
                {
                    return(false);
                }

                if (this.IsConditionalActivation)                 // if we need to check some conditions to activate
                {
                    if (!this.CheckTransferConditions(_other, _transit, _dir))
                    {
                        return(false);
                    }
                }

                if (_other is LBTransitiveAction)
                {
                    LBTransitiveAction other = (LBTransitiveAction)_other;

                    if (!other.HasOutputConn(this))                      // if _other action is not connected to this
                    {
                        return(false);
                    }

                    if (other.ActionState == LBActionStates.Inactive || other.ActionState == LBActionStates.Disabled)
                    {
                        return(false);
                    }

                    if (other.IsConditionalDeactivation && other.CheckTransferConditions(this, _transit, LBActionTransitDirection.Out) || !other.IsConditionalDeactivation)
                    {
                        return(true);
                    }
                }
                else
                {
                    if (_other.CanDeactivateAction())
                    {
                        return(true);
                    }
                }
            }
            else                                    // trying to transit from this to _other (OUT of this)
            {
                if (this.IsConditionalDeactivation) // if we need to check some conditions to deactvate
                {
                    if (!this.CheckTransferConditions(_other, _transit, _dir))
                    {
                        return(false);
                    }
                }

                if (_other is LBTransitiveAction)
                {
                    LBTransitiveAction other = (LBTransitiveAction)_other;

                    if (!other.HasInputConn(this))                      // if _other action is not connected to this
                    {
                        return(false);
                    }

                    if (_transit == LBActionTransitTypes.Switch && !HasOutputConn(_other))
                    {
                        return(false);
                    }

                    if (other.IsConditionalActivation && other.CheckTransferConditions(this, _transit, LBActionTransitDirection.In) || !other.IsConditionalActivation)
                    {
                        return(true);
                    }
                }
                else
                {
                    if (_transit == LBActionTransitTypes.Switch)
                    {
                        if (!CanSwitch(_other))
                        {
                            return(false);
                        }

                        if (_other.CanActivateAction())
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }