public void stop() { if (currentExecution != null) { currentExecution.stop(); } }
public override double execute(double dt) { // StreamWriter file = MascaretApplication.Instance.logfile; file.Flush(); // file.WriteLine("StateMachine"); file.Flush(); if (first) { // TODO: Attention a gerer plus tard : possibilite de fixe l'etat en cours a l'initialisation de l'instance // Recherche de l'etat Initial List <PseudoState> ps = getStateMachine().ConnectionPoint; StateMachine machine = getStateMachine(); List <Region> res = machine.Region; bool foundInitialState = false; // file.WriteLine("Pseudo state : " + ps.Count); file.Flush(); foreach (PseudoState pseudo in ps) { if (pseudo.kind == PseudoStateKind.INITIAL) { Dictionary <string, ValueSpecification> p = new Dictionary <string, ValueSpecification>(); List <Transition> trans = pseudo.Outgoing; foreach (Transition transition in trans) { //if (_currentState) _currentState->desactivate(); activateState(transition.Target, p); } //file.WriteLine("Found Initial"); file.Flush(); foundInitialState = true; break; } } if (!foundInitialState) { toStop = true; } //toStop = foundInitialState ? false : true; first = false; } else { while (eventQueue.Count != 0) { Vertex currentState = this.currentState; if (currentState == null)//|| (currentState.Noninterpt && currentState.running)) { break; } // if (this.Host.name == "tiroirProduits") // file.WriteLine(" ---> " + this.Host.name + " stateMachine Behavior " + this.Specification.getFullName()+ " in " + currentState.getFullName()); file.Flush(); Trigger trigger = eventQueue[0]; eventQueue.RemoveAt(0); List <Transition> trans = currentState.Outgoing; MascaretApplication.Instance.VRComponentFactory.Log(" Trigger : " + trigger.name); // file.WriteLine("Nb Trans : " + trans.Count); file.Flush(); for (int iT = 0; iT < trans.Count; iT++) { List <Trigger> transTriggers = trans[iT].Trigger; // file.WriteLine("Nb Triger : " + transTriggers.Count); file.Flush(); for (int i = 0; i < transTriggers.Count; i++) { Trigger transTrigger = transTriggers[i]; // if (this.Host.name == "tiroirProduits") // file.WriteLine(" ---> " + this.Host.name + " " + transTrigger.getFullName()); file.Flush(); if (transTrigger.equals(trigger)) { Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>(); //OclParser::Context context; MascaretApplication.Instance.VRComponentFactory.Log(" Trigger OK"); MascaretEvent evt = trigger.MEvent; if (evt != null && evt.Type == "SignalEvent") { SignalEvent sevt = (SignalEvent)evt; InstanceSpecification signal = sevt.Signal; if (signal != null) { /* // Gestion des parametres * map<string, shared_ptr<Slot> > props = signal->getSlots(); * map<string, shared_ptr<Slot> >::iterator it; * for (it = props.begin(); it != props.end(); it++) * { * vector<AnyValue> values; * values.push_back((AnyValue)it->second->getValue()->getStringFromValue()); * context[it->first] = CollectionAnyValue(values); * param[it->first] = it->second->getValue(); * cerr << it->first << " == " << it->second->getValue()->getStringFromValue() << endl; * } */ } } //context["self"]=getHost(); if (trans[iT].Guard == null) //|| trans[iT]->getGuard()->eval(context)) { if (currentState != null) { if (be != null) { be.stop(); BehaviorScheduler.Instance.deleteExecutionBehavior(be); be = null; } currentState.desactivate(); } Action effect = trans[iT].Effect; if (effect != null) { MascaretApplication.Instance.VRComponentFactory.Log("Has effect"); BehaviorScheduler.Instance.executeBehavior(effect, this.Host, param, false); } MascaretApplication.Instance.VRComponentFactory.Log("Activate new state : " + trans[iT].Target.name); activateState(trans[iT].Target, param); } } } } } // if(eventQueue.Count == 0) // pause(); //toStop = true; } return(0.01); //if (toStop) return 0; //else return 0.001; }
public override void stop() { base.stop(); behaviorExecution.stop(); }