FlightGear next
route_mgr.cxx
Go to the documentation of this file.
1// route_mgr.cxx - manage a route (i.e. a collection of waypoints)
2/*
3 * SPDX-FileCopyrightText: (C) 2004 Curtis L. Olson http://www.flightgear.org/~curt
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7
8#include <config.h>
9
10#include <cstdio>
11
12#include <simgear/compiler.h>
13#include "route_mgr.hxx"
14
15#include <simgear/misc/sg_path.hxx>
16#include <simgear/misc/strutils.hxx>
17#include <simgear/structure/commands.hxx>
18#include <simgear/structure/exception.hxx>
19
20#include <simgear/timing/sg_time.hxx>
21#include <simgear/sg_inlines.h>
22
23#include <Main/globals.hxx>
24#include "Main/fg_props.hxx"
26#include <Navaids/waypoint.hxx>
27#include <Navaids/procedure.hxx>
28#include <Navaids/routePath.hxx>
29
30#include "Airports/airport.hxx"
31#include "Airports/runways.hxx"
32#include <GUI/new_gui.hxx>
33#include <GUI/dialog.hxx>
34#include <GUI/MessageBox.hxx>
35
36#define RM "/autopilot/route-manager/"
37
38using namespace flightgear;
39using std::string;
40namespace su = simgear::strutils;
41
42static bool commandLoadFlightPlan(const SGPropertyNode* arg, SGPropertyNode *)
43{
44 auto self = globals->get_subsystem<FGRouteMgr>();
45 SGPath path = SGPath::fromUtf8(arg->getStringValue("path"));
46 return self->loadRoute(path);
47}
48
49static bool commandSaveFlightPlan(const SGPropertyNode* arg, SGPropertyNode *)
50{
51 auto self = globals->get_subsystem<FGRouteMgr>();
52 SGPath path = SGPath::fromUtf8(arg->getStringValue("path"));
53 const SGPath authorizedPath = SGPath(path).validate(true /* write */);
54
55 if (!authorizedPath.isNull()) {
56 return self->saveRoute(authorizedPath);
57 } else {
58 std::string msg =
59 "The route manager was asked to write the flightplan to '" +
60 path.utf8Str() + "', but this path is not authorized for writing. " +
61 "Please choose another location, for instance in the $FG_HOME/Export "
62 "folder (" + (globals->get_fg_home() / "Export").utf8Str() + ").";
63
64 SG_LOG(SG_AUTOPILOT, SG_ALERT, msg);
65 modalMessageBox("FlightGear", "Unable to write to the specified file",
66 msg);
67 return false;
68 }
69}
70
71static bool commandActivateFlightPlan(const SGPropertyNode* arg, SGPropertyNode *)
72{
73 auto self = globals->get_subsystem<FGRouteMgr>();
74 bool activate = arg->getBoolValue("activate", true);
75 if (activate) {
76 self->activate();
77 } else {
78 self->deactivate();
79 }
80
81 return true;
82}
83
84static bool commandClearFlightPlan(const SGPropertyNode*, SGPropertyNode *)
85{
86 auto self = globals->get_subsystem<FGRouteMgr>();
87 self->clearRoute();
88 return true;
89}
90
91static bool commandSetActiveWaypt(const SGPropertyNode* arg, SGPropertyNode *)
92{
93 auto self = globals->get_subsystem<FGRouteMgr>();
94 int index = arg->getIntValue("index");
95 if ((index < 0) || (index >= self->numLegs())) {
96 return false;
97 }
98
99 self->jumpToIndex(index);
100 return true;
101}
102
103static bool commandInsertWaypt(const SGPropertyNode* arg, SGPropertyNode *)
104{
105 auto self = globals->get_subsystem<FGRouteMgr>();
106 const bool haveIndex = arg->hasChild("index");
107 int index = arg->getIntValue("index");
108
109 std::string ident(arg->getStringValue("id"));
110 int alt = arg->getIntValue("altitude-ft", -999);
111 int ias = arg->getIntValue("speed-knots", -999);
112
113 WayptRef wp;
114 // lat/lon may be supplied to narrow down navaid search, or to specify
115 // a raw waypoint
116 SGGeod pos = SGGeod::invalid();
117 if (arg->hasChild("longitude-deg")) {
118 pos = SGGeod::fromDeg(arg->getDoubleValue("longitude-deg"),
119 arg->getDoubleValue("latitude-deg"));
120 }
121
122 if (arg->hasChild("navaid")) {
123 if (!pos.isValid()) {
124 pos = self->flightPlan()->vicinityForInsertIndex(haveIndex ? index : -1 /* append */);
125 }
126
129
130 FGPositionedRef p = FGPositioned::findClosestWithIdent(arg->getStringValue("navaid"), pos, &filter);
131 if (!p) {
132 SG_LOG(SG_AUTOPILOT, SG_WARN, "Unable to find navaid with ident:" << arg->getStringValue("navaid"));
133 return false;
134 }
135
136 if (arg->hasChild("navaid", 1)) {
137 // intersection of two radials
138 FGPositionedRef p2 = FGPositioned::findClosestWithIdent(arg->getStringValue("navaid[1]"), pos, &filter);
139 if (!p2) {
140 SG_LOG( SG_AUTOPILOT, SG_INFO, "Unable to find FGPositioned with ident:" << arg->getStringValue("navaid[1]"));
141 return false;
142 }
143
144 double r1 = arg->getDoubleValue("radial"),
145 r2 = arg->getDoubleValue("radial[1]");
146
147 SGGeod intersection;
148 bool ok = SGGeodesy::radialIntersection(p->geod(), r1, p2->geod(), r2, intersection);
149 if (!ok) {
150 SG_LOG(SG_AUTOPILOT, SG_INFO, "no valid intersection for:" << p->ident()
151 << "," << p2->ident());
152 return false;
153 }
154
155 std::string name = p->ident() + "-" + p2->ident();
156 wp = new BasicWaypt(intersection, name, NULL);
157 } else if (arg->hasChild("offset-nm") && arg->hasChild("radial")) {
158 // offset radial from navaid
159 double radial = arg->getDoubleValue("radial");
160 double distanceNm = arg->getDoubleValue("offset-nm");
161 //radial += magvar->getDoubleValue(); // convert to true bearing
162 wp = new OffsetNavaidWaypoint(p, NULL, radial, distanceNm);
163 } else {
164 wp = new NavaidWaypoint(p, NULL);
165 }
166 } else if (arg->hasChild("airport")) {
167 const FGAirport* apt = fgFindAirportID(arg->getStringValue("airport"));
168 if (!apt) {
169 SG_LOG(SG_AUTOPILOT, SG_INFO, "no such airport" << arg->getStringValue("airport"));
170 return false;
171 }
172
173 if (arg->hasChild("runway")) {
174 if (!apt->hasRunwayWithIdent(arg->getStringValue("runway"))) {
175 SG_LOG(SG_AUTOPILOT, SG_INFO, "No runway: " << arg->getStringValue("runway") << " at " << apt->ident());
176 return false;
177 }
178
179 FGRunway* runway = apt->getRunwayByIdent(arg->getStringValue("runway"));
180 wp = new RunwayWaypt(runway, NULL);
181 } else {
182 wp = new NavaidWaypoint((FGAirport*) apt, NULL);
183 }
184 } else if (arg->hasChild("text")) {
185 const auto t = su::strip(arg->getStringValue("text"));
186 if (pos.isValid()) {
187 // if 'pos' is valid, use it as the search vicinity
188 wp = self->flightPlan()->waypointFromString(t, pos);
189 } else {
190 const int searchIndex = haveIndex ? index : -1;
191 wp = self->waypointFromString(t, searchIndex);
192 }
193
194 if (!wp) { // failed to build waypoint
195 SG_LOG(SG_AUTOPILOT, SG_WARN, "insert-waypoint failed: couldn't parse waypoint from '" << t << "'");
196 return false;
197 }
198 } else if (pos.isValid()) {
199 // just a raw lat/lon
200 wp = new BasicWaypt(pos, ident, NULL);
201 } else {
202 return false; // failed to build waypoint
203 }
204
205 FlightPlan::Leg* leg = self->flightPlan()->insertWayptAtIndex(wp, index);
206 if (alt >= 0) {
207 leg->setAltitude(RESTRICT_AT, alt);
208 }
209
210 if (ias > 0) {
211 leg->setSpeed(RESTRICT_AT, ias);
212 }
213
214 return true;
215}
216
217static bool commandDeleteWaypt(const SGPropertyNode* arg, SGPropertyNode *)
218{
219 auto self = globals->get_subsystem<FGRouteMgr>();
220 int index = arg->getIntValue("index");
221 self->removeLegAtIndex(index);
222 return true;
223}
224
226
228 input(fgGetNode( RM "input", true )),
229 mirror(fgGetNode( RM "route", true ))
230{
231 listener = new InputListener(this);
232 input->setStringValue("");
233 input->addChangeListener(listener);
234
235 SGCommandMgr* cmdMgr = globals->get_commands();
236 cmdMgr->addCommand("define-user-waypoint", this, &FGRouteMgr::commandDefineUserWaypoint);
237 cmdMgr->addCommand("delete-user-waypoint", this, &FGRouteMgr::commandDeleteUserWaypoint);
238
239 cmdMgr->addCommand("load-flightplan", commandLoadFlightPlan);
240 cmdMgr->addCommand("save-flightplan", commandSaveFlightPlan);
241 cmdMgr->addCommand("activate-flightplan", commandActivateFlightPlan);
242 cmdMgr->addCommand("clear-flightplan", commandClearFlightPlan);
243 cmdMgr->addCommand("set-active-waypt", commandSetActiveWaypt);
244 cmdMgr->addCommand("insert-waypt", commandInsertWaypt);
245 cmdMgr->addCommand("delete-waypt", commandDeleteWaypt);
246}
247
248
250{
251 input->removeChangeListener(listener);
252 delete listener;
253
254 if (_plan) {
255 _plan->removeDelegate(this);
256 }
257
258 SGCommandMgr* cmdMgr = globals->get_commands();
259 cmdMgr->removeCommand("define-user-waypoint");
260 cmdMgr->removeCommand("delete-user-waypoint");
261 cmdMgr->removeCommand("load-flightplan");
262 cmdMgr->removeCommand("save-flightplan");
263 cmdMgr->removeCommand("activate-flightplan");
264 cmdMgr->removeCommand("clear-flightplan");
265 cmdMgr->removeCommand("set-active-waypt");
266 cmdMgr->removeCommand("insert-waypt");
267 cmdMgr->removeCommand("delete-waypt");
268}
269
270
272 SGPropertyNode_ptr rm(fgGetNode(RM));
273
274 magvar = fgGetNode("/environment/magnetic-variation-deg", true);
275
276 departure = fgGetNode(RM "departure", true);
277 departure->tie("airport", SGStringValueMethods<FGRouteMgr>(*this,
278 &FGRouteMgr::getDepartureICAO, &FGRouteMgr::setDepartureICAO));
279 departure->tie("runway", SGStringValueMethods<FGRouteMgr>(*this,
280 &FGRouteMgr::getDepartureRunway,
281 &FGRouteMgr::setDepartureRunway));
282 departure->tie("sid", SGStringValueMethods<FGRouteMgr>(*this,
283 &FGRouteMgr::getSID,
284 &FGRouteMgr::setSID));
285
286 departure->tie("name", SGStringValueMethods<FGRouteMgr>(*this,
287 &FGRouteMgr::getDepartureName, nullptr));
288 departure->tie("field-elevation-ft", SGRawValueMethods<FGRouteMgr, double>(*this,
289 &FGRouteMgr::getDepartureFieldElevation, nullptr));
290 departure->getChild("etd", 0, true);
291 departure->getChild("takeoff-time", 0, true);
292
293 destination = fgGetNode(RM "destination", true);
294 destination->getChild("airport", 0, true);
295
296 destination->tie("airport", SGStringValueMethods<FGRouteMgr>(*this,
297 &FGRouteMgr::getDestinationICAO, &FGRouteMgr::setDestinationICAO));
298 destination->tie("runway", SGStringValueMethods<FGRouteMgr>(*this,
299 &FGRouteMgr::getDestinationRunway,
300 &FGRouteMgr::setDestinationRunway));
301 destination->tie("star", SGStringValueMethods<FGRouteMgr>(*this,
302 &FGRouteMgr::getSTAR,
303 &FGRouteMgr::setSTAR));
304 destination->tie("approach", SGStringValueMethods<FGRouteMgr>(*this,
305 &FGRouteMgr::getApproach,
306 &FGRouteMgr::setApproach));
307
308 destination->tie("name", SGStringValueMethods<FGRouteMgr>(*this,
309 &FGRouteMgr::getDestinationName, nullptr));
310 destination->tie("field-elevation-ft", SGRawValueMethods<FGRouteMgr, double>(*this,
311 &FGRouteMgr::getDestinationFieldElevation, nullptr));
312
313 destination->getChild("eta", 0, true);
314 destination->getChild("eta-seconds", 0, true);
315 destination->getChild("touchdown-time", 0, true);
316
317 alternate = fgGetNode(RM "alternate", true);
318 alternate->tie("airport", SGStringValueMethods<FGRouteMgr>(*this,
319 &FGRouteMgr::getAlternate,
320 &FGRouteMgr::setAlternate));
321 alternate->tie("name", SGStringValueMethods<FGRouteMgr>(*this,
322 &FGRouteMgr::getAlternateName, nullptr));
323
324 cruise = fgGetNode(RM "cruise", true);
325 cruise->tie("altitude-ft", SGRawValueMethods<FGRouteMgr, int>(*this,
326 &FGRouteMgr::getCruiseAltitudeFt,
327 &FGRouteMgr::setCruiseAltitudeFt));
328 cruise->tie("flight-level", SGRawValueMethods<FGRouteMgr, int>(*this,
329 &FGRouteMgr::getCruiseFlightLevel,
330 &FGRouteMgr::setCruiseFlightLevel));
331 cruise->tie("speed-kts", SGRawValueMethods<FGRouteMgr, int>(*this,
332 &FGRouteMgr::getCruiseSpeedKnots,
333 &FGRouteMgr::setCruiseSpeedKnots));
334 cruise->tie("mach", SGRawValueMethods<FGRouteMgr, double>(*this,
335 &FGRouteMgr::getCruiseSpeedMach,
336 &FGRouteMgr::setCruiseSpeedMach));
337
338 totalDistance = fgGetNode(RM "total-distance", true);
339 totalDistance->setDoubleValue(0.0);
340 distanceToGo = fgGetNode(RM "distance-remaining-nm", true);
341 distanceToGo->setDoubleValue(0.0);
342
343 ete = fgGetNode(RM "ete", true);
344 ete->setDoubleValue(0.0);
345
346 elapsedFlightTime = fgGetNode(RM "flight-time", true);
347 elapsedFlightTime->setDoubleValue(0.0);
348
349 active = fgGetNode(RM "active", true);
350 active->setBoolValue(false);
351
352 airborne = fgGetNode(RM "airborne", true);
353 airborne->setBoolValue(false);
354
355 _edited = fgGetNode(RM "signals/edited", true);
356 _flightplanChanged = fgGetNode(RM "signals/flightplan-changed", true);
357 _isRoute = fgGetNode(RM "is-route", true);
358
359 _currentWpt = fgGetNode(RM "current-wp", true);
360 _currentWpt->setAttribute(SGPropertyNode::LISTENER_SAFE, true);
361 _currentWpt->tie(SGRawValueMethods<FGRouteMgr, int>
363
364 wp0 = fgGetNode(RM "wp", 0, true);
365 wp0->getChild("id", 0, true);
366 wp0->getChild("dist", 0, true);
367 wp0->getChild("eta", 0, true);
368 wp0->getChild("eta-seconds", 0, true);
369 wp0->getChild("bearing-deg", 0, true);
370
371 wp1 = fgGetNode(RM "wp", 1, true);
372 wp1->getChild("id", 0, true);
373 wp1->getChild("dist", 0, true);
374 wp1->getChild("eta", 0, true);
375 wp1->getChild("eta-seconds", 0, true);
376
377 wpn = fgGetNode(RM "wp-last", 0, true);
378 wpn->getChild("dist", 0, true);
379 wpn->getChild("eta", 0, true);
380 wpn->getChild("eta-seconds", 0, true);
381
382 _pathNode = fgGetNode(RM "file-path", 0, true);
383}
384
385
387{
389 _plan->setIdent("default-flightplan");
390
391 SGPath path = SGPath::fromUtf8(_pathNode->getStringValue());
392 if (!path.isNull()) {
393 SG_LOG(SG_AUTOPILOT, SG_INFO, "loading flight-plan from: " << path);
394 loadRoute(path);
395 }
396
397 _isRoute->setBoolValue(_plan->isRoute());
398
399// this code only matters for the --wp option now - perhaps the option
400// should be deprecated in favour of an explicit flight-plan file?
401// then the global initial waypoint list could die.
402 string_list *waypoints = globals->get_initial_waypoints();
403 if (waypoints) {
404 for (const auto& wpStr : *waypoints) {
405 WayptRef w = waypointFromString(wpStr, -1);
406 if (w) {
407 _plan->insertWayptAtIndex(w, -1);
408 } else {
409 SG_LOG(SG_AUTOPILOT, SG_WARN, "Failed to create waypoint from '" << wpStr << "'");
410 }
411 }
412
413 update_mirror();
414 }
415
416 weightOnWheels = fgGetNode("/gear/gear[0]/wow", true);
417 groundSpeed = fgGetNode("/velocities/groundspeed-kt", true);
418
419 // check airbone flag agrees with presets
420}
421
424
426{
427 return active->getBoolValue();
428}
429
430bool FGRouteMgr::saveRoute(const SGPath& p)
431{
432 if (!_plan) {
433 return false;
434 }
435
436 return _plan->save(p);
437}
438
439bool FGRouteMgr::loadRoute(const SGPath& p)
440{
442 if (!fp->load(p)) {
443 delete fp;
444 return false;
445 }
446
447 setFlightPlan(fp);
448 return true;
449}
450
452{
453 return _plan;
454}
455
457{
458 if (plan == _plan) {
459 return;
460 }
461
462 if (_plan) {
463 _plan->removeDelegate(this);
464
465 if (isRouteActive()) {
466 _plan->finish();
467 }
468
469 active->setBoolValue(false);
470 }
471
472 _plan = plan;
473 _plan->addDelegate(this);
474 _isRoute->setBoolValue(_plan->isRoute());
475 _flightplanChanged->fireValueChanged();
476
477// fire all the callbacks!
478 departureChanged();
479 arrivalChanged();
480 waypointsChanged();
481 currentWaypointChanged();
482}
483
484void FGRouteMgr::departureChanged()
485{
486 auto gui = globals->get_subsystem<NewGUI>();
487 FGDialog* rmDlg = gui ? gui->getDialog("route-manager") : NULL;
488 if (rmDlg) {
489 rmDlg->runCallback("departure-changed");
490 }
491}
492
493void FGRouteMgr::arrivalChanged()
494{
495 auto gui = globals->get_subsystem<NewGUI>();
496 FGDialog* rmDlg = gui ? gui->getDialog("route-manager") : NULL;
497 if (rmDlg) {
498 rmDlg->runCallback("arrival-changed");
499 }
500}
501
502
503void FGRouteMgr::update( double dt )
504{
505 if (dt <= 0.0) {
506 return; // paused, nothing to do here
507 }
508
509 double gs = groundSpeed->getDoubleValue();
510 if (airborne->getBoolValue()) {
511 time_t now = globals->get_time_params()->get_cur_time();
512 elapsedFlightTime->setDoubleValue(difftime(now, _takeoffTime));
513
514 if (weightOnWheels->getBoolValue()) {
515 // touch down
516 destination->setIntValue("touchdown-time", now);
517 airborne->setBoolValue(false);
518 }
519 } else { // not airborne
520 if (weightOnWheels->getBoolValue() || (gs < 40)) {
521 // either taking-off or rolling-out after touchdown
522 } else {
523 airborne->setBoolValue(true);
524 _takeoffTime = globals->get_time_params()->get_cur_time(); // start the clock
525 departure->setIntValue("takeoff-time", _takeoffTime);
526 }
527 }
528
529 if (!active->getBoolValue()) {
530 return;
531 }
532
533// basic course/distance information
534 SGGeod currentPos = globals->get_aircraft_position();
535
536 FlightPlan::Leg* leg = _plan ? _plan->currentLeg() : NULL;
537 if (!leg) {
538 return;
539 }
540
541 // use RoutePath to compute location of active WP
542 if (!_routePath) {
543 _routePath.reset(new RoutePath{_plan});
544 }
545
546 SGGeod wpPos = _routePath->positionForIndex(_plan->currentIndex());
547 double courseDeg, az2, distanceM;
548 SGGeodesy::inverse(currentPos, wpPos, courseDeg, az2, distanceM);
549
550 // update wp0 / wp1 / wp-last
551 wp0->setDoubleValue("dist", distanceM * SG_METER_TO_NM);
552 wp0->setDoubleValue("true-bearing-deg", courseDeg);
553 courseDeg -= magvar->getDoubleValue(); // expose magnetic bearing
554 wp0->setDoubleValue("bearing-deg", courseDeg);
555 setETAPropertyFromDistance(wp0, distanceM);
556
557 double totalPathDistanceNm = _plan->totalDistanceNm();
558 double totalDistanceRemaining = distanceM * SG_METER_TO_NM; // distance to current waypoint
559
560// total distance to go, is direct distance to wp0, plus the remaining
561// path distance from wp0
562 totalDistanceRemaining += (totalPathDistanceNm - leg->distanceAlongRoute());
563
564 wp0->setDoubleValue("distance-along-route-nm",
565 leg->distanceAlongRoute());
566 wp0->setDoubleValue("remaining-distance-nm",
567 totalPathDistanceNm - leg->distanceAlongRoute());
568
569 FlightPlan::Leg* nextLeg = _plan->nextLeg();
570 if (nextLeg) {
571 wpPos = _routePath->positionForIndex(_plan->currentIndex() + 1);
572 SGGeodesy::inverse(currentPos, wpPos, courseDeg, az2, distanceM);
573
574 wp1->setDoubleValue("dist", distanceM * SG_METER_TO_NM);
575 wp1->setDoubleValue("true-bearing-deg", courseDeg);
576 courseDeg -= magvar->getDoubleValue(); // expose magnetic bearing
577 wp1->setDoubleValue("bearing-deg", courseDeg);
578 setETAPropertyFromDistance(wp1, distanceM);
579 wp1->setDoubleValue("distance-along-route-nm",
580 nextLeg->distanceAlongRoute());
581 wp1->setDoubleValue("remaining-distance-nm",
582 totalPathDistanceNm - nextLeg->distanceAlongRoute());
583 }
584
585 distanceToGo->setDoubleValue(totalDistanceRemaining);
586 wpn->setDoubleValue("dist", totalDistanceRemaining);
587 ete->setDoubleValue(totalDistanceRemaining / gs * 3600.0);
588 setETAPropertyFromDistance(wpn, totalDistanceRemaining);
589}
590
592{
593 _routePath.reset();
594 if (_plan) {
595 _plan->clearLegs();
596 }
597}
598
600{
601 if (_plan && _plan->currentLeg()) {
602 return _plan->currentLeg()->waypoint();
603 }
604
605 return NULL;
606}
607
609{
610 if (!_plan) {
611 return 0;
612 }
613
614 return _plan->currentIndex();
615}
616
618{
619 if (!_plan) {
620 throw sg_range_exception("wayptAtindex: no flightplan");
621 }
622
623 return _plan->legAtIndex(index)->waypoint();
624}
625
627{
628 if (_plan) {
629 return _plan->numLegs();
630 }
631
632 return 0;
633}
634
635void FGRouteMgr::setETAPropertyFromDistance(SGPropertyNode_ptr aProp, double aDistance)
636{
637 double speed = groundSpeed->getDoubleValue();
638 if (speed < 1.0) {
639 aProp->setStringValue("--:--");
640 return;
641 }
642
643 char eta_str[64];
644 double eta = aDistance * SG_METER_TO_NM / speed;
645 aProp->getChild("eta-seconds")->setIntValue( eta * 3600 );
646 if ( eta >= 100.0 ) {
647 eta = 99.999; // clamp
648 }
649
650 if ( eta < (1.0/6.0) ) {
651 eta *= 60.0; // within 10 minutes, bump up to min/secs
652 }
653
654 int major = (int)eta,
655 minor = (int)((eta - (int)eta) * 60.0);
656 snprintf( eta_str, 64, "%d:%02d", major, minor );
657 aProp->getChild("eta")->setStringValue( eta_str );
658}
659
661{
662 if (!_plan) {
663 return;
664 }
665
666 _plan->deleteIndex(aIndex);
667}
668
669void FGRouteMgr::waypointsChanged()
670{
671 update_mirror();
672 _edited->fireValueChanged();
673}
674
675// mirror internal route to the property system for inspection by other subsystems
676void FGRouteMgr::update_mirror()
677{
678 _routePath.reset(); // wipe this so we re-compute on next update()
679 mirror->removeChildren("wp");
680 auto gui = globals->get_subsystem<NewGUI>();
681 FGDialog* rmDlg = gui ? gui->getDialog("route-manager") : NULL;
682
683 if (!_plan) {
684 mirror->setIntValue("num", 0);
685 if (rmDlg) {
686 rmDlg->updateValues();
687 }
688 return;
689 }
690
691 int num = _plan->numLegs();
692
693 for (int i = 0; i < num; i++) {
694 FlightPlan::Leg* leg = _plan->legAtIndex(i);
695 WayptRef wp = leg->waypoint();
696 SGPropertyNode *prop = mirror->getChild("wp", i, 1);
697
698 const SGGeod& pos(wp->position());
699 prop->setStringValue("id", wp->ident());
700 prop->setDoubleValue("longitude-deg", pos.getLongitudeDeg());
701 prop->setDoubleValue("latitude-deg",pos.getLatitudeDeg());
702
703 // leg course+distance
704
705 prop->setDoubleValue("leg-bearing-true-deg", leg->courseDeg());
706 prop->setDoubleValue("leg-distance-nm", leg->distanceNm());
707 prop->setDoubleValue("distance-along-route-nm", leg->distanceAlongRoute());
708
709 if (leg->altitudeRestriction() != RESTRICT_NONE) {
710 double ft = leg->altitudeFt();
711 prop->setDoubleValue("altitude-m", ft * SG_FEET_TO_METER);
712 prop->setDoubleValue("altitude-ft", ft);
713 prop->setIntValue("flight-level", static_cast<int>(ft / 1000) * 10);
714 } else {
715 prop->setDoubleValue("altitude-m", -9999.9);
716 prop->setDoubleValue("altitude-ft", -9999.9);
717 }
718
720 prop->setDoubleValue("speed-mach", leg->speedMach());
721 } else if (leg->speedRestriction() != RESTRICT_NONE) {
722 prop->setDoubleValue("speed-kts", leg->speedKts());
723 }
724
725 if (wp->flag(WPT_ARRIVAL)) {
726 prop->setBoolValue("arrival", true);
727 }
728
729 if (wp->flag(WPT_DEPARTURE)) {
730 prop->setBoolValue("departure", true);
731 }
732
733 if (wp->flag(WPT_MISS)) {
734 prop->setBoolValue("missed-approach", true);
735 }
736
737 prop->setBoolValue("generated", wp->flag(WPT_GENERATED));
738 } // of waypoint iteration
739
740 // set number as listener attachment point
741 mirror->setIntValue("num", _plan->numLegs());
742
743 if (rmDlg) {
744 rmDlg->updateValues();
745 }
746
747 totalDistance->setDoubleValue(_plan->totalDistanceNm());
748}
749
750// command interface /autopilot/route-manager/input:
751//
752// @CLEAR ... clear route
753// @POP ... remove first entry
754// @DELETE3 ... delete 4th entry
755// @INSERT2:KSFO@900 ... insert "KSFO@900" as 3rd entry
756// KSFO@900 ... append "KSFO@900"
757//
758void FGRouteMgr::InputListener::valueChanged(SGPropertyNode *prop)
759{
760 const auto input = su::uppercase(su::strip(prop->getStringValue()));
761 if (input.empty()) {
762 return;
763 }
764
765 if (input == "@CLEAR") {
766 mgr->clearRoute();
767 } else if (input == "@ACTIVATE") {
768 mgr->activate();
769 } else if (input == "@LOAD") {
770 SGPath path = SGPath::fromUtf8(mgr->_pathNode->getStringValue());
771 mgr->loadRoute(path);
772 } else if (input == "@SAVE") {
773 SGPath path = SGPath::fromUtf8(mgr->_pathNode->getStringValue());
774 const SGPath authorizedPath = SGPath(path).validate(true /* write */);
775
776 if (!authorizedPath.isNull()) {
777 mgr->saveRoute(authorizedPath);
778 } else {
779 std::string msg =
780 "The route manager was asked to write the flightplan to '" +
781 path.utf8Str() + "', but this path is not authorized for writing. " +
782 "Please choose another location, for instance in the $FG_HOME/Export "
783 "folder (" +
784 (globals->get_fg_home() / "Export").utf8Str() + ").";
785
786 SG_LOG(SG_AUTOPILOT, SG_ALERT, msg);
787 modalMessageBox("FlightGear", "Unable to write to the specified file",
788 msg);
789 }
790 } else if (input == "@NEXT") {
791 mgr->jumpToIndex(mgr->currentIndex() + 1);
792 } else if (input == "@PREVIOUS") {
793 mgr->jumpToIndex(mgr->currentIndex() - 1);
794 } else if (su::starts_with(input, "@JUMP")) {
795 const int index = stoi(input.substr(5));
796 mgr->jumpToIndex(index);
797 } else if (su::starts_with(input, "@DELETE")) {
798 const int index = stoi(input.substr(7));
799 mgr->removeLegAtIndex(index);
800 } else if (su::starts_with(input, "@INSERT")) {
801 size_t pos = 0;
802 const auto arg = input.substr(7); // input without prefix
803 const int index = stoi(arg, &pos, 10);
804 if (arg.at(pos) != ':') {
805 SG_LOG(SG_AUTOPILOT, SG_WARN, "@INSERT: couldn't parse index from:'" << input << "'");
806 return;
807 }
808
809 const auto wpString = su::strip(arg.substr(pos + 1));
810 const auto newWp = mgr->waypointFromString(wpString, index);
811 mgr->flightPlan()->insertWayptAtIndex(newWp, index);
812 } else {
813 const auto newWp = mgr->waypointFromString(input, -1);
814 mgr->flightPlan()->insertWayptAtIndex(newWp, -1);
815 }
816}
817
819{
820 if (!_plan) {
821 SG_LOG(SG_AUTOPILOT, SG_WARN, "::activate, no flight plan defined");
822 return false;
823 }
824
825 if (isRouteActive()) {
826 SG_LOG(SG_AUTOPILOT, SG_WARN, "duplicate route-activation, no-op");
827 return false;
828 }
829
830 _plan->activate();
831 active->setBoolValue(true);
832 SG_LOG(SG_AUTOPILOT, SG_INFO, "route-manager, activate route ok");
833 return true;
834}
835
837{
838 if (!isRouteActive()) {
839 return;
840 }
841
842 SG_LOG(SG_AUTOPILOT, SG_INFO, "deactivating flight plan");
843 active->setBoolValue(false);
844}
845
847{
848 if (!_plan) {
849 return;
850 }
851
852 // this method is tied() to current-wp property, but FlightPlan::setCurrentIndex
853 // will throw on invalid input, so guard against invalid values here.
854 // See Sentry FLIGHTGEAR-71
855 if ((index < -1) || (index >= _plan->numLegs())) {
856 SG_LOG(SG_AUTOPILOT, SG_WARN, "FGRouteMgr::jumpToIndex: ignoring invalid index:" << index);
857 return;
858 }
859
860 _plan->setCurrentIndex(index);
861}
862
863void FGRouteMgr::currentWaypointChanged()
864{
865 Waypt* cur = currentWaypt();
866 FlightPlan::Leg* next = _plan ? _plan->nextLeg() : NULL;
867
868 wp0->getChild("id")->setStringValue(cur ? cur->ident() : "");
869 wp1->getChild("id")->setStringValue(next ? next->waypoint()->ident() : "");
870
871 _currentWpt->fireValueChanged();
872 SG_LOG(SG_AUTOPILOT, SG_INFO, "route manager, current-wp is now " << currentIndex());
873}
874
875std::string FGRouteMgr::getDepartureICAO() const
876{
877 if (!_plan || !_plan->departureAirport()) {
878 return "";
879 }
880
881 return _plan->departureAirport()->ident();
882}
883
884std::string FGRouteMgr::getDepartureName() const
885{
886 if (!_plan || !_plan->departureAirport()) {
887 return "";
888 }
889
890 return _plan->departureAirport()->name();
891}
892
893std::string FGRouteMgr::getDepartureRunway() const
894{
895 if (_plan && _plan->departureRunway()) {
896 return _plan->departureRunway()->ident();
897 }
898
899 return "";
900}
901
902void FGRouteMgr::setDepartureRunway(const std::string& aIdent)
903{
904 if (!_plan) {
905 return;
906 }
907
908 FGAirport* apt = _plan->departureAirport();
909 if (!apt || aIdent.empty()) {
910 _plan->setDeparture(apt);
911 } else if (apt->hasRunwayWithIdent(aIdent)) {
912 _plan->setDeparture(apt->getRunwayByIdent(aIdent));
913 }
914}
915
916void FGRouteMgr::setDepartureICAO(const std::string& aIdent)
917{
918 if (!_plan) {
919 return;
920 }
921
922 if (aIdent.length() < 3) {
923 _plan->setDeparture((FGAirport*) nullptr);
924 } else {
925 _plan->setDeparture(FGAirport::findByIdent(aIdent));
926 }
927}
928
929std::string FGRouteMgr::getSID() const
930{
931 if (_plan && _plan->sid()) {
932 return _plan->sid()->ident();
933 }
934
935 return "";
936}
937
938static double headingDiffDeg(double a, double b)
939{
940 double rawDiff = b - a;
941 SG_NORMALIZE_RANGE(rawDiff, -180.0, 180.0);
942 return rawDiff;
943}
944
945flightgear::SID* createDefaultSID(FGRunway* aRunway, double enrouteCourse)
946{
947 if (!aRunway) {
948 return NULL;
949 }
950
951 double runwayElevFt = aRunway->end().getElevationFt();
952 WayptVec wpts;
953 std::ostringstream ss;
954 ss << aRunway->ident() << "-3";
955
956 SGGeod p = aRunway->pointOnCenterline(aRunway->lengthM() + (3.0 * SG_NM_TO_METER));
957 WayptRef w = new BasicWaypt(p, ss.str(), NULL);
958 w->setAltitude(runwayElevFt + 3000.0, RESTRICT_AT);
959 wpts.push_back(w);
960
961 ss.str("");
962 ss << aRunway->ident() << "-6";
963 p = aRunway->pointOnCenterline(aRunway->lengthM() + (6.0 * SG_NM_TO_METER));
964 w = new BasicWaypt(p, ss.str(), NULL);
965 w->setAltitude(runwayElevFt + 6000.0, RESTRICT_AT);
966 wpts.push_back(w);
967
968 if (enrouteCourse >= 0.0) {
969 // valid enroute course
970 int index = 3;
971 double course = aRunway->headingDeg();
972 double diff;
973 while (fabs(diff = headingDiffDeg(course, enrouteCourse)) > 45.0) {
974 // turn in the sign of the heading change 45 degrees
975 course += copysign(45.0, diff);
976 ss.str("");
977 ss << "DEP-" << index++;
978 SGGeod pos = wpts.back()->position();
979 pos = SGGeodesy::direct(pos, course, 3.0 * SG_NM_TO_METER);
980 w = new BasicWaypt(pos, ss.str(), NULL);
981 wpts.push_back(w);
982 }
983 } else {
984 // no enroute course, just keep runway heading
985 ss.str("");
986 ss << aRunway->ident() << "-9";
987 p = aRunway->pointOnCenterline(aRunway->lengthM() + (9.0 * SG_NM_TO_METER));
988 w = new BasicWaypt(p, ss.str(), NULL);
989 w->setAltitude(runwayElevFt + 9000.0, RESTRICT_AT);
990 wpts.push_back(w);
991 }
992
993 for (Waypt* w : wpts) {
994 w->setFlag(WPT_DEPARTURE);
995 w->setFlag(WPT_GENERATED);
996 }
997
998 return flightgear::SID::createTempSID("DEFAULT", aRunway, wpts);
999}
1000
1001void FGRouteMgr::setSID(const std::string& aIdent)
1002{
1003 if (!_plan) {
1004 return;
1005 }
1006
1007 FGAirport* apt = _plan->departureAirport();
1008 if (!apt || aIdent.empty()) {
1009 _plan->setSID((flightgear::SID*) NULL);
1010 return;
1011 }
1012
1013 if (aIdent == "DEFAULT") {
1014 double enrouteCourse = -1.0;
1015 if (_plan->destinationAirport()) {
1016 enrouteCourse = SGGeodesy::courseDeg(apt->geod(), _plan->destinationAirport()->geod());
1017 }
1018
1019 _plan->setSID(createDefaultSID(_plan->departureRunway(), enrouteCourse));
1020 return;
1021 }
1022
1023 size_t hyphenPos = aIdent.find('-');
1024 if (hyphenPos != string::npos) {
1025 string sidIdent = aIdent.substr(0, hyphenPos);
1026 string transIdent = aIdent.substr(hyphenPos + 1);
1027
1028 flightgear::SID* sid = apt->findSIDWithIdent(sidIdent);
1029 Transition* trans = sid ? sid->findTransitionByName(transIdent) : NULL;
1030 _plan->setSID(trans);
1031 } else {
1032 _plan->setSID(apt->findSIDWithIdent(aIdent));
1033 }
1034}
1035
1036std::string FGRouteMgr::getDestinationICAO() const
1037{
1038 if (!_plan || !_plan->destinationAirport()) {
1039 return "";
1040 }
1041
1042 return _plan->destinationAirport()->ident();
1043}
1044
1045std::string FGRouteMgr::getDestinationName() const
1046{
1047 if (!_plan || !_plan->destinationAirport()) {
1048 return "";
1049 }
1050
1051 return _plan->destinationAirport()->name();
1052}
1053
1054void FGRouteMgr::setDestinationICAO(const std::string& aIdent)
1055{
1056 if (!_plan) {
1057 return;
1058 }
1059
1060 if (aIdent.length() < 3) {
1061 _plan->setDestination((FGAirport*) NULL);
1062 } else {
1063 _plan->setDestination(FGAirport::findByIdent(aIdent));
1064 }
1065}
1066
1067std::string FGRouteMgr::getDestinationRunway() const
1068{
1069 if (_plan && _plan->destinationRunway()) {
1070 return _plan->destinationRunway()->ident();
1071 }
1072
1073 return "";
1074}
1075
1076void FGRouteMgr::setDestinationRunway(const std::string& aIdent)
1077{
1078 if (!_plan) {
1079 return;
1080 }
1081
1082 FGAirport* apt = _plan->destinationAirport();
1083 if (!apt || aIdent.empty()) {
1084 _plan->setDestination(apt);
1085 } else if (apt->hasRunwayWithIdent(aIdent)) {
1086 _plan->setDestination(apt->getRunwayByIdent(aIdent));
1087 }
1088}
1089
1090std::string FGRouteMgr::getApproach() const
1091{
1092 if (_plan && _plan->approach()) {
1093 return _plan->approach()->ident();
1094 }
1095
1096 return "";
1097}
1098
1099flightgear::Approach* createDefaultApproach(FGRunway* aRunway, double aEnrouteCourse)
1100{
1101 if (!aRunway) {
1102 return NULL;
1103 }
1104
1105 double thresholdElevFt = aRunway->threshold().getElevationFt();
1106 const double approachHeightFt = 2000.0;
1107 double glideslopeDistanceM = (approachHeightFt * SG_FEET_TO_METER) /
1108 tan(3.0 * SG_DEGREES_TO_RADIANS);
1109
1110 std::ostringstream ss;
1111 ss << aRunway->ident() << "-12";
1112 WayptVec wpts;
1113 SGGeod p = aRunway->pointOnCenterline(-12.0 * SG_NM_TO_METER);
1114 WayptRef w = new BasicWaypt(p, ss.str(), NULL);
1115 w->setAltitude(thresholdElevFt + 4000, RESTRICT_AT);
1116 wpts.push_back(w);
1117
1118// work back form the first point on the centerline
1119
1120 if (aEnrouteCourse >= 0.0) {
1121 // valid enroute course
1122 int index = 4;
1123 double course = aRunway->headingDeg();
1124 double diff;
1125 while (fabs(diff = headingDiffDeg(aEnrouteCourse, course)) > 45.0) {
1126 // turn in the sign of the heading change 45 degrees
1127 course -= copysign(45.0, diff);
1128 ss.str("");
1129 ss << "APP-" << index++;
1130 SGGeod pos = wpts.front()->position();
1131 pos = SGGeodesy::direct(pos, course + 180.0, 3.0 * SG_NM_TO_METER);
1132 w = new BasicWaypt(pos, ss.str(), NULL);
1133 wpts.insert(wpts.begin(), w);
1134 }
1135 }
1136
1137 p = aRunway->pointOnCenterline(-8.0 * SG_NM_TO_METER);
1138 ss.str("");
1139 ss << aRunway->ident() << "-8";
1140 w = new BasicWaypt(p, ss.str(), NULL);
1141 w->setAltitude(thresholdElevFt + approachHeightFt, RESTRICT_AT);
1142 wpts.push_back(w);
1143
1144 p = aRunway->pointOnCenterline(-glideslopeDistanceM);
1145 ss.str("");
1146 ss << aRunway->ident() << "-GS";
1147 w = new BasicWaypt(p, ss.str(), NULL);
1148 w->setAltitude(thresholdElevFt + approachHeightFt, RESTRICT_AT);
1149 wpts.push_back(w);
1150
1151 for (Waypt* w : wpts) {
1152 w->setFlag(WPT_APPROACH);
1153 w->setFlag(WPT_GENERATED);
1154 }
1155
1156 return Approach::createTempApproach("DEFAULT", aRunway, wpts);
1157}
1158
1159void FGRouteMgr::setApproach(const std::string& aIdent)
1160{
1161 if (!_plan) {
1162 return;
1163 }
1164
1165 FGAirport* apt = _plan->destinationAirport();
1166 if (aIdent == "DEFAULT") {
1167 double enrouteCourse = -1.0;
1168 if (_plan->departureAirport()) {
1169 enrouteCourse = SGGeodesy::courseDeg(_plan->departureAirport()->geod(), apt->geod());
1170 }
1171
1172 _plan->setApproach(createDefaultApproach(_plan->destinationRunway(), enrouteCourse));
1173 return;
1174 }
1175
1176 if (!apt || aIdent.empty()) {
1177 _plan->setApproach(static_cast<Approach*>(nullptr));
1178 } else {
1179 _plan->setApproach(apt->findApproachWithIdent(aIdent));
1180 }
1181}
1182
1183std::string FGRouteMgr::getSTAR() const
1184{
1185 if (_plan && _plan->star()) {
1186 return _plan->star()->ident();
1187 }
1188
1189 return "";
1190}
1191
1192void FGRouteMgr::setSTAR(const std::string& aIdent)
1193{
1194 if (!_plan) {
1195 return;
1196 }
1197
1198 FGAirport* apt = _plan->destinationAirport();
1199 if (!apt || aIdent.empty()) {
1200 _plan->setSTAR((STAR*) NULL);
1201 return;
1202 }
1203
1204 string ident(aIdent);
1205 size_t hyphenPos = ident.find('-');
1206 if (hyphenPos != string::npos) {
1207 string starIdent = ident.substr(0, hyphenPos);
1208 string transIdent = ident.substr(hyphenPos + 1);
1209
1210 STAR* star = apt->findSTARWithIdent(starIdent);
1211 Transition* trans = star ? star->findTransitionByName(transIdent) : NULL;
1212 _plan->setSTAR(trans);
1213 } else {
1214 _plan->setSTAR(apt->findSTARWithIdent(aIdent));
1215 }
1216}
1217
1218WayptRef FGRouteMgr::waypointFromString(const std::string& target, int insertPosition)
1219{
1220 return _plan->waypointFromString(target, _plan->vicinityForInsertIndex(insertPosition));
1221}
1222
1223double FGRouteMgr::getDepartureFieldElevation() const
1224{
1225 if (!_plan || !_plan->departureAirport()) {
1226 return 0.0;
1227 }
1228
1229 return _plan->departureAirport()->elevation();
1230}
1231
1232double FGRouteMgr::getDestinationFieldElevation() const
1233{
1234 if (!_plan || !_plan->destinationAirport()) {
1235 return 0.0;
1236 }
1237
1238 return _plan->destinationAirport()->elevation();
1239}
1240
1241int FGRouteMgr::getCruiseAltitudeFt() const
1242{
1243 if (!_plan)
1244 return 0;
1245
1246 return _plan->cruiseAltitudeFt();
1247}
1248
1249void FGRouteMgr::setCruiseAltitudeFt(int ft)
1250{
1251 if (!_plan)
1252 return;
1253
1254 _plan->setCruiseAltitudeFt(ft);
1255}
1256
1257int FGRouteMgr::getCruiseFlightLevel() const
1258{
1259 if (!_plan)
1260 return 0;
1261
1262 return _plan->cruiseFlightLevel();
1263}
1264
1265void FGRouteMgr::setCruiseFlightLevel(int fl)
1266{
1267 if (!_plan)
1268 return;
1269
1270 _plan->setCruiseFlightLevel(fl);
1271}
1272
1273int FGRouteMgr::getCruiseSpeedKnots() const
1274{
1275 if (!_plan)
1276 return 0;
1277
1278 return _plan->cruiseSpeedKnots();
1279}
1280
1281void FGRouteMgr::setCruiseSpeedKnots(int kts)
1282{
1283 if (!_plan)
1284 return;
1285
1286 _plan->setCruiseSpeedKnots(kts);
1287}
1288
1289double FGRouteMgr::getCruiseSpeedMach() const
1290{
1291 if (!_plan)
1292 return 0.0;
1293
1294 return _plan->cruiseSpeedMach();
1295}
1296
1297void FGRouteMgr::setCruiseSpeedMach(double m)
1298{
1299 if (!_plan)
1300 return;
1301
1302 _plan->setCruiseSpeedMach(m);
1303}
1304
1305string FGRouteMgr::getAlternate() const
1306{
1307 if (!_plan || !_plan->alternate())
1308 return {};
1309
1310 return _plan->alternate()->ident();
1311}
1312
1313std::string FGRouteMgr::getAlternateName() const
1314{
1315 if (!_plan || !_plan->alternate())
1316 return {};
1317
1318 return _plan->alternate()->name();
1319}
1320
1321void FGRouteMgr::setAlternate(const string &icao)
1322{
1323 if (!_plan)
1324 return;
1325
1326 _plan->setAlternate(FGAirport::findByIdent(icao));
1327 alternate->fireValueChanged();
1328}
1329
1330SGPropertyNode_ptr FGRouteMgr::wayptNodeAtIndex(int index) const
1331{
1332 if ((index < 0) || (index >= numWaypts())) {
1333 throw sg_range_exception("waypt index out of range", "FGRouteMgr::wayptAtIndex");
1334 }
1335
1336 return mirror->getChild("wp", index);
1337}
1338
1339bool FGRouteMgr::commandDefineUserWaypoint(const SGPropertyNode * arg, SGPropertyNode * root)
1340{
1341 std::string ident = arg->getStringValue("ident");
1342 if (ident.empty()) {
1343 SG_LOG(SG_AUTOPILOT, SG_WARN, "missing ident defining user waypoint");
1344 return false;
1345 }
1346
1347 // check for duplicate idents
1348 FGPositioned::TypeFilter f(FGPositioned::WAYPOINT);
1350 if (!dups.empty()) {
1351 SG_LOG(SG_AUTOPILOT, SG_WARN, "defineUserWaypoint: non-unique waypoint identifier:" << ident);
1352 return false;
1353 }
1354
1355 const bool temporary = arg->getBoolValue("temporary");
1356 SGGeod pos(SGGeod::fromDeg(arg->getDoubleValue("longitude-deg"),
1357 arg->getDoubleValue("latitude-deg")));
1358 const auto name = arg->getStringValue("name");
1360 temporary, name);
1361 return true;
1362}
1363
1364bool FGRouteMgr::commandDeleteUserWaypoint(const SGPropertyNode * arg, SGPropertyNode * root)
1365{
1366 std::string ident = arg->getStringValue("ident");
1367 if (ident.empty()) {
1368 SG_LOG(SG_AUTOPILOT, SG_WARN, "missing ident deleting user waypoint");
1369 return false;
1370 }
1371
1372 FGPositioned::TypeFilter f(FGPositioned::WAYPOINT);
1373 auto existing = FGPositioned::findFirstWithIdent(ident, &f);
1374 if (!existing) {
1375 SG_LOG(SG_AUTOPILOT, SG_WARN, "no user waypoint with ident:" << ident);
1376 return false;
1377 }
1378
1379 return FGPositioned::deleteWaypoint(existing);
1380}
1381
1382
1383// Register the subsystem.
1384SGSubsystemMgr::Registrant<FGRouteMgr> registrantFGRouteMgr(
1385 SGSubsystemMgr::GENERAL,
1386 {{"gui", SGSubsystemMgr::Dependency::HARD}});
#define p2(x, y)
#define p(x)
#define i(x)
const FGAirport * fgFindAirportID(const std::string &id)
Definition airport.cxx:523
FGRunwayRef getRunwayByIdent(const std::string &aIdent) const
Definition airport.cxx:182
static FGAirportRef findByIdent(const std::string &aIdent)
Helper to look up an FGAirport instance by unique ident.
Definition airport.cxx:489
flightgear::STAR * findSTARWithIdent(const std::string &aIdent) const
Definition airport.cxx:921
bool hasRunwayWithIdent(const std::string &aIdent) const
Definition airport.cxx:162
flightgear::Approach * findApproachWithIdent(const std::string &aIdent) const
Definition airport.cxx:954
flightgear::SID * findSIDWithIdent(const std::string &aIdent) const
Definition airport.cxx:887
An XML-configured dialog box.
Definition dialog.hxx:21
const SGPath & get_fg_home() const
Definition globals.hxx:213
static FGPositionedRef createWaypoint(FGPositioned::Type aType, const std::string &aIdent, const SGGeod &aPos, bool isTemporary=false, const std::string &aName={})
static FGPositionedRef findClosestWithIdent(const std::string &aIdent, const SGGeod &aPos, Filter *aFilter=NULL)
virtual const SGGeod & geod() const
static FGPositionedRef findFirstWithIdent(const std::string &aIdent, Filter *aFilter)
static FGPositionedList findAllWithIdent(const std::string &aIdent, Filter *aFilter=NULL, bool aExact=true)
Find all items with the specified ident.
const std::string & ident() const
static bool deleteWaypoint(FGPositionedRef aWpt)
Top level route manager class.
Definition route_mgr.hxx:27
int numWaypts() const
Definition route_mgr.hxx:56
void deactivate()
deactivate the route if active
flightgear::WayptRef waypointFromString(const std::string &target, int insertPosition)
Buiild a waypoint from a string description.
flightgear::Waypt * currentWaypt() const
bool isRouteActive() const
void clearRoute()
void setFlightPlan(const flightgear::FlightPlanRef &plan)
void bind() override
flightgear::Waypt * wayptAtIndex(int index) const
bool activate()
Activate a built route.
void update(double dt) override
void postinit() override
bool saveRoute(const SGPath &p)
void init() override
void removeLegAtIndex(int aIndex)
int numLegs() const
SGPropertyNode_ptr wayptNodeAtIndex(int index) const
void unbind() override
int currentIndex() const
bool loadRoute(const SGPath &p)
void jumpToIndex(int index)
Set the current waypoint to the specified index.
flightgear::FlightPlanRef flightPlan() const
double headingDeg() const
Runway heading in degrees.
SGGeod pointOnCenterline(double aOffset) const
Retrieve a position on the extended centerline.
double lengthM() const
SGGeod end() const
Get the 'far' end - this is equivalent to calling pointOnCenterline(lengthFt());.
Definition runways.cxx:94
SGGeod threshold() const
Get the (possibly displaced) threshold point.
Definition runways.cxx:99
XML-configured GUI subsystem.
Definition new_gui.hxx:31
Describe an approach procedure, including the missed approach segment.
static Approach * createTempApproach(const std::string &aIdent, FGRunway *aRunway, const WayptVec &aPath)
Definition procedure.cxx:58
Transition * findTransitionByName(const std::string &aIdent) const
Find an enroute transition waypoint by identifier.
flight-plan leg encapsulation
double distanceAlongRoute() const
RouteRestriction altitudeRestriction() const
void setSpeed(RouteRestriction ty, double speed, RouteUnits units=DEFAULT_UNITS)
RouteRestriction speedRestriction() const
void setAltitude(RouteRestriction ty, double alt, RouteUnits units=DEFAULT_UNITS)
static FlightPlanRef create()
create a FlightPlan with isRoute not set
bool load(const SGPath &p)
Waypoint based upon a navaid.
Definition waypoint.hxx:63
Waypoint based upon a runway.
Definition waypoint.hxx:117
static SID * createTempSID(const std::string &aIdent, FGRunway *aRunway, const WayptVec &aPath)
Abstract base class for waypoints (and things that are treated similarly by navigation systems).
Definition route.hxx:105
virtual std::string ident() const
Identifier assoicated with the waypoint.
Definition route.cxx:199
const char * name
FGGlobals * globals
Definition globals.cxx:142
std::vector< std::string > string_list
Definition globals.hxx:36
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
Definition Addon.cxx:53
SGSharedPtr< FlightPlan > FlightPlanRef
MessageBoxResult modalMessageBox(const std::string &caption, const std::string &msg, const std::string &moreText)
SGSharedPtr< FGPositioned > FGPositionedRef
Definition airways.cxx:49
SGSharedPtr< Waypt > WayptRef
@ WPT_DEPARTURE
Definition route.hxx:54
@ WPT_MISS
segment is part of missed approach
Definition route.hxx:46
@ WPT_APPROACH
Definition route.hxx:60
@ WPT_ARRIVAL
Definition route.hxx:55
@ WPT_GENERATED
waypoint was created automatically (not manually entered/loaded) for example waypoints from airway ro...
Definition route.hxx:52
std::vector< WayptRef > WayptVec
@ RESTRICT_NONE
Definition route.hxx:71
@ RESTRICT_AT
Definition route.hxx:72
@ SPEED_RESTRICT_MACH
encode an 'AT' restriction in Mach, not IAS
Definition route.hxx:76
std::vector< FGPositionedRef > FGPositionedList
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
Definition proptest.cpp:27
static bool commandClearFlightPlan(const SGPropertyNode *, SGPropertyNode *)
Definition route_mgr.cxx:84
static double headingDiffDeg(double a, double b)
flightgear::Approach * createDefaultApproach(FGRunway *aRunway, double aEnrouteCourse)
static bool commandInsertWaypt(const SGPropertyNode *arg, SGPropertyNode *)
flightgear::SID * createDefaultSID(FGRunway *aRunway, double enrouteCourse)
#define RM
Definition route_mgr.cxx:36
static bool commandDeleteWaypt(const SGPropertyNode *arg, SGPropertyNode *)
static bool commandSaveFlightPlan(const SGPropertyNode *arg, SGPropertyNode *)
Definition route_mgr.cxx:49
static bool commandActivateFlightPlan(const SGPropertyNode *arg, SGPropertyNode *)
Definition route_mgr.cxx:71
static bool commandSetActiveWaypt(const SGPropertyNode *arg, SGPropertyNode *)
Definition route_mgr.cxx:91
static bool commandLoadFlightPlan(const SGPropertyNode *arg, SGPropertyNode *)
Definition route_mgr.cxx:42
SGSubsystemMgr::Registrant< FGRouteMgr > registrantFGRouteMgr(SGSubsystemMgr::GENERAL, {{"gui", SGSubsystemMgr::Dependency::HARD}})