Ejemplo n.º 1
0
        public InstanceSpecification getInstanceValue()
        {
            //callbackMethod
            _update();

            ValueSpecification vSpec = null;

            if (values.Count == 1)
            {
                foreach (ValueSpecification valueSpec in values.Values)
                {
                    vSpec = valueSpec;
                }
            }

            // Check if value exist
            if (vSpec == null)
            {
                return(null);
            }

            if (vSpec.GetType().IsSubclassOf(typeof(LiteralSpecification)))
            {
                throw new Exception("Can not use this method with this kind of parameter !");
            }

            InstanceValue iValue = (InstanceValue)vSpec;

            return(iValue.SpecValue);
        }
Ejemplo n.º 2
0
        public ValueSpecification evaluateExpression(Dictionary <string, ValueSpecification> c)
        {
            MascaretApplication.Instance.VRComponentFactory.Log("Evaluate Expression");

            foreach (KeyValuePair <string, ValueSpecification> val in c)
            {
                string             valueS = "NotDef";
                ValueSpecification value  = val.Value;
                if (value.GetType().ToString() == "Mascaret.InstanceValue")
                {
                    valueS = ((InstanceValue)value).SpecValue.getFullName();
                }
                else
                {
                    MascaretApplication.Instance.VRComponentFactory.Log(value.GetType().ToString());
                }

                MascaretApplication.Instance.VRComponentFactory.Log("Context : " + val.Key + " = " + valueS);
            }

            OCLExpressionLexer  lex    = new OCLExpressionLexer(new AntlrInputStream(expressionValue));
            CommonTokenStream   tokens = new CommonTokenStream(lex);
            OCLExpressionParser parser = new OCLExpressionParser(tokens);

            parser.context = c;
            parser.expression();
            MascaretApplication.Instance.VRComponentFactory.Log("Parsing  : " + expressionValue);
            MascaretApplication.Instance.VRComponentFactory.Log("Nb Erreur : " + parser.NumberOfSyntaxErrors);


            return((LiteralBoolean)(parser.value));
        }
Ejemplo n.º 3
0
 public void replaceValue(string old, ValueSpecification newValue)
 {
     _removeValue(old);
     if (definingProperty.IsNavigable && definingProperty.Opposite != null)
     {
         _getOppositeSlot(old)._removeValue(owningInstance.name);
     }
     addValue(newValue);
 }
Ejemplo n.º 4
0
        public override ValueSpecification createValueFromString(string str)
        {
            ValueSpecification valueSpec = null;

            if (type == "real" || type == "double")
            {
                valueSpec = new LiteralReal(str);
            }
            else if (type == "integer")
            {
                valueSpec = new LiteralInteger(str);
            }
            else if (type == "string")
            {
                valueSpec = new LiteralString(str);
            }
            else if (type == "boolean")
            {
                valueSpec = new LiteralBoolean(str);
            }

            /*else if (type =="color")
             *  valueSpec = new Color(str);
             * else if (type =="Vector3")
             *  valueSpec = new Vector3(str);*/
            else if (type == "rotation")
            {
                valueSpec = new RotationVector(str);
            }
            else if (type == "shape")
            {
                //valueSpec = (UnityShapeSpecification)ScriptableObject.CreateInstance("UnityShapeSpecification");
                //((UnityShapeSpecification)valueSpec).instantiate(str);
            }
            else if (type == "point")
            {
                //valueSpec = (UnityPointSpecification)ScriptableObject.CreateInstance("UnityPointSpecification");
                //((UnityPointSpecification)valueSpec).instantiate(str);
            }

            /*else if (type =="path")
             *  valueSpec = new PathSpecification(str);
             * else if (type =="sound")
             *  valueSpec = new UnitySoundSpecification(str);
             * else if (type =="animation")
             *  valueSpec = new UnityAnimationSpecification(str);*/
            else
            {
                Console.WriteLine("Default : value is string");
                valueSpec = new LiteralString(str);
            }
            return(valueSpec);
        }
Ejemplo n.º 5
0
        public T getValue <T>()
        {
            //callbackMethod
            _update();

            ValueSpecification vSpec = null;

            if (values.Count == 1)
            {
                foreach (ValueSpecification valueSpec in values.Values)
                {
                    vSpec = valueSpec;
                }
            }

            // Check if value exist
            if (vSpec == null)
            {
                return(default(T));
            }

            // Check if value is a Litteral Specification
            if (vSpec.GetType().IsSubclassOf(typeof(LiteralSpecification)))
            {
                // The value exist now get the Classifier
                Type         type  = typeof(T);
                IConvertible value = null;
                if (type.Equals(typeof(System.Boolean)))
                {
                    value = vSpec.getBoolFromValue();
                }
                else if (type.Equals(typeof(System.Int32)))
                {
                    value = vSpec.getIntFromValue();
                }
                else if (type.Equals(typeof(System.Double)) || type.Equals(typeof(System.Single)))
                {
                    value = vSpec.getDoubleFromValue();
                }
                else
                {
                    value = vSpec.getStringFromValue();
                }

                return((T)value);
            }
            else
            {
                throw new Exception("Can not use this method with this kind of Value");
            }
        }
