Example #1
0
 //default parameters sync = false
 public override BehaviorExecution createBehaviorExecution(InstanceSpecification host, Dictionary<String, ValueSpecification> p, bool sync)
 {
     if (name == "SimpleCommunicationBehavior")
     {
         System.Console.WriteLine(" ######## CREATE SIMPLE COM BEHAVIOR");
         SimpleCommunicationBehavior scb = new SimpleCommunicationBehavior((Behavior)this, host, p);
         scb.Interval = 0.5;
         return scb;
     }
     else if (name == "CommunicationBehavior")
     {
         System.Console.WriteLine(" ######## CREATE COM BEHAVIOR");
         CommunicationBehavior scb = new CommunicationBehavior((Behavior)this, host, p);
         scb.Interval = 0.5;
         return scb;
     }
     else if (name == "ProceduralBehavior")
     {
         ProceduralBehavior pb = new ProceduralBehavior((Behavior)this, host, p);
         pb.Interval = 0.5;
         return pb;
     }
     else if (name == "ActionListenerBehavior")
     {
         ActionListenerBehavior alb = new ActionListenerBehavior((Behavior)this, host, p);
         return alb as BehaviorExecution;
     }
     else
     {
         //BehaviorInitDeleterFunc operations
         return null;
     }
 }
 //public BehaviorExecution behaviorExecution;
 public CallProcedureBehaviorExecution(CallProcedureAction paction, InstanceSpecification host, Dictionary<string, ValueSpecification> p)
     : base(paction, host, p, false)
 {
     this.action = paction;
     System.Console.WriteLine("CallProcedureAction : " + action.Procedure);
     //behaviorExecution=action.Operation.Method.createBehaviorExecution(this.Host, p,false);
 }
Example #3
0
        //sync =false
        public BehaviorExecution executeBehavior(Behavior behavior, InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync)
        {
            _updateCurrentVirtualTime();
            BehaviorExecution newBe = behavior.createBehaviorExecution(host, p, sync);

            if (newBe != null)
            {
                newBe.Start          = currentVirtualTime;
                newBe.LastCalledTime = currentVirtualTime;
                if (sync)
                {
                    newBe.execute(0.00);//remplacer le double par un timespan?
                }
                else
                {
                    //Debug.Log("Adding behavior : " + newBe.name);
                    allBehaviors.Add(newBe);
                    _insert(newBe, 0.00);
                }
            }
            else
            {
                System.Console.WriteLine("Error on adding behavior : " + behavior.name + " for " + host.name);
            }
            return(newBe);
        }
        //default parameters sync=false
        public GlobalActivityBehavior(GlobalActivity gActivity, InstanceSpecification host, Dictionary<string, ValueSpecification> p)
            : base(gActivity.globalActivity, host, p)
        {
            stateActivity = 0;
            this.activity = gActivity.globalActivity;
            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 ...");
                    }
                }

            }
        }
Example #5
0
        protected void findRessources(List <string> missings)
        {
            // FileStream wFile;
            // StreamWriter file;

            // wFile = new FileStream("findRessource.txt", FileMode.Append);
            // file = new StreamWriter(wFile);
            // file.AutoFlush = true;
            bool affectAdded = false;

            List <string> always_missings = new List <string>(); // resources we always missing after a search pass

            for (int i = 0; i < missings.Count; i++)
            {
                bool missingAffected = false;
                //int it = 0;
                foreach (KeyValuePair <string, InstanceSpecification> entityp in affectations)
                // while (it < affectations.Count && !missingAffected)
                {
                    string missing = missings[i];

                    InstanceSpecification entity = entityp.Value;
                    // file.WriteLine(" LOOK FOR : " + missing + " in " + entity.name);
                    if (entity != null)
                    {
                        Slot slot = entity.getProperty(missing);
                        if (slot != null)
                        {
                            InstanceValue val = (InstanceValue)slot.getValue();
                            affectations.Add(missing, val.SpecValue);

                            missingAffected = true;
                            affectAdded     = true;
                            //  file.WriteLine(missing + " in " + entity.name + " OK ");
                            break;
                        }
                        //else Debug.Log(missing + " in " + entity.name + " NOP");
                    }
                    else
                    {
                        //cerr << "ERROR >>> " << it->first << " NOT FOUND !!" << endl;
                    }
                    // it++;
                }
                if (!missingAffected)
                {
                    always_missings.Add(missings[i]);
                }
            }

            /* If we have always missing resources but we have add some on this pass
             * we recursively search again.
             */

            //    file.Close();
            if (affectAdded)
            {
                findRessources(always_missings);
            }
        }
