]> git.mxchange.org Git - flightgear.git/blob - src/Navaids/procedure.hxx
Implement a persistent cache for navigation data.
[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   bool route(WayptVec& aPath);
76   
77   Procedure* parent() const
78   { return _parent; }
79   
80   virtual FGAirport* airport() const;
81   
82   /**
83    * Return the enroute end of the transition
84    */
85   WayptRef enroute() const;
86   
87   /**
88    * Return the procedure end of the transition
89    */
90   WayptRef procedureEnd() const;
91   
92   
93   virtual ProcedureType type() const
94   { return _type; }
95   
96   void mark(WayptFlag f);
97 private:
98   friend class NavdataVisitor;
99
100   Transition(const std::string& aIdent, ProcedureType ty, Procedure* aPr);
101
102   void setPrimary(const WayptVec& aWps);
103   
104   ProcedureType _type;
105   Procedure* _parent;
106   WayptVec _primary;
107 };
108
109 /**
110  * Describe an approach procedure, including the missed approach
111  * segment
112  */
113 class Approach : public Procedure
114 {
115 public:
116   FGRunwayRef runway() 
117   { return _runway; }
118
119   static bool isApproach(ProcedureType ty);
120   
121   virtual FGAirport* airport() const;
122   
123   virtual RunwayVec runways() const;
124   
125   /**
126    * Build a route from a valid IAF to the runway, including the missed
127    * segment. Return false if no valid transition from the specified IAF
128    * could be found
129    */
130   bool route(WayptRef aIAF, WayptVec& aWps);
131
132   /**
133    * Build route as above, but ignore transitions, and assume radar
134    * vectoring to the start of main approach
135    */
136   bool routeFromVectors(WayptVec& aWps);
137   
138   const WayptVec& primary() const
139     { return _primary; }
140     
141   const WayptVec& missed() const
142     { return _missed; }
143
144   virtual ProcedureType type() const
145   { return _type; }
146 private:
147   friend class NavdataVisitor;
148   
149   Approach(const std::string& aIdent, ProcedureType ty);
150   
151   void setRunway(FGRunwayRef aRwy);
152   void setPrimaryAndMissed(const WayptVec& aPrimary, const WayptVec& aMissed);
153   void addTransition(Transition* aTrans);
154   
155   FGRunwayRef _runway;
156   ProcedureType _type;
157   
158   typedef std::map<WayptRef, Transition*> WptTransitionMap;
159   WptTransitionMap _transitions;
160   
161   WayptVec _primary; // unify these?
162   WayptVec _missed;
163 };
164
165 class ArrivalDeparture : public Procedure
166 {
167 public:
168   virtual FGAirport* airport() const
169   { return _airport; }
170   
171   /**
172    * Predicate, test if this procedure applies to the requested runway
173    */
174   virtual bool isForRunway(const FGRunway* aWay) const;
175
176   virtual RunwayVec runways() const;
177
178   /**
179    * Find a path between the runway and enroute structure. Waypoints 
180    * corresponding to the appropriate transitions and segments will be created.
181    */
182   virtual bool route(FGRunwayRef aWay, Transition* trans, WayptVec& aPath) = 0;
183
184   const WayptVec& common() const
185     { return _common; }
186
187   string_list transitionIdents() const;
188   
189   /**
190    * Given an enroute location, find the best enroute transition point for 
191    * this arrival/departure. Best is currently determined as 'closest to the
192    * enroute location'.
193    */
194   WayptRef findBestTransition(const SGGeod& aPos) const;
195   
196   /**
197    * Find an enroute transition waypoint by identifier. This is necessary
198    * for the route-manager and similar code that that needs to talk about
199    * transitions in a human-meaningful way (including persistence).
200    */
201   Transition* findTransitionByName(const std::string& aIdent) const;
202   
203   Transition* findTransitionByEnroute(Waypt* aEnroute) const;
204 protected:
205     
206   bool commonRoute(Transition* t, WayptVec& aPath, FGRunwayRef aRwy);
207   
208   ArrivalDeparture(const std::string& aIdent, FGAirport* apt);
209   
210   
211   void addRunway(FGRunwayRef aRwy);
212
213   typedef std::map<FGRunwayRef, Transition*> RunwayTransitionMap;
214   RunwayTransitionMap _runways;
215   
216   virtual WayptFlag flagType() const = 0;
217 private:
218   friend class NavdataVisitor;
219   
220   void addTransition(Transition* aTrans);
221   
222   void setCommon(const WayptVec& aWps);
223
224   void addRunwayTransition(FGRunwayRef aRwy, Transition* aTrans);
225   
226   FGAirport* _airport;
227   WayptVec _common;
228   
229   typedef std::map<WayptRef, Transition*> WptTransitionMap;
230   WptTransitionMap _enrouteTransitions;
231   
232   
233 };
234
235 class SID : public ArrivalDeparture
236 {
237 public:  
238   virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
239   
240   virtual ProcedureType type() const
241   { return PROCEDURE_SID; }
242   
243 protected:
244   virtual WayptFlag flagType() const
245   { return WPT_DEPARTURE; }
246   
247 private:
248   friend class NavdataVisitor;
249     
250   SID(const std::string& aIdent, FGAirport* apt);
251 };
252
253 class STAR : public ArrivalDeparture
254 {
255 public:  
256   virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
257   
258   virtual ProcedureType type() const
259   { return PROCEDURE_STAR; }
260   
261 protected:
262   virtual WayptFlag flagType() const
263   { return WPT_ARRIVAL; }
264   
265 private:
266   friend class NavdataVisitor;
267   
268   STAR(const std::string& aIdent, FGAirport* apt);
269 };
270
271 } // of namespace
272
273 #endif