public CallOperationBehaviorExecution(CallOperationAction paction, InstanceSpecification host, Dictionary<string, ValueSpecification> p)
            : base(paction, host, p, false)
        {
            this.action = paction;
            MascaretApplication.Instance.VRComponentFactory.Log("CallOperationAction : " + action.Operation.Method);

            foreach (ValuePin pin in action.ValuePins)
            {
                p.Add(pin.name, pin.ValueSpec);
            }
            MascaretApplication.Instance.VRComponentFactory.Log("READY TO Start");

            behaviorExecution = action.Operation.Method.createBehaviorExecution(this.Host, p, false);
            if (behaviorExecution == null) MascaretApplication.Instance.VRComponentFactory.Log("Chérie ca va trancher");
        }
Example #2
0
    public static void executeIsolateOperation(string operation, Agent agt, Dictionary <string, ValueSpecification> spec)
    {
        Operation op = MascaretUtils.getOperation(operation, agt);

        if (op != null)
        {
            CallOperationAction act = new CallOperationAction();
            act.Operation = op;
            BehaviorExecution be = act.createBehaviorExecution(agt, spec, false);
            PrintSingleton.Instance.log("Manually executing " + operation + " for " + agt.name);
            be.execute(0.0);
        }
        else
        {
            PrintSingleton.Instance.log("Operation " + operation + " not found for " + agt.name);
        }
    }
        /// <summary>
        ///
        /// </summary>
        /// <param name="rep"></param>
        /// <param name="pkg"></param>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="stereotype"></param>
        /// <returns></returns>
        public static EA.Element CreateElement(EA.Repository rep, EA.Package pkg, string name, string type, string stereotype)
        {
            var el = CallOperationAction.GetElementFromName(rep, name, type);

            if (el == null)
            {
                el = (EA.Element)pkg.Elements.AddNew(name, type);
                pkg.Elements.Refresh();
            }
            if (stereotype != "")
            {
                if (el.Stereotype != stereotype)
                {
                    el.Stereotype = stereotype;
                    el.Update();
                }
            }
            return(el);
        }
Example #4
0
    public static float executeIsolateBehavior(string operation, Agent agt, Dictionary <string, string> spec)
    {
        float behaviorExecutionTime = 1.0f;
        Class cl = (Class)agt.Classifier;

        if (cl.hasOperation(operation))
        {
            Operation           op  = cl.Operations[operation];
            CallOperationAction act = new CallOperationAction();
            act.Operation = op;
            Dictionary <string, ValueSpecification> param = MascaretUtils.getActionSpecification(spec);
            BehaviorExecution be = new CallOperationBehaviorExecution(act, agt, param);
            behaviorExecutionTime = (float)be.execute(0.00);
        }
        else
        {
            PrintSingleton.Instance.log("Operation " + operation + " not found for " + agt.name);
        }
        return(behaviorExecutionTime);
    }
