void SaveTask(WritableDataNode &node, const OrderedTask &task) { node.SetAttribute(_T("type"), GetTaskFactoryType(task.GetFactoryType())); Serialise(node, task.GetOrderedTaskSettings()); for (const auto &tp : task.GetPoints()) Serialise(node, tp, false); for (const auto &tp : task.GetOptionalStartPoints()) Serialise(node, tp, true); }
void Deserialiser::Deserialise(OrderedTask &task) { task.Clear(); task.SetFactory(GetTaskFactoryType()); task.Reset(); OrderedTaskSettings beh = task.GetOrderedTaskSettings(); Deserialise(beh); task.SetOrderedTaskSettings(beh); const DataNode::List children = node.ListChildrenNamed(_T("Point")); for (const auto &i : children) { std::unique_ptr<DataNode> point_node(i); Deserialiser pser(*point_node, waypoints); pser.DeserialiseTaskpoint(task); } }
void LoadTask(OrderedTask &task, const ConstDataNode &node, const Waypoints *waypoints) { task.Clear(); task.SetFactory(GetTaskFactoryType(node)); task.Reset(); OrderedTaskSettings beh = task.GetOrderedTaskSettings(); Deserialise(beh, node); task.SetOrderedTaskSettings(beh); const auto children = node.ListChildrenNamed(_T("Point")); for (const auto &i : children) { std::unique_ptr<ConstDataNode> point_node(i); DeserialiseTaskpoint(task, *point_node, waypoints); } }
static void RenderFAISectors(Canvas &canvas, const WindowProjection &projection, const OrderedTask &task) { const FAITriangleSettings &settings = task.GetOrderedTaskSettings().fai_triangle; const unsigned size = task.TaskSize(); const unsigned end = size - 1; for (unsigned i = 0; i != end; ++i) RenderFAISector(canvas, projection, task.GetPoint(i).GetLocation(), task.GetPoint(i + 1).GetLocation(), true, settings); for (unsigned i = 0; i != end; ++i) RenderFAISector(canvas, projection, task.GetPoint(i).GetLocation(), task.GetPoint(i + 1).GetLocation(), false, settings); }
OrderedTask* TaskFileSeeYou::GetTask(const TaskBehaviour &task_behaviour, const Waypoints *waypoints, unsigned index) const { // Create FileReader for reading the task FileLineReader reader(path, ConvertLineReader::AUTO); if (reader.error()) return NULL; // Read waypoints from the CUP file Waypoints file_waypoints; { WaypointReaderSeeYou waypoint_file(0); NullOperationEnvironment operation; waypoint_file.Parse(file_waypoints, reader, operation); } file_waypoints.Optimise(); if (!reader.Rewind()) return NULL; TCHAR *line = AdvanceReaderToTask(reader, index); if (line == NULL) return NULL; // Read waypoint list // e.g. "Club day 4 Racing task","085PRI","083BOJ","170D_K","065SKY","0844YY", "0844YY" // TASK NAME , TAKEOFF, START , TP1 , TP2 , FINISH , LANDING TCHAR waypoints_buffer[1024]; const TCHAR *wps[30]; size_t n_waypoints = WaypointReaderBase:: ExtractParameters(line, waypoints_buffer, wps, 30, true, _T('"')) - 3; SeeYouTaskInformation task_info; SeeYouTurnpointInformation turnpoint_infos[30]; const Waypoint *waypoints_in_task[30]; ParseCUTaskDetails(reader, &task_info, turnpoint_infos); OrderedTask *task = new OrderedTask(task_behaviour); task->SetFactory(task_info.wp_dis ? TaskFactoryType::RACING : TaskFactoryType::AAT); AbstractTaskFactory& fact = task->GetFactory(); const TaskFactoryType factType = task->GetFactoryType(); OrderedTaskSettings beh = task->GetOrderedTaskSettings(); if (factType == TaskFactoryType::AAT) { beh.aat_min_time = task_info.task_time; } if (factType == TaskFactoryType::AAT || factType == TaskFactoryType::RACING) { beh.start_constraints.max_height = (unsigned)task_info.max_start_altitude; beh.start_constraints.max_height_ref = AltitudeReference::MSL; } task->SetOrderedTaskSettings(beh); // mark task waypoints. Skip takeoff and landing point for (unsigned i = 0; i < n_waypoints; i++) { const Waypoint* file_wp = file_waypoints.LookupName(wps[i + 2]); if (file_wp == NULL) return NULL; // Try to find waypoint by name const Waypoint* wp = waypoints->LookupName(file_wp->name); // If waypoint by name found and closer than 10m to the original if (wp != NULL && wp->location.Distance(file_wp->location) <= fixed(10)) { // Use this waypoint for the task waypoints_in_task[i] = wp; continue; } // Try finding the closest waypoint to the original one wp = waypoints->GetNearest(file_wp->location, fixed(10)); // If closest waypoint found and closer than 10m to the original if (wp != NULL && wp->location.Distance(file_wp->location) <= fixed(10)) { // Use this waypoint for the task waypoints_in_task[i] = wp; continue; } // Use the original waypoint waypoints_in_task[i] = file_wp; } //now create TPs and OZs for (unsigned i = 0; i < n_waypoints; i++) { ObservationZonePoint* oz = CreateOZ(turnpoint_infos[i], i, n_waypoints, waypoints_in_task, factType); assert(waypoints_in_task[i]); OrderedTaskPoint *pt = CreatePoint(i, n_waypoints, waypoints_in_task[i], fact, oz, factType); if (pt != NULL) fact.Append(*pt, false); delete pt; } return task; }
OrderedTask* TaskFileSeeYou::GetTask(const TaskBehaviour &task_behaviour, const Waypoints *waypoints, unsigned index) const { // Create FileReader for reading the task FileLineReader reader(path, IgnoreError(), Charset::AUTO); if (reader.error()) return nullptr; // Read waypoints from the CUP file Waypoints file_waypoints; { const WaypointFactory factory(WaypointOrigin::NONE); WaypointReaderSeeYou waypoint_file(factory); NullOperationEnvironment operation; waypoint_file.Parse(file_waypoints, reader, operation); } file_waypoints.Optimise(); if (!reader.Rewind()) return nullptr; TCHAR *line = AdvanceReaderToTask(reader, index); if (line == nullptr) return nullptr; // Read waypoint list // e.g. "Club day 4 Racing task","085PRI","083BOJ","170D_K","065SKY","0844YY", "0844YY" // TASK NAME , TAKEOFF, START , TP1 , TP2 , FINISH , LANDING TCHAR waypoints_buffer[1024]; const TCHAR *wps[30]; size_t n_waypoints = ExtractParameters(line, waypoints_buffer, wps, 30, true, _T('"')); // Some versions of StrePla append a trailing ',' without a following // WP name resulting an empty last entry. Remove it from the results if (n_waypoints > 0 && wps[n_waypoints - 1][0] == _T('\0')) n_waypoints --; // At least taskname and takeoff, start, finish and landing points are needed if (n_waypoints < 5) return nullptr; // Remove taskname, start point and landing point from count n_waypoints -= 3; SeeYouTaskInformation task_info; SeeYouTurnpointInformation turnpoint_infos[30]; WaypointPtr waypoints_in_task[30]; ParseCUTaskDetails(reader, &task_info, turnpoint_infos); OrderedTask *task = new OrderedTask(task_behaviour); task->SetFactory(task_info.wp_dis ? TaskFactoryType::RACING : TaskFactoryType::AAT); AbstractTaskFactory& fact = task->GetFactory(); const TaskFactoryType factType = task->GetFactoryType(); OrderedTaskSettings beh = task->GetOrderedTaskSettings(); if (factType == TaskFactoryType::AAT) { beh.aat_min_time = task_info.task_time; } if (factType == TaskFactoryType::AAT || factType == TaskFactoryType::RACING) { beh.start_constraints.max_height = (unsigned)task_info.max_start_altitude; beh.start_constraints.max_height_ref = AltitudeReference::MSL; } task->SetOrderedTaskSettings(beh); // mark task waypoints. Skip takeoff and landing point for (unsigned i = 0; i < n_waypoints; i++) { auto file_wp = file_waypoints.LookupName(wps[i + 2]); if (file_wp == nullptr) return nullptr; // Try to find waypoint by name auto wp = waypoints->LookupName(file_wp->name); // If waypoint by name found and closer than 10m to the original if (wp != nullptr && wp->location.DistanceS(file_wp->location) <= fixed(10)) { // Use this waypoint for the task waypoints_in_task[i] = wp; continue; } // Try finding the closest waypoint to the original one wp = waypoints->GetNearest(file_wp->location, fixed(10)); // If closest waypoint found and closer than 10m to the original if (wp != nullptr && wp->location.DistanceS(file_wp->location) <= fixed(10)) { // Use this waypoint for the task waypoints_in_task[i] = wp; continue; } // Use the original waypoint waypoints_in_task[i] = file_wp; } //now create TPs and OZs for (unsigned i = 0; i < n_waypoints; i++) { ObservationZonePoint* oz = CreateOZ(turnpoint_infos[i], i, n_waypoints, waypoints_in_task, factType); assert(waypoints_in_task[i]); OrderedTaskPoint *pt = CreatePoint(i, n_waypoints, WaypointPtr(waypoints_in_task[i]), fact, oz, factType); if (pt != nullptr) fact.Append(*pt, false); delete pt; } return task; }