Example #1
0
 /// <summary>
 /// Adds a model element in this model element
 /// </summary>
 /// <param name="copy"></param>
 public override void AddModelElement(Utils.IModelElement element)
 {
     {
         Rules.PreCondition item = element as Rules.PreCondition;
         if (item != null)
         {
             appendPreConditions(item);
         }
     }
 }
Example #2
0
        public override void visit(Generated.PreCondition obj, bool visitSubNodes)
        {
            Rules.PreCondition preCondition = (Rules.PreCondition)obj;

            if (Rebuild)
            {
                preCondition.ExpressionTree = null;
            }

            // Side effect : compiles or recompiles the expression
            DataDictionary.Interpreter.Expression expression = preCondition.ExpressionTree;

            base.visit(obj, visitSubNodes);
        }
Example #3
0
            /// <summary>
            /// Adds a transition in the transitions sets
            /// </summary>
            /// <param name="update">The update state which provides the target of the transition</param>
            /// <param name="target">The target state, as determined by the update statement</param>
            /// <param name="filteredOut"></param>
            /// <param name="preCondition">the precondition (if any) which is used to determine the initial state</param>
            /// <param name="initial">The initial state</param>
            /// <returns>true if the transition has been filtered out. A transition can be filtered out if the target state is equal to the initial state or the initial state is null
            /// </returns>
            private bool AddTransition(Interpreter.Statement.VariableUpdateStatement update, Constants.State target, Rules.PreCondition preCondition, Constants.State initial)
            {
                bool retVal = false;

                Constants.State initialState = StateMachine.StateInThisStateMachine(initial);
                // TargetState is the target state either in this state machine or in a sub state machine
                Constants.State targetState = StateMachine.StateInThisStateMachine(target);

                // Determine the rule condition (if any) related to this state machine
                Rules.RuleCondition condition = null;
                if (update != null)
                {
                    Rules.Action action = update.Root as Rules.Action;
                    condition = action.RuleCondition;
                }

                if (targetState != null || initialState != null)
                {
                    // This transition is about this state machine.
                    if (initialState != targetState && initialState != null)
                    {
                        // Check that the transition is not yet present
                        // This case can occur when the same RuleCondition references two different states
                        // in a substate machine. Only draws the transition once.
                        if (!findMatchingTransition(condition, initialState, targetState))
                        {
                            Transitions.Add(new Rules.Transition(preCondition, initialState, update, targetState));
                        }
                    }
                    else
                    {
                        if (initialState == initial)
                        {
                            retVal = true;
                        }
                    }
                }

                return(retVal);
            }
        /// <summary>
        /// Evaluates the boundaries associated to a specific preCondition
        /// </summary>
        /// <param name="context">The context used to evaluate the precondition and segment value</param>
        /// <param name="preCondition">The precondition to evaluate the range</param>
        /// <param name="parameter"></param>
        /// <returns></returns>
        private List <Graph.Segment> EvaluateBoundaries(Interpreter.InterpretationContext context, Rules.PreCondition preCondition, Parameter parameter)
        {
            List <Graph.Segment> retVal = new List <Graph.Segment>();

            if (parameter != null)
            {
                Interpreter.BinaryExpression expression = preCondition.ExpressionTree as Interpreter.BinaryExpression;
                if (ExpressionBasedOnParameter(parameter, expression))
                {
                    Values.IValue val;
                    if (expression.Right.Ref == parameter)
                    {
                        // Expression like xxx <= Parameter
                        val = expression.Left.GetValue(context);
                        switch (expression.Operation)
                        {
                        case Interpreter.BinaryExpression.OPERATOR.LESS:
                        case Interpreter.BinaryExpression.OPERATOR.LESS_OR_EQUAL:
                            retVal.Add(new Graph.Segment(getDoubleValue(val), double.MaxValue, new Graph.Segment.Curve()));
                            break;

                        case Interpreter.BinaryExpression.OPERATOR.GREATER:
                        case Interpreter.BinaryExpression.OPERATOR.GREATER_OR_EQUAL:
                            retVal.Add(new Graph.Segment(0, getDoubleValue(val), new Graph.Segment.Curve()));
                            break;

                        default:
                            throw new Exception("Invalid comparison operator while evaluating Graph of function");
                        }
                    }
                    else
                    {
                        if (expression.Left.Ref == parameter)
                        {
                            // Expression like Parameter <= xxx
                            val = expression.Right.GetValue(context);
                            switch (expression.Operation)
                            {
                            case Interpreter.BinaryExpression.OPERATOR.LESS:
                            case Interpreter.BinaryExpression.OPERATOR.LESS_OR_EQUAL:
                                retVal.Add(new Graph.Segment(0, getDoubleValue(val), new Graph.Segment.Curve()));
                                break;

                            case Interpreter.BinaryExpression.OPERATOR.GREATER:
                            case Interpreter.BinaryExpression.OPERATOR.GREATER_OR_EQUAL:
                                retVal.Add(new Graph.Segment(getDoubleValue(val), double.MaxValue, new Graph.Segment.Curve()));
                                break;

                            default:
                                throw new Exception("Invalid comparison operator while evaluating Graph of function");
                            }
                        }
                        else
                        {
                            if (FunctionCallOnParameter(expression.Right, parameter))
                            {
                                Graph graph = expression.Right.createGraph(context, parameter);
                                if (graph != null)
                                {
                                    // Expression like xxx <= f(Parameter)
                                    val    = expression.Left.GetValue(context);
                                    retVal = graph.GetSegments(Interpreter.BinaryExpression.Inverse(expression.Operation), getDoubleValue(val));
                                }
                                else
                                {
                                    AddError("Cannot create graph for " + expression.Right);
                                }
                            }
                            else
                            {
                                Graph graph = expression.Left.createGraph(context, parameter);
                                if (graph != null)
                                {
                                    // Expression like f(Parameter) <= xxx
                                    val    = expression.Right.GetValue(context);
                                    retVal = graph.GetSegments(expression.Operation, getDoubleValue(val));
                                }
                                else
                                {
                                    throw new Exception("Cannot evaluate bounds of segment");
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (!ExpressionBasedOnPlaceHolder(context, expression))
                    {
                        Values.BoolValue value = preCondition.ExpressionTree.GetValue(context) as Values.BoolValue;
                        if (value != null && value.Val)
                        {
                            retVal.Add(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve()));
                        }
                    }
                }
            }
            else
            {
                AddError("Parameter is null");
            }

            return(retVal);
        }