Example #5
0
    public static void executeOperationInActivity(Agent agent, string operation, Dictionary <string, string> spec, int index, CallProcedureBehaviorExecution pbe)
    {
        if (pbe != null)
        {
            ActivityPartition   agentPartition = new ActivityPartition(agent.name);
            CallOperationAction act            = new CallOperationAction();
            act.Operation = MascaretUtils.getOperation(operation, agent);

            ActionNode an = new ActionNode(operation + "_" + index, "action");
            an.Action = act;
            foreach (KeyValuePair <string, string> kvp in spec)
            {
                act.Arguments.Add(kvp.Key, kvp.Value);
            }
            an.Partitions = new List <ActivityPartition>();
            an.Partitions.Add(agentPartition);

            AgentBehaviorExecution pbehavior = agent.getBehaviorExecutingByName("ProceduralBehavior");
            if (pbehavior != null)
            {
                ProceduralBehavior procBehave = (ProceduralBehavior)(pbehavior);
                PrintSingleton.Instance.log(procBehave.RunningProcedures.Count);
                OrganisationalEntity askedOrg  = MascaretApplication.Instance.AgentPlateform.Organisations.Find(x => x.name == pbe.action.OrganisationalEntity);
                Procedure            askedProc = askedOrg.Structure.Procedures.Find(x => x.name == pbe.action.Procedure);
                Role askedRole = askedOrg.RoleAssignement.Find(x => x.Role.name == agent.name).Role;
                if (procBehave.RunningProcedures.Count == 0) //No runningProcedure for this agent, need to create one
                {
                    Dictionary <string, ValueSpecification> procParams = new Dictionary <string, ValueSpecification>();
                    PrintSingleton.Instance.log("Launch procedure for " + agent.name);
                    askedProc.Activity.Partitions.Add(agentPartition);
                    procBehave.pushProcedureToDo(askedProc, askedOrg, askedRole, procParams);
                }
                //The new partition needs to be added to all agents..
                Dictionary <string, Agent> allAgents = VRApplication.Instance.AgentPlateform.Agents;
                foreach (KeyValuePair <string, Agent> kvp in allAgents)
                {
                    ProceduralBehavior pb = (ProceduralBehavior)kvp.Value.getBehaviorExecutingByName("ProceduralBehavior");
                    if (pb != null)
                    {
                        for (int iP = 0; iP < pb.runningProcedures.Count; iP++)
                        {
                            if (!pb.runningProcedures[iP].getAgentToPartition().ContainsKey(agent.Aid.toString()))
                            {
                                pb.runningProcedures[iP].getAgentToPartition().Add(agent.Aid.toString(), askedProc.Activity.Partitions.Find(x => x.name == agent.name));
                            }
                        }
                    }
                }

                executeOperation(an, agent);
            }
            else
            {
                PrintSingleton.Instance.log("Agent " + agent.name + " does not have a proceduralBehavior!");
            }
        }
        else
        {
            PrintSingleton.Instance.log("No procedure launched!");
        }
    }
Example #6
0
        protected void parseInteractions(XElement interactionNode)
        {
            Interaction interaction = new Interaction();

            foreach (XElement action in interactionNode.Elements())
            {
                if (action.Name.LocalName == "SendSignal")
                {
                    string signal = action.Attribute("name").Value;
                    string target = "";
                    if (action.Attribute("target") != null) target = action.Attribute("target").Value;
                    if (target == "") target = "designated";
                    string periphName = action.Attribute("peripheric").Value;
                    string buttonName = action.Attribute("button").Value;
                    bool pressed = (bool)action.Attribute("pressed");

                    SendSignalAction sendSignal = new SendSignalAction();
                    sendSignal.SignalClass = new Signal(signal);

                    Peripheric periph = this.window.getPeripheric(periphName);
                    Button button = periph.getButton(buttonName);
                    if (button != null)
                    {
                        interaction.addButtonAction(button, sendSignal, target, pressed);
                    }
                }
                else if(action.Name.LocalName == "CallOperation")
                {
                    string classifier=action.Attribute("classifier").Value;
                    Class targetClass=MascaretApplication.Instance.Model.AllClasses[classifier][0];
                    string operation=action.Attribute("name").Value;
                    string target=action.Attribute("target").Value;
                    string periphName=action.Attribute("peripheric").Value;
                    string buttonName=action.Attribute("button").Value;
                    bool pressed = (bool)action.Attribute("pressed");

                    CallOperationAction callOp = new CallOperationAction();
                    callOp.Operation = targetClass.Operations[operation];

                    Peripheric periph = this.window.getPeripheric(periphName);
                    Button button = periph.getButton(buttonName);
                    if (button != null)
                    {
                        interaction.addButtonAction(button, callOp, target, pressed);
                    }
                }
                else if (action.Name.LocalName == "CallProcedure")
                {
                    string procedure = action.Attribute("name").Value;
                    string organisation = action.Attribute("organisation").Value;

                    string target = "";
                    if (action.Attribute("target") != null) target = action.Attribute("target").Value;
                    if (target == "") target = "designated";
                    string periphName = action.Attribute("peripheric").Value;
                    string buttonName = action.Attribute("button").Value;
                    bool pressed = (bool)action.Attribute("pressed");

                    CallProcedureAction callProc = new CallProcedureAction();
                    callProc.Procedure = procedure;
                    callProc.OrganisationalEntity = organisation;

                    Peripheric periph = this.window.getPeripheric(periphName);
                    Button button = periph.getButton(buttonName);
                    if (button != null)
                    {
                        interaction.addButtonAction(button, callProc, target, pressed);
                    }
                }
            }
        }
