示例#1
0
static bool
TestErase(Waypoints& waypoints, unsigned id)
{
  waypoints.Optimise();
  auto wp = waypoints.LookupId(id);
  if (wp == NULL)
    return false;

  waypoints.Erase(std::move(wp));
  waypoints.Optimise();

  wp = waypoints.LookupId(id);
  return wp == NULL;
}
示例#2
0
bool
WaypointGlue::LoadWaypoints(Waypoints &way_points,
                            const RasterTerrain *terrain,
                            OperationEnvironment &operation)
{
  LogStartUp(_T("ReadWaypoints"));
  operation.SetText(_("Loading Waypoints..."));

  bool found = false;

  // Delete old waypoints
  way_points.Clear();

  // ### FIRST FILE ###
  found |= LoadWaypointFile(1, way_points, terrain, operation);

  // ### SECOND FILE ###
  found |= LoadWaypointFile(2, way_points, terrain, operation);

  // ### WATCHED WAYPOINT/THIRD FILE ###
  found |= LoadWaypointFile(3, way_points, terrain, operation);

  // ### MAP/FOURTH FILE ###

  // If no waypoint file found yet
  if (!found)
    found = LoadMapFileWaypoints(0, szProfileMapFile, way_points, terrain,
                                 operation);

  // Optimise the waypoint list after attaching new waypoints
  way_points.Optimise();

  // Return whether waypoints have been loaded into the waypoint list
  return found;
}
示例#3
0
bool
WaypointGlue::LoadWaypoints(Waypoints &way_points,
                            const RasterTerrain *terrain,
                            OperationEnvironment &operation)
{
  LogFormat("ReadWaypoints");
  operation.SetText(_("Loading Waypoints..."));

  bool found = false;

  // Delete old waypoints
  way_points.Clear();

  TCHAR path[MAX_PATH];

  LoadWaypointFile(way_points, LocalPath(path, _T("user.cup")),
                   WaypointFileType::SEEYOU,
                   WaypointOrigin::USER, terrain, operation);

  // ### FIRST FILE ###
  if (Profile::GetPath(ProfileKeys::WaypointFile, path))
    found |= LoadWaypointFile(way_points, path, WaypointOrigin::PRIMARY,
                              terrain, operation);

  // ### SECOND FILE ###
  if (Profile::GetPath(ProfileKeys::AdditionalWaypointFile, path))
    found |= LoadWaypointFile(way_points, path, WaypointOrigin::ADDITIONAL,
                              terrain, operation);

  // ### WATCHED WAYPOINT/THIRD FILE ###
  if (Profile::GetPath(ProfileKeys::WatchedWaypointFile, path))
    found |= LoadWaypointFile(way_points, path, WaypointOrigin::WATCHED,
                              terrain, operation);

  // ### MAP/FOURTH FILE ###

  // If no waypoint file found yet
  if (!found) {
    auto dir = OpenMapFile();
    if (dir != nullptr) {
      found |= LoadWaypointFile(way_points, dir, "waypoints.xcw",
                                WaypointFileType::WINPILOT,
                                WaypointOrigin::MAP,
                                terrain, operation);

      found |= LoadWaypointFile(way_points, dir, "waypoints.cup",
                                WaypointFileType::SEEYOU,
                                WaypointOrigin::MAP,
                                terrain, operation);

      zzip_dir_close(dir);
    }
  }

  // Optimise the waypoint list after attaching new waypoints
  way_points.Optimise();

  // Return whether waypoints have been loaded into the waypoint list
  return found;
}
示例#4
0
static void
SetAirfieldDetails(Waypoints &way_points, const TCHAR *name,
                   const tstring &Details)
{
  const Waypoint *wp = find_waypoint(way_points, name);
  if (wp == NULL)
    return;

  Waypoint new_wp(*wp);
  new_wp.details = Details.c_str();
  way_points.Replace(*wp, new_wp);
  way_points.Optimise();
}
示例#5
0
static unsigned
TestCopy(Waypoints& waypoints)
{
  const WaypointPtr wp = waypoints.LookupId(5);
  if (!wp)
    return false;

  unsigned size_old = waypoints.size();
  Waypoint wp_copy = *wp;
  wp_copy.id = waypoints.size() + 1;
  waypoints.Append(std::move(wp_copy));
  waypoints.Optimise();
  unsigned size_new = waypoints.size();
  return (size_new == size_old + 1);
}
示例#6
0
bool
WaypointGlue::LoadWaypoints(Waypoints &way_points,
                            const RasterTerrain *terrain,
                            OperationEnvironment &operation)
{
  LogFormat("ReadWaypoints");
  operation.SetText(_("Loading Waypoints..."));

  bool found = false;

  // Delete old waypoints
  way_points.Clear();

  TCHAR path[MAX_PATH];

  // ### FIRST FILE ###
  if (Profile::GetPath(ProfileKeys::WaypointFile, path))
    found |= LoadWaypointFile(way_points, path, 1, terrain, operation);

  // ### SECOND FILE ###
  if (Profile::GetPath(ProfileKeys::AdditionalWaypointFile, path))
    found |= LoadWaypointFile(way_points, path, 2, terrain, operation);

  // ### WATCHED WAYPOINT/THIRD FILE ###
  if (Profile::GetPath(ProfileKeys::WatchedWaypointFile, path))
    found |= LoadWaypointFile(way_points, path, 3, terrain, operation);

  // ### MAP/FOURTH FILE ###

  // If no waypoint file found yet
  if (!found && Profile::GetPath(ProfileKeys::MapFile, path)) {
    TCHAR *tail = path + _tcslen(path);

    _tcscpy(tail, _T("/waypoints.xcw"));
    found |= LoadWaypointFile(way_points, path, 0, terrain, operation);

    _tcscpy(tail, _T("/waypoints.cup"));
    found |= LoadWaypointFile(way_points, path, 0, terrain, operation);
  }

  // Optimise the waypoint list after attaching new waypoints
  way_points.Optimise();

  // Return whether waypoints have been loaded into the waypoint list
  return found;
}
示例#7
0
static bool
TestReplace(Waypoints& waypoints, unsigned id)
{
  auto wp = waypoints.LookupId(id);
  if (wp == NULL)
    return false;

  tstring oldName = wp->name;

  Waypoint copy = *wp;
  copy.name = _T("Fred");
  waypoints.Replace(wp, std::move(copy));
  waypoints.Optimise();

  wp = waypoints.LookupId(id);
  return wp != NULL && wp->name != oldName && wp->name == _T("Fred");
}
static bool
TestWaypointFile(const TCHAR* filename, Waypoints &way_points, unsigned num_wps)
{
    NullOperationEnvironment operation;
    if (!ok1(ReadWaypointFile(filename, way_points,
                              WaypointFactory(WaypointOrigin::NONE),
                              operation))) {
        skip(2, 0, "parsing waypoint file failed");
        return false;
    }

    way_points.Optimise();

    ok1(!way_points.IsEmpty());
    ok1(way_points.size() == num_wps);

    return true;
}
示例#9
0
static void
AddSpiralWaypoints(Waypoints &waypoints,
                   const GeoPoint &center = GeoPoint(Angle::Degrees(51.4),
                                                     Angle::Degrees(7.85)),
                   Angle angle_start = Angle::Degrees(0),
                   Angle angle_step = Angle::Degrees(15),
                   fixed distance_start = fixed(0),
                   fixed distance_step = fixed(1000),
                   fixed distance_max = fixed(150000))
{
  assert(positive(distance_step));

  for (unsigned i = 0;; ++i) {
    GeoVector vector;
    vector.distance = distance_start + distance_step * i;
    if (vector.distance > distance_max)
      break;

    vector.bearing = angle_start + angle_step * i;

    Waypoint waypoint;
    waypoint.location = vector.EndPoint(center);
    waypoint.original_id = i;
    waypoint.elevation = fixed(i * 10 - 500);

    StaticString<256> buffer;

    if (i % 7 == 0) {
      buffer = _T("Airfield");
      waypoint.type = Waypoint::Type::AIRFIELD;
    } else if (i % 3 == 0) {
      buffer = _T("Field");
      waypoint.type = Waypoint::Type::OUTLANDING;
    } else
      buffer = _T("Waypoint");

    buffer.AppendFormat(_T(" #%d"), i + 1);
    waypoint.name = buffer;

    waypoints.Append(std::move(waypoint));
  }

  waypoints.Optimise();
}
示例#10
0
static void
SetAirfieldDetails(Waypoints &way_points, const TCHAR *name,
                   const tstring &Details,
                   const std::vector<tstring> &files_external,
                   const std::vector<tstring> &files_embed)
{
  const Waypoint *wp = FindWaypoint(way_points, name);
  if (wp == NULL)
    return;

  Waypoint new_wp(*wp);
  new_wp.details = Details.c_str();
  new_wp.files_embed.assign(files_embed.begin(), files_embed.end());
#ifdef ANDROID
  new_wp.files_external.assign(files_external.begin(), files_external.end());
#endif
  way_points.Replace(*wp, new_wp);
  way_points.Optimise();
}
示例#11
0
static bool
TestWaypointFile(const TCHAR* filename, Waypoints &way_points, unsigned num_wps)
{
  WaypointReader f(filename, 0);
  if (!ok1(!f.Error())) {
    skip(3, 0, "opening waypoint file failed");
    return false;
  }

  NullOperationEnvironment operation;
  if(!ok1(f.Parse(way_points, operation))) {
    skip(2, 0, "parsing waypoint file failed");
    return false;
  }

  way_points.Optimise();

  ok1(!way_points.IsEmpty());
  ok1(way_points.size() == num_wps);

  return true;
}
示例#12
0
void
XCSoarInterface::AfterStartup()
{
  LogStartUp(_T("ProgramStarted = 3"));
  StartupLogFreeRamAndStorage();

  status_messages.Startup(true);

  if (is_simulator()) {
    LogStartUp(_T("GCE_STARTUP_SIMULATOR"));
    InputEvents::processGlideComputer(GCE_STARTUP_SIMULATOR);
  } else {
    LogStartUp(_T("GCE_STARTUP_REAL"));
    InputEvents::processGlideComputer(GCE_STARTUP_REAL);
  }

  OrderedTask *defaultTask = protected_task_manager->TaskCreateDefault(
      &way_points, GetComputerSettings().task.task_type_default);
  if (defaultTask) {
    {
      ScopeSuspendAllThreads suspend;
      defaultTask->CheckDuplicateWaypoints(way_points);
      way_points.Optimise();
    }
    protected_task_manager->TaskCommit(*defaultTask);
    delete defaultTask;
  }

  task_manager->Resume();

  main_window.Fullscreen();
  InfoBoxManager::SetDirty();

  TriggerGPSUpdate();

  status_messages.Startup(false);
}
示例#13
0
/** 
 * Initialises waypoints with random and non-random waypoints
 * for testing
 *
 * @param waypoints waypoints class to add waypoints to
 */
