private int GetFirstPointIndex(SectorData sectorData)
        {
            bool foundSecondPoint = false;

            for (int i = sectorData.dataSegments.Count - 2; i >= 0;)
            {
                // Work til we find the first valid point
                if (!PointParser.Parse(sectorData.dataSegments[i], sectorData.dataSegments[i + 1]).Equals(PointParser.InvalidPoint))
                {
                    // We've found the second valid point
                    if (!foundSecondPoint)
                    {
                        foundSecondPoint = true;
                        i -= 2;
                        continue;
                    }

                    // Found the first valid point
                    return(i);
                }

                i--;
            }

            return(-1);
        }
Exemplo n.º 2
0
        /**
         * The name in this format of line can be determined to mean all data segments up until the first coordinate.
         */
        private int GetEndOfNameIndex(SectorData line)
        {
            for (int i = 0; i < line.dataSegments.Count - 1; i++)
            {
                if (!PointParser.Parse(line.dataSegments[i], line.dataSegments[i + 1]).Equals(PointParser.InvalidPoint))
                {
                    return(i);
                }
            }

            return(-1);
        }
        /**
         * Process an individual SID/STARs worth of lines
         */
        private void ProcessSidStar(List <SectorData> lines)
        {
            // Get the name out and remove it from the array
            int firstLineFirstCoordinateIndex = this.GetFirstPointIndex(lines[0]);

            if (firstLineFirstCoordinateIndex == -1)
            {
                this.errorLog.AddEvent(
                    new SyntaxError("Invalid SID/STAR route segment coordinates", lines[0])
                    );
                return;
            }

            string sidStarName = string.Join(" ", lines[0].dataSegments.GetRange(0, firstLineFirstCoordinateIndex));

            lines[0].dataSegments.RemoveRange(0, firstLineFirstCoordinateIndex);
            List <RouteSegment> segments = new List <RouteSegment>();


            for (int i = 0; i < lines.Count; i++)
            {
                segments.Add(
                    new RouteSegment(
                        sidStarName,
                        PointParser.Parse(lines[i].dataSegments[0], lines[i].dataSegments[1]),
                        PointParser.Parse(lines[i].dataSegments[2], lines[i].dataSegments[3]),
                        lines[i].definition,
                        lines[i].docblock,
                        lines[i].inlineComment,
                        lines[i].dataSegments.Count == 5 ? lines[i].dataSegments[4] : null
                        )
                    );
            }

            RouteSegment initialSegment = segments.ElementAt(0);

            segments.RemoveAt(0);

            this.sectorElements.Add(
                new SidStarRoute(
                    this.Type,
                    sidStarName,
                    initialSegment,
                    segments,
                    lines[0].definition,
                    lines[0].docblock,
                    lines[0].inlineComment
                    )
                );
        }
Exemplo n.º 4
0
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count < 5)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Incorrect number of ARTCC segments", line)
                        );
                    continue;
                }

                int count = line.dataSegments.Count;

                // The points are at the end, so work backwards
                Point endPoint = PointParser.Parse(line.dataSegments[count - 2], line.dataSegments[count - 1]);
                if (endPoint.Equals(PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid ARTCC end point format: " + data.CurrentLine, line)
                        );
                    return;
                }

                Point startPoint = PointParser.Parse(line.dataSegments[count - 4], line.dataSegments[count - 3]);
                if (startPoint.Equals(PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid ARTCC start point format: " + data.CurrentLine, line)
                        );
                    return;
                }

                // Add it
                this.elements.Add(
                    new ArtccSegment(
                        string.Join(" ", line.dataSegments.GetRange(0, count - 4)),
                        this.artccType,
                        startPoint,
                        endPoint,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
Exemplo n.º 5
0
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 4)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Incorrect number of Airway segments", line)
                        );
                    continue;
                }

                // Parse the airway segment point
                Point startPoint = PointParser.Parse(line.dataSegments[0], line.dataSegments[1]);
                if (startPoint.Equals(PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid Airway start point format: " + data.CurrentLine, line)
                        );
                    return;
                }


                // Parse the segment endpoint
                Point endPoint = PointParser.Parse(line.dataSegments[2], line.dataSegments[3]);
                if (endPoint.Equals(PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid Airway end point format: " + data.CurrentLine, line)
                        );
                    return;
                }

                // Add it to the collection
                this.elements.Add(
                    new AirwaySegment(
                        data.GetFileName(),  // Each airway is in a file with its name
                        this.airwayType,
                        startPoint,
                        endPoint,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
Exemplo n.º 6
0
        /*
         * Parses an individual GEO segment of coordinates and colours
         */
        private GeoSegment ParseGeoSegment(SectorData line)
        {
            if (line.dataSegments.Count < 4 || line.dataSegments.Count > 5)
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Incorrect number parts for GEO segment", line)
                    );
                throw new ArgumentException();
            }

            // Parse the first coordinate
            Point parsedStartPoint = PointParser.Parse(line.dataSegments[0], line.dataSegments[1]);

            if (parsedStartPoint.Equals(PointParser.InvalidPoint))
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid GEO segment point format", line)
                    );
                throw new ArgumentException();
            }

            // Parse the end coordinate
            Point parsedEndPoint = PointParser.Parse(line.dataSegments[2], line.dataSegments[3]);

            if (parsedEndPoint.Equals(PointParser.InvalidPoint))
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid GEO segment point format", line)
                    );
                throw new ArgumentException();
            }

            return(new GeoSegment(
                       parsedStartPoint,
                       parsedEndPoint,
                       line.dataSegments.Count > 4 ? line.dataSegments[4] : null,
                       line.definition,
                       line.docblock,
                       line.inlineComment
                       ));
        }