Example #7
0
        //FinalNode, Merge et Decision devraent �tre des activityNode !!
        public void addActivityNode(XElement node, Activity activity)
        {
            MascaretApplication.Instance.VRComponentFactory.Log("New activity node");
            string type = "";
            string id = "";
            if (node.Attribute("{http://schema.omg.org/spec/XMI/2.1}type") != null)
                type = node.Attribute("{http://schema.omg.org/spec/XMI/2.1}type").Value;
            else
                type = node.Attribute("{http://www.omg.org/spec/XMI/20131001}type").Value;

            MascaretApplication.Instance.VRComponentFactory.Log(" Type : " + type);

            if (node.Attribute("{http://schema.omg.org/spec/XMI/2.1}id") != null)
                id = node.Attribute("{http://schema.omg.org/spec/XMI/2.1}id").Value;
            else
                id = node.Attribute("{http://www.omg.org/spec/XMI/20131001}id").Value;
            MascaretApplication.Instance.VRComponentFactory.Log(" ID : " + id);

            string name = "";
            if (node.Attribute("name") != null)
                name = node.Attribute("name").Value;
            else name = id;
            MascaretApplication.Instance.VRComponentFactory.Log(" Name : " + name);

            string idPartition = "";
            if (node.Attribute("inPartition") != null)
                idPartition = node.Attribute("inPartition").Value;

            MascaretApplication.Instance.VRComponentFactory.Log(id);
            MascaretApplication.Instance.VRComponentFactory.Log(type);
            MascaretApplication.Instance.VRComponentFactory.Log(name);
            MascaretApplication.Instance.VRComponentFactory.Log(idPartition);

            ActivityNode actNode = null;

            //Debug.Log(" TYPE NODE : " + type);

            if (type == "uml:InitialNode")
            {
                actNode = new InitialNode();
                activity.Initial = actNode;
                actNode.name = "Initial";
            }
            else if (type == "uml:FinalNode" || type == "uml:ActivityFinalNode")
            {
                actNode = new FinalNode();
            }
            else if (type == "uml:LoopNode")
            {
                addActivityGroup(node, activity);
            }
            else if (type == "uml:ForkNode")
            {
                actNode = new ForkNode();
            }
            else if (type == "uml:JoinNode")
            {
                actNode = new JoinNode();
            }
            else if (type == "uml:MergeNode")
            {
                actNode = new MergeNode();
            }
            /*else if (type == "uml:DecisionNode")
            {
                actNode = new DecisionNode();
            }*/
            else if (type == "uml:ObjectNode" || type == "uml:CentralBufferNode")
            {

                ObjectNode objNode = new ObjectNode(name);
                Classifier ressourceType = getObjectNodeType(node);
                if (ressourceType != null)
                    objNode.ResourceType = ressourceType;
                actNode = objNode;
                string type2 = node.Attribute("{http://schema.omg.org/spec/XMI/2.1}type").Value;
                if (_idClass.ContainsKey(type2))
                    ((ObjectNode)actNode).ResourceType = _idClass[type2];
            }
            else if (type == "uml:ValueSpecificationAction")
            {
                /*
                shared_ptr<XmlNode> valueNode = node->getChildByName("value");
                string expressionValue = valueNode->getProperty("value");
                shared_ptr<Expression> expression = make_shared<Expression>(expressionValue, _model->getBasicType("boolean"));
                _activityExpressions[node->getProperty("id")] = expression;
                */
            }
            else if (type == "uml:OpaqueAction")
            {
                if (isStereotypedPlayAnimation(node))
                {
                    string animationName = getAnimName(node);
                    MascaretApplication.Instance.VRComponentFactory.Log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NEW PLAY ANIMATION : " + name + "    " + animationName);

                    ActionNode an = new ActionNode(name, "action");
                    PlayAnimationAction ap = new PlayAnimationAction();
                    ap.Description = getComment(node);
                    ap.name = name;
                    ap.Owner = activity;
                    ap.animationName = animationName;

                    an.Action = ap;
                    addPins(an, node);
                    actNode = an;
                }
            }
            else if (type == "uml:CallBehaviorAction")
            {

                ActionNode an = new ActionNode(name, "action");
                CallBehaviorAction cb = new CallBehaviorAction();
                cb.Description = getComment(node);
                cb.name = name;
                cb.Owner = activity;
                XElement beNode = node.Element("behavior");

                string opid;

                if (beNode != null) opid = beNode.Attribute("idref").Value;
                else opid = node.Attribute("behavior").Value;

                if (_idBehaviors.ContainsKey(opid))
                {
                    cb.Behavior = _idBehaviors[opid];
                }
                else
                {
                    // Debug.Log("[ModelLoader2 Info] Behavior " + opid
                    //           + " not yet found for ActionNode " + name + ". Postbone...");
                    _callBehaviors.Add(cb, opid);
                }

                an.Action = cb;
                addPins(an, node);
                actNode = an;

            }
            else if (type == "uml:CallOperationAction")
            {

                ActionNode an = new ActionNode(name, "action");
                //Debug.Log("Action Node : " +name);
                CallOperationAction act = new CallOperationAction();
                act.Description = getComment(node);
                an.Fml = getFML(node);

                act.name = name;

                act.Owner = activity;

                XElement opNode = node.Element("operation");
                if (opNode != null)
                {
                    string opid;
                    opid = opNode.Attribute("idref").Value;
                    //MascaretApplication.Instance.logfile.WriteLine("Operation ID : " + opid); MascaretApplication.Instance.logfile.Flush();
                    string stereo = getStereotype(opid);
                    MascaretApplication.Instance.VRComponentFactory.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + name + " : " + opid + " " + stereo);
                    if (stereo != "")
                    {

                        an.Stereotype = stereo;
                    }

                    if (_idOperations.ContainsKey(opid))
                        act.Operation = _idOperations[opid];
                    else
                    {
                        //cerr << "ERREUR PAS OPERATION... " << opid<< endl;
                        _callOperations.Add(act, opid);
                    }
                }
                else
                {
                    string opid;
                    opid = node.Attribute("operation").Value;
                    // MascaretApplication.Instance.logfile.WriteLine("Operation ID : " + opid); MascaretApplication.Instance.logfile.Flush();
                    string stereo = getStereotype(opid);
                    MascaretApplication.Instance.VRComponentFactory.Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + name + " : " + opid + " " + stereo);
                    if (stereo != "")
                    {

                        an.Stereotype = stereo;
                    }

                    // MascaretApplication.Instance.logfile.WriteLine("Operation ID : " + opid); MascaretApplication.Instance.logfile.Flush();

                    if (_idOperations.ContainsKey(opid))
                    {
                        act.Operation = _idOperations[opid];
                        // MascaretApplication.Instance.logfile.WriteLine("Operation Name : " + act.Operation); MascaretApplication.Instance.logfile.Flush();

                    }
                    else
                        _callOperations.Add(act, opid);
                }
                an.Action = act;
                addPins(an, node);
                actNode = an;
            }
            else if (type == "uml:SendSignalAction")
            {
                MascaretApplication.Instance.VRComponentFactory.Log("SendSignalAction");
                ActionNode an = new ActionNode(name, "action");
                SendSignalAction act = new SendSignalAction();
                XElement sigNode = node.Element("signal");
                if (sigNode != null)
                {
                    string signame = sigNode.Attribute("name").Value;
                    if (!_signals.ContainsKey(signame))
                    {
                        Signal ns = new Signal(signame);
                        _signals.Add(signame, ns);
                    }
                    act.SignalClass = _signals[signame];
                }
                else
                {
                    string signame = "";
                    if (node.Attribute("signal") != null)
                        signame = node.Attribute("signal").Value;
                    if (!_signals.ContainsKey(signame))
                    {
                        Signal ns = new Signal(signame);
                        _signals.Add(signame, ns);
                    }

                    act.SignalClass = _signals[signame];
                }

                XElement targetNode = node.Element("argument");
                if (targetNode != null)
                {
                    string targetName = targetNode.Attribute("name").Value;
                    XElement typeNode = targetNode.Element("type");
                    string classid = "";
                    if (typeNode != null)
                        classid = typeNode.Attribute("idref").Value;
                    else
                        classid = targetNode.Attribute("type").Value;
                    act.Target = new SendSignalTarget();
                    act.Target.targetName = targetName;
                    act.Target.targetClass = _idClass[classid];
                }
                else
                {
                    targetNode = node.Element("target");
                    if (targetNode != null)
                    {
                        MascaretApplication.Instance.VRComponentFactory.Log("SendSignal Target");
                        string targetName = targetNode.Attribute("name").Value;
                        string classid = targetNode.Attribute("type").Value;
                        MascaretApplication.Instance.VRComponentFactory.Log("name : " + targetName);
                        MascaretApplication.Instance.VRComponentFactory.Log("name : " + targetName + " : " + _idClass[classid]);

                        act.Target = new SendSignalTarget();
                        act.Target.targetName = targetName;
                        act.Target.targetClass = _idClass[classid];

                    }
                    else MascaretApplication.Instance.VRComponentFactory.Log("No target");
                }
                an.Action = act;
                addPins(an, node);
                actNode = an;
            }
            else if (type == "uml:AddStructuralFeatureValueAction")
            {
                //cerr << " ############# Found a AddStructuralFeatureValueAction : " << endl;
                /*
                shared_ptr<ActionNode> an = make_shared<ActionNode>(name);
                shared_ptr<Classifier> type;
                shared_ptr<XmlNode> pinNode = node->getChildByName("object");

                string attrName = pinNode->getProperty("name");

                cerr << " Name == " << attrName << endl;

                shared_ptr<XmlNode> typeNode = pinNode->getChildByName("type");
                if (typeNode && typeNode->getProperty("type") == "uml:PrimitiveType")
                {
                    string href = typeNode->getProperty("href");
                    string strType = href.substr(href.rfind('#') + 1);
                    boost::to_lower(strType);
                    type = _model->getBasicType(strType);
                }

                shared_ptr<XmlNode> valueNode = pinNode->getChildByName("value");
                if (valueNode)
                {
                    string value = valueNode->getProperty("value");
                    cerr << "    VALUE : " << value << endl;
                    shared_ptr<Expression> expression = make_shared<Expression>(value, type);
                    shared_ptr<AddStructuralFeatureValueAction> act =
                        make_shared<AddStructuralFeatureValueAction>();
                    act->setValue(expression);
                    act->setProperty(attrName);
                    an->setAction(act);
                }
                actNode = an;
                */

            }
            else if (type == "uml:AcceptEventAction")
            {
                MascaretApplication.Instance.VRComponentFactory.Log("New uml:AcceptEventAction");
                ActionNode an = new ActionNode(name, "action");
                AcceptEventAction act = new AcceptEventAction();

                XElement triggerNode = node.Element("trigger");
                if (triggerNode != null)
                {
                    MascaretApplication.Instance.VRComponentFactory.Log("trigger node found");

                    Trigger trigger = new Trigger(name);
                    MascaretApplication.Instance.VRComponentFactory.Log("Debug : " + name);
                    string idT = "";
                    if (triggerNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}id") != null)
                        idT = triggerNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}id").Value;
                    else
                        idT = triggerNode.Attribute("{http://www.omg.org/spec/XMI/20131001}id").Value;

                    trigger.Id = idT;
                    MascaretApplication.Instance.VRComponentFactory.Log(trigger.Id);

                    if (triggerNode.Attribute("event") != null)
                    {
                        string idEvent = triggerNode.Attribute("event").Value;

                        if (_events.ContainsKey(idEvent))
                        {
                            trigger.MEvent = _events[idEvent];
                            act.setTrigger(trigger);
                        }
                        else
                            MascaretApplication.Instance.VRComponentFactory.Log("Could not find event : " + idEvent);
                    }
                }
                an.Action = act;
                addPins(an, node);
                actNode = an;

                MascaretApplication.Instance.VRComponentFactory.Log(" Fin AcceptEventAction");

            }
            // ...
            else
            {
                //Debug.Log("Unknown state: " + type);
            }

            if (actNode != null)
            {
                _activityNodes.Add(id, actNode);
                activity.addNode(actNode);
                //cerr << "searching _partitions for '" << idPartition << "'" << endl;
                if (_partitions.ContainsKey(idPartition))
                {
                    actNode.Partitions.Add(_partitions[idPartition]);
                    _partitions[idPartition].Node.Add(actNode);
                }
                actNode.Summary = getSummary(node);
                actNode.Description = getComment(node);
                actNode.Tags = getTags(node);
            }
        }
