Esempio n. 1
0
        /// <summary>
        /// Coputes targets from the function and adds them to the collection
        /// </summary>
        /// <param name="function">Function containing targets</param>
        /// <param name="collection">Collection to be filled with targets</param>
        private void ComputeTargets(Function function, Values.ListValue collection)
        {
            if (function != null)
            {
                Graph graph = function.Graph;
                if (graph != null && graph.Segments.Count > 1)
                {
                    double prevSpeed = Double.MaxValue;
                    for (int i = 1; i < graph.Segments.Count; i++)
                    {
                        Graph.Segment         s             = graph.Segments[i];
                        Types.Structure       structureType = (Types.Structure)EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Kernel.SpeedAndDistanceMonitoring.TargetSupervision"), "Kernel.SpeedAndDistanceMonitoring.TargetSupervision.Target");
                        Values.StructureValue value         = new Values.StructureValue(structureType, structureType.NameSpace);

                        Variables.Variable speed = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                        speed.Type      = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Speed");
                        speed.Name      = "Speed";
                        speed.Mode      = Generated.acceptor.VariableModeEnumType.aInternal;
                        speed.Default   = "0.0";
                        speed.Enclosing = value;
                        speed.Value     = new Values.DoubleValue(EFSSystem.DoubleType, s.Val(s.Start));
                        value.set(speed);

                        Variables.Variable location = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                        location.Type      = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Distance");
                        location.Name      = "Location";
                        location.Mode      = Generated.acceptor.VariableModeEnumType.aInternal;
                        location.Default   = "0.0";
                        location.Enclosing = value;
                        location.Value     = new Values.DoubleValue(EFSSystem.DoubleType, s.Start);
                        value.set(location);

                        Variables.Variable length = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                        length.Type      = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Length");
                        length.Name      = "Length";
                        length.Mode      = Generated.acceptor.VariableModeEnumType.aInternal;
                        length.Default   = "0.0";
                        length.Enclosing = value;
                        length.Value     = new Values.DoubleValue(EFSSystem.DoubleType, s.End);
                        value.set(length);

                        if (s.Val(s.Start) < prevSpeed)
                        {
                            collection.Val.Add(value);
                        }
                        prevSpeed = s.Val(s.Start);
                    }
                }
            }
        }
        /// <summary>
        /// Provides the value associated to this Expression
        /// </summary>
        /// <param name="instance">The instance on which the value is computed</param>
        /// <param name="localScope">The local scope used to compute the value of this expression</param>
        /// <param name="globalFind">Indicates that the search should be performed globally</param>
        /// <returns></returns>
        public override Values.IValue GetValue(InterpretationContext context)
        {
            Values.StructureValue retVal = null;

            Types.Structure structureType = Structure.GetExpressionType() as Types.Structure;
            if (structureType != null)
            {
                retVal = new Values.StructureValue(structureType, Root);

                foreach (KeyValuePair <string, Expression> pair in Associations)
                {
                    Values.IValue      val = pair.Value.GetValue(new InterpretationContext(context));
                    Variables.Variable var = (Variables.Variable)Generated.acceptor.getFactory().createVariable();
                    var.Name      = pair.Key;
                    var.Value     = val;
                    var.Enclosing = retVal;
                    retVal.set(var);
                }
            }
            else
            {
                AddError("Cannot determine structure type for " + ToString());
            }

            return(retVal);
        }
        /// <summary>
        /// Coputes targets from the function and adds them to the collection
        /// </summary>
        /// <param name="function">Function containing targets</param>
        /// <param name="collection">Collection to be filled with targets</param>
        private void ComputeTargets(Function function, Values.ListValue collection)
        {
            if (function != null)
            {
                Graph graph = function.Graph;
                if (graph != null && graph.Segments.Count > 1)
                {
                    double prevSpeed = Double.MaxValue;
                    for (int i = 1; i < graph.Segments.Count; i++)
                    {
                        Graph.Segment s = graph.Segments[i];
                        Types.Structure structureType = (Types.Structure)EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Kernel.SpeedAndDistanceMonitoring.TargetSupervision"), "Kernel.SpeedAndDistanceMonitoring.TargetSupervision.Target");
                        Values.StructureValue value = new Values.StructureValue(structureType, structureType.NameSpace);

                        Variables.Variable speed = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                        speed.Type = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Speed");
                        speed.Name = "Speed";
                        speed.Mode = Generated.acceptor.VariableModeEnumType.aInternal;
                        speed.Default = "0.0";
                        speed.Enclosing = value;
                        speed.Value = new Values.DoubleValue(EFSSystem.DoubleType, s.Val(s.Start));
                        value.set(speed);

                        Variables.Variable location = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                        location.Type = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Distance");
                        location.Name = "Location";
                        location.Mode = Generated.acceptor.VariableModeEnumType.aInternal;
                        location.Default = "0.0";
                        location.Enclosing = value;
                        location.Value = new Values.DoubleValue(EFSSystem.DoubleType, s.Start);
                        value.set(location);

                        Variables.Variable length = (Variables.Variable)DataDictionary.Generated.acceptor.getFactory().createVariable();
                        length.Type = EFSSystem.findType(OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"), "Default.BaseTypes.Length");
                        length.Name = "Length";
                        length.Mode = Generated.acceptor.VariableModeEnumType.aInternal;
                        length.Default = "0.0";
                        length.Enclosing = value;
                        length.Value = new Values.DoubleValue(EFSSystem.DoubleType, s.End);
                        value.set(length);

                        if (s.Val(s.Start) < prevSpeed)
                        {
                            collection.Val.Add(value);
                        }
                        prevSpeed = s.Val(s.Start);
                    }
                }
            }
        }
        /// <summary>
        /// Provides the value associated to this Expression
        /// </summary>
        /// <param name="instance">The instance on which the value is computed</param>
        /// <param name="localScope">The local scope used to compute the value of this expression</param>
        /// <param name="globalFind">Indicates that the search should be performed globally</param>
        /// <returns></returns>
        public override Values.IValue GetValue(InterpretationContext context)
        {
            Values.StructureValue retVal = null;

            Types.Structure structureType = Structure.GetExpressionType() as Types.Structure;
            if (structureType != null)
            {
                retVal = new Values.StructureValue(structureType, Root);

                foreach (KeyValuePair<string, Expression> pair in Associations)
                {
                    Values.IValue val = pair.Value.GetValue(new InterpretationContext(context));
                    Variables.Variable var = (Variables.Variable)Generated.acceptor.getFactory().createVariable();
                    var.Name = pair.Key;
                    var.Value = val;
                    var.Enclosing = retVal;
                    retVal.set(var);
                }
            }
            else
            {
                AddError("Cannot determine structure type for " + ToString());
            }

            return retVal;
        }