Ejemplo 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, ListValue collection)
        {
            if (function != null)
            {
                Graph graph = function.Graph;
                if (graph != null && graph.Segments.Count > 1)
                {
                    double prevSpeed = graph.Segments[0].Evaluate(graph.Segments[0].Start);
                    for (int i = 1; i < graph.Segments.Count; i++)
                    {
                        Graph.Segment s = graph.Segments[i];
                        Structure structureType =
                            (Structure)
                                EFSSystem.FindType(
                                    OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0],
                                        "Kernel.SpeedAndDistanceMonitoring.TargetSpeedMonitoring"),
                                    "Kernel.SpeedAndDistanceMonitoring.TargetSpeedMonitoring.Target");
                        StructureValue value = new StructureValue(structureType);

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

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

                        Variable length = (Variable) acceptor.getFactory().createVariable();
                        length.Type =
                            EFSSystem.FindType(
                                OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0],
                                    "Default.BaseTypes"), "Default.BaseTypes.Length");
                        length.Name = "Length";
                        length.Mode = acceptor.VariableModeEnumType.aInternal;
                        length.Default = "0.0";
                        length.Enclosing = value;
                        length.Value = SegmentLength(s.End);
                        value.set(length);

                        // Only add the target for the current segment to the collection if it brings a reduction in permitted speed
                        if (s.Evaluate(s.Start) < prevSpeed)
                        {
                            collection.Val.Add(value);
                        }
                        // But even if it is not added to the collection of targets, this segment is now the reference speed
                        prevSpeed = s.Evaluate(s.Start);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Creates a single target
        /// </summary>
        /// <param name="start"></param>
        /// <param name="length"></param>
        /// <param name="speed"></param>
        /// <returns></returns>
        private StructureValue CreateTarget(double start, double length, double speed)
        {
            Structure structureType =
                (Structure)
                    EFSSystem.FindType(
                        OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0],
                            "Kernel.SpeedAndDistanceMonitoring.TargetSpeedMonitoring"),
                        "Kernel.SpeedAndDistanceMonitoring.TargetSpeedMonitoring.Target");
            StructureValue value = new StructureValue(structureType);

            Variable speedV = (Variable) acceptor.getFactory().createVariable();
            speedV.Type =
                EFSSystem.FindType(
                    OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"),
                    "Default.BaseTypes.Speed");
            speedV.Name = "Speed";
            speedV.Mode = acceptor.VariableModeEnumType.aInternal;
            speedV.Default = "0.0";
            speedV.Enclosing = value;
            speedV.Value = new DoubleValue(EFSSystem.DoubleType, speed);
            value.set(speedV);

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

            Variable lengthV = (Variable) acceptor.getFactory().createVariable();
            lengthV.Type =
                EFSSystem.FindType(
                    OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Default.BaseTypes"),
                    "Default.BaseTypes.Length");
            lengthV.Name = "Length";
            lengthV.Mode = acceptor.VariableModeEnumType.aInternal;
            lengthV.Default = "0.0";
            lengthV.Enclosing = value;
            lengthV.Value = new DoubleValue(EFSSystem.DoubleType, length);
            value.set(lengthV);
            return value;
        }
            /// <summary>
            ///     Executes the action requested by this tool strip button
            /// </summary>
            protected override void OnClick(EventArgs e)
            {
                Collection collectionType = (Collection) Variable.Type;
                Structure structureType = (Structure) collectionType.Type;
                StructureValue element = new StructureValue(structureType, false);

                if (structureType.Elements.Count == 1)
                {
                    StructureElement subElement = (StructureElement) structureType.Elements[0];
                    Structure subElementStructureType = subElement.Type as Structure;
                    if (subElementStructureType != null)
                    {
                        Variable subVariable = CreateVariable(subElement);
                        element.set(subVariable);
                    }
                }

                Variable.Value = Variable.Value.RightSide(Variable, false, true) as ListValue;
                ListValue value = Variable.Value as ListValue;
                if (value != null)
                {
                    for (int i = 0; i < value.Val.Count; i++)
                    {
                        if (value.Val[i] == EFSSystem.INSTANCE.EmptyValue)
                        {
                            value.Val[i] = element;
                            element.Enclosing = Variable.Value;
                            break;
                        }
                    }
                }

                base.OnClick(e);
            }