Example #6
0
 //default parameters sync = false
 public override BehaviorExecution createBehaviorExecution(InstanceSpecification host, Dictionary <String, ValueSpecification> p, bool sync)
 {
     if (name == "SimpleCommunicationBehavior")
     {
         System.Console.WriteLine(" ######## CREATE SIMPLE COM BEHAVIOR");
         SimpleCommunicationBehavior scb = new SimpleCommunicationBehavior((Behavior)this, host, p);
         scb.Interval = 0.5;
         return(scb);
     }
     else if (name == "CommunicationBehavior")
     {
         System.Console.WriteLine(" ######## CREATE COM BEHAVIOR");
         CommunicationBehavior scb = new CommunicationBehavior((Behavior)this, host, p);
         scb.Interval = 0.5;
         return(scb);
     }
     else if (name == "ProceduralBehavior")
     {
         ProceduralBehavior pb = new ProceduralBehavior((Behavior)this, host, p);
         pb.Interval = 0.5;
         return(pb);
     }
     else if (name == "ActionListenerBehavior")
     {
         ActionListenerBehavior alb = new ActionListenerBehavior((Behavior)this, host, p);
         return(alb as BehaviorExecution);
     }
     else
     {
         //BehaviorInitDeleterFunc operations
         return(null);
     }
 }
Example #7
0
        //public BehaviorExecution behaviorExecution;


        public CallProcedureBehaviorExecution(CallProcedureAction paction, InstanceSpecification host, Dictionary <string, ValueSpecification> p)
            : base(paction, host, p, false)
        {
            this.action = paction;
            System.Console.WriteLine("CallProcedureAction : " + action.Procedure);
            //behaviorExecution=action.Operation.Method.createBehaviorExecution(this.Host, p,false);
        }
 //default parameter sync=false
 public StateMachineBehaviorExecution(StateMachine stateMachine, InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync)
     : base(stateMachine, host, p, sync)
 {
     first             = true;
     currentActionDone = true;
     eventQueue        = new List <Trigger>();
 }
 //default parameter sync=false
 public StateMachineBehaviorExecution(StateMachine stateMachine, InstanceSpecification host, Dictionary<string, ValueSpecification> p, bool sync)
     : base(stateMachine, host, p, sync)
 {
     first = true;
     currentActionDone = true;
     eventQueue = new List<Trigger>();
 }
Example #10
0
        public override BehaviorExecution createBehaviorExecution(InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync)
        {
            StateMachineBehaviorExecution behavior = new StateMachineBehaviorExecution(this, host, p, sync);

            host.SmBehaviorExecutions.Add(behavior);
            return(behavior);
        }
 public ConversationPlanExecution(ConversationPlan planToExe, InstanceSpecification host, Dictionary<String, ValueSpecification> p)
     : base(planToExe, host, p)
 {
     plan = planToExe;
     isFinished = false;
     isPlanStarted = false;
     x = 1;
 }
        public override double execute(double dt)
        {
            //MascaretApplication.Instance.VRComponentFactory.Log(" EXECUTION SEND SIGNAL ... : " + action.Target.target.getFullName());

            if (action.Target.target != null)
            {
              //  MascaretApplication.Instance.VRComponentFactory.Log("Send Signal Action to " + action.Target.target.getFullName() + " : " + action.Target.target.SmBehaviorExecutions.Count);
                foreach (StateMachineBehaviorExecution smBe in action.Target.target.SmBehaviorExecutions)
                {
                    MascaretApplication.Instance.VRComponentFactory.Log("Send signal Machine : " + smBe.getStateMachine().name);
                    if (action.Signal != null)
                        smBe.addSignal(action.Signal);
                    else
                    {
                        if (action.SignalClass != null)
                        {
                            MascaretApplication.Instance.VRComponentFactory.Log("Send Signal " + action.SignalClass.name + " to " + action.Target.target.name);

                            InstanceSpecification sig = new InstanceSpecification(action.SignalClass.name, action.SignalClass);
                            smBe.addSignal(sig);
                        }
                        else
                            MascaretApplication.Instance.VRComponentFactory.Log("Pas de Signal");
                    }
                }
            }
            else
            {
                if (action.Signal != null)
                    MascaretApplication.Instance.VRComponentFactory.Log(action.Signal.name);
                else if (action.SignalClass != null)
                    MascaretApplication.Instance.VRComponentFactory.Log(" (Class) " + action.SignalClass.name);
                else
                    MascaretApplication.Instance.VRComponentFactory.Log(" No signal or signalClass");

                foreach (InstanceSpecification currentInstance in MascaretApplication.Instance.getEnvironment().InstanceSpecifications.Values)
                {

                    foreach (StateMachineBehaviorExecution smBe in currentInstance.SmBehaviorExecutions)
                    {
                        if (action.Signal != null)
                            smBe.addSignal(action.Signal);
                        else
                        {
                            if (action.SignalClass != null)
                            {
                                InstanceSpecification sig = new InstanceSpecification(action.SignalClass.name, action.SignalClass);
                                smBe.addSignal(sig);
                            }
                            else
                                MascaretApplication.Instance.VRComponentFactory.Log("Pas de Signal");
                        }
                    }
                }
            }

            return 0;
        }