Example #8
0
        //non gestion des triggers
        //Attention ! Les Opaque expressions ne sont pas impl�ment� mais sont utilis� pour le moment dans les modelLoader
        //(par contre les expressions existe - c'est du ocl)
        public void addMachineTransition(XElement node, StateMachine machine, Dictionary<string, Vertex> vertices)
        {
            //shared_ptr<Operation> op;

            //    StreamWriter fileT = MascaretApplication.Instance.logfile;
            Transition t = new Transition();
            string transitionKind = "";

            if (node.Attribute("kind") != null)
                transitionKind = node.Attribute("kind").Value;
            t.Description = getComment(node);
            t.Summary = getSummary(node);
            t.Tags = getTags(node);
            if (transitionKind != "internal")
            {
                //cerr << "Not internal" << endl;
                Region region = machine.Region[machine.Region.Count - 1];
                region.Transitions.Add(t);
            }
            //   fileT.WriteLine("-------------------------------------------");
            //   fileT.WriteLine("Transition : " + transitionKind); fileT.Flush();

            // Trigger

            XElement triggerNode;
            triggerNode = node.Element("trigger");
            if (triggerNode != null)
            {
                if (triggerNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}idref") != null)
                {
                    string idRef = triggerNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}idref").Value;
                    MascaretEvent evt = this._events[idRef];
                    if (evt != null)
                    {
                        //    fileT.WriteLine("Trigger : " + evt.name);
                        Trigger trigger = new Trigger(evt.name);
                        trigger.MEvent = evt;
                        t.Trigger.Add(trigger);
                    }
                }
                else
                {
                    string triggerName = triggerNode.Attribute("name").Value;

                    if (triggerNode.Attribute("event") != null)
                    {
                        //cerr << "has prop event" << endl;
                        string eventID = triggerNode.Attribute("event").Value;
                        MascaretEvent evt = this._events[eventID];
                        if (evt != null)
                        {
                            //    fileT.WriteLine("Trigger : " + evt.name);
                            //   if (evt.GetType().ToString() == "Mascaret.SignalEvent") fileT.WriteLine("Trigger Class : " + ((SignalEvent)evt).SignalClass.name);
                            //   fileT.Flush();
                            Trigger trigger = new Trigger(evt.name);
                            trigger.MEvent = evt;
                            t.Trigger.Add(trigger);
                        }// else
                         //Debug.Log ("Error : Event not found for trigger : " + triggerName
                         //	+ " in machine " + machine.getFullName() );
                    }
                }
            }

            // Effect
            XElement effectNode;
            effectNode = node.Element("effect");
            if (effectNode != null)
            {
                string type = "";
                if (effectNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}type") != null)
                    type = effectNode.Attribute("{http://schema.omg.org/spec/XMI/2.1}type").Value;
                else
                    type = effectNode.Attribute("{http://www.omg.org/spec/XMI/20131001}type").Value;

                if (type == "uml:OpaqueBehavior")
                {
                    if (effectNode.Attribute("specification") != null)
                    {
                        string opName = effectNode.Attribute("specification").Value;
                        Operation op = _idOperations[opName];

                        if (transitionKind != "internal" && op != null)
                        {
                            CallOperationAction action = new CallOperationAction();
                            t.Effect = action;
                            action.Operation = op;
                        }

                    }
                    else
                    {
                        string sigName = effectNode.Attribute("name").Value;
                        Signal sig;
                        sig = _signals[sigName];
                        SendSignalAction action = new SendSignalAction();
                        t.Effect = action;
                        action.SignalClass = sig;
                    }
                }
            }

            if (transitionKind != "internal")
            {
                // Source
                string sourceID = node.Attribute("source").Value;
                string targetID = node.Attribute("target").Value;

                //            fileT.WriteLine("Source : " + sourceID);
                //          fileT.WriteLine("Target : " + targetID);
                foreach (KeyValuePair<string, Vertex> v in vertices)
                {
                    //    fileT.WriteLine("       Vertex : " + v.Key + " = " + v.Value.name);
                }

                Vertex vertex = null;

                if (!vertices.TryGetValue(sourceID, out vertex))
                {
                }
                else
                {
                    //  fileT.WriteLine("Source : " + vertex.name);
                    t.Source = vertex;
                    vertex.Outgoing.Add(t);
                }
                // target

                if (!vertices.TryGetValue(targetID, out vertex))
                {

                }
                else
                {
                    //   fileT.WriteLine("Target : " + vertex.name);

                    t.Target = vertex;
                    vertex.Incoming.Add(t);
                }
            }
        }
