/// <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; }
/// <summary> /// Provides the name of this model element when accessing it from the other model element (provided as parameter) /// </summary> /// <param name="user">The user of this element</param> /// <returns></returns> public virtual string ReferenceName(ModelElement user) { string retVal = Name; ModelElement current = Enclosing as ModelElement; bool validName = CheckNewName(user, retVal); while (current != null && !(current is Dictionary) && current != user && !validName) { StateMachine enclosingStateMachine = current as StateMachine; if (enclosingStateMachine != null && enclosingStateMachine.EnclosingStateMachine != null) { // Ignore state machines because they have the same name as their enclosing state // This is not true for the first state machine in the chain (no enclosing state) } else { retVal = current.Name + "." + retVal; validName = CheckNewName(user, retVal); } current = current.Enclosing as ModelElement; } return(retVal); }
/// <summary> /// Accepts drop of a tree node, in a drag & drop operation /// </summary> /// <param name="SourceNode"></param> public override void AcceptDrop(BaseTreeNode SourceNode) { base.AcceptDrop(SourceNode); if (SourceNode is StateMachineTreeNode) { StateMachineTreeNode stateMachineTreeNode = SourceNode as StateMachineTreeNode; DataDictionary.Types.StateMachine stateMachine = stateMachineTreeNode.Item; stateMachineTreeNode.Delete(); AddStateMachine(stateMachine); } else if (SourceNode is SpecificationView.ParagraphTreeNode) { SpecificationView.ParagraphTreeNode node = SourceNode as SpecificationView.ParagraphTreeNode; DataDictionary.Specification.Paragraph paragaph = node.Item; DataDictionary.Types.StateMachine stateMachine = (DataDictionary.Types.StateMachine)DataDictionary.Generated.acceptor.getFactory().createStateMachine(); stateMachine.Name = paragaph.Name; DataDictionary.ReqRef reqRef = (DataDictionary.ReqRef)DataDictionary.Generated.acceptor.getFactory().createReqRef(); reqRef.Name = paragaph.FullId; stateMachine.appendRequirements(reqRef); AddStateMachine(stateMachine); } }
/// <summary> /// Creates a copy of the rule in the designated dictionary. The namespace structure is copied over. /// The new rule is set to update this one. /// </summary> /// <param name="dictionary">The target dictionary of the copy</param> /// <returns></returns> public Rule CreateRuleUpdate(Dictionary dictionary) { Rule retVal = (Rule)Duplicate(); retVal.SetUpdateInformation(this); retVal.ClearAllRequirements(); String[] names = FullName.Split('.'); names = names.Take(names.Count() - 1).ToArray(); if (Enclosing is NameSpace) { NameSpace nameSpace = dictionary.GetNameSpaceUpdate(names, Dictionary); nameSpace.appendRules(retVal); } else { String[] nameSpaceRef = names.Take(names.Count() - 1).ToArray(); if (EnclosingStateMachine != null) { StateMachine stateMachine = EnclosingStateMachine.CreateSubStateMachineUpdate(dictionary); stateMachine.appendRules(retVal); } else if (EnclosingStructure != null) { NameSpace nameSpace = dictionary.GetNameSpaceUpdate(nameSpaceRef, Dictionary); Structure structure = nameSpace.GetStructureUpdate(names.Last(), (NameSpace)nameSpace.Updates); structure.appendRules(retVal); } } return(retVal); }
public void TestDifferentiationOfSubStatesWithSameName() { Dictionary dictionary = CreateDictionary("Test"); NameSpace nameSpace = CreateNameSpace(dictionary, "NameSpace"); StateMachine stateMachine = CreateStateMachine(nameSpace, "StateMachine"); // The left branch State state1 = CreateState(stateMachine, "State1"); State subState1 = CreateState(state1.StateMachine, "SubState"); // The right branch State state2 = CreateState(stateMachine, "State2"); State subState2 = CreateState(state2.StateMachine, "SubState"); Variable stateVariable = CreateVariable(nameSpace, "Variable", "StateMachine"); stateVariable.Default = "StateMachine.State1.SubState"; Compiler.Compile_Synchronous(true); Expression expression = new Parser().Expression(dictionary, "NameSpace.Variable in [NameSpace.StateMachine.State2.SubState]"); IValue value = expression.GetExpressionValue(new InterpretationContext(), null); Assert.AreEqual(System.BoolType.False, value); }
/// <summary> /// Creates a state in the state machine provided /// </summary> /// <param name="enclosing"></param> /// <param name="name"></param> /// <returns></returns> protected State CreateState(StateMachine enclosing, string name) { State retVal = (State)Factory.createState(); enclosing.appendStates(retVal); retVal.Name = name; return(retVal); }
/// <summary> /// Ensures that all update information for this state (and sub-states) is removed /// </summary> public override void RecoverUpdateInformation() { base.RecoverUpdateInformation(); if (StateMachine != null) { StateMachine.RecoverUpdateInformation(); } }
/// <summary> /// Creates a rule and a rule condition in the state machine /// </summary> /// <param name="enclosing"></param> /// <param name="name"></param> /// <returns></returns> protected RuleCondition CreateRuleAndCondition(StateMachine enclosing, string name) { Rule rule = (Rule)Factory.createRule(); enclosing.appendRules(rule); rule.Name = name; return(CreateRuleCondition(rule, name)); }
/// <summary> /// Adds a new state machine /// </summary> /// <param name="collection"></param> public StateMachineTreeNode AddStateMachine(DataDictionary.Types.StateMachine stateMachine) { StateMachineTreeNode retVal = new StateMachineTreeNode(stateMachine); Item.appendStateMachines(stateMachine); Nodes.Add(retVal); SortSubNodes(); return(retVal); }
public void Constants(string scope, Dictionary <string, object> retVal) { string name = Utils.Util.concat(scope, Name); retVal[name] = this; if (StateMachine != null) { StateMachine.Constants(name, retVal); } }
public void AddHandler(object sender, EventArgs args) { DataDictionaryTreeView treeView = BaseTreeView as DataDictionaryTreeView; if (treeView != null) { DataDictionary.Types.StateMachine stateMachine = (DataDictionary.Types.StateMachine)DataDictionary.Generated.acceptor.getFactory().createStateMachine(); stateMachine.Name = "<StateMachine" + (GetNodeCount(false) + 1) + ">"; AddStateMachine(stateMachine); } }
/// <summary> /// Duplicates this model element /// </summary> /// <returns></returns> public State duplicate() { State retVal = (State)acceptor.getFactory().createState(); retVal.Name = Name; retVal.X = X; retVal.Y = Y; retVal.Width = Width; retVal.Height = Height; retVal.setFather(getFather()); retVal.StateMachine = StateMachine.instanciate(); return(retVal); }
/// <summary> /// Adds information about a state machine /// </summary> /// <param name="aSM">The state machine</param> /// <param name="addDetails">Add details or simply enumerate the state machines</param> private void AddStateMachineSection(StateMachine aSM, bool addDetails) { string name = aSM.FullName; if (name == "" && aSM.EnclosingState != null) { name = aSM.EnclosingState.FullName; } AddSubParagraph(name); AddTable(new string[] { "State machine " + name }, new int[] { 20, 40, 80 }); AddRow(aSM.Comment); if (aSM.States.Count > 0) { AddRow("States", "Name", "Comment"); Row firstRow = lastRow; firstRow.Shading.Color = Colors.LightBlue; foreach (State state in aSM.States) { string comment = ""; if (aSM.Default.Equals(state.Name)) { comment = "Initial state"; } if (AddRow("", state.Name, comment) != null) { firstRow.Cells[0].MergeDown += 1; } else { throw new Exception("Tried to add an empty row in model report"); } } } if (CountDisplayedReqRelated(aSM.Rules) > 0) { CreateRulesSection(aSM.Rules, addDetails, true); } CreateStatusTable(aSM); CloseSubParagraph(); foreach (State state in aSM.States) { if (state.StateMachine != null && considerReqRelated(state.StateMachine)) { AddStateMachineSection(state.StateMachine, addDetails); } } }
/// <summary> /// Sets the update information for this state (this state updates source) /// </summary> /// <param name="source"></param> public override void SetUpdateInformation(ModelElement source) { base.SetUpdateInformation(source); State sourceState = (State)source; if (getStateMachine() != null) { StateMachine baseSataStateMachine = sourceState.StateMachine; if (baseSataStateMachine != null) { StateMachine.SetUpdateInformation(baseSataStateMachine); } } }
public StandardValuesCollection GetValues(DataDictionary.Types.StateMachine StateMachine) { Utils.FinderRepository.INSTANCE.ClearCache(); List <string> retVal = new List <string>(); foreach (DataDictionary.Constants.State subState in StateMachine.States) { retVal.Add(subState.Name); } retVal.Sort(); return(new StandardValuesCollection(retVal)); }
/// <summary> /// Creates a section for an (implemented) state machine /// </summary> /// <param name="section">Section to which the new section will be added</param> /// <param name="aSM">The state machine</param> private void AddStateMachineSection(DataDictionary.Types.StateMachine aSM) { AddSubParagraph(aSM.FullName); AddTable(new string[] { "State machine " + aSM.FullName }, new int[] { 30, 30, 80 }); AddRow(aSM.Comment); if (aSM.States.Count > 0) { AddRow("States", "Name", "Comment"); Row firstRow = lastRow; firstRow.Shading.Color = Colors.LightBlue; foreach (DataDictionary.Constants.State state in aSM.States) { string comment = ""; if (aSM.InitialState.Equals(state.Name)) { comment = "Initial state"; } AddRow("", state.Name, comment); firstRow.Cells[0].MergeDown += 1; } } if (countDisplayedReqRelated(aSM.Rules) > 0) { AddTableHeader("Rules"); foreach (DataDictionary.Rules.Rule rule in aSM.Rules) { if (rule.ImplementationPartiallyCompleted == true) { AddRuleRow(rule, true); } } } CreateStatusTable(aSM); CloseSubParagraph(); foreach (DataDictionary.Constants.State state in aSM.States) { if (state.StateMachine != null) { if (state.StateMachine.ImplementationPartiallyCompleted) { AddStateMachineSection(state.StateMachine); } } } }
/// <summary> /// Brings the model element from an update dictionary to the updated dictionary /// </summary> public virtual void Merge() { ModelElement target = Updates; if (target == null) { // Copy element to parent ModelElement parent = Enclosing as ModelElement; if (parent != null) { NameSpace parentNameSpace = parent.Updates as NameSpace; if (parentNameSpace != null) { parentNameSpace.AddModelElement(Duplicate()); } Paragraph parentParagraph = parent.Updates as Paragraph; if (parentParagraph != null) { parentParagraph.AddModelElement(Duplicate()); } Structure parentStructure = parent.Updates as Structure; if (parentStructure != null) { parentStructure.AddModelElement(Duplicate()); } StateMachine parentStateMachine = parent.Updates as StateMachine; if (parentStateMachine != null) { parentStateMachine.AddModelElement(Duplicate()); } } } else { if (!IsRemoved) { target.UpdateModelElementAccordingToSource(this); } else { target.Delete(); } } }
/// <summary> /// Setups the combo boxes according to the state machine and (optionally start and end states) /// </summary> /// <param name="stateMachine"></param> /// <param name="initialState"></param> /// <param name="endState"></param> public void SetStateMachine(StateMachine stateMachine, State initialState = null, State endState = null) { startStatesComboBox.Items.Clear(); endStatesComboBox.Items.Clear(); foreach (State state in stateMachine.States) { startStatesComboBox.Items.Add(state.Name); endStatesComboBox.Items.Add(state.Name); } if (initialState != null) { startStatesComboBox.Text = initialState.Name; } if (endState != null) { endStatesComboBox.Text = endState.Name; } }
/// <summary> /// Setups the combo boxes according to the state machine and (optionally start and end states) /// </summary> /// <param name="stateMachine"></param> /// <param name="initialState"></param> /// <param name="endState"></param> public void SetStateMachine(StateMachine stateMachine, State initialState = null, State endState = null) { startStatesComboBox.Items.Clear(); endStatesComboBox.Items.Clear(); foreach (State state in stateMachine.States) { startStatesComboBox.Items.Add(state.Name); endStatesComboBox.Items.Add(state.Name); } if (initialState != null) { startStatesComboBox.Text = initialState.Name; } if (endState != null) { endStatesComboBox.Text = endState.Name; } }
/// <summary> /// Try to find a rule, in this state machine, or in a sub state machine /// which /// </summary> /// <param name="activations"></param> /// <param name="priority">The priority when this evaluation occurs</param> /// <param name="currentStateVariable">The variable which holds the current state of the procedure</param> /// <param name="explanation">The explanation part to be filled</param> private void EvaluateStateMachine(HashSet <Activation> activations, acceptor.RulePriority priority, IVariable currentStateVariable, ExplanationPart explanation) { if (currentStateVariable != null) { State currentState = currentStateVariable.Value as State; if (currentState != null) { StateMachine currentStateMachine = currentState.StateMachine; while (currentStateMachine != null) { foreach (Rules.Rule rule in currentStateMachine.Rules) { rule.Evaluate(this, priority, currentStateVariable, activations, explanation); } currentStateMachine = currentStateMachine.EnclosingStateMachine; } } } }
/// <summary> /// Creates a copy of the state in the designated dictionary. The namespace structure is copied over. /// The new state is set to update this one. /// </summary> /// <param name="dictionary">The target dictionary of the copy</param> /// <returns></returns> public State CreateStateUpdate(Dictionary dictionary) { State retVal = (State)acceptor.getFactory().createState(); retVal.Name = Name; retVal.SetUpdateInformation(this); // Find the update for the enclosing state machine to add retVal to StateMachine enclosingSmUpdate = EnclosingStateMachine.CreateSubStateMachineUpdate(dictionary); enclosingSmUpdate.States.Add(retVal); retVal.setFather(enclosingSmUpdate); // If retVal is the first state added to the enclosing state machine update, it is the initial state if (enclosingSmUpdate.States.Count == 1) { enclosingSmUpdate.Default = retVal.Name; } return(retVal); }
/// <summary> /// Handles the drop event /// </summary> /// <param name="SourceNode"></param> public override void AcceptDrop(BaseTreeNode SourceNode) { if (SourceNode is StateMachineTreeNode) { if (MessageBox.Show("Are you sure you want to override the state machine ? ", "Override state machine", MessageBoxButtons.OKCancel) == DialogResult.OK) { StateMachineTreeNode stateMachineTreeNode = (StateMachineTreeNode)SourceNode; DataDictionary.Types.StateMachine stateMachine = stateMachineTreeNode.Item; stateMachineTreeNode.Delete(); // Update the model Item.StateMachine = stateMachine; // Update the view TreeNode parent = Parent; parent.Nodes.Remove(this); parent.Nodes.Add(stateMachineTreeNode); } } base.AcceptDrop(SourceNode); }
public override void visit(Generated.StateMachine obj, bool visitSubNodes) { DataDictionary.Types.StateMachine stateMachine = (DataDictionary.Types.StateMachine)obj; if (stateMachine != null) { stateMachine.Messages.Clear(); if (stateMachine.AllValues.Count > 0) { if (Utils.Utils.isEmpty(stateMachine.InitialState)) { stateMachine.AddError("Empty initial state"); } if (stateMachine.DefaultValue == null) { stateMachine.AddError("Cannot find default value"); } } } base.visit(obj, visitSubNodes); }
/// <summary> /// Creates a state in the state machine provided /// </summary> /// <param name="enclosing"></param> /// <param name="name"></param> /// <returns></returns> protected State CreateState(StateMachine enclosing, string name) { State retVal = (State) Factory.createState(); enclosing.appendStates(retVal); retVal.Name = name; return retVal; }
/// <summary> /// Creates a rule and a rule condition in the state machine /// </summary> /// <param name="enclosing"></param> /// <param name="name"></param> /// <returns></returns> protected RuleCondition CreateRuleAndCondition(StateMachine enclosing, string name) { Rule rule = (Rule) Factory.createRule(); enclosing.appendRules(rule); rule.Name = name; return CreateRuleCondition(rule, name); }
/// <summary> /// Merges this state, combining the state machine with the base /// </summary> public override void Merge() { StateMachine.Merge(); base.Merge(); }
/// <summary> /// Ensures that the element is used somewhere /// </summary> /// <param name="model"></param> private void checkUsage(ModelElement model) { List <Usage> references; Type type = model as Type; if (type != null && !(type is ICallable)) { bool checkType = true; StateMachine stateMachine = type as StateMachine; if (stateMachine != null) { checkType = stateMachine.EnclosingStateMachine == null; } if (checkType) { references = EfsSystem.Instance.FindReferences(type); if (references.Count == 0) { model.AddWarning("Type is declared but never used"); } } } else { IVariable variable = model as IVariable; if (variable != null) { references = EfsSystem.Instance.FindReferences(variable as ModelElement); bool read = false; bool written = variable.Mode == acceptor.VariableModeEnumType.aConstant; foreach (Usage usage in references) { switch (usage.Mode) { case Usage.ModeEnum.Read: read = true; break; case Usage.ModeEnum.Write: written = true; break; case Usage.ModeEnum.ReadAndWrite: read = true; written = true; break; default: break; } } if (!read && !written) { model.AddWarning("Variable is never read nor written"); } else { if (!read) { model.AddWarning("Variable is never read"); } if (!written) { model.AddWarning("Variable is never written"); } } } else { ICallable callable = model as ICallable; if (callable != null) { references = EfsSystem.Instance.FindReferences(callable as ModelElement); bool called = false; foreach (Usage usage in references) { switch (usage.Mode) { case Usage.ModeEnum.Call: called = true; break; } } if (!called) { model.AddWarning("Function or procedure is never called"); } } } } }
/// <summary> /// Adds a new state machine /// </summary> /// <param name="stateMachine"></param> /// <returns>the corresponding node</returns> public StateMachineTreeNode AddStateMachine(DataDictionary.Types.StateMachine stateMachine) { return(stateMachines.AddStateMachine(stateMachine)); }
/// <summary> /// Adds information about a state machine /// </summary> /// <param name="aSM">The state machine</param> /// <param name="addDetails">Add details or simply enumerate the state machines</param> private void AddStateMachineSection(StateMachine aSM, bool addDetails) { string name = aSM.FullName; if (name == "" && aSM.EnclosingState != null) { name = aSM.EnclosingState.FullName; } AddSubParagraph(name); AddTable(new string[] {"State machine " + name}, new int[] {20, 40, 80}); AddRow(aSM.Comment); if (aSM.States.Count > 0) { AddRow("States", "Name", "Comment"); Row firstRow = lastRow; firstRow.Shading.Color = Colors.LightBlue; foreach (State state in aSM.States) { string comment = ""; if (aSM.Default.Equals(state.Name)) { comment = "Initial state"; } if (AddRow("", state.Name, comment) != null) { firstRow.Cells[0].MergeDown += 1; } else { Log.Error("Error: tried to add an empty row in model report"); } } } if (CountDisplayedReqRelated(aSM.Rules) > 0) { CreateRulesSection(aSM.Rules, addDetails, true); } CreateStatusTable(aSM); CloseSubParagraph(); foreach (State state in aSM.States) { if (state.StateMachine != null && considerReqRelated(state.StateMachine)) { AddStateMachineSection(state.StateMachine, addDetails); } } }
/// <summary> /// Initialises the declared elements /// </summary> public void InitDeclaredElements() { StateMachine.InitDeclaredElements(); }
/// <summary> /// Adds a model element in this model element /// </summary> /// <param name="element"></param> public override void AddModelElement(IModelElement element) { StateMachine.AddModelElement(element); }
/// <summary> /// Appends the INamable which match the name provided in retVal /// </summary> /// <param name="name"></param> /// <param name="retVal"></param> public void Find(string name, List <INamable> retVal) { StateMachine.Find(name, retVal); }