コード例 #1
0
 public PolyLine(PolyLine _copy) : base(_copy)
 {
     points = new List <double[]>(_copy.points);
 }
コード例 #2
0
        static void ReadESE(string _file)
        {
            List <PolyLine> deferred    = new List <PolyLine>();
            bool            isPositions = false;
            bool            isAirspace  = false;
            bool            isPolyLine  = false;
            bool            isSector    = false;

            using (FileStream fs = File.Open(_file, FileMode.Open, FileAccess.Read, FileShare.Read))
                using (BufferedStream bs = new BufferedStream(fs))
                    using (StreamReader sr = new StreamReader(bs))
                    {
                        string raw;
                        while ((raw = sr.ReadLine()) != null)
                        {
                            string live = raw.Split(';')[0];
                            live = live.Replace('\t', ' ');

                            if (raw.Length != 0 && raw.First() != ';')
                            {
                                if (raw.First() == '[')
                                {
                                    isPositions = false;
                                    isAirspace  = false;

                                    if (raw.ToUpper() == @"[POSITIONS]")
                                    {
                                        isPositions = true;
                                    }
                                    else if (raw.ToUpper() == @"[AIRSPACE]")
                                    {
                                        isAirspace = true;
                                    }
                                }
                                else if (isPositions)
                                {
                                    Controller.Add(live.Split(':'));
                                }
                                else if (isAirspace)
                                {
                                    if (raw.StartsWith("CIRCLE_SECTORLINE:"))
                                    {
                                        isPolyLine = false;
                                        isSector   = false;

                                        SectorLine.list.Add(new CircleLine(live.Split(':')));
                                    }
                                    else if (raw.StartsWith("SECTORLINE:"))
                                    {
                                        isPolyLine = true;
                                        isSector   = false;

                                        SectorLine.list.Add(new PolyLine(live.Split(':')));
                                    }
                                    else if (raw.StartsWith("SECTOR:"))
                                    {
                                        isPolyLine = false;
                                        isSector   = true;
                                        deferred   = new List <PolyLine>();

                                        if (Controller.listSorted == null)
                                        {
                                            Controller.listSorted = Controller.Sort(Controller.list);
                                        }

                                        string[] liveparts = live.Split(':');

                                        Sector.list.Add(new Sector(liveparts));
                                    }
                                    //else if (isCircleLine)
                                    //{

                                    //}
                                    else if (isPolyLine)
                                    {
                                        if (raw.StartsWith("COORD:"))
                                        {
                                            ((PolyLine)SectorLine.list.Last()).AddPoint(live.Split(':'));
                                        }
                                    }
                                    else if (isSector)
                                    {
                                        if (raw.StartsWith("OWNER:"))
                                        {
                                            string[] split = live.Split(':');

                                            for (int i = 1; i < split.Length; i++)
                                            {
                                                string part = split[i];

                                                if (part != "")
                                                {
                                                    foreach (Controller ctl in Controller.Find(part))
                                                    {
                                                        Sector.list.Last().owners.Add(ctl);
                                                    }
                                                }
                                            }
                                        }
                                        else if (raw.StartsWith("ACTIVE:"))
                                        {
                                            string[] split = live.Split(':');

                                            Airport apTemp = Airport.Find(split[1]);

                                            if (apTemp != null)
                                            {
                                                Sector.list.Last().runways.Add(Runway.Find(apTemp.ID, split[2]));
                                            }
                                        }
                                        else if (raw.StartsWith("BORDER:"))
                                        {
                                            string[] split = live.Split(':');

                                            for (int i = 1; i < split.Length; i++)
                                            {
                                                string     part = split[i];
                                                SectorLine line = SectorLine.Find(part);
                                                Sector     last = Sector.list.Last();

                                                if (line != null && line is PolyLine)
                                                {
                                                    PolyLine poly = new PolyLine((PolyLine)line);

                                                    if (last.lines.Count == 0)
                                                    {
                                                        last.lines.Add(poly);
                                                    }
                                                    else
                                                    {
                                                        if (poly.points[0].SequenceEqual(((PolyLine)last.lines.Last()).points.Last()))
                                                        {
                                                            last.lines.Add(poly);
                                                        }
                                                        else if (poly.points.Last().SequenceEqual(((PolyLine)last.lines.Last()).points.Last()))
                                                        {
                                                            poly.points.Reverse();
                                                            last.lines.Add(poly);
                                                        }
                                                        else if (poly.points[0].SequenceEqual(((PolyLine)last.lines[0]).points[0]))
                                                        {
                                                            poly.points.Reverse();
                                                            last.lines.Insert(0, poly);
                                                        }
                                                        else if (poly.points.Last().SequenceEqual(((PolyLine)last.lines[0]).points[0]))
                                                        {
                                                            last.lines.Insert(0, poly);
                                                        }
                                                        else
                                                        {
                                                            deferred.Add(poly);
                                                        }
                                                    }

                                                    bool isChanged = true;
                                                    while (deferred.Count > 0 && isChanged)
                                                    {
                                                        isChanged = false;

                                                        for (int j = deferred.Count - 1; j >= 0; j--)
                                                        {
                                                            PolyLine plyPly = deferred[j];

                                                            if (plyPly.points[0].SequenceEqual(((PolyLine)last.lines.Last()).points.Last()))
                                                            {
                                                                last.lines.Add(plyPly);
                                                                deferred.RemoveAt(j);
                                                                isChanged = true;
                                                            }
                                                            else if (plyPly.points.Last().SequenceEqual(((PolyLine)last.lines.Last()).points.Last()))
                                                            {
                                                                plyPly.points.Reverse();
                                                                last.lines.Add(plyPly);
                                                                deferred.RemoveAt(j);
                                                                isChanged = true;
                                                            }
                                                            else if (plyPly.points[0].SequenceEqual(((PolyLine)last.lines[0]).points[0]))
                                                            {
                                                                plyPly.points.Reverse();
                                                                last.lines.Insert(0, plyPly);
                                                                deferred.RemoveAt(j);
                                                                isChanged = true;
                                                            }
                                                            else if (plyPly.points.Last().SequenceEqual(((PolyLine)last.lines[0]).points[0]))
                                                            {
                                                                last.lines.Insert(0, plyPly);
                                                                deferred.RemoveAt(j);
                                                                isChanged = true;
                                                            }
                                                        }
                                                    }
                                                }
                                                else if (line is CircleLine)
                                                {
                                                    Sector.list.Last().lines.Add(line);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
        }