2 * FlightPlan.hxx - defines a full flight-plan object, including
3 * departure, cruise, arrival information and waypoints
6 // Written by James Turner, started 2012.
8 // Copyright (C) 2012 James Turner
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.
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.
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.
24 #ifndef FG_FLIGHTPLAN_HXX
25 #define FG_FLIGHTPLAN_HXX
27 #include <Navaids/route.hxx>
28 #include <Airports/airport.hxx>
36 typedef SGSharedPtr<FlightPlan> FlightPlanRef;
38 const char ICAO_AIRCRAFT_CATEGORY_A = 'A';
39 const char ICAO_AIRCRAFT_CATEGORY_B = 'B';
40 const char ICAO_AIRCRAFT_CATEGORY_C = 'C';
41 const char ICAO_AIRCRAFT_CATEGORY_D = 'D';
42 const char ICAO_AIRCRAFT_CATEGORY_E = 'E';
44 class FlightPlan : public RouteBase
48 virtual ~FlightPlan();
50 virtual std::string ident() const;
51 void setIdent(const std::string& s);
53 // propogate the GPS/FMS setting for this through to the RoutePath
54 void setFollowLegTrackToFixes(bool tf);
55 bool followLegTrackToFixes() const;
57 // aircraft approach category as per CFR 97.3, etc
58 // http://www.flightsimaviation.com/data/FARS/part_97-3.html
59 std::string icaoAircraftCategory() const;
60 void setIcaoAircraftCategory(const std::string& cat);
62 FlightPlan* clone(const std::string& newIdent = std::string()) const;
65 * flight-plan leg encapsulation
70 FlightPlan* owner() const
73 Waypt* waypoint() const
76 // reutrn the next leg after this one
79 unsigned int index() const;
81 int altitudeFt() const;
85 double speedMach() const;
87 RouteRestriction altitudeRestriction() const;
88 RouteRestriction speedRestriction() const;
90 void setSpeed(RouteRestriction ty, double speed);
91 void setAltitude(RouteRestriction ty, int altFt);
93 double courseDeg() const;
94 double distanceNm() const;
95 double distanceAlongRoute() const;
97 friend class FlightPlan;
99 Leg(FlightPlan* owner, WayptRef wpt);
101 Leg* cloneFor(FlightPlan* owner) const;
104 RouteRestriction _speedRestrict, _altRestrict;
108 /// length of this leg following the flown path
109 mutable double _pathDistance;
110 mutable double _courseDeg;
111 /// total distance of this leg from departure point
112 mutable double _distanceAlongPath;
120 virtual void departureChanged() { }
121 virtual void arrivalChanged() { }
122 virtual void waypointsChanged() { }
123 virtual void cleared() { }
124 virtual void activated() { }
125 virtual void currentWaypointChanged() { }
126 virtual void endOfFlightPlan() { }
131 void removeInner(Delegate* d);
133 void runDepartureChanged();
134 void runArrivalChanged();
135 void runWaypointsChanged();
136 void runCurrentWaypointChanged();
141 friend class FlightPlan;
143 bool _deleteWithPlan;
147 Leg* insertWayptAtIndex(Waypt* aWpt, int aIndex);
148 void insertWayptsAtIndex(const WayptVec& wps, int aIndex);
150 void deleteIndex(int index);
152 int clearWayptsWithFlag(WayptFlag flag);
154 int currentIndex() const
155 { return _currentIndex; }
157 void setCurrentIndex(int index);
163 Leg* currentLeg() const;
164 Leg* nextLeg() const;
165 Leg* previousLeg() const;
168 { return _legs.size(); }
170 Leg* legAtIndex(int index) const;
171 int findLegIndex(const Leg* l) const;
173 int findWayptIndex(const SGGeod& aPos) const;
174 int findWayptIndex(const FGPositionedRef aPos) const;
176 bool load(const SGPath& p);
177 bool save(const SGPath& p);
179 FGAirportRef departureAirport() const
180 { return _departure; }
182 FGAirportRef destinationAirport() const
183 { return _destination; }
185 FGRunway* departureRunway() const
186 { return _departureRunway; }
188 FGRunway* destinationRunway() const
189 { return _destinationRunway; }
191 Approach* approach() const
192 { return _approach; }
194 void setDeparture(FGAirport* apt);
195 void setDeparture(FGRunway* rwy);
200 Transition* sidTransition() const;
202 void setSID(SID* sid, const std::string& transition = std::string());
204 void setSID(Transition* sidWithTrans);
206 void setDestination(FGAirport* apt);
207 void setDestination(FGRunway* rwy);
210 * note setting an approach will implicitly update the destination
211 * airport and runway to match
213 void setApproach(Approach* app);
218 Transition* starTransition() const;
220 void setSTAR(STAR* star, const std::string& transition = std::string());
222 void setSTAR(Transition* starWithTrans);
224 double totalDistanceNm() const
225 { return _totalDistance; }
228 * given a waypoint index, and an offset in NM, find the geodetic
229 * position on the route path. I.e the point 10nm before or after
230 * a particular waypoint.
232 SGGeod pointAlongRoute(int aIndex, double aOffsetNm) const;
235 * Create a WayPoint from a string in the following format:
236 * - simple identifier
237 * - decimal-lon,decimal-lat
238 * - airport-id/runway-id
239 * - navaid/radial-deg/offset-nm
241 WayptRef waypointFromString(const std::string& target);
244 * abstract interface for creating delegates automatically when a
245 * flight-plan is created or loaded
247 class DelegateFactory
250 virtual Delegate* createFlightPlanDelegate(FlightPlan* fp) = 0;
253 static void registerDelegateFactory(DelegateFactory* df);
254 static void unregisterDelegateFactory(DelegateFactory* df);
256 void addDelegate(Delegate* d);
257 void removeDelegate(Delegate* d);
260 void unlockDelegate();
263 bool _arrivalChanged,
266 _currentWaypointChanged;
268 bool loadXmlFormat(const SGPath& path);
269 bool loadGpxFormat(const SGPath& path);
270 bool loadPlainTextFormat(const SGPath& path);
272 void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
273 void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
274 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
275 WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
277 double magvarDegAt(const SGGeod& pos) const;
281 bool _followLegTrackToFix;
282 char _aircraftCategory;
284 FGAirportRef _departure, _destination;
285 FGRunway* _departureRunway, *_destinationRunway;
286 SGSharedPtr<SID> _sid;
287 SGSharedPtr<STAR> _star;
288 SGSharedPtr<Approach> _approach;
289 std::string _sidTransition, _starTransition;
291 double _totalDistance;
292 void rebuildLegData();
294 typedef std::vector<Leg*> LegVec;
300 } // of namespace flightgear
302 #endif // of FG_FLIGHTPLAN_HXX