Наследование: Generated.Action
        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);
            }
        }
Пример #2
0
        public override Action createAction()
        {
            Action retVal = new Rules.Action();

            _defaultValueSetter.SetDefaultValue(retVal);

            return(retVal);
        }
Пример #3
0
        /// <summary>
        ///     Handles a drop event
        /// </summary>
        /// <param name="sourceNode"></param>
        public override void AcceptDrop(BaseTreeNode sourceNode)
        {
            ActionTreeNode actionTreeNode = sourceNode as ActionTreeNode;

            if (actionTreeNode != null)
            {
                if (
                    MessageBox.Show("Are you sure you want to move the corresponding action ?", "Move action",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Action action = actionTreeNode.Item;
                    actionTreeNode.Delete();
                    Item.appendActions(action);
                    Item.setVerified(false);
                }
            }
        }
Пример #4
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(VariableUpdateStatement update, State target, PreCondition preCondition,
                                       State initial)
            {
                bool retVal = false;

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

                    // Determine the rule condition (if any) related to this state machine
                    Rules.RuleCondition condition = null;
                    if (update != null)
                    {
                        Action action = update.Root as 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 Transition(preCondition, initialState, update, targetState));
                            }
                        }
                        else
                        {
                            if (initialState == initial)
                            {
                                retVal = true;
                            }
                        }
                    }
                }

                return(retVal);
            }
Пример #5
0
        /// <summary>
        ///     Computes the changes related to this event
        /// </summary>
        /// <param name="apply">Indicates that the changes should be applied directly</param>
        /// <param name="runner"></param>
        public override bool ComputeChanges(bool apply, Runner runner)
        {
            bool retVal = base.ComputeChanges(apply, runner);

            if (retVal)
            {
                if (runner.Explain)
                {
                    Explanation = new ExplanationPart(Action, "Action ", Action);
                }

                InterpretationContext context = new InterpretationContext(Instance);
                Changes = new ChangeList();
                Action.GetChanges(context, Changes, Explanation, apply, runner);
                Changes.CheckChanges(Action);
            }

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

            if (action != null)
            {
                try
                {
                    action.Messages.Clear();
                    if (!action.Expression.Contains('%'))
                    {
                        Interpreter.Statement.Statement statement = checkStatement(action, action.Expression);
                    }
                }
                catch (Exception exception)
                {
                    action.AddException(exception);
                }
            }

            base.visit(obj, subNodes);
        }
Пример #7
0
        /// <summary>
        ///     Applies a specific statement on the model
        /// </summary>
        /// <param name="statementText"></param>
        public void ApplyStatement(string statementText)
        {
            EfsAccess.WaitOne();
            try
            {
                if (Runner != null)
                {
                    const bool silent = true;
                    using (Parser parser = new Parser())
                    {
                        Statement statement = parser.Statement(EfsSystem.Instance.Dictionaries[0],
                                                               statementText, silent);

                        if (statement != null)
                        {
                            Util.DontNotify(() =>
                            {
                                Runner.CacheImpact            = new CacheImpact();
                                Action action                 = (Action)acceptor.getFactory().createAction();
                                action.ExpressionText         = statementText;
                                VariableUpdate variableUpdate = new VariableUpdate(action, null, null);
                                Runner.EventTimeLine.AddModelEvent(variableUpdate, true);
                                Runner.ClearCaches();
                            });
                        }
                    }
                }
            }
            catch (Exception)
            {
                // TODO
            }
            finally
            {
                EfsAccess.ReleaseMutex();
            }
        }
Пример #8
0
        public void AddTransitionHandler(object sender, EventArgs args)
        {
            SelectStartAndTargetStateForTransition dialog = new SelectStartAndTargetStateForTransition();

            dialog.SetStateMachine(Item.EnclosingStateMachine, Item);
            dialog.ShowDialog(GuiUtils.MdiWindow);

            if (dialog.OkCkicked)
            {
                State sourceState = Item.EnclosingStateMachine.FindState(dialog.StartStateName);
                if (sourceState != null)
                {
                    Rule rule = Rule.CreateDefault(sourceState.StateMachine.Rules);
                    sourceState.StateMachine.appendRules(rule);
                    RuleCondition ruleCondition = (RuleCondition)rule.RuleConditions[0];

                    Action action = Action.CreateDefault(ruleCondition.Actions);
                    action.ExpressionText = "THIS <- " + dialog.EndStateName;
                    ruleCondition.appendActions(action);

                    RefreshModel.Execute();
                }
            }
        }