Example #9
0
        void OnButtonPressed(Button button, bool pressed)
        {
            foreach (ButtonActionInfo interaction in interactions)
            {
                if (interaction.pressed == pressed && interaction.button.name == button.name)
                {
                    Action action = interaction.action;
                    string target = interaction.target;

                    if (target == "broadcast")
                    {
                        //no target = broadcast. Just choose an arbitrary entity to execute
                        List<Entity> entities = MascaretApplication.Instance.getEnvironment().getEntities();
                        foreach (Entity entity in entities)
                        {
                            Action action2 = null;

                            if (action.GetType().ToString() == "Mascaret.SendSignalAction")
                            {
                                Signal signalC = ((SendSignalAction)(action)).SignalClass;
                                InstanceSpecification signal = new InstanceSpecification(signalC.name, signalC);

                                action2 = new SendSignalAction();
                                ((SendSignalAction)(action2)).SignalClass = ((SendSignalAction)(action)).SignalClass;
                                ((SendSignalAction)(action2)).Target = new SendSignalTarget();
                                ((SendSignalAction)(action2)).Target.target = entity;
                                ((SendSignalAction)(action2)).Signal = signal;
                            }
                            else if (action.GetType().ToString() == "Mascaret.CallOperationAction")
                            {
                                action2 = new CallOperationAction();
                                ((CallOperationAction)(action2)).Operation = ((CallOperationAction)(action)).Operation;
                                ((CallOperationAction)(action2)).Target = entity;
                            }
                            //if (agt)
                            //	BehaviorScheduler::getInstance()->executeBehavior(action2,agt,Parameters());
                            //else
                            BehaviorScheduler.Instance.executeBehavior(action2, entity, new Dictionary<string, ValueSpecification>(), false);
                            //_cbActionDone(action2);
                        }
                    }
                    else if (target == "designated")
                    {
                        InstanceSpecification entity = VRApplication.Instance.window.getSelectedEntity();

                        if (entity != null)
                        {

                            if (action.GetType().ToString() == "Mascaret.SendSignalAction")
                            {
                                Signal signalC = ((SendSignalAction)(action)).SignalClass;
                                InstanceSpecification signal = new InstanceSpecification(signalC.name, signalC);
                                ((SendSignalAction)(action)).Target = new SendSignalTarget();
                                ((SendSignalAction)(action)).Signal = signal;
                                ((SendSignalAction)(action)).Target.target = entity;

                            }
                            else if (action.GetType().ToString() == "Mascaret.CallOperationAction")
                            {
                                //cerr << "CALL OPERATION ..." << endl;
                                if (entity.Classifier.isA(((CallOperationAction)(action)).Operation.Classifier) == false)
                                {
                                    continue;
                                }
                                ((CallOperationAction)(action)).Target = entity;
                            }

                            //if (agt)
                            //	BehaviorScheduler::getInstance()->executeBehavior(action,agt,Parameters());
                            //else
                            BehaviorScheduler.Instance.executeBehavior(action, entity, new Dictionary<string, ValueSpecification>(), false);
                            //_cbActionDone(action);
                        }
                    }
                    else
                    {
                        if (action.GetType().ToString() == "Mascaret.CallProcedureAction")
                        {
                            List<Entity> entities = MascaretApplication.Instance.getEnvironment().getEntities();
                            Entity entity = entities[0];
                            Action action2 = null;
                            action2 = new CallProcedureAction();
                            ((CallProcedureAction)(action2)).Procedure = ((CallProcedureAction)(action)).Procedure;
                            ((CallProcedureAction)(action2)).OrganisationalEntity = ((CallProcedureAction)(action)).OrganisationalEntity;
                            BehaviorScheduler.Instance.executeBehavior(action2, entity, new Dictionary<string, ValueSpecification>(), false);
                        }
                    }
                }
            }
        }