bool setup_waypoints(Waypoints &waypoints, const unsigned n) 
{

  Waypoint wp = waypoints.Create(GeoPoint(Angle::Degrees(fixed_zero),
                                          Angle::Degrees(fixed_zero)));
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(wp);

  wp = waypoints.Create(GeoPoint(Angle::Degrees(fixed_zero), 
                                 Angle::Degrees(fixed_one)));
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(wp);

  wp = waypoints.Create(GeoPoint(Angle::Degrees(fixed_one), 
                                 Angle::Degrees(fixed_one)));
  wp.name = _T("Hello");
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed_half;
  waypoints.Append(wp);

  wp = waypoints.Create(GeoPoint(Angle::Degrees(fixed(0.8)), 
                                 Angle::Degrees(fixed(0.5))));
  wp.name = _T("Unk");
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(wp);

  wp = waypoints.Create(GeoPoint(Angle::Degrees(fixed_one), 
                                 Angle::Degrees(fixed_zero)));
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(wp);

  wp = waypoints.Create(GeoPoint(Angle::Degrees(fixed_zero), 
                                 Angle::Degrees(fixed(0.23))));
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(wp);

  for (unsigned i=0; i<(unsigned)std::max((int)n-6,0); i++) {
    int x = rand()%1200-100;
    int y = rand()%1200-100;
    double z = rand()% std::max(terrain_height,1);
    wp = waypoints.Create(GeoPoint(Angle::Degrees(fixed(x/1000.0)), 
                                   Angle::Degrees(fixed(y/1000.0))));
    wp.type = Waypoint::Type::NORMAL;
    wp.elevation = fixed(z);
    waypoints.Append(wp);
  }
  waypoints.Optimise();

  if (verbose) {
    std::ofstream fin("results/res-wp-in.txt");
    for (unsigned i=1; i<=waypoints.size(); i++) {
      const Waypoint *wp = waypoints.LookupId(i);
      if (wp != NULL)
        fin << *wp;
    }
  }
  return true;
}
示例#14
0
/** 
 * Initialises waypoints with random and non-random waypoints
 * for testing
 *
 * @param waypoints waypoints class to add waypoints to
 */
