Example #1
0
Waypoint*
Deserialiser::DeserialiseWaypoint()
{
  std::unique_ptr<DataNode> loc_node(node.GetChildNamed(_T("Location")));
  if (!loc_node)
    return nullptr;

  GeoPoint loc;
  Deserialiser lser(*loc_node, waypoints);
  lser.Deserialise(loc);

  const TCHAR *name = node.GetAttribute(_T("name"));
  if (name == nullptr)
    // Turnpoints need names
    return nullptr;

  if (waypoints != nullptr) {
    // Try to find waypoint by name
    const Waypoint *from_database = waypoints->LookupName(name);

    // If waypoint by name found and closer than 10m to the original
    if (from_database != nullptr &&
        from_database->location.Distance(loc) <= fixed(10))
      // Use this waypoint for the task
      return new Waypoint(*from_database);

    // Try finding the closest waypoint to the original one
    from_database = waypoints->GetNearest(loc, fixed(10));

    // If closest waypoint found and closer than 10m to the original
    if (from_database != nullptr &&
        from_database->location.Distance(loc) <= fixed(10))
      // Use this waypoint for the task
      return new Waypoint(*from_database);
  }

  // Create a new waypoint from the original one
  Waypoint *wp = new Waypoint(loc);
  wp->name = name;

  node.GetAttribute(_T("id"), wp->id);

  const TCHAR *comment = node.GetAttribute(_T("comment"));
  if (comment != nullptr)
    wp->comment.assign(comment);

  node.GetAttribute(_T("altitude"), wp->elevation);

  return wp;
}
Example #2
0
Waypoint*
Serialiser::deserialise_waypoint()
{
  DataNode* loc_node = m_node.get_child_by_name(_T("Location"));
  if (!loc_node)
    return NULL;
  GeoPoint loc;
  Serialiser lser(*loc_node);
  lser.deserialise(loc);
  delete loc_node;

  /// @todo: check if waypoint is already in database or needs to be added

  Waypoint *wp = new Waypoint(loc);
  m_node.get_attribute(_T("name"), wp->Name);
  m_node.get_attribute(_T("id"), wp->id);
  m_node.get_attribute(_T("comment"), wp->Comment);
  m_node.get_attribute(_T("altitude"), wp->Altitude);

  return wp;
}