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 manageRequest(HttpRequest req) { string id = ""; if (req.parameters.ContainsKey("agent")) { id = req.parameters["agent"]; } Environment env = MascaretApplication.Instance.getEnvironment(); InstanceSpecification entity = null; if (env.InstanceSpecifications.ContainsKey(id)) { entity = env.InstanceSpecifications[id]; } VirtualHuman human = null; if (entity != null) { human = (VirtualHuman)(entity); } if (human != null) { env = human.KnowledgeBase.Environment; } id = req.parameters["alias"]; if (!env.InstanceSpecifications.ContainsKey(id)) { req.response.write("<html>"); req.response.write("<body>"); req.response.write("Can't find entity: " + id); req.response.write("</body>"); req.response.write("</html>"); return; } entity = env.InstanceSpecifications[id]; req.response.write("<html>"); req.response.write("<body>"); req.response.write("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"30\">"); req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">"); req.response.write("<link href=\"doxygen.css\" rel=\"stylesheet\" type=\"text/css\">"); req.response.write("<link href=\"tabs.css\" rel=\"stylesheet\" type=\"text/css\">"); req.response.write("<H2>Description</H2>"); req.response.write("<ul>"); req.response.write("<li>"); req.response.write(entity.name); req.response.write("</li>"); req.response.write("<li>"); req.response.write(entity.getFullName()); req.response.write("</li>"); req.response.write("<li>"); req.response.write(entity.Description); req.response.write("</li>"); req.response.write("<li>"); req.response.write(" <a href=\"Class?alias="); req.response.write(entity.Classifier.name); req.response.write("\" target = \"Body\">"); req.response.write("</a>"); req.response.write("</li>"); req.response.write("</ul>"); //req.response.flushBuffer(); Vector3 position = new Vector3(0, 0, 0); Vector3 orientation = new Vector3(0, 0, 0); Entity entity2 = (Entity)(entity); if (entity2 != null) { //position = entity2.getLocalPosition(); //orientation = entity2.getLocalOrientation(); req.response.write("<HR>"); req.response.write("<H2>Geometrie</H2>"); req.response.write("<FORM METHOD=GET action=\"changeGeometry\">"); req.response.write("<input type=\"hidden\" name=\"alias\" value=\""); req.response.write(id); req.response.write("\" />"); req.response.write("<TABLE BORDER=1>"); req.response.write("<TR>"); req.response.write("<TD>Position locale</TD>"); req.response.write("<TD>"); req.response.write("" + position.x); req.response.write("</TD>"); req.response.write("<TD>"); req.response.write("" + position.y); req.response.write("</TD>"); req.response.write("<TD>"); req.response.write("" + position.z); req.response.write("</TD>"); req.response.write("</TR>"); req.response.write("<TR>"); req.response.write("<TD>Orientation locale</TD>"); req.response.write("<TD>"); req.response.write("" + orientation.x); req.response.write("</TD>"); req.response.write("<TD>"); req.response.write("" + orientation.y); req.response.write("</TD>"); req.response.write("<TD>"); req.response.write("" + orientation.z); req.response.write("</TD>"); req.response.write("</TR>"); req.response.write("</TABLE>"); req.response.write("<INPUT TYPE=\"submit\" VALUE=\"Modifier\">"); req.response.write("</FORM>"); //req.response.flushBuffer(); } req.response.write("<HR>"); req.response.write("<H2>Attributs</H2>"); req.response.write("<FORM METHOD=GET action=\"changeAttributes\">"); req.response.write("<input type=\"hidden\" name=\"alias\" value=\""); req.response.write(id); req.response.write("\" />"); req.response.write("<ul>"); Dictionary <string, Slot> attributes = entity.Slots; foreach (KeyValuePair <string, Slot> attr in attributes) { req.response.write("<li>"); req.response.write(attr.Key); req.response.write(" = "); //string value = it->second->getValue().getStringFromValue(); string value = ""; foreach (KeyValuePair <string, ValueSpecification> val in attr.Value.Values) { value += "'" + val.Value.getStringFromValue() + "' "; } req.response.write(value); req.response.write("</li>"); } req.response.write("</ul>"); req.response.write("<INPUT TYPE=\"submit\" VALUE=\"Modifier\">"); req.response.write("</FORM>"); //req.response.flushBuffer(); req.response.write("<HR>"); req.response.write("<H2>Operations</H2>"); req.response.write("<ul>"); Class classifier = entity.Classifier; Dictionary <string, Operation> operations = classifier.Operations; foreach (KeyValuePair <string, Operation> operation in operations) { req.response.write("<li>"); req.response.write(" <a href=\"Operation?alias="); req.response.write(entity.name); req.response.write("&oper="); req.response.write(operation.Key); req.response.write("\" target = \"Body\">"); req.response.write(operation.Key); req.response.write("</a>"); req.response.write("</li>"); } req.response.write("</ul>"); //req.response.flushBuffer(); req.response.write("<HR>"); req.response.write("<H2>Signaux</H2>"); req.response.write("<ul>"); Dictionary <string, Behavior> behaviors = classifier.OwnedBehavior; foreach (KeyValuePair <string, Behavior> behavior in behaviors) { StateMachine stateMachine = (StateMachine)(behavior.Value); Region region = stateMachine.Region[0]; if (region != null) { List <Transition> transitions = region.Transitions; for (int iTrans = 0; iTrans < transitions.Count; iTrans++) { List <Trigger> triggers = transitions[iTrans].Trigger; for (int iTrig = 0; iTrig < triggers.Count; iTrig++) { MascaretEvent evt = triggers[iTrig].MEvent; if (evt != null) { if (evt.Type == "SignalEvent") { SignalEvent signalEvent = (SignalEvent)(evt); req.response.write("<li>"); req.response.write(" <a href=\"Signal?alias="); req.response.write(entity.name); req.response.write("&signal="); req.response.write(((SignalEvent)(evt)).SignalClass.name); req.response.write("\" target = \"Body\">"); req.response.write(((SignalEvent)(evt)).SignalClass.name); req.response.write("</a>"); req.response.write("</li>"); } } } } } } req.response.write("</ul>"); //req.response.flushBuffer(); req.response.write("<HR>"); req.response.write("<H2>Machines d'états</H2>"); req.response.write("<ul>"); List <StateMachineBehaviorExecution> stmbes = entity.SmBehaviorExecutions; for (int i = 0; i < stmbes.Count; i++) { Vertex state = stmbes[i].CurrentState; string name = stmbes[i].getStateMachine().name; string state_name = ""; if (state == null) { state_name = "inconnu"; } else { state_name = state.name; } string tmp = "<li>" + name + " - État actif: " + state_name + "</li>"; req.response.write(tmp); } req.response.write("</ul>"); req.response.write("<HR>"); req.response.write("<a href=\"CenterView?alias=" + entity.name + "\">Centrer la vue sur cette entité</a><br/>"); req.response.write("<a href=\"SetRed?alias=" + entity.name + "\">Mettre en rouge</a>"); req.response.write("</body>"); req.response.write("</html>"); //req.response.flushBuffer(); }
public override void manageRequest(HttpRequest req) { string id = req.parameters["alias"]; Environment env = MascaretApplication.Instance.getEnvironment(); if (!env.InstanceSpecifications.ContainsKey(id)) { req.response.write("<html>"); req.response.write("<body>"); req.response.write("Can't find entity: " + id); req.response.write("</body>"); req.response.write("</html>"); return; } InstanceSpecification entity = env.InstanceSpecifications[id]; VirtualHuman human = null; try { human = (VirtualHuman)(entity); } catch (InvalidCastException e) { req.response.write("<html>"); req.response.write("<body>"); req.response.write("Entity: " + id + " is not an agent"); req.response.write("</body>"); req.response.write("</html>"); return; } req.response.write("<html>"); req.response.write("<body>"); req.response.write("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"30\">"); req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">"); req.response.write("<link href=\"doxygen.css\" rel=\"stylesheet\" type=\"text/css\">"); req.response.write("<link href=\"tabs.css\" rel=\"stylesheet\" type=\"text/css\">"); req.response.write("<H2>Description</H2>"); req.response.write("<ul>"); req.response.write("<li>"); req.response.write(human.name); req.response.write("</li>"); req.response.write("<li>"); req.response.write(human.getFullName()); req.response.write("</li>"); req.response.write("<li>"); req.response.write(human.Description); req.response.write("</li>"); req.response.write("<li>"); req.response.write(" <a href=\"Class?alias="); req.response.write(human.Classifier.name); req.response.write("\" target = \"Body\">"); req.response.write("</a>"); req.response.write("</li>"); req.response.write("</ul>"); string setControlled = req.parameters["setControlled"]; if (setControlled == "true") { human.ControlledByHuman = true; } else if (setControlled == "false") { human.ControlledByHuman = false; } req.response.write("<HR>"); req.response.write("<H2>Toggle controlled by human</H2>"); req.response.write("<FORM METHOD=POST action=\"Agent?alias=" + id + "\">"); req.response.write("<input type=\"hidden\" name=\"alias\" value=\"" + id + "\" />"); if (human.ControlledByHuman) { req.response.write("<font color=\"darkred\">This agent is currently controlled. (will not follow procedure automatically)</font><br />"); req.response.write("<input type=\"hidden\" name=\"setControlled\" value=\"false\" />"); req.response.write("<input type=\"submit\" name=\"control\" value=\"Release control of this agent\" />"); } else { req.response.write("<font color=\"darkgreen\">This agent is currently automatic. (will automatically follow procedures)</font><br />"); req.response.write("<input type=\"hidden\" name=\"setControlled\" value=\"true\" />"); req.response.write("<input type=\"submit\" name=\"control\" value=\"Take control of this agent\" />"); } req.response.write("</FORM>"); req.response.write("<HR>"); req.response.write("<H2>Knowledge base</H2>"); KnowledgeBase kb = human.KnowledgeBase; if (kb != null) { req.response.write(" <a href=\"KnowledgeBase?alias="); req.response.write(human.name); req.response.write("\" target = \"_blank\">"); req.response.write(kb.name); req.response.write("</a>"); } req.response.write("<HR>"); req.response.write("<H2>Parler</H2>"); req.response.write("<FORM METHOD=GET action=\"speak\">"); req.response.write("<input type=\"hidden\" name=\"alias\" value=\""); req.response.write(id); req.response.write("\" />"); req.response.write("Texte : \t <INPUT name=\"text\">"); req.response.write("<INPUT TYPE=\"submit\" VALUE=\"Dire\">"); req.response.write("</FORM>"); req.response.write("<HR>"); req.response.write("<H2>Attributs</H2>"); req.response.write("<FORM METHOD=GET action=\"changeAttributes\">"); req.response.write("<input type=\"hidden\" name=\"alias\" value=\""); req.response.write(id); req.response.write("\" />"); req.response.write("<ul>"); Dictionary <string, Slot> attributes = human.Slots; foreach (KeyValuePair <string, Slot> attr in attributes) { req.response.write("<li>"); req.response.write(attr.Key); req.response.write(" = "); //string value = it->second->getValue().getStringFromValue(); string value = ""; foreach (KeyValuePair <string, ValueSpecification> val in attr.Value.Values) { value += "'" + val.Value.getStringFromValue() + "' "; } req.response.write(value); req.response.write("</li>"); } req.response.write("</ul>"); req.response.write("<INPUT TYPE=\"submit\" VALUE=\"Modifier\">"); req.response.write("</FORM>"); //req.response.flushBuffer(); req.response.write("<HR>"); req.response.write("<H2>Operations</H2>"); req.response.write("<ul>"); Class classifier = human.Classifier; Dictionary <string, Operation> operations = classifier.Operations; foreach (KeyValuePair <string, Operation> operation in operations) { req.response.write("<li>"); req.response.write(" <a href=\"Operation?alias="); req.response.write(human.name); req.response.write("&oper="); req.response.write(operation.Key); req.response.write("\" target = \"Body\">"); req.response.write(operation.Key); req.response.write("</a>"); req.response.write("</li>"); } req.response.write("</ul>"); //req.response.flushBuffer(); req.response.write("<HR>"); req.response.write("<H2>Signaux</H2>"); req.response.write("<ul>"); Dictionary <string, Behavior> behaviors = classifier.OwnedBehavior; foreach (KeyValuePair <string, Behavior> behavior in behaviors) { StateMachine stateMachine = (StateMachine)(behavior.Value); Region region = stateMachine.Region[0]; if (region != null) { List <Transition> transitions = region.Transitions; for (int iTrans = 0; iTrans < transitions.Count; iTrans++) { List <Trigger> triggers = transitions[iTrans].Trigger; for (int iTrig = 0; iTrig < triggers.Count; iTrig++) { MascaretEvent evt = triggers[iTrig].MEvent; if (evt != null) { if (evt.Type == "SignalEvent") { SignalEvent signalEvent = (SignalEvent)(evt); req.response.write("<li>"); req.response.write(" <a href=\"Signal?alias="); req.response.write(human.name); req.response.write("&signal="); req.response.write(((SignalEvent)(evt)).SignalClass.name); req.response.write("\" target = \"Body\">"); req.response.write(((SignalEvent)(evt)).SignalClass.name); req.response.write("</a>"); req.response.write("</li>"); } } } } } } req.response.write("</ul>"); req.response.write("</ul>"); req.response.write("<HR>"); req.response.write("<H2>Messages</H2>"); req.response.write(" AID : "); req.response.write(human.Aid.toString()); req.response.write("<H3>"); req.response.write(" <a href=\"createMessage?alias="); req.response.write(human.name); req.response.write("\" target = \"Body\">"); req.response.write("Envoyer un message"); req.response.write("</a>"); req.response.write("</H3>"); req.response.write("<H3>Non lus</H3>"); List <ACLMessage> nl = human.Mailbox.MessagesQueue; req.response.write("<TABLE BORDER=1>"); req.response.write("<TR>"); req.response.write("<TD>De </TD>"); req.response.write("<TD>Performative </TD>"); req.response.write("<TD>Contenu </TD>"); req.response.write("</TR>"); for (int inl = 0; inl < nl.Count; inl++) { ACLMessage msg = nl[inl]; //nl.erase(nl.begin()); req.response.write("<TR>"); req.response.write("<TD>"); req.response.write(msg.Sender.toString()); req.response.write("</TD>"); req.response.write("<TD>"); req.response.write(msg.getPerformativeText()); req.response.write("</TD>"); req.response.write("<TD>"); req.response.write(msg.Content); req.response.write("</TD>"); req.response.write("</TR>"); } req.response.write("</TABLE>"); req.response.write("<H3>Lus</H3>"); List <ACLMessage> l = human.Mailbox.MessagesChecked; req.response.write("<TABLE BORDER=1>"); req.response.write("<TR>"); req.response.write("<TD>De </TD>"); req.response.write("<TD>Performative </TD>"); req.response.write("<TD>Contenu </TD>"); req.response.write("</TR>"); for (int il = 0; il < l.Count; il++) { ACLMessage msg = l[il]; req.response.write("<TR>"); req.response.write("<TD>"); req.response.write(msg.Sender.toString()); req.response.write("</TD>"); req.response.write("<TD>"); req.response.write(msg.getPerformativeText()); req.response.write("</TD>"); req.response.write("<TD>"); req.response.write(msg.Content); req.response.write("</TD>"); req.response.write("</TR>"); } req.response.write("</TABLE>"); req.response.write("<H3>Envoyes</H3>"); List <ACLMessage> me = human.Mailbox.MessagesSent; req.response.write("<TABLE BORDER=1>"); req.response.write("<TR>"); req.response.write("<TD>A </TD>"); req.response.write("<TD>Performative </TD>"); req.response.write("<TD>Contenu </TD>"); req.response.write("</TR>"); for (int ie = 0; ie < me.Count; ie++) { ACLMessage msg = me[ie]; req.response.write("<TR>"); req.response.write("<TD>"); List <AID> receivers = msg.Receivers; for (int ir = 0; ir < receivers.Count; ir++) { req.response.write(receivers[ir].toString()); } req.response.write("</TD>"); req.response.write("<TD>"); req.response.write(msg.getPerformativeText()); req.response.write("</TD>"); req.response.write("<TD>"); req.response.write(msg.Content); req.response.write("</TD>"); req.response.write("</TR>"); } }