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