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