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>
35 class FlightPlan : public RouteBase
39 virtual ~FlightPlan();
41 virtual std::string ident() const;
42 void setIdent(const std::string& s);
44 FlightPlan* clone(const std::string& newIdent = std::string()) const;
47 * flight-plan leg encapsulation
52 FlightPlan* owner() const
55 Waypt* waypoint() const
58 // reutrn the next leg after this one
61 unsigned int index() const;
63 int altitudeFt() const;
67 double speedMach() const;
69 RouteRestriction altitudeRestriction() const;
70 RouteRestriction speedRestriction() const;
72 void setSpeed(RouteRestriction ty, double speed);
73 void setAltitude(RouteRestriction ty, int altFt);
75 double courseDeg() const;
76 double distanceNm() const;
77 double distanceAlongRoute() const;
79 friend class FlightPlan;
81 Leg(FlightPlan* owner, WayptRef wpt);
83 Leg* cloneFor(FlightPlan* owner) const;
86 RouteRestriction _speedRestrict, _altRestrict;
90 /// length of this leg following the flown path
91 mutable double _pathDistance;
92 mutable double _courseDeg;
93 /// total distance of this leg from departure point
94 mutable double _distanceAlongPath;
102 virtual void departureChanged() { }
103 virtual void arrivalChanged() { }
104 virtual void waypointsChanged() { }
105 virtual void cleared() { }
106 virtual void currentWaypointChanged() { }
107 virtual void endOfFlightPlan() { }
112 void removeInner(Delegate* d);
114 void runDepartureChanged();
115 void runArrivalChanged();
116 void runWaypointsChanged();
117 void runCurrentWaypointChanged();
121 friend class FlightPlan;
123 bool _deleteWithPlan;
127 Leg* insertWayptAtIndex(Waypt* aWpt, int aIndex);
128 void insertWayptsAtIndex(const WayptVec& wps, int aIndex);
130 void deleteIndex(int index);
132 int clearWayptsWithFlag(WayptFlag flag);
134 int currentIndex() const
135 { return _currentIndex; }
137 void setCurrentIndex(int index);
141 Leg* currentLeg() const;
142 Leg* nextLeg() const;
143 Leg* previousLeg() const;
146 { return _legs.size(); }
148 Leg* legAtIndex(int index) const;
149 int findLegIndex(const Leg* l) const;
151 int findWayptIndex(const SGGeod& aPos) const;
153 bool load(const SGPath& p);
154 bool save(const SGPath& p);
156 FGAirportRef departureAirport() const
157 { return _departure; }
159 FGAirportRef destinationAirport() const
160 { return _destination; }
162 FGRunway* departureRunway() const
163 { return _departureRunway; }
165 FGRunway* destinationRunway() const
166 { return _destinationRunway; }
168 Approach* approach() const
169 { return _approach; }
171 void setDeparture(FGAirport* apt);
172 void setDeparture(FGRunway* rwy);
177 Transition* sidTransition() const;
179 void setSID(SID* sid, const std::string& transition = std::string());
181 void setSID(Transition* sidWithTrans);
183 void setDestination(FGAirport* apt);
184 void setDestination(FGRunway* rwy);
187 * note setting an approach will implicitly update the destination
188 * airport and runway to match
190 void setApproach(Approach* app);
195 Transition* starTransition() const;
197 void setSTAR(STAR* star, const std::string& transition = std::string());
199 void setSTAR(Transition* starWithTrans);
201 double totalDistanceNm() const
202 { return _totalDistance; }
205 * given a waypoint index, and an offset in NM, find the geodetic
206 * position on the route path. I.e the point 10nm before or after
207 * a particular waypoint.
209 SGGeod pointAlongRoute(int aIndex, double aOffsetNm) const;
212 * Create a WayPoint from a string in the following format:
213 * - simple identifier
214 * - decimal-lon,decimal-lat
215 * - airport-id/runway-id
216 * - navaid/radial-deg/offset-nm
218 WayptRef waypointFromString(const std::string& target);
221 * abstract interface for creating delegates automatically when a
222 * flight-plan is created or loaded
224 class DelegateFactory
227 virtual Delegate* createFlightPlanDelegate(FlightPlan* fp) = 0;
230 static void registerDelegateFactory(DelegateFactory* df);
231 static void unregisterDelegateFactory(DelegateFactory* df);
233 void addDelegate(Delegate* d);
234 void removeDelegate(Delegate* d);
237 void unlockDelegate();
240 bool _arrivalChanged,
243 _currentWaypointChanged;
245 bool loadPlainTextRoute(const SGPath& path);
247 void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
248 void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
249 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
250 WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
252 double magvarDegAt(const SGGeod& pos) const;
257 FGAirportRef _departure, _destination;
258 FGRunway* _departureRunway, *_destinationRunway;
259 SGSharedPtr<SID> _sid;
260 SGSharedPtr<STAR> _star;
261 SGSharedPtr<Approach> _approach;
262 std::string _sidTransition, _starTransition;
264 double _totalDistance;
265 void rebuildLegData();
267 typedef std::vector<Leg*> LegVec;
273 } // of namespace flightgear
275 #endif // of FG_FLIGHTPLAN_HXX