private SectorlineCoordinate ParseCoordinate(SectorData data) { if (data.dataSegments.Count != 3) { this.errorLog.AddEvent(new SyntaxError("Invalid number of SECTORLINE COORD segements", data)); throw new ArgumentException(); } Coordinate parsedCoordinate = CoordinateParser.Parse( data.dataSegments[1], data.dataSegments[2] ); if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate)) { this.errorLog.AddEvent(new SyntaxError("Invalid SECTORLINE coordinate", data)); throw new ArgumentException(); } return(new SectorlineCoordinate( parsedCoordinate, data.definition, data.docblock, data.inlineComment )); }
public void ParseData(AbstractSectorDataFile data) { foreach (SectorData line in data) { if (line.dataSegments.Count != 3) { this.eventLogger.AddEvent( new SyntaxError("Incorrect number of FIX segments", line) ); continue; } // Parse the coordinate Coordinate parsedCoordinate = CoordinateParser.Parse(line.dataSegments[1], line.dataSegments[2]); if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate)) { this.eventLogger.AddEvent( new SyntaxError("Invalid coordinate format: " + data.CurrentLine, line) ); return; } this.elements.Add( new Fix(line.dataSegments[0], parsedCoordinate, line.definition, line.docblock, line.inlineComment) ); } }
public void ParseData(AbstractSectorDataFile data) { foreach (SectorData line in data) { if (line.dataSegments.Count != 4) { this.errorLog.AddEvent( new SyntaxError("Incorrect number of Freetext segments", line) ); return; } Coordinate parsedCoordinate = CoordinateParser.Parse(line.dataSegments[0], line.dataSegments[1]); if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate)) { this.errorLog.AddEvent( new SyntaxError("Invalid coordinate format: " + data.CurrentLine, line) ); return; } this.sectorElements.Add( new Freetext( line.dataSegments[2], line.dataSegments[3], parsedCoordinate, line.definition, line.docblock, line.inlineComment ) ); } }
public void ParseData(AbstractSectorDataFile data) { foreach (SectorData line in data) { if (line.dataSegments.Count != 4) { eventLogger.AddEvent(new SyntaxError("Invalid number of runway centreline segments", line)); return; } if (!CoordinateParser.TryParse(line.dataSegments[0], line.dataSegments[1], out Coordinate firstCoordinate)) { eventLogger.AddEvent(new SyntaxError("Invalid first runway centreline coordinate", line)); return; } if (!CoordinateParser.TryParse(line.dataSegments[2], line.dataSegments[3], out Coordinate secondCoordinate)) { eventLogger.AddEvent(new SyntaxError("Invalid second runway centreline coordinate", line)); return; } // Create the segment once and share it to save memory RunwayCentrelineSegment segment = new(firstCoordinate, secondCoordinate); sectorElements.Add(new RunwayCentreline(segment, line.definition, line.docblock, line.inlineComment)); sectorElements.Add(new FixedColourRunwayCentreline(segment, line.definition, line.docblock, line.inlineComment)); } }
public void ParseData(AbstractSectorDataFile data) { foreach (SectorData line in data) { // Check everything starts ok if (line.rawData.Count(c => c == '"') != 2) { this.eventLogger.AddEvent( new SyntaxError("Labels may contain exactly two double quotes", line) ); continue; } if (line.rawData[0] != '"') { this.eventLogger.AddEvent( new SyntaxError("Labels must start with a name encased in quotes", line) ); continue; } // Get the name out and take the name segments off int endOfNameIndex = this.GetEndOfNameIndex(line); string name = string.Join(' ', line.dataSegments.GetRange(0, endOfNameIndex)).Trim('"'); line.dataSegments.RemoveRange(0, endOfNameIndex); if (line.dataSegments.Count != 3) { this.eventLogger.AddEvent( new SyntaxError("Invalid number of LABEL segments, expected 3", line) ); continue; } // Parse the position coordinate Coordinate parsedCoordinate = CoordinateParser.Parse(line.dataSegments[0], line.dataSegments[1]); if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate)) { this.eventLogger.AddEvent( new SyntaxError("Invalid label coordinate format: " + data.CurrentLine, line) ); continue; } // Add to the sector elements sectorElements.Add( new Label( name, parsedCoordinate, line.dataSegments[2], line.definition, line.docblock, line.inlineComment ) ); } }
public void ParseData(AbstractSectorDataFile data) { foreach (SectorData line in data) { if (line.dataSegments.Count != 4) { this.eventLogger.AddEvent( new SyntaxError("Incorrect number of VOR segments", line) ); continue; } // Check the identifier if ( line.dataSegments[0].Any(char.IsDigit) || (line.dataSegments[0].Length != 2 && line.dataSegments[0].Length != 3) ) { this.eventLogger.AddEvent( new SyntaxError("Invalid VOR identifier: " + line.dataSegments[1], line) ); return; } // Parse the frequency if (this.frequencyParser.ParseFrequency(line.dataSegments[1]) == null) { this.eventLogger.AddEvent( new SyntaxError("Invalid VOR frequency: " + line.dataSegments[1], line) ); return; } // Parse the coordinate Coordinate parsedCoordinate = CoordinateParser.Parse(line.dataSegments[2], line.dataSegments[3]); if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate)) { this.eventLogger.AddEvent( new SyntaxError("Invalid coordinate format: " + data.CurrentLine, line) ); return; } this.elements.Add( new Vor( line.dataSegments[0], line.dataSegments[1], parsedCoordinate, line.definition, line.docblock, line.inlineComment ) ); } }
private InfoLongitude GetLongitude(SectorData latitude, SectorData longitude) { if (CoordinateParser.Parse(latitude.rawData, longitude.rawData).Equals(CoordinateParser.InvalidCoordinate)) { this.eventLogger.AddEvent( new SyntaxError("Invalid INFO coordinate", latitude.rawData) ); throw new ArgumentNullException(); } return(new InfoLongitude(longitude.rawData, longitude.definition, longitude.docblock, longitude.inlineComment)); }
public void ParseData(AbstractSectorDataFile data) { // Validate the folder name if (!AirportValidator.ValidEuroscopeAirport(data.GetParentDirectoryName())) { this.eventLogger.AddEvent( new SyntaxError("Invalid airport ICAO", data.FullPath) ); return; } int linesParsed = 0; SectorData nameLine = new SectorData(); SectorData coordinateLine = new SectorData(); SectorData frequencyLine = new SectorData(); // Loop the lines to get the data out foreach (SectorData line in data) { if (linesParsed == 0) { nameLine = line; linesParsed++; continue; } else if (linesParsed == 1) { coordinateLine = line; linesParsed++; continue; } else if (linesParsed == 2) { frequencyLine = line; linesParsed++; continue; } this.eventLogger.AddEvent( new SyntaxError("Invalid number of airport lines", line) ); return; } // Check the syntax if (linesParsed != 3) { this.eventLogger.AddEvent( new SyntaxError("Invalid number of airport lines", data.FullPath) ); return; } // Parse the coordinate if (coordinateLine.dataSegments.Count != 2) { this.eventLogger.AddEvent( new SyntaxError("Invalid coordinate format for airport: " + coordinateLine.rawData, coordinateLine) ); return; } Coordinate parsedCoordinate = CoordinateParser.Parse(coordinateLine.dataSegments[0], coordinateLine.dataSegments[1]); if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate)) { this.eventLogger.AddEvent( new SyntaxError("Invalid coordinate format for airport: " + coordinateLine.rawData, coordinateLine) ); return; } this.elements.Add( new Airport( nameLine.rawData, data.GetParentDirectoryName(), parsedCoordinate, frequencyLine.rawData, nameLine.definition, nameLine.docblock, nameLine.inlineComment ) ); }
private List <GroundNetworkCoordinate> ProcessCoordinates( AbstractSectorDataFile file, List <SectorData> lines, string parentElementType ) { if (lines.Count == 0) { errorLog.AddEvent( new SyntaxError( $"All ground network {parentElementType} declarations must have at least one coordinate", file.GetFileName() ) ); throw new ArgumentException(); } List <GroundNetworkCoordinate> coordinates = new(); for (int i = 0; i < lines.Count; i++) { SectorData line = lines[i]; if (line.dataSegments.Count != 3) { errorLog.AddEvent( new SyntaxError($"Invalid number of {parentElementType} COORD segments", lines[i]) ); throw new ArgumentException(); } if (line.dataSegments[0] != "COORD") { errorLog.AddEvent( new SyntaxError($"Invalid COORD in {parentElementType} declaration", lines[i]) ); throw new ArgumentException(); } if ( !CoordinateParser.TryParse( line.dataSegments[1], line.dataSegments[2], out Coordinate parsedCoordinate ) ) { errorLog.AddEvent( new SyntaxError($"Invalid coordinate in {parentElementType} declaration", lines[i]) ); throw new ArgumentException(); } coordinates.Add( new GroundNetworkCoordinate( parsedCoordinate, line.definition, line.docblock, line.inlineComment ) ); } return(coordinates); }
private void ParseCircleSectorline(ref List <SectorData> lines) { // Deal with the declaration line SectorData declarationLine = lines[0]; if (declarationLine.dataSegments.Count != 4 && declarationLine.dataSegments.Count != 5) { this.errorLog.AddEvent( new SyntaxError("Incorrect number of segments for SECTORLINE declaration", declarationLine) ); throw new ArgumentException(); } Coordinate parsedCoordinate = new Coordinate("", ""); if (declarationLine.dataSegments.Count == 5) { parsedCoordinate = CoordinateParser.Parse( declarationLine.dataSegments[2], declarationLine.dataSegments[3] ); if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate)) { this.errorLog.AddEvent( new SyntaxError("Invalid CIRCLE_SECTORLINE coordinate", declarationLine) ); throw new ArgumentException(); } } if ( double.TryParse( declarationLine.dataSegments.Count == 4 ? declarationLine.dataSegments[3] : declarationLine.dataSegments[4], out double radius) == false) { this.errorLog.AddEvent( new SyntaxError("Invalid CIRCLE_SECTORLINE radius", declarationLine) ); throw new ArgumentException(); } List <SectorlineDisplayRule> displayRules = new List <SectorlineDisplayRule>(); int i = 1; while (i < lines.Count) { SectorData displayData = lines[i]; displayRules.Add(this.ParseDisplayRule(displayData)); i++; } // Add the right type of circle sectorline if (declarationLine.dataSegments.Count == 4) { this.sectorElements.Add( new CircleSectorline( declarationLine.dataSegments[1], declarationLine.dataSegments[2], radius, displayRules, declarationLine.definition, declarationLine.docblock, declarationLine.inlineComment ) ); } else { this.sectorElements.Add( new CircleSectorline( declarationLine.dataSegments[1], parsedCoordinate, radius, displayRules, declarationLine.definition, declarationLine.docblock, declarationLine.inlineComment ) ); } }
public void ParseData(AbstractSectorDataFile data) { foreach (SectorData line in data) { // Runways are weird and have double spaces randomly, so handle it. if (line.dataSegments.Count < 8) { this.errorLog.AddEvent( new SyntaxError("Too few RUNWAY segments", line) ); continue; } // Check the two identifiers if (!RunwayValidator.RunwayValidIncludingAdjacent(line.dataSegments[0])) { this.errorLog.AddEvent( new SyntaxError("Invalid runway designator " + line.dataSegments[0], line) ); continue; } if (!RunwayValidator.RunwayValidIncludingAdjacent(line.dataSegments[1])) { this.errorLog.AddEvent( new SyntaxError("Invalid runway designator " + line.dataSegments[1], line) ); continue; } // Check the two headings if (!this.HeadingIsValid(line.dataSegments[2])) { this.errorLog.AddEvent( new SyntaxError("Invalid runway heading " + line.dataSegments[2], line) ); continue; } if (!this.HeadingIsValid(line.dataSegments[3])) { this.errorLog.AddEvent( new SyntaxError("Invalid runway heading " + line.dataSegments[3], line) ); continue; } // Check the two coordinates Coordinate firstThreshold = CoordinateParser.Parse(line.dataSegments[4], line.dataSegments[5]); if (firstThreshold.Equals(CoordinateParser.InvalidCoordinate)) { this.errorLog.AddEvent( new SyntaxError("Invalid runway first threshold ", line) ); continue; } Coordinate reverseThreshold = CoordinateParser.Parse(line.dataSegments[6], line.dataSegments[7]); if (reverseThreshold.Equals(CoordinateParser.InvalidCoordinate)) { this.errorLog.AddEvent( new SyntaxError("Invalid runway reverse threshold ", line) ); continue; } // Compile together the airfield description if (line.dataSegments.Count > 8) { string.Join( " ", line.dataSegments .Skip(8) .Take(line.dataSegments.Count - 8) .ToList() ); } // Add the element this.sectorElements.Add( new Runway( data.GetParentDirectoryName(), line.dataSegments[0], int.Parse(line.dataSegments[2]), firstThreshold, line.dataSegments[1], int.Parse(line.dataSegments[3]), reverseThreshold, line.definition, line.docblock, line.inlineComment ) ); } }