Example #13
0
 public EasyDM(EasyDialogueFile planToExe, InstanceSpecification host, Dictionary<String, ValueSpecification> p)
     : base(planToExe, host, p)
 {
     vh = host as VirtualHuman;
         plan = planToExe;
         isFinished = false;
         isPlanStarted = false;
         x = 1;
 }
Example #14
0
 public BehaviorExecution(Behavior behavior, InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync)
 {
     specification = behavior;
     this.host     = host;
     this.sync     = sync;
     isFinished    = false;
     isSuspended   = false;
     parameters    = p;
     result        = new List <ValueSpecification>();
 }
 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();
 }
Example #16
0
 public Slot(InstanceSpecification instance, Property property)
     : base(property.name)
 {
     values = new Dictionary <string, ValueSpecification>();
     this.owningInstance   = instance;
     this.definingProperty = property;
     if (property.DefaultValue != null)
     {
         addValue(property.DefaultValue);
     }
 }
        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();
        }
Example #18
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
                {
                }
            }
        }
Example #19
0
 public SlotDerived(InstanceSpecification instance, Property property)
     : base(instance, property)
 {
     if (DefiningProperty != null)
     {
         System.Console.WriteLine("Slot deriver : " + ((Expression)DefiningProperty.DefaultValue).ExpressionValue + " from" + instance.name);
         expression = (Expression)DefiningProperty.DefaultValue.clone();
         if (expression == null)
         {
             expression = new Expression("No expression", DefiningProperty.Type);
         }
     }
 }
Example #20
0
 public SlotDerived(InstanceSpecification instance, Property property)
     : base(instance, property)
 {
     if (DefiningProperty != null)
     {
         System.Console.WriteLine("Slot deriver : " + ((Expression)DefiningProperty.DefaultValue).ExpressionValue + " from" + instance.name);
         expression = (Expression)DefiningProperty.DefaultValue.clone();
         if (expression == null)
         {
             expression = new Expression("No expression", DefiningProperty.Type);
         }
     }
 }
    public override BehaviorExecution InstanciateOpaqueBehavior(Mascaret.Behavior behavior, string typeName, InstanceSpecification host, Dictionary<string, ValueSpecification> p)
    {
        Type type = Types.GetType( typeName,"Assembly-CSharp" );
        BehaviorExecution be = null;
        if (type != null)
            be =  (BehaviorExecution)(Activator.CreateInstance(type));
        else Debug.Log ("ERREUR : " + typeName + " not found");

        if (be != null)
        {
            be.init(behavior,host,p,false);
        }
        return be;
    }
Example #22
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;
            }

            string texte = req.parameters["text"];

            texte = texte.Replace("+", " ");
            texte = texte.Replace("%2C", ",");
            texte = texte.Replace("%3F", "?");
            texte = texte.Replace("%C3%A7", "ç");

            //		human.speak(texte);

            req.response.write("<html>");
            req.response.write("<body>");
            req.response.write("Entity: " + id + " is speaking : " + texte);
            req.response.write("</body>");
            req.response.write("</html>");
            return;
        }
        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 #24
