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>
30 typedef SGSharedPtr<FGAirport> FGAirportRef;
37 class FlightPlan : public RouteBase
41 virtual ~FlightPlan();
43 virtual std::string ident() const;
44 void setIdent(const std::string& s);
46 FlightPlan* clone(const std::string& newIdent = std::string()) const;
49 * flight-plan leg encapsulation
54 FlightPlan* owner() const
57 Waypt* waypoint() const
60 // reutrn the next leg after this one
63 unsigned int index() const;
65 int altitudeFt() const;
69 double speedMach() const;
71 RouteRestriction altitudeRestriction() const;
72 RouteRestriction speedRestriction() const;
74 void setSpeed(RouteRestriction ty, double speed);
75 void setAltitude(RouteRestriction ty, int altFt);
77 double courseDeg() const;
78 double distanceNm() const;
79 double distanceAlongRoute() const;
81 friend class FlightPlan;
83 Leg(FlightPlan* owner, WayptRef wpt);
85 Leg* cloneFor(FlightPlan* owner) const;
88 RouteRestriction _speedRestrict, _altRestrict;
92 /// length of this leg following the flown path
93 mutable double _pathDistance;
94 mutable double _courseDeg;
95 /// total distance of this leg from departure point
96 mutable double _distanceAlongPath;
104 virtual void departureChanged() { }
105 virtual void arrivalChanged() { }
106 virtual void waypointsChanged() { }
107 virtual void cleared() { }
108 virtual void currentWaypointChanged() { }
114 void removeInner(Delegate* d);
116 void runDepartureChanged();
117 void runArrivalChanged();
118 void runWaypointsChanged();
119 void runCurrentWaypointChanged();
122 friend class FlightPlan;
124 bool _deleteWithPlan;
128 Leg* insertWayptAtIndex(Waypt* aWpt, int aIndex);
129 void insertWayptsAtIndex(const WayptVec& wps, int aIndex);
131 void deleteIndex(int index);
133 int clearWayptsWithFlag(WayptFlag flag);
135 int currentIndex() const
136 { return _currentIndex; }
138 void setCurrentIndex(int index);
140 Leg* currentLeg() const;
141 Leg* nextLeg() const;
142 Leg* previousLeg() const;
145 { return _legs.size(); }
147 Leg* legAtIndex(int index) const;
148 int findLegIndex(const Leg* l) const;
150 int findWayptIndex(const SGGeod& aPos) const;
152 bool load(const SGPath& p);
153 bool save(const SGPath& p);
155 FGAirportRef departureAirport() const
156 { return _departure; }
158 FGAirportRef destinationAirport() const
159 { return _destination; }
161 FGRunway* departureRunway() const
162 { return _departureRunway; }
164 FGRunway* destinationRunway() const
165 { return _destinationRunway; }
167 Approach* approach() const
168 { return _approach; }
170 void setDeparture(FGAirport* apt);
171 void setDeparture(FGRunway* rwy);
176 Transition* sidTransition() const;
178 void setSID(SID* sid, const std::string& transition = std::string());
180 void setSID(Transition* sidWithTrans);
182 void setDestination(FGAirport* apt);
183 void setDestination(FGRunway* rwy);
186 * note setting an approach will implicitly update the destination
187 * airport and runway to match
189 void setApproach(Approach* app);
194 Transition* starTransition() const;
196 void setSTAR(STAR* star, const std::string& transition = std::string());
198 void setSTAR(Transition* starWithTrans);
200 double totalDistanceNm() const
201 { return _totalDistance; }
204 * given a waypoint index, and an offset in NM, find the geodetic
205 * position on the route path. I.e the point 10nm before or after
206 * a particular waypoint.
208 SGGeod pointAlongRoute(int aIndex, double aOffsetNm) const;
211 * Create a WayPoint from a string in the following format:
212 * - simple identifier
213 * - decimal-lon,decimal-lat
214 * - airport-id/runway-id
215 * - navaid/radial-deg/offset-nm
217 WayptRef waypointFromString(const std::string& target);
220 * abstract interface for creating delegates automatically when a
221 * flight-plan is created or loaded
223 class DelegateFactory
226 virtual Delegate* createFlightPlanDelegate(FlightPlan* fp) = 0;
229 static void registerDelegateFactory(DelegateFactory* df);
230 static void unregisterDelegateFactory(DelegateFactory* df);
232 void addDelegate(Delegate* d);
233 void removeDelegate(Delegate* d);
236 void unlockDelegate();
239 bool _arrivalChanged,
242 _currentWaypointChanged;
244 bool loadPlainTextRoute(const SGPath& path);
246 void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
247 void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
248 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
249 WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
251 double magvarDegAt(const SGGeod& pos) const;
256 FGAirportRef _departure, _destination;
257 FGRunway* _departureRunway, *_destinationRunway;
258 SGSharedPtr<SID> _sid;
259 SGSharedPtr<STAR> _star;
260 SGSharedPtr<Approach> _approach;
261 std::string _sidTransition, _starTransition;
263 double _totalDistance;
264 void rebuildLegData();
266 typedef std::vector<Leg*> LegVec;
272 } // of namespace flightgear
274 #endif // of FG_FLIGHTPLAN_HXX