Ejemplo n.º 6
0
 public void _addValue(ValueSpecification element)
 {
     if (definingProperty.MaximumNumber == 1 && values.Keys.Count == 1)
     {
         values.Clear();
     }
     else if (values.Keys.Count > definingProperty.MaximumNumber && definingProperty.MaximumNumber != -1)
     {
         System.Console.WriteLine("Slot::addValue Error : " + definingProperty.name + " number of value is " + values.Keys.Count + " maximum is " + definingProperty.MaximumNumber);
     }
     if (element != null)
     {
         values.Add(element.getStringFromValue(), element);
     }
     //calbakcs functions call
 }
        public override double execute(double dt)
        {
            Dictionary <string, ValueSpecification> context = _action.context;

            bool   result = false;
            double time   = 0.2;

            if (_action.getTrigger().MEvent.Type == "ChangeEvent")
            {
                ChangeEvent        changeEvent = (ChangeEvent)(_action.getTrigger().MEvent);
                Expression         expr        = (Expression)(changeEvent.ChangeExpression);
                ValueSpecification resultVS    = expr.evaluateExpression(context);
                result = ((LiteralBoolean)(resultVS)).BValue;
                MascaretApplication.Instance.VRComponentFactory.Log("Checking context of AcceptEventAction " + changeEvent.Type);
            }

            /*
             * else if (_action->getTrigger()->getEvent()->getType() == "TimeEvent")
             * {
             * if (!_timeSpent)
             * {
             *  shared_ptr<TimeEvent> timeEvent = shared_dynamic_cast<TimeEvent>(_action->getTrigger()->getEvent());
             *  timeEvent->getWhen()->getDoubleValue(time);
             *  if (time != 0)
             *      _timeSpent = true;
             *  cerr << "Checking context of AcceptEventAction " << timeEvent->getType() << " time to spend : " << time << endl;
             * }
             * else
             * {
             *  time = 0;
             *  cerr << "TimeEvent is now checked." << endl;
             * }
             * }*/
            else
            {
                MascaretApplication.Instance.VRComponentFactory.Log("ERROR: This trigger event is not an AcceptEventAction event. This event should be a ChangeEvent. (Is type is " + _action.getTrigger().MEvent.Type + ")");
            }

            if (result)
            {
                return(0);
            }
            else
            {
                return(time);
            }
        }
Ejemplo n.º 8
0
        public void addValue(ValueSpecification val)
        {
            /*
             * Property oppositeProp=null;
             * if(definingProperty.IsNavigable)
             *  oppositeProp = definingProperty.Opposite;
             * if(oppositeProp!=null)
             * {
             *  InstanceSpecification test = val.valueSpecificationToInstanceSpecification();
             *  InstanceValue curInstanceValue = (InstanceValue)ScriptableObject.CreateInstance("InstanceValue");
             *  curInstanceValue.instantiate(owningInstance);
             *  test.getProperty(oppositeProp.name).addValue((ValueSpecification)curInstanceValue);
             * }*/
            _addValue(val);

            //backupFunction
        }
Ejemplo n.º 9
0
        //Default Parameters opposite = null ,ValueSpecification def= ,null,DomainSpecification domain=null
        public Property(string name, Class cl, Classifier type, Property opposite, ValueSpecification def, DomainSpecification domain)
            : base(name)
        {
            this.type          = type;
            this.classifier    = cl;
            this.opposite      = opposite;
            this.defaultValue  = null;
            this.domain        = domain;
            this.isComposite   = false;
            this.isNavigable   = false;
            this.isReadOnly    = false;
            this.isDerived     = false;
            this.isUnique      = false;
            this.isOrdered     = false;
            this.minimumNumber = 0;
            this.maximumNumber = 1;

            if (def != null)
            {
                this.defaultValue = def;
            }
            else
            {
                string typeName = type.name;
                if (typeName == "real")
                {
                    this.defaultValue = new LiteralReal();
                }
                else if (typeName == "integer")
                {
                    this.defaultValue = new LiteralInteger();
                }
                else if (typeName == "string")
                {
                    this.defaultValue = new LiteralString();
                }
                else if (typeName == "boolean")
                {
                    this.defaultValue = new LiteralBoolean();
                }
                else if (typeName == "bool")
                {
                    this.defaultValue = new LiteralBoolean();
                }
            }
        }
Ejemplo n.º 10
0
        //Default Parameters opposite = null ,ValueSpecification def= ,null,DomainSpecification domain=null
        public Property(string name, Class cl, Classifier type, Property opposite, ValueSpecification def, DomainSpecification domain)
            : base(name)
        {
            this.type = type;
            this.classifier = cl;
            this.opposite = opposite;
            this.defaultValue = null;
            this.domain = domain;
            this.isComposite = false;
            this.isNavigable = false;
            this.isReadOnly = false;
            this.isDerived = false;
            this.isUnique = false;
            this.isOrdered = false;
            this.minimumNumber = 0;
            this.maximumNumber = 1;

            if (def != null)
                this.defaultValue = def;
            else
            {
                string typeName = type.name;
                if (typeName == "real")
                {
                    this.defaultValue = new LiteralReal();
                }
                else if (typeName == "integer")
                {
                    this.defaultValue = new LiteralInteger();
                }
                else if (typeName == "string")
                {
                    this.defaultValue = new LiteralString();
                }
                else if (typeName == "boolean")
                {
                    this.defaultValue = new LiteralBoolean();
                }
                else if (typeName == "bool")
                {
                    this.defaultValue = new LiteralBoolean();
                }
            }
        }
