Esempio n. 1
0
OrderedTask*
TaskFileIGC::GetTask(const TaskBehaviour &task_behaviour,
                     const Waypoints *waypoints, unsigned index) const
{
  assert(index == 0);

  IGCDeclarationHeader header;
  std::list<IGCDeclarationTurnpoint> turnpoints;

  if (!ReadIGCDeclaration(path, header, turnpoints))
    return NULL;

  // Number of turnpoints including start and finish
  unsigned num_turnpoints = header.num_turnpoints + 2;

  if (num_turnpoints + 2 == turnpoints.size()) {
    // Remove takeoff and landing points from the turnpoints list
    turnpoints.pop_front();
    turnpoints.pop_back();
  } else if (num_turnpoints != turnpoints.size())
    // Declared number of turnpoints is not matching parsed number of turnpoints
    return NULL;

  // Create a blank task
  OrderedTask *task = new OrderedTask(task_behaviour);
  AbstractTaskFactory &fact = task->GetFactory();

  unsigned i = 0;
  for (auto it = turnpoints.begin(), it_end = turnpoints.end();
       it != it_end; ++it) {
    StaticString<256> waypoint_name;
    if (!it->name.empty()) {
      waypoint_name.clear();
      waypoint_name.UnsafeAppendASCII(it->name);
    } else if (i == 0)
      waypoint_name = _T("Start");
    else if (i == num_turnpoints - 1)
      waypoint_name = _T("Finish");
    else
      waypoint_name.Format(_T("%s #%u"), _T("Turnpoint"), i);

    Waypoint wp(it->location);
    wp.name = waypoint_name.c_str();


    OrderedTaskPoint *tp;

    if (i == 0)
      tp = fact.CreateStart(wp);
    else if (i == num_turnpoints - 1)
      tp = fact.CreateFinish(wp);
    else
      tp = fact.CreateIntermediate(wp);

    if (tp != NULL) {
      fact.Append(*tp);
      delete tp;
    }

    ++i;
  }

  return task;
}
Esempio n. 2
0
OrderedTask*
TaskFileIGC::GetTask(const TaskBehaviour &task_behaviour,
                     const Waypoints *waypoints, unsigned index) const
{
  assert(index == 0);

  IGCDeclarationHeader header;
  std::list<IGCDeclarationTurnpoint> turnpoints;

  if (!ReadIGCDeclaration(path, header, turnpoints))
    return nullptr;

  // Number of turnpoints including start and finish
  unsigned num_turnpoints = header.num_turnpoints + 2;

  if (num_turnpoints + 2 == turnpoints.size()) {
    // Remove takeoff and landing points from the turnpoints list
    turnpoints.pop_front();
    turnpoints.pop_back();
  } else if (num_turnpoints != turnpoints.size())
    // Declared number of turnpoints is not matching parsed number of turnpoints
    return nullptr;

  // Create a blank task
  OrderedTask *task = new OrderedTask(task_behaviour);
  AbstractTaskFactory &fact = task->GetFactory();

  unsigned i = 0;
  for (const auto &it : turnpoints) {
    StaticString<256> waypoint_name;
    if (!it.name.empty()) {
      waypoint_name.clear();
      waypoint_name.UnsafeAppendASCII(it.name);
    } else if (i == 0)
      waypoint_name = _T("Start");
    else if (i == num_turnpoints - 1)
      waypoint_name = _T("Finish");
    else
      waypoint_name.Format(_T("%s #%u"), _T("Turnpoint"), i);

    Waypoint wp(it.location);
    wp.name = waypoint_name.c_str();

    /* we don't know the elevation, so we just set it to zero; this is
       not correct, but better than leaving it uninitialised */
    wp.elevation = fixed(0);

    OrderedTaskPoint *tp;

    if (i == 0)
      tp = fact.CreateStart(wp);
    else if (i == num_turnpoints - 1)
      tp = fact.CreateFinish(wp);
    else
      tp = fact.CreateIntermediate(wp);

    if (tp != nullptr) {
      fact.Append(*tp);
      delete tp;
    }

    ++i;
  }

  return task;
}