FlightGear next
FlightPlan.hxx
Go to the documentation of this file.
1
5
6// Written by James Turner, started 2012.
7//
8// Copyright (C) 2012 James Turner
9//
10// This program is free software; you can redistribute it and/or
11// modify it under the terms of the GNU General Public License as
12// published by the Free Software Foundation; either version 2 of the
13// License, or (at your option) any later version.
14//
15// This program is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
24#ifndef FG_FLIGHTPLAN_HXX
25#define FG_FLIGHTPLAN_HXX
26
27#include <functional>
28
29#include <Navaids/route.hxx>
30#include <Airports/airport.hxx>
31
32namespace flightgear
33{
34
35class Transition;
36class FlightPlan;
37
38typedef SGSharedPtr<FlightPlan> FlightPlanRef;
39
41{
42 VFR = 0,
44 IFR_VFR, // type Y
45 VFR_IFR // type Z
46};
47
56
57class FlightPlan : public RouteBase
58{
59public:
60 virtual ~FlightPlan();
61
65 static FlightPlanRef create();
66
71
72 virtual std::string ident() const;
73 void setIdent(const std::string& s);
74
75 // propogate the GPS/FMS setting for this through to the RoutePath
76 void setFollowLegTrackToFixes(bool tf);
77 bool followLegTrackToFixes() const;
78
79 void setMaxFlyByTurnAngle(double deg);
80 double maxFlyByTurnAngle() const;
81
82 // aircraft approach category as per CFR 97.3, etc
83 // http://www.flightsimaviation.com/data/FARS/part_97-3.html
84 std::string icaoAircraftCategory() const;
85 void setIcaoAircraftCategory(const std::string& cat);
86
87 std::string icaoAircraftType() const
88 { return _aircraftType; }
89
90 void setIcaoAircraftType(const std::string& ty);
91
92 FlightPlanRef clone(const std::string& newIdent = {}, bool convertToFlightPlan = false) const;
93
99 bool isRoute() const;
100
104 class Leg : public SGReferenced
105 {
106 public:
108 { return const_cast<FlightPlan*>(_parent); }
109
111 { return _waypt; }
112
113 // return the next leg after this one
114 Leg* nextLeg() const;
115
124 bool setHoldCount(int count);
125
126 int holdCount() const;
127
128
130
131 unsigned int index() const;
132
133 int altitudeFt() const;
134 double speed(RouteUnits units = DEFAULT_UNITS) const;
135 double altitude(RouteUnits units = DEFAULT_UNITS) const;
136
137 int speedKts() const;
138 double speedMach() const;
139
142
143 void setSpeed(RouteRestriction ty, double speed, RouteUnits units = DEFAULT_UNITS);
144 void setAltitude(RouteRestriction ty, double alt, RouteUnits units = DEFAULT_UNITS);
145
146 double courseDeg() const;
147 double distanceNm() const;
148 double distanceAlongRoute() const;
149
155 void markWaypointDirty();
156 private:
157 friend class FlightPlan;
158
160
161 Leg* cloneFor(FlightPlan* owner) const;
162
163 void writeToProperties(SGPropertyNode* node) const;
164
165 const FlightPlan* _parent;
166 RouteRestriction _speedRestrict = RESTRICT_NONE,
167 _altRestrict = RESTRICT_NONE;
168 double _speed = 0.0;
169 double _altitude = 0.0;
170 RouteUnits _speedUnits = SPEED_KNOTS;
171 RouteUnits _altitudeUnits = ALTITUDE_FEET;
172
173 // if > 0, we will hold at the waypoint using
174 // the published hold side/course
175 // This only works if _waypt is a Hold, either defined by a procedure
176 // or modified to become one
177 int _holdCount = 0;
178
179 WayptRef _waypt;
181 mutable double _pathDistance = -1.0;
182 mutable double _courseDeg = -1.0;
184 mutable double _distanceAlongPath = 11.0;
185 };
186
187 using LegRef = SGSharedPtr<Leg>;
188
189 class DelegateFactory;
190 using DelegateFactoryRef = std::shared_ptr<DelegateFactory>;
191
193 {
194 public:
195 virtual ~Delegate();
196
197 virtual void departureChanged() { }
198 virtual void arrivalChanged() { }
199 virtual void waypointsChanged() { }
200 virtual void cruiseChanged() { }
201 virtual void cleared() { }
202 virtual void activated() { }
203
212 virtual void sequence() { }
213
214 virtual void currentWaypointChanged() { }
215 virtual void endOfFlightPlan() { }
216
217 virtual void loaded() { }
218 protected:
219 Delegate();
220
221 private:
222 friend class FlightPlan;
223
224 // record the factory which created us, so we have the option to clean up
225 DelegateFactoryRef _factory;
226 };
227
228 LegRef insertWayptAtIndex(Waypt* aWpt, int aIndex);
229 void insertWayptsAtIndex(const WayptVec& wps, int aIndex);
230
231 void deleteIndex(int index);
232 void clearAll();
233 void clearLegs();
235
236 int currentIndex() const
237 { return _currentIndex; }
238
239 void sequence();
240
241 void setCurrentIndex(int index);
242
243 void activate();
244
245 void finish();
246
247 bool isActive() const;
248
249 LegRef currentLeg() const;
250 LegRef nextLeg() const;
251 LegRef previousLeg() const;
252
253 int numLegs() const
254 { return static_cast<int>(_legs.size()); }
255
256 LegRef legAtIndex(int index) const;
257
258 int findWayptIndex(const SGGeod& aPos) const;
259 int findWayptIndex(const FGPositionedRef aPos) const;
260
262 int indexOfFirstArrivalWaypoint() const;
265
266 bool load(const SGPath& p);
267 bool save(const SGPath& p) const;
268
269 bool save(std::ostream& stream) const;
270 bool load(std::istream& stream);
271
273 { return _departure; }
274
276 { return _destination; }
277
279 { return _departureRunway; }
280
282 { return _destinationRunway; }
283
285 { return _approach; }
286
287 void setDeparture(FGAirport* apt);
288 void setDeparture(FGRunway* rwy);
289
290 void clearDeparture();
291
292 SID* sid() const
293 { return _sid; }
294
295 Transition* sidTransition() const;
296
297 void setSID(SID* sid, const std::string& transition = std::string());
298
299 void setSID(Transition* sidWithTrans);
300
301 void clearSID();
302
303 void setDestination(FGAirport* apt);
304 void setDestination(FGRunway* rwy);
305
306 void clearDestination();
307
308 FGAirportRef alternate() const;
309 void setAlternate(FGAirportRef alt);
310
315 void setApproach(Approach* app, const std::string& transition = {});
316
317 void setApproach(Transition* approachWithTrans);
318
319
320 Transition* approachTransition() const;
321
322 STAR* star() const
323 { return _star; }
324
325 Transition* starTransition() const;
326
327 void setSTAR(STAR* star, const std::string& transition = std::string());
328
329 void setSTAR(Transition* starWithTrans);
330
331 void clearSTAR();
332
333 double totalDistanceNm() const
334 { return _totalDistance; }
335
337 { return _estimatedDuration; }
338
339 void setEstimatedDurationMinutes(int minutes);
340
346
352 SGGeod pointAlongRoute(int aIndex, double aOffsetNm) const;
353
359 SGGeod pointAlongRouteNorm(int aIndex, double aOffsetNorm) const;
360
369 SGGeod vicinityForInsertIndex(int aIndex) const;
370
376 WayptRef waypointFromString(const std::string& target, const SGGeod& vicinity = SGGeod::invalid());
377
385 bool parseICAORouteString(const std::string& routeData);
386
387 std::string asICAORouteString() const;
388
389 // ICAO flight-plan data
392
393 void setFlightType(ICAOFlightType type);
395
396 void setCallsign(const std::string& callsign);
397 std::string callsign() const
398 { return _callsign; }
399
400 void setRemarks(const std::string& remarks);
401 std::string remarks() const
402 { return _remarks; }
403
404// cruise data
405 void setCruiseSpeedKnots(int kts);
406 int cruiseSpeedKnots() const;
407
408 void setCruiseSpeedMach(double mach);
409 double cruiseSpeedMach() const;
410
411 void setCruiseSpeedKPH(int kmh);
412 int cruiseSpeedKPH() const;
413
414 void setCruiseFlightLevel(int flightLevel);
415 int cruiseFlightLevel() const;
416
417 void setCruiseAltitudeFt(int altFt);
418 int cruiseAltitudeFt() const;
419
420 void setCruiseAltitudeM(int altM);
421 int cruiseAltitudeM() const;
422
428 {
429 public:
430 virtual Delegate* createFlightPlanDelegate(FlightPlan* fp) = 0;
431 virtual void destroyFlightPlanDelegate(FlightPlan* fp, Delegate* d);
432 };
433
436
437 void addDelegate(Delegate* d);
438 void removeDelegate(Delegate* d);
439
440 using LegVisitor = std::function<void(Leg*)>;
441 void forEachLeg(const LegVisitor& lv);
442private:
443 FlightPlan(bool isRoute);
444
445 friend class Leg;
446
447 int findLegIndex(const Leg* l) const;
448
449 void lockDelegates();
450 void unlockDelegates();
451
452 void notifyCleared();
453
454 unsigned int _delegateLock = 0;
455 bool _arrivalChanged = false,
456 _departureChanged = false,
457 _waypointsChanged = false,
458 _currentWaypointChanged = false,
459 _cruiseDataChanged = false;
460 bool _didLoadFP = false;
461
462 void saveToProperties(SGPropertyNode* d) const;
463
464 bool loadXmlFormat(const SGPath& path);
465 bool loadGpxFormat(const SGPath& path);
466 bool loadPlainTextFormat(const SGPath& path);
467
468 bool loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
469 bool loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
470 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
471 WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
472
473 double magvarDegAt(const SGGeod& pos) const;
474 bool parseICAOLatLon(const std::string &s, SGGeod &p);
475
479 bool expandVias();
480
481 std::string _ident;
482 std::string _callsign;
483 std::string _remarks;
484 std::string _aircraftType;
485 const bool _isRoute;
486
487 int _currentIndex;
488 bool _followLegTrackToFix;
489 char _aircraftCategory;
492 int _cruiseAirspeedKnots = 0;
493 double _cruiseAirspeedMach = 0.0;
494 int _cruiseAirspeedKph = 0;
495 int _cruiseFlightLevel = 0;
496 int _cruiseAltitudeFt = 0;
497 int _cruiseAltitudeM = 0;
498 int _estimatedDuration = 0;
499 double _maxFlyByTurnAngle = 90.0;
500
501 FGAirportRef _departure, _destination;
502 FGAirportRef _alternate;
503 FGRunway *_departureRunway, *_destinationRunway;
504 SGSharedPtr<SID> _sid;
505 SGSharedPtr<STAR> _star;
506 SGSharedPtr<Approach> _approach;
507 std::string _sidTransition, _starTransition, _approachTransition;
508
509 double _totalDistance;
510 void rebuildLegData();
511
512 using LegVec = std::vector<LegRef>;
513 LegVec _legs;
514
515 std::vector<Delegate*> _delegates;
516};
517
518} // of namespace flightgear
519
520#endif // of FG_FLIGHTPLAN_HXX
double altitude
Definition ADA.cxx:46
#define p(x)
SGSharedPtr< FGAirport > FGAirportRef
Describe an approach procedure, including the missed approach segment.
abstract interface for creating delegates automatically when a flight-plan is created or loaded
virtual Delegate * createFlightPlanDelegate(FlightPlan *fp)=0
virtual void destroyFlightPlanDelegate(FlightPlan *fp, Delegate *d)
virtual void sequence()
Invoked when the C++ code determines the active leg is done / next leg should be sequenced.
flight-plan leg encapsulation
double speed(RouteUnits units=DEFAULT_UNITS) const
double distanceAlongRoute() const
RouteRestriction altitudeRestriction() const
void setSpeed(RouteRestriction ty, double speed, RouteUnits units=DEFAULT_UNITS)
RouteRestriction speedRestriction() const
bool setHoldCount(int count)
requesting holding at the waypoint upon reaching it.
void markWaypointDirty()
helper function, if the waypoint is modified in some way, to notify the flightplan owning this leg,...
unsigned int index() const
FlightPlan * owner() const
void setAltitude(RouteRestriction ty, double alt, RouteUnits units=DEFAULT_UNITS)
ICAOFlightType flightType() const
void setCruiseSpeedMach(double mach)
std::string icaoAircraftCategory() const
SGSharedPtr< Leg > LegRef
void setAlternate(FGAirportRef alt)
void deleteIndex(int index)
Approach * approach() const
std::shared_ptr< DelegateFactory > DelegateFactoryRef
FGAirportRef departureAirport() const
double maxFlyByTurnAngle() const
int indexOfFirstNonDepartureWaypoint() const
int indexOfFirstApproachWaypoint() const
std::string remarks() const
LegRef nextLeg() const
SGGeod vicinityForInsertIndex(int aIndex) const
given an index to insert a waypoint into the plan, find the geographical vicinity.
int clearWayptsWithFlag(WayptFlag flag)
LegRef currentLeg() const
bool parseICAORouteString(const std::string &routeData)
attempt to replace the route waypoints (and potentially the SID and STAR) based on an ICAO standard r...
void setSID(SID *sid, const std::string &transition=std::string())
int indexOfFirstArrivalWaypoint() const
void insertWayptsAtIndex(const WayptVec &wps, int aIndex)
FlightPlanRef clone(const std::string &newIdent={}, bool convertToFlightPlan=false) const
void setCruiseSpeedKPH(int kmh)
static void unregisterDelegateFactory(DelegateFactoryRef df)
void setSTAR(STAR *star, const std::string &transition=std::string())
std::string callsign() const
bool isRoute() const
is this flight-pan a route (for planning) or an active flight-plan (which can be flown?...
static FlightPlanRef create()
create a FlightPlan with isRoute not set
void setEstimatedDurationMinutes(int minutes)
void forEachLeg(const LegVisitor &lv)
void setCruiseFlightLevel(int flightLevel)
void setDeparture(FGAirport *apt)
double totalDistanceNm() const
FGRunway * destinationRunway() const
std::string asICAORouteString() const
void setCruiseAltitudeFt(int altFt)
FGAirportRef alternate() const
void setFlightRules(ICAOFlightRules rules)
double cruiseSpeedMach() const
void setIcaoAircraftType(const std::string &ty)
LegRef insertWayptAtIndex(Waypt *aWpt, int aIndex)
FGRunway * departureRunway() const
void setRemarks(const std::string &remarks)
void setApproach(Approach *app, const std::string &transition={})
note setting an approach will implicitly update the destination airport and runway to match
int estimatedDurationMinutes() const
LegRef previousLeg() const
int cruiseFlightLevel() const
void addDelegate(Delegate *d)
bool followLegTrackToFixes() const
void setDestination(FGAirport *apt)
void setCallsign(const std::string &callsign)
void setFlightType(ICAOFlightType type)
Transition * approachTransition() const
virtual std::string ident() const
int findWayptIndex(const SGGeod &aPos) const
void setIdent(const std::string &s)
void setCurrentIndex(int index)
LegRef legAtIndex(int index) const
void setCruiseSpeedKnots(int kts)
bool load(const SGPath &p)
void setFollowLegTrackToFixes(bool tf)
FGAirportRef destinationAirport() const
WayptRef waypointFromString(const std::string &target, const SGGeod &vicinity=SGGeod::invalid())
Create a WayPoint from a string in the following format:'vicinity' specifies the search area,...
bool save(const SGPath &p) const
void setMaxFlyByTurnAngle(double deg)
static void registerDelegateFactory(DelegateFactoryRef df)
Transition * sidTransition() const
SGGeod pointAlongRoute(int aIndex, double aOffsetNm) const
given a waypoint index, and an offset in NM, find the geodetic position on the route path.
void removeDelegate(Delegate *d)
std::string icaoAircraftType() const
SGGeod pointAlongRouteNorm(int aIndex, double aOffsetNorm) const
given a waypoint index, find a point at a normalised offset, which must be [-1 .
std::function< void(Leg *)> LegVisitor
void setIcaoAircraftCategory(const std::string &cat)
int indexOfDestinationRunwayWaypoint() const
void computeDurationMinutes()
computeDurationMinutes - use performance data and cruise data to estimate enroute time
static FlightPlanRef createRoute()
@factory to create a FlightPlan with isRoute=true
void setCruiseAltitudeM(int altM)
ICAOFlightRules flightRules() const
Transition * starTransition() const
Encapsulate a transition segment.
Definition procedure.hxx:70
Abstract base class for waypoints (and things that are treated similarly by navigation systems).
Definition route.hxx:105
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
Definition Addon.cxx:53
SGSharedPtr< FlightPlan > FlightPlanRef
@ DEFAULT_UNITS
Definition route.hxx:83
@ SPEED_KNOTS
Definition route.hxx:87
@ ALTITUDE_FEET
Definition route.hxx:84
SGSharedPtr< FGPositioned > FGPositionedRef
Definition airways.cxx:49
SGSharedPtr< Waypt > WayptRef
std::vector< WayptRef > WayptVec
RouteRestriction
Definition route.hxx:70
@ RESTRICT_NONE
Definition route.hxx:71