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