0
        public override BehaviorExecution createBehaviorExecution(InstanceSpecification host, Dictionary<string, ValueSpecification> p, bool sync)
        {
            MascaretApplication.Instance.VRComponentFactory.Log("OPAQUEBEHAVIOR::CREATEBEHAVIOREXECUTION");

            Class cl = (Class)(host.Classifier);

            MascaretApplication.Instance.VRComponentFactory.Log(cl.getFullName());

            Class ocl = _lookForOperation(cl);

            if (ocl == null) return null;

            string typeName = ocl.name + "_" + body;
            BehaviorExecution be = BehaviorScheduler.Instance.InstanciateOpaqueBehavior(this, typeName, host, p);
            return be;
        }
Example #25
0
        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 #26
0
        public new void simulate(InstanceSpecification entity)
        {
            BehaviorExecution be = null;

            if (isSubMachineState)
            {
                be = BehaviorScheduler.Instance.executeBehavior(submachine, entity, new Dictionary <string, ValueSpecification>(), false);
            }
            else if (!isSimple)
            {
                System.Console.WriteLine("!!!!!!!!!!! SUBREGION !!!!!!!");
            }

            if (doBehavior != null)
            {
                be = BehaviorScheduler.Instance.executeBehavior(doBehavior.Method, entity, new Dictionary <string, ValueSpecification>(), true);
            }
        }
Example #27
0
        public override BehaviorExecution createBehaviorExecution(InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync)
        {
            MascaretApplication.Instance.VRComponentFactory.Log("OPAQUEBEHAVIOR::CREATEBEHAVIOREXECUTION");

            Class cl = (Class)(host.Classifier);

            MascaretApplication.Instance.VRComponentFactory.Log(cl.getFullName());

            Class ocl = _lookForOperation(cl);

            if (ocl == null)
            {
                return(null);
            }

            string            typeName = ocl.name + "_" + body;
            BehaviorExecution be       = BehaviorScheduler.Instance.InstanciateOpaqueBehavior(this, typeName, host, p);

            return(be);
        }
Example #28
0
        public override BehaviorExecution activate(InstanceSpecification entity, Dictionary<string, ValueSpecification> param)
        {
            BehaviorExecution be = null;
            if (isSubMachineState)
            {
                be = BehaviorScheduler.Instance.executeBehavior(submachine, entity, param, false);
            }
            else if (!isSimple)
            {
                System.Console.WriteLine("!!!!!!!!!!! SUBREGION !!!!!!!");
            }

            System.Console.WriteLine(" Running State : " + name + " : " + DoBehavior);

            if (doBehavior != null)
            {
                be = BehaviorScheduler.Instance.executeBehavior(doBehavior.Method, entity, param, false);
            }

            return be;
        }
Example #29
0
        public override BehaviorExecution activate(InstanceSpecification entity, Dictionary <string, ValueSpecification> param)
        {
            BehaviorExecution be = null;

            if (isSubMachineState)
            {
                be = BehaviorScheduler.Instance.executeBehavior(submachine, entity, param, false);
            }
            else if (!isSimple)
            {
                System.Console.WriteLine("!!!!!!!!!!! SUBREGION !!!!!!!");
            }

            System.Console.WriteLine(" Running State : " + name + " : " + DoBehavior);

            if (doBehavior != null)
            {
                be = BehaviorScheduler.Instance.executeBehavior(doBehavior.Method, entity, param, false);
            }

            return(be);
        }
 public CallBehaviorBehaviorExecution(CallBehaviorAction paction, InstanceSpecification host, Dictionary<string, ValueSpecification> p)
     : base(paction, host, p, false)
 {
     this.action = paction;
 }