Exemplo n.º 7
0
 private bool IsNameSegment(SectorData line)
 {
     return(line.dataSegments.Count >= 2 &&
            PointParser.Parse(line.dataSegments[0], line.dataSegments[1]).Equals(PointParser.InvalidPoint));
 }
Exemplo n.º 8
0
        public void ParseData(AbstractSectorDataFile data)
        {
            List <RegionPoint> points                = new List <RegionPoint>();
            bool       foundFirst                    = false;
            string     regionName                    = "";
            bool       expectingColourDefinition     = false;
            bool       expectingRegionNameDefinition = true;
            SectorData declarationLine               = new SectorData();

            foreach (SectorData line in data)
            {
                // Check for the first REGIONNAME
                if (expectingRegionNameDefinition && (line.dataSegments.Count < 2 || !line.rawData.StartsWith(RegionParser.RegionNameDeclaration)))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid first line of region " + data.CurrentLine, line)
                        );
                    return;
                }

                if (expectingColourDefinition && line.dataSegments.Count != 3)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Unexpected colour definition " + data.CurrentLine, line)
                        );
                    return;
                }

                // We've found our first region name if we get here for the first time, so we don't demand another in this file
                expectingRegionNameDefinition = false;

                // Expecting a colour definition for the region
                if (expectingColourDefinition)
                {
                    if (line.dataSegments.Count != 3)
                    {
                        this.eventLogger.AddEvent(
                            new SyntaxError("All regions must have a colour " + data.CurrentLine, line)
                            );
                        return;
                    }

                    // Setup a new segment
                    Point parsedNewPoint = PointParser.Parse(line.dataSegments[1], line.dataSegments[2]);
                    if (parsedNewPoint.Equals(PointParser.InvalidPoint))
                    {
                        this.eventLogger.AddEvent(
                            new SyntaxError("Invalid region point format: " + data.CurrentLine, line)
                            );
                        return;
                    }

                    points.Add(
                        new RegionPoint(
                            parsedNewPoint,
                            line.definition,
                            line.docblock,
                            line.inlineComment,
                            line.dataSegments[0]
                            )
                        );
                    expectingColourDefinition = false;
                    continue;
                }


                /*
                 * We've found a new REGIONNAME declaration, so must be the start of a new region.
                 */
                if (line.rawData.StartsWith(RegionParser.RegionNameDeclaration))
                {
                    // If it's not the first in the data stream, then it's a new declaration, save the previous
                    if (foundFirst)
                    {
                        if (points.Count == 0)
                        {
                            this.eventLogger.AddEvent(
                                new SyntaxError("Cannot have region with no points" + data.CurrentLine, line)
                                );
                            return;
                        }

                        this.elements.Add(
                            new Region(
                                regionName,
                                points,
                                declarationLine.definition,
                                declarationLine.docblock,
                                declarationLine.inlineComment
                                )
                            );

                        // Clear the segments array
                        points = new List <RegionPoint>();
                    }
                    else
                    {
                        foundFirst = true;
                    }

                    // Save the new declaration line
                    declarationLine = line;
                    regionName      = string.Join(" ", line.dataSegments.Skip(1));

                    // Immediately after REGIONNAME, we should expect a colour definition
                    expectingColourDefinition = true;
                    continue;
                }

                Point parsedPoint = PointParser.Parse(line.dataSegments[0], line.dataSegments[1]);
                if (Equals(parsedPoint, PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid region point format: " + data.CurrentLine, line)
                        );
                    return;
                }

                points.Add(
                    new RegionPoint(
                        parsedPoint,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }

            // We shouldn't end without a fully defined region
            if (expectingColourDefinition)
            {
                this.eventLogger.AddEvent(
                    new SyntaxError(
                        "Incomplete region at end of file",
                        data.FullPath
                        )
                    );
                return;
            }

            // Add the last element
            this.elements.Regions.Add(
                new Region(
                    regionName,
                    points,
                    declarationLine.definition,
                    declarationLine.docblock,
                    declarationLine.inlineComment
                    )
                );
        }