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() { }
112 void removeInner(Delegate* d);
114 void runDepartureChanged();
115 void runArrivalChanged();
116 void runWaypointsChanged();
117 void runCurrentWaypointChanged();
120 friend class FlightPlan;
122 bool _deleteWithPlan;
126 Leg* insertWayptAtIndex(Waypt* aWpt, int aIndex);
127 void insertWayptsAtIndex(const WayptVec& wps, int aIndex);
129 void deleteIndex(int index);
131 int clearWayptsWithFlag(WayptFlag flag);
133 int currentIndex() const
134 { return _currentIndex; }
136 void setCurrentIndex(int index);
138 Leg* currentLeg() const;
139 Leg* nextLeg() const;
140 Leg* previousLeg() const;
143 { return _legs.size(); }
145 Leg* legAtIndex(int index) const;
146 int findLegIndex(const Leg* l) const;
148 int findWayptIndex(const SGGeod& aPos) const;
150 bool load(const SGPath& p);
151 bool save(const SGPath& p);
153 FGAirportRef departureAirport() const
154 { return _departure; }
156 FGAirportRef destinationAirport() const
157 { return _destination; }
159 FGRunway* departureRunway() const
160 { return _departureRunway; }
162 FGRunway* destinationRunway() const
163 { return _destinationRunway; }
165 Approach* approach() const
166 { return _approach; }
168 void setDeparture(FGAirport* apt);
169 void setDeparture(FGRunway* rwy);
174 Transition* sidTransition() const;
176 void setSID(SID* sid, const std::string& transition = std::string());
178 void setSID(Transition* sidWithTrans);
180 void setDestination(FGAirport* apt);
181 void setDestination(FGRunway* rwy);
184 * note setting an approach will implicitly update the destination
185 * airport and runway to match
187 void setApproach(Approach* app);
192 Transition* starTransition() const;
194 void setSTAR(STAR* star, const std::string& transition = std::string());
196 void setSTAR(Transition* starWithTrans);
198 double totalDistanceNm() const
199 { return _totalDistance; }
202 * given a waypoint index, and an offset in NM, find the geodetic
203 * position on the route path. I.e the point 10nm before or after
204 * a particular waypoint.
206 SGGeod pointAlongRoute(int aIndex, double aOffsetNm) const;
209 * Create a WayPoint from a string in the following format:
210 * - simple identifier
211 * - decimal-lon,decimal-lat
212 * - airport-id/runway-id
213 * - navaid/radial-deg/offset-nm
215 WayptRef waypointFromString(const std::string& target);
218 * abstract interface for creating delegates automatically when a
219 * flight-plan is created or loaded
221 class DelegateFactory
224 virtual Delegate* createFlightPlanDelegate(FlightPlan* fp) = 0;
227 static void registerDelegateFactory(DelegateFactory* df);
228 static void unregisterDelegateFactory(DelegateFactory* df);
230 void addDelegate(Delegate* d);
231 void removeDelegate(Delegate* d);
234 void unlockDelegate();
237 bool _arrivalChanged,
240 _currentWaypointChanged;
242 bool loadPlainTextRoute(const SGPath& path);
244 void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
245 void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
246 void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
247 WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
249 double magvarDegAt(const SGGeod& pos) const;
254 FGAirportRef _departure, _destination;
255 FGRunway* _departureRunway, *_destinationRunway;
256 SGSharedPtr<SID> _sid;
257 SGSharedPtr<STAR> _star;
258 SGSharedPtr<Approach> _approach;
259 std::string _sidTransition, _starTransition;
261 double _totalDistance;
262 void rebuildLegData();
264 typedef std::vector<Leg*> LegVec;
270 } // of namespace flightgear
272 #endif // of FG_FLIGHTPLAN_HXX