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;
155 int findWayptIndex(const FGPositionedRef aPos) const;
157 bool load(const SGPath& p);
158 bool save(const SGPath& p);
160 FGAirportRef departureAirport() const
161 { return _departure; }
163 FGAirportRef destinationAirport() const
164 { return _destination; }
166 FGRunway* departureRunway() const
167 { return _departureRunway; }
169 FGRunway* destinationRunway() const
170 { return _destinationRunway; }
172 Approach* approach() const
173 { return _approach; }
175 void setDeparture(FGAirport* apt);
176 void setDeparture(FGRunway* rwy);
181 Transition* sidTransition() const;
183 void setSID(SID* sid, const std::string& transition = std::string());
185 void setSID(Transition* sidWithTrans);
187 void setDestination(FGAirport* apt);
188 void setDestination(FGRunway* rwy);
191 * note setting an approach will implicitly update the destination
192 * airport and runway to match
194 void setApproach(Approach* app);
199 Transition* starTransition() const;
201 void setSTAR(STAR* star, const std::string& transition = std::string());
203 void setSTAR(Transition* starWithTrans);
205 double totalDistanceNm() const
206 { return _totalDistance; }
209 * given a waypoint index, and an offset in NM, find the geodetic
210 * position on the route path. I.e the point 10nm before or after
211 * a particular waypoint.
213 SGGeod pointAlongRoute(int aIndex, double aOffsetNm) const;
216 * Create a WayPoint from a string in the following format:
217 * - simple identifier
218 * - decimal-lon,decimal-lat
219 * - airport-id/runway-id
220 * - navaid/radial-deg/offset-nm
222 WayptRef waypointFromString(const std::string& target);
225 * abstract interface for creating delegates automatically when a
226 * flight-plan is created or loaded
228 class DelegateFactory
231 virtual Delegate* createFlightPlanDelegate(FlightPlan* fp) = 0;
234 static void registerDelegateFactory(DelegateFactory* df);
235 static void unregisterDelegateFactory(DelegateFactory* df);
237 void addDelegate(Delegate* d);
238 void removeDelegate(Delegate* d);
241 void unlockDelegate();
244 bool _arrivalChanged,
247 _currentWaypointChanged;
249 bool loadXmlFormat(const SGPath& path);
250 bool loadGpxFormat(const SGPath& path);
251 bool loadPlainTextFormat(const SGPath& path);
253 void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
254 void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
255 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
256 WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
258 double magvarDegAt(const SGGeod& pos) const;
263 FGAirportRef _departure, _destination;
264 FGRunway* _departureRunway, *_destinationRunway;
265 SGSharedPtr<SID> _sid;
266 SGSharedPtr<STAR> _star;
267 SGSharedPtr<Approach> _approach;
268 std::string _sidTransition, _starTransition;
270 double _totalDistance;
271 void rebuildLegData();
273 typedef std::vector<Leg*> LegVec;
279 } // of namespace flightgear
281 #endif // of FG_FLIGHTPLAN_HXX