]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/FlightPlan.hxx
Break FlightPlan out into its own file.
[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/simple.hxx>
29
30 typedef SGSharedPtr<FGAirport> FGAirportRef;
31     
32 namespace flightgear
33 {
34
35 class Transition;
36
37 class FlightPlan : public RouteBase
38 {
39 public:
40   FlightPlan();
41   virtual ~FlightPlan();
42   
43   virtual std::string ident() const;
44   void setIdent(const std::string& s);
45   
46   FlightPlan* clone(const std::string& newIdent = std::string()) const;
47   
48   /**
49    * flight-plan leg encapsulation
50    */
51   class Leg
52   {
53   public:
54     FlightPlan* owner() const
55     { return _parent; }
56     
57     Waypt* waypoint() const
58     { return _waypt; }
59     
60     // reutrn the next leg after this one
61     Leg* nextLeg() const;
62     
63     unsigned int index() const;
64     
65     int altitudeFt() const;             
66     int speed() const;
67     
68     int speedKts() const;
69     double speedMach() const;
70     
71     RouteRestriction altitudeRestriction() const;    
72     RouteRestriction speedRestriction() const;
73     
74     void setSpeed(RouteRestriction ty, double speed);
75     void setAltitude(RouteRestriction ty, int altFt);
76     
77     double courseDeg() const;
78     double distanceNm() const;
79     double distanceAlongRoute() const;
80   private:
81     friend class FlightPlan;
82     
83     Leg(FlightPlan* owner, WayptRef wpt);
84     
85     Leg* cloneFor(FlightPlan* owner) const;
86     
87     FlightPlan* _parent;
88     RouteRestriction _speedRestrict, _altRestrict;
89     int _speed;
90     int _altitudeFt;
91     WayptRef _waypt;
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; 
97   };
98   
99   class Delegate
100   {
101   public:
102     virtual ~Delegate();
103     
104     virtual void departureChanged() { }
105     virtual void arrivalChanged() { }
106     virtual void waypointsChanged() { }
107     
108     virtual void currentWaypointChanged() { }
109   
110   protected:
111     Delegate();
112     
113   private:
114     void removeInner(Delegate* d);
115     
116     void runDepartureChanged();
117     void runArrivalChanged();
118     void runWaypointsChanged();
119     void runCurrentWaypointChanged();
120     
121     friend class FlightPlan;
122     
123     Delegate* _inner;
124   };
125   
126   Leg* insertWayptAtIndex(Waypt* aWpt, int aIndex);
127   void insertWayptsAtIndex(const WayptVec& wps, int aIndex);
128   
129   void deleteIndex(int index);
130   void clear();
131   int clearWayptsWithFlag(WayptFlag flag);
132   
133   int currentIndex() const
134   { return _currentIndex; }
135   
136   void setCurrentIndex(int index);
137   
138   Leg* currentLeg() const;
139   Leg* nextLeg() const;
140   Leg* previousLeg() const;
141   
142   int numLegs() const
143   { return _legs.size(); }
144   
145   Leg* legAtIndex(int index) const;
146   int findLegIndex(const Leg* l) const;
147   
148   int findWayptIndex(const SGGeod& aPos) const;
149   
150   bool load(const SGPath& p);
151   bool save(const SGPath& p);
152   
153   FGAirportRef departureAirport() const
154   { return _departure; }
155   
156   FGAirportRef destinationAirport() const
157   { return _destination; }
158   
159   FGRunway* departureRunway() const
160   { return _departureRunway; }
161   
162   FGRunway* destinationRunway() const
163   { return _destinationRunway; }
164   
165   Approach* approach() const
166   { return _approach; }
167   
168   void setDeparture(FGAirport* apt);
169   void setDeparture(FGRunway* rwy);
170   
171   SID* sid() const
172   { return _sid; }
173   
174   Transition* sidTransition() const;
175   
176   void setSID(SID* sid, const std::string& transition = std::string());
177   
178   void setSID(Transition* sidWithTrans);
179   
180   void setDestination(FGAirport* apt);
181   void setDestination(FGRunway* rwy);
182   
183   /**
184     * note setting an approach will implicitly update the destination
185     * airport and runway to match
186     */
187   void setApproach(Approach* app);
188   
189   STAR* star() const
190   { return _star; }
191   
192   Transition* starTransition() const;
193   
194   void setSTAR(STAR* star, const std::string& transition = std::string());
195   
196   void setSTAR(Transition* starWithTrans);
197   
198   double totalDistanceNm() const
199   { return _totalDistance; }
200   
201   /**
202    * Create a WayPoint from a string in the following format:
203    *  - simple identifier
204    *  - decimal-lon,decimal-lat
205    *  - airport-id/runway-id
206    *  - navaid/radial-deg/offset-nm
207    */
208   WayptRef waypointFromString(const std::string& target);
209   
210   void setDelegate(Delegate* d);
211   void removeDelegate(Delegate* d);
212 private:
213   
214   bool loadPlainTextRoute(const SGPath& path);
215   
216   void loadVersion1XMLRoute(SGPropertyNode_ptr routeData);
217   void loadVersion2XMLRoute(SGPropertyNode_ptr routeData);
218   void loadXMLRouteHeader(SGPropertyNode_ptr routeData);
219   WayptRef parseVersion1XMLWaypt(SGPropertyNode* aWP);
220   
221   double magvarDegAt(const SGGeod& pos) const;
222   
223   std::string _ident;
224   int _currentIndex;
225   
226   FGAirportRef _departure, _destination;
227   FGRunway* _departureRunway, *_destinationRunway;
228   SID* _sid;
229   STAR* _star;
230   Approach* _approach;
231   std::string _sidTransition, _starTransition;
232   
233   double _totalDistance;
234   void rebuildLegData();
235   
236   typedef std::vector<Leg*> LegVec;
237   LegVec _legs;
238   
239   Delegate* _delegate;
240 };
241   
242 } // of namespace flightgear
243
244 #endif // of FG_FLIGHTPLAN_HXX