| 1 | // waypoint.hxx - waypoints that can occur in routes/procedures |
| 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_WAYPOINT_HXX |
| 21 | #define FG_WAYPOINT_HXX |
| 22 | |
| 23 | #include <Airports/airports_fwd.hxx> |
| 24 | #include <Navaids/route.hxx> |
| 25 | #include <Navaids/positioned.hxx> |
| 26 | #include <Navaids/airways.hxx> |
| 27 | |
| 28 | namespace flightgear |
| 29 | { |
| 30 | |
| 31 | class BasicWaypt : public Waypt |
| 32 | { |
| 33 | public: |
| 34 | |
| 35 | BasicWaypt(const SGGeod& aPos, const std::string& aIdent, RouteBase* aOwner); |
| 36 | |
| 37 | BasicWaypt(RouteBase* aOwner); |
| 38 | |
| 39 | virtual SGGeod position() const |
| 40 | { return _pos; } |
| 41 | |
| 42 | virtual std::string ident() const |
| 43 | { return _ident; } |
| 44 | |
| 45 | std::string icaoDescription() const override; |
| 46 | protected: |
| 47 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 48 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 49 | |
| 50 | virtual std::string type() const |
| 51 | { return "basic"; } |
| 52 | |
| 53 | SGGeod _pos; |
| 54 | std::string _ident; |
| 55 | |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | * Waypoint based upon a navaid. In practice this means any Positioned |
| 60 | * element, excluding runways (see below) |
| 61 | */ |
| 62 | class NavaidWaypoint : public Waypt |
| 63 | { |
| 64 | public: |
| 65 | NavaidWaypoint(FGPositioned* aPos, RouteBase* aOwner); |
| 66 | |
| 67 | NavaidWaypoint(RouteBase* aOwner); |
| 68 | |
| 69 | virtual SGGeod position() const; |
| 70 | |
| 71 | virtual FGPositioned* source() const |
| 72 | { return _navaid; } |
| 73 | |
| 74 | virtual std::string ident() const; |
| 75 | |
| 76 | protected: |
| 77 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 78 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 79 | |
| 80 | virtual std::string type() const |
| 81 | { return "navaid"; } |
| 82 | |
| 83 | FGPositionedRef _navaid; |
| 84 | }; |
| 85 | |
| 86 | class OffsetNavaidWaypoint : public NavaidWaypoint |
| 87 | { |
| 88 | public: |
| 89 | OffsetNavaidWaypoint(FGPositioned* aPos, RouteBase* aOwner, double aRadial, double aDistNm); |
| 90 | |
| 91 | OffsetNavaidWaypoint(RouteBase* aOwner); |
| 92 | |
| 93 | virtual SGGeod position() const |
| 94 | { return _geod; } |
| 95 | |
| 96 | protected: |
| 97 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 98 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 99 | |
| 100 | virtual std::string type() const |
| 101 | { return "offset-navaid"; } |
| 102 | |
| 103 | private: |
| 104 | void init(); |
| 105 | |
| 106 | SGGeod _geod; |
| 107 | double _radial; // true, degrees |
| 108 | double _distanceNm; |
| 109 | }; |
| 110 | |
| 111 | /** |
| 112 | * Waypoint based upon a runway. |
| 113 | * Runways are handled specially in various places, so it's cleaner |
| 114 | * to be able to distuinguish them from other navaid waypoints |
| 115 | */ |
| 116 | class RunwayWaypt : public Waypt |
| 117 | { |
| 118 | public: |
| 119 | RunwayWaypt(FGRunway* aPos, RouteBase* aOwner); |
| 120 | |
| 121 | RunwayWaypt(RouteBase* aOwner); |
| 122 | |
| 123 | virtual SGGeod position() const; |
| 124 | |
| 125 | virtual FGPositioned* source() const; |
| 126 | |
| 127 | virtual std::string ident() const; |
| 128 | |
| 129 | FGRunway* runway() const |
| 130 | { return _runway; } |
| 131 | |
| 132 | virtual double headingRadialDeg() const; |
| 133 | protected: |
| 134 | virtual std::string type() const |
| 135 | { return "runway"; } |
| 136 | |
| 137 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 138 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 139 | |
| 140 | private: |
| 141 | FGRunway* _runway; |
| 142 | }; |
| 143 | |
| 144 | class Hold : public BasicWaypt |
| 145 | { |
| 146 | public: |
| 147 | Hold(const SGGeod& aPos, const std::string& aIdent, RouteBase* aOwner); |
| 148 | |
| 149 | Hold(RouteBase* aOwner); |
| 150 | |
| 151 | void setHoldRadial(double aInboundRadial); |
| 152 | void setHoldDistance(double aDistanceNm); |
| 153 | void setHoldTime(double aTimeSec); |
| 154 | |
| 155 | void setRightHanded(); |
| 156 | void setLeftHanded(); |
| 157 | |
| 158 | double inboundRadial() const |
| 159 | { return _bearing; } |
| 160 | |
| 161 | bool isLeftHanded() const |
| 162 | { return !_righthanded; } |
| 163 | |
| 164 | bool isDistance() const |
| 165 | { return _isDistance; } |
| 166 | |
| 167 | double timeOrDistance() const |
| 168 | { return _holdTD;} |
| 169 | |
| 170 | virtual double headingRadialDeg() const |
| 171 | { return inboundRadial(); } |
| 172 | protected: |
| 173 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 174 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 175 | |
| 176 | virtual std::string type() const |
| 177 | { return "hold"; } |
| 178 | |
| 179 | private: |
| 180 | double _bearing; |
| 181 | bool _righthanded; |
| 182 | bool _isDistance; |
| 183 | double _holdTD; |
| 184 | }; |
| 185 | |
| 186 | class HeadingToAltitude : public Waypt |
| 187 | { |
| 188 | public: |
| 189 | HeadingToAltitude(RouteBase* aOwner, const std::string& aIdent, double aMagHdg); |
| 190 | |
| 191 | HeadingToAltitude(RouteBase* aOwner); |
| 192 | |
| 193 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 194 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 195 | |
| 196 | virtual std::string type() const |
| 197 | { return "hdgToAlt"; } |
| 198 | |
| 199 | virtual SGGeod position() const |
| 200 | { return SGGeod(); } |
| 201 | |
| 202 | virtual std::string ident() const |
| 203 | { return _ident; } |
| 204 | |
| 205 | double headingDegMagnetic() const |
| 206 | { return _magHeading; } |
| 207 | |
| 208 | virtual double magvarDeg() const |
| 209 | { return 0.0; } |
| 210 | |
| 211 | virtual double headingRadialDeg() const |
| 212 | { return headingDegMagnetic(); } |
| 213 | private: |
| 214 | std::string _ident; |
| 215 | double _magHeading; |
| 216 | }; |
| 217 | |
| 218 | class DMEIntercept : public Waypt |
| 219 | { |
| 220 | public: |
| 221 | DMEIntercept(RouteBase* aOwner, const std::string& aIdent, const SGGeod& aPos, |
| 222 | double aCourseDeg, double aDistanceNm); |
| 223 | |
| 224 | DMEIntercept(RouteBase* aOwner); |
| 225 | |
| 226 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 227 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 228 | |
| 229 | virtual std::string type() const |
| 230 | { return "dmeIntercept"; } |
| 231 | |
| 232 | virtual SGGeod position() const |
| 233 | { return _pos; } |
| 234 | |
| 235 | virtual std::string ident() const |
| 236 | { return _ident; } |
| 237 | |
| 238 | double courseDegMagnetic() const |
| 239 | { return _magCourse; } |
| 240 | |
| 241 | double dmeDistanceNm() const |
| 242 | { return _dmeDistanceNm; } |
| 243 | |
| 244 | virtual double headingRadialDeg() const |
| 245 | { return courseDegMagnetic(); } |
| 246 | private: |
| 247 | std::string _ident; |
| 248 | SGGeod _pos; |
| 249 | double _magCourse; |
| 250 | double _dmeDistanceNm; |
| 251 | }; |
| 252 | |
| 253 | class RadialIntercept : public Waypt |
| 254 | { |
| 255 | public: |
| 256 | RadialIntercept(RouteBase* aOwner, const std::string& aIdent, const SGGeod& aPos, |
| 257 | double aCourseDeg, double aRadialDeg); |
| 258 | |
| 259 | RadialIntercept(RouteBase* aOwner); |
| 260 | |
| 261 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 262 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 263 | |
| 264 | virtual std::string type() const |
| 265 | { return "radialIntercept"; } |
| 266 | |
| 267 | virtual SGGeod position() const |
| 268 | { return _pos; } |
| 269 | |
| 270 | virtual std::string ident() const |
| 271 | { return _ident; } |
| 272 | |
| 273 | double courseDegMagnetic() const |
| 274 | { return _magCourse; } |
| 275 | |
| 276 | double radialDegMagnetic() const |
| 277 | { return _radial; } |
| 278 | |
| 279 | virtual double headingRadialDeg() const |
| 280 | { return courseDegMagnetic(); } |
| 281 | private: |
| 282 | std::string _ident; |
| 283 | SGGeod _pos; |
| 284 | double _magCourse; |
| 285 | double _radial; |
| 286 | }; |
| 287 | |
| 288 | |
| 289 | /** |
| 290 | * Represent ATC radar vectored segment. Common at the end of published |
| 291 | * missed approach procedures, and from STAR arrival points to final approach |
| 292 | */ |
| 293 | class ATCVectors : public Waypt |
| 294 | { |
| 295 | public: |
| 296 | ATCVectors(RouteBase* aOwner, FGAirport* aFacility); |
| 297 | virtual ~ATCVectors(); |
| 298 | |
| 299 | ATCVectors(RouteBase* aOwner); |
| 300 | |
| 301 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 302 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 303 | |
| 304 | virtual std::string type() const |
| 305 | { return "vectors"; } |
| 306 | |
| 307 | virtual SGGeod position() const; |
| 308 | |
| 309 | virtual std::string ident() const; |
| 310 | |
| 311 | private: |
| 312 | /** |
| 313 | * ATC facility. Using an airport here is incorrect, since often arrivals |
| 314 | * facilities will be shared between several nearby airports, but it |
| 315 | * suffices until we have a proper facility representation |
| 316 | */ |
| 317 | FGAirportRef _facility; |
| 318 | }; |
| 319 | |
| 320 | /** |
| 321 | * Represent a route discontinuity. These can occur while editing |
| 322 | * plans via certain interfaces (such as CDUs) |
| 323 | */ |
| 324 | class Discontinuity : public Waypt |
| 325 | { |
| 326 | public: |
| 327 | virtual ~Discontinuity(); |
| 328 | Discontinuity(RouteBase* aOwner); |
| 329 | |
| 330 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 331 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 332 | |
| 333 | virtual std::string type() const |
| 334 | { return "discontinuity"; } |
| 335 | |
| 336 | virtual SGGeod position() const; |
| 337 | |
| 338 | virtual std::string ident() const; |
| 339 | |
| 340 | virtual double magvarDeg() const |
| 341 | { return 0.0; } |
| 342 | private: |
| 343 | }; |
| 344 | |
| 345 | class Via : public Waypt |
| 346 | { |
| 347 | public: |
| 348 | Via(RouteBase* aOwner); |
| 349 | Via(RouteBase* aOwner, AirwayRef airway, FGPositionedRef to); |
| 350 | virtual ~Via(); |
| 351 | |
| 352 | bool initFromProperties(SGPropertyNode_ptr aProp) override; |
| 353 | void writeToProperties(SGPropertyNode_ptr aProp) const override; |
| 354 | |
| 355 | std::string type() const override |
| 356 | { return "via"; } |
| 357 | |
| 358 | SGGeod position() const override; |
| 359 | |
| 360 | std::string ident() const override; |
| 361 | |
| 362 | AirwayRef airway() const |
| 363 | { return _airway; } |
| 364 | |
| 365 | FGPositioned* source() const override |
| 366 | { return _to.ptr(); } |
| 367 | |
| 368 | WayptVec expandToWaypoints(WayptRef aPreceeding) const; |
| 369 | private: |
| 370 | AirwayRef _airway; |
| 371 | FGPositionedRef _to; |
| 372 | }; |
| 373 | |
| 374 | } // of namespace flighgear |
| 375 | |
| 376 | #endif // of FG_WAYPOINT_HXX |