コード例 #1
0
        /// <summary>
        /// Generate train drawing information.
        /// </summary>
        /// <returns>A series of train drawing information objects containing drawing instructions.</returns>
        public IEnumerable <TrainDrawingInfo> GetTrainDrawingInformation()
        {
            RecomputeTimeBase();
            RecomputeLocationCoordinates();

            foreach (Train train in TrainList.Where(t => t.TrainTimes?.Count > 0))
            {
                TrainDrawingInfo tdi = new TrainDrawingInfo {
                    Properties = train.GraphProperties, Headcode = train.Headcode, Train = train
                };
                for (int i = 0; i < train.TrainTimes.Count; ++i)
                {
                    if (train.TrainTimes[i]?.ArrivalTime?.Time != null && train.TrainTimes[i]?.DepartureTime?.Time != null)
                    {
                        double locationCoordinate = _locationCoordinates[train.TrainTimes[i].Location.Id];
                        tdi.Lines.Add(new LineCoordinates(
                                          new VertexInformation(tdi, train.TrainTimes[i].ArrivalTime.Time, ArrivalDepartureOptions.Arrival, GetXPositionFromTime(train.TrainTimes[i].ArrivalTime.Time),
                                                                locationCoordinate),
                                          new VertexInformation(tdi, train.TrainTimes[i].DepartureTime.Time, ArrivalDepartureOptions.Departure, GetXPositionFromTime(train.TrainTimes[i].DepartureTime.Time),
                                                                locationCoordinate)));
                    }
                    if (i > 0 && train.TrainTimes[i - 1]?.DepartureTime?.Time != null)
                    {
                        VertexInformation startVertex =
                            new VertexInformation(tdi, train.TrainTimes[i - 1].DepartureTime.Time, ArrivalDepartureOptions.Departure,
                                                  GetXPositionFromTime(train.TrainTimes[i - 1].DepartureTime.Time), _locationCoordinates[train.TrainTimes[i - 1].Location.Id]);
                        double endY = _locationCoordinates[train.TrainTimes[i].Location.Id];
                        if (train.TrainTimes[i]?.ArrivalTime?.Time != null)
                        {
                            tdi.Lines.Add(new LineCoordinates(startVertex, new VertexInformation(tdi, train.TrainTimes[i].ArrivalTime.Time, ArrivalDepartureOptions.Arrival,
                                                                                                 GetXPositionFromTime(train.TrainTimes[i].ArrivalTime.Time), endY)));
                        }
                        else if (train.TrainTimes[i]?.DepartureTime?.Time != null)
                        {
                            tdi.Lines.Add(new LineCoordinates(startVertex, new VertexInformation(tdi, train.TrainTimes[i].DepartureTime.Time, ArrivalDepartureOptions.Departure,
                                                                                                 GetXPositionFromTime(train.TrainTimes[i].DepartureTime.Time), endY)));
                        }
                    }
                }

                yield return(tdi);
            }
        }
コード例 #2
0
 /// <summary>
 /// Constructor which sets the vertex properties.
 /// </summary>
 /// <param name="v1">The first vertex.</param>
 /// <param name="v2">The second vertex.</param>
 public LineCoordinates(VertexInformation v1, VertexInformation v2)
 {
     Vertex1 = v1;
     Vertex2 = v2;
 }