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 virtual ~Transition() { ; }
77 bool route(WayptVec& aPath);
79 Procedure* parent() const
82 virtual FGAirport* airport() const;
85 * Return the enroute end of the transition
87 WayptRef enroute() const;
90 * Return the procedure end of the transition
92 WayptRef procedureEnd() const;
95 virtual ProcedureType type() const
98 void mark(WayptFlag f);
100 friend class NavdataVisitor;
102 Transition(const std::string& aIdent, ProcedureType ty, Procedure* aPr);
104 void setPrimary(const WayptVec& aWps);
111 typedef SGSharedPtr<Transition> TransitionRef;
114 * Describe an approach procedure, including the missed approach
117 class Approach : public Procedure
120 virtual ~Approach() { ; }
125 static bool isApproach(ProcedureType ty);
127 virtual FGAirport* airport() const;
129 virtual RunwayVec runways() const;
132 * Build a route from a valid IAF to the runway, including the missed
133 * segment. Return false if no valid transition from the specified IAF
136 bool route(WayptRef aIAF, WayptVec& aWps);
139 * Build route as above, but ignore transitions, and assume radar
140 * vectoring to the start of main approach
142 bool routeFromVectors(WayptVec& aWps);
144 const WayptVec& primary() const
147 const WayptVec& missed() const
150 virtual ProcedureType type() const
153 static Approach* createTempApproach(const std::string& aIdent, FGRunway* aRunway, const WayptVec& aPath);
155 friend class NavdataVisitor;
157 Approach(const std::string& aIdent, ProcedureType ty);
159 void setRunway(FGRunwayRef aRwy);
160 void setPrimaryAndMissed(const WayptVec& aPrimary, const WayptVec& aMissed);
161 void addTransition(Transition* aTrans);
166 typedef std::map<WayptRef, TransitionRef> WptTransitionMap;
167 WptTransitionMap _transitions;
169 WayptVec _primary; // unify these?
173 class ArrivalDeparture : public Procedure
176 virtual FGAirport* airport() const
180 * Predicate, test if this procedure applies to the requested runway
182 virtual bool isForRunway(const FGRunway* aWay) const;
184 virtual RunwayVec runways() const;
187 * Find a path between the runway and enroute structure. Waypoints
188 * corresponding to the appropriate transitions and segments will be created.
190 virtual bool route(FGRunwayRef aWay, Transition* trans, WayptVec& aPath) = 0;
192 const WayptVec& common() const
195 string_list transitionIdents() const;
198 * Given an enroute location, find the best enroute transition point for
199 * this arrival/departure. Best is currently determined as 'closest to the
202 WayptRef findBestTransition(const SGGeod& aPos) const;
205 * Find an enroute transition waypoint by identifier. This is necessary
206 * for the route-manager and similar code that that needs to talk about
207 * transitions in a human-meaningful way (including persistence).
209 Transition* findTransitionByName(const std::string& aIdent) const;
211 Transition* findTransitionByEnroute(Waypt* aEnroute) const;
214 bool commonRoute(Transition* t, WayptVec& aPath, FGRunwayRef aRwy);
216 ArrivalDeparture(const std::string& aIdent, FGAirport* apt);
218 void addRunway(FGRunwayRef aRwy);
220 typedef std::map<FGRunwayRef, TransitionRef> RunwayTransitionMap;
221 RunwayTransitionMap _runways;
223 virtual WayptFlag flagType() const = 0;
225 void setCommon(const WayptVec& aWps);
228 friend class NavdataVisitor;
230 void addTransition(Transition* aTrans);
232 void addRunwayTransition(FGRunwayRef aRwy, Transition* aTrans);
237 typedef std::map<WayptRef, TransitionRef> WptTransitionMap;
238 WptTransitionMap _enrouteTransitions;
243 class SID : public ArrivalDeparture
248 virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
250 virtual ProcedureType type() const
251 { return PROCEDURE_SID; }
253 static SID* createTempSID(const std::string& aIdent, FGRunway* aRunway, const WayptVec& aPath);
255 virtual WayptFlag flagType() const
256 { return WPT_DEPARTURE; }
259 friend class NavdataVisitor;
261 SID(const std::string& aIdent, FGAirport* apt);
264 class STAR : public ArrivalDeparture
267 virtual ~STAR() { ; }
269 virtual bool route(FGRunwayRef aWay, Transition* aTrans, WayptVec& aPath);
271 virtual ProcedureType type() const
272 { return PROCEDURE_STAR; }
275 virtual WayptFlag flagType() const
276 { return WPT_ARRIVAL; }
279 friend class NavdataVisitor;
281 STAR(const std::string& aIdent, FGAirport* apt);