bool SetupWaypoints(Waypoints &waypoints, const unsigned n)
{
  Waypoint wp = waypoints.Create(GeoPoint(Angle::Zero(),
                                          Angle::Zero()));
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(std::move(wp));

  wp = waypoints.Create(GeoPoint(Angle::Zero(),
                                 Angle::Degrees(1)));
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(std::move(wp));

  wp = waypoints.Create(GeoPoint(Angle::Degrees(1),
                                 Angle::Degrees(1)));
  wp.name = _T("Hello");
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.5);
  waypoints.Append(std::move(wp));

  wp = waypoints.Create(GeoPoint(Angle::Degrees(0.8),
                                 Angle::Degrees(0.5)));
  wp.name = _T("Unk");
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(std::move(wp));

  wp = waypoints.Create(GeoPoint(Angle::Degrees(1),
                                 Angle::Zero()));
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(std::move(wp));

  wp = waypoints.Create(GeoPoint(Angle::Zero(),
                                 Angle::Degrees(0.23)));
  wp.type = Waypoint::Type::AIRFIELD;
  wp.elevation = fixed(0.25);
  waypoints.Append(std::move(wp));

  for (unsigned i=0; i<(unsigned)std::max((int)n-6,0); i++) {
    int x = rand()%1200-100;
    int y = rand()%1200-100;
    double z = rand()% std::max(terrain_height,1);
    wp = waypoints.Create(GeoPoint(Angle::Degrees(x / 1000.0),
                                   Angle::Degrees(y / 1000.0)));
    wp.type = Waypoint::Type::NORMAL;
    wp.elevation = fixed(z);
    waypoints.Append(std::move(wp));
  }
  waypoints.Optimise();

  if (verbose) {
    Directory::Create(Path(_T("output/results")));
    std::ofstream fin("output/results/res-wp-in.txt");
    for (unsigned i=1; i<=waypoints.size(); i++) {
      const Waypoint *wpt = waypoints.LookupId(i);
      if (wpt != NULL)
        fin << *wpt;
    }
  }
  return true;
}
示例#15
0
static bool
test_replay_retrospective()
{
  Directory::Create(_T("output/results"));
  std::ofstream f("output/results/res-sample.txt");

  Waypoints waypoints;
  WaypointReader w(waypoint_file.c_str(), 0);
  if (!ok1(!w.Error())) {
    printf("# waypoint file %s\n", waypoint_file.c_str());
    skip(2, 0, "opening waypoint file failed");
    return false;
  }

  NullOperationEnvironment operation;
  if(!ok1(w.Parse(waypoints, operation))) {
    skip(1, 0, "parsing waypoint file failed");
    return false;
  }

  waypoints.Optimise();

  ok1(!waypoints.IsEmpty());

  Retrospective retro(waypoints);

  retro.search_range = range_threshold;
  retro.angle_tolerance = Angle::Degrees(autopilot_parms.bearing_noise);

  FileLineReaderA *reader = new FileLineReaderA(replay_file.c_str());
  if (reader->error()) {
    delete reader;
    return false;
  }

  waypoints.Optimise();

  IgcReplay sim(reader);

  NMEAInfo basic;
  basic.Reset();

  while (sim.Update(basic)) {
    n_samples++;

    if (retro.UpdateSample(basic.location)) {
      std::ofstream g("output/results/res-retro.txt");

      // report task
      auto candidate_list = retro.getNearWaypointList();
      for (auto it = candidate_list.begin(); it != candidate_list.end(); ++it) {
	const Waypoint& wp = it->waypoint;
	g << (double)wp.location.longitude.Degrees() << " "
	  << (double)wp.location.latitude.Degrees() << " "
	  << "\"" << wp.name << "\"\n";
      }
    }

    f << (double)basic.time << " " 
      <<  (double)basic.location.longitude.Degrees() << " "
      <<  (double)basic.location.latitude.Degrees() << "\n";
    f.flush();
  };

  double d_ach, d_can;
  retro.CalcDistances(d_ach, d_can);
  printf("# distances %f %f\n", (double)d_ach, (double)d_can);
  printf("# size %d\n", retro.getNearWaypointList().size());

  return true;
}