示例#1
0
 public bool Equals(SendSignalAction other)
 {
     if (other == this.Action)
     {
         return(true);
     }
     return(false);
 }
示例#2
0
        protected void buildAffectationsAction(ref List <string> missing, ActivityNode node)
        {
            Action action = ((ActionNode)(node)).Action;

            if (action != null)
            {
                if (action.Kind == "SendSignal")
                {
                    SendSignalAction sendAct = (SendSignalAction)(action);
                    string           pname   = sendAct.Target.targetName;
                    if (pname != "")
                    {
                        RessourceAssignement ra = organisation.findRessourceAssignement(pname);

                        if (ra != null && ra.Entity != null)
                        {
                            affectations.Add(pname, ra.Entity);
                            sendAct.Target.target = ra.Entity;
                        }
                        else
                        {
                            missing.Add(pname);
                        }
                    }
                }
                else if (action.Kind == "CallOperation")
                {
                    CallOperationAction            callAct = (CallOperationAction)(action);
                    InstanceSpecification          host    = (InstanceSpecification)(agent);
                    Dictionary <string, Operation> opers   = host.Classifier.Operations;
                    if (opers.ContainsKey(callAct.Operation.name))
                    {
                        callAct.Operation = opers[callAct.Operation.name];
                    }
                }
                else if (action.Kind == "CallBehavior")
                {
                    /*
                     * shared_ptr<CallBehaviorAction> callBeh = shared_dynamic_cast<CallBehaviorAction>(action);
                     * map<string, shared_ptr<Operation> > opers = getHost()->getClassifier()->getOperations();
                     * map<string, shared_ptr<Operation> >::iterator it = opers.find(callBeh->getOperation()->getName());
                     * if (it != opers.end())
                     * {
                     *  callBeh->setBehavior(it->second);
                     * }
                     */
                }
                else
                {
                }
            }
        }
示例#3
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);
                        }
                    }
                }
            }
        }
示例#4
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);
                    }
                }
            }
        }
示例#5
0
 public SendSignalBehaviorExecution(SendSignalAction action, InstanceSpecification host, Dictionary <string, ValueSpecification> p)
     : base(action, host, p, false)
 {
     this.action = action;
 }
示例#6
0
        //default parameters sync = false
        public void start(InstanceSpecification host, Dictionary <string, InstanceSpecification> affectations, bool sync)
        {
            // StreamWriter file = MascaretApplication.Instance.logfile;
            if (action == null)
            {
                // file.WriteLine("Le noeud " + name + " n'a pas d'action associée!!!"); file.Flush();
                return;
            }

            Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();

            if (action.Kind == "SendSignal")
            {
                if (((SendSignalAction)action).Target == null)
                {
                    foreach (ActivityEdge currentEdge in Outgoing)
                    {
                        if (currentEdge.Target.Kind == "object")
                        {
                            if (affectations.ContainsKey(currentEdge.Target.name))
                            {
                                System.Console.WriteLine("Sending signal to : " + currentEdge.Target.name);
                                SendSignalAction ssAct = (SendSignalAction)action;
                                ssAct.Target        = new SendSignalTarget();
                                ssAct.Target.target = affectations[currentEdge.Target.name];
                            }

                            else
                            {
                                System.Console.WriteLine("affectation of " + currentEdge.Target.name + " not found");
                            }
                        }
                    }
                }
            }
            if (action.Kind == "CallOperation")
            {
                // file.WriteLine("Executing Call operation" + action.name + " " + ((CallOperationAction)action).Operation.getFullName()); file.Flush();

                if (((CallOperationAction)action).isDynamic())
                {
                    param = ((CallOperationAction)action).getParameters();
                }
                else
                {
                    foreach (InputPin currentPin in action.InputPins)
                    {
                        string paramName = currentPin.getIncomingObjectNode()[0].name;
                        //  file.WriteLine(" Looking for : " + paramName); file.Flush();
                        if (!affectations.ContainsKey(currentPin.getIncomingObjectNode()[0].name))
                        {
                            //        file.WriteLine(((CallOperationAction)action).Operation.getFullName() + " from " + action.Owner.name + " MISS " + currentPin.getIncomingObjectNode()[0].name); file.Flush();
                        }
                        InstanceValue val = new InstanceValue(affectations[currentPin.getIncomingObjectNode()[0].name]);
                        //    file.WriteLine("..... Trouve " + val.ToString()); file.Flush();
                        param.Add(currentPin.name, val);
                    }
                }

                if (Activity != null)
                {
                    //	action.Context(Activity.Context);
                }
            }
            currentExecution = BehaviorScheduler.Instance.executeBehavior(action, host, param, sync);
        }
