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 class FlightPlan : public RouteBase
42 virtual ~FlightPlan();
44 virtual std::string ident() const;
45 void setIdent(const std::string& s);
47 FlightPlan* clone(const std::string& newIdent = std::string()) const;
50 * flight-plan leg encapsulation
55 FlightPlan* owner() const
58 Waypt* waypoint() const
61 // reutrn the next leg after this one
64 unsigned int index() const;
66 int altitudeFt() const;
70 double speedMach() const;
72 RouteRestriction altitudeRestriction() const;
73 RouteRestriction speedRestriction() const;
75 void setSpeed(RouteRestriction ty, double speed);
76 void setAltitude(RouteRestriction ty, int altFt);
78 double courseDeg() const;
79 double distanceNm() const;
80 double distanceAlongRoute() const;
82 friend class FlightPlan;
84 Leg(FlightPlan* owner, WayptRef wpt);
86 Leg* cloneFor(FlightPlan* owner) const;
89 RouteRestriction _speedRestrict, _altRestrict;
93 /// length of this leg following the flown path
94 mutable double _pathDistance;
95 mutable double _courseDeg;
96 /// total distance of this leg from departure point
97 mutable double _distanceAlongPath;
105 virtual void departureChanged() { }
106 virtual void arrivalChanged() { }
107 virtual void waypointsChanged() { }
108 virtual void cleared() { }
109 virtual void currentWaypointChanged() { }
110 virtual void endOfFlightPlan() { }
115 void removeInner(Delegate* d);
117 void runDepartureChanged();
118 void runArrivalChanged();
119 void runWaypointsChanged();
120 void runCurrentWaypointChanged();
124 friend class FlightPlan;
126 bool _deleteWithPlan;
130 Leg* insertWayptAtIndex(Waypt* aWpt, int aIndex);
131 void insertWayptsAtIndex(const WayptVec& wps, int aIndex);
133 void deleteIndex(int index);
135 int clearWayptsWithFlag(WayptFlag flag);
137 int currentIndex() const
138 { return _currentIndex; }
140 void setCurrentIndex(int index);
144 Leg* currentLeg() const;
145 Leg* nextLeg() const;
146 Leg* previousLeg() const;
149 { return _legs.size(); }
151 Leg* legAtIndex(int index) const;
152 int findLegIndex(const Leg* l) const;
154 int findWayptIndex(const SGGeod& aPos) const;
156 bool load(const SGPath& p);
157 bool save(const SGPath& p);
159 FGAirportRef departureAirport() const
160 { return _departure; }
162 FGAirportRef destinationAirport() const
163 { return _destination; }
165 FGRunway* departureRunway() const
166 { return _departureRunway; }
168 FGRunway* destinationRunway() const
169 { return _destinationRunway; }
171 Approach* approach() const
172 { return _approach; }
174 void setDeparture(FGAirport* apt);
175 void setDeparture(FGRunway* rwy);
180 Transition* sidTransition() const;
182 void setSID(SID* sid, const std::string& transition = std::string());
184 void setSID(Transition* sidWithTrans);
186 void setDestination(FGAirport* apt);
187 void setDestination(FGRunway* rwy);
190 * note setting an approach will implicitly update the destination
191 * airport and runway to match
193 void setApproach(Approach* app);
198 Transition* starTransition() const;
200 void setSTAR(STAR* star, const std::string& transition = std::string());
202 void setSTAR(Transition* starWithTrans);
204 double totalDistanceNm() const
205 { return _totalDistance; }
208 * given a waypoint index, and an offset in NM, find the geodetic
209 * position on the route path. I.e the point 10nm before or after
210 * a particular waypoint.
212 SGGeod pointAlongRoute(int aIndex, double aOffsetNm) const;
215 * Create a WayPoint from a string in the following format:
216 * - simple identifier
217 * - decimal-lon,decimal-lat
218 * - airport-id/runway-id
219 * - navaid/radial-deg/offset-nm
221 WayptRef waypointFromString(const std::string& target);
224 * abstract interface for creating delegates automatically when a
225 * flight-plan is created or loaded
227 class DelegateFactory
230 virtual Delegate* createFlightPlanDelegate(FlightPlan* fp) = 0;
233 static void registerDelegateFactory(DelegateFactory* df);
234 static void unregisterDelegateFactory(DelegateFactory* df);
236 void addDelegate(Delegate* d);
237 void removeDelegate(Delegate* d);
240 void unlockDelegate();
243 bool _arrivalChanged,
246 _currentWaypointChanged;
248 bool loadXmlFormat(const SGPath& path);
249 bool loadGpxFormat(const SGPath& path);
250 bool loadPlainTextFormat(const SGPath& path);
252 void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
253 void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
254 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
255 WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
257 double magvarDegAt(const SGGeod& pos) const;
262 FGAirportRef _departure, _destination;
263 FGRunway* _departureRunway, *_destinationRunway;
264 SGSharedPtr<SID> _sid;
265 SGSharedPtr<STAR> _star;
266 SGSharedPtr<Approach> _approach;
267 std::string _sidTransition, _starTransition;
269 double _totalDistance;
270 void rebuildLegData();
272 typedef std::vector<Leg*> LegVec;
278 } // of namespace flightgear
280 #endif // of FG_FLIGHTPLAN_HXX