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/simple.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() { }
108 virtual void currentWaypointChanged() { }
114 void removeInner(Delegate* d);
116 void runDepartureChanged();
117 void runArrivalChanged();
118 void runWaypointsChanged();
119 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);
139 Leg* currentLeg() const;
140 Leg* nextLeg() const;
141 Leg* previousLeg() const;
144 { return _legs.size(); }
146 Leg* legAtIndex(int index) const;
147 int findLegIndex(const Leg* l) const;
149 int findWayptIndex(const SGGeod& aPos) const;
151 bool load(const SGPath& p);
152 bool save(const SGPath& p);
154 FGAirportRef departureAirport() const
155 { return _departure; }
157 FGAirportRef destinationAirport() const
158 { return _destination; }
160 FGRunway* departureRunway() const
161 { return _departureRunway; }
163 FGRunway* destinationRunway() const
164 { return _destinationRunway; }
166 Approach* approach() const
167 { return _approach; }
169 void setDeparture(FGAirport* apt);
170 void setDeparture(FGRunway* rwy);
175 Transition* sidTransition() const;
177 void setSID(SID* sid, const std::string& transition = std::string());
179 void setSID(Transition* sidWithTrans);
181 void setDestination(FGAirport* apt);
182 void setDestination(FGRunway* rwy);
185 * note setting an approach will implicitly update the destination
186 * airport and runway to match
188 void setApproach(Approach* app);
193 Transition* starTransition() const;
195 void setSTAR(STAR* star, const std::string& transition = std::string());
197 void setSTAR(Transition* starWithTrans);
199 double totalDistanceNm() const
200 { return _totalDistance; }
203 * Create a WayPoint from a string in the following format:
204 * - simple identifier
205 * - decimal-lon,decimal-lat
206 * - airport-id/runway-id
207 * - navaid/radial-deg/offset-nm
209 WayptRef waypointFromString(const std::string& target);
212 * abstract interface for creating delegates automatically when a
213 * flight-plan is created or loaded
215 class DelegateFactory
218 virtual Delegate* createFlightPlanDelegate(FlightPlan* fp) = 0;
221 static void registerDelegateFactory(DelegateFactory* df);
222 static void unregisterDelegateFactory(DelegateFactory* df);
224 void addDelegate(Delegate* d);
225 void removeDelegate(Delegate* d);
228 void unlockDelegate();
231 bool _arrivalChanged,
234 _currentWaypointChanged;
236 bool loadPlainTextRoute(const SGPath& path);
238 void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
239 void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
240 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
241 WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
243 double magvarDegAt(const SGGeod& pos) const;
248 FGAirportRef _departure, _destination;
249 FGRunway* _departureRunway, *_destinationRunway;
253 std::string _sidTransition, _starTransition;
255 double _totalDistance;
256 void rebuildLegData();
258 typedef std::vector<Leg*> LegVec;
264 } // of namespace flightgear
266 #endif // of FG_FLIGHTPLAN_HXX