]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/procedure.hxx
Bug #927 - flightplan XML loading.
[flightgear.git] / src / Navaids / procedure.hxx
1 /// procedure.hxx - define route storing an approach, arrival or departure procedure
2 // Written by James Turner, started 2009.
3 //
4 // Copyright (C) 2009  Curtis L. Olson
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20 #ifndef FG_NAVAID_PROCEDURE_HXX
21 #define FG_NAVAID_PROCEDURE_HXX
22
23 #include <set>
24
25 #include <simgear/math/sg_types.hxx> // for string_list
26
27 #include <Navaids/route.hxx>
28 #include <Airports/runways.hxx>
29
30 typedef SGSharedPtr<FGRunway> FGRunwayRef;
31
32 namespace flightgear {
33
34 // forward decls
35 class NavdataVisitor;
36
37 typedef std::vector<FGRunwayRef> RunwayVec;
38   
39 typedef enum {
40   PROCEDURE_INVALID,
41   PROCEDURE_APPROACH_ILS,
42   PROCEDURE_APPROACH_VOR,
43   PROCEDURE_APPROACH_NDB,
44   PROCEDURE_APPROACH_RNAV,
45   PROCEDURE_SID,
46   PROCEDURE_STAR,
47   PROCEDURE_TRANSITION,
48   PROCEDURE_RUNWAY_TRANSITION
49 } ProcedureType;
50   
51 class Procedure : public RouteBase
52 {
53 public:  
54   virtual ProcedureType type() const = 0;
55   
56   virtual std::string ident() const
57   { return _ident; }
58   
59   virtual FGAirport* airport() const = 0;
60   
61   virtual RunwayVec runways() const
62   { return RunwayVec(); }
63 protected:
64   Procedure(const std::string& aIdent);
65   
66   std::string _ident;
67 };
68
69 /**
70  * Encapsulate a transition segment
71  */
72 class Transition : public Procedure
73 {
74 public:
75   virtual ~Transition() { ; }
76     
77   bool route(WayptVec& aPath);
78   
79   Procedure* parent() const
80   { return _parent; }
81   
82   virtual FGAirport* airport() const;
83   
84   /**
85    * Return the enroute end of the transition
86    */
87   WayptRef enroute() const;
88   
89   /**
90    * Return the procedure end of the transition
91    */
92   WayptRef procedureEnd() const;
93   
94   
95   virtual ProcedureType type() const
96   { return _type; }
97   
98   void mark(WayptFlag f);
99 private:
100   friend class NavdataVisitor;
101
102   Transition(const std::string& aIdent, ProcedureType ty, Procedure* aPr);
103
104   void setPrimary(const WayptVec& aWps);
105   
106   ProcedureType _type;
107   Procedure* _parent;
108   WayptVec _primary;
109 };
110
111 typedef SGSharedPtr<Transition> TransitionRef;
112     
113 /**
114  * Describe an approach procedure, including the missed approach
115  * segment
116  */
117 class Approach : public Procedure
118 {
119 public:
120   virtual ~Approach() { ; }
121     
122   FGRunwayRef runway() 
123   { return _runway; }
124
125   static bool isApproach(ProcedureType ty);
126   
127   virtual FGAirport* airport() const;
128   
129   virtual RunwayVec runways() const;
130   
131   /**
132    * Build a route from a valid IAF to the runway, including the missed
133    * segment. Return false if no valid transition from the specified IAF
134    * could be found
135    */
136   bool route(WayptRef aIAF, WayptVec& aWps);
137
138   /**
139    * Build route as above, but ignore transitions, and assume radar
140    * vectoring to the start of main approach
141    */
142   bool routeFromVectors(WayptVec& aWps);
143   
144   const WayptVec& primary() const
145     { return _primary; }
146     
147   const WayptVec& missed() const
148     { return _missed; }
149
150   virtual ProcedureType type() const
151   { return _type; }
152     
153   static Approach* createTempApproach(const std::string& aIdent, FGRunway* aRunway, const WayptVec& aPath);
154 private:
155   friend class NavdataVisitor;
156   
157   Approach(const std::string& aIdent, ProcedureType ty);
158   
159   void setRunway(FGRunwayRef aRwy);
160   void setPrimaryAndMissed(const WayptVec& aPrimary, const WayptVec& aMissed);
161   void addTransition(Transition* aTrans);
162   
163   FGRunwayRef _runway;
164   ProcedureType _type;
165   
166   typedef std::map<WayptRef, TransitionRef> WptTransitionMap;
167   WptTransitionMap _transitions;
168   
169   WayptVec _primary; // unify these?
170   WayptVec _missed;
171 };
172
173 class ArrivalDeparture : public Procedure
174 {
175 public:
176   virtual FGAirport* airport() const
177   { return _airport; }
178   
179   /**
180    * Predicate, test if this procedure applies to the requested runway
181    */
182   virtual bool isForRunway(const FGRunway* aWay) const;
183
184   virtual RunwayVec runways() const;
185
186   /**
187    * Find a path between the runway and enroute structure. Waypoints 
188    * corresponding to the appropriate transitions and segments will be created.
189    */
190   virtual bool route(FGRunwayRef aWay, Transition* trans, WayptVec& aPath) = 0;
191
192   const WayptVec& common() const
193     { return _common; }
194
195   string_list transitionIdents() const;
196   
197   /**
198    * Given an enroute location, find the best enroute transition point for 
199    * this arrival/departure. Best is currently determined as 'closest to the
200    * enroute location'.
201    */
202   WayptRef findBestTransition(const SGGeod& aPos) const;
203   
204   /**
205    * Find an enroute transition waypoint by identifier. This is necessary
206    * for the route-manager and similar code that that needs to talk about
207    * transitions in a human-meaningful way (including persistence).
208    */
209   Transition* findTransitionByName(const std::string& aIdent) const;
210   
211   Transition* findTransitionByEnroute(Waypt* aEnroute) const;
212 protected:
213     
214   bool commonRoute(Transition* t, WayptVec& aPath, FGRunwayRef aRwy);
215   
216   ArrivalDeparture(const std::string& aIdent, FGAirport* apt);
217   
218   void addRunway(FGRunwayRef aRwy);
219
220   typedef std::map<FGRunwayRef, TransitionRef> RunwayTransitionMap;
221   RunwayTransitionMap _runways;
222   
223   virtual WayptFlag flagType() const = 0;
224     
225     void setCommon(const WayptVec& aWps);
226
227 private:
228   friend class NavdataVisitor;
229   
230   void addTransition(Transition* aTrans);
231   
232   void addRunwayTransition(FGRunwayRef aRwy, Transition* aTrans);
233   
234   FGAirport* _airport;
235   WayptVec _common;
236   
237   typedef std::map<WayptRef, TransitionRef> WptTransitionMap;
238   WptTransitionMap _enrouteTransitions;
239   
240   
241 };
242
243 class SID : public ArrivalDeparture
244 {
245 public:
246     virtual ~SID() { ; }
247         
248   virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
249   
250   virtual ProcedureType type() const
251   { return PROCEDURE_SID; }
252   
253   static SID* createTempSID(const std::string& aIdent, FGRunway* aRunway, const WayptVec& aPath);
254 protected:
255   virtual WayptFlag flagType() const
256   { return WPT_DEPARTURE; }
257   
258 private:
259   friend class NavdataVisitor;
260     
261   SID(const std::string& aIdent, FGAirport* apt);
262 };
263
264 class STAR : public ArrivalDeparture
265 {
266 public:
267   virtual ~STAR() { ; }
268     
269   virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
270   
271   virtual ProcedureType type() const
272   { return PROCEDURE_STAR; }
273   
274 protected:
275   virtual WayptFlag flagType() const
276   { return WPT_ARRIVAL; }
277   
278 private:
279   friend class NavdataVisitor;
280   
281   STAR(const std::string& aIdent, FGAirport* apt);
282 };
283
284 } // of namespace
285
286 #endif