示例#7
0
        //default parameters sync=false
        public ActivityBehaviorExecution(Activity activity, InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync) :
            base(activity, host, p, sync)
        {
            stateActivity = 0;
            this.activity = activity;
            affectations  = new Dictionary <string, InstanceSpecification>();


            /* Affectation des parametres */
            MascaretApplication.Instance.VRComponentFactory.Log("BUILD AFFECTATIONS ........ " + activity.name + " : " + activity.Partitions.Count);

            foreach (ActivityPartition currentPartition in activity.Partitions)
            {
                if (currentPartition.name == "this")
                {
                    affectations.Add("this", host);
                    // MascaretApplication.Instance.VRComponentFactory.Log("Affectation de this a : " + host.name);
                }
                else
                {
                    if (p.ContainsKey(currentPartition.name))
                    {
                        InstanceValue val = (InstanceValue)p[currentPartition.name];
                        affectations.Add(currentPartition.name, val.SpecValue);
                    }
                    else
                    {
                        if (host.Slots.ContainsKey(currentPartition.name))
                        {
                            affectations.Add(currentPartition.name, host.getProperty(currentPartition.name).getValue().valueSpecificationToInstanceSpecification());
                        }
                        else
                        {
                            MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation Partition de " + currentPartition.name + " impossible ...");
                        }
                    }
                }

                foreach (ActivityNode currentNode in currentPartition.Node)
                {
                    if (currentNode.Kind == "object")
                    {
                        MascaretApplication.Instance.VRComponentFactory.Log(" Parameters size : " + p.Count);
                        if (p.ContainsKey(currentNode.name))
                        {
                            InstanceValue val = (InstanceValue)p[currentNode.name];
                            affectations.Add(currentNode.name, val.SpecValue);
                        }
                        else
                        {
                            MascaretApplication.Instance.VRComponentFactory.Log("Slot ? " + currentNode.name);
                            if (host.Slots.ContainsKey(currentNode.name))
                            {
                                try
                                {
                                    MascaretApplication.Instance.VRComponentFactory.Log("Find");
                                    affectations.Add(currentNode.name, ((InstanceValue)(host.getProperty(currentNode.name).getValue())).SpecValue);
                                }
                                catch (Exception)
                                {
                                    // MascaretApplication.Instance.VRComponentFactory.Log("Multiple relation found, not supported, get the last one");
                                    foreach (ValueSpecification currentValue in host.getProperty(currentNode.name).Values.Values)
                                    {
                                        affectations.Add(currentNode.name, currentValue.valueSpecificationToInstanceSpecification());
                                    }
                                }
                            }
                            // else
                            //  MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation Object de " + currentNode.name + " impossible ...");
                        }
                    }
                    else
                    {
                        if (currentNode.Kind == "action")
                        {
                            Action action = ((ActionNode)currentNode).Action;
                            if (action.Kind == "SendSignal")
                            {
                                SendSignalAction sendAct = (SendSignalAction)action;
                                MascaretApplication.Instance.VRComponentFactory.Log("SendSignal to affect");
                                if (sendAct.Target != null && sendAct.Target.targetName != "")
                                {
                                    MascaretApplication.Instance.VRComponentFactory.Log("Look for : " + sendAct.Target.targetName);

                                    if (p.ContainsKey(sendAct.Target.targetName))
                                    {
                                        InstanceValue val = (InstanceValue)p[sendAct.Target.targetName];
                                        affectations.Add(sendAct.Target.targetName, val.SpecValue);
                                    }
                                    else
                                    {
                                        if (host.Slots.ContainsKey(sendAct.Target.targetName))
                                        {
                                            InstanceSpecification instance = ((InstanceValue)(host.getProperty(sendAct.Target.targetName).getValue())).SpecValue;
                                            MascaretApplication.Instance.VRComponentFactory.Log("Affecttion : " + sendAct.Target.targetName + " a " + instance.getFullName());

                                            affectations.Add(sendAct.Target.targetName, instance);
                                            sendAct.Target.target = instance;
                                            //affectations.Add(sendAct.Target.targetName, host.getProperty(sendAct.Target.targetName).getValue().valueSpecificationToInstanceSpecification());
                                            //sendAct.Target.target = host.getProperty(sendAct.Target.targetName).getValue().valueSpecificationToInstanceSpecification();
                                        }
                                        else
                                        {
                                            MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation SendAction de " + sendAct.Target.targetName + " impossible ...");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //OCLParser::Context function called

            /* OclParser::Context context;
             * map<string, shared_ptr<InstanceSpecification> >::iterator it;
             * for(it=_affectations.begin();it!=_affectations.end();it++)
             * {
             *       context[it->first]=it->second;
             * }
             * _activity->setContext(context);*/
        }