Inheritance: Generated.RuleCondition, ITextualExplain
        /// <summary>
        ///     Sets the update information for this rule condition (this rule condition updates source)
        /// </summary>
        /// <param name="source"></param>
        public override void SetUpdateInformation(ModelElement source)
        {
            base.SetUpdateInformation(source);
            RuleCondition sourceRuleCondition = (RuleCondition)source;

            foreach (Action action in Actions)
            {
                Action baseAction = sourceRuleCondition.FindAction(action.Name);
                if (baseAction != null)
                {
                    action.SetUpdateInformation(baseAction);
                }
            }

            foreach (PreCondition preCondition in PreConditions)
            {
                PreCondition basePreCondition = sourceRuleCondition.FindPreCondition(preCondition.Name);
                if (basePreCondition != null)
                {
                    preCondition.SetUpdateInformation(basePreCondition);
                }
            }

            foreach (Rule rule in SubRules)
            {
                Rule baseRule = sourceRuleCondition.FindRule(rule.Name);
                if (baseRule != null)
                {
                    rule.SetUpdateInformation(baseRule);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Updates (if possible) the initial state for this transition
        /// </summary>
        /// <param name="initialBox"></param>
        public void SetInitialBox(IGraphicalDisplay initialBox)
        {
            State initialState = (State)initialBox;

            if (Action != null)
            {
                if (PreCondition != null)
                {
                    if (PreCondition.Rule == Action.Rule)
                    {
                        List <State> states = StateMachine.GetStates(PreCondition.Expression);
                        if (states.Count == 1)
                        {
                            PreCondition.ExpressionText = "THIS == " + initialState.FullName;
                            Source = initialState;
                        }
                        else
                        {
                            throw new CannotChangeRuleException("More than one state in the pre condition expression");
                        }
                    }
                    else
                    {
                        throw new CannotChangeRuleException("Precondition is not at the same level as the action");
                    }
                }
                else
                {
                    RuleCondition ruleCondition = Action.Enclosing as RuleCondition;
                    if (ruleCondition != null)
                    {
                        Rule rule = ruleCondition.EnclosingRule;

                        if (EnclosingFinder <State> .find(rule) == Source)
                        {
                            if (rule.RuleConditions.Count == 1)
                            {
                                Source.StateMachine.removeRules(rule);
                                Source = initialState;
                                Source.StateMachine.appendRules(rule);
                            }
                            else
                            {
                                rule.removeConditions(ruleCondition);
                                Source = initialState;
                                Rule newRule = (Rule)acceptor.getFactory().createRule();
                                newRule.Name = rule.Name;
                                newRule.appendConditions(ruleCondition);
                                Source.StateMachine.appendRules(newRule);
                            }
                        }
                        else
                        {
                            throw new CannotChangeRuleException("Action is not defined directly in the state");
                        }
                    }
                }
            }
            Source = initialState;
        }
        private void addTransitionMenuItem_Click(object sender, EventArgs e)
        {
            if (StateMachine.States.Count > 1)
            {
                DataDictionary.ObjectFactory factory = (DataDictionary.ObjectFactory)DataDictionary.Generated.acceptor.getFactory();
                DataDictionary.Rules.Rule    rule    = (DataDictionary.Rules.Rule)factory.createRule();
                rule.Name = "Rule" + (StateMachine.Rules.Count + 1);

                DataDictionary.Rules.RuleCondition ruleCondition = (DataDictionary.Rules.RuleCondition)factory.createRuleCondition();
                ruleCondition.Name = "RuleCondition" + (rule.RuleConditions.Count + 1);
                rule.appendConditions(ruleCondition);

                DataDictionary.Rules.Action action = (DataDictionary.Rules.Action)factory.createAction();
                action.Expression = "THIS <- " + ((State)StateMachine.States[1]).LiteralName;
                ruleCondition.appendActions(action);

                if (MDIWindow.DataDictionaryWindow != null)
                {
                    DataDictionaryView.StateTreeNode stateNode = MDIWindow.DataDictionaryWindow.FindNode((State)StateMachine.States[0]) as DataDictionaryView.StateTreeNode;
                    DataDictionaryView.RuleTreeNode  ruleNode  = stateNode.Rules.AddRule(rule);
                }

                StateContainerPanel.RefreshControl();
                StateContainerPanel.Refresh();

                TransitionControl control = StateContainerPanel.getTransitionControl(ruleCondition);
                Select(control);
            }
        }
        public override RuleCondition createRuleCondition()
        {
            RuleCondition retVal = new Rules.RuleCondition();

            _defaultValueSetter.SetDefaultValue(retVal);

            return(retVal);
        }
        /// <summary>
        /// Updates (if possible) the initial state for this transition
        /// </summary>
        /// <param name="initialState"></param>
        public void SetInitialState(State initialState)
        {
            if (Action != null)
            {
                if (PreCondition != null)
                {
                    if (PreCondition.Rule == Action.Rule)
                    {
                        List <State> states = DataDictionary.Types.StateMachine.GetStates(PreCondition.ExpressionTree);
                        if (states.Count == 1)
                        {
                            PreCondition.ExpressionText = "THIS == " + initialState.FullName;
                            InitialState = initialState;
                        }
                        else
                        {
                            throw new CannotChangeRuleException("More than one state in the pre condition expression");
                        }
                    }
                    else
                    {
                        throw new CannotChangeRuleException("Precondition is not at the same level as the action");
                    }
                }
                else
                {
                    RuleCondition ruleCondition = Action.Enclosing as RuleCondition;
                    Rule          rule          = ruleCondition.EnclosingRule;

                    if (Utils.EnclosingFinder <Constants.State> .find(rule) == InitialState)
                    {
                        if (rule.RuleConditions.Count == 1)
                        {
                            InitialState.StateMachine.removeRules(rule);
                            InitialState = initialState;
                            InitialState.StateMachine.appendRules(rule);
                        }
                        else
                        {
                            rule.removeConditions(ruleCondition);
                            InitialState = initialState;
                            Rule newRule = (Rule)Generated.acceptor.getFactory().createRule();
                            newRule.Name = rule.Name;
                            newRule.appendConditions(ruleCondition);
                            InitialState.StateMachine.appendRules(newRule);
                        }
                    }
                    else
                    {
                        throw new CannotChangeRuleException("Action is not defined directly in the state");
                    }
                }
            }
            InitialState = initialState;
        }
Beispiel #6
0
            /// <summary>
            ///     Take care of all conditions
            /// </summary>
            /// <param name="obj"></param>
            /// <param name="visitSubNodes"></param>
            public override void visit(Generated.RuleCondition obj, bool visitSubNodes)
            {
                RuleCondition ruleCondition = (RuleCondition)obj;

                if (ruleCondition.Uses(Target))
                {
                    Usages.Add(ruleCondition);
                }

                base.visit(obj, visitSubNodes);
            }
        /// <summary>
        ///     Creates a default element
        /// </summary>
        /// <param name="enclosingCollection"></param>
        /// <returns></returns>
        public static RuleCondition CreateDefault(ICollection enclosingCollection)
        {
            RuleCondition retVal = (RuleCondition)acceptor.getFactory().createRuleCondition();

            Util.DontNotify(() =>
            {
                retVal.Name = "RuleCondition" + GetElementNumber(enclosingCollection);
            });

            return(retVal);
        }
Beispiel #8
0
        /// <summary>
        ///     Adds a model element in this model element
        /// </summary>
        /// <param name="element"></param>
        public override void AddModelElement(IModelElement element)
        {
            {
                RuleCondition item = element as RuleCondition;
                if (item != null)
                {
                    appendConditions(item);
                }
            }

            base.AddModelElement(element);
        }
Beispiel #9
0
        /// <summary>
        ///     Duplicates this model element
        /// </summary>
        /// <returns></returns>
        public Rule duplicate()
        {
            Rule retVal = (Rule)acceptor.getFactory().createRule();

            retVal.Name = Name;
            foreach (RuleCondition ruleCondition in RuleConditions)
            {
                RuleCondition newRuleCondition = ruleCondition.duplicate();
                retVal.appendConditions(newRuleCondition);
            }

            return(retVal);
        }
Beispiel #10
0
        /// <summary>
        ///     Sets the update information for this rule (this rule updates source)
        /// </summary>
        /// <param name="source"></param>
        public override void SetUpdateInformation(ModelElement source)
        {
            base.SetUpdateInformation(source);
            Rule sourceRule = (Rule)source;

            foreach (RuleCondition ruleCondition in RuleConditions)
            {
                RuleCondition baseRuleCondition = sourceRule.FindRuleCondition(ruleCondition.Name);
                if (baseRuleCondition != null)
                {
                    ruleCondition.SetUpdateInformation(baseRuleCondition);
                }
            }
        }
Beispiel #11
0
        /// <summary>
        ///     Creates a default element
        /// </summary>
        /// <param name="enclosingCollection"></param>
        /// <returns></returns>
        public static Rule CreateDefault(ICollection enclosingCollection)
        {
            Rule retVal = (Rule)acceptor.getFactory().createRule();

            Util.DontNotify(() =>
            {
                retVal.Name = "Rule" + GetElementNumber(enclosingCollection);

                RuleCondition condition = (RuleCondition)acceptor.getFactory().createRuleCondition();
                condition.Name          = "<Condition1>";
                retVal.appendConditions(condition);
            });

            return(retVal);
        }
Beispiel #12
0
        /// <summary>
        /// Duplicates this model element
        /// </summary>
        /// <returns></returns>
        public RuleCondition duplicate()
        {
            RuleCondition retVal = (RuleCondition)Generated.acceptor.getFactory().createRuleCondition();

            retVal.Name = Name;
            foreach (PreCondition preCondition in PreConditions)
            {
                PreCondition newPreCondition = preCondition.duplicate();
                retVal.appendPreConditions(newPreCondition);
            }
            foreach (Action action in Actions)
            {
                Action newAction = action.duplicate();
                retVal.appendActions(newAction);
            }

            return(retVal);
        }
Beispiel #13
0
 /// <summary>
 ///     Indicates whether a rule condition has been activated at a given time
 /// </summary>
 /// <param name="ruleCondition">The rule condition that should be activated</param>
 /// <param name="time">the time when the rule condition should be activated</param>
 /// <param name="variable">The variable impacted by this rule condition, if any</param>
 /// <returns>true if the corresponding rule condition has been activated at the time provided</returns>
 public bool RuleActivatedAtTime(RuleCondition ruleCondition, double time, IVariable variable)
 {
     return(EventTimeLine.RuleActivatedAtTime(ruleCondition, time, variable));
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="model"></param>
 public RuleConditionModelControl(ModelDiagramPanel panel, RuleCondition model)
     : base(panel, model)
 {
     BoxMode = BoxModeEnum.RoundedCorners;
     NormalColor = Color.LightBlue;
 }
 /// <summary>
 /// Indicates whether a rule condition has been activated at a given time
 /// </summary>
 /// <param name="ruleCondition">The rule condition that should be activated</param>
 /// <param name="time">the time when the rule condition should be activated</param>
 /// <param name="variable">The variable impacted by this rule condition, if any</param>
 /// <returns>true if the corresponding rule condition has been activated at the time provided</returns>
 public bool RuleActivatedAtTime(DataDictionary.Rules.RuleCondition ruleCondition, double time, Variables.IVariable variable)
 {
     return(EventTimeLine.RuleActivatedAtTime(ruleCondition, time, variable));
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="item"></param>
 /// <param name="buildSubNodes"></param>
 public ActionsTreeNode(RuleCondition item, bool buildSubNodes)
     : base(item, buildSubNodes, "Actions", false)
 {
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="ruleCondition">The rule condition which leads to this activation</param>
 /// <param name="instance">The instance on which this rule condition's preconditions are evaluated to true</param>
 /// <param name="explanation"></param>
 public Activation(RuleCondition ruleCondition, IModelElement instance, ExplanationPart explanation)
 {
     RuleCondition = ruleCondition;
     Instance = instance;
     Explanation = explanation;
 }
        /// <summary>
        ///     Indicates whether a rule condition has been activated at the time provided
        /// </summary>
        /// <param name="ruleCondition">The rule condition that should be activated</param>
        /// <param name="time">the time when the rule condition should be activated</param>
        /// <param name="variable">The variable impacted by this rule condition, if any</param>
        /// <returns>True if the provided rule condition has been activated</returns>
        public bool RuleActivatedAtTime(RuleCondition ruleCondition, double time, IVariable variable)
        {
            bool retVal = false;

            if (variable != null)
            {
                foreach (ModelEvent modelEvent in Events)
                {
                    RuleFired ruleFired = modelEvent as RuleFired;
                    if (modelEvent.Time == time && ruleFired != null)
                    {
                        if (ruleFired.RuleCondition == ruleCondition)
                        {
                            retVal = ruleFired.ImpactVariable(variable);

                            if (retVal)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return retVal;
        }
        public override RuleCondition createRuleCondition()
        {
            RuleCondition retVal = new Rules.RuleCondition();

            _defaultValueSetter.SetDefaultValue(retVal);

            return retVal;
        }
        public override void visit(Generated.RuleCondition obj, bool subNodes)
        {
            Rules.RuleCondition ruleCondition = obj as Rules.RuleCondition;

            if (ruleCondition != null)
            {
                try
                {
                    bool found = false;
                    ruleCondition.Messages.Clear();

                    foreach (Rules.PreCondition preCondition in ruleCondition.PreConditions)
                    {
                        Interpreter.BinaryExpression expression = checkExpression(preCondition, preCondition.Expression) as Interpreter.BinaryExpression;
                        if (expression != null)
                        {
                            if (expression.IsSimpleEquality())
                            {
                                Types.ITypedElement variable = expression.Left.Ref as Types.ITypedElement;
                                if (variable != null)
                                {
                                    if (variable.Type != null)
                                    {
                                        // Check that when preconditions are based on a request,
                                        // the corresponding action affects the value Request.Disabled to the same variable
                                        if (variable.Type.Name.Equals("Request") && expression.Right != null && expression.Right is Interpreter.UnaryExpression)
                                        {
                                            Values.IValue val2 = expression.Right.Ref as Values.IValue;
                                            if (val2 != null && "Response".CompareTo(val2.Name) == 0)
                                            {
                                                if (ruleCondition != null)
                                                {
                                                    found = false;
                                                    foreach (Rules.Action action in ruleCondition.Actions)
                                                    {
                                                        Variables.IVariable var = OverallVariableFinder.INSTANCE.findByName(action, preCondition.findVariable());
                                                        Interpreter.Statement.VariableUpdateStatement update = action.Modifies(var);
                                                        if (update != null)
                                                        {
                                                            Interpreter.UnaryExpression updateExpr = update.Expression as Interpreter.UnaryExpression;
                                                            if (updateExpr != null)
                                                            {
                                                                Values.IValue val3 = updateExpr.Ref as Values.IValue;
                                                                if (val3 != null && val3.Name.CompareTo("Disabled") == 0)
                                                                {
                                                                    found = true;
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }

                                                    if (!found)
                                                    {
                                                        preCondition.AddError("Rules where the Pre conditions is based on a Request type variable must assign that variable the value 'Request.Disabled'");
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // Check that the outgoing variables are not read
                                    if (variable.Mode == Generated.acceptor.VariableModeEnumType.aOutgoing)
                                    {
                                        if (ruleCondition.Reads(variable))
                                        {
                                            preCondition.AddError("An outgoing variable cannot be read");
                                        }
                                    }

                                    // Check that the incoming variables are not modified
                                    if (variable.Mode == Generated.acceptor.VariableModeEnumType.aIncoming)
                                    {
                                        if (ruleCondition.Modifies(variable) != null)
                                        {
                                            preCondition.AddError("An incoming variable cannot be written");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    ruleCondition.AddException(exception);
                }
            }

            base.visit(obj, subNodes);
        }
Beispiel #21
0
 /// <summary>
 ///     Indicates whether a rule condition has been activated at a given time
 /// </summary>
 /// <param name="ruleCondition">The rule condition that should be activated</param>
 /// <param name="time">the time when the rule condition should be activated</param>
 /// <param name="variable">The variable impacted by this rule condition, if any</param>
 /// <returns>true if the corresponding rule condition has been activated at the time provided</returns>
 public bool RuleActivatedAtTime(RuleCondition ruleCondition, double time, IVariable variable)
 {
     return EventTimeLine.RuleActivatedAtTime(ruleCondition, time, variable);
 }