Example #31
0
        public void buildAffectations(Dictionary<String, ValueSpecification> parameters, InstanceSpecification host)
        {
            List<string> missing = new List<string>();

            /* Affectation de self */

            affectations.Add("self", host);
               // MascaretApplication.Instance.logfile.WriteLine("Build Affectations"); MascaretApplication.Instance.logfile.Flush();

            /* Affectation des parametres */
            activityParams.Clear();
            List<ActivityNode> nodes = procedure.Activity.Nodes;
            for (int iNode = 0; iNode < nodes.Count; iNode++)
            {
                ActivityNode node = nodes[iNode];
                if (node.Kind == "parameter")
                {
                    Parameter p = ((ActivityParameterNode)(node)).Parameter;
                    string strVal = parameters[p.name].getStringFromValue();
                    activityParams.Add(p.name, p.Type.createValueFromString(strVal));
                }
            }

            /* Affectation des ressources */
            List<ActivityPartition> partitions = procedure.Activity.Partitions;
            for (int i = 0; i < partitions.Count; i++)
            {
                if (partitions[i].name == "this")
                {
                    affectations.Add("this", host);
                }
                else
                {
                    string pname = partitions[i].name;
                }

                nodes = partitions[i].Node;
                for (int iNode = 0; iNode < nodes.Count; iNode++)
                {
                    ActivityNode node = nodes[iNode];
                    if (node.Kind == "object")
                    {
                        buildAffectationsObject(ref missing, node);
                    }
                    else
                    {
                        if (node.Kind == "action")
                        {
                            buildAffectationsAction(ref missing, node);
                        }
                    }
                }
            }

            if (missing.Count > 0)
            {
                buildAffectationsPostbone(missing);
            }

            procedure.Activity.context = _buildOclContext(activityParams);
            List<ActivityNode> actnodes = procedure.Activity.Nodes;
            foreach (ActivityNode actnode in actnodes)
            {
                if (actnode.Kind == "action")
                {
                    ((ActionNode)actnode).Action.context = procedure.Activity.context;
                }
            }
        }
Example #32
0
 public void restockInstance(InstanceSpecification specValue, string newName)
 {
     instances.Remove(specValue.name);
     instances.Add(newName, specValue);
 }
Example #33
0
 public abstract BehaviorExecution activate(InstanceSpecification host, Dictionary <string, ValueSpecification> p);
Example #34
0
        public override double execute(double dt)
        {
            //MascaretApplication.Instance.VRComponentFactory.Log(" EXECUTION SEND SIGNAL ... : " + action.Target.target.getFullName());

            if (action.Target.target != null)
            {
                //  MascaretApplication.Instance.VRComponentFactory.Log("Send Signal Action to " + action.Target.target.getFullName() + " : " + action.Target.target.SmBehaviorExecutions.Count);
                foreach (StateMachineBehaviorExecution smBe in action.Target.target.SmBehaviorExecutions)
                {
                    MascaretApplication.Instance.VRComponentFactory.Log("Send signal Machine : " + smBe.getStateMachine().name);
                    if (action.Signal != null)
                    {
                        smBe.addSignal(action.Signal);
                    }
                    else
                    {
                        if (action.SignalClass != null)
                        {
                            MascaretApplication.Instance.VRComponentFactory.Log("Send Signal " + action.SignalClass.name + " to " + action.Target.target.name);

                            InstanceSpecification sig = new InstanceSpecification(action.SignalClass.name, action.SignalClass);
                            smBe.addSignal(sig);
                        }
                        else
                        {
                            MascaretApplication.Instance.VRComponentFactory.Log("Pas de Signal");
                        }
                    }
                }
            }
            else
            {
                if (action.Signal != null)
                {
                    MascaretApplication.Instance.VRComponentFactory.Log(action.Signal.name);
                }
                else if (action.SignalClass != null)
                {
                    MascaretApplication.Instance.VRComponentFactory.Log(" (Class) " + action.SignalClass.name);
                }
                else
                {
                    MascaretApplication.Instance.VRComponentFactory.Log(" No signal or signalClass");
                }

                foreach (InstanceSpecification currentInstance in MascaretApplication.Instance.getEnvironment().InstanceSpecifications.Values)
                {
                    foreach (StateMachineBehaviorExecution smBe in currentInstance.SmBehaviorExecutions)
                    {
                        if (action.Signal != null)
                        {
                            smBe.addSignal(action.Signal);
                        }
                        else
                        {
                            if (action.SignalClass != null)
                            {
                                InstanceSpecification sig = new InstanceSpecification(action.SignalClass.name, action.SignalClass);
                                smBe.addSignal(sig);
                            }
                            else
                            {
                                MascaretApplication.Instance.VRComponentFactory.Log("Pas de Signal");
                            }
                        }
                    }
                }
            }


            return(0);
        }
 public ConversationalBehavior(Behavior specif, InstanceSpecification host, Dictionary<String, ValueSpecification> p)
     : base(specif, host, p)
 {
 }
