]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/FlightPlan.hxx
Handle libCurl linkage when enabled in SimGear
[flightgear.git] / src / Navaids / FlightPlan.hxx
1 /**
2  * FlightPlan.hxx - defines a full flight-plan object, including
3  * departure, cruise, arrival information and waypoints
4  */
5  
6 // Written by James Turner, started 2012.
7 //
8 // Copyright (C) 2012 James Turner
9 //
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.
14 //
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.
19 //
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.
23
24 #ifndef FG_FLIGHTPLAN_HXX
25 #define FG_FLIGHTPLAN_HXX
26
27 #include <Navaids/route.hxx>
28 #include <Airports/airport.hxx>
29
30 namespace flightgear
31 {
32
33 class Transition;
34 class FlightPlan;
35     
36 typedef SGSharedPtr<FlightPlan> FlightPlanRef;
37
38 const char ICAO_AIRCRAFT_CATEGORY_A = 'A';
39 const char ICAO_AIRCRAFT_CATEGORY_B = 'B';
40 const char ICAO_AIRCRAFT_CATEGORY_C = 'C';
41 const char ICAO_AIRCRAFT_CATEGORY_D = 'D';
42 const char ICAO_AIRCRAFT_CATEGORY_E = 'E';
43
44 class FlightPlan : public RouteBase
45 {
46 public:
47   FlightPlan();
48   virtual ~FlightPlan();
49   
50   virtual std::string ident() const;
51   void setIdent(const std::string& s);
52
53     // propogate the GPS/FMS setting for this through to the RoutePath
54     void setFollowLegTrackToFixes(bool tf);
55     bool followLegTrackToFixes() const;
56
57     // aircraft approach category as per CFR 97.3, etc
58     // http://www.flightsimaviation.com/data/FARS/part_97-3.html
59     std::string icaoAircraftCategory() const;
60     void setIcaoAircraftCategory(const std::string& cat);
61
62   FlightPlan* clone(const std::string& newIdent = std::string()) const;
63   
64   /**
65    * flight-plan leg encapsulation
66    */
67   class Leg
68   {
69   public:
70     FlightPlan* owner() const
71     { return _parent; }
72     
73     Waypt* waypoint() const
74     { return _waypt; }
75     
76     // reutrn the next leg after this one
77     Leg* nextLeg() const;
78     
79     unsigned int index() const;
80     
81     int altitudeFt() const;             
82     int speed() const;
83     
84     int speedKts() const;
85     double speedMach() const;
86     
87     RouteRestriction altitudeRestriction() const;    
88     RouteRestriction speedRestriction() const;
89     
90     void setSpeed(RouteRestriction ty, double speed);
91     void setAltitude(RouteRestriction ty, int altFt);
92     
93     double courseDeg() const;
94     double distanceNm() const;
95     double distanceAlongRoute() const;
96   private:
97     friend class FlightPlan;
98     
99     Leg(FlightPlan* owner, WayptRef wpt);
100     
101     Leg* cloneFor(FlightPlan* owner) const;
102     
103     FlightPlan* _parent;
104     RouteRestriction _speedRestrict, _altRestrict;
105     int _speed;
106     int _altitudeFt;
107     WayptRef _waypt;
108     /// length of this leg following the flown path
109     mutable double _pathDistance;
110     mutable double _courseDeg;
111     /// total distance of this leg from departure point
112     mutable double _distanceAlongPath; 
113   };
114   
115   class Delegate
116   {
117   public:
118     virtual ~Delegate();
119         
120     virtual void departureChanged() { }
121     virtual void arrivalChanged() { }
122     virtual void waypointsChanged() { }
123     virtual void cleared() { }
124     virtual void activated() { }
125     virtual void currentWaypointChanged() { }
126     virtual void endOfFlightPlan() { }
127   protected:
128     Delegate();
129     
130   private:
131     void removeInner(Delegate* d);
132     
133     void runDepartureChanged();
134     void runArrivalChanged();
135     void runWaypointsChanged();
136     void runCurrentWaypointChanged();
137     void runCleared();
138     void runFinished();
139     void runActivated();
140
141     friend class FlightPlan;
142     
143     bool _deleteWithPlan;
144     Delegate* _inner;
145   };
146   
147   Leg* insertWayptAtIndex(Waypt* aWpt, int aIndex);
148   void insertWayptsAtIndex(const WayptVec& wps, int aIndex);
149   
150   void deleteIndex(int index);
151   void clear();
152   int clearWayptsWithFlag(WayptFlag flag);
153   
154   int currentIndex() const
155   { return _currentIndex; }
156   
157   void setCurrentIndex(int index);
158
159   void activate();
160
161   void finish();
162     
163   Leg* currentLeg() const;
164   Leg* nextLeg() const;
165   Leg* previousLeg() const;
166   
167   int numLegs() const
168   { return _legs.size(); }
169   
170   Leg* legAtIndex(int index) const;
171   int findLegIndex(const Leg* l) const;
172   
173   int findWayptIndex(const SGGeod& aPos) const;
174   int findWayptIndex(const FGPositionedRef aPos) const;
175   
176   bool load(const SGPath& p);
177   bool save(const SGPath& p);
178   
179   FGAirportRef departureAirport() const
180   { return _departure; }
181   
182   FGAirportRef destinationAirport() const
183   { return _destination; }
184   
185   FGRunway* departureRunway() const
186   { return _departureRunway; }
187   
188   FGRunway* destinationRunway() const
189   { return _destinationRunway; }
190   
191   Approach* approach() const
192   { return _approach; }
193   
194   void setDeparture(FGAirport* apt);
195   void setDeparture(FGRunway* rwy);
196   
197   SID* sid() const
198   { return _sid; }
199   
200   Transition* sidTransition() const;
201   
202   void setSID(SID* sid, const std::string& transition = std::string());
203   
204   void setSID(Transition* sidWithTrans);
205   
206   void setDestination(FGAirport* apt);
207   void setDestination(FGRunway* rwy);
208   
209   /**
210     * note setting an approach will implicitly update the destination
211     * airport and runway to match
212     */
213   void setApproach(Approach* app);
214   
215   STAR* star() const
216   { return _star; }
217   
218   Transition* starTransition() const;
219   
220   void setSTAR(STAR* star, const std::string& transition = std::string());
221   
222   void setSTAR(Transition* starWithTrans);
223   
224   double totalDistanceNm() const
225   { return _totalDistance; }
226   
227   /**
228    * given a waypoint index, and an offset in NM, find the geodetic
229    * position on the route path. I.e the point 10nm before or after
230    * a particular waypoint.
231    */
232   SGGeod pointAlongRoute(int aIndex, double aOffsetNm) const;
233     
234   /**
235    * Create a WayPoint from a string in the following format:
236    *  - simple identifier
237    *  - decimal-lon,decimal-lat
238    *  - airport-id/runway-id
239    *  - navaid/radial-deg/offset-nm
240    */
241   WayptRef waypointFromString(const std::string& target);
242   
243   /**
244    * abstract interface for creating delegates automatically when a
245    * flight-plan is created or loaded
246    */
247   class DelegateFactory
248   {
249   public:
250     virtual Delegate* createFlightPlanDelegate(FlightPlan* fp) = 0;
251   };
252   
253   static void registerDelegateFactory(DelegateFactory* df);
254   static void unregisterDelegateFactory(DelegateFactory* df);
255   
256   void addDelegate(Delegate* d);
257   void removeDelegate(Delegate* d);
258 private:
259   void lockDelegate();
260   void unlockDelegate();
261   
262   int _delegateLock;
263   bool _arrivalChanged, 
264     _departureChanged, 
265     _waypointsChanged, 
266     _currentWaypointChanged;
267   
268   bool loadXmlFormat(const SGPath& path);
269   bool loadGpxFormat(const SGPath& path);
270   bool loadPlainTextFormat(const SGPath& path);
271   
272   void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
273   void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
274   void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
275   WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
276   
277   double magvarDegAt(const SGGeod& pos) const;
278   
279   std::string _ident;
280   int _currentIndex;
281     bool _followLegTrackToFix;
282     char _aircraftCategory;
283
284   FGAirportRef _departure, _destination;
285   FGRunway* _departureRunway, *_destinationRunway;
286   SGSharedPtr<SID> _sid;
287   SGSharedPtr<STAR> _star;
288   SGSharedPtr<Approach> _approach;
289   std::string _sidTransition, _starTransition;
290   
291   double _totalDistance;
292   void rebuildLegData();
293   
294   typedef std::vector<Leg*> LegVec;
295   LegVec _legs;
296   
297   Delegate* _delegate;
298 };
299   
300 } // of namespace flightgear
301
302 #endif // of FG_FLIGHTPLAN_HXX