void OrderedTask::CheckDuplicateWaypoints(Waypoints& waypoints, OrderedTaskPointVector& points, const bool is_task) { for (auto begin = points.cbegin(), end = points.cend(), i = begin; i != end; ++i) { auto wp = waypoints.CheckExistsOrAppend((*i)->GetWaypointPtr()); const OrderedTaskPoint *new_tp = (*i)->Clone(task_behaviour, ordered_settings, std::move(wp)); if (is_task) Replace(*new_tp, std::distance(begin, i)); else ReplaceOptionalStart(*new_tp, std::distance(begin, i)); delete new_tp; } }
static void FillLastUsedList(WaypointSelectInfoVector &list, const std::list<unsigned int> &last_used_ids, const Waypoints &waypoints, const GeoPoint location) { list.clear(); if (last_used_ids.empty()) return; for (auto it = last_used_ids.rbegin(); it != last_used_ids.rend(); it++) { const Waypoint* waypoint = waypoints.LookupId(*it); if (waypoint == NULL) continue; list.push_back(*waypoint, location); } }
unsigned test_copy(Waypoints& waypoints) { const Waypoint *r = waypoints.lookup_id(5); if (!r) { return false; } unsigned size_old = waypoints.size(); Waypoint wp = *r; wp.id = waypoints.size()+1; waypoints.append(wp); waypoints.optimise(); unsigned size_new = waypoints.size(); return (size_new == size_old+1); }
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); }
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); }
static void TestLookups(const Waypoints &waypoints, const GeoPoint ¢er) { WaypointPtr waypoint; ok1((waypoint = waypoints.LookupId(0)) == NULL); ok1((waypoint = waypoints.LookupId(1)) != NULL); ok1(waypoint->original_id == 0); ok1((waypoint = waypoints.LookupId(151)) != NULL); ok1(waypoint->original_id == 150); ok1((waypoint = waypoints.LookupId(152)) == NULL); ok1((waypoint = waypoints.LookupId(160)) == NULL); ok1((waypoint = waypoints.LookupLocation(center, fixed(0))) != NULL); ok1(waypoint->original_id == 0); ok1((waypoint = waypoints.LookupName(_T("Waypoint #5"))) != NULL); ok1(waypoint->original_id == 4); ok1((waypoint = waypoints.LookupLocation(waypoint->location, fixed(10000))) != NULL); ok1(waypoint->original_id == 4); }
int main(int argc, char** argv) { if (!parse_args(argc,argv)) { return 0; } plan_tests(16); Waypoints waypoints; ok(setup_waypoints(waypoints),"waypoint setup",0); unsigned size = waypoints.size(); ok(test_lookup(waypoints,3),"waypoint lookup",0); ok(!test_lookup(waypoints,5000),"waypoint bad lookup",0); ok(test_nearest(waypoints),"waypoint nearest",0); ok(test_nearest_landable(waypoints),"waypoint nearest landable",0); ok(test_location(waypoints,true),"waypoint location good",0); ok(test_location(waypoints,false),"waypoint location bad",0); ok(test_range(waypoints,100)==1,"waypoint visit range 100m",0); ok(test_radius(waypoints,100)==1,"waypoint radius 100m",0); ok(test_range(waypoints,500000)== waypoints.size(),"waypoint range 500000m",0); ok(test_radius(waypoints,25000)<= test_range(waypoints,25000),"waypoint radius<range",0); // test clear waypoints.clear(); ok(waypoints.size()==0,"waypoint clear",0); setup_waypoints(waypoints); ok(size == waypoints.size(),"waypoint setup after clear",0); ok(test_copy(waypoints),"waypoint copy",0); ok(test_erase(waypoints,3),"waypoint erase",0); ok(test_replace(waypoints,4),"waypoint replace",0); return exit_status(); }
static void TestGetNearest(const Waypoints &waypoints, const GeoPoint ¢er) { WaypointPtr waypoint; GeoPoint near = GeoVector(fixed(250), Angle::Degrees(15)).EndPoint(center); GeoPoint far = GeoVector(fixed(750), Angle::Degrees(15)).EndPoint(center); GeoPoint further = GeoVector(fixed(4200), Angle::Degrees(48)).EndPoint(center); ok1((waypoint = waypoints.GetNearest(center, fixed(1))) != NULL); ok1(waypoint->original_id == 0); ok1((waypoint = waypoints.GetNearest(center, fixed(10000))) != NULL); ok1(waypoint->original_id == 0); ok1((waypoint = waypoints.GetNearest(near, fixed(1))) == NULL); ok1((waypoint = waypoints.GetNearest(near, fixed(10000))) != NULL); ok1(waypoint->original_id == 0); ok1((waypoint = waypoints.GetNearest(far, fixed(1))) == NULL); ok1((waypoint = waypoints.GetNearest(far, fixed(10000))) != NULL); ok1(waypoint->original_id == 1); ok1((waypoint = waypoints.GetNearestLandable(center, fixed(1))) != NULL); ok1(waypoint->original_id == 0); ok1((waypoint = waypoints.GetNearestLandable(center, fixed(10000))) != NULL); ok1(waypoint->original_id == 0); ok1((waypoint = waypoints.GetNearestLandable(further, fixed(1))) == NULL); ok1((waypoint = waypoints.GetNearestLandable(further, fixed(10000))) != NULL); ok1(waypoint->original_id == 3); ok1((waypoint = waypoints.GetNearestIf(center, fixed(1), OriginalIDAbove5)) == NULL); ok1((waypoint = waypoints.GetNearestIf(center, fixed(10000), OriginalIDAbove5)) != NULL); ok1(waypoint->original_id == 6); }
static bool test_task_mat(TaskManager &task_manager, const Waypoints &waypoints) { task_manager.SetFactory(TaskFactoryType::MAT); AbstractTaskFactory &fact = task_manager.GetFactory(); const Waypoint *wp; task_report(task_manager, "# adding start\n"); wp = waypoints.LookupId(1); if (wp) { OrderedTaskPoint *tp = fact.CreateStart(*wp); if (!fact.Append(*tp,false)) { return false; } delete tp; } task_manager.SetActiveTaskPoint(0); task_manager.Resume(); task_report(task_manager, "# adding intermediate\n"); wp = waypoints.LookupId(2); if (wp) { OrderedTaskPoint* tp = fact.CreateIntermediate(TaskPointFactoryType::MAT_CYLINDER,*wp); if (!fact.Append(*tp,false)) { return false; } delete tp; } task_report(task_manager, "# adding intermediate\n"); wp = waypoints.LookupId(3); if (wp) { OrderedTaskPoint* tp = fact.CreateIntermediate(TaskPointFactoryType::MAT_CYLINDER,*wp); if (!fact.Append(*tp,false)) { return false; } delete tp; } task_report(task_manager, "# adding finish\n"); wp = waypoints.LookupId(1); if (wp) { OrderedTaskPoint *tp = fact.CreateFinish(*wp); if (!fact.Append(*tp,false)) { return false; } delete tp; } fact.UpdateStatsGeometry(); task_report(task_manager, "# checking task..\n"); if (!fact.Validate()) { return false; } if (!task_manager.CheckOrderedTask()) { return false; } return true; }
bool test_task_aat(TaskManager& task_manager, const Waypoints &waypoints) { task_manager.SetFactory(TaskFactoryType::AAT); AbstractTaskFactory &fact = task_manager.GetFactory(); const Waypoint *wp; task_report(task_manager, "# adding start\n"); wp = waypoints.LookupId(1); if (wp) { OrderedTaskPoint *tp = fact.CreateStart(*wp); if (!fact.Append(*tp,false)) { return false; } delete tp; } task_manager.SetActiveTaskPoint(0); task_manager.Resume(); task_report(task_manager, "# adding intermediate\n"); wp = waypoints.LookupId(2); if (wp) { OrderedTaskPoint* tp = fact.CreateIntermediate(TaskPointFactoryType::AAT_CYLINDER,*wp); if (tp->GetObservationZone().GetShape() == ObservationZone::Shape::CYLINDER) { CylinderZone &cz = (CylinderZone &)tp->GetObservationZone(); cz.SetRadius(fixed(30000.0)); } if (!fact.Append(*tp,false)) { return false; } delete tp; } task_report(task_manager, "# adding intermediate\n"); wp = waypoints.LookupId(3); if (wp) { OrderedTaskPoint* tp = fact.CreateIntermediate(TaskPointFactoryType::AAT_CYLINDER,*wp); if (tp->GetObservationZone().GetShape() == ObservationZone::Shape::CYLINDER) { CylinderZone &cz = (CylinderZone &)tp->GetObservationZone(); cz.SetRadius(fixed(40000.0)); } if (!fact.Append(*tp,false)) { return false; } delete tp; } task_report(task_manager, "# adding finish\n"); wp = waypoints.LookupId(1); if (wp) { OrderedTaskPoint *tp = fact.CreateFinish(*wp); if (!fact.Append(*tp,false)) { return false; } delete tp; } fact.UpdateStatsGeometry(); task_report(task_manager, "# checking task..\n"); if (!fact.Validate()) { return false; } if (!task_manager.CheckOrderedTask()) { return false; } return true; }
bool test_task_manip(TaskManager& task_manager, const Waypoints &waypoints) { if (!test_task_mixed(task_manager, waypoints)) { return false; } AbstractTaskFactory &fact = task_manager.GetFactory(); task_report(task_manager, "# removing tp 2\n"); if (!fact.Remove(2)) { return false; } task_report(task_manager, "# removing tp 0\n"); if (!fact.Remove(0)) { return false; } task_report(task_manager, "# removing tp -1 (illegal)\n"); if (fact.Remove(0-1)) { return false; } task_report(task_manager, "# removing tp 50 (illegal)\n"); if (fact.Remove(50)) { return false; } OrderedTaskPoint *tp; const Waypoint *wp; task_report(task_manager, "# inserting at 3\n"); wp = waypoints.LookupId(3); if (wp) { tp = fact.CreateIntermediate(TaskPointFactoryType::AST_CYLINDER,*wp); if (!fact.Insert(*tp,3)) return false; delete tp; } task_report(task_manager, "# auto-replacing at 2 (no morph)\n"); wp = waypoints.LookupId(9); if (wp) { tp = fact.CreateIntermediate(TaskPointFactoryType::AST_CYLINDER,*wp); if (!fact.Replace(*tp,2)) return false; delete tp; } task_report(task_manager, "# auto-replacing at 2 (morph)\n"); wp = waypoints.LookupId(9); if (wp) { tp = fact.CreateStart(*wp); if (!fact.Replace(*tp,2)) return false; delete tp; } task_report(task_manager, "# auto-replacing at 0 (morph this)\n"); wp = waypoints.LookupId(12); if (wp) { tp = fact.CreateIntermediate(TaskPointFactoryType::AST_CYLINDER,*wp); if (!fact.Replace(*tp,0)) return false; delete tp; } task_report(task_manager, "# auto-replacing at end (morph this)\n"); wp = waypoints.LookupId(14); if (wp) { tp = fact.CreateIntermediate(TaskPointFactoryType::AST_CYLINDER,*wp); if (!fact.Replace(*tp,task_manager.TaskSize()-1)) return false; delete tp; } task_report(task_manager, "# removing finish point\n"); if (!fact.Remove(task_manager.TaskSize()-1)) { return false; } task_report(task_manager, "# inserting at 50 (equivalent to append)\n"); wp = waypoints.LookupId(8); if (wp) { tp = fact.CreateFinish(*wp); if (!fact.Insert(*tp,50)) return false; delete tp; } task_report(task_manager, "# inserting at 0 (morph this)\n"); wp = waypoints.LookupId(3); if (wp) { tp = fact.CreateFinish(*wp); if (!fact.Insert(*tp,0)) return false; delete tp; } task_report(task_manager, "# inserting at 2 (morph this)\n"); wp = waypoints.LookupId(4); if (wp) { tp = fact.CreateStart(*wp); if (!fact.Insert(*tp,2)) return false; delete tp; } task_report(task_manager, "# inserting at 2 (direct)\n"); wp = waypoints.LookupId(6); if (wp) { tp = fact.CreateIntermediate(*wp); if (!fact.Insert(*tp,2,false)) return false; delete tp; } task_report(task_manager, "# checking task\n"); fact.UpdateStatsGeometry(); if (task_manager.CheckOrderedTask()) { task_manager.Reset(); task_manager.SetActiveTaskPoint(0); task_manager.Resume(); } else { return false; } return true; }
void XCSoarInterface::Shutdown() { VerboseOperationEnvironment operation; gcc_unused ScopeBusyIndicator busy; // Show progress dialog operation.SetText(_("Shutdown, please wait...")); // Log shutdown information LogStartUp(_T("Entering shutdown...")); StartupLogFreeRamAndStorage(); // Turn off all displays globalRunningEvent.Reset(); #ifdef HAVE_TRACKING if (tracking != NULL) tracking->StopAsync(); #endif // Stop logger and save igc file operation.SetText(_("Shutdown, saving logs...")); logger.GUIStopLogger(Basic(), true); delete flight_logger; flight_logger = NULL; GetLiveBlackboard().RemoveListener(glide_computer_events); FlarmFriends::Save(); // Save settings to profile operation.SetText(_("Shutdown, saving profile...")); Profile::Save(); // Stop sound AudioVarioGlue::Deinitialise(); operation.SetText(_("Shutdown, please wait...")); // Stop threads LogStartUp(_T("Stop threads")); #ifndef ENABLE_OPENGL draw_thread->BeginStop(); #endif calculation_thread->BeginStop(); merge_thread->BeginStop(); // Wait for the calculations thread to finish LogStartUp(_T("Waiting for calculation thread")); merge_thread->Join(); delete merge_thread; merge_thread = NULL; calculation_thread->Join(); delete calculation_thread; calculation_thread = NULL; // Wait for the drawing thread to finish #ifndef ENABLE_OPENGL LogStartUp(_T("Waiting for draw thread")); draw_thread->Join(); delete draw_thread; #endif LogStartUp(_T("delete MapWindow")); main_window.Deinitialise(); // Save the task for the next time operation.SetText(_("Shutdown, saving task...")); LogStartUp(_T("Save default task")); protected_task_manager->TaskSaveDefault(); // Clear waypoint database LogStartUp(_T("Close waypoints")); way_points.Clear(); operation.SetText(_("Shutdown, please wait...")); // Clear weather database LogStartUp(_T("CloseRASP")); RASP.Close(); // Clear terrain database LogStartUp(_T("CloseTerrain")); delete terrain; LogStartUp(_T("CloseTopography")); delete topography; delete protected_marks; delete marks; // Close any device connections devShutdown(); NMEALogger::Shutdown(); delete replay; DeviceListDeinitialise(); delete device_blackboard; device_blackboard = NULL; protected_task_manager->SetRoutePlanner(NULL); delete protected_task_manager; delete task_manager; #ifdef HAVE_NET delete noaa_store; #endif #ifdef HAVE_TRACKING if (tracking != NULL) { tracking->WaitStopped(); delete tracking; } #endif // Close the progress dialog LogStartUp(_T("Close Progress Dialog")); operation.Hide(); // Clear the EGM96 database EGM96::Close(); delete glide_computer; // Clear airspace database LogStartUp(_T("Close airspace")); airspace_database.clear(); // Destroy FlarmNet records FlarmNet::Destroy(); delete file_cache; LogStartUp(_T("Close Windows - main")); main_window.reset(); CloseLanguageFile(); Display::RestoreOrientation(); StartupLogFreeRamAndStorage(); LogStartUp(_T("Finished shutdown")); }
bool test_task_mixed(TaskManager& task_manager, const Waypoints &waypoints) { const TaskProjection &projection = task_manager.get_ordered_task().get_task_projection(); OrderedTaskPoint *tp; const Waypoint *wp; task_manager.set_factory(TaskBehaviour::FACTORY_MIXED); AbstractTaskFactory &fact = task_manager.get_factory(); task_report(task_manager, "# adding start\n"); wp = waypoints.lookup_id(1); if (wp) { tp = fact.createStart(AbstractTaskFactory::START_LINE,*wp); if (tp->get_oz()->shape == ObservationZonePoint::CYLINDER) { CylinderZone *cz = (CylinderZone *)tp->get_oz(); cz->setRadius(fixed(5000.0)); tp->update_oz(projection); } if (!fact.append(*tp,false)) return false; delete tp; } else { return false; } task_manager.setActiveTaskPoint(0); task_manager.resume(); task_report(task_manager, "# adding intermdiate\n"); wp = waypoints.lookup_id(2); if (wp) { tp = fact.createIntermediate(AbstractTaskFactory::AST_CYLINDER,*wp); if (!fact.append(*tp,false)) return false; delete tp; } else { return false; } task_report(task_manager, "# adding intermdiate\n"); wp = waypoints.lookup_id(3); if (wp) { tp = fact.createIntermediate(AbstractTaskFactory::AAT_CYLINDER,*wp); if (tp->get_oz()->shape == ObservationZonePoint::CYLINDER) { CylinderZone *cz = (CylinderZone *)tp->get_oz(); cz->setRadius(fixed(30000.0)); tp->update_oz(projection); } if (!fact.append(*tp,false)) return false; delete tp; } else { return false; } task_report(task_manager, "# adding intermediate\n"); wp = waypoints.lookup_id(4); if (wp) { tp = fact.createIntermediate(AbstractTaskFactory::AAT_CYLINDER,*wp); if (!fact.append(*tp,false)) return false; delete tp; } else { return false; } task_report(task_manager, "# adding intermediate\n"); wp = waypoints.lookup_id(5); if (wp) { tp = fact.createIntermediate(AbstractTaskFactory::AAT_CYLINDER,*wp); if (tp->get_oz()->shape == ObservationZonePoint::CYLINDER) { CylinderZone *cz = (CylinderZone *)tp->get_oz(); cz->setRadius(fixed(30000.0)); tp->update_oz(projection); } if (!fact.append(*tp,false)) return false; delete tp; } else { return false; } task_report(task_manager, "# adding finish\n"); wp = waypoints.lookup_id(1); if (wp) { tp = fact.createFinish(AbstractTaskFactory::FINISH_LINE,*wp); if (!fact.append(*tp,false)) return false; delete tp; } else { return false; } task_report(task_manager, "# checking task\n"); if (!fact.validate()) { return false; } if (!task_manager.check_ordered_task()) { return false; } return true; }
/** * 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; }
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; }
bool WaypointReaderCompeGPS::ParseLine(const TCHAR* line, const unsigned linenum, Waypoints &waypoints) { /* * G WGS 84 * U 1 * W IT05FC A 46.9121939503ºN 11.9605922700°E 27-MAR-62 00:00:00 566.000000 Ahornach Sand, Ahornach LP, GS und HG * w Waypoint,0,-1.0,16777215,255,0,0,7,,0.0, * W IT05FB A 46.9260440931ºN 11.9676733017°E 27-MAR-62 00:00:00 1425.000000 Ahornach Sand, Ahornach SP, GS und HG * w Waypoint,0,-1.0,16777215,255,0,0,7,,0.0, * * W ShortName 31T 318570 4657569 27-MAR-62 00:00:00 0 some Comments * W ShortName A 41.234234N 7.234424W 27-MAR-62 00:00:00 0 Comments */ // Skip projection and file encoding information if (*line == _T('G') || *line == _T('B')) return true; // Check for format: UTM or LatLon if (*line == _T('U') && _tcsstr(line, _T("U 0")) == line) { is_utm = true; return true; } // Skip non-waypoint lines if (*line != _T('W')) return true; // Skip W indicator and whitespace line++; while (*line == _T(' ')) line++; // Find next space delimiter, skip shortname const TCHAR *name = line; const TCHAR *space = _tcsstr(line, _T(" ")); if (space == NULL) return false; unsigned name_length = space - line; if (name_length == 0) return false; line = space; while (*line == _T(' ')) line++; // Parse location GeoPoint location; if ((!is_utm && !ParseLocation(line, location)) || (is_utm && !ParseLocationUTM(line, location))) return false; // Skip whitespace while (*line == _T(' ')) line++; // Skip unused date field line = _tcsstr(line, _T(" ")); if (line == NULL) return false; line++; // Skip unused time field line = _tcsstr(line, _T(" ")); if (line == NULL) return false; line++; // Create new waypoint instance Waypoint waypoint(location); waypoint.file_num = file_num; waypoint.original_id = 0; waypoint.name.assign(name, name_length); // Parse altitude if (!ParseAltitude(line, waypoint.elevation) && !CheckAltitude(waypoint)) return false; // Skip whitespace while (*line == _T(' ')) line++; // Parse waypoint name waypoint.comment.assign(line); waypoints.Append(std::move(waypoint)); return true; }
/** * 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; }
bool WaypointReaderSeeYou::ParseLine(const TCHAR* line, const unsigned linenum, Waypoints &waypoints) { enum { iName = 0, iLatitude = 3, iLongitude = 4, iElevation = 5, iStyle = 6, iRWDir = 7, iRWLen = 8, iFrequency = 9, iDescription = 10, }; if (linenum == 0) ignore_following = false; // If (end-of-file or comment) if (StringIsEmpty(line) || StringStartsWith(line, _T("**")) || StringStartsWith(line, _T("*"))) // -> return without error condition return true; TCHAR ctemp[4096]; if (_tcslen(line) >= ARRAY_SIZE(ctemp)) /* line too long for buffer */ return false; // Skip first line if it doesn't begin with a quotation character // (usually the field order line) if (linenum == 0 && line[0] != _T('\"')) return true; // If task marker is reached ignore all following lines if (_tcsstr(line, _T("-----Related Tasks-----")) == line) ignore_following = true; if (ignore_following) return true; // Get fields const TCHAR *params[20]; size_t n_params = ExtractParameters(line, ctemp, params, ARRAY_SIZE(params), true, _T('"')); // Check if the basic fields are provided if (iName >= n_params || iLatitude >= n_params || iLongitude >= n_params) return false; Waypoint new_waypoint; // Latitude (e.g. 5115.900N) if (!ParseAngle(params[iLatitude], new_waypoint.location.latitude, true)) return false; // Longitude (e.g. 00715.900W) if (!ParseAngle(params[iLongitude], new_waypoint.location.longitude, false)) return false; new_waypoint.location.Normalize(); // ensure longitude is within -180:180 new_waypoint.file_num = file_num; new_waypoint.original_id = 0; // Name (e.g. "Some Turnpoint") if (*params[iName] == _T('\0')) return false; new_waypoint.name = params[iName]; // Elevation (e.g. 458.0m) /// @todo configurable behaviour if ((iElevation >= n_params || !ParseAltitude(params[iElevation], new_waypoint.elevation)) && !CheckAltitude(new_waypoint)) return false; // Style (e.g. 5) if (iStyle < n_params) ParseStyle(params[iStyle], new_waypoint.type); new_waypoint.flags.turn_point = true; // Frequency & runway direction/length (for airports and landables) // and description (e.g. "Some Description") if (new_waypoint.IsLandable()) { if (iFrequency < n_params) new_waypoint.radio_frequency = RadioFrequency::Parse(params[iFrequency]); // Runway length (e.g. 546.0m) fixed rwlen = fixed_minus_one; if (iRWLen < n_params && ParseDistance(params[iRWLen], rwlen) && positive(rwlen)) new_waypoint.runway.SetLength(uround(rwlen)); if (iRWDir < n_params && *params[iRWDir]) { TCHAR *end; int direction =_tcstol(params[iRWDir], &end, 10); if (end == params[iRWDir] || direction < 0 || direction > 360 || (direction == 0 && !positive(rwlen))) direction = -1; else if (direction == 360) direction = 0; if (direction >= 0) new_waypoint.runway.SetDirectionDegrees(direction); } } if (iDescription < n_params) new_waypoint.comment = params[iDescription]; waypoints.Append(new_waypoint); return true; }
bool test_task_aat(TaskManager& task_manager, const Waypoints &waypoints) { const TaskProjection &projection = task_manager.get_ordered_task().get_task_projection(); task_manager.set_factory(OrderedTask::FACTORY_AAT); AbstractTaskFactory &fact = task_manager.get_factory(); const Waypoint *wp; task_report(task_manager, "# adding start\n"); wp = waypoints.lookup_id(1); if (wp) { if (!fact.append(fact.createStart(*wp),false)) { return false; } } task_manager.setActiveTaskPoint(0); task_manager.resume(); task_report(task_manager, "# adding intermediate\n"); wp = waypoints.lookup_id(2); if (wp) { OrderedTaskPoint* tp = fact.createIntermediate(AbstractTaskFactory::AAT_CYLINDER,*wp); if (tp->get_oz()->shape == ObservationZonePoint::CYLINDER) { CylinderZone *cz = (CylinderZone *)tp->get_oz(); cz->setRadius(fixed(30000.0)); tp->update_oz(projection); } if (!fact.append(tp,false)) { return false; } } task_report(task_manager, "# adding intermediate\n"); wp = waypoints.lookup_id(3); if (wp) { OrderedTaskPoint* tp = fact.createIntermediate(AbstractTaskFactory::AAT_CYLINDER,*wp); if (tp->get_oz()->shape == ObservationZonePoint::CYLINDER) { CylinderZone *cz = (CylinderZone *)tp->get_oz(); cz->setRadius(fixed(40000.0)); tp->update_oz(projection); } if (!fact.append(tp,false)) { return false; } } task_report(task_manager, "# adding finish\n"); wp = waypoints.lookup_id(1); if (wp) { if (!fact.append(fact.createFinish(*wp),false)) { return false; } } task_report(task_manager, "# checking task..\n"); if (!fact.validate()) { return false; } if (!task_manager.check_ordered_task()) { return false; } return true; }
bool test_task_manip(TaskManager& task_manager, const Waypoints &waypoints) { if (!test_task_mixed(task_manager, waypoints)) { return false; } AbstractTaskFactory &fact = task_manager.get_factory(); task_report(task_manager, "# removing tp 2\n"); if (!fact.remove(2)) { return false; } task_report(task_manager, "# removing tp 0\n"); if (!fact.remove(0)) { return false; } task_report(task_manager, "# removing tp -1 (illegal)\n"); if (fact.remove(0-1)) { return false; } task_report(task_manager, "# removing tp 50 (illegal)\n"); if (fact.remove(50)) { return false; } OrderedTaskPoint *tp; const Waypoint *wp; task_report(task_manager, "# inserting at 3\n"); wp = waypoints.lookup_id(3); if (wp) { tp = fact.createIntermediate(AbstractTaskFactory::AST_CYLINDER,*wp); if (!fact.insert(tp,3)) return false; } task_report(task_manager, "# auto-replacing at 2 (no morph)\n"); wp = waypoints.lookup_id(9); if (wp) { tp = fact.createIntermediate(AbstractTaskFactory::AST_CYLINDER,*wp); if (!fact.replace(tp,2)) return false; } task_report(task_manager, "# auto-replacing at 2 (morph)\n"); wp = waypoints.lookup_id(9); if (wp) { tp = fact.createStart(*wp); if (!fact.replace(tp,2)) return false; } task_report(task_manager, "# auto-replacing at 0 (morph this)\n"); wp = waypoints.lookup_id(12); if (wp) { tp = fact.createIntermediate(AbstractTaskFactory::AST_CYLINDER,*wp); if (!fact.replace(tp,0)) return false; } task_report(task_manager, "# auto-replacing at end (morph this)\n"); wp = waypoints.lookup_id(14); if (wp) { tp = fact.createIntermediate(AbstractTaskFactory::AST_CYLINDER,*wp); if (!fact.replace(tp,task_manager.task_size()-1)) return false; } task_report(task_manager, "# removing finish point\n"); if (!fact.remove(task_manager.task_size()-1)) { return false; } task_report(task_manager, "# inserting at 50 (equivalent to append)\n"); wp = waypoints.lookup_id(8); if (wp) { tp = fact.createFinish(*wp); if (!fact.insert(tp,50)) return false; } task_report(task_manager, "# inserting at 0 (morph this)\n"); wp = waypoints.lookup_id(3); if (wp) { tp = fact.createFinish(*wp); if (!fact.insert(tp,0)) return false; } task_report(task_manager, "# inserting at 2 (morph this)\n"); wp = waypoints.lookup_id(4); if (wp) { tp = fact.createStart(*wp); if (!fact.insert(tp,2)) return false; } task_report(task_manager, "# inserting at 2 (direct)\n"); wp = waypoints.lookup_id(6); if (wp) { tp = fact.createIntermediate(*wp); if (!fact.insert(tp,2,false)) return false; } task_report(task_manager, "# checking task\n"); if (task_manager.check_ordered_task()) { task_manager.reset(); task_manager.setActiveTaskPoint(0); task_manager.resume(); } else { return false; } return true; }
void MapItemListBuilder::AddWaypoints(const Waypoints &waypoints) { WaypointListBuilderVisitor waypoint_list_builder(list); waypoints.VisitWithinRange(location, range, waypoint_list_builder); }
void WaypointListBuilder::Visit(const Waypoints &waypoints) { if (filter.distance > 0) waypoints.VisitWithinRange(location, filter.distance, *this); else waypoints.VisitNamePrefix(filter.name, *this); }
bool test_task_fai(TaskManager& task_manager, const Waypoints &waypoints) { task_manager.SetFactory(TaskFactoryType::FAI_GENERAL); AbstractTaskFactory &fact = task_manager.GetFactory(); WaypointPtr wp; task_report(task_manager, "# adding start\n"); wp = waypoints.LookupId(1); if (wp) { OrderedTaskPoint *tp = fact.CreateStart(std::move(wp)); if (!fact.Append(*tp)) { return false; } delete tp; } task_manager.SetActiveTaskPoint(0); task_manager.Resume(); task_report(task_manager, "# adding intermdiate\n"); wp = waypoints.LookupId(2); if (wp) { OrderedTaskPoint *tp = fact.CreateIntermediate(std::move(wp)); if (!fact.Append(*tp, false)) { return false; } delete tp; } task_report(task_manager, "# adding intermdiate\n"); wp = waypoints.LookupId(3); if (wp) { OrderedTaskPoint *tp = fact.CreateIntermediate(std::move(wp)); if (!fact.Append(*tp,false)) { return false; } delete tp; } task_report(task_manager, "# adding finish\n"); wp = waypoints.LookupId(1); if (wp) { OrderedTaskPoint *tp = fact.CreateFinish(std::move(wp)); if (!fact.Append(*tp,false)) { return false; } delete tp; } fact.UpdateStatsGeometry(); task_report(task_manager, "# checking task\n"); if (!fact.Validate()) { return false; } if (!task_manager.CheckOrderedTask()) { return false; } return true; }
bool WaypointReaderWinPilot::ParseLine(const TCHAR *line, Waypoints &waypoints) { TCHAR ctemp[4096]; const TCHAR *params[20]; static constexpr unsigned int max_params = ARRAY_SIZE(params); size_t n_params; // If (end-of-file) if (line[0] == '\0') // -> return without error condition return true; // If comment if (line[0] == _T('*')) { if (first) { first = false; welt2000_format = (_tcsstr(line, _T("WRITTEN BY WELT2000")) != nullptr); } // -> return without error condition return true; } if (_tcslen(line) >= ARRAY_SIZE(ctemp)) /* line too long for buffer */ return false; GeoPoint location; // Get fields n_params = ExtractParameters(line, ctemp, params, max_params, true); if (n_params < 6) return false; // Latitude (e.g. 51:15.900N) if (!ParseAngle(params[1], location.latitude, true)) return false; // Longitude (e.g. 00715.900W) if (!ParseAngle(params[2], location.longitude, false)) return false; location.Normalize(); // ensure longitude is within -180:180 Waypoint new_waypoint = factory.Create(location); // Name (e.g. KAMPLI) if (*params[5] == _T('\0')) return false; new_waypoint.name=params[5]; // Altitude (e.g. 458M) /// @todo configurable behaviour if (!ParseAltitude(params[3], new_waypoint.elevation) && !factory.FallbackElevation(new_waypoint)) return false; if (n_params > 6) { // Description (e.g. 119.750 Airport) new_waypoint.comment=params[6]; if (welt2000_format) ParseRunwayDirection(params[6], new_waypoint.runway); } // Waypoint Flags (e.g. AT) ParseFlags(params[4], new_waypoint); waypoints.Append(std::move(new_waypoint)); return true; }
void XCSoarInterface::Shutdown(void) { gcc_unused ScopeBusyIndicator busy; // Show progress dialog ProgressGlue::Create(_("Shutdown, please wait...")); // Log shutdown information LogStartUp(_T("Entering shutdown...")); StartupLogFreeRamAndStorage(); // Turn off all displays globalRunningEvent.reset(); // Stop logger and save igc file ProgressGlue::Create(_("Shutdown, saving logs...")); logger.guiStopLogger(Basic(), true); // Save settings to profile ProgressGlue::Create(_("Shutdown, saving profile...")); Profile::Save(); // Stop sound LogStartUp(_T("SaveSoundSettings")); Profile::SetSoundSettings(); #ifndef DISABLEAUDIOVARIO // VarioSound_EnableSound(false); // VarioSound_Close(); #endif ProgressGlue::Create(_("Shutdown, please wait...")); // Stop threads LogStartUp(_T("Stop threads")); #ifndef ENABLE_OPENGL draw_thread->stop(); #endif calculation_thread->stop(); // Wait for the calculations thread to finish LogStartUp(_T("Waiting for calculation thread")); calculation_thread->join(); delete calculation_thread; calculation_thread = NULL; // Wait for the drawing thread to finish #ifndef ENABLE_OPENGL LogStartUp(_T("Waiting for draw thread")); draw_thread->join(); delete draw_thread; #endif LogStartUp(_T("delete MapWindow")); main_window.map.reset(); // Save the task for the next time ProgressGlue::Create(_("Shutdown, saving task...")); LogStartUp(_T("Save default task")); protected_task_manager->task_save_default(); // Clear waypoint database LogStartUp(_T("Close waypoints")); way_points.clear(); ProgressGlue::Create(_("Shutdown, please wait...")); // Clear weather database LogStartUp(_T("CloseRASP")); RASP.Close(); // Clear terrain database LogStartUp(_T("CloseTerrain")); delete terrain; LogStartUp(_T("CloseTopography")); delete topography; delete marks; // Close any device connections devShutdown(); RawLoggerShutdown(); delete replay; // Save everything in the persistent memory file SaveCalculationsPersist(Basic(), Calculated(), *protected_task_manager, *glide_computer, logger); delete protected_task_manager; delete task_manager; // Kill windows LogStartUp(_T("Destroy Info Boxes")); InfoBoxManager::Destroy(); LogStartUp(_T("Destroy Button Labels")); ButtonLabel::Destroy(); // Close the progress dialog LogStartUp(_T("Close Progress Dialog")); ProgressGlue::Close(); // Clear the EGM96 database CloseGeoid(); delete glide_computer; // Clear airspace database LogStartUp(_T("Close airspace")); airspace_warnings->clear(); airspace_database.clear(); delete airspace_warnings; delete airspace_warning; // Destroy FlarmNet records FlarmNet::Destroy(); delete file_cache; LogStartUp(_T("Close Windows - main ")); main_window.reset(); CloseLanguageFile(); RestoreDisplayOrientation(); StartupLogFreeRamAndStorage(); LogStartUp(_T("Finished shutdown")); }
bool WaypointReaderSeeYou::ParseLine(const TCHAR* line, Waypoints &waypoints) { enum { iName = 0, iLatitude = 3, iLongitude = 4, iElevation = 5, iStyle = 6, iRWDir = 7, iRWLen = 8, iFrequency = 9, iDescription = 10, }; if (first) { first = false; /* skip first line if it doesn't begin with a quotation character (usually the field order line) */ if (line[0] != _T('\"')) return true; } // If (end-of-file or comment) if (StringIsEmpty(line) || StringStartsWith(line, _T("*"))) // -> return without error condition return true; TCHAR ctemp[4096]; if (_tcslen(line) >= ARRAY_SIZE(ctemp)) /* line too long for buffer */ return false; // If task marker is reached ignore all following lines if (StringStartsWith(line, _T("-----Related Tasks-----"))) ignore_following = true; if (ignore_following) return true; // Get fields const TCHAR *params[20]; size_t n_params = ExtractParameters(line, ctemp, params, ARRAY_SIZE(params), true, _T('"')); // Check if the basic fields are provided if (iName >= n_params || iLatitude >= n_params || iLongitude >= n_params) return false; GeoPoint location; // Latitude (e.g. 5115.900N) if (!ParseAngle(params[iLatitude], location.latitude, true)) return false; // Longitude (e.g. 00715.900W) if (!ParseAngle(params[iLongitude], location.longitude, false)) return false; location.Normalize(); // ensure longitude is within -180:180 Waypoint new_waypoint = factory.Create(location); // Name (e.g. "Some Turnpoint") if (*params[iName] == _T('\0')) return false; new_waypoint.name = params[iName]; // Elevation (e.g. 458.0m) /// @todo configurable behaviour if ((iElevation >= n_params || !ParseAltitude(params[iElevation], new_waypoint.elevation)) && !factory.FallbackElevation(new_waypoint)) return false; // Style (e.g. 5) if (iStyle < n_params) ParseStyle(params[iStyle], new_waypoint.type); new_waypoint.flags.turn_point = true; // Frequency & runway direction/length (for airports and landables) // and description (e.g. "Some Description") if (new_waypoint.IsLandable()) { if (iFrequency < n_params) new_waypoint.radio_frequency = RadioFrequency::Parse(params[iFrequency]); // Runway length (e.g. 546.0m) double rwlen = -1; if (iRWLen < n_params && ParseDistance(params[iRWLen], rwlen) && rwlen > 0) new_waypoint.runway.SetLength(uround(rwlen)); if (iRWDir < n_params && *params[iRWDir]) { TCHAR *end; int direction =_tcstol(params[iRWDir], &end, 10); if (end == params[iRWDir] || direction < 0 || direction > 360 || (direction == 0 && rwlen <= 0)) direction = -1; else if (direction == 360) direction = 0; if (direction >= 0) new_waypoint.runway.SetDirectionDegrees(direction); } } if (iDescription < n_params) { /* * This convention was introduced by the OpenAIP * project (http://www.openaip.net/), since no waypoint type * exists for thermal hotspots. */ if (StringStartsWith(params[iDescription], _T("Hotspot"))) new_waypoint.type = Waypoint::Type::THERMAL_HOTSPOT; new_waypoint.comment = params[iDescription]; } waypoints.Append(std::move(new_waypoint)); return true; }
/** * 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.Flags.Airport = true; wp.Altitude = fixed(0.25); waypoints.append(wp); wp = waypoints.create(GeoPoint(Angle::degrees(fixed_zero), Angle::degrees(fixed_one))); wp.Flags.Airport = true; wp.Altitude = fixed(0.25); waypoints.append(wp); wp = waypoints.create(GeoPoint(Angle::degrees(fixed_one), Angle::degrees(fixed_one))); wp.Name = _T("Hello"); wp.Flags.Airport = true; wp.Altitude = fixed_half; waypoints.append(wp); wp = waypoints.create(GeoPoint(Angle::degrees(fixed(0.8)), Angle::degrees(fixed(0.5)))); wp.Name = _T("Unk"); wp.Flags.Airport = true; wp.Altitude = fixed(0.25); waypoints.append(wp); wp = waypoints.create(GeoPoint(Angle::degrees(fixed_one), Angle::degrees(fixed_zero))); wp.Flags.Airport = true; wp.Altitude = fixed(0.25); waypoints.append(wp); wp = waypoints.create(GeoPoint(Angle::degrees(fixed_zero), Angle::degrees(fixed(0.23)))); wp.Flags.Airport = true; wp.Altitude = 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.Flags.Airport = false; wp.Altitude = 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++) { Waypoints::WaypointTree::const_iterator it = waypoints.find_id(i); if (it != waypoints.end()) { #ifdef DO_PRINT fin << it->get_waypoint(); #endif } } } return true; }