Ejemplo n.º 11
0
        public void checkSlots()
        {
            int modif = 0;

            foreach (Slot slot in slots.Values)
            {
                foreach (KeyValuePair <string, ValueSpecification> pair in slot.Values)
                {
                    if (pair.Key != pair.Value.getStringFromValue())
                    {
                        ValueSpecification val = pair.Value.clone();
                        slot.removeValue(pair.Key);
                        slot.addValue(val);
                        modif++;
                    }
                }
            }

            System.Console.WriteLine("Slot modifications : " + modif);
        }
Ejemplo n.º 12
0
        public Dictionary <string, T> getValues <T> ()
        {
            //callbackMethod
            _update();

            Dictionary <string, T> dict = new Dictionary <string, T>();

            foreach (KeyValuePair <string, ValueSpecification> pair in values)
            {
                // Check if value is a Litteral Specification
                ValueSpecification vSpec = pair.Value;
                if (vSpec.GetType().IsSubclassOf(typeof(LiteralSpecification)))
                {
                    // The value exist now get the Classifier
                    Type         type  = typeof(T);
                    IConvertible value = null;
                    if (type.Equals(typeof(System.Boolean)))
                    {
                        value = vSpec.getBoolFromValue();
                    }
                    else if (type.Equals(typeof(System.Int32)))
                    {
                        value = vSpec.getIntFromValue();
                    }
                    else if (type.Equals(typeof(System.Double)) || type.Equals(typeof(System.Single)))
                    {
                        value = vSpec.getDoubleFromValue();
                    }
                    else
                    {
                        value = vSpec.getStringFromValue();
                    }

                    dict.Add(pair.Key, (T)value);
                }
            }

            return(dict);
        }
Ejemplo n.º 13
0
        public Entity Clone()
        {
            MascaretApplication.Instance.VRComponentFactory.Log(" ######## Cloning : " + this.name);

            Entity clone = new Entity(this.name, (EntityClass)(this.Classifier));

            /*foreach (Slot slot in this.Slots.Values)
             * {
             *
             *  //clone.Slots.Add(slot.getValue().getStringFromValue(), slot);
             *
             *  //Slot s = new Slot();
             *
             *  foreach (KeyValuePair<string, ValueSpecification> pair in slot.Values)
             *  {
             *      //clone.Slots.Add(pair.Value.getStringFromValue(), slot);
             *      ValueSpecification val = pair.Value.clone();
             *      //s.addValue(val);
             *  }
             *  clone.Slots.Add(slot.getValue().getStringFromValue(), s);
             * }*/

            foreach (KeyValuePair <string, Slot> slot in this.Slots)
            {
                MascaretApplication.Instance.VRComponentFactory.Log(" ######## Add Value for : " + slot.Value.DefiningProperty.name);

                //clone.addSlot(slot.Value.DefiningProperty);
                Slot s = clone.getProperty(slot.Value.DefiningProperty.name);

                foreach (KeyValuePair <string, ValueSpecification> pair in slot.Value.Values)
                {
                    ValueSpecification val = pair.Value.clone();
                    s.addValue(val);
                }
            }

            return(clone);
        }
Ejemplo n.º 14
0
        public override ValueSpecification createValueFromString(string str)
        {
            string             type      = unit.Classifier.name;
            ValueSpecification valueSpec = null;

            if (type == "real" || type == "double")
            {
                valueSpec = new LiteralReal(str);
            }
            else if (type == "integer")
            {
                valueSpec = new LiteralInteger(str);
            }
            else if (type == "string")
            {
                valueSpec = new LiteralString(str);
            }
            else if (type == "boolean")
            {
                valueSpec = new LiteralBoolean(str);
            }

            return(valueSpec);
        }
Ejemplo n.º 15
0
 public Port(string name, Class cl, Classifier type, Property opposite, ValueSpecification def, DomainSpecification domain)
     : base(name, cl, type, opposite, def, domain)
 {
 }
Ejemplo n.º 16
0
 public FlowPort(string name, Class cl, Classifier type, Property opposite, ValueSpecification def, DomainSpecification domain) :
     base(name, cl, type, opposite, def, domain)
 {
 }
Ejemplo n.º 17
0
 public new void addValue(ValueSpecification val)
 {
     System.Console.WriteLine("Can't add values in a derived slot");
 }
Ejemplo n.º 18
0
 public new void addValue(ValueSpecification val)
 {
     System.Console.WriteLine("Can't add values in a derived slot");
 }