Example #36
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);
        }
Example #37
0
 //default parameters sync = false
 public abstract BehaviorExecution createBehaviorExecution(InstanceSpecification host, Dictionary <String, ValueSpecification> p, bool sync);
Example #38
0
        public override BehaviorExecution createBehaviorExecution(InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync)
        {
            CallOperationBehaviorExecution behavior = new CallOperationBehaviorExecution(this, host, p);

            return(behavior);
        }
 public AcceptEventBehaviorExecution(AcceptEventAction action, InstanceSpecification host, Dictionary<string, ValueSpecification> p)
     : base(action, host, p, false)
 {
     _action = action;
     _timeSpent = false;
 }
Example #40
0
 public PlayAnimationBehaviorExecution(PlayAnimationAction paction, InstanceSpecification host, Dictionary <string, ValueSpecification> p)
     : base(paction, host, p, false)
 {
     this.action = paction;
 }
Example #41
0
 public InstanceValue(Classifier type)
     : base(type)
 {
     CLASSTYPE = "Instance";
     specValue = null;
 }
Example #42
0
 public InstanceValue(InstanceSpecification instance)
     : base(instance.Classifier)
 {
     specValue = instance;
     CLASSTYPE = "Instance";
 }
Example #43
0
 public ValueSpecification evaluateExpression(InstanceSpecification owner)
 {
     return null;
 }
 public SimpleBehaviorExecution(Behavior specif, InstanceSpecification host, Dictionary <String, ValueSpecification> p)
     : base(specif, host, p)
 {
 }
Example #45
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);
                        }
                    }
                }
            }
        }
Example #46
0
 public AgentBehaviorExecution(Behavior specif, InstanceSpecification host, Dictionary <String, ValueSpecification> p)
     : base(specif, host, p, false)
 {
 }
Example #47
0
 public ActionListenerBehavior(Behavior specif, InstanceSpecification host, Dictionary <String, ValueSpecification> p)
     : base(specif, host, p)
 {
 }
Example #48
0
 public void simulate(InstanceSpecification host)
 {
 }
 public PlayAnimationBehaviorExecution(PlayAnimationAction paction, InstanceSpecification host, Dictionary<string, ValueSpecification> p)
     : base(paction, host, p, false)
 {
     this.action = paction;
 }
Example #50
0
        public new void simulate(InstanceSpecification entity)
        {
            BehaviorExecution be = null;
            if (isSubMachineState)
            {

                be = BehaviorScheduler.Instance.executeBehavior(submachine, entity, new Dictionary<string, ValueSpecification>(), false);
            }
            else if (!isSimple)
            {
                System.Console.WriteLine("!!!!!!!!!!! SUBREGION !!!!!!!");
            }

            if (doBehavior != null)
            {
                be = BehaviorScheduler.Instance.executeBehavior(doBehavior.Method, entity, new Dictionary<string, ValueSpecification>(), true);
            }
        }
 public ConversationOperation(string cname, InstanceSpecification agt)
 {
     host = agt;
     name = cname;
 }
 public AgentBehaviorExecution(Behavior specif, InstanceSpecification host, Dictionary<String, ValueSpecification> p)
     : base(specif, host, p, false)
 {
 }
Example #53
0
 public void simulate(InstanceSpecification host)
 {
 }
Example #54
0
        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 + " - &Eacute;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 ActionListenerBehavior(Behavior specif, InstanceSpecification host, Dictionary<String, ValueSpecification> p)
     : base(specif, host, p)
 {
 }
Example #56
0
        public override void init(Behavior behavior, InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync)
        {
            base.init(behavior, host, p, sync);

            this.m_Method.Invoke(this.m_Component, this.GetParameters(p));
        }
Example #57
0
 public ValueSpecification evaluateExpression(InstanceSpecification owner)
 {
     return(null);
 }
Example #58
0
 public abstract BehaviorExecution activate(InstanceSpecification host, Dictionary<string, ValueSpecification> p);
        //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);*/
        }
Example #60
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);
                        }
                    }
                }
            }
        }