public void addSignal(InstanceSpecification signal)
 {
     // StreamWriter file = MascaretApplication.Instance.logfile;
       //  file.WriteLine("recu signal : " + signal.name + " par " + Host.name); file.Flush();
     Trigger trigger = new Trigger(signal.name);
     SignalEvent se = new SignalEvent(signal.name);
     se.Signal = signal;
     trigger.MEvent = se;
     eventQueue.Add(trigger);
     //restart();
 }
Exemplo n.º 2
0
        public void addStateMachineToClass(XElement smNode, Class classe)
        {
            //StreamWriter file = MascaretApplication.Instance.logfile;

            //Debug.Log ("********* [ModelLoader2 Info] addStateMachineToClass (SM: ");

            string name = smNode.Attribute("name").Value;

            //Debug.Log("RQ : " + name + " Class: " + classe.getFullName());
            // file.WriteLine("StateMachine : " + name); file.Flush();
            StateMachine machine = new StateMachine(name);

            machine.Description = getComment(smNode);
            machine.Summary = getSummary(smNode);
            machine.Tags = getTags(smNode);

            // SubMachine ?
            //if (smNode->hasProperty("submachineState")) {
            //	string subMachineRef = smNode->getProperty("id");
            //	_subStateMachines[subMachineRef] = machine;
            //cerr << "SUB STATE MACHINE" << endl;
            //} else {
            classe.addOwnedBehavior(machine);
            machine.Owner = classe;
            //}

            Dictionary<string, Vertex> vertices = new Dictionary<string, Vertex>();

            foreach (XElement child in smNode.Elements())
            {
                if (child.Name.LocalName.CompareTo("packagedElement") == 0 || child.Name.LocalName.CompareTo("ownedMember") == 0)
                {
                    string childType = "";
                    //  file.WriteLine("Child : " + child.Name.LocalName);
                    //  file.Flush();

                    XAttribute attr = (XAttribute)child.Attribute("{http://schema.omg.org/spec/XMI/2.1}type");
                    if (attr == null) attr = (XAttribute)child.Attribute("{http://www.omg.org/spec/XMI/20131001}type");

                    if (attr != null) childType = attr.Value;

                    if (childType == "uml:Trigger")
                    {
                        string id = "";
                        //   file.WriteLine("Trigger");
                        XAttribute attr3 = (XAttribute)child.Attribute("{http://schema.omg.org/spec/XMI/2.1}id");
                        if (attr3 == null) attr3 = (XAttribute)child.Attribute("{http://www.omg.org/spec/XMI/20131001}id");

                        if (attr3 != null) id = attr3.Value;

                        foreach (XElement child2 in child.Elements())
                        {
                            if (child2.Name.LocalName.CompareTo("event") == 0)
                            {
                                XAttribute attr2 = (XAttribute)child2.Attribute("{http://schema.omg.org/spec/XMI/2.1}type");
                                if (attr2 == null) attr2 = (XAttribute)child.Attribute("{http://www.omg.org/spec/XMI/20131001}type");

                                if (attr2 != null) childType = attr2.Value;
                                if (childType.CompareTo("uml:SignalEvent") == 0)
                                {
                                    XElement cSignal = child2.Element("signal");
                                    XAttribute idSignal = (XAttribute)cSignal.Attribute("{http://schema.omg.org/spec/XMI/2.1}idref");
                                    if (idSignal == null) idSignal = (XAttribute)cSignal.Attribute("{http://www.omg.org/spec/XMI/20131001}idref");

                                    string idref = idSignal.Value;
                                    Signal signal = _signals[idref];
                                    //   file.WriteLine("Signal name : " + signal.name); file.Flush();
                                    SignalEvent signalEvent = new SignalEvent(signal.name);
                                    signalEvent.SignalClass = signal;

                                    _events.Add(id, signalEvent);
                                }
                            }
                        }
                    }
                }
            }

            foreach (XElement child in smNode.Elements())
            {
                if (child.Name.LocalName == "region")
                {
                    //Debug.Log(" ####### add region .....");
                    Region region = new Region();
                    machine.Region.Add(region);
                    addMachineRegion(child, machine, region, vertices);
                }
                else if (child.Name.LocalName == "transition")
                {
                    //Debug.Log(" ####### add transition.....");
                    addMachineTransition(child, machine, vertices);
                }

            }
            //    file.Close();
        }
Exemplo n.º 3
0
        public void addSignalEvent(XElement signalNode, Package pkg)
        {
            // Bouml preserved body begin 0001F5E7

            string type = "", className = "", id = "";

            XAttribute attr = (XAttribute)signalNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}type");
            if (attr == null) attr = (XAttribute)signalNode.Attribute("{http://www.omg.org/spec/XMI/20131001}type");

            if (attr != null) type = attr.Value;

            attr = (XAttribute)signalNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}id");
            if (attr == null) attr = (XAttribute)signalNode.Attribute("{http://www.omg.org/spec/XMI/20131001}id");

            if (attr != null) id = attr.Value;

            attr = (XAttribute)signalNode.Attribute("name");
            if (attr != null) className = attr.Value;

            if (type.CompareTo("uml:SignalEvent") != 0)
            {
                //Debug.Log(className + " is a " + type + " and must be a signal");
                return;
            }

            SignalEvent signalEvent = new SignalEvent(className);

            attr = (XAttribute)signalNode.Attribute("signal");
            if (attr != null)
            {
                if (_signals.ContainsKey(attr.Value))
                {
                    Signal sig = _signals[attr.Value];
                    signalEvent.SignalClass = _signals[attr.Value];
                }

            }

            _events.Add(id, signalEvent);

            // Bouml preserved body end 0001F5E7
        }
        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;
        }
Exemplo n.º 5
0
        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>");
            }
        }