Пример #9
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="action">The action which raised the variable update></param>
 public VariableUpdate(Action action, IModelElement instance, acceptor.RulePriority?priority)
     : base(action.ExpressionText, instance, priority)
 {
     Action = action;
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="action" The action which raised the variable update></param>
 public VariableUpdate(Action action, IModelElement instance, acceptor.RulePriority? priority)
     : base(action.ExpressionText, instance, priority)
 {
     Action = action;
 }
Пример #11
0
        public override Action createAction()
        {
            Action retVal = new Rules.Action();

            _defaultValueSetter.SetDefaultValue(retVal);

            return retVal;
        }
Пример #12
0
            /// <summary>
            ///     Check if this rule corresponds to a transition for this state machine
            /// </summary>
            /// <param name="obj"></param>
            /// <param name="visitSubNodes"></param>
            public override void visit(RuleCondition obj, bool visitSubNodes)
            {
                Rules.RuleCondition ruleCondition = (Rules.RuleCondition)obj;

                foreach (Action action in ruleCondition.Actions)
                {
                    try
                    {
                        foreach (VariableUpdateStatement update in action.UpdateStatements)
                        {
                            Type targetType = update.TargetType;
                            if (targetType is StateMachine)
                            {
                                Expression expressionTree = update.Expression;
                                if (expressionTree != null)
                                {
                                    // HaCK: This is a bit rough, but should be sufficient for now...
                                    foreach (State stt1 in GetStates(expressionTree))
                                    {
                                        // TargetState is the target state either in this state machine or in a sub state machine
                                        State targetState = StateMachine.StateInThisStateMachine(stt1);

                                        int  transitionCount = Transitions.Count;
                                        bool filteredOut     = false;

                                        // Finds the enclosing state of this action to determine the source state of this transition
                                        State enclosingState = EnclosingFinder <State> .find(action);

                                        if (enclosingState != null)
                                        {
                                            filteredOut = filteredOut ||
                                                          AddTransition(update, stt1, null, enclosingState);
                                        }

                                        if (!filteredOut)
                                        {
                                            foreach (PreCondition preCondition in ruleCondition.AllPreConditions)
                                            {
                                                // A transition from one state to another has been found
                                                foreach (State stt2 in GetStates(preCondition.Expression))
                                                {
                                                    filteredOut = filteredOut ||
                                                                  AddTransition(update, stt1, preCondition, stt2);
                                                }
                                            }
                                        }

                                        if (Transitions.Count == transitionCount)
                                        {
                                            if (targetState == stt1 && targetState.EnclosingStateMachine == StateMachine)
                                            {
                                                if (!filteredOut)
                                                {
                                                    Action enclosingAction = update.Root as Action;

                                                    if (enclosingAction != null)
                                                    {
                                                        // No precondition could be found => one can reach this state at anytime
                                                        if (
                                                            !findMatchingTransition(enclosingAction.RuleCondition, null,
                                                                                    targetState))
                                                        {
                                                            Transitions.Add(new Transition(null, null, update,
                                                                                           targetState));
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    action.AddError("Cannot parse expression");
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }

                base.visit(obj, visitSubNodes);
            }
Пример #13
0
 public void AddHandler(object sender, EventArgs args)
 {
     Item.appendActions(Action.CreateDefault(Item.Actions));
     Item.setVerified(false);
 }
Пример #14
0
        /// <summary>
        ///     Method used to create a box
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public override BoxControl <IModelElement, IGraphicalDisplay, ModelArrow> CreateBox(IGraphicalDisplay model)
        {
            ModelControl retVal = null;

            NameSpace nameSpace = model as NameSpace;

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (retVal == null && nameSpace != null)
            {
                retVal = new NameSpaceModelControl(this, nameSpace);
            }

            Variable variable = model as Variable;

            if (retVal == null && variable != null)
            {
                retVal = new VariableModelControl(this, variable);
            }

            Function function = model as Function;

            if (retVal == null && function != null)
            {
                retVal = new FunctionModelControl(this, function);
            }

            Parameter parameter = model as Parameter;

            if (retVal == null && parameter != null)
            {
                retVal = new ParameterModelControl(this, parameter);
            }

            Case cas = model as Case;

            if (retVal == null && cas != null)
            {
                retVal = new CaseModelControl(this, cas);
            }

            PreCondition preCondition = model as PreCondition;

            if (retVal == null && preCondition != null)
            {
                retVal = new PreConditionModelControl(this, preCondition);
            }

            Procedure procedure = model as Procedure;

            if (procedure != null)
            {
                retVal = new ProcedureModelControl(this, procedure);
            }

            Range range = model as Range;

            if (range != null)
            {
                retVal = new RangeModelControl(this, range);
            }

            Enum enumeration = model as Enum;

            if (enumeration != null)
            {
                retVal = new EnumModelControl(this, enumeration);
            }

            EnumValue value = model as EnumValue;

            if (value != null)
            {
                retVal = new EnumValueModelControl(this, value);
            }

            Collection collection = model as Collection;

            if (collection != null)
            {
                retVal = new CollectionModelControl(this, collection);
            }

            StateMachine stateMachine = model as StateMachine;

            if (stateMachine != null)
            {
                retVal = new StateMachineModelControl(this, stateMachine);
            }

            Structure structure = model as Structure;

            if (structure != null)
            {
                if (structure.IsAbstract)
                {
                    retVal = new InterfaceModelControl(this, structure);
                }
                else
                {
                    retVal = new StructureModelControl(this, structure);
                }
            }

            StructureElement element = model as StructureElement;

            if (element != null)
            {
                retVal = new StructureElementModelControl(this, element);
            }

            Rule rule = model as Rule;

            if (rule != null)
            {
                retVal = new RuleModelControl(this, rule);
            }

            RuleCondition ruleCondition = model as RuleCondition;

            if (ruleCondition != null)
            {
                retVal = new RuleConditionModelControl(this, ruleCondition);
            }

            Action action = model as Action;

            if (action != null)
            {
                retVal = new ActionModelControl(this, action);
            }

            return(retVal);
        }
Пример #15
0
        /// <summary>
        /// Checks the compatibility of all updates
        /// </summary>
        /// <param name="variableUpdates"></param>
        public void CheckUpdatesCompatibility(IEnumerable <VariableUpdate> variableUpdates)
        {
            if (CheckForCompatibleChanges)
            {
                // Holds all changes that have already been processed
                Dictionary <IVariable, Change>      changes   = new Dictionary <IVariable, Change>();
                Dictionary <Change, VariableUpdate> traceBack = new Dictionary <Change, VariableUpdate>();

                foreach (VariableUpdate variableUpdate in variableUpdates)
                {
                    Action action = variableUpdate.Action;

                    ChangeList actionChanges = variableUpdate.Changes;
                    if (variableUpdate.Action.Statement is ProcedureCallStatement)
                    {
                        Dictionary <IVariable, Change> procedureChanges = new Dictionary <IVariable, Change>();

                        foreach (Change change in variableUpdate.Changes.Changes)
                        {
                            procedureChanges[change.Variable] = change;
                        }

                        actionChanges = new ChangeList();
                        foreach (Change change in procedureChanges.Values)
                        {
                            actionChanges.Add(change, false, this);
                        }
                    }

                    foreach (Change change in actionChanges.Changes)
                    {
                        IVariable variable = change.Variable;
                        if (changes.ContainsKey(change.Variable))
                        {
                            Change otherChange = changes[change.Variable];
                            Action otherAction = traceBack[otherChange].Action;
                            if (!variable.Type.CompareForEquality(otherChange.NewValue, change.NewValue))
                            {
                                if (change.CheckForCompatibility() || otherChange.CheckForCompatibility())
                                {
                                    string action1 = ((INamable)action.Enclosing).FullName + " : " +
                                                     variableUpdate.Action.FullName;
                                    string action2 = ((INamable)otherAction.Enclosing).FullName + " : " +
                                                     traceBack[otherChange].Action.FullName;
                                    variableUpdate.Action.AddError(
                                        "Simultaneous change of the variable " + variable.FullName +
                                        " with different values. Conflit between\n" +
                                        action1 + "\n and \n" + action2);
                                    action.AddError("Conflicting change");
                                    otherAction.AddError("Conflicting change");
                                }
                            }
                        }
                        else
                        {
                            changes.Add(change.Variable, change);
                            traceBack.Add(change, variableUpdate);
                        }
                    }
                }
            }
        }
Пример #16
0
 /// <summary>
 ///     Adds an action
 /// </summary>
 public void AddActionHandler(object sender, EventArgs args)
 {
     Item.appendActions(Action.CreateDefault(Item.Actions));
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="model"></param>
 public ActionModelControl(ModelDiagramPanel panel, Action model)
     : base(panel, model)
 {
 }