Beispiel #1
0
        //Split the path
        private void IniBusLineAnimation()
        {
            bool         flag     = false;
            List <Point> tempList = new List <Point>();

            traces.Clear();

            for (int i = 0; i < Route.Count; i++)
            {
                RoadPoint rp = Route.ElementAt <RoadPoint>(i);
                if (rp is RoadStop)
                {
                    if (flag)
                    {
                        tempList.Add(rp.Coordinate);
                        traces.Add(tempList.ToArray());

                        if (i != Route.Count - 1)
                        {
                            tempList = new List <Point>();
                        }
                    }
                    else
                    {
                        flag = true;
                    }
                }
                tempList.Add(rp.Coordinate);
            }
        }
Beispiel #2
0
        public static void InitBus(string buslineconfig, Canvas Carrier)
        {
            StopBase.StopTable.Clear();
            BusLineBase.BusLineTable.Clear();
            TextReader tr   = new StreamReader(buslineconfig);
            String     line = tr.ReadLine();

            int lineNo = 0;

            while (line != null)
            {
                List <RoadPoint> route    = new List <RoadPoint>();
                string           linename = line.Substring(0, line.IndexOf(":"));
                line = line.Substring(line.IndexOf(":") + 1);
                string[] points = line.Split(';');
                for (int i = 0; i < points.Length; i++)
                {
                    string point = points[i];
                    if (!point[0].Equals('('))
                    {
                        string   stopname = point.Substring(0, point.IndexOf("("));
                        RoadStop rs       = null;
                        if (!StopBase.StopTable.TryGetValue(stopname, out rs))
                        {
                            int x = Convert.ToInt32(point.Substring(point.IndexOf("(") + 1, point.IndexOf(",") - point.IndexOf("(") - 1));
                            int y = Convert.ToInt32(point.Substring(point.IndexOf(",") + 1, point.IndexOf(")") - point.IndexOf(",") - 1));

                            rs = new RoadStop(x, y, stopname);
                            StopBase.StopTable.Add(stopname, rs);
                        }
                        if (i + 1 != points.Length)
                        {
                            rs.AddBusLine(linename);
                        }
                        route.Add(rs);
                    }
                    else
                    {
                        int       x  = Convert.ToInt32(point.Substring(point.IndexOf("(") + 1, point.IndexOf(",") - point.IndexOf("(") - 1));
                        int       y  = Convert.ToInt32(point.Substring(point.IndexOf(",") + 1, point.IndexOf(")") - point.IndexOf(",") - 1));
                        RoadPoint rp = new RoadPoint(x, y);
                        route.Add(rp);
                    }
                }
                BusLineBase.BusLineTable.Add(linename, new Bus(route, linename, Carrier, colors[lineNo / 2]));
                line = tr.ReadLine();
                lineNo++;

                //break;
            }

            //Calculate Stops that are opposite to each other
            for (int i = 0; i < StopBase.StopTable.Values.Count; i++)
            {
                RoadStop rs1 = StopBase.StopTable.Values.ElementAt <RoadStop>(i);
                for (int j = i + 1; j < StopBase.StopTable.Values.Count; j++)
                {
                    RoadStop rs2 = StopBase.StopTable.Values.ElementAt <RoadStop>(j);
                    if (isClose(rs1.Coordinate, rs2.Coordinate))
                    {
                        rs1.Opposite = rs2;
                        rs2.Opposite = rs1;
                        break;
                    }
                }
            }
        }