// Use this for initialization void Start() { state = Constants.State.None; deltaScale = new Vector3(0.01f, 0.01f, 0.01f); originalScale = transform.localScale; distanceSet = false; }
/// <summary> /// Provides the states used in an expression /// </summary> /// <param name="expression"></param> /// <returns></returns> public static List <Constants.State> GetStates(Interpreter.Expression expression) { List <Constants.State> retval = new List <Constants.State>(); if (expression != null) { foreach (Values.IValue value in expression.GetLiterals()) { Constants.State state = value as Constants.State; if (state != null) { retval.Add(state); } } Interpreter.Call call = expression as Interpreter.Call; if (call != null) { Functions.Function function = call.Called.getStaticCallable() as Functions.Function; if (function != null) { foreach (Values.IValue value in function.GetLiterals()) { Constants.State state = value as Constants.State; if (state != null) { retval.Add(state); } } } } } return(retval); }
/// <summary> /// Constructor /// </summary> /// <param name="stateMachine"></param> public TransitionFinder(StateMachine stateMachine) { Utils.FinderRepository.INSTANCE.ClearCache(); Transitions.Clear(); StateMachine = stateMachine; Constants.State initialState = StateMachine.DefaultValue as Constants.State; if (initialState != null) { Transitions.Add(new Rules.Transition(null, null, null, initialState)); } }
/// <summary> /// Provides the state which corresponds to the name provided /// </summary> /// <param name="name"></param> /// <returns></returns> public Constants.State findState(string name) { Constants.State retVal = (Constants.State)findValue(name.Split('.'), 0); if (retVal == null) { Log.Error("Cannot find state " + name); } return(retVal); }
public void Target(float distance) { if (!distanceSet) { dis = distance; distanceSet = true; } if (state != Constants.State.Selected) { state = Constants.State.Targeted; } }
internal void AddBreadCrumb(Constants.State value) { RightsManagementAsyncResult rightsManagementAsyncResult = base.AsyncState as RightsManagementAsyncResult; if (rightsManagementAsyncResult == null || rightsManagementAsyncResult == this) { if (this.breadcrumbs == null) { this.breadcrumbs = new Breadcrumbs <Constants.State>(32); } this.breadcrumbs.Drop(value); return; } rightsManagementAsyncResult.AddBreadCrumb(value); }
/// <summary> /// Finds a transition which matches the initial state, target state and rule condition in the existing transitions /// </summary> /// <param name="condition"></param> /// <param name="initialState"></param> /// <param name="targetState"></param> /// <returns></returns> private bool findMatchingTransition(Rules.RuleCondition condition, Constants.State initialState, Constants.State targetState) { bool retVal = false; foreach (Rules.Transition t in Transitions) { if (t.RuleCondition == condition && t.InitialState == initialState && t.TargetState == targetState) { retVal = true; break; } } return(retVal); }
/// <summary> /// Try to find a rule, in this state machine, or in a sub state machine /// which /// </summary> /// <param name="ruleConditions"></param> /// <param name="priority"></param> /// <param name="currentStateVariable">The variable which holds the current state of the procedure</param> private void EvaluateStateMachine(List <Rules.RuleCondition> ruleConditions, Generated.acceptor.RulePriority priority, Variables.IVariable currentStateVariable) { if (currentStateVariable != null) { Constants.State currentState = currentStateVariable.Value as Constants.State; Types.StateMachine currentStateMachine = currentState.StateMachine; while (currentStateMachine != null) { foreach (Rule rule in currentStateMachine.Rules) { rule.Evaluate(this, priority, currentStateVariable, ruleConditions); } currentStateMachine = currentStateMachine.EnclosingStateMachine; } } }
/// <summary> /// Provides the state whose name matches the name provided /// </summary> /// <param name="index">the index in names to consider</param> /// <param name="names">the simple value names</param> public Constants.State findSubState(string[] names, int index) { Constants.State retVal = null; foreach (Constants.State state in StateMachine.States) { if (state.Name.CompareTo(names[index]) == 0) { retVal = state; if (index < names.Length - 1) { retVal = retVal.findSubState(names, index + 1); } break; } } return(retVal); }
/// <summary> /// Adds a model element in this model element /// </summary> /// <param name="copy"></param> public override void AddModelElement(Utils.IModelElement element) { { Constants.State item = element as Constants.State; if (item != null) { appendStates(item); } } { Rules.Rule item = element as Rules.Rule; if (item != null) { appendRules(item); } } base.AddModelElement(element); }
/// <summary> /// Instanciates this state machine for the instanciation of a StructureProcedure into a Procedure /// </summary> /// <returns></returns> public StateMachine instanciate() { StateMachine retVal = (StateMachine)Generated.acceptor.getFactory().createStateMachine(); retVal.Name = Name; retVal.setFather(getFather()); retVal.InitialState = InitialState; foreach (Constants.State state in States) { Constants.State newState = state.duplicate(); retVal.appendStates(newState); } foreach (Rules.Rule rule in Rules) { Rules.Rule newRule = rule.duplicate(); retVal.appendRules(newRule); } return(retVal); }
/// <summary> /// Provides the values whose name matches the name provided /// </summary> /// <param name="index">the index in names to consider</param> /// <param name="names">the simple value names</param> public Values.IValue findValue(string[] names, int index) { Constants.State retVal = null; if (index < names.Length) { retVal = (Constants.State)Utils.INamableUtils.findByName(names[index], States);; if (retVal != null && index < names.Length - 1) { StateMachine stateMachine = retVal.StateMachine; if (stateMachine != null) { retVal = (Constants.State)stateMachine.findValue(names, index + 1); } } } return(retVal); }
public override bool Contains(Values.IValue first, Values.IValue other) { bool retVal = false; Constants.State state1 = first as Constants.State; Constants.State state2 = other as Constants.State; if (state1 != null && state2 != null) { if (state1.Type == state2.Type) { Constants.State current = state2; while (current != null & retVal == false) { retVal = (current == state1); current = current.EnclosingState; } } } return(retVal); }
/// <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> /// Indicates that the state machine contains (either directly or indirectly) the state /// </summary> /// <param name="state"></param> /// <returns></returns> internal Constants.State StateInThisStateMachine(DataDictionary.Constants.State state) { Constants.State retVal = null; foreach (Constants.State other in States) { if (other == state) { retVal = state; break; } retVal = other.StateMachine.StateInThisStateMachine(state); if (retVal != null) { retVal = other; break; } } return(retVal); }
/// <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(Generated.RuleCondition obj, bool visitSubNodes) { Rules.RuleCondition ruleCondition = (Rules.RuleCondition)obj; foreach (Rules.Action action in ruleCondition.Actions) { foreach (Interpreter.Statement.VariableUpdateStatement update in action.UpdateStatements) { Types.Type targetType = update.TargetType; if (targetType is StateMachine) { Interpreter.Expression expressionTree = update.Expression; if (expressionTree != null) { // HaCK: This is a bit rough, but should be sufficient for now... foreach (Constants.State stt1 in GetStates(expressionTree)) { // TargetState is the target state either in this state machine or in a sub state machine Constants.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 Constants.State enclosingState = Utils.EnclosingFinder <Constants.State> .find(action); if (enclosingState != null) { filteredOut = filteredOut || AddTransition(update, stt1, null, enclosingState); } if (!filteredOut) { foreach (Rules.PreCondition preCondition in ruleCondition.AllPreConditions) { // A transition from one state to another has been found foreach (Constants.State stt2 in GetStates(preCondition.ExpressionTree)) { filteredOut = filteredOut || AddTransition(update, stt1, preCondition, stt2); } } } if (Transitions.Count == transitionCount) { if (targetState == stt1 && targetState.EnclosingStateMachine == StateMachine) { if (!filteredOut) { // No precondition could be found => one can reach this state at anytime Transitions.Add(new Rules.Transition(null, null, update, targetState)); } } } } } else { action.AddError("Cannot parse expression"); } } } } base.visit(obj, visitSubNodes); }
public void Dehighlight() { distanceSet = false; state = Constants.State.None; }
public void Select() { state = Constants.State.Selected; }