Esempio n. 1
0
void setup_airspaces(Airspaces& airspaces, const GeoPoint& center, const unsigned n) {
    std::ofstream *fin = NULL;

    if (verbose) {
        Directory::Create(_T("output/results"));
        fin = new std::ofstream("output/results/res-bb-in.txt");
    }

    for (unsigned i=0; i<n; i++) {
        AbstractAirspace* as;
        if (rand()%4!=0) {
            GeoPoint c;
            c.longitude = Angle::Degrees(fixed((rand()%1200-600)/1000.0))+center.longitude;
            c.latitude = Angle::Degrees(fixed((rand()%1200-600)/1000.0))+center.latitude;
            fixed radius(10000.0*(0.2+(rand()%12)/12.0));
            as = new AirspaceCircle(c,radius);
        } else {

            // just for testing, create a random polygon from a convex hull around
            // random points
            const unsigned num = rand()%10+5;
            GeoPoint c;
            c.longitude = Angle::Degrees(fixed((rand()%1200-600)/1000.0))+center.longitude;
            c.latitude = Angle::Degrees(fixed((rand()%1200-600)/1000.0))+center.latitude;

            std::vector<GeoPoint> pts;
            for (unsigned j=0; j<num; j++) {
                GeoPoint p=c;
                p.longitude += Angle::Degrees(fixed((rand()%200)/1000.0));
                p.latitude += Angle::Degrees(fixed((rand()%200)/1000.0));
                pts.push_back(p);
            }
            as = new AirspacePolygon(pts,true);
        }
        airspace_random_properties(*as);
        airspaces.Add(as);
        if (fin)
            *fin << *as;
    }

    delete fin;

    // try inserting nothing
    airspaces.Add(NULL);

    airspaces.Optimise();

}
Esempio n. 2
0
static bool
ParseFile(const TCHAR *path, Airspaces &airspaces)
{
  FileLineReader reader(path, ConvertLineReader::AUTO);

  if (!ok1(!reader.error())) {
    skip(1, 0, "Failed to read input file");
    return false;
  }

  AirspaceParser parser(airspaces);
  NullOperationEnvironment operation;

  if (!ok1(parser.Parse(reader, operation)))
    return false;

  airspaces.Optimise();
  return true;
}
Esempio n. 3
0
static bool
ParseFile(Path path, Airspaces &airspaces)
{
  Error error;
  FileLineReader reader(path, error, Charset::AUTO);

  if (!ok1(!reader.error())) {
    skip(1, 0, error.GetMessage());
    return false;
  }

  AirspaceParser parser(airspaces);
  NullOperationEnvironment operation;

  if (!ok1(parser.Parse(reader, operation)))
    return false;

  airspaces.Optimise();
  return true;
}
Esempio n. 4
0
static void
LoadFiles(ComputerSettings &settings)
{
  NullOperationEnvironment operation;

  topography = new TopographyStore();
  LoadConfiguredTopography(*topography, operation);

  terrain = RasterTerrain::OpenTerrain(NULL, operation);

  WaypointGlue::LoadWaypoints(way_points, terrain, operation);
  WaypointGlue::SetHome(way_points, terrain, settings, NULL, false);

  std::unique_ptr<TLineReader> reader(OpenConfiguredTextFile(ProfileKeys::AirspaceFile,
                                                             ConvertLineReader::AUTO));
  if (reader) {
    AirspaceParser parser(airspace_database);
    parser.Parse(*reader, operation);
    airspace_database.Optimise();
  }
}
Esempio n. 5
0
void
ReadAirspace(Airspaces &airspaces,
             RasterTerrain *terrain,
             const AtmosphericPressure &press,
             OperationEnvironment &operation)
{
    LogFormat("ReadAirspace");
    operation.SetText(_("Loading Airspace File..."));

    bool airspace_ok = false;

    AirspaceParser parser(airspaces);

    // Read the airspace filenames from the registry
    auto path = Profile::GetPath(ProfileKeys::AirspaceFile);
    if (!path.IsNull())
        airspace_ok |= ParseAirspaceFile(parser, path, operation);

    path = Profile::GetPath(ProfileKeys::AdditionalAirspaceFile);
    if (!path.IsNull())
        airspace_ok |= ParseAirspaceFile(parser, path, operation);

    auto archive = OpenMapFile();
    if (archive)
        airspace_ok |= ParseAirspaceFile(parser, archive->get(), "airspace.txt",
                                         operation);

    if (airspace_ok) {
        airspaces.Optimise();
        airspaces.SetFlightLevels(press);

        if (terrain != NULL)
            airspaces.SetGroundLevels(*terrain);
    } else
        // there was a problem
        airspaces.Clear();
}