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
26 #include <Airports/airports_fwd.hxx>
27 #include <Navaids/route.hxx>
29 namespace flightgear {
34 typedef std::vector<FGRunwayRef> RunwayVec;
38 PROCEDURE_APPROACH_ILS,
39 PROCEDURE_APPROACH_VOR,
40 PROCEDURE_APPROACH_NDB,
41 PROCEDURE_APPROACH_RNAV,
45 PROCEDURE_RUNWAY_TRANSITION
48 class Procedure : public RouteBase
51 virtual ProcedureType type() const = 0;
53 virtual std::string ident() const
56 virtual FGAirport* airport() const = 0;
58 virtual RunwayVec runways() const
59 { return RunwayVec(); }
61 Procedure(const std::string& aIdent);
67 * Encapsulate a transition segment
69 class Transition : public Procedure
72 virtual ~Transition() { ; }
74 bool route(WayptVec& aPath);
76 Procedure* parent() const
79 virtual FGAirport* airport() const;
82 * Return the enroute end of the transition
84 WayptRef enroute() const;
87 * Return the procedure end of the transition
89 WayptRef procedureEnd() const;
92 virtual ProcedureType type() const
95 void mark(WayptFlag f);
97 friend class NavdataVisitor;
99 Transition(const std::string& aIdent, ProcedureType ty, Procedure* aPr);
101 void setPrimary(const WayptVec& aWps);
108 typedef SGSharedPtr<Transition> TransitionRef;
111 * Describe an approach procedure, including the missed approach
114 class Approach : public Procedure
117 virtual ~Approach() { ; }
122 static bool isApproach(ProcedureType ty);
124 virtual FGAirport* airport() const;
126 virtual RunwayVec runways() const;
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
133 bool route(WayptRef aIAF, WayptVec& aWps);
136 * Build route as above, but ignore transitions, and assume radar
137 * vectoring to the start of main approach
139 bool routeFromVectors(WayptVec& aWps);
141 const WayptVec& primary() const
144 const WayptVec& missed() const
147 virtual ProcedureType type() const
150 static Approach* createTempApproach(const std::string& aIdent, FGRunway* aRunway, const WayptVec& aPath);
152 friend class NavdataVisitor;
154 Approach(const std::string& aIdent, ProcedureType ty);
156 void setRunway(FGRunwayRef aRwy);
157 void setPrimaryAndMissed(const WayptVec& aPrimary, const WayptVec& aMissed);
158 void addTransition(Transition* aTrans);
163 typedef std::map<WayptRef, TransitionRef> WptTransitionMap;
164 WptTransitionMap _transitions;
166 WayptVec _primary; // unify these?
170 class ArrivalDeparture : public Procedure
173 virtual FGAirport* airport() const
177 * Predicate, test if this procedure applies to the requested runway
179 virtual bool isForRunway(const FGRunway* aWay) const;
181 virtual RunwayVec runways() const;
184 * Find a path between the runway and enroute structure. Waypoints
185 * corresponding to the appropriate transitions and segments will be created.
187 virtual bool route(FGRunwayRef aWay, Transition* trans, WayptVec& aPath) = 0;
189 const WayptVec& common() const
192 string_list transitionIdents() const;
195 * Given an enroute location, find the best enroute transition point for
196 * this arrival/departure. Best is currently determined as 'closest to the
199 WayptRef findBestTransition(const SGGeod& aPos) const;
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).
206 Transition* findTransitionByName(const std::string& aIdent) const;
208 Transition* findTransitionByEnroute(Waypt* aEnroute) const;
211 bool commonRoute(Transition* t, WayptVec& aPath, FGRunwayRef aRwy);
213 ArrivalDeparture(const std::string& aIdent, FGAirport* apt);
215 void addRunway(FGRunwayRef aRwy);
217 typedef std::map<FGRunwayRef, TransitionRef> RunwayTransitionMap;
218 RunwayTransitionMap _runways;
220 virtual WayptFlag flagType() const = 0;
222 void setCommon(const WayptVec& aWps);
225 friend class NavdataVisitor;
227 void addTransition(Transition* aTrans);
229 void addRunwayTransition(FGRunwayRef aRwy, Transition* aTrans);
234 typedef std::map<WayptRef, TransitionRef> WptTransitionMap;
235 WptTransitionMap _enrouteTransitions;
240 class SID : public ArrivalDeparture
245 virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
247 virtual ProcedureType type() const
248 { return PROCEDURE_SID; }
250 static SID* createTempSID(const std::string& aIdent, FGRunway* aRunway, const WayptVec& aPath);
252 virtual WayptFlag flagType() const
253 { return WPT_DEPARTURE; }
256 friend class NavdataVisitor;
258 SID(const std::string& aIdent, FGAirport* apt);
261 class STAR : public ArrivalDeparture
264 virtual ~STAR() { ; }
266 virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
268 virtual ProcedureType type() const
269 { return PROCEDURE_STAR; }
272 virtual WayptFlag flagType() const
273 { return WPT_ARRIVAL; }
276 friend class NavdataVisitor;
278 STAR(const std::string& aIdent, FGAirport* apt);