Exemple #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);
        }
Exemple #2
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);
        }