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)); } }
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); }