1 /// procedure.hxx - define route storing an approach, arrival or departure procedure
2 // Written by James Turner, started 2009.
4 // Copyright (C) 2009 Curtis L. Olson
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.
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.
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.
20 #ifndef FG_NAVAID_PROCEDURE_HXX
21 #define FG_NAVAID_PROCEDURE_HXX
25 #include <simgear/math/sg_types.hxx> // for string_list
27 #include <Navaids/route.hxx>
28 #include <Airports/runways.hxx>
30 typedef SGSharedPtr<FGRunway> FGRunwayRef;
32 namespace flightgear {
37 typedef std::vector<FGRunwayRef> RunwayVec;
41 PROCEDURE_APPROACH_ILS,
42 PROCEDURE_APPROACH_VOR,
43 PROCEDURE_APPROACH_NDB,
44 PROCEDURE_APPROACH_RNAV,
48 PROCEDURE_RUNWAY_TRANSITION
51 class Procedure : public RouteBase
54 virtual ProcedureType type() const = 0;
56 virtual std::string ident() const
59 virtual FGAirport* airport() const = 0;
61 virtual RunwayVec runways() const
62 { return RunwayVec(); }
64 Procedure(const std::string& aIdent);
70 * Encapsulate a transition segment
72 class Transition : public Procedure
75 bool route(WayptVec& aPath);
77 Procedure* parent() const
80 virtual FGAirport* airport() const;
83 * Return the enroute end of the transition
85 WayptRef enroute() const;
88 * Return the procedure end of the transition
90 WayptRef procedureEnd() const;
93 virtual ProcedureType type() const
96 void mark(WayptFlag f);
98 friend class NavdataVisitor;
100 Transition(const std::string& aIdent, ProcedureType ty, Procedure* aPr);
102 void setPrimary(const WayptVec& aWps);
110 * Describe an approach procedure, including the missed approach
113 class Approach : public Procedure
119 static bool isApproach(ProcedureType ty);
121 virtual FGAirport* airport() const;
123 virtual RunwayVec runways() const;
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
130 bool route(WayptRef aIAF, WayptVec& aWps);
133 * Build route as above, but ignore transitions, and assume radar
134 * vectoring to the start of main approach
136 bool routeFromVectors(WayptVec& aWps);
138 const WayptVec& primary() const
141 const WayptVec& missed() const
144 virtual ProcedureType type() const
147 friend class NavdataVisitor;
149 Approach(const std::string& aIdent, ProcedureType ty);
151 void setRunway(FGRunwayRef aRwy);
152 void setPrimaryAndMissed(const WayptVec& aPrimary, const WayptVec& aMissed);
153 void addTransition(Transition* aTrans);
158 typedef std::map<WayptRef, Transition*> WptTransitionMap;
159 WptTransitionMap _transitions;
161 WayptVec _primary; // unify these?
165 class ArrivalDeparture : public Procedure
168 virtual FGAirport* airport() const
172 * Predicate, test if this procedure applies to the requested runway
174 virtual bool isForRunway(const FGRunway* aWay) const;
176 virtual RunwayVec runways() const;
179 * Find a path between the runway and enroute structure. Waypoints
180 * corresponding to the appropriate transitions and segments will be created.
182 virtual bool route(FGRunwayRef aWay, Transition* trans, WayptVec& aPath) = 0;
184 const WayptVec& common() const
187 string_list transitionIdents() const;
190 * Given an enroute location, find the best enroute transition point for
191 * this arrival/departure. Best is currently determined as 'closest to the
194 WayptRef findBestTransition(const SGGeod& aPos) const;
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).
201 Transition* findTransitionByName(const std::string& aIdent) const;
203 Transition* findTransitionByEnroute(Waypt* aEnroute) const;
206 bool commonRoute(Transition* t, WayptVec& aPath, FGRunwayRef aRwy);
208 ArrivalDeparture(const std::string& aIdent, FGAirport* apt);
211 void addRunway(FGRunwayRef aRwy);
213 typedef std::map<FGRunwayRef, Transition*> RunwayTransitionMap;
214 RunwayTransitionMap _runways;
216 virtual WayptFlag flagType() const = 0;
218 friend class NavdataVisitor;
220 void addTransition(Transition* aTrans);
222 void setCommon(const WayptVec& aWps);
224 void addRunwayTransition(FGRunwayRef aRwy, Transition* aTrans);
229 typedef std::map<WayptRef, Transition*> WptTransitionMap;
230 WptTransitionMap _enrouteTransitions;
235 class SID : public ArrivalDeparture
238 virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
240 virtual ProcedureType type() const
241 { return PROCEDURE_SID; }
244 virtual WayptFlag flagType() const
245 { return WPT_DEPARTURE; }
248 friend class NavdataVisitor;
250 SID(const std::string& aIdent, FGAirport* apt);
253 class STAR : public ArrivalDeparture
256 virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
258 virtual ProcedureType type() const
259 { return PROCEDURE_STAR; }
262 virtual WayptFlag flagType() const
263 { return WPT_ARRIVAL; }
266 friend class NavdataVisitor;
268 STAR(const std::string& aIdent, FGAirport* apt);